test_flow_builder_inter_evc   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 946
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 640
dl 0
loc 946
ccs 94
cts 94
cp 1
rs 9.96
c 0
b 0
f 0
wmc 6

2 Functions

Rating   Name   Duplication   Size   Complexity  
B test_build_int_flows_inter_evpl_no_proxy_ports() 0 414 2
B test_build_int_flows_inter_evpl() 0 515 4
1
"""Test flow_builder."""
2
3 1
from unittest.mock import MagicMock
4 1
from napps.kytos.telemetry_int.managers.flow_builder import FlowBuilder
5 1
from napps.kytos.telemetry_int.managers.int import INTManager
6 1
from napps.kytos.telemetry_int.utils import get_cookie
7 1
from napps.kytos.telemetry_int.proxy_port import ProxyPort
8 1
from napps.kytos.telemetry_int.exceptions import ProxyPortMetadataNotFound
9 1
from napps.kytos.telemetry_int import settings
10 1
from napps.kytos.telemetry_int.kytos_api_helper import _map_stored_flows_by_cookies
11 1
from kytos.lib.helpers import get_controller_mock, get_switch_mock, get_interface_mock
12 1
from kytos.core.common import EntityStatus
13
14
15 1
def test_build_int_flows_inter_evpl(
16
    evcs_data, inter_evc_evpl_set_queue_flows_data
17
) -> None:
18
    """Test build INT flows inter EVPL.
19
20
               +----+                                              +----+
21
              5|    |6                                            5|    |6
22
           +---+----v---+            +------------+           +----+----v---+
23
        1  |            |            |            |           |             |1
24
    -------+            |3         2 |            |3        2 |             +-------
25
     vlan  |     s1     +------------+    s2      +-----------+    s3       | vlan
26
     101   |            |            |            |           |             | 102
27
           |            |            |            |           |             |
28
           +------------+            +------------+           +-------------+
29
30
    """
31 1
    controller = get_controller_mock()
32 1
    int_manager = INTManager(controller)
33 1
    get_proxy_port_or_raise = MagicMock()
34 1
    int_manager.get_proxy_port_or_raise = get_proxy_port_or_raise
35
36 1
    evc_id = "16a76ae61b2f46"
37 1
    dpid_a = "00:00:00:00:00:00:00:01"
38 1
    mock_switch_a = get_switch_mock(dpid_a, 0x04)
39 1
    mock_interface_a1 = get_interface_mock("s1-eth1", 1, mock_switch_a)
40 1
    mock_interface_a1.id = f"{dpid_a}:{mock_interface_a1.port_number}"
41 1
    mock_interface_a5 = get_interface_mock("s1-eth5", 5, mock_switch_a)
42 1
    mock_interface_a1.metadata = {"proxy_port": mock_interface_a5.port_number}
43 1
    mock_interface_a5.status = EntityStatus.UP
44 1
    mock_interface_a6 = get_interface_mock("s1-eth6", 6, mock_switch_a)
45 1
    mock_interface_a6.status = EntityStatus.UP
46 1
    mock_interface_a5.metadata = {
47
        "looped": {
48
            "port_numbers": [
49
                mock_interface_a5.port_number,
50
                mock_interface_a6.port_number,
51
            ]
52
        }
53
    }
54
55 1
    dpid_z = "00:00:00:00:00:00:00:03"
56 1
    mock_switch_z = get_switch_mock(dpid_z, 0x04)
57 1
    mock_interface_z1 = get_interface_mock("s1-eth1", 1, mock_switch_z)
58 1
    mock_interface_z1.status = EntityStatus.UP
59 1
    mock_interface_z1.id = f"{dpid_z}:{mock_interface_z1.port_number}"
60 1
    mock_interface_z5 = get_interface_mock("s1-eth5", 5, mock_switch_z)
61 1
    mock_interface_z1.metadata = {"proxy_port": mock_interface_z5.port_number}
62 1
    mock_interface_z5.status = EntityStatus.UP
63 1
    mock_interface_z6 = get_interface_mock("s1-eth6", 6, mock_switch_z)
64 1
    mock_interface_z6.status = EntityStatus.UP
65 1
    mock_interface_z5.metadata = {
66
        "looped": {
67
            "port_numbers": [
68
                mock_interface_z5.port_number,
69
                mock_interface_z6.port_number,
70
            ]
71
        }
72
    }
73
74 1
    mock_switch_a.get_interface_by_port_no = lambda port_no: {
75
        mock_interface_a5.port_number: mock_interface_a5,
76
        mock_interface_a6.port_number: mock_interface_a6,
77
    }[port_no]
