1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
|
#!/usr/bin/env python
# SPDX-License-Identifier: ISC
#
# test_ospf_prefix_suppression.py
#
# Copyright (c) 2023 LabN Consulting
# Acee Lindem
#
import os
import sys
from functools import partial
import pytest
# pylint: disable=C0413
# Import topogen and topotest helpers
from lib import topotest
from lib.topogen import Topogen, get_topogen
from lib.topolog import logger
from lib.common_config import (
step,
)
"""
test_ospf_metric_propagation.py: Test OSPF/BGP metric propagation
"""
TOPOLOGY = """
+-----+ +-----+ +-----+
eth4 | | eth0 | | eth4 eth0 | |
------+ +-------------+ +--------------+ |
10.1.7.0/24 | | 10.1.1.0/24 | | 10.1.5.0/24 | |
| | | |.2 .3| |
| | eth1 | | | |
| +-------------+ | | |
| R1 | 10.1.2.0/24 | R2 | | R3 |
| | | | | |
| | eth2 | | | |
| +-------------+ | | |
| | 10.1.3.0/24 | | | |
| | | | | |
| | eth3 | | eth5 eth1 | |
| +-------------+ +--------------+ |
| | 10.1.4.0/24 | | 10.1.6.0/24 | |
.1 +-----+.1 .2+-----+.2 .3+-----+
"""
# Save the Current Working Directory to find configuration files.
CWD = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(CWD, "../"))
# Required to instantiate the topology builder class.
pytestmark = [pytest.mark.ospfd, pytest.mark.bgpd]
def build_topo(tgen):
"Build function"
# Create 3 routers
tgen.add_router("r1")
tgen.add_router("r2")
tgen.add_router("r3")
# Interconect router 1, 2 (0)
switch = tgen.add_switch("s1-1-2")
switch.add_link(tgen.gears["r1"])
switch.add_link(tgen.gears["r2"])
# Interconect router 1, 2 (1)
switch = tgen.add_switch("s2-1-2")
switch.add_link(tgen.gears["r1"])
switch.add_link(tgen.gears["r2"])
# Interconect router 1, 2 (2)
switch = tgen.add_switch("s3-1-2")
switch.add_link(tgen.gears["r1"])
switch.add_link(tgen.gears["r2"])
# Interconect router 1, 2 (3)
switch = tgen.add_switch("s4-1-2")
switch.add_link(tgen.gears["r1"])
switch.add_link(tgen.gears["r2"])
# Interconect router 2, 3 (0)
switch = tgen.add_switch("s5-2-3")
switch.add_link(tgen.gears["r2"])
switch.add_link(tgen.gears["r3"])
# Interconect router 2, 3 (1)
switch = tgen.add_switch("s6-2-3")
switch.add_link(tgen.gears["r2"])
switch.add_link(tgen.gears["r3"])
# Add standalone network to router 1
switch = tgen.add_switch("s7-1")
switch.add_link(tgen.gears["r1"])
def setup_module(mod):
logger.info("OSPF Prefix Suppression:\n {}".format(TOPOLOGY))
tgen = Topogen(build_topo, mod.__name__)
tgen.start_topology()
# Starting Routers
router_list = tgen.routers()
for rname, router in router_list.items():
logger.info("Loading router %s" % rname)
router.load_frr_config(os.path.join(CWD, "{}/frr.conf".format(rname)))
# Initialize all routers.
tgen.start_router()
def teardown_module():
"Teardown the pytest environment"
tgen = get_topogen()
tgen.stop_topology()
def test_all_routes_advertised():
tgen = get_topogen()
if tgen.routers_have_failure():
pytest.skip("Skipped because of router(s) failure")
# Verify OSPF routes are installed
r3 = tgen.gears["r3"]
input_dict = {
"10.1.1.0/24": [
{
"prefix": "10.1.1.0/24",
"prefixLen": 24,
"protocol": "ospf",
"nexthops": [
{
"ip": "10.1.5.2",
"interfaceName": "r3-eth0",
}
],
}
]
}
test_func = partial(
topotest.router_json_cmp, r3, "show ip route 10.1.1.0/24 json", input_dict
)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
assertmsg = "10.1.1.0/24 not installed on router r3"
assert result is None, assertmsg
input_dict = {
"10.1.2.0/24": [
{
"prefix": "10.1.2.0/24",
"prefixLen": 24,
"protocol": "ospf",
"nexthops": [
{
"ip": "10.1.5.2",
"interfaceName": "r3-eth0",
}
],
}
]
}
test_func = partial(
topotest.router_json_cmp, r3, "show ip route 10.1.2.0/24 json", input_dict
)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
assertmsg = "10.1.2.0/24 not installed on router r3"
assert result is None, assertmsg
input_dict = {
"10.1.3.0/24": [
{
"prefix": "10.1.3.0/24",
"prefixLen": 24,
"protocol": "ospf",
"nexthops": [
{
"ip": "10.1.5.2",
"interfaceName": "r3-eth0",
}
],
}
]
}
test_func = partial(
topotest.router_json_cmp, r3, "show ip route 10.1.3.0/24 json", input_dict
)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
assertmsg = "10.1.3.0/24 not installed on router r3"
assert result is None, assertmsg
input_dict = {
"10.1.4.1/32": [
{
"prefix": "10.1.4.1/32",
"prefixLen": 32,
"protocol": "ospf",
"nexthops": [
{
"ip": "10.1.5.2",
"interfaceName": "r3-eth0",
}
],
}
]
}
test_func = partial(
topotest.router_json_cmp, r3, "show ip route 10.1.4.1/32 json", input_dict
)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
assertmsg = "10.1.4.1/32 not installed on router r3"
assert result is None, assertmsg
input_dict = {
"10.1.4.2/32": [
{
"prefix": "10.1.4.2/32",
"prefixLen": 32,
"protocol": "ospf",
"nexthops": [
{
"ip": "10.1.5.2",
"interfaceName": "r3-eth0",
}
],
}
]
}
test_func = partial(
topotest.router_json_cmp, r3, "show ip route 10.1.4.2/32 json", input_dict
)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
assertmsg = "10.1.4.2/32 not installed on router r3"
assert result is None, assertmsg
input_dict = {
"10.1.7.0/24": [
{
"prefix": "10.1.7.0/24",
"prefixLen": 24,
"protocol": "ospf",
"nexthops": [
{
"ip": "10.1.5.2",
"interfaceName": "r3-eth0",
}
],
}
]
}
test_func = partial(
topotest.router_json_cmp, r3, "show ip route 10.1.7.0/24 json", input_dict
)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
assertmsg = "10.1.7.0/24 not installed on router r3"
assert result is None, assertmsg
input_dict = {}
test_func = partial(
topotest.router_json_cmp, r3, "show ip route 10.1.8.0/24 json", input_dict, True
)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
assertmsg = "10.1.8.0/24 installed on router r3"
assert result is None, assertmsg
def test_broadcast_stub_suppression():
tgen = get_topogen()
if tgen.routers_have_failure():
pytest.skip("Skipped because of router(s) failure")
step("Configure R1 interface r1-eth4 with prefix suppression")
r1 = tgen.gears["r1"]
r1.vtysh_cmd("conf t\ninterface r1-eth4\nip ospf prefix-suppression")
step("Verify the R1 configuration of 'ip ospf prefix-suppression'")
prefix_suppression_cfg = (
tgen.net["r1"]
.cmd('vtysh -c "show running ospfd" | grep "^ ip ospf prefix-suppression"')
.rstrip()
)
assertmsg = "'ip ospf prefix-suppression' applied, but not present in configuration"
assert prefix_suppression_cfg == " ip ospf prefix-suppression", assertmsg
step("Verify that ospf-prefix suppression is applied to the R1 interface")
r1_eth4_with_prefix_suppression = {
"interfaces": {
"r1-eth4": {
"ifUp": True,
"ospfEnabled": True,
"ipAddress": "10.1.7.1",
"ospfIfType": "Broadcast",
"prefixSuppression": True,
}
}
}
test_func = partial(
topotest.router_json_cmp,
r1,
"show ip ospf interface r1-eth4 json",
r1_eth4_with_prefix_suppression,
)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
assertmsg = "R1 OSPF interface r1-eth4 doesn't have prefix-suppression enabled"
assert result is None, assertmsg
step(
"Verify that ospf-prefix suppression is applied to the R1 interface (non-JSON)"
)
prefix_suppression_show = (
tgen.net["r1"]
.cmd(
'vtysh -c "show ip ospf interface r1-eth4" | grep "^ Suppress advertisement of interface IP prefix"'
)
.rstrip()
)
assertmsg = (
"'ip ospf prefix-suppression' applied, but not present in interface show"
)
assert (
prefix_suppression_show == " Suppress advertisement of interface IP prefix"
), assertmsg
step("Verify the ospf prefix is not advertised and not present on r3")
r3 = tgen.gears["r3"]
input_dict = {}
test_func = partial(
topotest.router_json_cmp, r3, "show ip route 10.1.7.0/24 json", input_dict, True
)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
assertmsg = "10.1.7.0/24 installed on router r3"
assert result is None, assertmsg
step("Remove R1 interface r1-eth4 prefix-suppression configuration")
r1 = tgen.gears["r1"]
r1.vtysh_cmd("conf t\ninterface r1-eth4\nno ip ospf prefix-suppression")
step("Verify no R1 configuration of 'ip ospf prefix-suppression")
rc, _, _ = tgen.net["r1"].cmd_status(
"show running ospfd | grep -q 'ip ospf prefix-suppression'", warn=False
)
assertmsg = (
"'ip ospf prefix-suppression' not applied, but present in R1 configuration"
)
assert rc, assertmsg
step("Verify that ospf-prefix suppression is not applied to the R1 interface")
r1_eth4_without_prefix_suppression = {
"interfaces": {
"r1-eth4": {
"ifUp": True,
"ospfEnabled": True,
"ipAddress": "10.1.7.1",
"ospfIfType": "Broadcast",
"prefixSuppression": False,
}
}
}
test_func = partial(
topotest.router_json_cmp,
r1,
"show ip ospf interface r1-eth4 json",
r1_eth4_without_prefix_suppression,
)
step("Verify that 10.1.7.0/24 route is now installed on R3")
input_dict = {
"10.1.7.0/24": [
{
"prefix": "10.1.7.0/24",
"prefixLen": 24,
"protocol": "ospf",
"nexthops": [
{
"ip": "10.1.5.2",
"interfaceName": "r3-eth0",
}
],
}
]
}
test_func = partial(
topotest.router_json_cmp, r3, "show ip route 10.1.7.0/24 json", input_dict
)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
assertmsg = "10.1.7.0/24 not installed on router r3"
assert result is None, assertmsg
def test_broadcast_transit_suppression():
tgen = get_topogen()
if tgen.routers_have_failure():
pytest.skip("Skipped because of router(s) failure")
step(
"Configure R1 interface r1-eth0 with prefix suppression using interface address"
)
r1 = tgen.gears["r1"]
r1.vtysh_cmd("conf t\ninterface r1-eth0\nip ospf prefix-suppression 10.1.1.1")
step("Verify the R1 configuration of 'ip ospf prefix-suppression 10.1.1.1'")
prefix_suppression_cfg = (
tgen.net["r1"]
.cmd(
'vtysh -c "show running ospfd" | grep "^ ip ospf prefix-suppression 10.1.1.1"'
)
.rstrip()
)
assertmsg = "'ip ospf prefix-suppression 10.1.1.1' applied, but not present in configuration"
assert prefix_suppression_cfg == " ip ospf prefix-suppression 10.1.1.1", assertmsg
step(
"Configure R2 interface r2-eth0 with prefix suppression using interface address"
)
r2 = tgen.gears["r2"]
r2.vtysh_cmd("conf t\ninterface r2-eth0\nip ospf prefix-suppression 10.1.1.2")
step("Verify that ospf-prefix suppression is applied to the R1 interface")
r1_eth0_with_prefix_suppression = {
"interfaces": {
"r1-eth0": {
"ifUp": True,
"ospfEnabled": True,
"ipAddress": "10.1.1.1",
"ospfIfType": "Broadcast",
"networkType": "BROADCAST",
"prefixSuppression": True,
}
}
}
test_func = partial(
topotest.router_json_cmp,
r1,
"show ip ospf interface r1-eth0 json",
r1_eth0_with_prefix_suppression,
)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
assertmsg = "R1 OSPF interface r1-eth0 doesn't have prefix-suppression enabled"
assert result is None, assertmsg
step("Verify the OSPF prefix is not advertised and not present on r3")
r3 = tgen.gears["r3"]
input_dict = {}
test_func = partial(
topotest.router_json_cmp, r3, "show ip route 10.1.1.0/24 json", input_dict, True
)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
assertmsg = "10.1.1.0/24 installed on router r3"
assert result is None, assertmsg
step("Verify the OSPF Network-LSA prefixes are also not present on R3 ")
test_func = partial(
topotest.router_json_cmp, r3, "show ip route 10.1.1.1/24 json", input_dict, True
)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
assertmsg = "10.1.1.1/24 installed on router r3"
assert result is None, assertmsg
test_func = partial(
topotest.router_json_cmp, r3, "show ip route 10.1.1.2/24 json", input_dict, True
)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
assertmsg = "10.1.1.2/24 installed on router r3"
assert result is None, assertmsg
step(
"Remove R1 interface r1-eth0 prefix-suppression configuration using interface address"
)
r1 = tgen.gears["r1"]
r1.vtysh_cmd("conf t\ninterface r1-eth0\nno ip ospf prefix-suppression 10.1.1.1")
step(
"Remove R2 interface r2-eth0 prefix-suppression configuration using interface address"
)
r2 = tgen.gears["r2"]
r2.vtysh_cmd("conf t\ninterface r2-eth0\nno ip ospf prefix-suppression 10.1.1.2")
step("Verify no R1 configuration of 'ip ospf prefix-suppression")
rc, _, _ = tgen.net["r1"].cmd_status(
"show running ospfd | grep -q 'ip ospf prefix-suppression 10.1.1.1'", warn=False
)
assertmsg = "'ip ospf prefix-suppression 10.1.1.1' not applied, but present in R1 configuration"
assert rc, assertmsg
step("Verify that ospf-prefix suppression is not applied to the R1 interface")
r1_eth0_without_prefix_suppression = {
"interfaces": {
"r1-eth0": {
"ifUp": True,
"ospfEnabled": True,
"ipAddress": "10.1.1.1",
"ospfIfType": "Broadcast",
"networkType": "BROADCAST",
"prefixSuppression": False,
}
}
}
test_func = partial(
topotest.router_json_cmp,
r1,
"show ip ospf interface r1-eth0 json",
r1_eth0_without_prefix_suppression,
)
step("Verify that 10.1.1.0/24 route is now installed on R3")
input_dict = {
"10.1.1.0/24": [
{
"prefix": "10.1.1.0/24",
"prefixLen": 24,
"protocol": "ospf",
"nexthops": [
{
"ip": "10.1.5.2",
"interfaceName": "r3-eth0",
}
],
}
]
}
test_func = partial(
topotest.router_json_cmp, r3, "show ip route 10.1.1.0/24 json", input_dict
)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
assertmsg = "10.1.1.0/24 not installed on router r3"
assert result is None, assertmsg
def test_nbma_transit_suppression():
tgen = get_topogen()
if tgen.routers_have_failure():
pytest.skip("Skipped because of router(s) failure")
step("Configure R1 interface r1-eth1 with prefix suppression")
r1 = tgen.gears["r1"]
r1.vtysh_cmd("conf t\ninterface r1-eth1\nip ospf prefix-suppression")
step("Configure R2 interface r2-eth1 with prefix suppression")
r2 = tgen.gears["r2"]
r2.vtysh_cmd("conf t\ninterface r2-eth1\nip ospf prefix-suppression")
step("Verify that ospf-prefix suppression is applied to the R1 interface")
r1_eth1_with_prefix_suppression = {
"interfaces": {
"r1-eth1": {
"ifUp": True,
"ospfEnabled": True,
"ipAddress": "10.1.2.1",
"ospfIfType": "Broadcast",
"networkType": "NBMA",
"prefixSuppression": True,
}
}
}
test_func = partial(
topotest.router_json_cmp,
r1,
"show ip ospf interface r1-eth1 json",
r1_eth1_with_prefix_suppression,
)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
assertmsg = "R1 OSPF interface r1-eth1 doesn't have prefix-suppression enabled"
assert result is None, assertmsg
step("Verify the OSPF prefix is not advertised and not present on r3")
r3 = tgen.gears["r3"]
input_dict = {}
test_func = partial(
topotest.router_json_cmp, r3, "show ip route 10.1.2.0/24 json", input_dict, True
)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
assertmsg = "10.1.2.0/24 installed on router r3"
assert result is None, assertmsg
step("Verify the OSPF Network-LSA prefixes are also not present on R3 ")
test_func = partial(
topotest.router_json_cmp, r3, "show ip route 10.1.2.1/24 json", input_dict, True
)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
assertmsg = "10.1.2.1/24 installed on router r3"
assert result is None, assertmsg
test_func = partial(
topotest.router_json_cmp, r3, "show ip route 10.1.2.2/24 json", input_dict, True
)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
assertmsg = "10.1.2.2/24 installed on router r3"
assert result is None, assertmsg
step("Remove R1 interface r1-eth1 prefix-suppression configuration")
r1 = tgen.gears["r1"]
r1.vtysh_cmd("conf t\ninterface r1-eth1\nno ip ospf prefix-suppression")
step("Remove R2 interface eth1 prefix-suppression configuration")
r2 = tgen.gears["r2"]
r2.vtysh_cmd("conf t\ninterface r2-eth1\nno ip ospf prefix-suppression")
step("Verify no R1 configuration of 'ip ospf prefix-suppression")
rc, _, _ = tgen.net["r1"].cmd_status(
"show running ospfd | grep -q 'ip ospf prefix-suppression'", warn=False
)
assertmsg = (
"'ip ospf prefix-suppression' not applied, but present in R1 configuration"
)
assert rc, assertmsg
step("Verify that ospf-prefix suppression is not applied to the R1 interface")
r1_eth1_without_prefix_suppression = {
"interfaces": {
"r1-eth1": {
"ifUp": True,
"ospfEnabled": True,
"ipAddress": "10.1.2.1",
"ospfIfType": "Broadcast",
"networkType": "NBMA",
"prefixSuppression": False,
}
}
}
test_func = partial(
topotest.router_json_cmp,
r1,
"show ip ospf interface r1-eth1 json",
r1_eth1_without_prefix_suppression,
)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
assertmsg = "Prefix suppression on interface r1-eth1"
assert result is None, assertmsg
step("Verify that 10.1.2.0/24 route is now installed on R3")
input_dict = {
"10.1.2.0/24": [
{
"prefix": "10.1.2.0/24",
"prefixLen": 24,
"protocol": "ospf",
"nexthops": [
{
"ip": "10.1.5.2",
"interfaceName": "r3-eth0",
}
],
}
]
}
test_func = partial(
topotest.router_json_cmp, r3, "show ip route 10.1.2.0/24 json", input_dict
)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
assertmsg = "10.1.2.0/24 not installed on router r3"
assert result is None, assertmsg
def test_p2p_suppression():
tgen = get_topogen()
if tgen.routers_have_failure():
pytest.skip("Skipped because of router(s) failure")
step(
"Configure R1 interface r1-eth2 with prefix suppression with interface address"
)
r1 = tgen.gears["r1"]
r1.vtysh_cmd("conf t\ninterface r1-eth2\nip ospf prefix-suppression 10.1.3.1")
step(
"Configure R2 interface r2-eth1 with prefix suppression with interface address"
)
r2 = tgen.gears["r2"]
r2.vtysh_cmd("conf t\ninterface r2-eth2\nip ospf prefix-suppression 10.1.3.2")
step("Verify the R1 configuration of 'ip ospf prefix-suppression 10.1.3.1'")
prefix_suppression_cfg = (
tgen.net["r1"]
.cmd(
'vtysh -c "show running ospfd" | grep "^ ip ospf prefix-suppression 10.1.3.1"'
)
.rstrip()
)
assertmsg = "'ip ospf prefix-suppression 10.1.3.1' applied, but not present in configuration"
assert prefix_suppression_cfg == " ip ospf prefix-suppression 10.1.3.1", assertmsg
step("Verify that ospf-prefix suppression is applied to the R1 interface")
r1_eth2_with_prefix_suppression = {
"interfaces": {
"r1-eth2": {
"ifUp": True,
"ospfEnabled": True,
"ipAddress": "10.1.3.1",
"ospfIfType": "Broadcast",
"networkType": "POINTOPOINT",
"prefixSuppression": True,
}
}
}
test_func = partial(
topotest.router_json_cmp,
r1,
"show ip ospf interface r1-eth2 json",
r1_eth2_with_prefix_suppression,
)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
assertmsg = "R1 OSPF interface r1-eth2 doesn't have prefix-suppression enabled"
assert result is None, assertmsg
step("Verify the OSPF prefix is not advertised and not present on r3")
r3 = tgen.gears["r3"]
input_dict = {}
test_func = partial(
topotest.router_json_cmp, r3, "show ip route 10.1.3.0/24 json", input_dict, True
)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
assertmsg = "10.1.3.0/24 installed on router r3"
assert result is None, assertmsg
step(
"Remove R1 interface r1-eth2 prefix-suppression configuration using interface address"
)
r1 = tgen.gears["r1"]
r1.vtysh_cmd("conf t\ninterface r1-eth2\nno ip ospf prefix-suppression 10.1.3.1")
step(
"Remove R2 interface r2-eth2 prefix-suppression configuration using interface address"
)
r2 = tgen.gears["r2"]
r2.vtysh_cmd("conf t\ninterface r2-eth2\nno ip ospf prefix-suppression 10.1.3.2")
step("Verify no R1 configuration of 'ip ospf prefix-suppression")
rc, _, _ = tgen.net["r1"].cmd_status(
"show running ospfd | grep -q 'ip ospf prefix-suppression 10.1.3.1'", warn=False
)
assertmsg = "'ip ospf prefix-suppressio 10.1.3.1' not applied, but present in R1 configuration"
assert rc, assertmsg
step("Verify that ospf-prefix suppression is not applied to the R1 interface")
r1_eth2_without_prefix_suppression = {
"interfaces": {
"r1-eth2": {
"ifUp": True,
"ospfEnabled": True,
"ipAddress": "10.1.3.1",
"ospfIfType": "Broadcast",
"networkType": "POINTOPOINT",
"prefixSuppression": False,
}
}
}
test_func = partial(
topotest.router_json_cmp,
r1,
"show ip ospf interface r1-eth2 json",
r1_eth2_without_prefix_suppression,
)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
assertmsg = "Prefix suppression on interface r1-eth2"
assert result is None, assertmsg
step("Verify that 10.1.3.0/24 route is now installed on R3")
input_dict = {
"10.1.3.0/24": [
{
"prefix": "10.1.3.0/24",
"prefixLen": 24,
"protocol": "ospf",
"nexthops": [
{
"ip": "10.1.5.2",
"interfaceName": "r3-eth0",
}
],
}
]
}
test_func = partial(
topotest.router_json_cmp, r3, "show ip route 10.1.3.0/24 json", input_dict
)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
assertmsg = "10.1.3.0/24 not installed on router r3"
assert result is None, assertmsg
def test_p2mp_suppression():
tgen = get_topogen()
if tgen.routers_have_failure():
pytest.skip("Skipped because of router(s) failure")
step("Configure R1 interface r1-eth3 with prefix suppression")
r1 = tgen.gears["r1"]
r1.vtysh_cmd("conf t\ninterface r1-eth3\nip ospf prefix-suppression")
step("Configure R2 interface r2-eth3 with prefix suppression")
r2 = tgen.gears["r2"]
r2.vtysh_cmd("conf t\ninterface r2-eth3\nip ospf prefix-suppression")
step("Verify that ospf-prefix suppression is applied to the R1 interface")
r1_eth3_with_prefix_suppression = {
"interfaces": {
"r1-eth3": {
"ifUp": True,
"ospfEnabled": True,
"ipAddress": "10.1.4.1",
"ospfIfType": "Broadcast",
"networkType": "POINTOMULTIPOINT",
"prefixSuppression": True,
}
}
}
test_func = partial(
topotest.router_json_cmp,
r1,
"show ip ospf interface r1-eth3 json",
r1_eth3_with_prefix_suppression,
)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
assertmsg = "R1 OSPF interface r1-eth3 doesn't have prefix-suppression enabled"
assert result is None, assertmsg
step("Verify the OSPF P2MP prefixes are not advertised and not present on r3")
r3 = tgen.gears["r3"]
input_dict = {}
test_func = partial(
topotest.router_json_cmp, r3, "show ip route 10.1.4.1/32 json", input_dict, True
)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
assertmsg = "10.1.4.1/32 installed on router r3"
assert result is None, assertmsg
test_func = partial(
topotest.router_json_cmp, r3, "show ip route 10.1.4.2/32 json", input_dict, True
)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
assertmsg = "10.1.4.2/32 installed on router r3"
assert result is None, assertmsg
step("Remove R1 interface r1-eth3 prefix-suppression configuration")
r1 = tgen.gears["r1"]
r1.vtysh_cmd("conf t\ninterface r1-eth3\nno ip ospf prefix-suppression")
step("Remove R2 interface r2-eth3 prefix-suppression configuration")
r2 = tgen.gears["r2"]
r2.vtysh_cmd("conf t\ninterface r2-eth3\nno ip ospf prefix-suppression")
step("Verify no R1 configuration of 'ip ospf prefix-suppression")
rc, _, _ = tgen.net["r1"].cmd_status(
"show running ospfd | grep -q 'ip ospf prefix-suppression'", warn=False
)
assertmsg = (
"'ip ospf prefix-suppression' not applied, but present in R1 configuration"
)
assert rc, assertmsg
step("Verify that ospf-prefix suppression is not applied to the R1 interface")
r1_eth3_without_prefix_suppression = {
"interfaces": {
"r1-eth3": {
"ifUp": True,
"ospfEnabled": True,
"ipAddress": "10.1.4.1",
"ospfIfType": "Broadcast",
"networkType": "POINTOMULTIPOINT",
"prefixSuppression": False,
}
}
}
test_func = partial(
topotest.router_json_cmp,
r1,
"show ip ospf interface r1-eth3 json",
r1_eth3_without_prefix_suppression,
)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
assertmsg = "Prefix suppression on interface r1-eth3"
assert result is None, assertmsg
step("Verify that 10.1.4.1/32 route is now installed on R3")
input_dict = {
"10.1.4.1/32": [
{
"prefix": "10.1.4.1/32",
"prefixLen": 32,
"protocol": "ospf",
"nexthops": [
{
"ip": "10.1.5.2",
"interfaceName": "r3-eth0",
}
],
}
]
}
test_func = partial(
topotest.router_json_cmp, r3, "show ip route 10.1.4.1/32 json", input_dict
)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
assertmsg = "10.1.4.1/32 not installed on router r3"
assert result is None, assertmsg
step("Verify that 10.1.4.2/32 route is now installed on R3")
input_dict = {
"10.1.4.2/32": [
{
"prefix": "10.1.4.2/32",
"prefixLen": 32,
"protocol": "ospf",
"nexthops": [
{
"ip": "10.1.5.2",
"interfaceName": "r3-eth0",
}
],
}
]
}
test_func = partial(
topotest.router_json_cmp, r3, "show ip route 10.1.4.2/32 json", input_dict
)
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
assertmsg = "10.1.4.2/32 not installed on router r3"
assert result is None, assertmsg
def test_memory_leak():
"Run the memory leak test and report results."
tgen = get_topogen()
if not tgen.is_memleak_enabled():
pytest.skip("Memory leak test/report is disabled")
tgen.report_memory_leaks()
if __name__ == "__main__":
args = ["-s"] + sys.argv[1:]
sys.exit(pytest.main(args))
|