Skip to content
This repository was archived by the owner on Apr 22, 2024. It is now read-only.

Commit abca8be

Browse files
committed
Adding some tests for multipart request/reply
1 parent deb35e3 commit abca8be

2 files changed

Lines changed: 62 additions & 12 deletions

File tree

tests/v0x04/test_controller2switch/test_multipart_reply.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
"""MultipartReply message test."""
22

33
from pyof.v0x04.controller2switch.common import MultipartTypes
4-
from pyof.v0x04.controller2switch.multipart_reply import (MultipartReply,
4+
from pyof.v0x04.controller2switch.multipart_reply import (Desc, MultipartReply,
55
MultipartReplyFlags)
6-
76
from tests.v0x04.test_struct import TestStruct
87

98

@@ -19,3 +18,22 @@ def setUpClass(cls):
1918
flags=MultipartReplyFlags.OFPMPF_REPLY_MORE,
2019
body='')
2120
super().set_minimum_size(16)
21+
22+
@staticmethod
23+
def get_attributes(multipart_type=MultipartTypes.OFPMP_DESC,
24+
flags=MultipartReplyFlags.OFPMPF_REPLY_MORE,
25+
body=''):
26+
"""Method used to return a dict with instance paramenters."""
27+
return {'xid': 32, 'multipart_type': multipart_type, 'flags': flags,
28+
'body': body}
29+
30+
def test_pack_unpack_desc(self):
31+
"""Testing multipart_type with OFPMP_DESC."""
32+
instances = Desc(mfr_desc="MANUFACTURER DESCRIPTION",
33+
hw_desc="HARDWARE DESCRIPTION",
34+
sw_desc="SOFTWARE DESCRIPTION",
35+
serial_num="SERIAL NUMBER",
36+
dp_desc="DATAPATH DESCRIPTION")
37+
options = TestMultipartReply.get_attributes(
38+
multipart_type=MultipartTypes.OFPMP_DESC, body=instances)
39+
self._test_pack_unpack(**options)

tests/v0x04/test_controller2switch/test_multipart_request.py

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""MultipartRequest message test."""
22
from pyof.v0x04.controller2switch.multipart_request import (
3-
MultipartRequest, MultipartRequestFlags, MultipartTypes, TableFeatures)
3+
MultipartRequest, MultipartRequestFlags, MultipartTypes,
4+
PortStatsRequest, TableFeatures)
45

56
from tests.v0x04.test_struct import TestStruct
67

@@ -19,14 +20,45 @@ def setUpClass(cls):
1920
body=b'')
2021
super().set_minimum_size(16)
2122

22-
def test_body_table_features(self):
23-
"""Method to test pack and unpack using table_features as body."""
24-
table_features = [TableFeatures(table_id=2),
25-
TableFeatures(table_id=6),
26-
TableFeatures(table_id=4)]
23+
@staticmethod
24+
def get_attributes(multipart_type=MultipartTypes.OFPMP_DESC,
25+
flags=MultipartRequestFlags.OFPMPF_REQ_MORE,
26+
body=''):
27+
"""Method used to return a dict with instance paramenters."""
28+
return {'xid': 32, 'multipart_type': multipart_type, 'flags': flags,
29+
'body': body}
2730

28-
options = {'xid': 16,
29-
'multipart_type': MultipartTypes.OFPMP_TABLE_FEATURES,
30-
'flags': MultipartRequestFlags.OFPMPF_REQ_MORE,
31-
'body': table_features}
31+
def test_pack_unpack_desc(self):
32+
"""Testing multipart_type with OFPMP_DESC."""
33+
options = TestMultipartRequest.get_attributes(
34+
multipart_type=MultipartTypes.OFPMP_DESC)
35+
self._test_pack_unpack(**options)
36+
37+
def test_pack_unpack_table(self):
38+
"""Testing multipart_type with OFPMP_TABLE."""
39+
options = TestMultipartRequest.get_attributes(
40+
multipart_type=MultipartTypes.OFPMP_TABLE)
41+
self._test_pack_unpack(**options)
42+
43+
def test_pack_unpack__port_stats_request(self):
44+
"""Testing multipart_type with OFPMP_PORT_STATS."""
45+
options = TestMultipartRequest.get_attributes(
46+
multipart_type=MultipartTypes.OFPMP_PORT_STATS,
47+
body=PortStatsRequest(port_no=33))
48+
self._test_pack_unpack(**options)
49+
50+
def test_pack_unpack_port_desc(self):
51+
"""Testing multipart_type with OFPMP_PORT_DESC."""
52+
options = TestMultipartRequest.get_attributes(
53+
multipart_type=MultipartTypes.OFPMP_PORT_DESC)
54+
self._test_pack_unpack(**options)
55+
56+
def test_pack_unpack_table_features(self):
57+
"""Testing multipart_type with OFPMP_TABLE_FEATURES."""
58+
instance = [TableFeatures(table_id=2),
59+
TableFeatures(table_id=6),
60+
TableFeatures(table_id=4)]
61+
options = TestMultipartRequest.get_attributes(
62+
multipart_type=MultipartTypes.OFPMP_TABLE_FEATURES,
63+
body=instance)
3264
self._test_pack_unpack(**options)

0 commit comments

Comments
 (0)