X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Fofp-msgs.c;h=4f07d0e18306c33df7fb87641c6bf8f704ace314;hb=4b0424809b823101c969a0691fc1db0c880ae64a;hp=8bb1754f6015fb20571807e0cce6676792df46e2;hpb=d0c79f7fe0954b5d607e4190d26bb6b5ba75ceaf;p=sliver-openvswitch.git diff --git a/lib/ofp-msgs.c b/lib/ofp-msgs.c index 8bb1754f6..4f07d0e18 100644 --- a/lib/ofp-msgs.c +++ b/lib/ofp-msgs.c @@ -110,14 +110,10 @@ static enum ofperr ofpraw_from_ofphdrs(enum ofpraw *, const struct ofphdrs *); static ovs_be32 alloc_xid(void) { - static uint32_t next_xid = 1; - static pthread_mutex_t mutex = PTHREAD_ADAPTIVE_MUTEX_INITIALIZER; + static atomic_uint32_t next_xid = ATOMIC_VAR_INIT(1); uint32_t xid; - xpthread_mutex_lock(&mutex); - xid = next_xid++; - xpthread_mutex_unlock(&mutex); - + atomic_add(&next_xid, 1, &xid); return htonl(xid); } @@ -264,22 +260,48 @@ ofphdrs_decode_assert(struct ofphdrs *hdrs, } static bool -ofphdrs_is_stat(const struct ofphdrs *hdrs) +ofp_is_stat_request(enum ofp_version version, uint8_t type) { - switch ((enum ofp_version) hdrs->version) { + switch (version) { + case OFP10_VERSION: + return type == OFPT10_STATS_REQUEST; + case OFP11_VERSION: + case OFP12_VERSION: + case OFP13_VERSION: + return type == OFPT11_STATS_REQUEST; + } + + return false; +} + +static bool +ofp_is_stat_reply(enum ofp_version version, uint8_t type) +{ + switch (version) { case OFP10_VERSION: - return (hdrs->type == OFPT10_STATS_REQUEST || - hdrs->type == OFPT10_STATS_REPLY); + return type == OFPT10_STATS_REPLY; case OFP11_VERSION: case OFP12_VERSION: case OFP13_VERSION: - return (hdrs->type == OFPT11_STATS_REQUEST || - hdrs->type == OFPT11_STATS_REPLY); + return type == OFPT11_STATS_REPLY; } return false; } +static bool +ofp_is_stat(enum ofp_version version, uint8_t type) +{ + return (ofp_is_stat_request(version, type) || + ofp_is_stat_reply(version, type)); +} + +static bool +ofphdrs_is_stat(const struct ofphdrs *hdrs) +{ + return ofp_is_stat(hdrs->version, hdrs->type); +} + size_t ofphdrs_len(const struct ofphdrs *hdrs) { @@ -671,7 +693,7 @@ ofpraw_put__(enum ofpraw raw, uint8_t version, ovs_be32 xid, nsm->subtype = htonl(hdrs->subtype); memset(nsm->pad, 0, sizeof nsm->pad); } else { - NOT_REACHED(); + OVS_NOT_REACHED(); } } } else if (version != OFP10_VERSION @@ -692,7 +714,7 @@ ofpraw_put__(enum ofpraw raw, uint8_t version, ovs_be32 xid, nsm->subtype = htonl(hdrs->subtype); } else { - NOT_REACHED(); + OVS_NOT_REACHED(); } } } @@ -735,7 +757,7 @@ ofpraw_stats_request_to_reply(enum ofpraw raw, uint8_t version) hdrs.type = OFPT11_STATS_REPLY; break; default: - NOT_REACHED(); + OVS_NOT_REACHED(); } error = ofpraw_from_ofphdrs(&reply_raw, &hdrs); @@ -815,6 +837,13 @@ ofpmsg_body(const struct ofp_header *oh) ofphdrs_decode_assert(&hdrs, oh, ntohs(oh->length)); return (const uint8_t *) oh + ofphdrs_len(&hdrs); } + +/* Return if it's a stat/multipart (OFPST) request message. */ +bool +ofpmsg_is_stat_request(const struct ofp_header *oh) +{ + return ofp_is_stat_request(oh->version, oh->type); +} static ovs_be16 *ofpmp_flags__(const struct ofp_header *); @@ -912,7 +941,7 @@ ofpmp_flags__(const struct ofp_header *oh) case OFP13_VERSION: return &((struct ofp11_stats_msg *) oh)->flags; default: - NOT_REACHED(); + OVS_NOT_REACHED(); } }