{ OFPUTIL_NXT_FLOW_REMOVED,
NXT_FLOW_REMOVED, "NXT_FLOW_REMOVED",
sizeof(struct nx_flow_removed), 8 },
+
+ { OFPUTIL_NXT_FLOW_MOD_TABLE_ID,
+ NXT_FLOW_MOD_TABLE_ID, "NXT_FLOW_MOD_TABLE_ID",
+ sizeof(struct nxt_flow_mod_table_id), 0 },
};
static const struct ofputil_msg_category nxt_category = {
}
nh = (const struct nicira_header *) oh;
-
- if (nh->subtype == htonl(NXT_FLOW_MOD_TABLE_ID)
- && oh->length == htons(sizeof(struct nxt_flow_mod_table_id))) {
- /* NXT_SET_FLOW_FORMAT and NXT_FLOW_MOD_TABLE_ID accidentally have the
- * same value but different lengths. ofputil_lookup_openflow_message()
- * doesn't support this case, so special case it here. */
- static const struct ofputil_msg_type nxt_flow_mod_table_id =
- { OFPUTIL_NXT_FLOW_MOD_TABLE_ID,
- NXT_FLOW_MOD_TABLE_ID, "NXT_FLOW_MOD_TABLE_ID",
- sizeof(struct nxt_flow_mod_table_id), 0 };
-
- *typep = &nxt_flow_mod_table_id;
- return 0;
- }
-
return ofputil_lookup_openflow_message(&nxt_category, ntohl(nh->subtype),
ntohs(oh->length), typep);
}
static int
check_nxstats_msg(const struct ofp_header *oh)
{
- const struct ofp_stats_request *osr;
+ const struct ofp_stats_msg *osm = (const struct ofp_stats_msg *) oh;
ovs_be32 vendor;
- osr = (const struct ofp_stats_request *) oh;
-
- memcpy(&vendor, osr->body, sizeof vendor);
+ memcpy(&vendor, osm + 1, sizeof vendor);
if (vendor != htonl(NX_VENDOR_ID)) {
VLOG_WARN_RL(&bad_ofmsg_rl, "received vendor stats message for "
"unknown vendor %"PRIx32, ntohl(vendor));
return ofp_mkerr(OFPET_BAD_REQUEST, OFPBRC_BAD_VENDOR);
}
- if (ntohs(osr->header.length) < sizeof(struct nicira_stats_msg)) {
+ if (ntohs(osm->header.length) < sizeof(struct nicira_stats_msg)) {
VLOG_WARN_RL(&bad_ofmsg_rl, "truncated Nicira stats message");
return ofp_mkerr(OFPET_BAD_REQUEST, OFPBRC_BAD_LEN);
}
ofputil_decode_ofpst_request(const struct ofp_header *oh,
const struct ofputil_msg_type **typep)
{
- enum { OSR_SIZE = sizeof(struct ofp_stats_request) };
static const struct ofputil_msg_type ofpst_requests[] = {
{ OFPUTIL_OFPST_DESC_REQUEST,
OFPST_DESC, "OFPST_DESC request",
- OSR_SIZE, 0 },
+ sizeof(struct ofp_stats_msg), 0 },
{ OFPUTIL_OFPST_FLOW_REQUEST,
OFPST_FLOW, "OFPST_FLOW request",
- OSR_SIZE + sizeof(struct ofp_flow_stats_request), 0 },
+ sizeof(struct ofp_flow_stats_request), 0 },
{ OFPUTIL_OFPST_AGGREGATE_REQUEST,
OFPST_AGGREGATE, "OFPST_AGGREGATE request",
- OSR_SIZE + sizeof(struct ofp_aggregate_stats_request), 0 },
+ sizeof(struct ofp_flow_stats_request), 0 },
{ OFPUTIL_OFPST_TABLE_REQUEST,
OFPST_TABLE, "OFPST_TABLE request",
- OSR_SIZE, 0 },
+ sizeof(struct ofp_stats_msg), 0 },
{ OFPUTIL_OFPST_PORT_REQUEST,
OFPST_PORT, "OFPST_PORT request",
- OSR_SIZE + sizeof(struct ofp_port_stats_request), 0 },
+ sizeof(struct ofp_port_stats_request), 0 },
{ OFPUTIL_OFPST_QUEUE_REQUEST,
OFPST_QUEUE, "OFPST_QUEUE request",
- OSR_SIZE + sizeof(struct ofp_queue_stats_request), 0 },
+ sizeof(struct ofp_queue_stats_request), 0 },
{ 0,
OFPST_VENDOR, "OFPST_VENDOR request",
- OSR_SIZE + sizeof(uint32_t), 1 },
+ sizeof(struct ofp_vendor_stats_msg), 1 },
};
static const struct ofputil_msg_category ofpst_request_category = {
OFP_MKERR(OFPET_BAD_REQUEST, OFPBRC_BAD_STAT)
};
- const struct ofp_stats_request *osr;
+ const struct ofp_stats_msg *request = (const struct ofp_stats_msg *) oh;
int error;
- osr = (const struct ofp_stats_request *) oh;
error = ofputil_lookup_openflow_message(&ofpst_request_category,
- ntohs(osr->type),
+ ntohs(request->type),
ntohs(oh->length), typep);
- if (!error && osr->type == htons(OFPST_VENDOR)) {
+ if (!error && request->type == htons(OFPST_VENDOR)) {
error = ofputil_decode_nxst_request(oh, typep);
}
return error;
ofputil_decode_ofpst_reply(const struct ofp_header *oh,
const struct ofputil_msg_type **typep)
{
- enum { OSR_SIZE = sizeof(struct ofp_stats_reply) };
static const struct ofputil_msg_type ofpst_replies[] = {
{ OFPUTIL_OFPST_DESC_REPLY,
OFPST_DESC, "OFPST_DESC reply",
- OSR_SIZE + sizeof(struct ofp_desc_stats), 0 },
+ sizeof(struct ofp_desc_stats), 0 },
{ OFPUTIL_OFPST_FLOW_REPLY,
OFPST_FLOW, "OFPST_FLOW reply",
- OSR_SIZE, 1 },
+ sizeof(struct ofp_stats_msg), 1 },
{ OFPUTIL_OFPST_AGGREGATE_REPLY,
OFPST_AGGREGATE, "OFPST_AGGREGATE reply",
- OSR_SIZE + sizeof(struct ofp_aggregate_stats_reply), 0 },
+ sizeof(struct ofp_aggregate_stats_reply), 0 },
{ OFPUTIL_OFPST_TABLE_REPLY,
OFPST_TABLE, "OFPST_TABLE reply",
- OSR_SIZE, sizeof(struct ofp_table_stats) },
+ sizeof(struct ofp_stats_msg), sizeof(struct ofp_table_stats) },
{ OFPUTIL_OFPST_PORT_REPLY,
OFPST_PORT, "OFPST_PORT reply",
- OSR_SIZE, sizeof(struct ofp_port_stats) },
+ sizeof(struct ofp_stats_msg), sizeof(struct ofp_port_stats) },
{ OFPUTIL_OFPST_QUEUE_REPLY,
OFPST_QUEUE, "OFPST_QUEUE reply",
- OSR_SIZE, sizeof(struct ofp_queue_stats) },
+ sizeof(struct ofp_stats_msg), sizeof(struct ofp_queue_stats) },
{ 0,
OFPST_VENDOR, "OFPST_VENDOR reply",
- OSR_SIZE + sizeof(uint32_t), 1 },
+ sizeof(struct ofp_vendor_stats_msg), 1 },
};
static const struct ofputil_msg_category ofpst_reply_category = {
OFP_MKERR(OFPET_BAD_REQUEST, OFPBRC_BAD_STAT)
};
- const struct ofp_stats_reply *osr = (const struct ofp_stats_reply *) oh;
+ const struct ofp_stats_msg *reply = (const struct ofp_stats_msg *) oh;
int error;
error = ofputil_lookup_openflow_message(&ofpst_reply_category,
- ntohs(osr->type),
+ ntohs(reply->type),
ntohs(oh->length), typep);
- if (!error && osr->type == htons(OFPST_VENDOR)) {
+ if (!error && reply->type == htons(OFPST_VENDOR)) {
error = ofputil_decode_nxst_reply(oh, typep);
}
return error;
{ 0,
OFPT_STATS_REQUEST, "OFPT_STATS_REQUEST",
- sizeof(struct ofp_stats_request), 1 },
+ sizeof(struct ofp_stats_msg), 1 },
{ 0,
OFPT_STATS_REPLY, "OFPT_STATS_REPLY",
- sizeof(struct ofp_stats_reply), 1 },
+ sizeof(struct ofp_stats_msg), 1 },
{ OFPUTIL_OFPT_BARRIER_REQUEST,
OFPT_BARRIER_REQUEST, "OFPT_BARRIER_REQUEST",
const struct ofp_header *oh,
bool aggregate)
{
- const struct ofp_flow_stats_request *ofsr = ofputil_stats_body(oh);
+ const struct ofp_flow_stats_request *ofsr =
+ (const struct ofp_flow_stats_request *) oh;
fsr->aggregate = aggregate;
ofputil_cls_rule_from_match(&ofsr->match, 0, &fsr->match);
struct ofp_flow_stats_request *ofsr;
int type;
- BUILD_ASSERT_DECL(sizeof(struct ofp_flow_stats_request)
- == sizeof(struct ofp_aggregate_stats_request));
-
type = fsr->aggregate ? OFPST_AGGREGATE : OFPST_FLOW;
- ofsr = ofputil_make_stats_request(sizeof *ofsr, type, &msg);
+ ofsr = ofputil_make_stats_request(sizeof *ofsr, type, 0, &msg);
ofputil_cls_rule_to_match(&fsr->match, &ofsr->match);
ofsr->table_id = fsr->table_id;
ofsr->out_port = htons(fsr->out_port);
int subtype;
subtype = fsr->aggregate ? NXST_AGGREGATE : NXST_FLOW;
- ofputil_make_nxstats_request(sizeof *nfsr, subtype, &msg);
+ ofputil_make_stats_request(sizeof *nfsr, OFPST_VENDOR, subtype, &msg);
match_len = nx_put_match(msg, &fsr->match);
nfsr = msg->data;
if (!msg->l2) {
msg->l2 = msg->data;
if (code == OFPUTIL_OFPST_FLOW_REPLY) {
- ofpbuf_pull(msg, sizeof(struct ofp_stats_reply));
+ ofpbuf_pull(msg, sizeof(struct ofp_stats_msg));
} else if (code == OFPUTIL_NXST_FLOW_REPLY) {
ofpbuf_pull(msg, sizeof(struct nicira_stats_msg));
} else {
oh->length = htons(buffer->size);
}
-/* Creates an ofp_stats_request with the given 'type' and 'body_len' bytes of
- * space allocated for the 'body' member. Returns the first byte of the 'body'
- * member. */
+static void
+put_stats__(ovs_be32 xid, uint8_t ofp_type,
+ ovs_be16 ofpst_type, ovs_be32 nxst_subtype,
+ struct ofpbuf *msg)
+{
+ if (ofpst_type == htons(OFPST_VENDOR)) {
+ struct nicira_stats_msg *nsm;
+
+ nsm = put_openflow_xid(sizeof *nsm, ofp_type, xid, msg);
+ nsm->vsm.osm.type = ofpst_type;
+ nsm->vsm.vendor = htonl(NX_VENDOR_ID);
+ nsm->subtype = nxst_subtype;
+ } else {
+ struct ofp_stats_msg *osm;
+
+ osm = put_openflow_xid(sizeof *osm, ofp_type, xid, msg);
+ osm->type = ofpst_type;
+ }
+}
+
+/* Creates a statistics request message with total length 'openflow_len'
+ * (including all headers) and the given 'ofpst_type', and stores the buffer
+ * containing the new message in '*bufferp'. If 'ofpst_type' is OFPST_VENDOR
+ * then 'nxst_subtype' is used as the Nicira vendor extension statistics
+ * subtype (otherwise 'nxst_subtype' is ignored).
+ *
+ * Initializes bytes following the headers to all-bits-zero.
+ *
+ * Returns the first byte of the new message. */
void *
-ofputil_make_stats_request(size_t body_len, uint16_t type,
- struct ofpbuf **bufferp)
+ofputil_make_stats_request(size_t openflow_len, uint16_t ofpst_type,
+ uint32_t nxst_subtype, struct ofpbuf **bufferp)
{
- struct ofp_stats_request *osr;
- osr = make_openflow((offsetof(struct ofp_stats_request, body)
- + body_len), OFPT_STATS_REQUEST, bufferp);
- osr->type = htons(type);
- osr->flags = htons(0);
- return osr->body;
+ struct ofpbuf *msg;
+
+ msg = *bufferp = ofpbuf_new(openflow_len);
+ put_stats__(alloc_xid(), OFPT_STATS_REQUEST,
+ htons(ofpst_type), htonl(nxst_subtype), msg);
+ ofpbuf_padto(msg, openflow_len);
+
+ return msg->data;
}
-/* Creates a stats request message with Nicira as vendor and the given
- * 'subtype', of total length 'openflow_len'. Returns the message. */
+static void
+put_stats_reply__(const struct ofp_stats_msg *request, struct ofpbuf *msg)
+{
+ assert(request->header.type == OFPT_STATS_REQUEST ||
+ request->header.type == OFPT_STATS_REPLY);
+ put_stats__(request->header.xid, OFPT_STATS_REPLY, request->type,
+ (request->type != htons(OFPST_VENDOR)
+ ? htonl(0)
+ : ((const struct nicira_stats_msg *) request)->subtype),
+ msg);
+}
+
+/* Creates a statistics reply message with total length 'openflow_len'
+ * (including all headers) and the same type (either a standard OpenFlow
+ * statistics type or a Nicira extension type and subtype) as 'request', and
+ * stores the buffer containing the new message in '*bufferp'.
+ *
+ * Initializes bytes following the headers to all-bits-zero.
+ *
+ * Returns the first byte of the new message. */
void *
-ofputil_make_nxstats_request(size_t openflow_len, uint32_t subtype,
- struct ofpbuf **bufferp)
+ofputil_make_stats_reply(size_t openflow_len,
+ const struct ofp_stats_msg *request,
+ struct ofpbuf **bufferp)
+{
+ struct ofpbuf *msg;
+
+ msg = *bufferp = ofpbuf_new(openflow_len);
+ put_stats_reply__(request, msg);
+ ofpbuf_padto(msg, openflow_len);
+
+ return msg->data;
+}
+
+/* Initializes 'replies' as a list of ofpbufs that will contain a series of
+ * replies to 'request', which should be an OpenFlow or Nicira extension
+ * statistics request. Initially 'replies' will have a single reply message
+ * that has only a header. The functions ofputil_reserve_stats_reply() and
+ * ofputil_append_stats_reply() may be used to add to the reply. */
+void
+ofputil_start_stats_reply(const struct ofp_stats_msg *request,
+ struct list *replies)
{
- struct nicira_stats_msg *nsm;
+ struct ofpbuf *msg;
+
+ msg = ofpbuf_new(1024);
+ put_stats_reply__(request, msg);
+
+ list_init(replies);
+ list_push_back(replies, &msg->list_node);
+}
- nsm = make_openflow(openflow_len, OFPT_STATS_REQUEST, bufferp);
- nsm->type = htons(OFPST_VENDOR);
- nsm->flags = htons(0);
- nsm->vendor = htonl(NX_VENDOR_ID);
- nsm->subtype = htonl(subtype);
- return nsm;
+/* Prepares to append up to 'len' bytes to the series of statistics replies in
+ * 'replies', which should have been initialized with
+ * ofputil_start_stats_reply(). Returns an ofpbuf with at least 'len' bytes of
+ * tailroom. (The 'len' bytes have not actually be allocated; the caller must
+ * do so with e.g. ofpbuf_put_uninit().) */
+struct ofpbuf *
+ofputil_reserve_stats_reply(size_t len, struct list *replies)
+{
+ struct ofpbuf *msg = ofpbuf_from_list(list_back(replies));
+ struct ofp_stats_msg *osm = msg->data;
+
+ if (msg->size + len <= UINT16_MAX) {
+ ofpbuf_prealloc_tailroom(msg, len);
+ } else {
+ osm->flags |= htons(OFPSF_REPLY_MORE);
+
+ msg = ofpbuf_new(MAX(1024, sizeof(struct nicira_stats_msg) + len));
+ put_stats_reply__(osm, msg);
+ list_push_back(replies, &msg->list_node);
+ }
+ return msg;
+}
+
+/* Appends 'len' bytes to the series of statistics replies in 'replies', and
+ * returns the first byte. */
+void *
+ofputil_append_stats_reply(size_t len, struct list *replies)
+{
+ return ofpbuf_put_uninit(ofputil_reserve_stats_reply(len, replies), len);
}
-/* Returns the first byte of the 'body' member of the ofp_stats_request or
- * ofp_stats_reply in 'oh'. */
+/* Returns the first byte past the ofp_stats_msg header in 'oh'. */
const void *
ofputil_stats_body(const struct ofp_header *oh)
{
assert(oh->type == OFPT_STATS_REQUEST || oh->type == OFPT_STATS_REPLY);
- return ((const struct ofp_stats_request *) oh)->body;
+ return (const struct ofp_stats_msg *) oh + 1;
}
-/* Returns the length of the 'body' member of the ofp_stats_request or
- * ofp_stats_reply in 'oh'. */
+/* Returns the number of bytes past the ofp_stats_msg header in 'oh'. */
size_t
ofputil_stats_body_len(const struct ofp_header *oh)
{
assert(oh->type == OFPT_STATS_REQUEST || oh->type == OFPT_STATS_REPLY);
- return ntohs(oh->length) - sizeof(struct ofp_stats_request);
+ return ntohs(oh->length) - sizeof(struct ofp_stats_msg);
}
-/* Returns the first byte of the body of the nicira_stats_msg in 'oh'. */
+/* Returns the first byte past the nicira_stats_msg header in 'oh'. */
const void *
ofputil_nxstats_body(const struct ofp_header *oh)
{
return ((const struct nicira_stats_msg *) oh) + 1;
}
-/* Returns the length of the body of the nicira_stats_msg in 'oh'. */
+/* Returns the number of bytes past the nicira_stats_msg header in 'oh'. */
size_t
ofputil_nxstats_body_len(const struct ofp_header *oh)
{
switch ((enum nx_action_subtype) subtype) {
case NXAST_RESUBMIT:
case NXAST_SET_TUNNEL:
- case NXAST_DROP_SPOOFED_ARP:
case NXAST_SET_QUEUE:
case NXAST_POP_QUEUE:
return check_nx_action_exact_len(nah, len, 16);
return autopath_check((const struct nx_action_autopath *) a);
case NXAST_SNAT__OBSOLETE:
+ case NXAST_DROP_SPOOFED_ARP__OBSOLETE:
default:
VLOG_WARN_RL(&bad_ofmsg_rl,
"unknown Nicira vendor action subtype %d", subtype);