78
79 1
    mock_switch_z.get_interface_by_port_no = lambda port_no: {
80
        mock_interface_z5.port_number: mock_interface_z5,
81
        mock_interface_z6.port_number: mock_interface_z6,
82
    }[port_no]
83
84 1
    pp_a = ProxyPort(source=mock_interface_a5)
85 1
    assert pp_a.source == mock_interface_a5
86 1
    assert pp_a.destination == mock_interface_a6
87 1
    pp_z = ProxyPort(source=mock_interface_z5)
88 1
    assert pp_z.source == mock_interface_z5
89 1
    assert pp_z.destination == mock_interface_z6
90
91 1
    get_proxy_port_or_raise.side_effect = [pp_a, pp_z]
92 1
    evcs_data = {evc_id: evcs_data[evc_id]}
93 1
    evcs_data = int_manager._validate_map_enable_evcs(evcs_data)
94 1
    stored_flows = _map_stored_flows_by_cookies(inter_evc_evpl_set_queue_flows_data)
95
96 1
    cookie = get_cookie(evc_id, settings.MEF_COOKIE_PREFIX)
97 1
    flows = FlowBuilder().build_int_flows(evcs_data, stored_flows)[cookie]
98
99 1
    n_expected_source_flows, n_expected_hop_flows, n_expected_sink_flows = 3, 2, 4
100 1
    assert (
101
        len(flows)
102
        == (n_expected_source_flows + n_expected_hop_flows + n_expected_sink_flows) * 2
103
    )
104
105 1
    expected_uni_a_source_flows = [
106
        {
107
            "flow": {
108
                "owner": "telemetry_int",
109
                "cookie": int(0xA816A76AE61B2F46),
110
                "match": {"in_port": 1, "dl_vlan": 101, "dl_type": 2048, "nw_proto": 6},
111
                "table_id": 0,
112
                "table_group": "evpl",
113
                "priority": 20100,
114
                "idle_timeout": 0,
115
                "hard_timeout": 0,
116
                "instructions": [
117
                    {
118
                        "instruction_type": "apply_actions",
119
                        "actions": [{"action_type": "push_int"}],
120
                    },
121
                    {"instruction_type": "goto_table", "table_id": 2},
122
                ],
123
            }
124
        },
125
        {
126
            "flow": {
127
                "owner": "telemetry_int",
128
                "cookie": int(0xA816A76AE61B2F46),
129
                "match": {
130
                    "in_port": 1,
131
                    "dl_vlan": 101,
132
                    "dl_type": 2048,
133
                    "nw_proto": 17,
134
                },
135
                "table_id": 0,
136
                "table_group": "evpl",
137
                "priority": 20100,
138
                "idle_timeout": 0,
139
                "hard_timeout": 0,
140
                "instructions": [
141
                    {
142
                        "instruction_type": "apply_actions",
143
                        "actions": [{"action_type": "push_int"}],
144
                    },
145
                    {"instruction_type": "goto_table", "table_id": 2},
146
                ],
147
            },
148
        },
149
        {
150
            "flow": {
151
                "owner": "telemetry_int",
152
                "cookie": int(0xA816A76AE61B2F46),
153
                "match": {"in_port": 1, "dl_vlan": 101},
154
                "table_id": 2,
155
                "table_group": "evpl",
156
                "priority": 20000,
157
                "idle_timeout": 0,
158
                "hard_timeout": 0,
159
                "instructions": [
160
                    {
161
                        "instruction_type": "apply_actions",
162
                        "actions": [
163
                            {"action_type": "add_int_metadata"},
164
                            {"action_type": "set_vlan", "vlan_id": 102},
165
                            {"action_type": "push_vlan", "tag_type": "s"},
166
                            {"action_type": "set_vlan", "vlan_id": 1},
167
                            {"action_type": "set_queue", "queue_id": 1},
168
                            {"action_type": "output", "port": 3},
169
                        ],
170
                    }
171
                ],
172
            },
173
        },
174
    ]
