[ovs-dev] [PATCH 04/41] ofp-util: Allow decoding of Open Flow 1.2 Packet In Messages

Simon Horman horms at verge.net.au
Tue Aug 7 21:49:39 UTC 2012


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

---

v10
* No change

v9
* No change

v8
* Manual rebase
* Add ofp-print test

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

v6
* No change

v5
* Manual rebase

v4
* No change

v3
* Add OF1.2 entry to to ofputil_msg_types
* Make OF1.2 the first option in the if statement in ofputil_decode_packet_in()
* Rename o11pi as opi, which is consistent with the style used elsewhere
* Rebase

v2
* No change
---
 lib/ofp-util.c     | 61 ++++++++++++++++++++++++++++++++++++++++--------------
 tests/ofp-print.at | 16 +++++++++++++-
 2 files changed, 61 insertions(+), 16 deletions(-)

diff --git a/lib/ofp-util.c b/lib/ofp-util.c
index 6b67e89..f305952 100644
--- a/lib/ofp-util.c
+++ b/lib/ofp-util.c
@@ -1911,6 +1911,27 @@ ofputil_encode_flow_removed(const struct ofputil_flow_removed *fr,
     return msg;
 }
 
+static void
+ofputil_decode_packet_in_finish(struct ofputil_packet_in *pin,
+                                struct cls_rule *rule,
+                                struct ofpbuf *b)
+{
+    pin->packet = b->data;
+    pin->packet_len = b->size;
+
+    pin->fmd.in_port = rule->flow.in_port;
+
+    pin->fmd.tun_id = rule->flow.tun_id;
+    pin->fmd.tun_id_mask = rule->wc.tun_id_mask;
+
+    pin->fmd.metadata = rule->flow.metadata;
+    pin->fmd.metadata_mask = rule->wc.metadata_mask;
+
+    memcpy(pin->fmd.regs, rule->flow.regs, sizeof pin->fmd.regs);
+    memcpy(pin->fmd.reg_masks, rule->wc.reg_masks,
+           sizeof pin->fmd.reg_masks);
+}
+
 enum ofperr
 ofputil_decode_packet_in(struct ofputil_packet_in *pin,
                          const struct ofp_header *oh)
@@ -1922,7 +1943,29 @@ ofputil_decode_packet_in(struct ofputil_packet_in *pin,
 
     ofpbuf_use_const(&b, oh, ntohs(oh->length));
     raw = ofpraw_pull_assert(&b);
-    if (raw == OFPRAW_OFPT10_PACKET_IN) {
+    if (raw == OFPRAW_OFPT12_PACKET_IN) {
+        const struct ofp12_packet_in *opi;
+        struct cls_rule rule;
+        int error;
+
+        opi = ofpbuf_pull(&b, sizeof *opi);
+        error = oxm_pull_match_loose(&b, 0, &rule);
+        if (error) {
+            return error;
+        }
+
+        if (!ofpbuf_try_pull(&b, 2)) {
+            return OFPERR_OFPBRC_BAD_LEN;
+        }
+
+        pin->reason = opi->reason;
+        pin->table_id = opi->table_id;
+
+        pin->buffer_id = ntohl(opi->buffer_id);
+        pin->total_len = ntohs(opi->total_len);
+
+        ofputil_decode_packet_in_finish(pin, &rule, &b);
+    } else if (raw == OFPRAW_OFPT10_PACKET_IN) {
         const struct ofp_packet_in *opi;
 
         opi = ofpbuf_pull(&b, offsetof(struct ofp_packet_in, data));
@@ -1950,26 +1993,14 @@ ofputil_decode_packet_in(struct ofputil_packet_in *pin,
             return OFPERR_OFPBRC_BAD_LEN;
         }
 
-        pin->packet = b.data;
-        pin->packet_len = b.size;
         pin->reason = npi->reason;
         pin->table_id = npi->table_id;
         pin->cookie = npi->cookie;
 
-        pin->fmd.in_port = rule.flow.in_port;
-
-        pin->fmd.tun_id = rule.flow.tun_id;
-        pin->fmd.tun_id_mask = rule.wc.tun_id_mask;
-
-        pin->fmd.metadata = rule.flow.metadata;
-        pin->fmd.metadata_mask = rule.wc.metadata_mask;
-
-        memcpy(pin->fmd.regs, rule.flow.regs, sizeof pin->fmd.regs);
-        memcpy(pin->fmd.reg_masks, rule.wc.reg_masks,
-               sizeof pin->fmd.reg_masks);
-
         pin->buffer_id = ntohl(npi->buffer_id);
         pin->total_len = ntohs(npi->total_len);
+
+        ofputil_decode_packet_in_finish(pin, &rule, &b);
     } else {
         NOT_REACHED();
     }
diff --git a/tests/ofp-print.at b/tests/ofp-print.at
index 05e6cac..2c4e6c5 100644
--- a/tests/ofp-print.at
+++ b/tests/ofp-print.at
@@ -327,7 +327,7 @@ OFPT_GET_CONFIG_REPLY (xid=0x3): frags=reassemble miss_send_len=255
 ])
 AT_CLEANUP
 
-AT_SETUP([OFPT_PACKET_IN])
+AT_SETUP([OFPT_PACKET_IN - OF1.0])
 AT_KEYWORDS([ofp-print])
 AT_CHECK([ovs-ofctl ofp-print "\
 01 0a 00 4e 00 00 00 00 00 00 01 11 00 3c 00 03 \
@@ -341,6 +341,20 @@ priority:0,tunnel:0,metadata:0,in_port:0000,tci(0) mac(50:54:00:00:00:05->50:54:
 ])
 AT_CLEANUP
 
+AT_SETUP([OFPT_PACKET_IN - OF1.2])
+AT_KEYWORDS([ofp-print])
+AT_CHECK([ovs-ofctl ofp-print "\
+03 0a 00 4c 00 00 00 00 ff ff ff 00 00 2a 00 00 \
+00 01 00 0c 80 00 00 04 ff ff ff fe 00 00 00 00 \
+00 00 ff ff ff ff ff ff 00 23 20 83 c1 5f 80 35 \
+00 01 08 00 06 04 00 03 00 23 20 83 c1 5f 00 00 \
+00 00 00 23 20 83 c1 5f 00 00 00 00 \
+"], [0], [dnl
+OFPT_PACKET_IN (OF1.2) (xid=0x0): total_len=42 in_port=LOCAL (via no_match) data_len=42 buffer=0xffffff00
+priority:0,tunnel:0,metadata:0,in_port:0000,tci(0) mac(00:23:20:83:c1:5f->ff:ff:ff:ff:ff:ff) type:8035 proto:0 tos:0 ttl:0 ip(0.0.0.0->0.0.0.0)
+])
+AT_CLEANUP
+
 AT_SETUP([OFPT_FLOW_REMOVED])
 AT_KEYWORDS([ofp-print])
 AT_CHECK([ovs-ofctl ofp-print "\
-- 
1.7.10.2.484.gcd07cc5




More information about the dev mailing list