[ovs-dev] [PATCH 17/24] ofp-util: Allow encoding of Open Flow 1.2 Packet In Messages

Simon Horman horms at verge.net.au
Mon Jul 23 06:16:46 UTC 2012


Signed-off-by: Simon Horman <horms at verge.net.au>

---

v7
* Manual Rebase
* Use struct ofp12_packet_in instead of struct ofp11_packet_in

v6
* No change

v5
* No change

v4
* No change

v3
* Add protocol parameter to ofputil_encode_packet_in().
  This allows packet_in_format to be ignored for Open Flow 1.2.

v2
* Update for new ofputil_put_match() implementation

Conflicts:
	lib/ofp-util.c
---
 lib/ofp-msgs.h    |  3 +++
 lib/ofp-util.c    | 58 +++++++++++++++++++++++++++++++++++++++++--------------
 lib/ofp-util.h    |  1 +
 ofproto/connmgr.c |  3 ++-
 4 files changed, 49 insertions(+), 16 deletions(-)

diff --git a/lib/ofp-msgs.h b/lib/ofp-msgs.h
index 5ff5976..1639cd9 100644
--- a/lib/ofp-msgs.h
+++ b/lib/ofp-msgs.h
@@ -127,6 +127,8 @@ enum ofpraw {
     OFPRAW_OFPT10_PACKET_IN,
     /* OFPT 1.1 (10): struct ofp11_packet_in up to data, uint8_t[]. */
     OFPRAW_OFPT11_PACKET_IN,
+    /* OFPT 1.2 (10): struct ofp12_packet_in, uint8_t[]. */
+    OFPRAW_OFPT12_PACKET_IN,
     /* NXT 1.0+ (17): struct nx_packet_in, uint8_t[]. */
     OFPRAW_NXT_PACKET_IN,
 
@@ -327,6 +329,7 @@ enum ofptype {
     /* Asynchronous messages. */
     OFPTYPE_PACKET_IN,           /* OFPRAW_OFPT10_PACKET_IN.
                                   * OFPRAW_OFPT11_PACKET_IN.
+                                  * OFPRAW_OFPT12_PACKET_IN.
                                   * OFPRAW_NXT_PACKET_IN. */
     OFPTYPE_FLOW_REMOVED,        /* OFPRAW_OFPT10_FLOW_REMOVED.
                                   * OFPRAW_NXT_FLOW_REMOVED. */
diff --git a/lib/ofp-util.c b/lib/ofp-util.c
index 695432f..5cf49c0 100644
--- a/lib/ofp-util.c
+++ b/lib/ofp-util.c
@@ -1999,17 +1999,58 @@ ofputil_decode_packet_in(struct ofputil_packet_in *pin,
     return 0;
 }
 
+static void
+ofputil_packet_in_to_rule(const struct ofputil_packet_in *pin,
+                          struct cls_rule *rule)
+{
+    int i;
+
+    cls_rule_init_catchall(rule, 0);
+    cls_rule_set_tun_id_masked(rule, pin->fmd.tun_id,
+                               pin->fmd.tun_id_mask);
+    cls_rule_set_metadata_masked(rule, pin->fmd.metadata,
+                                 pin->fmd.metadata_mask);
+
+    for (i = 0; i < FLOW_N_REGS; i++) {
+        cls_rule_set_reg_masked(rule, i, pin->fmd.regs[i],
+                                pin->fmd.reg_masks[i]);
+    }
+
+    cls_rule_set_in_port(rule, pin->fmd.in_port);
+}
+
 /* Converts abstract ofputil_packet_in 'pin' into a PACKET_IN message
  * in the format specified by 'packet_in_format'.  */
 struct ofpbuf *
 ofputil_encode_packet_in(const struct ofputil_packet_in *pin,
+                         enum ofputil_protocol protocol,
                          enum nx_packet_in_format packet_in_format)
 {
     size_t send_len = MIN(pin->send_len, pin->packet_len);
     struct ofpbuf *packet;
 
     /* Add OFPT_PACKET_IN. */
-    if (packet_in_format == NXPIF_OPENFLOW10) {
+    if (protocol == OFPUTIL_P_OF12) {
+        struct ofp12_packet_in *opi;
+        struct cls_rule rule;
+
+        ofputil_packet_in_to_rule(pin, &rule);
+
+        /* The final argument is just an estimate of the space required. */
+        packet = ofpraw_alloc_xid(OFPRAW_OFPT12_PACKET_IN, OFP12_VERSION,
+                                  htonl(0), (sizeof(struct flow_metadata) * 2
+                                             + 2 + send_len));
+        ofpbuf_put_zeros(packet, sizeof *opi);
+        oxm_put_match(packet, &rule, 0, 0);
+        ofpbuf_put_zeros(packet, 2);
+        ofpbuf_put(packet, pin->packet, send_len);
+
+        opi = packet->l3;
+        opi->buffer_id = htonl(pin->buffer_id);
+        opi->total_len = htons(pin->total_len);
+        opi->reason = pin->reason;
+        opi->table_id = pin->table_id;
+   } else if (packet_in_format == NXPIF_OPENFLOW10) {
         struct ofp_packet_in *opi;
 
         packet = ofpraw_alloc_xid(OFPRAW_OFPT10_PACKET_IN, OFP10_VERSION,
@@ -2025,21 +2066,8 @@ ofputil_encode_packet_in(const struct ofputil_packet_in *pin,
         struct nx_packet_in *npi;
         struct cls_rule rule;
         size_t match_len;
-        size_t i;
-
-        cls_rule_init_catchall(&rule, 0);
-        cls_rule_set_tun_id_masked(&rule, pin->fmd.tun_id,
-                                   pin->fmd.tun_id_mask);
-        cls_rule_set_metadata_masked(&rule, pin->fmd.metadata,
-                                   pin->fmd.metadata_mask);
-
-
-        for (i = 0; i < FLOW_N_REGS; i++) {
-            cls_rule_set_reg_masked(&rule, i, pin->fmd.regs[i],
-                                    pin->fmd.reg_masks[i]);
-        }
 
-        cls_rule_set_in_port(&rule, pin->fmd.in_port);
+        ofputil_packet_in_to_rule(pin, &rule);
 
         /* The final argument is just an estimate of the space required. */
         packet = ofpraw_alloc_xid(OFPRAW_NXT_PACKET_IN, OFP10_VERSION,
diff --git a/lib/ofp-util.h b/lib/ofp-util.h
index 0db04ca..4851c52 100644
--- a/lib/ofp-util.h
+++ b/lib/ofp-util.h
@@ -280,6 +280,7 @@ struct ofputil_packet_in {
 enum ofperr ofputil_decode_packet_in(struct ofputil_packet_in *,
                                      const struct ofp_header *);
 struct ofpbuf *ofputil_encode_packet_in(const struct ofputil_packet_in *,
+                                        enum ofputil_protocol protocol,
                                         enum nx_packet_in_format);
 
 const char *ofputil_packet_in_reason_to_string(enum ofp_packet_in_reason);
diff --git a/ofproto/connmgr.c b/ofproto/connmgr.c
index 5ce77c0..1f0b6b0 100644
--- a/ofproto/connmgr.c
+++ b/ofproto/connmgr.c
@@ -1407,7 +1407,8 @@ schedule_packet_in(struct ofconn *ofconn, struct ofputil_packet_in pin)
      * while (until a later call to pinsched_run()). */
     pinsched_send(ofconn->schedulers[pin.reason == OFPR_NO_MATCH ? 0 : 1],
                   pin.fmd.in_port,
-                  ofputil_encode_packet_in(&pin, ofconn->packet_in_format),
+                  ofputil_encode_packet_in(&pin, ofconn->protocol,
+                                           ofconn->packet_in_format),
                   do_send_packet_in, ofconn);
 }
 
-- 
1.7.10.2.484.gcd07cc5




More information about the dev mailing list