175
176 1
    expected_uni_z_source_flows = [
177
        {
178
            "flow": {
179
                "owner": "telemetry_int",
180
                "cookie": int(0xA816A76AE61B2F46),
181
                "match": {"in_port": 1, "dl_vlan": 102, "dl_type": 2048, "nw_proto": 6},
182
                "table_id": 0,
183
                "table_group": "evpl",
184
                "priority": 20100,
185
                "idle_timeout": 0,
186
                "hard_timeout": 0,
187
                "instructions": [
188
                    {
189
                        "instruction_type": "apply_actions",
190
                        "actions": [{"action_type": "push_int"}],
191
                    },
192
                    {"instruction_type": "goto_table", "table_id": 2},
193
                ],
194
            },
195
        },
196
        {
197
            "flow": {
198
                "owner": "telemetry_int",
199
                "cookie": int(0xA816A76AE61B2F46),
200
                "match": {
201
                    "in_port": 1,
202
                    "dl_vlan": 102,
203
                    "dl_type": 2048,
204
                    "nw_proto": 17,
205
                },
206
                "table_id": 0,
207
                "table_group": "evpl",
208
                "priority": 20100,
209
                "idle_timeout": 0,
210
                "hard_timeout": 0,
211
                "instructions": [
212
                    {
213
                        "instruction_type": "apply_actions",
214
                        "actions": [{"action_type": "push_int"}],
215
                    },
216
                    {"instruction_type": "goto_table", "table_id": 2},
217
                ],
218
            },
219
        },
220
        {
221
            "flow": {
222
                "owner": "telemetry_int",
223
                "cookie": int(0xA816A76AE61B2F46),
224
                "match": {"in_port": 1, "dl_vlan": 102},
225
                "table_id": 2,
226
                "table_group": "evpl",
227
                "priority": 20000,
228
                "idle_timeout": 0,
229
                "hard_timeout": 0,
230
                "instructions": [
231
                    {
232
                        "instruction_type": "apply_actions",
233
                        "actions": [
234
                            {"action_type": "add_int_metadata"},
235
                            {"action_type": "set_vlan", "vlan_id": 101},
236
                            {"action_type": "push_vlan", "tag_type": "s"},
237
                            {"action_type": "set_vlan", "vlan_id": 1},
238
                            {"action_type": "set_queue", "queue_id": 1},
239
                            {"action_type": "output", "port": 2},
240
                        ],
241
                    }
242
                ],
243
            },
244
        },
245
    ]
246
247 1
    expected_hop_flows = [
248
        {
249
            "flow": {
250
                "owner": "telemetry_int",
251
                "cookie": int(0xA816A76AE61B2F46),
252
                "match": {"in_port": 2, "dl_vlan": 1, "dl_type": 2048, "nw_proto": 6},
253
                "table_id": 0,
254
                "table_group": "evpl",
255
                "priority": 20100,
256
                "idle_timeout": 0,
257
                "hard_timeout": 0,
258
                "instructions": [
259
                    {
260
                        "instruction_type": "apply_actions",
261
                        "actions": [
262
                            {"action_type": "add_int_metadata"},
263
                            {"action_type": "set_vlan", "vlan_id": 1},
264
                            {"action_type": "set_queue", "queue_id": 1},
265
                            {"action_type": "output", "port": 3},
266
                        ],
267
                    }
268
                ],
269
            },
270
        },
271
        {
272
            "flow": {
273
                "owner": "telemetry_int",
274
                "cookie": int(0xA816A76AE61B2F46),
275
                "match": {"in_port": 2, "dl_vlan": 1, "dl_type": 2048, "nw_proto": 17},
276
                "table_id": 0,
277
                "table_group": "evpl",
278
                "priority": 20100,
279
                "idle_timeout": 0,
280
                "hard_timeout": 0,
281
                "instructions": [
282
                    {
283
                        "instruction_type": "apply_actions",
284
                        "actions": [
285
                            {"action_type": "add_int_metadata"},
286
                            {"action_type": "set_vlan", "vlan_id": 1},
287
                            {"action_type": "set_queue", "queue_id": 1},
288
                            {"action_type": "output", "port": 3},
289
                        ],
290
                    }
291
                ],
292
            },
293
        },
294
        {
295
            "flow": {
296
                "owner": "telemetry_int",
297
                "cookie": int(0xA816A76AE61B2F46),
298
                "match": {"in_port": 3, "dl_vlan": 1, "dl_type": 2048, "nw_proto": 6},
299
                "table_id": 0,
300
                "table_group": "evpl",
301
                "priority": 20100,
302
                "idle_timeout": 0,
303
                "hard_timeout": 0,
304
                "instructions": [
305
                    {
306
                        "instruction_type": "apply_actions",
307
                        "actions": [
308
                            {"action_type": "add_int_metadata"},
309
                            {"action_type": "set_vlan", "vlan_id": 1},
310
                            {"action_type": "set_queue", "queue_id": 1},
311
                            {"action_type": "output", "port": 2},
312
                        ],
313
                    }
314
                ],
315
            },
316
        },
317
        {
318
            "flow": {
319
                "owner": "telemetry_int",
320
                "cookie": int(0xA816A76AE61B2F46),
321
                "match": {"in_port": 3, "dl_vlan": 1, "dl_type": 2048, "nw_proto": 17},
322
                "table_id": 0,
323
                "table_group": "evpl",
324
                "priority": 20100,
325
                "idle_timeout": 0,
326
                "hard_timeout": 0,
327
                "instructions": [
328
                    {
329
                        "instruction_type": "apply_actions",
330
                        "actions": [
331
                            {"action_type": "add_int_metadata"},
332
                            {"action_type": "set_vlan", "vlan_id": 1},
333
                            {"action_type": "set_queue", "queue_id": 1},
334
                            {"action_type": "output", "port": 2},
335
                        ],
336
                    }
337
                ],
338
            },
339
        },
340
    ]
