]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/multicast_pim_bsm_topo1/test_mcast_pim_bsmp_01.py
*: auto-convert to SPDX License IDs
[mirror_frr.git] / tests / topotests / multicast_pim_bsm_topo1 / test_mcast_pim_bsmp_01.py
1 #!/usr/bin/env python
2 # SPDX-License-Identifier: ISC
3 #
4 # Copyright (c) 2020 by VMware, Inc. ("VMware")
5 # Used Copyright (c) 2018 by Network Device Education Foundation,
6 # Inc. ("NetDEF") in this file.
7 #
8
9 """
10 Following tests are covered to test PIM BSM processing basic functionality:
11
12 Test steps
13 - Create topology (setup module)
14 - Bring up topology
15
16 Tests covered in this suite
17 1. Verify FRR router select higher IP BSR , when 2 BSR present in the network
18 2. Verify BSR and RP updated correctly after configuring as black hole address
19 3.1 Verify when new router added to the topology, FRR node will send
20 unicast BSM to new router
21 3.2 Verify if no forwarding bit is set , FRR is not forwarding the
22 BSM to other PIM nbrs
23 3.3 Verify multicast BSM is sent to new router when unicast BSM is disabled
24 4.1 Verify BSM arrived on non bsm capable interface is dropped and
25 not processed
26 4.2 Verify group to RP info updated correctly in FRR node, after shut and
27 no-shut of BSM enable interfaces
28 5. Verify static RP is preferred over BSR
29 6.1 Verify adding/deleting the group to rp mapping and RP priority
30 multiple times
31 6.2 Verify RP and (*,G) detail after PIM process restart on FRR node
32 7.1 Verify BSM timeout on FRR1
33 7.2 Verify RP state in FRR1 after Bootstrap timer expiry
34 8.1 Verify upstream interfaces(IIF) and join state are updated properly
35 after BSM received for FRR
36 8.2 Verify IIF and OIL in "show ip pim state" updated properly after
37 BSM received
38 """
39
40 import os
41 import sys
42 import time
43 import pytest
44
45 # Save the Current Working Directory to find configuration files.
46 CWD = os.path.dirname(os.path.realpath(__file__))
47 sys.path.append(os.path.join(CWD, "../"))
48 sys.path.append(os.path.join(CWD, "../lib/"))
49
50 # Required to instantiate the topology builder class.
51
52 # pylint: disable=C0413
53 # Import topogen and topotest helpers
54 from lib.topogen import Topogen, get_topogen
55
56 from lib.common_config import (
57 start_topology,
58 write_test_header,
59 write_test_footer,
60 step,
61 addKernelRoute,
62 create_static_routes,
63 stop_router,
64 start_router,
65 shutdown_bringup_interface,
66 kill_router_daemons,
67 start_router_daemons,
68 reset_config_on_routers,
69 do_countdown,
70 apply_raw_config,
71 run_frr_cmd,
72 required_linux_kernel_version,
73 verify_rib,
74 )
75
76 from lib.pim import (
77 create_pim_config,
78 add_rp_interfaces_and_pim_config,
79 reconfig_interfaces,
80 scapy_send_bsr_raw_packet,
81 find_rp_from_bsrp_info,
82 verify_pim_grp_rp_source,
83 verify_pim_bsr,
84 verify_mroutes,
85 verify_join_state_and_timer,
86 verify_pim_state,
87 verify_upstream_iif,
88 verify_igmp_groups,
89 verify_pim_upstream_rpf,
90 enable_disable_pim_unicast_bsm,
91 enable_disable_pim_bsm,
92 clear_mroute,
93 clear_pim_interface_traffic,
94 get_pim_interface_traffic,
95 McastTesterHelper,
96 verify_pim_neighbors,
97 )
98 from lib.topolog import logger
99 from lib.topojson import build_config_from_json
100
101
102 pytestmark = [pytest.mark.pimd, pytest.mark.staticd]
103
104 TOPOLOGY = """
105
106 b1_____
107 |
108 |
109 s1-----f1-----i1-----l1----r1
110 |
111 ______|
112 b2
113
114 b1 - BSR 1
115 b2 - BSR 2
116 s1 - Source
117 f1 - FHR
118 i1 - Intermediate Router (also RP)
119 r1 - Receiver
120
121 """
122 # Global variables
123 NEXT_HOP1 = "70.0.0.1"
124 NEXT_HOP2 = "65.0.0.1"
125 BSR_IP_1 = "1.1.2.7"
126 BSR_IP_2 = "10.2.1.1"
127 BSR1_ADDR = "1.1.2.7/32"
128 BSR2_ADDR = "10.2.1.1/32"
129
130
131 def setup_module(mod):
132 """
133 Sets up the pytest environment
134
135 * `mod`: module name
136 """
137
138 # Required linux kernel version for this suite to run.
139 result = required_linux_kernel_version("4.15")
140 if result is not True:
141 pytest.skip("Kernel version should be >= 4.15")
142
143 testsuite_run_time = time.asctime(time.localtime(time.time()))
144 logger.info("Testsuite start time: {}".format(testsuite_run_time))
145 logger.info("=" * 40)
146 logger.info("Master Topology: \n {}".format(TOPOLOGY))
147
148 logger.info("Running setup_module to create topology")
149
150 # This function initiates the topology build with Topogen...
151 json_file = "{}/mcast_pim_bsmp_01.json".format(CWD)
152 tgen = Topogen(json_file, mod.__name__)
153 global topo
154 topo = tgen.json_topo
155 # ... and here it calls Mininet initialization functions.
156
157 # Starting topology, create tmp files which are loaded to routers
158 # to start daemons and then start routers
159 start_topology(tgen)
160
161 # Don"t run this test if we have any failure.
162 if tgen.routers_have_failure():
163 pytest.skip(tgen.errors)
164
165 # Creating configuration from JSON
166 build_config_from_json(tgen, topo)
167
168 # Verify PIM neighbors
169 result = verify_pim_neighbors(tgen, topo)
170 assert result is True, " Verify PIM neighbor: Failed Error: {}".format(result)
171
172 # XXX Replace this using "with McastTesterHelper()... " in each test if possible.
173 global app_helper
174 app_helper = McastTesterHelper(tgen)
175
176 logger.info("Running setup_module() done")
177
178
179 def teardown_module():
180 """Teardown the pytest environment"""
181
182 logger.info("Running teardown_module to delete topology")
183
184 tgen = get_topogen()
185
186 app_helper.cleanup()
187
188 # Stop toplogy and Remove tmp files
189 tgen.stop_topology()
190
191 logger.info(
192 "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
193 )
194 logger.info("=" * 40)
195
196
197 #####################################################
198 #
199 # Local APIs
200 #
201 #####################################################
202
203
204 def clear_bsrp_data(tgen, topo):
205
206 """
207 clear bsm databas after test"
208 Parameters
209 ----------
210 * `tgen`: topogen object
211
212 Usage
213 -----
214 result = clear_bsrp_data(tgen, topo)
215 Returns
216 -------
217 errormsg(str) or True
218 """
219
220 for dut in tgen.routers():
221
222 rnode = tgen.routers()[dut]
223
224 logger.info("[DUT: %s]: clear_bsrp_data")
225
226 run_frr_cmd(rnode, "clear ip pim bsr-data")
227
228 return True
229
230
231 def verify_state_incremented(state_before, state_after):
232 """
233 API to compare interface traffic state incrementing
234
235 Parameters
236 ----------
237 * `state_before` : State dictionary for any particular instance
238 * `state_after` : State dictionary for any particular instance
239 """
240
241 for router, state_data in state_before.items():
242 for state, value in state_data.items():
243 if state_before[router][state] >= state_after[router][state]:
244 errormsg = (
245 "[DUT: %s]: state %s value has not"
246 " incremented, Initial value: %s, "
247 "Current value: %s [FAILED!!]"
248 % (
249 router,
250 state,
251 state_before[router][state],
252 state_after[router][state],
253 )
254 )
255 return errormsg
256
257 logger.info(
258 "[DUT: %s]: State %s value is "
259 "incremented, Initial value: %s, Current value: %s"
260 " [PASSED!!]",
261 router,
262 state,
263 state_before[router][state],
264 state_after[router][state],
265 )
266
267 return True
268
269
270 def pre_config_to_bsm(tgen, topo, tc_name, bsr, sender, receiver, fhr, rp, lhr, packet):
271 """
272 API to do required configuration to send and receive BSR packet
273 """
274
275 # Re-configure interfaces as per BSR packet
276 result = reconfig_interfaces(tgen, topo, bsr, fhr, packet)
277 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
278
279 # Create static routes
280 if "bsr" in topo["routers"][bsr]["bsm"]["bsr_packets"][packet]:
281 bsr_route = topo["routers"][bsr]["bsm"]["bsr_packets"][packet]["bsr"]
282 next_hop = topo["routers"][bsr]["bsm"]["bsr_packets"][packet]["src_ip"].split(
283 "/"
284 )[0]
285 next_hop_rp = topo["routers"][fhr]["links"][rp]["ipv4"].split("/")[0]
286 next_hop_lhr = topo["routers"][rp]["links"][lhr]["ipv4"].split("/")[0]
287
288 # Add static routes
289 input_dict = {
290 rp: {"static_routes": [{"network": bsr_route, "next_hop": next_hop_rp}]},
291 lhr: {"static_routes": [{"network": bsr_route, "next_hop": next_hop_lhr}]},
292 }
293
294 result = create_static_routes(tgen, input_dict)
295 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
296
297 # Verifying static routes are installed
298 for dut, _nexthop in zip([rp, lhr], [next_hop_rp, next_hop_lhr]):
299 input_routes = {dut: input_dict[dut]}
300 result = verify_rib(
301 tgen, "ipv4", dut, input_routes, _nexthop, protocol="static"
302 )
303 assert result is True, "Testcase {} : Failed \n Error {}".format(
304 tc_name, result
305 )
306
307 # RP Mapping
308 rp_mapping = topo["routers"][bsr]["bsm"]["bsr_packets"][packet]["rp_mapping"]
309
310 # Add interfaces in RP for all the RPs
311 result = add_rp_interfaces_and_pim_config(tgen, topo, "lo", rp, rp_mapping)
312 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
313
314 # Add kernel routes to sender and receiver
315 for group, rp_list in rp_mapping.items():
316 mask = group.split("/")[1]
317 if int(mask) == 32:
318 group = group.split("/")[0]
319
320 # Add static routes for RPs in FHR and LHR
321 next_hop_fhr = topo["routers"][rp]["links"][fhr]["ipv4"].split("/")[0]
322 next_hop_lhr = topo["routers"][rp]["links"][lhr]["ipv4"].split("/")[0]
323 input_dict = {
324 fhr: {"static_routes": [{"network": rp_list, "next_hop": next_hop_fhr}]},
325 }
326 result = create_static_routes(tgen, input_dict)
327 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
328
329 # Verifying static routes are installed
330 result = verify_rib(
331 tgen, "ipv4", fhr, input_dict, next_hop_fhr, protocol="static"
332 )
333 assert result is True, "Testcase {} : Failed \n Error {}".format(
334 tc_name, result
335 )
336
337 input_dict = {
338 lhr: {"static_routes": [{"network": rp_list, "next_hop": next_hop_lhr}]},
339 }
340 result = create_static_routes(tgen, input_dict)
341 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
342
343 # Verifying static routes are installed
344 result = verify_rib(
345 tgen, "ipv4", lhr, input_dict, next_hop_lhr, protocol="static"
346 )
347 assert result is True, "Testcase {} : Failed \n Error {}".format(
348 tc_name, result
349 )
350
351 return True
352
353
354 #####################################################
355 #
356 # Testcases
357 #
358 #####################################################
359
360
361 def test_BSR_higher_prefer_ip_p0(request):
362 """
363 Verify FRR router select higher IP BSR , when 2 BSR present in the network
364
365 Topology used:
366 b1_____
367 |
368 |
369 s1-----f1-----i1-----l1----r1
370 |
371 ______|
372 b2
373
374 b1 - BSR 1
375 b2 - BSR 2
376 s1 - Source
377 f1 - FHR
378 i1 - Intermediate Router (also RP)
379 r1 - Receiver
380 """
381
382 tgen = get_topogen()
383 tc_name = request.node.name
384 write_test_header(tc_name)
385
386 # Don"t run this test if we have any failure.
387 if tgen.routers_have_failure():
388 pytest.skip(tgen.errors)
389
390 app_helper.stop_all_hosts()
391 clear_mroute(tgen)
392 reset_config_on_routers(tgen)
393 clear_pim_interface_traffic(tgen, topo)
394
395 step("pre-configure BSM packet")
396 step("Configure cisco-1 as BSR1 1.1.2.7")
397 result = pre_config_to_bsm(
398 tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
399 )
400 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
401 step("Configure cisco-1 as BSR1 10.2.1.1")
402 result = pre_config_to_bsm(
403 tgen, topo, tc_name, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
404 )
405 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
406 step("configuring loopback address of b1 and b2 as BSR")
407 intf_lo_addr_b1 = topo["routers"]["b1"]["links"]["lo"]["ipv4"]
408 intf_lo_addr_b2 = topo["routers"]["b2"]["links"]["lo"]["ipv4"]
409
410 raw_config = {
411 "b1": {
412 "raw_config": [
413 "interface lo",
414 "no ip address {}".format(intf_lo_addr_b1),
415 "ip address {}".format(BSR1_ADDR),
416 "ip pim",
417 ]
418 },
419 "b2": {
420 "raw_config": [
421 "interface lo",
422 "no ip address {}".format(intf_lo_addr_b2),
423 "ip address {}".format(BSR2_ADDR),
424 "ip pim",
425 ]
426 },
427 }
428 result = apply_raw_config(tgen, raw_config)
429 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
430
431 GROUP_ADDRESS = "225.200.100.100"
432 step("configuring static routes for both the BSR")
433
434 next_hop_rp = topo["routers"]["f1"]["links"]["i1"]["ipv4"].split("/")[0]
435 next_hop_lhr = topo["routers"]["i1"]["links"]["l1"]["ipv4"].split("/")[0]
436
437 input_dict = {
438 "f1": {
439 "static_routes": [
440 {"network": BSR1_ADDR, "next_hop": NEXT_HOP1},
441 {"network": BSR2_ADDR, "next_hop": NEXT_HOP2},
442 ]
443 },
444 "i1": {
445 "static_routes": [
446 {"network": BSR1_ADDR, "next_hop": next_hop_rp},
447 {"network": BSR2_ADDR, "next_hop": next_hop_rp},
448 ]
449 },
450 "l1": {
451 "static_routes": [
452 {"network": BSR1_ADDR, "next_hop": next_hop_lhr},
453 {"network": BSR2_ADDR, "next_hop": next_hop_lhr},
454 ]
455 },
456 }
457
458 result = create_static_routes(tgen, input_dict)
459 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
460
461 # Verifying static routes are installed
462 for dut, _nexthop in zip(["i1", "l1"], [next_hop_rp, next_hop_lhr]):
463 input_routes = {dut: input_dict[dut]}
464 result = verify_rib(
465 tgen, "ipv4", dut, input_routes, _nexthop, protocol="static"
466 )
467 assert result is True, "Testcase {} : Failed \n Error {}".format(
468 tc_name, result
469 )
470
471 for bsr_add, next_hop in zip([BSR1_ADDR, BSR2_ADDR], [NEXT_HOP1, NEXT_HOP2]):
472 input_routes = {
473 "f1": {"static_routes": [{"network": bsr_add, "next_hop": next_hop}]}
474 }
475 result = verify_rib(
476 tgen, "ipv4", "f1", input_routes, next_hop, protocol="static"
477 )
478 assert result is True, "Testcase {} : Failed \n Error {}".format(
479 tc_name, result
480 )
481
482 # Use scapy to send pre-defined packet from senser to receiver
483 step("Send BSR packet from b1 to FHR")
484 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet9")
485 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
486
487 result = app_helper.run_join("r1", GROUP_ADDRESS, "l1")
488 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
489 do_countdown(5)
490
491 dut = "l1"
492 step("Verify if b1 chosen as BSR in f1")
493 result = verify_pim_bsr(tgen, topo, "f1", BSR_IP_1)
494 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
495
496 group = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet9"]["group"]
497 step("Find the elected rp from bsrp-info in LHR l1")
498 rp = find_rp_from_bsrp_info(tgen, dut, BSR_IP_1, group)
499 assert rp is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
500
501 step("Verify RP in LHR")
502 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp[group])
503 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
504
505 step("Send BSR packet from b2 to FHR")
506 result = scapy_send_bsr_raw_packet(tgen, topo, "b2", "f1", "packet3")
507 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
508
509 dut = "l1"
510 step("Verify if b2 chosen as BSR in f1")
511 result = verify_pim_bsr(tgen, topo, "f1", BSR_IP_2)
512 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
513
514 step("Find the elected rp from bsrp-info in LHR l1")
515 rp = find_rp_from_bsrp_info(tgen, dut, BSR_IP_2, group)
516 assert rp is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
517
518 step("Verify RP in LHR")
519 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp[group])
520 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
521
522 step("Shut higher prefer BSR2 link f1 to b2")
523
524 f1_b2_eth1 = topo["routers"]["f1"]["links"]["b2"]["interface"]
525 shutdown_bringup_interface(tgen, "f1", "f1-b2-eth1", False)
526
527 step("clearing bsr to timeout old BSR")
528 clear_bsrp_data(tgen, topo)
529
530 step("Send BSR packet from b1 and b2 to FHR")
531 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet9")
532 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
533
534 result = scapy_send_bsr_raw_packet(tgen, topo, "b2", "f1", "packet3")
535 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
536
537 step("sleeping for 3 sec to leran new packet")
538 do_countdown(3)
539 step("verify BSR1 has become preferred RP")
540 dut = "l1"
541
542 step("Verify if b1 chosen as BSR in f1")
543 result = verify_pim_bsr(tgen, topo, "f1", BSR_IP_1)
544 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
545
546 step("Find the elected rp from bsrp-info in LHR l1")
547 rp = find_rp_from_bsrp_info(tgen, dut, BSR_IP_1, group)
548 assert rp is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
549
550 step("Verify RP in LHR")
551 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp[group])
552 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
553
554 step("NoShut higher prefer BSR2 link f1 to b2")
555 step("sleeping for 3 min to leran new packet")
556 do_countdown(3)
557 f1_b2_eth1 = topo["routers"]["f1"]["links"]["b2"]["interface"]
558 shutdown_bringup_interface(tgen, "f1", "f1-b2-eth1", True)
559 step("verify BSR2 has become preferred RP")
560 dut = "l1"
561
562 step("Send BSR packet from b1 and b2 to FHR")
563 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet9")
564 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
565
566 result = scapy_send_bsr_raw_packet(tgen, topo, "b2", "f1", "packet3")
567 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
568
569 step("Verify if b2 chosen as BSR in f1")
570 result = verify_pim_bsr(tgen, topo, "f1", BSR_IP_2)
571 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
572
573 step("Find the elected rp from bsrp-info in LHR l1")
574 rp = find_rp_from_bsrp_info(tgen, dut, BSR_IP_2, group)
575 assert rp is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
576
577 step("Verify RP in LHR")
578 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp[group])
579 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
580
581 step("Clear BSM database before moving to next case")
582 clear_bsrp_data(tgen, topo)
583
584 write_test_footer(tc_name)
585
586
587 def test_BSR_CRP_with_blackhole_address_p1(request):
588 """
589 Verify BSR and RP updated correctly after configuring as black hole address
590
591 Topology used:
592 b1_____
593 |
594 |
595 s1-----f1-----i1-----l1----r1
596 |
597 ______|
598 b2
599
600 b1 - BSR 1
601 b2 - BSR 2
602 s1 - Source
603 f1 - FHR
604 i1 - Intermediate Router (also RP)
605 r1 - Receiver
606 """
607
608 tgen = get_topogen()
609 tc_name = request.node.name
610 write_test_header(tc_name)
611
612 # Don"t run this test if we have any failure.
613 if tgen.routers_have_failure():
614 pytest.skip(tgen.errors)
615
616 app_helper.stop_all_hosts()
617 clear_mroute(tgen)
618 reset_config_on_routers(tgen)
619 clear_pim_interface_traffic(tgen, topo)
620
621 step("pre-configure BSM packet")
622 step("Configure cisco-1 as BSR1 1.1.2.7")
623 result = pre_config_to_bsm(
624 tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
625 )
626 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
627
628 step("configuring loopback address of b1 and b2 as BSR")
629 intf_lo_addr_b1 = topo["routers"]["b1"]["links"]["lo"]["ipv4"]
630
631 raw_config = {
632 "b1": {
633 "raw_config": [
634 "interface lo",
635 "no ip address {}".format(intf_lo_addr_b1),
636 "ip address {}".format(BSR1_ADDR),
637 "ip pim",
638 ]
639 }
640 }
641 result = apply_raw_config(tgen, raw_config)
642 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
643
644 GROUP_ADDRESS = "225.200.100.100"
645 step("configuring static routes for both the BSR")
646
647 next_hop_rp = topo["routers"]["f1"]["links"]["i1"]["ipv4"].split("/")[0]
648 next_hop_lhr = topo["routers"]["i1"]["links"]["l1"]["ipv4"].split("/")[0]
649 next_hop_fhr = topo["routers"]["i1"]["links"]["f1"]["ipv4"].split("/")[0]
650 CRP = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet9"]["candidate_rp"]
651
652 input_dict = {
653 "i1": {"static_routes": [{"network": BSR1_ADDR, "next_hop": next_hop_rp}]},
654 "l1": {"static_routes": [{"network": BSR1_ADDR, "next_hop": next_hop_lhr}]},
655 "f1": {
656 "static_routes": [
657 {"network": CRP, "next_hop": next_hop_fhr, "delete": True}
658 ]
659 },
660 }
661
662 result = create_static_routes(tgen, input_dict)
663 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
664
665 # Verifying static routes are installed
666 for dut, _nexthop in zip(["i1", "l1"], [next_hop_rp, next_hop_lhr]):
667 input_routes = {dut: input_dict[dut]}
668 result = verify_rib(
669 tgen, "ipv4", dut, input_routes, _nexthop, protocol="static"
670 )
671 assert result is True, "Testcase {} : Failed \n Error {}".format(
672 tc_name, result
673 )
674
675 input_routes = {
676 "f1": {"static_routes": [{"network": CRP, "next_hop": next_hop_fhr}]}
677 }
678 result = verify_rib(
679 tgen, "ipv4", "f1", input_routes, protocol="static", expected=False
680 )
681 assert result is not True, (
682 "Testcase {} : Failed \n "
683 "Expected: Routes should not be present in {} RIB \n "
684 "Found: {}".format(tc_name, "f1", result)
685 )
686
687 # Use scapy to send pre-defined packet from senser to receiver
688
689 group = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet9"]["group"]
690 step("waiting for BSR to timeout before configuring blackhole route")
691 clear_bsrp_data(tgen, topo)
692
693 step("Configure black-hole address for BSR and candidate RP")
694 input_dict = {
695 "f1": {
696 "static_routes": [{"network": [BSR1_ADDR, CRP], "next_hop": "blackhole"}]
697 }
698 }
699
700 result = create_static_routes(tgen, input_dict)
701 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
702
703 # Verifying static routes are installed
704 result = verify_rib(tgen, "ipv4", "f1", input_dict, protocol="static")
705 assert result is True, "Testcase {} : Failed \n Error {}".format(tc_name, result)
706
707 intf_f1_i1 = topo["routers"]["f1"]["links"]["i1"]["interface"]
708 step("Verify bsm transit count is not increamented" "show ip pim interface traffic")
709 state_dict = {"f1": {intf_f1_i1: ["bsmTx"]}}
710
711 state_before = get_pim_interface_traffic(tgen, state_dict)
712 assert isinstance(
713 state_before, dict
714 ), "Testcase{} : Failed \n state_before is not dictionary \n Error: {}".format(
715 tc_name, result
716 )
717
718 step("Sending BSR after Configure black hole address for BSR and candidate RP")
719 step("Send BSR packet from b1 to FHR")
720 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet9")
721 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
722
723 dut = "l1"
724 step("Find the elected rp from bsrp-info in LHR l1")
725 rp = find_rp_from_bsrp_info(tgen, dut, BSR_IP_1, group)
726 assert rp is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
727
728 step("Verify if b1 chosen as BSR in l1")
729 result = verify_pim_bsr(tgen, topo, "l1", BSR_IP_1, expected=False)
730 assert result is not True, (
731 "Testcase {} : Failed \n "
732 "Expected: b1 should be chosen as BSR in {} \n "
733 "Found: {}".format(tc_name, "l1", result)
734 )
735
736 state_after = get_pim_interface_traffic(tgen, state_dict)
737 assert isinstance(
738 state_after, dict
739 ), "Testcase{} : Failed \n state_before is not dictionary \n Error: {}".format(
740 tc_name, result
741 )
742
743 result = verify_state_incremented(state_before, state_after)
744 assert result is not True, "Testcase{} : Failed Error: {}".format(tc_name, result)
745
746 step("Remove black-hole address for BSR and candidate RP")
747 input_dict = {
748 "f1": {
749 "static_routes": [
750 {"network": [BSR1_ADDR, CRP], "next_hop": "blackhole", "delete": True},
751 {"network": BSR1_ADDR, "next_hop": NEXT_HOP1},
752 ]
753 }
754 }
755
756 result = create_static_routes(tgen, input_dict)
757 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
758
759 # Verifying static routes are installed
760 input_dict = {
761 "f1": {"static_routes": [{"network": BSR1_ADDR, "next_hop": NEXT_HOP1}]}
762 }
763 result = verify_rib(tgen, "ipv4", "f1", input_dict, NEXT_HOP1, protocol="static")
764 assert result is True, "Testcase {} : Failed \n Error {}".format(tc_name, result)
765
766 input_dict = {
767 "f1": {
768 "static_routes": [
769 {"network": [BSR1_ADDR, CRP], "next_hop": "blackhole", "delete": True}
770 ]
771 }
772 }
773 result = verify_rib(
774 tgen, "ipv4", "f1", input_dict, protocol="static", expected=False
775 )
776 assert result is not True, (
777 "Testcase {} : Failed \n "
778 "Expected: Routes should not be present in {} RIB \n "
779 "Found: {}".format(tc_name, "f1", result)
780 )
781
782 step("Sending BSR after removing black-hole address for BSR and candidate RP")
783 step("Send BSR packet from b1 to FHR")
784 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet9")
785 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
786
787 step("Verify if b1 chosen as BSR in f1")
788 result = verify_pim_bsr(tgen, topo, "f1", BSR_IP_1)
789 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
790
791 dut = "l1"
792 group = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet9"]["group"]
793 step("Find the elected rp from bsrp-info in LHR l1")
794 rp = find_rp_from_bsrp_info(tgen, dut, BSR_IP_1, group)
795 assert rp is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
796
797 step("Verify RP in LHR l1")
798 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp[group])
799 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
800
801 step("clear BSM database before moving to next case")
802 clear_bsrp_data(tgen, topo)
803
804 write_test_footer(tc_name)
805
806
807 def test_new_router_fwd_p0(request):
808 """
809 1. Verify when new router added to the topology, FRR node will send
810 unicast BSM to new router
811 2. Verify if no forwarding bit is set , FRR is not forwarding the
812 BSM to other PIM nbrs
813 3. Verify multicast BSM is sent to new router when unicast BSM is disabled
814
815 Topology used:
816 b1_____
817 |
818 |
819 s1-----f1-----i1-----l1----r1
820 |
821 ______|
822 b2
823
824 b1 - BSR 1
825 b2 - BSR 2
826 s1 - Source
827 f1 - FHR
828 i1 - Intermediate Router (also RP)
829 r1 - Receiver
830
831 """
832
833 tgen = get_topogen()
834 tc_name = request.node.name
835 write_test_header(tc_name)
836
837 # Don"t run this test if we have any failure.
838 if tgen.routers_have_failure():
839 pytest.skip(tgen.errors)
840
841 app_helper.stop_all_hosts()
842 clear_mroute(tgen)
843 reset_config_on_routers(tgen)
844 clear_pim_interface_traffic(tgen, topo)
845
846 result = pre_config_to_bsm(
847 tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
848 )
849 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
850
851 result = pre_config_to_bsm(
852 tgen, topo, tc_name, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
853 )
854 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
855
856 GROUP_ADDRESS = "225.1.1.1"
857
858 # Use scapy to send pre-defined packet from senser to receiver
859 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet1")
860 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
861
862 bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
863 time.sleep(1)
864
865 result = app_helper.run_join("r1", GROUP_ADDRESS, "l1")
866 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
867
868 # Verify bsr state in FHR
869 step("Verify if b1 chosen as BSR in f1")
870 result = verify_pim_bsr(tgen, topo, "f1", bsr_ip)
871 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
872
873 # Verify bsr state in i1
874 step("Verify if b1 chosen as BSR in i1")
875 result = verify_pim_bsr(tgen, topo, "i1", bsr_ip)
876 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
877
878 # Verify ip mroute
879 iif = "l1-i1-eth0"
880 src_addr = "*"
881 oil = "l1-r1-eth1"
882
883 step("Verify mroute populated on l1")
884 result = verify_mroutes(tgen, "l1", src_addr, GROUP_ADDRESS, iif, oil)
885 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
886
887 # Reload i1 and l1
888 step("Reloading i1 and l1. Stop both. bring up l1 and then i1")
889 stop_router(tgen, "i1")
890 start_router(tgen, "i1")
891 stop_router(tgen, "l1")
892 start_router(tgen, "l1")
893
894 # Verify bsr state in i1
895 step("Verify BSR in i1 after restart while no new bsm sent from b1")
896 result = verify_pim_bsr(tgen, topo, "i1", bsr_ip)
897 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
898
899 # Verify bsr state in l1
900 step("Verify no BSR in l1 as i1 would not forward the no-forward bsm")
901 result = verify_pim_bsr(tgen, topo, "l1", bsr_ip, expected=False)
902 assert result is not True, (
903 "Testcase {} : Failed \n "
904 "Expected: [{}]: BSR data should not be present after no-forward bsm \n "
905 "Found: {}".format(tc_name, "l1", result)
906 )
907
908 # unconfigure unicast bsm on f1-i1-eth2
909 step("unconfigure unicast bsm on f1-i1-eth2, will forward with only mcast")
910 enable_disable_pim_unicast_bsm(tgen, "f1", "f1-i1-eth2", enable=False)
911
912 # Reboot i1 to check if still bsm received with multicast address
913 step("Reboot i1 to check if still bsm received with multicast address")
914 stop_router(tgen, "i1")
915 start_router(tgen, "i1")
916
917 result = app_helper.run_join("r1", GROUP_ADDRESS, "l1")
918 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
919
920 # Verify again if BSR is installed from bsm forwarded by f1
921 step("Verify again if BSR is installed from bsm forwarded by f1")
922 result = verify_pim_bsr(tgen, topo, "i1", bsr_ip)
923 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
924
925 # Use scapy to send pre-defined packet from senser to receiver
926 step("Send another BSM packet from b1 which will reach l1(LHR)")
927 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet2")
928 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
929 do_countdown(5)
930
931 step("Verify again if BSR is installed from bsm forwarded by i1")
932 result = verify_pim_bsr(tgen, topo, "l1", bsr_ip)
933 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
934
935 # Verify ip mroute populated again
936 step("Verify mroute again on l1 (lhr)")
937 result = verify_mroutes(tgen, "l1", src_addr, GROUP_ADDRESS, iif, oil)
938 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
939
940 step("clear BSM database before moving to next case")
941 clear_bsrp_data(tgen, topo)
942
943 write_test_footer(tc_name)
944
945
946 def test_int_bsm_config_p1(request):
947 """
948 1. Verify BSM arrived on non bsm capable interface is dropped and
949 not processed
950 2. Verify group to RP info updated correctly in FRR node, after shut and
951 no-shut of BSM enable interfaces
952
953 Topology used:
954 b1_____
955 |
956 |
957 s1-----f1-----i1-----l1----r1
958 |
959 ______|
960 b2
961
962 b1 - BSR 1
963 b2 - BSR 2
964 s1 - Source
965 f1 - FHR
966 i1 - Intermediate Router (also RP)
967 r1 - Receiver
968
969 """
970
971 tgen = get_topogen()
972 tc_name = request.node.name
973 write_test_header(tc_name)
974
975 # Don"t run this test if we have any failure.
976 if tgen.routers_have_failure():
977 pytest.skip(tgen.errors)
978
979 app_helper.stop_all_hosts()
980 clear_mroute(tgen)
981 reset_config_on_routers(tgen)
982 clear_pim_interface_traffic(tgen, topo)
983
984 result = pre_config_to_bsm(
985 tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
986 )
987 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
988
989 result = pre_config_to_bsm(
990 tgen, topo, tc_name, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
991 )
992 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
993
994 GROUP_ADDRESS = "225.1.1.1"
995
996 bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
997 time.sleep(1)
998
999 result = app_helper.run_join("r1", GROUP_ADDRESS, "l1")
1000 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1001
1002 # Use scapy to send pre-defined packet from senser to receiver
1003 step("Send BSM packet from b1")
1004 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet1")
1005 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1006
1007 # Verify bsr state in i1
1008 step("Verify if b1 is chosen as BSR in i1")
1009 result = verify_pim_bsr(tgen, topo, "i1", bsr_ip)
1010 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1011
1012 # check if mroute installed
1013 step("check if mroute installed in i1")
1014 iif = "lo"
1015 src_addr = "*"
1016 oil = "i1-l1-eth1"
1017
1018 result = verify_mroutes(tgen, "i1", src_addr, GROUP_ADDRESS, iif, oil)
1019 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1020
1021 # wait till bsm rp age out
1022 step("wait till bsm rp age out")
1023 clear_bsrp_data(tgen, topo)
1024
1025 # check if mroute uninstalled because of rp age out
1026 step("check if mroute uninstalled because of rp age out in i1")
1027 result = verify_mroutes(
1028 tgen, "i1", src_addr, GROUP_ADDRESS, iif, oil, expected=False
1029 )
1030 assert result is not True, (
1031 "Testcase {} : Failed \n "
1032 "Expected: [{}]: mroute (S, G) should be cleared from mroute table\n "
1033 "Found: {}".format(tc_name, "i1", result)
1034 )
1035
1036 # unconfigure bsm processing on f1 on f1-i1-eth2
1037 step("unconfigure bsm processing on f1 in f1-i1-eth2, will drop bsm")
1038 result = enable_disable_pim_bsm(tgen, "f1", "f1-i1-eth2", enable=False)
1039 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1040
1041 # Use scapy to send pre-defined packet from senser to receiver
1042 step("Send BSM packet from b1")
1043 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet1")
1044 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1045
1046 # Verify bsr state in FHR
1047 step("Verify if b1 chosen as BSR in f1")
1048 result = verify_pim_bsr(tgen, topo, "f1", bsr_ip)
1049 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1050
1051 # Verify bsr state in i1
1052 step("Verify if b1 is not chosen as BSR in i1")
1053 result = verify_pim_bsr(tgen, topo, "i1", bsr_ip, expected=False)
1054 assert result is not True, (
1055 "Testcase {} : Failed \n "
1056 "Expected: [{}]: b1 should not be chosen as BSR \n "
1057 "Found: {}".format(tc_name, "i1", result)
1058 )
1059
1060 # check if mroute still not installed because of rp not available
1061 step("check if mroute still not installed because of rp not available")
1062 result = verify_mroutes(
1063 tgen, "i1", src_addr, GROUP_ADDRESS, iif, oil, expected=False
1064 )
1065 assert result is not True, (
1066 "Testcase {} : Failed \n "
1067 "Expected: [{}]: mroute (S, G) should not be installed as RP is not available\n "
1068 "Found: {}".format(tc_name, "i1", result)
1069 )
1070
1071 # configure bsm processing on i1 on f1-i1-eth2
1072 step("configure bsm processing on f1 in f1-i1-eth2, will accept bsm")
1073 result = enable_disable_pim_bsm(tgen, "f1", "f1-i1-eth2", enable=True)
1074 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1075
1076 # Use scapy to send pre-defined packet from senser to receiver
1077 step("Send BSM packet again from b1")
1078 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet2")
1079 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1080
1081 # Verify again if BSR is installed from bsm forwarded by f1
1082 step("Verify again if BSR is installed from bsm forwarded by f1")
1083 result = verify_pim_bsr(tgen, topo, "i1", bsr_ip)
1084 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1085
1086 # verify ip mroute populated
1087 step("Verify ip mroute")
1088 result = verify_mroutes(tgen, "i1", src_addr, GROUP_ADDRESS, iif, oil)
1089 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1090
1091 # Shut/No shut the bsm rpf interface and check mroute on lhr(l1)
1092 step("Shut/No shut the bsm rpf interface and check mroute on lhr(l1)")
1093 intf = "l1-i1-eth0"
1094 shutdown_bringup_interface(tgen, "l1", intf, False)
1095 shutdown_bringup_interface(tgen, "l1", intf, True)
1096
1097 iif = "l1-i1-eth0"
1098 oil = "l1-r1-eth1"
1099
1100 result = verify_mroutes(tgen, "l1", src_addr, GROUP_ADDRESS, iif, oil)
1101 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1102
1103 step("clear BSM database before moving to next case")
1104 clear_bsrp_data(tgen, topo)
1105
1106 write_test_footer(tc_name)
1107
1108
1109 def test_static_rp_override_p1(request):
1110 """
1111 Verify static RP is preferred over BSR
1112
1113 Topology used:
1114 b1_____
1115 |
1116 |
1117 s1-----f1-----i1-----l1----r1
1118 |
1119 ______|
1120 b2
1121
1122 b1 - BSR 1
1123 b2 - BSR 2
1124 s1 - Source
1125 f1 - FHR
1126 i1 - Intermediate Router (also RP)
1127 r1 - Receiver
1128
1129 """
1130
1131 tgen = get_topogen()
1132 tc_name = request.node.name
1133 write_test_header(tc_name)
1134
1135 # Don"t run this test if we have any failure.
1136 if tgen.routers_have_failure():
1137 pytest.skip(tgen.errors)
1138
1139 app_helper.stop_all_hosts()
1140 clear_mroute(tgen)
1141 reset_config_on_routers(tgen)
1142 clear_pim_interface_traffic(tgen, topo)
1143
1144 result = pre_config_to_bsm(
1145 tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
1146 )
1147 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1148
1149 result = pre_config_to_bsm(
1150 tgen, topo, tc_name, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
1151 )
1152 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1153
1154 GROUP_ADDRESS = "225.1.1.1"
1155 # Use scapy to send pre-defined packet from senser to receiver
1156 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet1")
1157 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1158
1159 bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
1160 time.sleep(1)
1161
1162 result = app_helper.run_join("r1", GROUP_ADDRESS, "l1")
1163 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1164
1165 # Verify bsr state in FHR
1166 result = verify_pim_bsr(tgen, topo, "f1", bsr_ip)
1167 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1168
1169 # Check igmp groups
1170 step("Verify IGMP groups in LHR")
1171 dut = "l1"
1172 intf = "l1-r1-eth1"
1173 result = verify_igmp_groups(tgen, dut, intf, GROUP_ADDRESS)
1174 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1175
1176 group = "225.1.1.1/32"
1177
1178 # Find the elected rp from bsrp-info
1179 step("Find the elected rp from bsrp-info in LHR l1")
1180 rp = find_rp_from_bsrp_info(tgen, dut, bsr_ip, group)
1181 assert rp is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1182
1183 # Check RP detail in LHR
1184 step("Verify that BS RP in LHR l1")
1185 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp[group])
1186 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1187
1188 iif = "l1-i1-eth0"
1189 # Verify upstream rpf for 225.1.1.1 is chosen as rp1
1190 step("Verify upstream rpf for 225.1.1.1 is chosen as bsrp")
1191 result = verify_pim_upstream_rpf(tgen, topo, dut, iif, GROUP_ADDRESS, rp[group])
1192 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1193
1194 # Configure a static rp for the group 225.1.1.1/32
1195 step("Configure a static rp 33.33.33.33 for the group 225.1.1.1/32 in l1")
1196 input_dict = {
1197 "l1": {
1198 "pim": {
1199 "rp": [
1200 {
1201 "rp_addr": "33.33.33.33",
1202 "group_addr_range": ["225.1.1.1/32"],
1203 }
1204 ]
1205 }
1206 }
1207 }
1208 result = create_pim_config(tgen, topo, input_dict)
1209 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
1210
1211 # Verify that static rp is configured over bsrp
1212 static_rp = "33.33.33.33"
1213 step("Verify that Static RP in LHR in l1")
1214 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "Static", static_rp)
1215 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1216
1217 # Verify if upstream also reflects the static rp
1218 step("Verify upstream rpf for 225.1.1.1 is chosen as static in l1")
1219 result = verify_pim_upstream_rpf(tgen, topo, dut, iif, GROUP_ADDRESS, static_rp)
1220 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1221
1222 # delete static rp for the group 225.1.1.1/32
1223 step("Delete static rp 33.33.33.33 for the group 225.1.1.1/32 in l1")
1224 input_dict = {
1225 "l1": {
1226 "pim": {
1227 "rp": [
1228 {
1229 "rp_addr": "33.33.33.33",
1230 "group_addr_range": ["225.1.1.1/32"],
1231 "delete": True,
1232 }
1233 ]
1234 }
1235 }
1236 }
1237 result = create_pim_config(tgen, topo, input_dict)
1238 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
1239
1240 # Verify if bsrp is installed back for the group 225.1.1.1/32
1241 step("Verify that BS RP in installed in LHR")
1242 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp[group])
1243 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1244
1245 # Verify upstream rpf for 225.1.1.1 is chosen as bsrp
1246 step("Verify upstream rpf for 225.1.1.1 is chosen as bsrp in l1")
1247 result = verify_pim_upstream_rpf(tgen, topo, dut, iif, GROUP_ADDRESS, rp[group])
1248 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1249
1250 step("clear BSM database before moving to next case")
1251 clear_bsrp_data(tgen, topo)
1252
1253 write_test_footer(tc_name)
1254
1255
1256 def test_bsmp_stress_add_del_restart_p2(request):
1257 """
1258 1. Verify adding/deleting the group to rp mapping and RP priority
1259 multiple times
1260 2. Verify RP and (*,G) detail after PIM process restart on FRR node
1261
1262 Topology used:
1263 b1_____
1264 |
1265 |
1266 s1-----f1-----i1-----l1----r1
1267 |
1268 ______|
1269 b2
1270
1271 b1 - BSR 1
1272 b2 - BSR 2
1273 s1 - Source
1274 f1 - FHR
1275 i1 - Intermediate Router (also RP)
1276 r1 - Receiver
1277
1278 """
1279
1280 tgen = get_topogen()
1281 tc_name = request.node.name
1282 write_test_header(tc_name)
1283
1284 # Don"t run this test if we have any failure.
1285 if tgen.routers_have_failure():
1286 pytest.skip(tgen.errors)
1287
1288 app_helper.stop_all_hosts()
1289 clear_mroute(tgen)
1290 reset_config_on_routers(tgen)
1291 clear_pim_interface_traffic(tgen, topo)
1292
1293 result = pre_config_to_bsm(
1294 tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
1295 )
1296 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1297
1298 result = pre_config_to_bsm(
1299 tgen, topo, tc_name, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
1300 )
1301 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1302
1303 GROUP_ADDRESS = "225.1.1.1"
1304
1305 # Use scapy to send pre-defined packet from senser to receiver
1306 step("Send BSR packet from b1 to FHR")
1307 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet1")
1308 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1309
1310 bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
1311 time.sleep(1)
1312
1313 result = app_helper.run_join("r1", GROUP_ADDRESS, "l1")
1314 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1315
1316 # Verify bsr state in FHR
1317 step("Verify if b1 is chosen as bsr in f1")
1318 result = verify_pim_bsr(tgen, topo, "f1", bsr_ip)
1319 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1320
1321 dut = "l1"
1322 group = "225.1.1.0/24"
1323 # Find the elected rp from bsrp-info
1324 step("Find the elected rp from bsrp-info in LHR l1")
1325 rp1 = find_rp_from_bsrp_info(tgen, dut, bsr_ip, group)
1326 assert rp1 is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1327
1328 # Check RP detail in LHR
1329 step("Verify RP in LHR l1")
1330 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp1[group])
1331 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1332
1333 # Send BSR packet from b1 after deleting high prio rp for 225.1.1.0/24
1334 step("Send BSM from b1 to FHR deleting high prio rp for 225.1.1.0/24")
1335 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet6")
1336 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1337
1338 # Find the elected rp from bsrp-info
1339 step("Find the elected rp from bsrp-info in LHR l1")
1340 rp2 = find_rp_from_bsrp_info(tgen, dut, bsr_ip, group)
1341 assert rp2 is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1342 logger.info("RP old: %s RP2 new: %s", rp1[group], rp2[group])
1343
1344 # Verify is the rp is different now
1345 assert rp1[group] != rp2[group], "Testcase {} :Failed \n Error {}".format(
1346 tc_name, result
1347 )
1348
1349 rp_add1 = rp1[group]
1350 rp_add2 = rp2[group]
1351
1352 # Verify if that rp is installed
1353 step("Verify new RP in LHR installed")
1354 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp_add2)
1355 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1356
1357 step("Change rp priority in the bsm and send multiple times")
1358
1359 for i in range(4):
1360 # Send BSR pkt from b1 after putting back high prio rp for 225.1.1.0/24
1361 step("Send BSM from b1 to FHR put back high prio rp for 225.1.1.0/24")
1362 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet1")
1363 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1364
1365 # Find the elected rp from bsrp-info
1366 step("Find the elected rp from bsrp-info in LHR")
1367 rp2 = find_rp_from_bsrp_info(tgen, dut, bsr_ip, group)
1368 assert rp2 is not {}, "Testcase {} :Failed \n Error : RP not Found".format(
1369 tc_name
1370 )
1371
1372 # Verify is the rp is different now
1373 step("Verify now old RP is elected again")
1374 assert (
1375 rp_add1 == rp2[group]
1376 ), "Testcase {} :Failed \n Error : rp expected {} rp received {}".format(
1377 tc_name, rp_add1, rp2[group]
1378 )
1379
1380 # Verify if that rp is installed
1381 step("Verify old RP in LHR installed")
1382 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp_add1)
1383 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1384
1385 # Send BSR packet from b1 after deleting high prio rp for 225.1.1.0/24
1386 step("Send BSM from b1 to FHR deleting high prio rp for 225.1.1.0/24")
1387 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet6")
1388 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1389
1390 # Verify if that rp is installed
1391 step("Verify new RP(rp2) in LHR installed")
1392 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp_add2)
1393 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1394
1395 # Restart pimd
1396 step("Restarting pimd in LHR")
1397 kill_router_daemons(tgen, "l1", ["pimd"])
1398 start_router_daemons(tgen, "l1", ["pimd"])
1399 logger.info("Restarting done")
1400
1401 # Verify if that rp is installed
1402 step("Verify old RP in LHR installed")
1403 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp_add2)
1404 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1405
1406 # Send IGMP join to LHR
1407 result = app_helper.run_join("r1", GROUP_ADDRESS, "l1")
1408 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1409
1410 do_countdown(5)
1411
1412 # VErify mroute created after pimd restart
1413 step("VErify mroute created after pimd restart")
1414 iif = "l1-i1-eth0"
1415 src_addr = "*"
1416 oil = "l1-r1-eth1"
1417 result = verify_mroutes(tgen, "l1", src_addr, GROUP_ADDRESS, iif, oil)
1418 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
1419
1420 write_test_footer(tc_name)
1421
1422
1423 def test_BSM_timeout_p0(request):
1424 """
1425 Verify BSM timeout on FRR1
1426 Verify RP state in FRR1 after Bootstrap timer expiry
1427
1428 Topology used:
1429 b1_____
1430 |
1431 |
1432 s1-----f1-----i1-----l1----r1
1433 |
1434 ______|
1435 b2
1436
1437 b1 - BSR 1
1438 b2 - BSR 2
1439 s1 - Source
1440 f1 - FHR
1441 i1 - Intermediate Router (also RP)
1442 r1 - Receiver
1443
1444 """
1445
1446 tgen = get_topogen()
1447 tc_name = request.node.name
1448 write_test_header(tc_name)
1449
1450 # Don"t run this test if we have any failure.
1451 if tgen.routers_have_failure():
1452 pytest.skip(tgen.errors)
1453
1454 app_helper.stop_all_hosts()
1455 clear_mroute(tgen)
1456 reset_config_on_routers(tgen)
1457 clear_pim_interface_traffic(tgen, topo)
1458
1459 result = pre_config_to_bsm(
1460 tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
1461 )
1462 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1463
1464 result = pre_config_to_bsm(
1465 tgen, topo, tc_name, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
1466 )
1467 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1468
1469 GROUP_ADDRESS = "225.1.1.1"
1470
1471 bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
1472
1473 # Use scapy to send pre-defined packet from senser to receiver
1474 step("send BSR packet from b1")
1475 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet1")
1476 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1477
1478 # Send IGMP join for group 225.1.1.1 from receiver
1479 result = app_helper.run_join("r1", GROUP_ADDRESS, "l1")
1480 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1481
1482 # Verify bsr state in FHR
1483 step("Verify bsr state in FHR f1")
1484 result = verify_pim_bsr(tgen, topo, "f1", bsr_ip)
1485 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1486
1487 # Verify ip mroute in LHR
1488 step(" Verify ip mroute in LHR l1")
1489 dut = "l1"
1490 iif = "l1-i1-eth0"
1491 src_addr = "*"
1492 oil = "l1-r1-eth1"
1493 result = verify_mroutes(tgen, dut, src_addr, GROUP_ADDRESS, iif, oil)
1494 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1495
1496 # Verify join state and join timer
1497 step("Verify join state and join timer in lhr l1")
1498 result = verify_join_state_and_timer(tgen, dut, iif, src_addr, GROUP_ADDRESS)
1499 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1500
1501 # Verify upstream IIF interface
1502 step("Verify upstream IIF interface in LHR l1")
1503 result = verify_upstream_iif(tgen, dut, iif, src_addr, GROUP_ADDRESS)
1504 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1505
1506 # Verify RP mapping
1507 dut = "l1"
1508 group = "225.1.1.1/32"
1509 step("Verify RP mapping in LHR l1")
1510 rp = find_rp_from_bsrp_info(tgen, dut, bsr_ip, group)
1511 assert rp != {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1512
1513 logger.info("Waiting for 130 secs to check BSR timeout")
1514 clear_bsrp_data(tgen, topo)
1515
1516 # Verify if bsr has aged out
1517 step("Verify if bsr has aged out in f1")
1518 no_bsr_ip = "0.0.0.0"
1519 result = verify_pim_bsr(tgen, topo, "f1", no_bsr_ip)
1520 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1521
1522 result = verify_pim_grp_rp_source(
1523 tgen, topo, "f1", group, rp_source="BSR", expected=False
1524 )
1525 assert result is not True, (
1526 "Testcase {} : Failed \n "
1527 "Expected: [{}]: bsr should be aged out \n "
1528 "Found: {}".format(tc_name, "f1", result)
1529 )
1530
1531 # Verify RP mapping removed after hold timer expires
1532 group = "225.1.1.1/32"
1533 step("Verify RP mapping removed after hold timer expires in l1")
1534 rp = find_rp_from_bsrp_info(tgen, dut, bsr_ip, group)
1535 assert rp == {}, "Testcase {} :Failed \n Error : RP found when not expected".format(
1536 tc_name
1537 )
1538
1539 # Verify iif is unknown after RP timeout
1540 step("Verify iif is unknown after RP timeout in l1")
1541 iif = "Unknown"
1542 result = verify_upstream_iif(
1543 tgen, dut, iif, src_addr, GROUP_ADDRESS, joinState="NotJoined"
1544 )
1545 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1546
1547 # Verify join state and join timer
1548 step("Verify join state and join timer in l1")
1549 iif = "l1-i1-eth0"
1550 result = verify_join_state_and_timer(
1551 tgen, dut, iif, src_addr, GROUP_ADDRESS, expected=False
1552 )
1553 assert result is not True, (
1554 "Testcase {} : Failed \n "
1555 "Expected: [{}]: Upstream Join State timer should not run\n "
1556 "Found: {}".format(tc_name, dut, result)
1557 )
1558
1559 # Verify ip mroute is not installed
1560 step("Verify mroute not installed in l1")
1561 result = verify_mroutes(
1562 tgen, dut, src_addr, GROUP_ADDRESS, iif, oil, expected=False
1563 )
1564 assert result is not True, (
1565 "Testcase {} : Failed \n "
1566 "Expected: [{}]: mroute (S, G) should not be installed \n "
1567 "Found: {}".format(tc_name, dut, result)
1568 )
1569
1570 step("clear BSM database before moving to next case")
1571 clear_bsrp_data(tgen, topo)
1572
1573 write_test_footer(tc_name)
1574
1575
1576 def test_iif_join_state_p0(request):
1577 """
1578 1. Verify upstream interfaces(IIF) and join state are updated properly
1579 after BSM received for FRR
1580 2. Verify IIF and OIL in "show ip pim state" updated properly after
1581 BSM received
1582
1583 Topology used:
1584 b1_____
1585 |
1586 |
1587 s1-----f1-----i1-----l1----r1
1588 |
1589 ______|
1590 b2
1591
1592 b1 - BSR 1
1593 b2 - BSR 2
1594 s1 - Source
1595 f1 - FHR
1596 i1 - Intermediate Router (also RP)
1597 r1 - Receiver
1598
1599 """
1600
1601 tgen = get_topogen()
1602 tc_name = request.node.name
1603 write_test_header(tc_name)
1604
1605 # Don"t run this test if we have any failure.
1606 if tgen.routers_have_failure():
1607 pytest.skip(tgen.errors)
1608
1609 app_helper.stop_all_hosts()
1610 clear_mroute(tgen)
1611 reset_config_on_routers(tgen)
1612 clear_pim_interface_traffic(tgen, topo)
1613
1614 result = pre_config_to_bsm(
1615 tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
1616 )
1617 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1618
1619 result = pre_config_to_bsm(
1620 tgen, topo, tc_name, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
1621 )
1622 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1623
1624 GROUP_ADDRESS = "225.1.1.1"
1625
1626 # Use scapy to send pre-defined packet from senser to receiver
1627 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet1")
1628 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1629
1630 bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
1631 time.sleep(1)
1632
1633 result = app_helper.run_join("r1", GROUP_ADDRESS, "l1")
1634 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1635
1636 # Verify bsr state in FHR
1637 result = verify_pim_bsr(tgen, topo, "f1", bsr_ip)
1638 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1639
1640 # Check igmp groups
1641 step("Verify IGMP groups in LHR l1")
1642 dut = "l1"
1643 intf = "l1-r1-eth1"
1644 result = verify_igmp_groups(tgen, dut, intf, GROUP_ADDRESS)
1645 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1646
1647 group = "225.1.1.1/32"
1648
1649 # Find the elected rp from bsrp-info
1650 step("Find the elected rp from bsrp-info in LHR l1")
1651 rp = find_rp_from_bsrp_info(tgen, dut, bsr_ip, group)
1652 assert rp is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1653
1654 # Check RP detail in LHR
1655 step("Verify RP in LHR l1")
1656 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp[group])
1657 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1658
1659 # Verify join state and join timer
1660 step("Verify join state and join timer l1")
1661 iif = "l1-i1-eth0"
1662 src_addr = "*"
1663 result = verify_join_state_and_timer(tgen, dut, iif, src_addr, GROUP_ADDRESS)
1664 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1665
1666 # Verify upstream IIF interface
1667 step("Verify upstream IIF interface l1")
1668 result = verify_upstream_iif(tgen, dut, iif, src_addr, GROUP_ADDRESS)
1669 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1670
1671 # Verify IIF/OIL in pim state
1672 oil = "l1-r1-eth1"
1673 result = verify_pim_state(tgen, dut, iif, oil, GROUP_ADDRESS)
1674 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1675
1676 # Verify ip mroute
1677 src_addr = "*"
1678 step("Verify ip mroute in l1")
1679 result = verify_mroutes(tgen, dut, src_addr, GROUP_ADDRESS, iif, oil)
1680 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1681
1682 # Make RP unreachanble in LHR
1683 step("Make RP unreachanble in LHR l1")
1684 rp = find_rp_from_bsrp_info(tgen, dut, bsr_ip, group)
1685 assert rp is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1686
1687 next_hop_lhr = topo["routers"]["i1"]["links"]["l1"]["ipv4"].split("/")[0]
1688
1689 rp_ip = rp[group] + "/32"
1690 input_dict = {
1691 "l1": {
1692 "static_routes": [
1693 {"network": rp_ip, "next_hop": next_hop_lhr, "delete": True}
1694 ]
1695 }
1696 }
1697 result = create_static_routes(tgen, input_dict)
1698 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1699
1700 # Verifying static routes are installed
1701 result = verify_rib(
1702 tgen, "ipv4", "l1", input_dict, protocol="static", expected=False
1703 )
1704 assert result is not True, (
1705 "Testcase {} : Failed \n "
1706 "Expected: Routes should not be present in {} BGP RIB \n "
1707 "Found: {}".format(tc_name, "l1", result)
1708 )
1709
1710 # Check RP unreachable
1711 step("Check RP unreachability")
1712 iif = "Unknown"
1713 result = verify_upstream_iif(
1714 tgen, dut, iif, src_addr, GROUP_ADDRESS, joinState="NotJoined"
1715 )
1716 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1717
1718 # Verify that it is not installed
1719 step("Verify that it is not installed")
1720 iif = "<iif?>"
1721 result = verify_pim_state(tgen, dut, iif, oil, GROUP_ADDRESS, installed_fl=0)
1722 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1723
1724 # Verify mroute not installed
1725 step("Verify mroute not installed")
1726 result = verify_mroutes(
1727 tgen, dut, src_addr, GROUP_ADDRESS, iif, oil, expected=False
1728 )
1729 assert result is not True, (
1730 "Testcase {} : Failed \n "
1731 "Expected: [{}]: mroute (S, G) should not be installed \n "
1732 "Found: {}".format(tc_name, dut, result)
1733 )
1734
1735 # Add back route for RP to make it reachable
1736 step("Add back route for RP to make it reachable")
1737 input_dict = {
1738 "l1": {
1739 "static_routes": [
1740 {
1741 "network": rp_ip,
1742 "next_hop": next_hop_lhr,
1743 }
1744 ]
1745 }
1746 }
1747 result = create_static_routes(tgen, input_dict)
1748 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1749
1750 # Verifying static routes are installed
1751 result = verify_rib(tgen, "ipv4", "l1", input_dict, next_hop_lhr, protocol="static")
1752 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1753
1754 # Verify that (*,G) installed in mroute again
1755 iif = "l1-i1-eth0"
1756 result = verify_mroutes(tgen, dut, src_addr, GROUP_ADDRESS, iif, oil)
1757 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1758
1759 step("clear BSM database before moving to next case")
1760 clear_bsrp_data(tgen, topo)
1761
1762 write_test_footer(tc_name)
1763
1764
1765 if __name__ == "__main__":
1766 args = ["-s"] + sys.argv[1:]
1767 sys.exit(pytest.main(args))