mirror of
https://github.com/openvswitch/ovs
synced 2025-10-17 14:28:02 +00:00
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>
This commit is contained in:
23
lib/bundle.c
23
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);
|
||||
|
Reference in New Issue
Block a user