[ovs-dev] [oxm vlan 4/7] OXM: Add encoding of VLAN VID and VLAN PCP
Ben Pfaff
blp at nicira.com
Mon Jul 23 06:48:56 UTC 2012
From: Simon Horman <horms at verge.net.au>
Signed-off-by: Simon Horman <horms at verge.net.au>
Signed-off-by: Ben Pfaff <blp at nicira.com>
---
lib/nx-match.c | 22 ++++++++++++++++++----
tests/ovs-ofctl.at | 16 ++++++++++++++++
2 files changed, 34 insertions(+), 4 deletions(-)
diff --git a/lib/nx-match.c b/lib/nx-match.c
index 0f67692..893566d 100644
--- a/lib/nx-match.c
+++ b/lib/nx-match.c
@@ -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)) {
diff --git a/tests/ovs-ofctl.at b/tests/ovs-ofctl.at
index 08026ec..af36486 100644
--- a/tests/ovs-ofctl.at
+++ b/tests/ovs-ofctl.at
@@ -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
--
1.7.2.5
More information about the dev
mailing list