From 1e72c73685afe101f4d91dc97ccd84a2733152d6 Mon Sep 17 00:00:00 2001 From: Minoru TAKAHASHI Date: Tue, 7 Oct 2014 13:28:22 +0900 Subject: [PATCH] of12/3: support setting the oxm_value to OFPVID_NONE In openflow spec 1.2 and 1.3.4, in order to match only packets without a VLAN tag, the value of OFPXMT_OFB_VLAN_VID must be set to OFPVID_NONE (0x0000). Old API of ofproto_v1_2/3_parser is now enabled to setting the oxm_value to OFPVID_NONE(0x0000) as follows: e.g.) match = ofproto_v1_2_parser.OFPMatch() match.set_vlan_vid_none() Signed-off-by: Minoru TAKAHASHI Signed-off-by: FUJITA Tomonori --- ryu/ofproto/ofproto_v1_2_parser.py | 10 +++--- ryu/ofproto/ofproto_v1_3_parser.py | 10 +++--- ryu/tests/unit/ofproto/test_parser_v12.py | 37 +++++++++++++++++++++++ 3 files changed, 49 insertions(+), 8 deletions(-) diff --git a/ryu/ofproto/ofproto_v1_2_parser.py b/ryu/ofproto/ofproto_v1_2_parser.py index 0a490e41..39a5b0c8 100644 --- a/ryu/ofproto/ofproto_v1_2_parser.py +++ b/ryu/ofproto/ofproto_v1_2_parser.py @@ -3786,10 +3786,16 @@ class OFPMatch(StringifyMixin): self._wc.ft_set(ofproto.OFPXMT_OFB_ETH_TYPE) self._flow.dl_type = dl_type + def set_vlan_vid_none(self): + self._wc.ft_set(ofproto.OFPXMT_OFB_VLAN_VID) + self._wc.vlan_vid_mask = UINT16_MAX + self._flow.vlan_vid = ofproto.OFPVID_NONE + def set_vlan_vid(self, vid): self.set_vlan_vid_masked(vid, UINT16_MAX) def set_vlan_vid_masked(self, vid, mask): + vid |= ofproto.OFPVID_PRESENT self._wc.ft_set(ofproto.OFPXMT_OFB_VLAN_VID) self._wc.vlan_vid_mask = mask self._flow.vlan_vid = vid @@ -4142,10 +4148,6 @@ class MTVlanVid(OFPMatchField): m.value &= ~ofproto.OFPVID_PRESENT return m - def serialize(self, buf, offset): - self.value |= ofproto.OFPVID_PRESENT - super(MTVlanVid, self).serialize(buf, offset) - @OFPMatchField.register_field_header([ofproto.OXM_OF_VLAN_PCP]) class MTVlanPcp(OFPMatchField): diff --git a/ryu/ofproto/ofproto_v1_3_parser.py b/ryu/ofproto/ofproto_v1_3_parser.py index 87704093..53d235c3 100644 --- a/ryu/ofproto/ofproto_v1_3_parser.py +++ b/ryu/ofproto/ofproto_v1_3_parser.py @@ -1250,10 +1250,16 @@ class OFPMatch(StringifyMixin): self._wc.ft_set(ofproto.OFPXMT_OFB_ETH_TYPE) self._flow.dl_type = dl_type + def set_vlan_vid_none(self): + self._wc.ft_set(ofproto.OFPXMT_OFB_VLAN_VID) + self._wc.vlan_vid_mask = UINT16_MAX + self._flow.vlan_vid = ofproto.OFPVID_NONE + def set_vlan_vid(self, vid): self.set_vlan_vid_masked(vid, UINT16_MAX) def set_vlan_vid_masked(self, vid, mask): + vid |= ofproto.OFPVID_PRESENT self._wc.ft_set(ofproto.OFPXMT_OFB_VLAN_VID) self._wc.vlan_vid_mask = mask self._flow.vlan_vid = vid @@ -1638,10 +1644,6 @@ class MTVlanVid(OFPMatchField): m.value &= ~ofproto.OFPVID_PRESENT return m - def serialize(self, buf, offset): - self.value |= ofproto.OFPVID_PRESENT - super(MTVlanVid, self).serialize(buf, offset) - @OFPMatchField.register_field_header([ofproto.OXM_OF_VLAN_PCP]) class MTVlanPcp(OFPMatchField): diff --git a/ryu/tests/unit/ofproto/test_parser_v12.py b/ryu/tests/unit/ofproto/test_parser_v12.py index 1c288c8d..2560fbab 100644 --- a/ryu/tests/unit/ofproto/test_parser_v12.py +++ b/ryu/tests/unit/ofproto/test_parser_v12.py @@ -6853,6 +6853,40 @@ class TestOFPMatch(unittest.TestCase): match.set_vlan_vid_masked(vid, mask) self._test_serialize_and_parser(match, header, vid, mask) + def _test_set_vlan_vid_none(self): + header = ofproto.OXM_OF_VLAN_VID + match = OFPMatch() + match.set_vlan_vid_none() + value = ofproto.OFPVID_NONE + cls_ = OFPMatchField._FIELDS_HEADERS.get(header) + pack_str = cls_.pack_str.replace('!', '') + fmt = '!HHI' + pack_str + + # serialize + buf = bytearray() + length = match.serialize(buf, 0) + eq_(length, len(buf)) + + res = list(unpack_from(fmt, str(buf), 0)[3:]) + res_value = res.pop(0) + eq_(res_value, value) + + # parser + res = match.parser(str(buf), 0) + eq_(res.type, ofproto.OFPMT_OXM) + eq_(res.fields[0].header, header) + eq_(res.fields[0].value, value) + + # to_jsondict + jsondict = match.to_jsondict() + + # from_jsondict + match2 = match.from_jsondict(jsondict["OFPMatch"]) + buf2 = bytearray() + match2.serialize(buf2, 0) + eq_(str(match), str(match2)) + eq_(buf, buf2) + def test_set_vlan_vid_mid(self): self._test_set_vlan_vid(2047) @@ -6871,6 +6905,9 @@ class TestOFPMatch(unittest.TestCase): def test_set_vlan_vid_masked_min(self): self._test_set_vlan_vid(2047, 0) + def test_set_vlan_vid_none(self): + self._test_set_vlan_vid_none() + # set_vlan_pcp def _test_set_vlan_pcp(self, pcp): header = ofproto.OXM_OF_VLAN_PCP