ofproto: Report correct errors for unsupported stats/multipart requests.
authorYAMAMOTO Takashi <yamamoto@valinux.co.jp>
Thu, 24 Oct 2013 03:07:43 +0000 (12:07 +0900)
committerBen Pfaff <blp@nicira.com>
Fri, 25 Oct 2013 03:54:37 +0000 (20:54 -0700)
The correct error in that case is OFPERR_OFPBRC_BAD_STAT,
not OFPERR_OFPBRC_BAD_TYPE.

Currently, the only example of unsupported stats/multipart request is
OFPTYPE_TABLE_FEATURES_STATS_REQUEST.

Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: Ben Pfaff <blp@nicira.com>
OPENFLOW-1.1+
lib/ofp-msgs.c
lib/ofp-msgs.h
ofproto/ofproto.c

index bd6ced6..47cb603 100644 (file)
@@ -116,9 +116,6 @@ following additional work.  (This is based on the change log at the
 end of the OF1.3 spec, reusing most of the section titles directly.  I
 didn't compare the specs carefully yet.)
 
-    * Send errors for unsupported multipart requests.
-      [required for OF1.3+]
-
     * Add support for multipart requests.
       [optional for OF1.3+]
 
index d136f73..9f1b453 100644 (file)
@@ -260,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)
 {
@@ -811,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);
+}
 \f
 static ovs_be16 *ofpmp_flags__(const struct ofp_header *);
 
index bfc84f3..aa19fe3 100644 (file)
@@ -584,6 +584,7 @@ enum ofptype ofptype_from_ofpraw(enum ofpraw);
 /* OpenFlow message properties. */
 void ofpmsg_update_length(struct ofpbuf *);
 const void *ofpmsg_body(const struct ofp_header *);
+bool ofpmsg_is_stat_request(const struct ofp_header *);
 \f
 /* Multipart messages (aka "statistics").
  *
index 402b38d..cb5bc73 100644 (file)
@@ -5790,7 +5790,7 @@ handle_openflow__(struct ofconn *ofconn, const struct ofpbuf *msg)
         /* FIXME: Change the following once they are implemented: */
     case OFPTYPE_QUEUE_GET_CONFIG_REQUEST:
     case OFPTYPE_TABLE_FEATURES_STATS_REQUEST:
-        return OFPERR_OFPBRC_BAD_TYPE;
+        /* fallthrough */
 
     case OFPTYPE_HELLO:
     case OFPTYPE_ERROR:
@@ -5821,7 +5821,11 @@ handle_openflow__(struct ofconn *ofconn, const struct ofpbuf *msg)
     case OFPTYPE_METER_FEATURES_STATS_REPLY:
     case OFPTYPE_TABLE_FEATURES_STATS_REPLY:
     default:
-        return OFPERR_OFPBRC_BAD_TYPE;
+        if (ofpmsg_is_stat_request(oh)) {
+            return OFPERR_OFPBRC_BAD_STAT;
+        } else {
+            return OFPERR_OFPBRC_BAD_TYPE;
+        }
     }
 }