1
|
|
|
"""group_mod tests.""" |
2
|
|
|
from unittest import TestCase |
3
|
|
|
|
4
|
|
|
from pyof.v0x04.controller2switch.group_mod import GroupMod |
5
|
|
|
from pyof.v0x04.common.action import ( |
6
|
|
|
ActionExperimenter, ActionSetField, ListOfActions) |
7
|
|
|
from pyof.v0x04.common.flow_match import OxmClass, OxmOfbMatchField, OxmTLV |
8
|
|
|
from pyof.v0x04.common.port import PortNo |
9
|
|
|
from pyof.v0x04.controller2switch.common import Bucket |
10
|
|
|
from pyof.v0x04.controller2switch.group_mod import ListOfBuckets |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class TestGroupMod(TestCase): |
14
|
|
|
"""group_mod tests.""" |
15
|
|
|
|
16
|
|
|
def test_min_size(self): |
17
|
|
|
"""Test minimum struct size.""" |
18
|
|
|
self.assertEqual(16, GroupMod().get_size()) |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
class TestBucket(TestCase): |
22
|
|
|
"""bucket tests.""" |
23
|
|
|
|
24
|
|
|
def test_min_size(self): |
25
|
|
|
"""Test minimum struct size.""" |
26
|
|
|
self.assertEqual(16, Bucket().get_size()) |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
class TestListBuckets(TestCase): |
30
|
|
|
|
31
|
|
|
def setUp(self): |
32
|
|
|
"""Configure raw file and its object in parent class (TestDump).""" |
33
|
|
|
super().setUp() |
34
|
|
|
|
35
|
|
|
self.oxmtlv1 = OxmTLV(oxm_class=OxmClass.OFPXMC_OPENFLOW_BASIC, |
36
|
|
|
oxm_field=OxmOfbMatchField.OFPXMT_OFB_METADATA, |
37
|
|
|
oxm_hasmask=False, |
38
|
|
|
oxm_value=b'\x00\x00\x00\x00\x00\x00\x00\x01') |
39
|
|
|
self.oxmtlv2 = OxmTLV(oxm_class=OxmClass.OFPXMC_OPENFLOW_BASIC, |
40
|
|
|
oxm_field=OxmOfbMatchField.OFPXMT_OFB_METADATA, |
41
|
|
|
oxm_hasmask=False, |
42
|
|
|
oxm_value=b'\x00\x00\x00\x00\x00\x00\x00\x02') |
43
|
|
|
|
44
|
|
|
self.action1 = ActionSetField(field=self.oxmtlv1) |
45
|
|
|
self.action2 = ActionSetField(field=self.oxmtlv2) |
46
|
|
|
self.action3 = ActionExperimenter(length=16, experimenter=0x00002320, |
47
|
|
|
body=b'\x00\x0e\xff\xf8\x28\x00\x00\x00') |
48
|
|
|
self.action4 = ActionExperimenter(length=16, experimenter=0x00001223, |
49
|
|
|
body=b'\x00\x0e\xff\xff\x28\x00\x00\x00') |
50
|
|
|
|
51
|
|
|
def test_bucket_list(self): |
52
|
|
|
|
53
|
|
|
bucket1 = Bucket(length=48, weight=1, watch_port=PortNo.OFPP_ANY, |
54
|
|
|
watch_group=PortNo.OFPP_ANY, |
55
|
|
|
actions=ListOfActions([self.action1, self.action2])) |
56
|
|
|
bucket2 = Bucket(length=80, weight=2, watch_port=PortNo.OFPP_ANY, |
57
|
|
|
watch_group=PortNo.OFPP_ANY, |
58
|
|
|
actions=ListOfActions([self.action1, self.action2, |
59
|
|
|
self.action3, self.action4])) |
60
|
|
|
bucket3 = Bucket(length=48, weight=3, watch_port=PortNo.OFPP_ANY, |
61
|
|
|
watch_group=PortNo.OFPP_ANY, |
62
|
|
|
actions=ListOfActions([self.action3, self.action4])) |
63
|
|
|
|
64
|
|
|
# Packing buckets |
65
|
|
|
buckets = ListOfBuckets([bucket1, bucket2, bucket3]) |
66
|
|
|
buff = packed_buff = buckets.pack() |
67
|
|
|
|
68
|
|
|
# Unpacking buckets bytes |
69
|
|
|
unpacked_buckets = ListOfBuckets() |
70
|
|
|
unpacked_buckets.unpack(buff) |
71
|
|
|
|
72
|
|
|
self.assertEqual(len(unpacked_buckets), 3) |
73
|
|
|
self.assertEqual(unpacked_buckets[0].length, 48) |
74
|
|
|
self.assertEqual(unpacked_buckets[0].weight, 1) |
75
|
|
|
self.assertEqual(len(unpacked_buckets[0].actions), 2) |
76
|
|
|
self.assertEqual(unpacked_buckets[0].actions[0].field.oxm_value, |
77
|
|
|
self.oxmtlv1.oxm_value) |
78
|
|
|
self.assertEqual(unpacked_buckets[0].actions[1].field.oxm_value, |
79
|
|
|
self.oxmtlv2.oxm_value) |
80
|
|
|
|
81
|
|
|
self.assertEqual(unpacked_buckets[1].length, 80) |
82
|
|
|
self.assertEqual(unpacked_buckets[1].weight, 2) |
83
|
|
|
self.assertEqual(len(unpacked_buckets[1].actions), 4) |
84
|
|
|
self.assertEqual(unpacked_buckets[1].actions[0].field.oxm_value, |
85
|
|
|
self.oxmtlv1.oxm_value) |
86
|
|
|
self.assertEqual(unpacked_buckets[1].actions[1].field.oxm_value, |
87
|
|
|
self.oxmtlv2.oxm_value) |
88
|
|
|
self.assertEqual(unpacked_buckets[1].actions[2].body, |
89
|
|
|
self.action3.body) |
90
|
|
|
self.assertEqual(unpacked_buckets[1].actions[3].body, |
91
|
|
|
self.action4.body) |
92
|
|
|
|
93
|
|
|
self.assertEqual(unpacked_buckets[2].length, 48) |
94
|
|
|
self.assertEqual(unpacked_buckets[2].weight, 3) |
95
|
|
|
self.assertEqual(len(unpacked_buckets[2].actions), 2) |
96
|
|
|
self.assertEqual(unpacked_buckets[2].actions[0].body, |
97
|
|
|
self.action3.body) |
98
|
|
|
self.assertEqual(unpacked_buckets[2].actions[1].body, |
99
|
|
|
self.action4.body) |
100
|
|
|
|
101
|
|
|
def test_buckets_one_item(self): |
102
|
|
|
|
103
|
|
|
bucket1 = Bucket(length=48, weight=1, watch_port=PortNo.OFPP_ANY, |
104
|
|
|
watch_group=PortNo.OFPP_ANY, |
105
|
|
|
actions=ListOfActions([self.action1, self.action2])) |
106
|
|
|
|
107
|
|
|
# Packing buckets |
108
|
|
|
buckets = ListOfBuckets([bucket1]) |
109
|
|
|
buff = packed_buff = buckets.pack() |
110
|
|
|
|
111
|
|
|
# Unpacking buckets bytes |
112
|
|
|
unpacked_buckets = ListOfBuckets() |
113
|
|
|
unpacked_buckets.unpack(buff) |
114
|
|
|
|
115
|
|
|
self.assertEqual(len(unpacked_buckets), 1) |
116
|
|
|
self.assertEqual(unpacked_buckets[0].length, 48) |
117
|
|
|
self.assertEqual(unpacked_buckets[0].weight, 1) |
118
|
|
|
self.assertEqual(len(unpacked_buckets[0].actions), 2) |
119
|
|
|
self.assertEqual(unpacked_buckets[0].actions[0].field.oxm_value, |
120
|
|
|
self.oxmtlv1.oxm_value) |
121
|
|
|
self.assertEqual(unpacked_buckets[0].actions[1].field.oxm_value, |
122
|
|
|
self.oxmtlv2.oxm_value) |
123
|
|
|
|
124
|
|
|
def test_buckets_no_action(self): |
125
|
|
|
|
126
|
|
|
bucket1 = Bucket(length=48, weight=1, watch_port=PortNo.OFPP_ANY, |
127
|
|
|
watch_group=PortNo.OFPP_ANY, |
128
|
|
|
actions=ListOfActions([self.action1])) |
129
|
|
|
|
130
|
|
|
# Packing buckets |
131
|
|
|
buckets = ListOfBuckets([bucket1]) |
132
|
|
|
buff = packed_buff = buckets.pack() |
133
|
|
|
|
134
|
|
|
# Unpacking buckets bytes |
135
|
|
|
unpacked_buckets = ListOfBuckets() |
136
|
|
|
unpacked_buckets.unpack(buff) |
137
|
|
|
|
138
|
|
|
self.assertEqual(len(unpacked_buckets), 1) |
139
|
|
|
self.assertEqual(unpacked_buckets[0].length, 48) |
140
|
|
|
self.assertEqual(unpacked_buckets[0].weight, 1) |
141
|
|
|
self.assertEqual(len(unpacked_buckets[0].actions), 1) |
142
|
|
|
self.assertEqual(unpacked_buckets[0].actions[0].field.oxm_value, |
143
|
|
|
self.oxmtlv1.oxm_value) |
144
|
|
|
|