From 95f61ba8829a545d5e3edfb5b4d6e7341bd58f0f Mon Sep 17 00:00:00 2001 From: Simon Horman Date: Mon, 23 Jul 2012 11:36:43 +0900 Subject: [PATCH] OXM: Add encoding of VLAN VID and VLAN PCP Signed-off-by: Simon Horman Signed-off-by: Ben Pfaff --- 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 0f676926..893566da 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 08026ec8..af364868 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 -- 2.30.2