1
|
|
|
"""Test flow_builder.""" |
2
|
|
|
|
3
|
1 |
|
import pytest |
4
|
|
|
|
5
|
1 |
|
from collections import defaultdict |
6
|
1 |
|
from unittest.mock import MagicMock |
7
|
1 |
|
from napps.kytos.telemetry_int.exceptions import FlowsNotFound |
8
|
1 |
|
from napps.kytos.telemetry_int.managers.flow_builder import FlowBuilder |
9
|
1 |
|
from napps.kytos.telemetry_int.managers.int import INTManager |
10
|
1 |
|
from napps.kytos.telemetry_int.utils import get_cookie |
11
|
1 |
|
from napps.kytos.telemetry_int.proxy_port import ProxyPort |
12
|
1 |
|
from napps.kytos.telemetry_int import settings |
13
|
1 |
|
from napps.kytos.telemetry_int.kytos_api_helper import _map_stored_flows_by_cookies |
14
|
1 |
|
from kytos.lib.helpers import get_controller_mock, get_switch_mock, get_interface_mock |
15
|
1 |
|
from kytos.core.common import EntityStatus |
16
|
|
|
|
17
|
|
|
|
18
|
1 |
|
def test_flow_builder_default_table_groups() -> None: |
19
|
|
|
"""test flow builder default table groups.""" |
20
|
1 |
|
assert FlowBuilder().table_group == {"evpl": 2, "epl": 3} |
21
|
|
|
|
22
|
|
|
|
23
|
1 |
|
def test_build_int_flows_intra_evpl(evcs_data, intra_evc_evpl_flows_data) -> None: |
24
|
|
|
"""Test build INT flows intra EVPL. |
25
|
|
|
|
26
|
|
|
+--------+ |
27
|
|
|
| | |
28
|
|
|
10 | 11| |
29
|
|
|
+--------+--------v--+ |
30
|
|
|
| | 20 |
31
|
|
|
1 | +-----+ |
32
|
|
|
--------------+ | | |
33
|
|
|
(vlan 200) | | | |
34
|
|
|
| sw1 | | |
35
|
|
|
2 | |21 | |
36
|
|
|
---------------+ <-----+ |
37
|
|
|
(vlan 200) | | |
38
|
|
|
+--------------------+ |
39
|
|
|
""" |
40
|
1 |
|
controller = get_controller_mock() |
41
|
1 |
|
int_manager = INTManager(controller) |
42
|
1 |
|
get_proxy_port_or_raise = MagicMock() |
43
|
1 |
|
int_manager.get_proxy_port_or_raise = get_proxy_port_or_raise |
44
|
|
|
|
45
|
1 |
|
evc_id = "3766c105686749" |
46
|
1 |
|
dpid_a = "00:00:00:00:00:00:00:01" |
47
|
1 |
|
mock_switch_a = get_switch_mock(dpid_a, 0x04) |
48
|
1 |
|
mock_interface_a1 = get_interface_mock("s1-eth1", 1, mock_switch_a) |
49
|
1 |
|
mock_interface_a1.id = f"{dpid_a}:{mock_interface_a1.port_number}" |
50
|
1 |
|
mock_interface_a10 = get_interface_mock("s1-eth10", 10, mock_switch_a) |
51
|
1 |
|
mock_interface_a1.metadata = {"proxy_port": mock_interface_a10.port_number} |
52
|
1 |
|
mock_interface_a10.status = EntityStatus.UP |
53
|
1 |
|
mock_interface_a11 = get_interface_mock("s1-eth11", 11, mock_switch_a) |
54
|
1 |
|
mock_interface_a11.status = EntityStatus.UP |
55
|
1 |
|
mock_interface_a10.metadata = { |
56
|
|
|
"looped": { |
57
|
|
|
"port_numbers": [ |
58
|
|
|
mock_interface_a10.port_number, |
59
|
|
|
mock_interface_a11.port_number, |
60
|
|
|
] |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
1 |
|
mock_interface_z1 = get_interface_mock("s1-eth2", 1, mock_switch_a) |
65
|
1 |
|
mock_interface_z1.status = EntityStatus.UP |
66
|
1 |
|
mock_interface_z1.id = f"{dpid_a}:{mock_interface_a1.port_number}" |
67
|
1 |
|
mock_interface_z20 = get_interface_mock("s1-eth20", 20, mock_switch_a) |
68
|
1 |
|
mock_interface_z1.metadata = {"proxy_port": mock_interface_z20.port_number} |
69
|
1 |
|
mock_interface_z20.status = EntityStatus.UP |
70
|
1 |
|
mock_interface_z21 = get_interface_mock("s1-eth21", 21, mock_switch_a) |
71
|
1 |
|
mock_interface_z21.status = EntityStatus.UP |
72
|
1 |
|
mock_interface_z20.metadata = { |
73
|
|
|
"looped": { |
74
|
|
|
"port_numbers": [ |
75
|
|
|
mock_interface_z20.port_number, |
76
|
|
|
mock_interface_z21.port_number, |
77
|
|
|
] |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
1 |
|
mock_switch_a.get_interface_by_port_no = lambda port_no: { |
82
|
|
|
mock_interface_a10.port_number: mock_interface_a10, |
83
|
|
|
mock_interface_a11.port_number: mock_interface_a11, |
84
|
|
|
mock_interface_z20.port_number: mock_interface_z20, |
85
|
|
|
mock_interface_z21.port_number: mock_interface_z21, |
86
|
|
|
}[port_no] |
87
|
|
|
|
88
|
1 |
|
pp_a = ProxyPort(controller, source=mock_interface_a10) |
89
|
1 |
|
assert pp_a.source == mock_interface_a10 |
90
|
1 |
|
assert pp_a.destination == mock_interface_a11 |
91
|
1 |
|
pp_z = ProxyPort(controller, source=mock_interface_z20) |
92
|
1 |
|
assert pp_z.source == mock_interface_z20 |
93
|
1 |
|
assert pp_z.destination == mock_interface_z21 |
94
|
|
|
|
95
|
1 |
|
get_proxy_port_or_raise.side_effect = [pp_a, pp_z] |
96
|
1 |
|
evcs_data = {evc_id: evcs_data[evc_id]} |
97
|
1 |
|
evcs_data = int_manager._validate_map_enable_evcs(evcs_data) |
98
|
1 |
|
stored_flows = _map_stored_flows_by_cookies(intra_evc_evpl_flows_data) |
99
|
|
|
|
100
|
1 |
|
cookie = get_cookie(evc_id, settings.MEF_COOKIE_PREFIX) |
101
|
1 |
|
flows = FlowBuilder().build_int_flows(evcs_data, stored_flows)[cookie] |
102
|
|
|
|
103
|
1 |
|
n_expected_source_flows, n_expected_sink_flows = 3, 2 |
104
|
1 |
|
assert len(flows) == (n_expected_source_flows + n_expected_sink_flows) * 2 |
105
|
|
|
|
106
|
1 |
|
expected_uni_a_source_flows = [ |
107
|
|
|
{ |
108
|
|
|
"flow": { |
109
|
|
|
"owner": "telemetry_int", |
110
|
|
|
"cookie": int(0xA83766C105686749), |
111
|
|
|
"match": {"in_port": 1, "dl_vlan": 200, "dl_type": 2048, "nw_proto": 6}, |
112
|
|
|
"table_id": 0, |
113
|
|
|
"table_group": "evpl", |
114
|
|
|
"priority": 20100, |
115
|
|
|
"idle_timeout": 0, |
116
|
|
|
"hard_timeout": 0, |
117
|
|
|
"instructions": [ |
118
|
|
|
{ |
119
|
|
|
"instruction_type": "apply_actions", |
120
|
|
|
"actions": [{"action_type": "push_int"}], |
121
|
|
|
}, |
122
|
|
|
{"instruction_type": "goto_table", "table_id": 2}, |
123
|
|
|
], |
124
|
|
|
} |
125
|
|
|
}, |
126
|
|
|
{ |
127
|
|
|
"flow": { |
128
|
|
|
"owner": "telemetry_int", |
129
|
|
|
"cookie": int(0xA83766C105686749), |
130
|
|
|
"match": { |
131
|
|
|
"in_port": 1, |
132
|
|
|
"dl_vlan": 200, |
133
|
|
|
"dl_type": 2048, |
134
|
|
|
"nw_proto": 17, |
135
|
|
|
}, |
136
|
|
|
"table_id": 0, |
137
|
|
|
"table_group": "evpl", |
138
|
|
|
"priority": 20100, |
139
|
|
|
"idle_timeout": 0, |
140
|
|
|
"hard_timeout": 0, |
141
|
|
|
"instructions": [ |
142
|
|
|
{ |
143
|
|
|
"instruction_type": "apply_actions", |
144
|
|
|
"actions": [{"action_type": "push_int"}], |
145
|
|
|
}, |
146
|
|
|
{"instruction_type": "goto_table", "table_id": 2}, |
147
|
|
|
], |
148
|
|
|
} |
149
|
|
|
}, |
150
|
|
|
{ |
151
|
|
|
"flow": { |
152
|
|
|
"owner": "telemetry_int", |
153
|
|
|
"cookie": int(0xA83766C105686749), |
154
|
|
|
"match": {"in_port": 1, "dl_vlan": 200}, |
155
|
|
|
"table_id": 2, |
156
|
|
|
"table_group": "evpl", |
157
|
|
|
"priority": 20000, |
158
|
|
|
"idle_timeout": 0, |
159
|
|
|
"hard_timeout": 0, |
160
|
|
|
"instructions": [ |
161
|
|
|
{ |
162
|
|
|
"instruction_type": "apply_actions", |
163
|
|
|
"actions": [ |
164
|
|
|
{"action_type": "add_int_metadata"}, |
165
|
|
|
{"action_type": "output", "port": 20}, |
166
|
|
|
], |
167
|
|
|
} |
168
|
|
|
], |
169
|
|
|
} |
170
|
|
|
}, |
171
|
|
|
] |
172
|
|
|
|
173
|
1 |
|
expected_uni_z_source_flows = [ |
174
|
|
|
{ |
175
|
|
|
"flow": { |
176
|
|
|
"owner": "telemetry_int", |
177
|
|
|
"cookie": int(0xA83766C105686749), |
178
|
|
|
"match": {"in_port": 2, "dl_vlan": 200, "dl_type": 2048, "nw_proto": 6}, |
179
|
|
|
"table_id": 0, |
180
|
|
|
"table_group": "evpl", |
181
|
|
|
"priority": 20100, |
182
|
|
|
"idle_timeout": 0, |
183
|
|
|
"hard_timeout": 0, |
184
|
|
|
"instructions": [ |
185
|
|
|
{ |
186
|
|
|
"instruction_type": "apply_actions", |
187
|
|
|
"actions": [{"action_type": "push_int"}], |
188
|
|
|
}, |
189
|
|
|
{"instruction_type": "goto_table", "table_id": 2}, |
190
|
|
|
], |
191
|
|
|
} |
192
|
|
|
}, |
193
|
|
|
{ |
194
|
|
|
"flow": { |
195
|
|
|
"owner": "telemetry_int", |
196
|
|
|
"cookie": int(0xA83766C105686749), |
197
|
|
|
"match": { |
198
|
|
|
"in_port": 2, |
199
|
|
|
"dl_vlan": 200, |
200
|
|
|
"dl_type": 2048, |
201
|
|
|
"nw_proto": 17, |
202
|
|
|
}, |
203
|
|
|
"table_id": 0, |
204
|
|
|
"table_group": "evpl", |
205
|
|
|
"priority": 20100, |
206
|
|
|
"idle_timeout": 0, |
207
|
|
|
"hard_timeout": 0, |
208
|
|
|
"instructions": [ |
209
|
|
|
{ |
210
|
|
|
"instruction_type": "apply_actions", |
211
|
|
|
"actions": [{"action_type": "push_int"}], |
212
|
|
|
}, |
213
|
|
|
{"instruction_type": "goto_table", "table_id": 2}, |
214
|
|
|
], |
215
|
|
|
} |
216
|
|
|
}, |
217
|
|
|
{ |
218
|
|
|
"flow": { |
219
|
|
|
"owner": "telemetry_int", |
220
|
|
|
"cookie": int(0xA83766C105686749), |
221
|
|
|
"match": {"in_port": 2, "dl_vlan": 200}, |
222
|
|
|
"table_id": 2, |
223
|
|
|
"table_group": "evpl", |
224
|
|
|
"priority": 20000, |
225
|
|
|
"idle_timeout": 0, |
226
|
|
|
"hard_timeout": 0, |
227
|
|
|
"instructions": [ |
228
|
|
|
{ |
229
|
|
|
"instruction_type": "apply_actions", |
230
|
|
|
"actions": [ |
231
|
|
|
{"action_type": "add_int_metadata"}, |
232
|
|
|
{"action_type": "output", "port": 10}, |
233
|
|
|
], |
234
|
|
|
} |
235
|
|
|
], |
236
|
|
|
} |
237
|
|
|
}, |
238
|
|
|
] |
239
|
|
|
|
240
|
1 |
|
expected_uni_a_sink_flows = [ |
241
|
|
|
{ |
242
|
|
|
"flow": { |
243
|
|
|
"owner": "telemetry_int", |
244
|
|
|
"cookie": int(0xA83766C105686749), |
245
|
|
|
"match": {"in_port": 11, "dl_vlan": 200}, |
246
|
|
|
"table_id": 0, |
247
|
|
|
"table_group": "evpl", |
248
|
|
|
"priority": 20000, |
249
|
|
|
"idle_timeout": 0, |
250
|
|
|
"hard_timeout": 0, |
251
|
|
|
"instructions": [ |
252
|
|
|
{ |
253
|
|
|
"instruction_type": "apply_actions", |
254
|
|
|
"actions": [{"action_type": "send_report"}], |
255
|
|
|
}, |
256
|
|
|
{"instruction_type": "goto_table", "table_id": 2}, |
257
|
|
|
], |
258
|
|
|
}, |
259
|
|
|
}, |
260
|
|
|
{ |
261
|
|
|
"flow": { |
262
|
|
|
"owner": "telemetry_int", |
263
|
|
|
"cookie": int(0xA83766C105686749), |
264
|
|
|
"match": {"in_port": 11, "dl_vlan": 200}, |
265
|
|
|
"table_id": 2, |
266
|
|
|
"table_group": "evpl", |
267
|
|
|
"priority": 20000, |
268
|
|
|
"idle_timeout": 0, |
269
|
|
|
"hard_timeout": 0, |
270
|
|
|
"instructions": [ |
271
|
|
|
{ |
272
|
|
|
"instruction_type": "apply_actions", |
273
|
|
|
"actions": [ |
274
|
|
|
{"action_type": "pop_int"}, |
275
|
|
|
{"action_type": "set_vlan", "vlan_id": 200}, |
276
|
|
|
{"action_type": "output", "port": 1}, |
277
|
|
|
], |
278
|
|
|
} |
279
|
|
|
], |
280
|
|
|
}, |
281
|
|
|
}, |
282
|
|
|
] |
283
|
1 |
|
expected_uni_z_sink_flows = [ |
284
|
|
|
{ |
285
|
|
|
"flow": { |
286
|
|
|
"owner": "telemetry_int", |
287
|
|
|
"cookie": int(0xA83766C105686749), |
288
|
|
|
"match": {"in_port": 21, "dl_vlan": 200}, |
289
|
|
|
"table_id": 0, |
290
|
|
|
"table_group": "evpl", |
291
|
|
|
"priority": 20000, |
292
|
|
|
"idle_timeout": 0, |
293
|
|
|
"hard_timeout": 0, |
294
|
|
|
"instructions": [ |
295
|
|
|
{ |
296
|
|
|
"instruction_type": "apply_actions", |
297
|
|
|
"actions": [{"action_type": "send_report"}], |
298
|
|
|
}, |
299
|
|
|
{"instruction_type": "goto_table", "table_id": 2}, |
300
|
|
|
], |
301
|
|
|
}, |
302
|
|
|
}, |
303
|
|
|
{ |
304
|
|
|
"flow": { |
305
|
|
|
"owner": "telemetry_int", |
306
|
|
|
"cookie": int(0xA83766C105686749), |
307
|
|
|
"match": {"in_port": 21, "dl_vlan": 200}, |
308
|
|
|
"table_id": 2, |
309
|
|
|
"table_group": "evpl", |
310
|
|
|
"priority": 20000, |
311
|
|
|
"idle_timeout": 0, |
312
|
|
|
"hard_timeout": 0, |
313
|
|
|
"instructions": [ |
314
|
|
|
{ |
315
|
|
|
"instruction_type": "apply_actions", |
316
|
|
|
"actions": [ |
317
|
|
|
{"action_type": "pop_int"}, |
318
|
|
|
{"action_type": "set_vlan", "vlan_id": 200}, |
319
|
|
|
{"action_type": "output", "port": 2}, |
320
|
|
|
], |
321
|
|
|
} |
322
|
|
|
], |
323
|
|
|
}, |
324
|
|
|
}, |
325
|
|
|
] |
326
|
|
|
|
327
|
1 |
|
expected_flows = ( |
328
|
|
|
expected_uni_a_source_flows |
329
|
|
|
+ expected_uni_z_source_flows |
330
|
|
|
+ expected_uni_z_sink_flows |
331
|
|
|
+ expected_uni_a_sink_flows |
332
|
|
|
) |
333
|
|
|
|
334
|
1 |
|
for i, flow in enumerate(flows): |
335
|
1 |
|
assert (i, flow["flow"]) == (i, expected_flows[i]["flow"]) |
336
|
|
|
|
337
|
|
|
|
338
|
1 |
|
def test_build_int_flows_intra_epl(evcs_data, intra_evc_epl_flows_data) -> None: |
339
|
|
|
"""Test build INT flows intra EPL. |
340
|
|
|
|
341
|
|
|
+--------+ |
342
|
|
|
| | |
343
|
|
|
10 | 11| |
344
|
|
|
+--------+--------v--+ |
345
|
|
|
| | 20 |
346
|
|
|
1 | +-----+ |
347
|
|
|
--------------+ | | |
348
|
|
|
| | | |
349
|
|
|
| sw1 | | |
350
|
|
|
2 | |21 | |
351
|
|
|
---------------+ <-----+ |
352
|
|
|
| | |
353
|
|
|
+--------------------+ |
354
|
|
|
""" |
355
|
1 |
|
controller = get_controller_mock() |
356
|
1 |
|
int_manager = INTManager(controller) |
357
|
1 |
|
get_proxy_port_or_raise = MagicMock() |
358
|
1 |
|
int_manager.get_proxy_port_or_raise = get_proxy_port_or_raise |
359
|
|
|
|
360
|
1 |
|
evc_id = "3766c105686749" |
361
|
1 |
|
dpid_a = "00:00:00:00:00:00:00:01" |
362
|
1 |
|
mock_switch_a = get_switch_mock(dpid_a, 0x04) |
363
|
1 |
|
mock_interface_a1 = get_interface_mock("s1-eth1", 1, mock_switch_a) |
364
|
1 |
|
mock_interface_a1.id = f"{dpid_a}:{mock_interface_a1.port_number}" |
365
|
1 |
|
mock_interface_a10 = get_interface_mock("s1-eth10", 10, mock_switch_a) |
366
|
1 |
|
mock_interface_a1.metadata = {"proxy_port": mock_interface_a10.port_number} |
367
|
1 |
|
mock_interface_a10.status = EntityStatus.UP |
368
|
1 |
|
mock_interface_a11 = get_interface_mock("s1-eth11", 11, mock_switch_a) |
369
|
1 |
|
mock_interface_a11.status = EntityStatus.UP |
370
|
1 |
|
mock_interface_a10.metadata = { |
371
|
|
|
"looped": { |
372
|
|
|
"port_numbers": [ |
373
|
|
|
mock_interface_a10.port_number, |
374
|
|
|
mock_interface_a11.port_number, |
375
|
|
|
] |
376
|
|
|
} |
377
|
|
|
} |
378
|
|
|
|
379
|
1 |
|
mock_interface_z1 = get_interface_mock("s1-eth2", 1, mock_switch_a) |
380
|
1 |
|
mock_interface_z1.status = EntityStatus.UP |
381
|
1 |
|
mock_interface_z1.id = f"{dpid_a}:{mock_interface_a1.port_number}" |
382
|
1 |
|
mock_interface_z20 = get_interface_mock("s1-eth20", 20, mock_switch_a) |
383
|
1 |
|
mock_interface_z1.metadata = {"proxy_port": mock_interface_z20.port_number} |
384
|
1 |
|
mock_interface_z20.status = EntityStatus.UP |
385
|
1 |
|
mock_interface_z21 = get_interface_mock("s1-eth21", 21, mock_switch_a) |
386
|
1 |
|
mock_interface_z21.status = EntityStatus.UP |
387
|
1 |
|
mock_interface_z20.metadata = { |
388
|
|
|
"looped": { |
389
|
|
|
"port_numbers": [ |
390
|
|
|
mock_interface_z20.port_number, |
391
|
|
|
mock_interface_z21.port_number, |
392
|
|
|
] |
393
|
|
|
} |
394
|
|
|
} |
395
|
|
|
|
396
|
1 |
|
mock_switch_a.get_interface_by_port_no = lambda port_no: { |
397
|
|
|
mock_interface_a10.port_number: mock_interface_a10, |
398
|
|
|
mock_interface_a11.port_number: mock_interface_a11, |
399
|
|
|
mock_interface_z20.port_number: mock_interface_z20, |
400
|
|
|
mock_interface_z21.port_number: mock_interface_z21, |
401
|
|
|
}[port_no] |
402
|
|
|
|
403
|
1 |
|
pp_a = ProxyPort(controller, source=mock_interface_a10) |
404
|
1 |
|
assert pp_a.source == mock_interface_a10 |
405
|
1 |
|
assert pp_a.destination == mock_interface_a11 |
406
|
1 |
|
pp_z = ProxyPort(controller, source=mock_interface_z20) |
407
|
1 |
|
assert pp_z.source == mock_interface_z20 |
408
|
1 |
|
assert pp_z.destination == mock_interface_z21 |
409
|
|
|
|
410
|
1 |
|
get_proxy_port_or_raise.side_effect = [pp_a, pp_z] |
411
|
1 |
|
evcs_data = {evc_id: evcs_data[evc_id]} |
412
|
1 |
|
evcs_data = int_manager._validate_map_enable_evcs(evcs_data) |
413
|
1 |
|
stored_flows = _map_stored_flows_by_cookies(intra_evc_epl_flows_data) |
414
|
|
|
|
415
|
1 |
|
cookie = get_cookie(evc_id, settings.MEF_COOKIE_PREFIX) |
416
|
1 |
|
flows = FlowBuilder().build_int_flows(evcs_data, stored_flows)[cookie] |
417
|
|
|
|
418
|
1 |
|
n_expected_source_flows, n_expected_sink_flows = 3, 2 |
419
|
1 |
|
assert len(flows) == (n_expected_source_flows + n_expected_sink_flows) * 2 |
420
|
|
|
|
421
|
1 |
|
expected_uni_a_source_flows = [ |
422
|
|
|
{ |
423
|
|
|
"flow": { |
424
|
|
|
"owner": "telemetry_int", |
425
|
|
|
"cookie": int(0xA83766C105686749), |
426
|
|
|
"match": {"in_port": 1, "dl_type": 2048, "nw_proto": 6}, |
427
|
|
|
"table_id": 0, |
428
|
|
|
"table_group": "epl", |
429
|
|
|
"priority": 10100, |
430
|
|
|
"idle_timeout": 0, |
431
|
|
|
"hard_timeout": 0, |
432
|
|
|
"instructions": [ |
433
|
|
|
{ |
434
|
|
|
"instruction_type": "apply_actions", |
435
|
|
|
"actions": [{"action_type": "push_int"}], |
436
|
|
|
}, |
437
|
|
|
{"instruction_type": "goto_table", "table_id": 3}, |
438
|
|
|
], |
439
|
|
|
} |
440
|
|
|
}, |
441
|
|
|
{ |
442
|
|
|
"flow": { |
443
|
|
|
"owner": "telemetry_int", |
444
|
|
|
"cookie": int(0xA83766C105686749), |
445
|
|
|
"match": { |
446
|
|
|
"in_port": 1, |
447
|
|
|
"dl_type": 2048, |
448
|
|
|
"nw_proto": 17, |
449
|
|
|
}, |
450
|
|
|
"table_id": 0, |
451
|
|
|
"table_group": "epl", |
452
|
|
|
"priority": 10100, |
453
|
|
|
"idle_timeout": 0, |
454
|
|
|
"hard_timeout": 0, |
455
|
|
|
"instructions": [ |
456
|
|
|
{ |
457
|
|
|
"instruction_type": "apply_actions", |
458
|
|
|
"actions": [{"action_type": "push_int"}], |
459
|
|
|
}, |
460
|
|
|
{"instruction_type": "goto_table", "table_id": 3}, |
461
|
|
|
], |
462
|
|
|
} |
463
|
|
|
}, |
464
|
|
|
{ |
465
|
|
|
"flow": { |
466
|
|
|
"owner": "telemetry_int", |
467
|
|
|
"cookie": int(0xA83766C105686749), |
468
|
|
|
"match": {"in_port": 1}, |
469
|
|
|
"table_id": 3, |
470
|
|
|
"table_group": "epl", |
471
|
|
|
"priority": 10000, |
472
|
|
|
"idle_timeout": 0, |
473
|
|
|
"hard_timeout": 0, |
474
|
|
|
"instructions": [ |
475
|
|
|
{ |
476
|
|
|
"instruction_type": "apply_actions", |
477
|
|
|
"actions": [ |
478
|
|
|
{"action_type": "add_int_metadata"}, |
479
|
|
|
{"action_type": "output", "port": 20}, |
480
|
|
|
], |
481
|
|
|
} |
482
|
|
|
], |
483
|
|
|
} |
484
|
|
|
}, |
485
|
|
|
] |
486
|
|
|
|
487
|
1 |
|
expected_uni_z_source_flows = [ |
488
|
|
|
{ |
489
|
|
|
"flow": { |
490
|
|
|
"owner": "telemetry_int", |
491
|
|
|
"cookie": int(0xA83766C105686749), |
492
|
|
|
"match": {"in_port": 2, "dl_type": 2048, "nw_proto": 6}, |
493
|
|
|
"table_id": 0, |
494
|
|
|
"table_group": "epl", |
495
|
|
|
"priority": 10100, |
496
|
|
|
"idle_timeout": 0, |
497
|
|
|
"hard_timeout": 0, |
498
|
|
|
"instructions": [ |
499
|
|
|
{ |
500
|
|
|
"instruction_type": "apply_actions", |
501
|
|
|
"actions": [{"action_type": "push_int"}], |
502
|
|
|
}, |
503
|
|
|
{"instruction_type": "goto_table", "table_id": 3}, |
504
|
|
|
], |
505
|
|
|
} |
506
|
|
|
}, |
507
|
|
|
{ |
508
|
|
|
"flow": { |
509
|
|
|
"owner": "telemetry_int", |
510
|
|
|
"cookie": int(0xA83766C105686749), |
511
|
|
|
"match": { |
512
|
|
|
"in_port": 2, |
513
|
|
|
"dl_type": 2048, |
514
|
|
|
"nw_proto": 17, |
515
|
|
|
}, |
516
|
|
|
"table_id": 0, |
517
|
|
|
"table_group": "epl", |
518
|
|
|
"priority": 10100, |
519
|
|
|
"idle_timeout": 0, |
520
|
|
|
"hard_timeout": 0, |
521
|
|
|
"instructions": [ |
522
|
|
|
{ |
523
|
|
|
"instruction_type": "apply_actions", |
524
|
|
|
"actions": [{"action_type": "push_int"}], |
525
|
|
|
}, |
526
|
|
|
{"instruction_type": "goto_table", "table_id": 3}, |
527
|
|
|
], |
528
|
|
|
} |
529
|
|
|
}, |
530
|
|
|
{ |
531
|
|
|
"flow": { |
532
|
|
|
"owner": "telemetry_int", |
533
|
|
|
"cookie": int(0xA83766C105686749), |
534
|
|
|
"match": {"in_port": 2}, |
535
|
|
|
"table_id": 3, |
536
|
|
|
"table_group": "epl", |
537
|
|
|
"priority": 10000, |
538
|
|
|
"idle_timeout": 0, |
539
|
|
|
"hard_timeout": 0, |
540
|
|
|
"instructions": [ |
541
|
|
|
{ |
542
|
|
|
"instruction_type": "apply_actions", |
543
|
|
|
"actions": [ |
544
|
|
|
{"action_type": "add_int_metadata"}, |
545
|
|
|
{"action_type": "output", "port": 10}, |
546
|
|
|
], |
547
|
|
|
} |
548
|
|
|
], |
549
|
|
|
} |
550
|
|
|
}, |
551
|
|
|
] |
552
|
|
|
|
553
|
1 |
|
expected_uni_a_sink_flows = [ |
554
|
|
|
{ |
555
|
|
|
"flow": { |
556
|
|
|
"owner": "telemetry_int", |
557
|
|
|
"cookie": int(0xA83766C105686749), |
558
|
|
|
"match": {"in_port": 11}, |
559
|
|
|
"table_id": 0, |
560
|
|
|
"table_group": "epl", |
561
|
|
|
"priority": 10000, |
562
|
|
|
"idle_timeout": 0, |
563
|
|
|
"hard_timeout": 0, |
564
|
|
|
"instructions": [ |
565
|
|
|
{ |
566
|
|
|
"instruction_type": "apply_actions", |
567
|
|
|
"actions": [{"action_type": "send_report"}], |
568
|
|
|
}, |
569
|
|
|
{"instruction_type": "goto_table", "table_id": 3}, |
570
|
|
|
], |
571
|
|
|
}, |
572
|
|
|
}, |
573
|
|
|
{ |
574
|
|
|
"flow": { |
575
|
|
|
"owner": "telemetry_int", |
576
|
|
|
"cookie": int(0xA83766C105686749), |
577
|
|
|
"match": {"in_port": 11}, |
578
|
|
|
"table_id": 3, |
579
|
|
|
"table_group": "epl", |
580
|
|
|
"priority": 10000, |
581
|
|
|
"idle_timeout": 0, |
582
|
|
|
"hard_timeout": 0, |
583
|
|
|
"instructions": [ |
584
|
|
|
{ |
585
|
|
|
"instruction_type": "apply_actions", |
586
|
|
|
"actions": [ |
587
|
|
|
{"action_type": "pop_int"}, |
588
|
|
|
{"action_type": "output", "port": 1}, |
589
|
|
|
], |
590
|
|
|
} |
591
|
|
|
], |
592
|
|
|
}, |
593
|
|
|
}, |
594
|
|
|
] |
595
|
1 |
|
expected_uni_z_sink_flows = [ |
596
|
|
|
{ |
597
|
|
|
"flow": { |
598
|
|
|
"owner": "telemetry_int", |
599
|
|
|
"cookie": int(0xA83766C105686749), |
600
|
|
|
"match": {"in_port": 21}, |
601
|
|
|
"table_id": 0, |
602
|
|
|
"table_group": "epl", |
603
|
|
|
"priority": 10000, |
604
|
|
|
"idle_timeout": 0, |
605
|
|
|
"hard_timeout": 0, |
606
|
|
|
"instructions": [ |
607
|
|
|
{ |
608
|
|
|
"instruction_type": "apply_actions", |
609
|
|
|
"actions": [{"action_type": "send_report"}], |
610
|
|
|
}, |
611
|
|
|
{"instruction_type": "goto_table", "table_id": 3}, |
612
|
|
|
], |
613
|
|
|
}, |
614
|
|
|
}, |
615
|
|
|
{ |
616
|
|
|
"flow": { |
617
|
|
|
"owner": "telemetry_int", |
618
|
|
|
"cookie": int(0xA83766C105686749), |
619
|
|
|
"match": {"in_port": 21}, |
620
|
|
|
"table_id": 3, |
621
|
|
|
"table_group": "epl", |
622
|
|
|
"priority": 10000, |
623
|
|
|
"idle_timeout": 0, |
624
|
|
|
"hard_timeout": 0, |
625
|
|
|
"instructions": [ |
626
|
|
|
{ |
627
|
|
|
"instruction_type": "apply_actions", |
628
|
|
|
"actions": [ |
629
|
|
|
{"action_type": "pop_int"}, |
630
|
|
|
{"action_type": "output", "port": 2}, |
631
|
|
|
], |
632
|
|
|
} |
633
|
|
|
], |
634
|
|
|
}, |
635
|
|
|
}, |
636
|
|
|
] |
637
|
|
|
|
638
|
1 |
|
expected_flows = ( |
639
|
|
|
expected_uni_a_source_flows |
640
|
|
|
+ expected_uni_z_source_flows |
641
|
|
|
+ expected_uni_z_sink_flows |
642
|
|
|
+ expected_uni_a_sink_flows |
643
|
|
|
) |
644
|
|
|
|
645
|
1 |
|
for i, flow in enumerate(flows): |
646
|
1 |
|
assert (i, flow["flow"]) == (i, expected_flows[i]["flow"]) |
647
|
|
|
|
648
|
|
|
|
649
|
1 |
|
def test_build_int_flows_intra_epl_inactive(evcs_data) -> None: |
650
|
|
|
"""Test build INT flows intra EPL inactive. |
651
|
|
|
|
652
|
|
|
+--------+ |
653
|
|
|
| | |
654
|
|
|
10 | 11| |
655
|
|
|
+--------+--------v--+ |
656
|
|
|
| | 20 |
657
|
|
|
1 | +-----+ |
658
|
|
|
--------------+ | | |
659
|
|
|
| | | |
660
|
|
|
| sw1 | | |
661
|
|
|
2 | |21 | |
662
|
|
|
---------------+ <-----+ |
663
|
|
|
| | |
664
|
|
|
+--------------------+ |
665
|
|
|
""" |
666
|
1 |
|
controller = get_controller_mock() |
667
|
1 |
|
int_manager = INTManager(controller) |
668
|
1 |
|
get_proxy_port_or_raise = MagicMock() |
669
|
1 |
|
int_manager.get_proxy_port_or_raise = get_proxy_port_or_raise |
670
|
|
|
|
671
|
1 |
|
evc_id = "3766c105686749" |
672
|
1 |
|
dpid_a = "00:00:00:00:00:00:00:01" |
673
|
1 |
|
mock_switch_a = get_switch_mock(dpid_a, 0x04) |
674
|
1 |
|
mock_interface_a1 = get_interface_mock("s1-eth1", 1, mock_switch_a) |
675
|
1 |
|
mock_interface_a1.id = f"{dpid_a}:{mock_interface_a1.port_number}" |
676
|
1 |
|
mock_interface_a10 = get_interface_mock("s1-eth10", 10, mock_switch_a) |
677
|
1 |
|
mock_interface_a1.metadata = {"proxy_port": mock_interface_a10.port_number} |
678
|
1 |
|
mock_interface_a10.status = EntityStatus.UP |
679
|
1 |
|
mock_interface_a11 = get_interface_mock("s1-eth11", 11, mock_switch_a) |
680
|
1 |
|
mock_interface_a11.status = EntityStatus.UP |
681
|
1 |
|
mock_interface_a10.metadata = { |
682
|
|
|
"looped": { |
683
|
|
|
"port_numbers": [ |
684
|
|
|
mock_interface_a10.port_number, |
685
|
|
|
mock_interface_a11.port_number, |
686
|
|
|
] |
687
|
|
|
} |
688
|
|
|
} |
689
|
|
|
|
690
|
1 |
|
mock_interface_z1 = get_interface_mock("s1-eth2", 1, mock_switch_a) |
691
|
1 |
|
mock_interface_z1.status = EntityStatus.UP |
692
|
1 |
|
mock_interface_z1.id = f"{dpid_a}:{mock_interface_a1.port_number}" |
693
|
1 |
|
mock_interface_z20 = get_interface_mock("s1-eth20", 20, mock_switch_a) |
694
|
1 |
|
mock_interface_z1.metadata = {"proxy_port": mock_interface_z20.port_number} |
695
|
1 |
|
mock_interface_z20.status = EntityStatus.UP |
696
|
1 |
|
mock_interface_z21 = get_interface_mock("s1-eth21", 21, mock_switch_a) |
697
|
1 |
|
mock_interface_z21.status = EntityStatus.UP |
698
|
1 |
|
mock_interface_z20.metadata = { |
699
|
|
|
"looped": { |
700
|
|
|
"port_numbers": [ |
701
|
|
|
mock_interface_z20.port_number, |
702
|
|
|
mock_interface_z21.port_number, |
703
|
|
|
] |
704
|
|
|
} |
705
|
|
|
} |
706
|
|
|
|
707
|
1 |
|
mock_switch_a.get_interface_by_port_no = lambda port_no: { |
708
|
|
|
mock_interface_a10.port_number: mock_interface_a10, |
709
|
|
|
mock_interface_a11.port_number: mock_interface_a11, |
710
|
|
|
mock_interface_z20.port_number: mock_interface_z20, |
711
|
|
|
mock_interface_z21.port_number: mock_interface_z21, |
712
|
|
|
}[port_no] |
713
|
|
|
|
714
|
1 |
|
pp_a = ProxyPort(controller, source=mock_interface_a10) |
715
|
1 |
|
assert pp_a.source == mock_interface_a10 |
716
|
1 |
|
assert pp_a.destination == mock_interface_a11 |
717
|
1 |
|
pp_z = ProxyPort(controller, source=mock_interface_z20) |
718
|
1 |
|
assert pp_z.source == mock_interface_z20 |
719
|
1 |
|
assert pp_z.destination == mock_interface_z21 |
720
|
|
|
|
721
|
1 |
|
get_proxy_port_or_raise.side_effect = [pp_a, pp_z] |
722
|
1 |
|
evcs_data = {evc_id: evcs_data[evc_id]} |
723
|
|
|
|
724
|
|
|
# if it's an inactive EVC it shouldn't return any flows for this intra EPL |
725
|
1 |
|
evcs_data[evc_id]["active"] = False |
726
|
1 |
|
evcs_data = int_manager._validate_map_enable_evcs(evcs_data) |
727
|
1 |
|
stored_flows = defaultdict(list) |
728
|
1 |
|
cookie = get_cookie(evc_id, settings.MEF_COOKIE_PREFIX) |
729
|
1 |
|
flows = FlowBuilder().build_int_flows(evcs_data, stored_flows)[cookie] |
730
|
1 |
|
assert not flows |
731
|
|
|
|
732
|
|
|
# if it's active but there's no flows then it should raise FlowsNotFound |
733
|
1 |
|
evcs_data[evc_id]["active"] = True |
734
|
1 |
|
cookie = get_cookie(evc_id, settings.MEF_COOKIE_PREFIX) |
735
|
1 |
|
with pytest.raises(FlowsNotFound): |
736
|
1 |
|
int_manager._validate_evcs_stored_flows( |
737
|
|
|
evcs_data, FlowBuilder().build_int_flows(evcs_data, stored_flows) |
738
|
|
|
) |
739
|
|
|
|