diff options
author | Alex Wang <alexw@nicira.com> | 2013-06-19 16:58:44 -0700 |
---|---|---|
committer | Ben Pfaff <blp@nicira.com> | 2013-06-20 10:42:37 -0700 |
commit | 4e022ec09e14ac89add74c1b4b8e3ff3873edbf0 (patch) | |
tree | a6817234d1d992d2a7970865c1464dfaaf247c7f /lib/bundle.c | |
parent | e6cc0babc25de1800aeffad66d2804e64e5bd602 (diff) |
Create specific types for ofp and odp port
Until now, datapath ports and openflow ports were both represented by
unsigned integers of various sizes. With implicit conversions, etc., it is
easy to mix them up and use one where the other is expected. This commit
creates two typedefs, ofp_port_t and odp_port_t. Both of these two types
are marked by "__attribute__((bitwise))" so that sparse can be used to
detect any misuse.
Signed-off-by: Alex Wang <alexw@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'lib/bundle.c')
-rw-r--r-- | lib/bundle.c | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/lib/bundle.c b/lib/bundle.c index b3821e85..d1834d0e 100644 --- a/lib/bundle.c +++ b/lib/bundle.c @@ -35,14 +35,14 @@ VLOG_DEFINE_THIS_MODULE(bundle); -static uint16_t +static ofp_port_t execute_ab(const struct ofpact_bundle *bundle, - bool (*slave_enabled)(uint16_t ofp_port, void *aux), void *aux) + bool (*slave_enabled)(ofp_port_t ofp_port, void *aux), void *aux) { size_t i; for (i = 0; i < bundle->n_slaves; i++) { - uint16_t slave = bundle->slaves[i]; + ofp_port_t slave = bundle->slaves[i]; if (slave_enabled(slave, aux)) { return slave; } @@ -51,10 +51,10 @@ execute_ab(const struct ofpact_bundle *bundle, return OFPP_NONE; } -static uint16_t +static ofp_port_t execute_hrw(const struct ofpact_bundle *bundle, const struct flow *flow, struct flow_wildcards *wc, - bool (*slave_enabled)(uint16_t ofp_port, void *aux), void *aux) + bool (*slave_enabled)(ofp_port_t ofp_port, void *aux), void *aux) { uint32_t flow_hash, best_hash; int best, i; @@ -85,10 +85,11 @@ execute_hrw(const struct ofpact_bundle *bundle, * calculate the result. Uses 'slave_enabled' to determine if the slave * designated by 'ofp_port' is up. Returns the chosen slave, or * OFPP_NONE if none of the slaves are acceptable. */ -uint16_t +ofp_port_t bundle_execute(const struct ofpact_bundle *bundle, const struct flow *flow, struct flow_wildcards *wc, - bool (*slave_enabled)(uint16_t ofp_port, void *aux), void *aux) + bool (*slave_enabled)(ofp_port_t ofp_port, void *aux), + void *aux) { switch (bundle->algorithm) { case NX_BD_ALG_HRW: @@ -186,7 +187,7 @@ bundle_from_openflow(const struct nx_action_bundle *nab, } enum ofperr -bundle_check(const struct ofpact_bundle *bundle, int max_ports, +bundle_check(const struct ofpact_bundle *bundle, ofp_port_t max_ports, const struct flow *flow) { static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5); @@ -200,7 +201,7 @@ bundle_check(const struct ofpact_bundle *bundle, int max_ports, } for (i = 0; i < bundle->n_slaves; i++) { - uint16_t ofp_port = bundle->slaves[i]; + ofp_port_t ofp_port = bundle->slaves[i]; enum ofperr error; error = ofputil_check_output_port(ofp_port, max_ports); @@ -246,7 +247,7 @@ bundle_to_nxast(const struct ofpact_bundle *bundle, struct ofpbuf *openflow) slaves = ofpbuf_put_zeros(openflow, slaves_len); for (i = 0; i < bundle->n_slaves; i++) { - slaves[i] = htons(bundle->slaves[i]); + slaves[i] = htons(ofp_to_u16(bundle->slaves[i])); } } @@ -271,7 +272,7 @@ bundle_parse__(const char *s, char **save_ptr, bundle = ofpact_put_BUNDLE(ofpacts); for (;;) { - uint16_t slave_port; + ofp_port_t slave_port; char *slave; slave = strtok_r(NULL, ", []", save_ptr); |