OXM: Add encoding of VLAN VID and VLAN PCP
authorSimon Horman <horms@verge.net.au>
Mon, 23 Jul 2012 02:36:43 +0000 (11:36 +0900)
committerBen Pfaff <blp@nicira.com>
Mon, 23 Jul 2012 16:21:40 +0000 (09:21 -0700)
Signed-off-by: Simon Horman <horms@verge.net.au>
Signed-off-by: Ben Pfaff <blp@nicira.com>
lib/nx-match.c
tests/ovs-ofctl.at

index 0f676926d96b0d76a985862b0875dc2eb175eb97..893566da4b0daf66e38e15e0908280e7ecce7924 100644 (file)
@@ -515,10 +515,24 @@ nx_put_match(struct ofpbuf *b, bool oxm, const struct cls_rule *cr,
                    ofputil_dl_type_to_openflow(flow->dl_type));
     }
 
-    /* 802.1Q.
-     *
-     * XXX missing OXM support */
-    nxm_put_16m(b, NXM_OF_VLAN_TCI, flow->vlan_tci, cr->wc.vlan_tci_mask);
+    /* 802.1Q. */
+    if (oxm) {
+        ovs_be16 vid = flow->vlan_tci & htons(VLAN_VID_MASK | VLAN_CFI);
+        ovs_be16 mask = cr->wc.vlan_tci_mask & htons(VLAN_VID_MASK | VLAN_CFI);
+
+        if (mask == htons(VLAN_VID_MASK | VLAN_CFI)) {
+            nxm_put_16(b, OXM_OF_VLAN_VID, vid);
+        } else if (mask) {
+            nxm_put_16m(b, OXM_OF_VLAN_VID, vid, mask);
+        }
+
+        if (vid && vlan_tci_to_pcp(cr->wc.vlan_tci_mask)) {
+            nxm_put_8(b, OXM_OF_VLAN_PCP, vlan_tci_to_pcp(flow->vlan_tci));
+        }
+
+    } else {
+        nxm_put_16m(b, NXM_OF_VLAN_TCI, flow->vlan_tci, cr->wc.vlan_tci_mask);
+    }
 
     /* L3. */
     if (!(wc & FWW_DL_TYPE) && flow->dl_type == htons(ETH_TYPE_IP)) {
index 08026ec8a2f66632c57fa120eb3dace9a64f2417..af364868b48c59556a55a9e3af327b38fd3350c0 100644 (file)
@@ -1308,6 +1308,14 @@ OXM_OF_ETH_SRC(020898456ddb)
 OXM_OF_ETH_TYPE(0800)
 OXM_OF_ETH_TYPE(0800) OXM_OF_IN_PORT(00000012)
 
+# vlan
+OXM_OF_VLAN_VID(1009) OXM_OF_VLAN_VID(1009) # Duplicate Field
+OXM_OF_VLAN_VID(f009)           # Bad Value
+OXM_OF_VLAN_VID(0000)           # Packets without 802.1Q header or with VID=0
+OXM_OF_VLAN_VID(1123)           # Packets with VID=123, any PCP
+OXM_OF_VLAN_VID(1123) OXM_OF_VLAN_PCP(01) # Packets with VID=123, PCP=1.
+OXM_OF_VLAN_VID(0123)           # Does not make sense (but supported anyway)
+
 # IP ECN
 OXM_OF_ETH_TYPE(0800) OXM_OF_IP_ECN(03)
 OXM_OF_ETH_TYPE(0800) OXM_OF_IP_ECN(06)
@@ -1483,6 +1491,14 @@ OXM_OF_ETH_SRC(020898456ddb)
 OXM_OF_ETH_TYPE(0800)
 OXM_OF_IN_PORT(00000012), OXM_OF_ETH_TYPE(0800)
 
+# vlan
+nx_pull_match() returned error OFPBMC_DUP_FIELD
+nx_pull_match() returned error OFPBMC_BAD_VALUE
+OXM_OF_VLAN_VID(0000)
+OXM_OF_VLAN_VID(1123)
+OXM_OF_VLAN_VID(1123), OXM_OF_VLAN_PCP(01)
+OXM_OF_VLAN_VID(0123)
+
 # IP ECN
 OXM_OF_ETH_TYPE(0800), OXM_OF_IP_ECN(03)
 nx_pull_match() returned error OFPBMC_BAD_VALUE