341
342 1
    expected_uni_z_sink_flows = [
343
        {
344
            "flow": {
345
                "owner": "telemetry_int",
346
                "cookie": int(0xA816A76AE61B2F46),
347
                "match": {"in_port": 2, "dl_vlan": 1, "dl_type": 2048, "nw_proto": 6},
348
                "table_id": 0,
349
                "table_group": "evpl",
350
                "priority": 20100,
351
                "idle_timeout": 0,
352
                "hard_timeout": 0,
353
                "instructions": [
354
                    {
355
                        "instruction_type": "apply_actions",
356
                        "actions": [
357
                            {"action_type": "add_int_metadata"},
358
                            {"action_type": "set_queue", "queue_id": 1},
359
                            {"action_type": "output", "port": 5},
360
                        ],
361
                    }
362
                ],
363
            },
364
        },
365
        {
366
            "flow": {
367
                "owner": "telemetry_int",
368
                "cookie": int(0xA816A76AE61B2F46),
369
                "match": {"in_port": 2, "dl_vlan": 1, "dl_type": 2048, "nw_proto": 17},
370
                "table_id": 0,
371
                "table_group": "evpl",
372
                "priority": 20100,
373
                "idle_timeout": 0,
374
                "hard_timeout": 0,
375
                "instructions": [
376
                    {
377
                        "instruction_type": "apply_actions",
378
                        "actions": [
379
                            {"action_type": "add_int_metadata"},
380
                            {"action_type": "set_queue", "queue_id": 1},
381
                            {"action_type": "output", "port": 5},
382
                        ],
383
                    }
384
                ],
385
            },
386
        },
387
        {
388
            "flow": {
389
                "owner": "telemetry_int",
390
                "cookie": int(0xA816A76AE61B2F46),
391
                "match": {"in_port": 6, "dl_vlan": 1},
392
                "table_id": 0,
393
                "table_group": "evpl",
394
                "priority": 20000,
395
                "idle_timeout": 0,
396
                "hard_timeout": 0,
397
                "instructions": [
398
                    {
399
                        "instruction_type": "apply_actions",
400
                        "actions": [{"action_type": "send_report"}],
401
                    },
402
                    {"instruction_type": "goto_table", "table_id": 2},
403
                ],
404
            },
405
        },
406
        {
407
            "flow": {
408
                "owner": "telemetry_int",
409
                "cookie": int(0xA816A76AE61B2F46),
410
                "match": {"in_port": 6, "dl_vlan": 1},
411
                "table_id": 2,
412
                "table_group": "evpl",
413
                "priority": 20000,
414
                "idle_timeout": 0,
415
                "hard_timeout": 0,
416
                "instructions": [
417
                    {
418
                        "instruction_type": "apply_actions",
419
                        "actions": [
420
                            {"action_type": "pop_int"},
421
                            {"action_type": "pop_vlan"},
422
                            {"action_type": "set_queue", "queue_id": 1},
423
                            {"action_type": "output", "port": 1},
424
                        ],
425
                    }
426
                ],
427
            }
428
        },
429
    ]
