Skip to content

Commit

Permalink
ofp-util: Move ofputil_check_output_port() to ofp-actions, rename.
Browse files Browse the repository at this point in the history
This function is related to actions to ofp-actions seems like a logical
place for it.

Signed-off-by: Ben Pfaff <[email protected]>
Acked-by: Jarno Rajahalme <[email protected]>
  • Loading branch information
blp committed Nov 2, 2013
1 parent 1e7db67 commit 57ad4e9
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 32 deletions.
2 changes: 1 addition & 1 deletion lib/bundle.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ bundle_check(const struct ofpact_bundle *bundle, ofp_port_t max_ports,
ofp_port_t ofp_port = bundle->slaves[i];
enum ofperr error;

error = ofputil_check_output_port(ofp_port, max_ports);
error = ofpact_check_output_port(ofp_port, max_ports);
if (error) {
VLOG_WARN_RL(&rl, "invalid slave %"PRIu16, ofp_port);
return error;
Expand Down
33 changes: 29 additions & 4 deletions lib/ofp-actions.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ output_from_openflow10(const struct ofp10_action_output *oao,
output->port = u16_to_ofp(ntohs(oao->port));
output->max_len = ntohs(oao->max_len);

return ofputil_check_output_port(output->port, OFPP_MAX);
return ofpact_check_output_port(output->port, OFPP_MAX);
}

static enum ofperr
Expand Down Expand Up @@ -1088,7 +1088,7 @@ output_from_openflow11(const struct ofp11_action_output *oao,
return error;
}

return ofputil_check_output_port(output->port, OFPP_MAX);
return ofpact_check_output_port(output->port, OFPP_MAX);
}

static enum ofperr
Expand Down Expand Up @@ -1793,6 +1793,31 @@ ofpacts_pull_openflow_instructions(struct ofpbuf *openflow,
return error;
}

/* Checks that 'port' is a valid output port for OFPACT_OUTPUT, given that the
* switch will never have more than 'max_ports' ports. Returns 0 if 'port' is
* valid, otherwise an OpenFlow error code. */
enum ofperr
ofpact_check_output_port(ofp_port_t port, ofp_port_t max_ports)
{
switch (port) {
case OFPP_IN_PORT:
case OFPP_TABLE:
case OFPP_NORMAL:
case OFPP_FLOOD:
case OFPP_ALL:
case OFPP_CONTROLLER:
case OFPP_NONE:
case OFPP_LOCAL:
return 0;

default:
if (ofp_to_u16(port) < ofp_to_u16(max_ports)) {
return 0;
}
return OFPERR_OFPBAC_BAD_OUT_PORT;
}
}

/* May modify flow->dl_type and flow->vlan_tci, caller must restore them.
*
* Modifies some actions, filling in fields that could not be properly set
Expand All @@ -1806,8 +1831,8 @@ ofpact_check__(struct ofpact *a, struct flow *flow, ofp_port_t max_ports,

switch (a->type) {
case OFPACT_OUTPUT:
return ofputil_check_output_port(ofpact_get_OUTPUT(a)->port,
max_ports);
return ofpact_check_output_port(ofpact_get_OUTPUT(a)->port,
max_ports);

case OFPACT_CONTROLLER:
return 0;
Expand Down
1 change: 1 addition & 0 deletions lib/ofp-actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ enum ofperr ofpacts_check(struct ofpact[], size_t ofpacts_len,
struct flow *, ofp_port_t max_ports,
uint8_t table_id, bool enforce_consistency);
enum ofperr ofpacts_verify(const struct ofpact ofpacts[], size_t ofpacts_len);
enum ofperr ofpact_check_output_port(ofp_port_t port, ofp_port_t max_ports);

/* Converting ofpacts to OpenFlow. */
size_t ofpacts_put_openflow_actions(const struct ofpact[], size_t ofpacts_len,
Expand Down
25 changes: 0 additions & 25 deletions lib/ofp-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -4847,31 +4847,6 @@ ofputil_port_to_ofp11(ofp_port_t ofp10_port)
: ofp_to_u16(ofp10_port) + OFPP11_OFFSET);
}

/* Checks that 'port' is a valid output port for the OFPAT10_OUTPUT action, given
* that the switch will never have more than 'max_ports' ports. Returns 0 if
* 'port' is valid, otherwise an OpenFlow return code. */
enum ofperr
ofputil_check_output_port(ofp_port_t port, ofp_port_t max_ports)
{
switch (port) {
case OFPP_IN_PORT:
case OFPP_TABLE:
case OFPP_NORMAL:
case OFPP_FLOOD:
case OFPP_ALL:
case OFPP_CONTROLLER:
case OFPP_NONE:
case OFPP_LOCAL:
return 0;

default:
if (ofp_to_u16(port) < ofp_to_u16(max_ports)) {
return 0;
}
return OFPERR_OFPBAC_BAD_OUT_PORT;
}
}

#define OFPUTIL_NAMED_PORTS \
OFPUTIL_NAMED_PORT(IN_PORT) \
OFPUTIL_NAMED_PORT(TABLE) \
Expand Down
2 changes: 0 additions & 2 deletions lib/ofp-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ enum ofperr ofputil_port_from_ofp11(ovs_be32 ofp11_port,
ofp_port_t *ofp10_port);
ovs_be32 ofputil_port_to_ofp11(ofp_port_t ofp10_port);

enum ofperr ofputil_check_output_port(ofp_port_t ofp_port,
ofp_port_t max_ports);
bool ofputil_port_from_string(const char *, ofp_port_t *portp);
void ofputil_format_port(ofp_port_t port, struct ds *);
void ofputil_port_to_string(ofp_port_t, char namebuf[OFP_MAX_PORT_NAME_LEN],
Expand Down

0 comments on commit 57ad4e9

Please sign in to comment.