summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--ryu/tests/unit/ofproto/test_ofproto_parser.py19
-rw-r--r--ryu/tests/unit/ofproto/test_parser_v10.py26
-rw-r--r--ryu/tests/unit/ofproto/test_parser_v12.py26
3 files changed, 45 insertions, 26 deletions
diff --git a/ryu/tests/unit/ofproto/test_ofproto_parser.py b/ryu/tests/unit/ofproto/test_ofproto_parser.py
index 9baf46ab..be67434b 100644
--- a/ryu/tests/unit/ofproto/test_ofproto_parser.py
+++ b/ryu/tests/unit/ofproto/test_ofproto_parser.py
@@ -161,16 +161,23 @@ class TestMsgBase(unittest.TestCase):
c.set_xid(xid)
def _test_parser(self, msg_type=ofproto_v1_0.OFPT_HELLO):
+ version = ofproto_v1_0.OFP_VERSION
+ msg_len = ofproto_v1_0.OFP_HEADER_SIZE
xid = 2183948390
+ data = '\x00\x01\x02\x03'
+
+ fmt = ofproto_v1_0.OFP_HEADER_PACK_STR
+ buf = struct.pack(fmt, version, msg_type, msg_len, xid) \
+ + data
+
res = ofproto_v1_0_parser.OFPHello.parser(
- object, ofproto_v1_0.OFP_VERSION, msg_type,
- ofproto_v1_0.OFP_HEADER_SIZE, xid,
- str().zfill(ofproto_v1_0.OFP_HEADER_SIZE))
+ object, version, msg_type, msg_len, xid, bytearray(buf))
- eq_(ofproto_v1_0.OFP_VERSION, res.version)
- eq_(ofproto_v1_0.OFPT_HELLO, res.msg_type)
- eq_(ofproto_v1_0.OFP_HEADER_SIZE, res.msg_len)
+ eq_(version, res.version)
+ eq_(msg_type, res.msg_type)
+ eq_(msg_len, res.msg_len)
eq_(xid, res.xid)
+ eq_(buffer(buf), res.buf)
# test __str__()
list_ = ('version:', 'msg_type', 'xid')
diff --git a/ryu/tests/unit/ofproto/test_parser_v10.py b/ryu/tests/unit/ofproto/test_parser_v10.py
index 9a47ebca..66a69a44 100644
--- a/ryu/tests/unit/ofproto/test_parser_v10.py
+++ b/ryu/tests/unit/ofproto/test_parser_v10.py
@@ -2695,18 +2695,24 @@ class TestOFPHello(unittest.TestCase):
pass
def test_parser(self):
+ version = ofproto_v1_0.OFP_VERSION
+ msg_type = ofproto_v1_0.OFPT_HELLO
+ msg_len = ofproto_v1_0.OFP_HEADER_SIZE
xid = 2183948390
- res = OFPHello.parser(object,
- ofproto_v1_0.OFP_VERSION,
- ofproto_v1_0.OFPT_HELLO,
- ofproto_v1_0.OFP_HEADER_SIZE,
- xid,
- str().zfill(ofproto_v1_0.OFP_HEADER_SIZE))
-
- eq_(ofproto_v1_0.OFP_VERSION, res.version)
- eq_(ofproto_v1_0.OFPT_HELLO, res.msg_type)
- eq_(ofproto_v1_0.OFP_HEADER_SIZE, res.msg_len)
+ data = '\x00\x01\x02\x03'
+
+ fmt = ofproto_v1_0.OFP_HEADER_PACK_STR
+ buf = struct.pack(fmt, version, msg_type, msg_len, xid) \
+ + data
+
+ res = OFPHello.parser(object, version, msg_type, msg_len, xid,
+ bytearray(buf))
+
+ eq_(version, res.version)
+ eq_(msg_type, res.msg_type)
+ eq_(msg_len, res.msg_len)
eq_(xid, res.xid)
+ eq_(buffer(buf), res.buf)
# test __str__()
list_ = ('version:', 'msg_type', 'xid')
diff --git a/ryu/tests/unit/ofproto/test_parser_v12.py b/ryu/tests/unit/ofproto/test_parser_v12.py
index 5efd527a..7f38725a 100644
--- a/ryu/tests/unit/ofproto/test_parser_v12.py
+++ b/ryu/tests/unit/ofproto/test_parser_v12.py
@@ -85,18 +85,24 @@ class TestOFPHello(unittest.TestCase):
pass
def test_parser(self):
+ version = ofproto_v1_2.OFP_VERSION
+ msg_type = ofproto_v1_2.OFPT_HELLO
+ msg_len = ofproto_v1_2.OFP_HEADER_SIZE
xid = 2183948390
- res = OFPHello.parser(object,
- ofproto_v1_2.OFP_VERSION,
- ofproto_v1_2.OFPT_HELLO,
- ofproto_v1_2.OFP_HEADER_SIZE,
- xid,
- str().zfill(ofproto_v1_2.OFP_HEADER_SIZE))
-
- eq_(ofproto_v1_2.OFP_VERSION, res.version)
- eq_(ofproto_v1_2.OFPT_HELLO, res.msg_type)
- eq_(ofproto_v1_2.OFP_HEADER_SIZE, res.msg_len)
+ data = '\x00\x01\x02\x03'
+
+ fmt = ofproto_v1_2.OFP_HEADER_PACK_STR
+ buf = pack(fmt, version, msg_type, msg_len, xid) \
+ + data
+
+ res = OFPHello.parser(object, version, msg_type, msg_len, xid,
+ bytearray(buf))
+
+ eq_(version, res.version)
+ eq_(msg_type, res.msg_type)
+ eq_(msg_len, res.msg_len)
eq_(xid, res.xid)
+ eq_(buffer(buf), res.buf)
def test_serialize(self):