430
431 1
    expected_uni_a_sink_flows = [
432
        {
433
            "flow": {
434
                "owner": "telemetry_int",
435
                "cookie": int(0xA816A76AE61B2F46),
436
                "match": {"in_port": 3, "dl_vlan": 1, "dl_type": 2048, "nw_proto": 6},
437
                "table_id": 0,
438
                "table_group": "evpl",
439
                "priority": 20100,
440
                "idle_timeout": 0,
441
                "hard_timeout": 0,
442
                "instructions": [
443
                    {
444
                        "instruction_type": "apply_actions",
445
                        "actions": [
446
                            {"action_type": "add_int_metadata"},
447
                            {"action_type": "set_queue", "queue_id": 1},
448
                            {"action_type": "output", "port": 5},
449
                        ],
450
                    }
451
                ],
452
            },
453
        },
454
        {
455
            "flow": {
456
                "owner": "telemetry_int",
457
                "cookie": int(0xA816A76AE61B2F46),
458
                "match": {"in_port": 3, "dl_vlan": 1, "dl_type": 2048, "nw_proto": 17},
459
                "table_id": 0,
460
                "table_group": "evpl",
461
                "priority": 20100,
462
                "idle_timeout": 0,
463
                "hard_timeout": 0,
464
                "instructions": [
465
                    {
466
                        "instruction_type": "apply_actions",
467
                        "actions": [
468
                            {"action_type": "add_int_metadata"},
469
                            {"action_type": "set_queue", "queue_id": 1},
470
                            {"action_type": "output", "port": 5},
471
                        ],
472
                    }
473
                ],
474
            },
475
        },
476
        {
477
            "flow": {
478
                "owner": "telemetry_int",
479
                "cookie": int(0xA816A76AE61B2F46),
480
                "match": {"in_port": 6, "dl_vlan": 1},
481
                "table_id": 0,
482
                "table_group": "evpl",
483
                "priority": 20000,
484
                "idle_timeout": 0,
485
                "hard_timeout": 0,
486
                "instructions": [
487
                    {
488
                        "instruction_type": "apply_actions",
489
                        "actions": [{"action_type": "send_report"}],
490
                    },
491
                    {"instruction_type": "goto_table", "table_id": 2},
492
                ],
493
            },
494
        },
495
        {
496
            "flow": {
497
                "owner": "telemetry_int",
498
                "cookie": int(0xA816A76AE61B2F46),
499
                "match": {"in_port": 6, "dl_vlan": 1},
500
                "table_id": 2,
501
                "table_group": "evpl",
502
                "priority": 20000,
503
                "idle_timeout": 0,
504
                "hard_timeout": 0,
505
                "instructions": [
506
                    {
507
                        "instruction_type": "apply_actions",
508
                        "actions": [
509
                            {"action_type": "pop_int"},
510
                            {"action_type": "pop_vlan"},
511
                            {"action_type": "set_queue", "queue_id": 1},
512
                            {"action_type": "output", "port": 1},
513
                        ],
514
                    }
515
                ],
516
            },
517
        },
518
    ]
519
520 1
    expected_flows = (
521
        expected_uni_a_source_flows
522
        + expected_uni_z_source_flows
523
        + expected_hop_flows
524
        + expected_uni_z_sink_flows
525
        + expected_uni_a_sink_flows
526
    )
527
528 1
    for i, flow in enumerate(flows):
529 1
        assert (i, flow["flow"]) == (i, expected_flows[i]["flow"])
530
531
532 1
def test_build_int_flows_inter_evpl_no_proxy_ports(
533
    evcs_data, inter_evc_evpl_flows_data
534
) -> None:
535
    """Test build INT flows inter EVPL.
536
537
           +---+----v---+            +------------+           +----+----v---+
538
        1  |            |            |            |           |             |1
539
    -------+            |3         2 |            |3        2 |             +-------
540
     vlan  |     s1     +------------+    s2      +-----------+    s3       | vlan
541
     101   |            |            |            |           |             | 102
542
           |            |            |            |           |             |
543
           +------------+            +------------+           +-------------+
544
545
    """
546 1
    controller = get_controller_mock()
547 1
    int_manager = INTManager(controller)
548 1
    get_proxy_port_or_raise = MagicMock()
549 1
    exc = ProxyPortMetadataNotFound("evc_id", "not found")
550 1
    get_proxy_port_or_raise.side_effect = exc
551 1
    int_manager.get_proxy_port_or_raise = get_proxy_port_or_raise
552
553 1
    evc_id = "16a76ae61b2f46"
554 1
    dpid_a = "00:00:00:00:00:00:00:01"
555 1
    mock_switch_a = get_switch_mock(dpid_a, 0x04)
556 1
    mock_interface_a1 = get_interface_mock("s1-eth1", 1, mock_switch_a)
557 1
    mock_interface_a1.status = EntityStatus.UP
558 1
    mock_interface_a1.id = f"{dpid_a}:{mock_interface_a1.port_number}"
559
560 1
    dpid_z = "00:00:00:00:00:00:00:03"
561 1
    mock_switch_z = get_switch_mock(dpid_z, 0x04)
562 1
    mock_interface_z1 = get_interface_mock("s1-eth1", 1, mock_switch_z)
