[ovs-dev] [of1.1 draft v2 6/7] Break OFPT_* constants into common value and 1.0- and 1.1-specific values.

Ben Pfaff blp at nicira.com
Fri Feb 3 20:43:54 UTC 2012


---
 include/openflow/openflow-1.0.h    |   41 ++++++++++-------------------------
 include/openflow/openflow-1.1.h    |   23 +++++++++++++++++++-
 include/openflow/openflow-common.h |   22 +++++++++++++++++++
 lib/ofp-print.c                    |   18 ++++++++--------
 lib/ofp-util.c                     |   40 +++++++++++++++++-----------------
 lib/vconn.c                        |    2 +-
 ofproto/ofproto.c                  |   11 ++++-----
 utilities/ovs-ofctl.c              |    5 ++-
 8 files changed, 94 insertions(+), 68 deletions(-)

diff --git a/include/openflow/openflow-1.0.h b/include/openflow/openflow-1.0.h
index 6fafd97..dee4e9c 100644
--- a/include/openflow/openflow-1.0.h
+++ b/include/openflow/openflow-1.0.h
@@ -43,42 +43,25 @@ enum ofp_port {
     OFPP_NONE       = 0xffff   /* Not associated with a physical port. */
 };
 
-enum ofp_type {
-    /* Immutable messages. */
-    OFPT_HELLO,               /* Symmetric message */
-    OFPT_ERROR,               /* Symmetric message */
-    OFPT_ECHO_REQUEST,        /* Symmetric message */
-    OFPT_ECHO_REPLY,          /* Symmetric message */
-    OFPT_VENDOR,              /* Symmetric message */
-
-    /* Switch configuration messages. */
-    OFPT_FEATURES_REQUEST,    /* Controller/switch message */
-    OFPT_FEATURES_REPLY,      /* Controller/switch message */
-    OFPT_GET_CONFIG_REQUEST,  /* Controller/switch message */
-    OFPT_GET_CONFIG_REPLY,    /* Controller/switch message */
-    OFPT_SET_CONFIG,          /* Controller/switch message */
-
-    /* Asynchronous messages. */
-    OFPT_PACKET_IN,           /* Async message */
-    OFPT_FLOW_REMOVED,        /* Async message */
-    OFPT_PORT_STATUS,         /* Async message */
-
+/* OpenFlow 1.0 specific message types, in addition to the common message
+ * types. */
+enum ofp10_type {
     /* Controller command messages. */
-    OFPT_PACKET_OUT,          /* Controller/switch message */
-    OFPT_FLOW_MOD,            /* Controller/switch message */
-    OFPT_PORT_MOD,            /* Controller/switch message */
+    OFPT10_PACKET_OUT = 13,     /* Controller/switch message */
+    OFPT10_FLOW_MOD,            /* Controller/switch message */
+    OFPT10_PORT_MOD,            /* Controller/switch message */
 
     /* Statistics messages. */
-    OFPT_STATS_REQUEST,       /* Controller/switch message */
-    OFPT_STATS_REPLY,         /* Controller/switch message */
+    OFPT10_STATS_REQUEST,       /* Controller/switch message */
+    OFPT10_STATS_REPLY,         /* Controller/switch message */
 
     /* Barrier messages. */
-    OFPT_BARRIER_REQUEST,     /* Controller/switch message */
-    OFPT_BARRIER_REPLY,       /* Controller/switch message */
+    OFPT10_BARRIER_REQUEST,     /* Controller/switch message */
+    OFPT10_BARRIER_REPLY,       /* Controller/switch message */
 
     /* Queue Configuration messages. */
-    OFPT_QUEUE_GET_CONFIG_REQUEST,  /* Controller/switch message */
-    OFPT_QUEUE_GET_CONFIG_REPLY     /* Controller/switch message */
+    OFPT10_QUEUE_GET_CONFIG_REQUEST,  /* Controller/switch message */
+    OFPT10_QUEUE_GET_CONFIG_REPLY     /* Controller/switch message */
 };
 
 /* Header on all OpenFlow packets. */
diff --git a/include/openflow/openflow-1.1.h b/include/openflow/openflow-1.1.h
index 8b407e3..859cf3a 100644
--- a/include/openflow/openflow-1.1.h
+++ b/include/openflow/openflow-1.1.h
@@ -54,6 +54,27 @@
 
 #include "openflow/openflow-common.h"
 
-/* Nothing here yet. */
+/* OpenFlow 1.1 specific message types, in addition to the common message
+ * types. */
+enum ofp11_type {
+    /* Controller command messages. */
+    OFPT11_PACKET_OUT = 13,     /* Controller/switch message */
+    OFPT11_FLOW_MOD,            /* Controller/switch message */
+    OFPT11_GROUP_MOD,           /* Controller/switch message */
+    OFPT11_PORT_MOD,            /* Controller/switch message */
+    OFPT11_TABLE_MOD,           /* Controller/switch message */
+
+    /* Statistics messages. */
+    OFPT11_STATS_REQUEST,       /* Controller/switch message */
+    OFPT11_STATS_REPLY,         /* Controller/switch message */
+
+    /* Barrier messages. */
+    OFPT11_BARRIER_REQUEST,     /* Controller/switch message */
+    OFPT11_BARRIER_REPLY,       /* Controller/switch message */
+
+    /* Queue Configuration messages. */
+    OFPT11_QUEUE_GET_CONFIG_REQUEST,  /* Controller/switch message */
+    OFPT11_QUEUE_GET_CONFIG_REPLY,    /* Controller/switch message */
+};
 
 #endif /* openflow/openflow-1.1.h */
diff --git a/include/openflow/openflow-common.h b/include/openflow/openflow-common.h
index 9163efd..d0f4b18 100644
--- a/include/openflow/openflow-common.h
+++ b/include/openflow/openflow-common.h
@@ -82,4 +82,26 @@
 
 #define OFP_ETH_ALEN 6          /* Bytes in an Ethernet address. */
 
+/* Common OpenFlow message types. */
+enum ofp_type {
+    /* Immutable messages. */
+    OFPT_HELLO,               /* Symmetric message */
+    OFPT_ERROR,               /* Symmetric message */
+    OFPT_ECHO_REQUEST,        /* Symmetric message */
+    OFPT_ECHO_REPLY,          /* Symmetric message */
+    OFPT_VENDOR,              /* Symmetric message */
+
+    /* Switch configuration messages. */
+    OFPT_FEATURES_REQUEST,    /* Controller/switch message */
+    OFPT_FEATURES_REPLY,      /* Controller/switch message */
+    OFPT_GET_CONFIG_REQUEST,  /* Controller/switch message */
+    OFPT_GET_CONFIG_REPLY,    /* Controller/switch message */
+    OFPT_SET_CONFIG,          /* Controller/switch message */
+
+    /* Asynchronous messages. */
+    OFPT_PACKET_IN,           /* Async message */
+    OFPT_FLOW_REMOVED,        /* Async message */
+    OFPT_PORT_STATUS,         /* Async message */
+};
+
 #endif /* openflow/openflow-common.h */
diff --git a/lib/ofp-print.c b/lib/ofp-print.c
index 058ac07..c5efc4b 100644
--- a/lib/ofp-print.c
+++ b/lib/ofp-print.c
@@ -1334,31 +1334,31 @@ ofp_message_type_to_string(uint8_t type)
     case OFPT_PORT_STATUS:
         name = "PORT_STATUS";
         break;
-    case OFPT_PACKET_OUT:
+    case OFPT10_PACKET_OUT:
         name = "PACKET_OUT";
         break;
-    case OFPT_FLOW_MOD:
+    case OFPT10_FLOW_MOD:
         name = "FLOW_MOD";
         break;
-    case OFPT_PORT_MOD:
+    case OFPT10_PORT_MOD:
         name = "PORT_MOD";
         break;
-    case OFPT_STATS_REQUEST:
+    case OFPT10_STATS_REQUEST:
         name = "STATS_REQUEST";
         break;
-    case OFPT_STATS_REPLY:
+    case OFPT10_STATS_REPLY:
         name = "STATS_REPLY";
         break;
-    case OFPT_BARRIER_REQUEST:
+    case OFPT10_BARRIER_REQUEST:
         name = "BARRIER_REQUEST";
         break;
-    case OFPT_BARRIER_REPLY:
+    case OFPT10_BARRIER_REPLY:
         name = "BARRIER_REPLY";
         break;
-    case OFPT_QUEUE_GET_CONFIG_REQUEST:
+    case OFPT10_QUEUE_GET_CONFIG_REQUEST:
         name = "QUEUE_GET_CONFIG_REQUEST";
         break;
-    case OFPT_QUEUE_GET_CONFIG_REPLY:
+    case OFPT10_QUEUE_GET_CONFIG_REPLY:
         name = "QUEUE_GET_CONFIG_REPLY";
         break;
     default:
diff --git a/lib/ofp-util.c b/lib/ofp-util.c
index a4d13cc..962f7a7 100644
--- a/lib/ofp-util.c
+++ b/lib/ofp-util.c
@@ -713,31 +713,31 @@ ofputil_decode_msg_type__(const struct ofp_header *oh, size_t length,
           sizeof(struct ofp_port_status), 0 },
 
         { OFPUTIL_OFPT_PACKET_OUT, OFP10_VERSION,
-          OFPT_PACKET_OUT, "OFPT_PACKET_OUT",
+          OFPT10_PACKET_OUT, "OFPT_PACKET_OUT",
           sizeof(struct ofp_packet_out), 1 },
 
         { OFPUTIL_OFPT_FLOW_MOD, OFP10_VERSION,
-          OFPT_FLOW_MOD, "OFPT_FLOW_MOD",
+          OFPT10_FLOW_MOD, "OFPT_FLOW_MOD",
           sizeof(struct ofp_flow_mod), 1 },
 
         { OFPUTIL_OFPT_PORT_MOD, OFP10_VERSION,
-          OFPT_PORT_MOD, "OFPT_PORT_MOD",
+          OFPT10_PORT_MOD, "OFPT_PORT_MOD",
           sizeof(struct ofp_port_mod), 0 },
 
         { 0, OFP10_VERSION,
-          OFPT_STATS_REQUEST, "OFPT_STATS_REQUEST",
+          OFPT10_STATS_REQUEST, "OFPT_STATS_REQUEST",
           sizeof(struct ofp_stats_msg), 1 },
 
         { 0, OFP10_VERSION,
-          OFPT_STATS_REPLY, "OFPT_STATS_REPLY",
+          OFPT10_STATS_REPLY, "OFPT_STATS_REPLY",
           sizeof(struct ofp_stats_msg), 1 },
 
         { OFPUTIL_OFPT_BARRIER_REQUEST, OFP10_VERSION,
-          OFPT_BARRIER_REQUEST, "OFPT_BARRIER_REQUEST",
+          OFPT10_BARRIER_REQUEST, "OFPT_BARRIER_REQUEST",
           sizeof(struct ofp_header), 0 },
 
         { OFPUTIL_OFPT_BARRIER_REPLY, OFP10_VERSION,
-          OFPT_BARRIER_REPLY, "OFPT_BARRIER_REPLY",
+          OFPT10_BARRIER_REPLY, "OFPT_BARRIER_REPLY",
           sizeof(struct ofp_header), 0 },
 
         { 0, 0,
@@ -761,11 +761,11 @@ ofputil_decode_msg_type__(const struct ofp_header *oh, size_t length,
             error = ofputil_decode_vendor(oh, length, typep);
             break;
 
-        case OFPT_STATS_REQUEST:
+        case OFPT10_STATS_REQUEST:
             error = ofputil_decode_ofpst_request(oh, length, typep);
             break;
 
-        case OFPT_STATS_REPLY:
+        case OFPT10_STATS_REPLY:
             error = ofputil_decode_ofpst_reply(oh, length, typep);
 
         default:
@@ -1384,7 +1384,7 @@ ofputil_encode_flow_mod(const struct ofputil_flow_mod *fm,
     case OFPUTIL_P_OF10:
     case OFPUTIL_P_OF10_TID:
         msg = ofpbuf_new(sizeof *ofm + fm->ofpacts_len);
-        ofm = put_openflow(sizeof *ofm, OFPT_FLOW_MOD, msg);
+        ofm = put_openflow(sizeof *ofm, OFPT10_FLOW_MOD, msg);
         ofputil_cls_rule_to_match(&fm->cr, &ofm->match);
         ofm->cookie = fm->cookie;
         ofm->command = htons(command);
@@ -2268,7 +2268,7 @@ ofputil_make_stats_request(size_t openflow_len, uint16_t ofpst_type,
     struct ofpbuf *msg;
 
     msg = *bufferp = ofpbuf_new(openflow_len);
-    put_stats__(alloc_xid(), OFPT_STATS_REQUEST,
+    put_stats__(alloc_xid(), OFPT10_STATS_REQUEST,
                 htons(ofpst_type), htonl(nxst_subtype), msg);
     ofpbuf_padto(msg, openflow_len);
 
@@ -2278,9 +2278,9 @@ ofputil_make_stats_request(size_t openflow_len, uint16_t ofpst_type,
 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,
+    assert(request->header.type == OFPT10_STATS_REQUEST ||
+           request->header.type == OFPT10_STATS_REPLY);
+    put_stats__(request->header.xid, OFPT10_STATS_REPLY, request->type,
                 (request->type != htons(OFPST_VENDOR)
                  ? htonl(0)
                  : ((const struct nicira_stats_msg *) request)->subtype),
@@ -2376,7 +2376,7 @@ ofputil_postappend_stats_reply(size_t start_ofs, struct list *replies)
 const void *
 ofputil_stats_body(const struct ofp_header *oh)
 {
-    assert(oh->type == OFPT_STATS_REQUEST || oh->type == OFPT_STATS_REPLY);
+    assert(oh->type == OFPT10_STATS_REQUEST || oh->type == OFPT10_STATS_REPLY);
     return (const struct ofp_stats_msg *) oh + 1;
 }
 
@@ -2384,7 +2384,7 @@ ofputil_stats_body(const struct ofp_header *oh)
 size_t
 ofputil_stats_body_len(const struct ofp_header *oh)
 {
-    assert(oh->type == OFPT_STATS_REQUEST || oh->type == OFPT_STATS_REPLY);
+    assert(oh->type == OFPT10_STATS_REQUEST || oh->type == OFPT10_STATS_REPLY);
     return ntohs(oh->length) - sizeof(struct ofp_stats_msg);
 }
 
@@ -2392,7 +2392,7 @@ ofputil_stats_body_len(const struct ofp_header *oh)
 const void *
 ofputil_nxstats_body(const struct ofp_header *oh)
 {
-    assert(oh->type == OFPT_STATS_REQUEST || oh->type == OFPT_STATS_REPLY);
+    assert(oh->type == OFPT10_STATS_REQUEST || oh->type == OFPT10_STATS_REPLY);
     return ((const struct nicira_stats_msg *) oh) + 1;
 }
 
@@ -2400,7 +2400,7 @@ ofputil_nxstats_body(const struct ofp_header *oh)
 size_t
 ofputil_nxstats_body_len(const struct ofp_header *oh)
 {
-    assert(oh->type == OFPT_STATS_REQUEST || oh->type == OFPT_STATS_REPLY);
+    assert(oh->type == OFPT10_STATS_REQUEST || oh->type == OFPT10_STATS_REPLY);
     return ntohs(oh->length) - sizeof(struct nicira_stats_msg);
 }
 
@@ -2413,7 +2413,7 @@ make_flow_mod(uint16_t command, const struct cls_rule *rule,
     struct ofpbuf *out = ofpbuf_new(size);
     ofm = ofpbuf_put_zeros(out, sizeof *ofm);
     ofm->header.version = OFP10_VERSION;
-    ofm->header.type = OFPT_FLOW_MOD;
+    ofm->header.type = OFPT10_FLOW_MOD;
     ofm->header.length = htons(size);
     ofm->cookie = 0;
     ofm->priority = htons(MIN(rule->priority, UINT16_MAX));
@@ -2494,7 +2494,7 @@ make_packet_out(const struct ofpbuf *packet, uint32_t buffer_id,
 
     opo = ofpbuf_put_uninit(out, sizeof *opo);
     opo->header.version = OFP10_VERSION;
-    opo->header.type = OFPT_PACKET_OUT;
+    opo->header.type = OFPT10_PACKET_OUT;
     opo->header.length = htons(size);
     opo->header.xid = htonl(0);
     opo->buffer_id = htonl(buffer_id);
diff --git a/lib/vconn.c b/lib/vconn.c
index 31de44b..d89304e 100644
--- a/lib/vconn.c
+++ b/lib/vconn.c
@@ -741,7 +741,7 @@ vconn_transact_noreply(struct vconn *vconn, struct ofpbuf *request,
     }
 
     /* Send barrier. */
-    make_openflow(sizeof(struct ofp_header), OFPT_BARRIER_REQUEST, &barrier);
+    make_openflow(sizeof(struct ofp_header), OFPT10_BARRIER_REQUEST, &barrier);
     barrier_xid = ((struct ofp_header *) barrier->data)->xid;
     error = vconn_send_block(vconn, barrier);
     if (error) {
diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
index 3b7eac1..ca4a688 100644
--- a/ofproto/ofproto.c
+++ b/ofproto/ofproto.c
@@ -3134,7 +3134,7 @@ handle_barrier_request(struct ofconn *ofconn, const struct ofp_header *oh)
         return OFPROTO_POSTPONE;
     }
 
-    ob = make_openflow_xid(sizeof *ob, OFPT_BARRIER_REPLY, oh->xid, &buf);
+    ob = make_openflow_xid(sizeof *ob, OFPT10_BARRIER_REPLY, oh->xid, &buf);
     ofconn_send_reply(ofconn, buf);
     return 0;
 }
@@ -3241,11 +3241,10 @@ handle_openflow__(struct ofconn *ofconn, const struct ofpbuf *msg)
     case OFPUTIL_NXST_FLOW_REPLY:
     case OFPUTIL_NXST_AGGREGATE_REPLY:
     default:
-        if (oh->type == OFPT_STATS_REQUEST || oh->type == OFPT_STATS_REPLY) {
-            return OFPERR_OFPBRC_BAD_STAT;
-        } else {
-            return OFPERR_OFPBRC_BAD_TYPE;
-        }
+        return (oh->type == OFPT10_STATS_REQUEST ||
+                oh->type == OFPT10_STATS_REPLY
+                ? OFPERR_OFPBRC_BAD_STAT
+                : OFPERR_OFPBRC_BAD_TYPE);
     }
 }
 
diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c
index 6f41850..512f02f 100644
--- a/utilities/ovs-ofctl.c
+++ b/utilities/ovs-ofctl.c
@@ -326,7 +326,7 @@ alloc_stats_request(size_t rq_len, uint16_t type, struct ofpbuf **bufferp)
 {
     struct ofp_stats_msg *rq;
 
-    rq = make_openflow(rq_len, OFPT_STATS_REQUEST, bufferp);
+    rq = make_openflow(rq_len, OFPT10_STATS_REQUEST, bufferp);
     rq->type = htons(type);
     rq->flags = htons(0);
     return rq;
@@ -1000,7 +1000,8 @@ do_mod_port(int argc OVS_UNUSED, char *argv[])
 
     fetch_ofp_phy_port(argv[1], argv[2], &opp);
 
-    opm = make_openflow(sizeof(struct ofp_port_mod), OFPT_PORT_MOD, &request);
+    opm = make_openflow(sizeof(struct ofp_port_mod), OFPT10_PORT_MOD,
+                        &request);
     opm->port_no = opp.port_no;
     memcpy(opm->hw_addr, opp.hw_addr, sizeof opm->hw_addr);
     opm->config = htonl(0);
-- 
1.7.2.5




More information about the dev mailing list