#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);
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);
}
\f
static uint32_t
}
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 (hdrs->type == OFPT10_STATS_REQUEST ||
- hdrs->type == OFPT10_STATS_REPLY);
+ return type == OFPT10_STATS_REQUEST;
case OFP11_VERSION:
case OFP12_VERSION:
case OFP13_VERSION:
- return (hdrs->type == OFPT11_STATS_REQUEST ||
- hdrs->type == OFPT11_STATS_REPLY);
+ 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 type == OFPT10_STATS_REPLY;
+ case OFP11_VERSION:
+ case OFP12_VERSION:
+ case OFP13_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)
{
return ofpraw_pull(raw, &msg);
}
+/* Does the same job as ofpraw_decode(), except that it assert-fails if
+ * ofpraw_decode() would have reported an error. Thus, it's able to use the
+ * return value for the OFPRAW_* message type instead of an error code.
+ *
+ * (It only makes sense to use this function if you previously called
+ * ofpraw_decode() on the message and thus know that it's OK.) */
+enum ofpraw
+ofpraw_decode_assert(const struct ofp_header *oh)
+{
+ enum ofperr error;
+ enum ofpraw raw;
+
+ error = ofpraw_decode(&raw, oh);
+ ovs_assert(!error);
+ return raw;
+}
+
/* Determines the OFPRAW_* type of the OpenFlow message in 'msg', which starts
* at 'msg->data' and has length 'msg->size' bytes. On success, returns 0 and
* stores the type into '*rawp'. On failure, returns an OFPERR_* error code
}
/* Does the same job as ofpraw_pull(), except that it assert-fails if
- * ofpbuf_pull() would have reported an error. Thus, it's able to use the
+ * ofpraw_pull() would have reported an error. Thus, it's able to use the
* return value for the OFPRAW_* message type instead of an error code.
*
* (It only makes sense to use this function if you previously called
- * ofpbuf_decode() on the message and thus know that it's OK.) */
+ * ofpraw_decode() on the message and thus know that it's OK.) */
enum ofpraw
ofpraw_pull_assert(struct ofpbuf *msg)
{
nsm->subtype = htonl(hdrs->subtype);
memset(nsm->pad, 0, sizeof nsm->pad);
} else {
- NOT_REACHED();
+ OVS_NOT_REACHED();
}
}
} else if (version != OFP10_VERSION
nsm->subtype = htonl(hdrs->subtype);
} else {
- NOT_REACHED();
+ OVS_NOT_REACHED();
}
}
}
hdrs.type = OFPT11_STATS_REPLY;
break;
default:
- NOT_REACHED();
+ OVS_NOT_REACHED();
}
error = ofpraw_from_ofphdrs(&reply_raw, &hdrs);
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);
+}
\f
static ovs_be16 *ofpmp_flags__(const struct ofp_header *);
next = ofpbuf_new(MAX(1024, hdrs_len + len));
ofpbuf_put(next, msg->data, hdrs_len);
+ next->l2 = next->data;
+ next->l3 = ofpbuf_tail(next);
list_push_back(replies, &next->list_node);
*ofpmp_flags__(msg->data) |= htons(OFPSF_REPLY_MORE);
case OFP13_VERSION:
return &((struct ofp11_stats_msg *) oh)->flags;
default:
- NOT_REACHED();
+ OVS_NOT_REACHED();
}
}
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;
}
ofphdrs_hash(&inst->hdrs));
}
}
+
+ ovsthread_once_done(&once);
}