563 1
    mock_interface_z1.status = EntityStatus.UP
564 1
    mock_interface_z1.id = f"{dpid_z}:{mock_interface_z1.port_number}"
565
566 1
    evcs_data = {evc_id: evcs_data[evc_id]}
567 1
    evcs_data = int_manager._validate_map_enable_evcs(evcs_data)
568 1
    stored_flows = _map_stored_flows_by_cookies(inter_evc_evpl_flows_data)
569
570 1
    cookie = get_cookie(evc_id, settings.MEF_COOKIE_PREFIX)
571 1
    flows = FlowBuilder().build_int_flows(evcs_data, stored_flows)[cookie]
572
573 1
    n_expected_source_flows, n_expected_hop_flows, n_expected_sink_flows = 3, 2, 3
574 1
    assert (
575
        len(flows)
576
        == (n_expected_source_flows + n_expected_hop_flows + n_expected_sink_flows) * 2
577
    )
578
579 1
    expected_uni_a_source_flows = [
580
        {
581
            "flow": {
582
                "owner": "telemetry_int",
583
                "cookie": int(0xA816A76AE61B2F46),
584
                "match": {"in_port": 1, "dl_vlan": 101, "dl_type": 2048, "nw_proto": 6},
585
                "table_id": 0,
586
                "table_group": "evpl",
587
                "priority": 20100,
588
                "idle_timeout": 0,
589
                "hard_timeout": 0,
590
                "instructions": [
591
                    {
592
                        "instruction_type": "apply_actions",
593
                        "actions": [{"action_type": "push_int"}],
594
                    },
595
                    {"instruction_type": "goto_table", "table_id": 2},
596
                ],
597
            }
598
        },
599
        {
600
            "flow": {
601
                "owner": "telemetry_int",
602
                "cookie": int(0xA816A76AE61B2F46),
603
                "match": {
604
                    "in_port": 1,
605
                    "dl_vlan": 101,
606
                    "dl_type": 2048,
607
                    "nw_proto": 17,
608
                },
609
                "table_id": 0,
610
                "table_group": "evpl",
611
                "priority": 20100,
612
                "idle_timeout": 0,
613
                "hard_timeout": 0,
614
                "instructions": [
615
                    {
616
                        "instruction_type": "apply_actions",
617
                        "actions": [{"action_type": "push_int"}],
618
                    },
619
                    {"instruction_type": "goto_table", "table_id": 2},
620
                ],
621
            },
622
        },
623
        {
624
            "flow": {
625
                "owner": "telemetry_int",
626
                "cookie": int(0xA816A76AE61B2F46),
627
                "match": {"in_port": 1, "dl_vlan": 101},
628
                "table_id": 2,
629
                "table_group": "evpl",
630
                "priority": 20000,
631
                "idle_timeout": 0,
632
                "hard_timeout": 0,
633
                "instructions": [
634
                    {
635
                        "instruction_type": "apply_actions",
636
                        "actions": [
637
                            {"action_type": "add_int_metadata"},
638
                            {"action_type": "set_vlan", "vlan_id": 102},
639
                            {"action_type": "push_vlan", "tag_type": "s"},
640
                            {"action_type": "set_vlan", "vlan_id": 1},
641
                            {"action_type": "output", "port": 3},
642
                        ],
643
                    }
644
                ],
645
            },
646
        },
647
    ]
648
649 1
    expected_uni_z_source_flows = [
650
        {
651
            "flow": {
652
                "owner": "telemetry_int",
653
                "cookie": int(0xA816A76AE61B2F46),
654
                "match": {"in_port": 1, "dl_vlan": 102, "dl_type": 2048, "nw_proto": 6},
655
                "table_id": 0,
656
                "table_group": "evpl",
657
                "priority": 20100,
658
                "idle_timeout": 0,
659
                "hard_timeout": 0,
660
                "instructions": [
661
                    {
662
                        "instruction_type": "apply_actions",
663
                        "actions": [{"action_type": "push_int"}],
664
                    },
665
                    {"instruction_type": "goto_table", "table_id": 2},
666
                ],
667
            },
668
        },
669
        {
670
            "flow": {
671
                "owner": "telemetry_int",
672
                "cookie": int(0xA816A76AE61B2F46),
673
                "match": {
674
                    "in_port": 1,
675
                    "dl_vlan": 102,
676
                    "dl_type": 2048,
677
                    "nw_proto": 17,
678
                },
679
                "table_id": 0,
680
                "table_group": "evpl",
681
                "priority": 20100,
682
                "idle_timeout": 0,
683
                "hard_timeout": 0,
684
                "instructions": [
685
                    {
686
                        "instruction_type": "apply_actions",
687
                        "actions": [{"action_type": "push_int"}],
688
                    },
689
                    {"instruction_type": "goto_table", "table_id": 2},
690
                ],
691
            },
692
        },
693
        {
694
            "flow": {
695
                "owner": "telemetry_int",
696
                "cookie": int(0xA816A76AE61B2F46),
697
                "match": {"in_port": 1, "dl_vlan": 102},
698
                "table_id": 2,
699
                "table_group": "evpl",
700
                "priority": 20000,
701
                "idle_timeout": 0,
702
                "hard_timeout": 0,
703
                "instructions": [
704
                    {
705
                        "instruction_type": "apply_actions",
706
                        "actions": [
707
                            {"action_type": "add_int_metadata"},
708
                            {"action_type": "set_vlan", "vlan_id": 101},
709
                            {"action_type": "push_vlan", "tag_type": "s"},
710
                            {"action_type": "set_vlan", "vlan_id": 1},
711
                            {"action_type": "output", "port": 2},
712
                        ],
713
                    }
714
                ],
715
            },
716
        },
717
    ]
