- The OFPVID_PRESENT bit indicate the presence of a valid VLAN_ID.
- Reflect to unittests.

Signed-off-by: HIYAMA Manabu <[email protected]>
---
 ryu/ofproto/ofproto_v1_2_parser.py        |   10 ++++++++++
 ryu/tests/unit/ofproto/test_parser_v12.py |   26 ++++++++++++++++++++++----
 2 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/ryu/ofproto/ofproto_v1_2_parser.py 
b/ryu/ofproto/ofproto_v1_2_parser.py
index 37d1ee1..f8d2af4 100644
--- a/ryu/ofproto/ofproto_v1_2_parser.py
+++ b/ryu/ofproto/ofproto_v1_2_parser.py
@@ -2076,6 +2076,16 @@ class MTVlanVid(OFPMatchField):
         self.value = value
         self.mask = mask
 
+    @classmethod
+    def field_parser(cls, header, buf, offset):
+        m = super(MTVlanVid, cls).field_parser(header, buf, offset)
+        m.value &= ~ofproto_v1_2.OFPVID_PRESENT
+        return m
+
+    def serialize(self, buf, offset):
+        self.value |= ofproto_v1_2.OFPVID_PRESENT
+        super(MTVlanVid, self).serialize(buf, offset)
+
 
 @OFPMatchField.register_field_header([ofproto_v1_2.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 7f38725..b1e1cfc 100644
--- a/ryu/tests/unit/ofproto/test_parser_v12.py
+++ b/ryu/tests/unit/ofproto/test_parser_v12.py
@@ -3511,24 +3511,42 @@ class TestOFPMatch(unittest.TestCase):
 
         self._test_serialize_and_parser(header, value, match)
 
+    def _test_serialize_and_parser_vid(self, header, vid, match):
+        # match_serialize
+        buf = bytearray()
+        length = match.serialize(buf, 0)
+
+        cls_ = OFPMatchField._FIELDS_HEADERS.get(header)
+        fmt = '!HHI' + cls_.pack_str.replace('!', '')
+        res = unpack_from(fmt, buffer(buf), 0)
+
+        eq_(res[3], vid | ofproto_v1_2.OFPVID_PRESENT)
+
+        # match_parser
+        res = match.parser(str(buf), 0)
+
+        eq_(res.type, ofproto_v1_2.OFPMT_OXM)
+        eq_(res.fields[0].header, header)
+        eq_(res.fields[0].value, vid)
+
     def test_set_vlan_vid(self):
         header = ofproto_v1_2.OXM_OF_VLAN_VID
-        value = vid = 0b101010101010
+        vid = 0b101010101010
 
         match = OFPMatch()
         match.set_vlan_vid(vid)
 
-        self._test_serialize_and_parser(header, value, match)
+        self._test_serialize_and_parser_vid(header, vid, match)
 
     def test_set_vlan_vid_masked(self):
         header = ofproto_v1_2.OXM_OF_VLAN_VID_W
-        value = vid = 0b101010101010
+        vid = 0b101010101010
         mask = 0xfff
 
         match = OFPMatch()
         match.set_vlan_vid_masked(vid, mask)
 
-        self._test_serialize_and_parser(header, value, match)
+        self._test_serialize_and_parser_vid(header, vid, match)
 
     def test_set_vlan_pcp(self):
         header = ofproto_v1_2.OXM_OF_VLAN_PCP
-- 
1.7.9.5



------------------------------------------------------------------------------
LogMeIn Central: Instant, anywhere, Remote PC access and management.
Stay in control, update software, and manage PCs from one command center
Diagnose problems and improve visibility into emerging IT issues
Automate, monitor and manage. Do more in less time with Central
http://p.sf.net/sfu/logmein12331_d2d
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to