X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Fofp-msgs.c;h=677d359ed113635751838feb57e1061167042aa3;hb=79f108b14e7944ddc4669e9c03fc34b40a3a2288;hp=af4178eb4867b843561c0aa70aa4fce45ad55ed3;hpb=67680b012be30d9c26eab999b83b08c6eb32dbd2;p=sliver-openvswitch.git diff --git a/lib/ofp-msgs.c b/lib/ofp-msgs.c index af4178eb4..677d359ed 100644 --- a/lib/ofp-msgs.c +++ b/lib/ofp-msgs.c @@ -23,6 +23,7 @@ #include "ofpbuf.h" #include "openflow/nicira-ext.h" #include "openflow/openflow.h" +#include "ovs-thread.h" #include "vlog.h" VLOG_DEFINE_THIS_MODULE(ofp_msgs); @@ -109,8 +110,11 @@ static enum ofperr ofpraw_from_ofphdrs(enum ofpraw *, const struct ofphdrs *); static ovs_be32 alloc_xid(void) { - static uint32_t next_xid = 1; - return htonl(next_xid++); + static atomic_uint32_t next_xid = ATOMIC_VAR_INIT(1); + uint32_t xid; + + atomic_add(&next_xid, 1, &xid); + return htonl(xid); } static uint32_t @@ -256,22 +260,50 @@ 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: + case OFP14_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); + case OFP14_VERSION: + 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) { @@ -292,6 +324,7 @@ ofphdrs_len(const struct ofphdrs *hdrs) case OFP11_VERSION: case OFP12_VERSION: case OFP13_VERSION: + case OFP14_VERSION: if (hdrs->type == OFPT11_STATS_REQUEST || hdrs->type == OFPT11_STATS_REPLY) { return (hdrs->stat == OFPST_VENDOR @@ -366,7 +399,8 @@ ofpraw_pull(enum ofpraw *rawp, struct ofpbuf *msg) enum ofpraw raw; /* Set default outputs. */ - msg->l2 = msg->l3 = msg->data; + msg->l2 = msg->data; + ofpbuf_set_l3(msg, msg->data); *rawp = 0; len = msg->size; @@ -383,7 +417,7 @@ ofpraw_pull(enum ofpraw *rawp, struct ofpbuf *msg) info = raw_info_get(raw); instance = raw_instance_get(info, hdrs.version); msg->l2 = ofpbuf_pull(msg, instance->hdrs_len); - msg->l3 = msg->data; + ofpbuf_set_l3(msg, msg->data); min_len = instance->hdrs_len + info->min_body; switch (info->extra_multiple) { @@ -631,7 +665,7 @@ ofpraw_put__(enum ofpraw raw, uint8_t version, ovs_be32 xid, ofpbuf_prealloc_tailroom(buf, (instance->hdrs_len + info->min_body + extra_tailroom)); buf->l2 = ofpbuf_put_uninit(buf, instance->hdrs_len); - buf->l3 = ofpbuf_tail(buf); + ofpbuf_set_l3(buf, ofpbuf_tail(buf)); oh = buf->l2; oh->version = version; @@ -663,7 +697,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 @@ -684,7 +718,7 @@ ofpraw_put__(enum ofpraw raw, uint8_t version, ovs_be32 xid, nsm->subtype = htonl(hdrs->subtype); } else { - NOT_REACHED(); + OVS_NOT_REACHED(); } } } @@ -723,11 +757,12 @@ ofpraw_stats_request_to_reply(enum ofpraw raw, uint8_t version) case OFP11_VERSION: case OFP12_VERSION: case OFP13_VERSION: + case OFP14_VERSION: ovs_assert(hdrs.type == OFPT11_STATS_REQUEST); hdrs.type = OFPT11_STATS_REPLY; break; default: - NOT_REACHED(); + OVS_NOT_REACHED(); } error = ofpraw_from_ofphdrs(&reply_raw, &hdrs); @@ -807,6 +842,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 *); @@ -852,7 +894,7 @@ ofpmp_reserve(struct list *replies, size_t len) next = ofpbuf_new(MAX(1024, hdrs_len + len)); ofpbuf_put(next, msg->data, hdrs_len); next->l2 = next->data; - next->l3 = ofpbuf_tail(next); + ofpbuf_set_l3(next, ofpbuf_tail(next)); list_push_back(replies, &next->list_node); *ofpmp_flags__(msg->data) |= htons(OFPSF_REPLY_MORE); @@ -902,9 +944,10 @@ ofpmp_flags__(const struct ofp_header *oh) case OFP11_VERSION: case OFP12_VERSION: case OFP13_VERSION: + case OFP14_VERSION: return &((struct ofp11_stats_msg *) oh)->flags; default: - NOT_REACHED(); + OVS_NOT_REACHED(); } } @@ -988,9 +1031,10 @@ ofpraw_from_ofphdrs(enum ofpraw *raw, const struct ofphdrs *hdrs) static void ofpmsgs_init(void) { + static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER; const struct raw_info *info; - if (raw_instance_map.buckets) { + if (!ovsthread_once_start(&once)) { return; } @@ -1008,4 +1052,6 @@ ofpmsgs_init(void) ofphdrs_hash(&inst->hdrs)); } } + + ovsthread_once_done(&once); }