718
719 1
    expected_hop_flows = [
720
        {
721
            "flow": {
722
                "owner": "telemetry_int",
723
                "cookie": int(0xA816A76AE61B2F46),
724
                "match": {"in_port": 2, "dl_vlan": 1, "dl_type": 2048, "nw_proto": 6},
725
                "table_id": 0,
726
                "table_group": "evpl",
727
                "priority": 20100,
728
                "idle_timeout": 0,
729
                "hard_timeout": 0,
730
                "instructions": [
731
                    {
732
                        "instruction_type": "apply_actions",
733
                        "actions": [
734
                            {"action_type": "add_int_metadata"},
735
                            {"action_type": "set_vlan", "vlan_id": 1},
736
                            {"action_type": "output", "port": 3},
737
                        ],
738
                    }
739
                ],
740
            },
741
        },
742
        {
743
            "flow": {
744
                "owner": "telemetry_int",
745
                "cookie": int(0xA816A76AE61B2F46),
746
                "match": {"in_port": 2, "dl_vlan": 1, "dl_type": 2048, "nw_proto": 17},
747
                "table_id": 0,
748
                "table_group": "evpl",
749
                "priority": 20100,
750
                "idle_timeout": 0,
751
                "hard_timeout": 0,
752
                "instructions": [
753
                    {
754
                        "instruction_type": "apply_actions",
755
                        "actions": [
756
                            {"action_type": "add_int_metadata"},
757
                            {"action_type": "set_vlan", "vlan_id": 1},
758
                            {"action_type": "output", "port": 3},
759
                        ],
760
                    }
761
                ],
762
            },
763
        },
764
        {
765
            "flow": {
766
                "owner": "telemetry_int",
767
                "cookie": int(0xA816A76AE61B2F46),
768
                "match": {"in_port": 3, "dl_vlan": 1, "dl_type": 2048, "nw_proto": 6},
769
                "table_id": 0,
770
                "table_group": "evpl",
771
                "priority": 20100,
772
                "idle_timeout": 0,
773
                "hard_timeout": 0,
774
                "instructions": [
775
                    {
776
                        "instruction_type": "apply_actions",
777
                        "actions": [
778
                            {"action_type": "add_int_metadata"},
779
                            {"action_type": "set_vlan", "vlan_id": 1},
780
                            {"action_type": "output", "port": 2},
781
                        ],
782
                    }
783
                ],
784
            },
785
        },
786
        {
787
            "flow": {
788
                "owner": "telemetry_int",
789
                "cookie": int(0xA816A76AE61B2F46),
790
                "match": {"in_port": 3, "dl_vlan": 1, "dl_type": 2048, "nw_proto": 17},
791
                "table_id": 0,
792
                "table_group": "evpl",
793
                "priority": 20100,
794
                "idle_timeout": 0,
795
                "hard_timeout": 0,
796
                "instructions": [
797
                    {
798
                        "instruction_type": "apply_actions",
799
                        "actions": [
800
                            {"action_type": "add_int_metadata"},
801
                            {"action_type": "set_vlan", "vlan_id": 1},
802
                            {"action_type": "output", "port": 2},
803
                        ],
804
                    }
805
                ],
806
            },
807
        },
808
    ]
