blob: fd72925a3058181279f5cb730879e9328c1204f6 [file] [log] [blame]
Zsolt Haraszti3578a1c2017-01-10 15:29:02 -08001from unittest import TestCase, main
2
3from loxi import of13
4from voltha.protos import third_party
5from ofagent.converter import to_loxi
6from voltha.core.flow_decomposer import *
7
8_ = third_party
9
10
11class TestConverter(TestCase):
12
13 def gen_pb_flow_stats(self):
14
15 # device level flows
16
17 flow_stats = [
18 mk_flow_stat(
19 priority=2000,
20 match_fields=[in_port(2), vlan_vid(4096 + 4000), vlan_pcp(0)],
21 actions=[pop_vlan(), output(1)]
22 ),
23 mk_flow_stat(
24 priority=2000,
25 match_fields=[in_port(1), eth_type(0x888e)],
26 actions=[push_vlan(0x8100), set_field(vlan_vid(4096 + 4000)),
27 output(2)]
28 ),
29 mk_flow_stat(
30 priority=1000,
31 match_fields=[in_port(1), eth_type(0x800), ip_proto(2)],
32 actions=[push_vlan(0x8100), set_field(vlan_vid(4096 + 4000)),
33 output(2)]
34 ),
35 mk_flow_stat(
36 priority=1000,
37 match_fields=[in_port(1), eth_type(0x800), ip_proto(17),
38 udp_src(68), udp_dst(67)],
39 actions=[push_vlan(0x8100), set_field(vlan_vid(4096 + 4000)),
40 output(2)]
41 ),
42 mk_flow_stat(
43 priority=1000,
44 match_fields=[in_port(2), vlan_vid(4096 + 140)],
45 actions=[pop_vlan(), output(1)]
46 ),
47 mk_flow_stat(
48 priority=500,
49 match_fields=[in_port(2), vlan_vid(4096 + 1000), metadata(128)],
50 actions=[pop_vlan(), output(1)]
51 ),
52 mk_flow_stat(
53 priority=500,
54 match_fields=[in_port(1), vlan_vid(4096 + 128)],
55 actions=[
56 push_vlan(0x8100), set_field(vlan_vid(4096 + 1000)),
57 output(2)]
58 ),
59 mk_flow_stat(
60 priority=500,
61 match_fields=[in_port(1), vlan_vid(4096 + 129)],
62 actions=[
63 push_vlan(0x8100), set_field(vlan_vid(4096 + 1000)),
64 output(2)]
65 ),
66 ] + [
67 mk_flow_stat(
68 priority=500,
69 match_fields=[in_port(2), vlan_vid(4096 + 0)],
70 actions=[
71 set_field(vlan_vid(4096 + 128)), output(1)]
72 ),
73 mk_flow_stat(
74 priority=1000,
75 match_fields=[
76 in_port(1), eth_type(0x800), ipv4_dst(0xe4010102)],
77 actions=[output(2)]
78 ),
79 mk_flow_stat(
80 priority=1000,
81 match_fields=[
82 in_port(1), eth_type(0x800), ipv4_dst(0xe4010104)],
83 actions=[output(2)]
84 ),
85 mk_flow_stat(
86 priority=500,
87 match_fields=[in_port(1), vlan_vid(4096 + 128)],
88 actions=[set_field(vlan_vid(4096 + 0)), output(2)]
89 ),
90 mk_flow_stat(
91 priority=500,
92 match_fields=[in_port(2), vlan_vid(0)],
93 actions=[push_vlan(0x8100), set_field(vlan_vid(4096 + 128)),
94 output(1)]
95 )
96
97 ]
98
99 # logical device level flows
100
101 # Various controller-bound rules
102 for _in_port in (1, 2):
103 flow_stats.append(mk_flow_stat(
104 priority=2000,
105 match_fields=[in_port(_in_port), eth_type(0x888e)],
106 actions=[
107 push_vlan(0x8100),
108 set_field(vlan_vid(4096 + 4000)),
109 output(ofp.OFPP_CONTROLLER)
110 ]
111 ))
112 flow_stats.append(mk_flow_stat(
113 priority=1000,
114 match_fields=[eth_type(0x800), ip_proto(2)],
115 actions=[output(ofp.OFPP_CONTROLLER)]
116 ))
117 flow_stats.append(mk_flow_stat(
118 priority=1000,
119 match_fields=[eth_type(0x800), ip_proto(17),
120 udp_src(68), udp_dst(67)],
121 actions=[output(ofp.OFPP_CONTROLLER)]
122 ))
123
124 # Multicast channels
125 mcast_setup = (
126 (1, 0xe4010101, ()),
127 (2, 0xe4010102, (1,)),
128 (3, 0xe4010103, (2,)),
129 (4, 0xe4010104, (1, 2)),
130 )
alshabibf4fb2682017-01-12 00:32:56 -0600131
132 group_stats = []
Zsolt Haraszti3578a1c2017-01-10 15:29:02 -0800133 for group_id, mcast_addr, ports in mcast_setup:
134 # self.lda.update_group_table(mk_multicast_group_mod(
135 # group_id=group_id,
136 # buckets=[
137 # ofp.ofp_bucket(actions=[
138 # pop_vlan(),
139 # output(port)
140 # ]) for port in ports
141 # ]))
142 flow_stats.append(mk_flow_stat(
143 priority=1000,
144 match_fields=[
145 in_port(0),
146 eth_type(0x800),
147 vlan_vid(4096 + 140),
148 ipv4_dst(mcast_addr)
149 ],
150 actions=[
151 group(group_id)
152 ]
153 ))
alshabibf4fb2682017-01-12 00:32:56 -0600154 group_stats.append(group_entry_from_group_mod(
155 mk_multicast_group_mod(
156 group_id=group_id,
157 buckets=[
158 ofp.ofp_bucket(actions=[
159 pop_vlan(),
160 output(port)
161 ]) for port in ports
162 ])))
163
Zsolt Haraszti3578a1c2017-01-10 15:29:02 -0800164
165 # Unicast channels for each subscriber
166 # Downstream flow 1 for both
167 flow_stats.append(mk_flow_stat(
168 priority=500,
169 match_fields=[
170 in_port(0),
171 vlan_vid(4096 + 1000),
172 metadata(128)
173 ],
174 actions=[pop_vlan()],
175 next_table_id=1
176 ))
177 # Downstream flow 2 and upsrteam flow 1 for each ONU
178 for port, c_vid in ((1, 101), (2, 102)):
179 flow_stats.append(mk_flow_stat(
180 priority=500,
181 match_fields=[in_port(0), vlan_vid(4096 + c_vid)],
182 actions=[set_field(vlan_vid(4096 + 0)), output(port)]
183 ))
184 # for the 0-tagged case
185 flow_stats.append(mk_flow_stat(
186 priority=500,
187 match_fields=[in_port(port), vlan_vid(4096 + 0)],
188 actions=[set_field(vlan_vid(4096 + c_vid))],
189 next_table_id=1
190 ))
191 # for the untagged case
192 flow_stats.append(mk_flow_stat(
193 priority=500,
194 match_fields=[in_port(port), vlan_vid(0)],
195 actions=[push_vlan(0x8100), set_field(vlan_vid(4096 + c_vid))],
196 next_table_id=1
197 ))
198 # Upstream flow 2 for s-tag
199 flow_stats.append(mk_flow_stat(
200 priority=500,
201 match_fields=[in_port(port), vlan_vid(4096 + c_vid)],
202 actions=[
203 push_vlan(0x8100),
204 set_field(vlan_vid(4096 + 1000)),
205 output(0)
206 ]
207 ))
208
alshabibf4fb2682017-01-12 00:32:56 -0600209 return (flow_stats, group_stats)
Zsolt Haraszti3578a1c2017-01-10 15:29:02 -0800210
211 def test_flow_spec_pb_to_loxi_conversion(self):
alshabibf4fb2682017-01-12 00:32:56 -0600212 flow_stats, _ = self.gen_pb_flow_stats()
Zsolt Haraszti3578a1c2017-01-10 15:29:02 -0800213 for flow_stat in flow_stats:
214 loxi_flow_stats = to_loxi(flow_stat)
215
alshabibf4fb2682017-01-12 00:32:56 -0600216 def test_group_stat_spec_pb_to_loxi_conversion(self):
217 _, group_stats = self.gen_pb_flow_stats()
218 for group_stat in group_stats:
219 loxi_group_stat = to_loxi(group_stat.stats)
220
221 def test_group_desc_spec_pb_to_loxi_conversion(self):
222 _, group_stats = self.gen_pb_flow_stats()
223 for group_stat in group_stats:
224 loxi_group_desc = to_loxi(group_stat.desc)
Zsolt Haraszti3578a1c2017-01-10 15:29:02 -0800225
Zsolt Haraszti66927732017-01-14 16:50:59 -0800226
Zsolt Haraszti3578a1c2017-01-10 15:29:02 -0800227if __name__ == '__main__':
228 main()