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 <takahashi.minoru7@gmail.com> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
parent
baf4b7a01a
commit
1e72c73685
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user