809
810 1
    expected_uni_z_sink_flows = [
811
        {
812
            "flow": {
813
                "owner": "telemetry_int",
814
                "cookie": int(0xA816A76AE61B2F46),
815
                "match": {"in_port": 2, "dl_vlan": 1, "dl_type": 2048, "nw_proto": 6},
816
                "table_id": 0,
817
                "table_group": "evpl",
818
                "priority": 20100,
819
                "idle_timeout": 0,
820
                "hard_timeout": 0,
821
                "instructions": [
822
                    {
823
                        "instruction_type": "apply_actions",
824
                        "actions": [{"action_type": "send_report"}],
825
                    },
826
                    {"instruction_type": "goto_table", "table_id": 2},
827
                ],
828
            },
829
        },
830
        {
831
            "flow": {
832
                "owner": "telemetry_int",
833
                "cookie": int(0xA816A76AE61B2F46),
834
                "match": {"in_port": 2, "dl_vlan": 1, "dl_type": 2048, "nw_proto": 17},
835
                "table_id": 0,
836
                "table_group": "evpl",
837
                "priority": 20100,
838
                "idle_timeout": 0,
839
                "hard_timeout": 0,
840
                "instructions": [
841
                    {
842
                        "instruction_type": "apply_actions",
843
                        "actions": [{"action_type": "send_report"}],
844
                    },
845
                    {"instruction_type": "goto_table", "table_id": 2},
846
                ],
847
            },
848
        },
849
        {
850
            "flow": {
851
                "owner": "telemetry_int",
852
                "cookie": int(0xA816A76AE61B2F46),
853
                "match": {"in_port": 2, "dl_vlan": 1},
854
                "table_id": 2,
855
                "table_group": "evpl",
856
                "priority": 20000,
857
                "idle_timeout": 0,
858
                "hard_timeout": 0,
859
                "instructions": [
860
                    {
861
                        "instruction_type": "apply_actions",
862
                        "actions": [
863
                            {"action_type": "pop_int"},
864
                            {"action_type": "pop_vlan"},
865
                            {"action_type": "output", "port": 1},
866
                        ],
867
                    }
868
                ],
869
            }
870
        },
871
    ]
872
873 1
    expected_uni_a_sink_flows = [
874
        {
875
            "flow": {
876
                "owner": "telemetry_int",
877
                "cookie": int(0xA816A76AE61B2F46),
878
                "match": {"in_port": 3, "dl_vlan": 1, "dl_type": 2048, "nw_proto": 6},
879
                "table_id": 0,
880
                "table_group": "evpl",
881
                "priority": 20100,
882
                "idle_timeout": 0,
883
                "hard_timeout": 0,
884
                "instructions": [
885
                    {
886
                        "instruction_type": "apply_actions",
887
                        "actions": [{"action_type": "send_report"}],
888
                    },
889
                    {"instruction_type": "goto_table", "table_id": 2},
890
                ],
891
            },
892
        },
893
        {
894
            "flow": {
895
                "owner": "telemetry_int",
896
                "cookie": int(0xA816A76AE61B2F46),
897
                "match": {"in_port": 3, "dl_vlan": 1, "dl_type": 2048, "nw_proto": 17},
898
                "table_id": 0,
899
                "table_group": "evpl",
900
                "priority": 20100,
901
                "idle_timeout": 0,
902
                "hard_timeout": 0,
903
                "instructions": [
904
                    {
905
                        "instruction_type": "apply_actions",
906
                        "actions": [{"action_type": "send_report"}],
907
                    },
908
                    {"instruction_type": "goto_table", "table_id": 2},
909
                ],
910
            },
911
        },
912
        {
913
            "flow": {
914
                "owner": "telemetry_int",
915
                "cookie": int(0xA816A76AE61B2F46),
916
                "match": {"in_port": 3, "dl_vlan": 1},
917
                "table_id": 2,
918
                "table_group": "evpl",
919
                "priority": 20000,
920
                "idle_timeout": 0,
921
                "hard_timeout": 0,
922
                "instructions": [
923
                    {
924
                        "instruction_type": "apply_actions",
925
                        "actions": [
926
                            {"action_type": "pop_int"},
927
                            {"action_type": "pop_vlan"},
928
                            {"action_type": "output", "port": 1},
929
                        ],
930
                    }
931
                ],
932
            },
933
        },
934
    ]
935
936 1
    expected_flows = (
937
        expected_uni_a_source_flows
938
        + expected_uni_z_source_flows
939
        + expected_hop_flows
940
        + expected_uni_z_sink_flows
941
        + expected_uni_a_sink_flows
942
    )
943
944 1
    for i, flow in enumerate(flows):
945
        assert (i, flow["flow"]) == (i, expected_flows[i]["flow"])
946