2 # SPDX-License-Identifier: ISC
4 # Copyright (c) 2020 by VMware, Inc. ("VMware")
5 # Used Copyright (c) 2018 by Network Device Education Foundation,
6 # Inc. ("NetDEF") in this file.
10 Following tests are covered to test PIM BSM processing basic functionality:
13 - Create topology (setup module)
16 Tests covered in this suite
17 1. Verify (*,G) mroute detail on FRR router after BSM rp installed
18 2. Verify group to RP updated correctly on FRR router, when BSR advertising
19 the overlapping group address
20 3. Verify group to RP info is updated correctly, when BSR advertising the
21 same RP with different priority
22 4. Verify group to RP mapping in FRR node when 2 BSR are present in the network
23 and both are having same BSR priority
24 5. Verify RP is selected based on hash function, when BSR advertising the group
25 to RP mapping with same priority
26 6. Verify fragmentation of bootstrap message
27 7. Verify when candidate RP advertised with 32 mask length
28 and contain all the contacts
36 # Save the Current Working Directory to find configuration files.
37 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
38 sys
.path
.append(os
.path
.join(CWD
, "../"))
39 sys
.path
.append(os
.path
.join(CWD
, "../lib/"))
41 # Required to instantiate the topology builder class.
43 # pylint: disable=C0413
44 # Import topogen and topotest helpers
45 from lib
.topogen
import Topogen
, get_topogen
47 from lib
.common_config
import (
54 reset_config_on_routers
,
56 required_linux_kernel_version
,
61 add_rp_interfaces_and_pim_config
,
63 scapy_send_bsr_raw_packet
,
64 find_rp_from_bsrp_info
,
65 verify_pim_grp_rp_source
,
68 verify_join_state_and_timer
,
72 verify_pim_upstream_rpf
,
74 clear_pim_interface_traffic
,
78 from lib
.topolog
import logger
79 from lib
.topojson
import build_config_from_json
81 pytestmark
= [pytest
.mark
.pimd
, pytest
.mark
.staticd
]
89 s1-----f1-----i1-----l1----r1
98 i1 - Intermediate Router (also RP)
103 NEXT_HOP1
= "70.0.0.1"
104 NEXT_HOP2
= "65.0.0.1"
106 BSR_IP_2
= "10.2.1.1"
107 BSR1_ADDR
= "1.1.2.7/32"
108 BSR2_ADDR
= "10.2.1.1/32"
111 def setup_module(mod
):
113 Sets up the pytest environment
118 # Required linux kernel version for this suite to run.
119 result
= required_linux_kernel_version("4.15")
120 if result
is not True:
121 pytest
.skip("Kernel version should be >= 4.15")
123 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
124 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
125 logger
.info("=" * 40)
126 logger
.info("Master Topology: \n {}".format(TOPOLOGY
))
128 logger
.info("Running setup_module to create topology")
130 # This function initiates the topology build with Topogen...
131 json_file
= "{}/mcast_pim_bsmp_02.json".format(CWD
)
132 tgen
= Topogen(json_file
, mod
.__name
__)
134 topo
= tgen
.json_topo
135 # ... and here it calls Mininet initialization functions.
137 # Starting topology, create tmp files which are loaded to routers
138 # to start daemons and then start routers
141 # Don"t run this test if we have any failure.
142 if tgen
.routers_have_failure():
143 pytest
.skip(tgen
.errors
)
145 # Creating configuration from JSON
146 build_config_from_json(tgen
, topo
)
148 # Verify PIM neighbors
149 result
= verify_pim_neighbors(tgen
, topo
)
150 assert result
is True, " Verify PIM neighbor: Failed Error: {}".format(result
)
152 # XXX Replace this using "with McastTesterHelper()... " in each test if possible.
154 app_helper
= McastTesterHelper(tgen
)
156 logger
.info("Running setup_module() done")
159 def teardown_module():
160 """Teardown the pytest environment"""
162 logger
.info("Running teardown_module to delete topology")
168 # Stop toplogy and Remove tmp files
172 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
174 logger
.info("=" * 40)
177 #####################################################
181 #####################################################
184 def clear_bsrp_data(tgen
, topo
):
187 clear bsm databas after test"
190 * `tgen`: topogen object
194 result = clear_bsrp_data(tgen, topo)
197 errormsg(str) or True
200 for dut
in tgen
.routers():
202 rnode
= tgen
.routers()[dut
]
204 logger
.info("[DUT: %s]: clear_bsrp_data")
206 run_frr_cmd(rnode
, "clear ip pim bsr-data")
211 def pre_config_to_bsm(tgen
, topo
, tc_name
, bsr
, sender
, receiver
, fhr
, rp
, lhr
, packet
):
213 API to do required configuration to send and receive BSR packet
216 # Re-configure interfaces as per BSR packet
217 result
= reconfig_interfaces(tgen
, topo
, bsr
, fhr
, packet
)
218 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
220 # Create static routes
221 if "bsr" in topo
["routers"][bsr
]["bsm"]["bsr_packets"][packet
]:
222 bsr_route
= topo
["routers"][bsr
]["bsm"]["bsr_packets"][packet
]["bsr"]
223 next_hop
= topo
["routers"][bsr
]["bsm"]["bsr_packets"][packet
]["src_ip"].split(
226 next_hop_rp
= topo
["routers"][fhr
]["links"][rp
]["ipv4"].split("/")[0]
227 next_hop_lhr
= topo
["routers"][rp
]["links"][lhr
]["ipv4"].split("/")[0]
231 rp
: {"static_routes": [{"network": bsr_route
, "next_hop": next_hop_rp
}]},
232 lhr
: {"static_routes": [{"network": bsr_route
, "next_hop": next_hop_lhr
}]},
235 result
= create_static_routes(tgen
, input_dict
)
236 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
238 # Verifying static routes are installed
239 for dut
, _nexthop
in zip([rp
, lhr
], [next_hop_rp
, next_hop_lhr
]):
240 input_routes
= {dut
: input_dict
[dut
]}
242 tgen
, "ipv4", dut
, input_routes
, _nexthop
, protocol
="static"
244 assert result
is True, "Testcase {} : Failed \n Error {}".format(
248 # Add kernel route for source
249 group
= topo
["routers"][bsr
]["bsm"]["bsr_packets"][packet
]["pkt_dst"]
250 bsr_interface
= topo
["routers"][bsr
]["links"][fhr
]["interface"]
251 result
= addKernelRoute(tgen
, bsr
, bsr_interface
, group
)
252 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
255 rp_mapping
= topo
["routers"][bsr
]["bsm"]["bsr_packets"][packet
]["rp_mapping"]
257 # Add interfaces in RP for all the RPs
258 result
= add_rp_interfaces_and_pim_config(tgen
, topo
, "lo", rp
, rp_mapping
)
259 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
261 # Add kernel routes to sender and receiver
262 for group
, rp_list
in rp_mapping
.items():
263 mask
= group
.split("/")[1]
265 group
= group
.split("/")[0]
267 # Add kernel routes for sender
268 s_interface
= topo
["routers"][sender
]["links"][fhr
]["interface"]
269 result
= addKernelRoute(tgen
, sender
, s_interface
, group
)
270 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
272 # Add kernel routes for receiver
273 r_interface
= topo
["routers"][receiver
]["links"][lhr
]["interface"]
274 result
= addKernelRoute(tgen
, receiver
, r_interface
, group
)
275 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
277 # Add static routes for RPs in FHR and LHR
278 next_hop_fhr
= topo
["routers"][rp
]["links"][fhr
]["ipv4"].split("/")[0]
279 next_hop_lhr
= topo
["routers"][rp
]["links"][lhr
]["ipv4"].split("/")[0]
281 fhr
: {"static_routes": [{"network": rp_list
, "next_hop": next_hop_fhr
}]},
283 result
= create_static_routes(tgen
, input_dict
)
284 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
286 # Verifying static routes are installed
288 tgen
, "ipv4", fhr
, input_dict
, next_hop_fhr
, protocol
="static"
290 assert result
is True, "Testcase {} : Failed \n Error {}".format(
295 lhr
: {"static_routes": [{"network": rp_list
, "next_hop": next_hop_lhr
}]},
297 result
= create_static_routes(tgen
, input_dict
)
298 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
300 # Verifying static routes are installed
302 tgen
, "ipv4", lhr
, input_dict
, next_hop_lhr
, protocol
="static"
304 assert result
is True, "Testcase {} : Failed \n Error {}".format(
311 #####################################################
315 #####################################################
318 def test_starg_mroute_p0(request
):
320 1. Verify (*,G) mroute detail on FRR router after BSM rp installed
326 s1-----f1-----i1-----l1----r1
335 i1 - Intermediate Router (also RP)
341 tc_name
= request
.node
.name
342 write_test_header(tc_name
)
344 # Don"t run this test if we have any failure.
345 if tgen
.routers_have_failure():
346 pytest
.skip(tgen
.errors
)
348 app_helper
.stop_all_hosts()
350 reset_config_on_routers(tgen
)
351 clear_pim_interface_traffic(tgen
, topo
)
353 result
= pre_config_to_bsm(
354 tgen
, topo
, tc_name
, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
356 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
358 result
= pre_config_to_bsm(
359 tgen
, topo
, tc_name
, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
361 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
363 GROUP_ADDRESS
= "226.1.1.1"
365 # Use scapy to send pre-defined packet from senser to receiver
366 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet1")
367 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
369 bsr_ip
= topo
["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
372 result
= app_helper
.run_join("r1", GROUP_ADDRESS
, "l1")
373 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
375 # Verify bsr state in FHR
376 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip
)
377 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
380 step("Verify IGMP groups in LHR l1")
383 result
= verify_igmp_groups(tgen
, dut
, intf
, GROUP_ADDRESS
)
384 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
386 group
= "226.1.1.1/32"
389 # Find the elected rp from bsrp-info
390 step("Find the elected rp from bsrp-info in LHR in l1")
391 rp
= find_rp_from_bsrp_info(tgen
, dut
, bsr_ip
, group
)
392 assert rp
is not {}, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
394 # Check RP detail in LHR
395 step("Verify RP in LHR in l1")
396 result
= verify_pim_grp_rp_source(tgen
, topo
, dut
, group
, "BSR", rp
[group
])
397 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
399 # Verify join state and join timer
400 step("Verify join state and join timer in l1")
402 result
= verify_join_state_and_timer(tgen
, dut
, iif
, src_addr
, GROUP_ADDRESS
)
403 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
405 # Verify upstream IIF interface
406 step("Verify upstream IIF interface in l1")
407 result
= verify_upstream_iif(tgen
, dut
, iif
, src_addr
, GROUP_ADDRESS
)
408 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
410 # Verify IIF/OIL in pim state
412 result
= verify_pim_state(tgen
, dut
, iif
, oil
, GROUP_ADDRESS
)
413 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
416 step("Verify ip mroute in l1")
418 result
= verify_mroutes(tgen
, dut
, src_addr
, GROUP_ADDRESS
, iif
, oil
)
419 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
421 # Remove the group rp mapping and send bsm
422 step("Remove the grp-rp mapping by sending bsm with hold time 0 for grp-rp")
423 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet2")
424 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
426 # Check RP unreachable
427 step("Check RP unreachability in l1")
429 result
= verify_upstream_iif(
430 tgen
, dut
, iif
, src_addr
, GROUP_ADDRESS
, joinState
="NotJoined"
432 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
434 # Verify that it is not installed
435 step("Verify that iif is not installed in l1")
437 result
= verify_pim_state(tgen
, dut
, iif
, oil
, GROUP_ADDRESS
, installed_fl
=0)
438 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
440 # Verify mroute not installed
441 step("Verify mroute not installed in l1")
442 result
= verify_mroutes(
443 tgen
, dut
, src_addr
, GROUP_ADDRESS
, iif
, oil
, retry_timeout
=20, expected
=False
445 assert result
is not True, (
446 "Testcase {} : Failed \n "
447 "Expected: [{}]: mroute (S, G) should not be installed \n "
448 "Found: {}".format(tc_name
, dut
, result
)
451 # Send BSM again to configure rp
452 step("Add back RP by sending BSM from b1")
453 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet1")
454 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
456 # Verify that (*,G) installed in mroute again
458 result
= verify_mroutes(tgen
, dut
, src_addr
, GROUP_ADDRESS
, iif
, oil
)
459 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
461 step("clear BSM database before moving to next case")
462 clear_bsrp_data(tgen
, topo
)
464 write_test_footer(tc_name
)
467 def test_overlapping_group_p0(request
):
469 Verify group to RP updated correctly on FRR router, when BSR advertising
470 the overlapping group address
476 s1-----f1-----i1-----l1----r1
485 i1 - Intermediate Router (also RP)
491 tc_name
= request
.node
.name
492 write_test_header(tc_name
)
494 # Don"t run this test if we have any failure.
495 if tgen
.routers_have_failure():
496 pytest
.skip(tgen
.errors
)
498 app_helper
.stop_all_hosts()
500 reset_config_on_routers(tgen
)
501 clear_pim_interface_traffic(tgen
, topo
)
503 result
= pre_config_to_bsm(
504 tgen
, topo
, tc_name
, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
506 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
508 result
= pre_config_to_bsm(
509 tgen
, topo
, tc_name
, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
511 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
513 GROUP_ADDRESS
= "225.1.1.1"
515 # Use scapy to send pre-defined packet from senser to receiver
516 step("Send BSR packet from b1 to FHR")
517 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet4")
518 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
520 bsr_ip
= topo
["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
523 result
= app_helper
.run_join("r1", GROUP_ADDRESS
, "l1")
524 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
526 # Verify bsr state in FHR
527 step("Verify if b1 is chosen as bsr in f1")
528 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip
)
529 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
532 group1
= "225.1.1.1/32"
533 # Find the elected rp from bsrp-info fro group 225.1.1.1/32
534 step("Find the elected rp from bsrp-info in LHR for 225.1.1.1/32")
535 rp1
= find_rp_from_bsrp_info(tgen
, dut
, bsr_ip
, group1
)
536 assert rp1
is not {}, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
538 group2
= "225.1.1.0/24"
539 # Find the elected rp from bsrp-info fro group 225.1.1.0/24
540 step("Find the elected rp from bsrp-info in LHR for 225.1.1.0/24")
541 rp2
= find_rp_from_bsrp_info(tgen
, dut
, bsr_ip
, group2
)
542 assert rp2
is not {}, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
545 # Verify upstream rpf for 225.1.1.1 is chosen as rp1
546 step("Verify upstream rpf for 225.1.1.1 is chosen as rp1 in l1")
547 result
= verify_pim_upstream_rpf(tgen
, topo
, dut
, iif
, GROUP_ADDRESS
, rp1
)
548 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
550 # Send BSR packet from b1 with rp for 225.1.1.1/32 removed
551 step("Send BSR packet from b1 with rp for 225.1.1.1/32 removed")
552 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet5")
553 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
555 # Verify upstream rpf for 225.1.1.1 is chosen as rp1
556 step("Verify upstream rpf for 225.1.1.1 is chosen as rp2 in l1")
557 result
= verify_pim_upstream_rpf(tgen
, topo
, dut
, iif
, GROUP_ADDRESS
, rp2
)
558 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
560 # Verify IIF/OIL in pim state
561 step("Verify iif is installed after rp change in l1")
563 result
= verify_pim_state(tgen
, dut
, iif
, oil
, GROUP_ADDRESS
)
564 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
566 step("clear BSM database before moving to next case")
567 clear_bsrp_data(tgen
, topo
)
569 write_test_footer(tc_name
)
572 def test_RP_priority_p0(request
):
574 Verify group to RP info is updated correctly, when BSR advertising the
575 same RP with different priority
581 s1-----f1-----i1-----l1----r1
590 i1 - Intermediate Router (also RP)
595 tc_name
= request
.node
.name
596 write_test_header(tc_name
)
598 # Don"t run this test if we have any failure.
599 if tgen
.routers_have_failure():
600 pytest
.skip(tgen
.errors
)
602 app_helper
.stop_all_hosts()
604 reset_config_on_routers(tgen
)
605 clear_pim_interface_traffic(tgen
, topo
)
607 result
= pre_config_to_bsm(
608 tgen
, topo
, tc_name
, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
610 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
612 result
= pre_config_to_bsm(
613 tgen
, topo
, tc_name
, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
615 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
617 GROUP_ADDRESS
= "225.1.1.1"
619 # Use scapy to send pre-defined packet from senser to receiver
620 step("Send BSR packet from b1 to FHR")
621 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet1")
622 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
624 bsr_ip
= topo
["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
627 result
= app_helper
.run_join("r1", GROUP_ADDRESS
, "l1")
628 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
630 # Verify bsr state in FHR
631 step("Verify if b1 is chosen as bsr in f1")
632 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip
)
633 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
636 group
= "225.1.1.0/24"
637 # Find the elected rp from bsrp-info
638 step("Find the elected rp from bsrp-info in LHR l1")
639 rp1
= find_rp_from_bsrp_info(tgen
, dut
, bsr_ip
, group
)
640 assert rp1
is not {}, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
642 # Check RP detail in LHR
643 step("Verify RP in LHR l1")
644 result
= verify_pim_grp_rp_source(tgen
, topo
, dut
, group
, "BSR", rp1
[group
])
645 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
647 # Send BSR packet from b1 after deleting high prio rp for 225.1.1.0/24
648 step("Send BSM from b1 to FHR deleting high prio rp for 225.1.1.0/24")
649 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet6")
650 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
652 # Find the elected rp from bsrp-info
653 step("Find the elected rp from bsrp-info in LHR l1")
654 rp2
= find_rp_from_bsrp_info(tgen
, dut
, bsr_ip
, group
)
655 assert rp2
is not {}, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
656 logger
.info("RP old: {} RP2 new: {} ".format(rp1
[group
], rp2
[group
]))
658 # Verify is the rp is different now
659 assert rp1
[group
] != rp2
[group
], "Testcase {} :Failed \n Error {}".format(
666 # Verify if that rp is installed
667 step("Verify new RP in LHR installed")
668 result
= verify_pim_grp_rp_source(tgen
, topo
, dut
, group
, "BSR", rp_add2
)
669 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
671 # Send BSR packet from b1 after putting back high prio rp for 225.1.1.0/24
672 step("Send BSM from b1 to FHR put back old high prio rp for 225.1.1.0/24")
673 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet1")
674 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
676 # Find the elected rp from bsrp-info
677 step("Find the elected rp from bsrp-info in LHR")
678 rp2
= find_rp_from_bsrp_info(tgen
, dut
, bsr_ip
, group
)
679 assert rp2
is not {}, "Testcase {} :Failed \n Error : RP not Found".format(tc_name
)
681 # Verify is the rp is different now
682 step("Verify now old RP is elected again")
684 rp_add1
== rp2
[group
]
685 ), "Testcase {} :Failed \n Error : rp expected {} rp received {}".format(
686 tc_name
, rp_add1
, rp2
[group
] if group
in rp2
else None
689 # Verify if that rp is installed
690 step("Verify new RP in LHR installed")
691 result
= verify_pim_grp_rp_source(tgen
, topo
, dut
, group
, "BSR", rp_add1
)
692 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
694 step("clear BSM database before moving to next case")
695 clear_bsrp_data(tgen
, topo
)
697 write_test_footer(tc_name
)
700 def test_BSR_election_p0(request
):
702 Verify group to RP mapping in FRR node when 2 BSR are present in the network
703 and both are having same BSR priority
709 s1-----f1-----i1-----l1----r1
718 i1 - Intermediate Router (also RP)
724 tc_name
= request
.node
.name
725 write_test_header(tc_name
)
727 app_helper
.stop_all_hosts()
729 reset_config_on_routers(tgen
)
730 clear_pim_interface_traffic(tgen
, topo
)
732 # Don"t run this test if we have any failure.
733 if tgen
.routers_have_failure():
734 pytest
.skip(tgen
.errors
)
736 result
= pre_config_to_bsm(
737 tgen
, topo
, tc_name
, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
739 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
741 result
= pre_config_to_bsm(
742 tgen
, topo
, tc_name
, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
744 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
746 GROUP_ADDRESS
= "225.1.1.1"
748 # Use scapy to send pre-defined packet from senser to receiver
749 step("Send BSR packet from b1 to FHR")
750 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet3")
751 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
753 bsr_ip1
= topo
["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[
758 result
= app_helper
.run_join("r1", GROUP_ADDRESS
, "l1")
759 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
761 # Verify bsr state in FHR
762 step("Verify if b1 is chosen as bsr in f1")
763 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip1
)
764 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
767 group
= "225.1.1.0/24"
768 # Find the elected rp from bsrp-info
769 step("Find the elected rp from bsrp-info in LHR in l1")
770 rp
= find_rp_from_bsrp_info(tgen
, dut
, bsr_ip1
, group
)
771 assert rp
is not {}, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
773 # Check RP detail in LHR
774 step("Verify RP in LHR l1")
775 result
= verify_pim_grp_rp_source(tgen
, topo
, dut
, group
, "BSR", rp
[group
])
776 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
778 # Send BSR packet from b2 with same priority
779 step("Send BSR packet from b2 to FHR with same priority")
780 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b2", "f1", "packet1")
781 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
783 bsr_ip2
= topo
["routers"]["b2"]["bsm"]["bsr_packets"]["packet2"]["bsr"].split("/")[
788 logger
.info("BSR b1:" + bsr_ip1
+ " BSR b2:" + bsr_ip2
)
789 # Verify bsr state in FHR
790 step("Verify if b2 is not chosen as bsr in f1")
791 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip2
, expected
=False)
792 assert result
is not True, (
793 "Testcase {} : Failed \n "
794 "Expected: [{}]: b2 should not be chosen as bsr \n "
795 "Found: {}".format(tc_name
, "f1", result
)
798 # Verify if b1 is still chosen as bsr
799 step("Verify if b1 is still chosen as bsr in f1")
800 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip1
)
801 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
803 # Verify if that rp is installed
804 step("Verify that same RP in istalled in LHR l1")
805 result
= verify_pim_grp_rp_source(tgen
, topo
, dut
, group
, "BSR", rp
[group
])
806 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
808 step("clear BSM database before moving to next case")
809 clear_bsrp_data(tgen
, topo
)
811 write_test_footer(tc_name
)
814 def test_RP_hash_p0(request
):
816 Verify RP is selected based on hash function, when BSR advertising the group
817 to RP mapping with same priority
823 s1-----f1-----i1-----l1----r1
832 i1 - Intermediate Router (also RP)
838 tc_name
= request
.node
.name
839 write_test_header(tc_name
)
841 # Don"t run this test if we have any failure.
842 if tgen
.routers_have_failure():
843 pytest
.skip(tgen
.errors
)
845 app_helper
.stop_all_hosts()
847 reset_config_on_routers(tgen
)
848 clear_pim_interface_traffic(tgen
, topo
)
850 result
= pre_config_to_bsm(
851 tgen
, topo
, tc_name
, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
853 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
855 result
= pre_config_to_bsm(
856 tgen
, topo
, tc_name
, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
858 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
860 GROUP_ADDRESS
= "225.1.1.1"
862 # Use scapy to send pre-defined packet from senser to receiver
863 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet7")
864 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
866 bsr_ip
= topo
["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
869 result
= app_helper
.run_join("r1", GROUP_ADDRESS
, "l1")
870 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
874 # Verify bsr state in FHR
875 step("Verify if b1 chosen as BSR in f1")
876 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip
)
877 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
879 group
= "225.1.1.0/24"
881 # Find the elected rp from bsrp-info
882 step("Find the elected rp from bsrp-info in LHR l1")
883 rp
= find_rp_from_bsrp_info(tgen
, dut
, bsr_ip
, group
)
884 assert rp
is not {}, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
886 # Verify if RP with highest hash value is chosen
887 step("Verify if RP(2.2.2.2) with highest hash value is chosen in l1")
888 if rp
[group
] == "2.2.2.2":
891 result
= "rp expected: 2.2.2.2 got:" + rp
[group
]
893 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
895 # Check RP detail in LHR
896 step("Verify RP in LHR")
897 result
= verify_pim_grp_rp_source(tgen
, topo
, dut
, group
, "BSR", rp
[group
])
898 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
900 step("clear BSM database before moving to next case")
901 clear_bsrp_data(tgen
, topo
)
903 write_test_footer(tc_name
)
906 def test_BSM_fragmentation_p1(request
):
908 Verify fragmentation of bootstrap message
914 s1-----f1-----i1-----l1----r1
923 i1 - Intermediate Router (also RP)
929 tc_name
= request
.node
.name
930 write_test_header(tc_name
)
932 # Don"t run this test if we have any failure.
933 if tgen
.routers_have_failure():
934 pytest
.skip(tgen
.errors
)
936 app_helper
.stop_all_hosts()
938 reset_config_on_routers(tgen
)
939 clear_pim_interface_traffic(tgen
, topo
)
941 result
= pre_config_to_bsm(
942 tgen
, topo
, tc_name
, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
944 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
946 result
= pre_config_to_bsm(
947 tgen
, topo
, tc_name
, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
949 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
951 GROUP_ADDRESS
= "225.1.1.1"
953 bsr_ip
= topo
["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
955 step("Send BSM and verify if all routers have same bsrp before fragment")
956 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet1")
957 # Verify bsr state in FHR
958 step("Verify if b1 chosen as BSR in f1")
959 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip
)
960 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
962 fhr_node
= tgen
.routers()["f1"]
963 inter_node
= tgen
.routers()["i1"]
964 lhr_node
= tgen
.routers()["l1"]
966 # Verify if bsrp list is same across f1, i1 and l1
967 step("Verify if bsrp list is same across f1, i1 and l1")
968 bsrp_f1
= fhr_node
.vtysh_cmd("show ip pim bsrp-info json", isjson
=True)
969 logger
.info("show_ip_pim_bsrp_info_json f1: \n %s", bsrp_f1
)
970 bsrp_i1
= inter_node
.vtysh_cmd("show ip pim bsrp-info json", isjson
=True)
971 logger
.info("show_ip_pim_bsrp_info_json i1: \n %s", bsrp_i1
)
972 bsrp_l1
= lhr_node
.vtysh_cmd("show ip pim bsrp-info json", isjson
=True)
973 logger
.info("show_ip_pim_bsrp_info_json l1: \n %s", bsrp_l1
)
975 if bsrp_f1
== bsrp_l1
:
978 result
= "bsrp info in f1 is not same in l1"
980 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
982 # set mtu of fhr(f1) to i1 interface to 100 so that bsm fragments
983 step("set mtu of fhr(f1) to i1 interface to 100 so that bsm fragments")
984 fhr_node
.run("ip link set f1-i1-eth2 mtu 100")
985 inter_node
.run("ip link set i1-f1-eth0 mtu 100")
987 # Use scapy to send pre-defined packet from senser to receiver
988 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet2")
989 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
991 result
= app_helper
.run_join("r1", GROUP_ADDRESS
, "l1")
992 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
994 # Verify bsr state in FHR
995 step("Verify if b1 chosen as BSR")
996 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip
)
997 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
999 # Verify if bsrp list is same across f1, i1 and l1
1000 step("Verify if bsrp list is same across f1, i1 and l1 after fragmentation")
1001 bsrp_f1
= fhr_node
.vtysh_cmd("show ip pim bsrp-info json", isjson
=True)
1002 logger
.info("show_ip_pim_bsrp_info_json f1: \n %s", bsrp_f1
)
1003 bsrp_i1
= inter_node
.vtysh_cmd("show ip pim bsrp-info json", isjson
=True)
1004 logger
.info("show_ip_pim_bsrp_info_json i1: \n %s", bsrp_i1
)
1005 bsrp_l1
= lhr_node
.vtysh_cmd("show ip pim bsrp-info json", isjson
=True)
1006 logger
.info("show_ip_pim_bsrp_info_json l1: \n %s", bsrp_l1
)
1008 if bsrp_f1
== bsrp_l1
:
1011 result
= "bsrp info in f1 is not same in l1"
1013 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1015 step("clear BSM database before moving to next case")
1016 clear_bsrp_data(tgen
, topo
)
1018 write_test_footer(tc_name
)
1021 def test_RP_with_all_ip_octet_p1(request
):
1023 Verify when candidate RP advertised with 32 mask length
1024 and contain all the contacts
1030 s1-----f1-----i1-----l1----r1
1039 i1 - Intermediate Router (also RP)
1044 tgen
= get_topogen()
1045 tc_name
= request
.node
.name
1046 write_test_header(tc_name
)
1048 # Don"t run this test if we have any failure.
1049 if tgen
.routers_have_failure():
1050 pytest
.skip(tgen
.errors
)
1052 app_helper
.stop_all_hosts()
1054 reset_config_on_routers(tgen
)
1055 clear_pim_interface_traffic(tgen
, topo
)
1057 step("pre-configure BSM packet")
1058 result
= pre_config_to_bsm(
1059 tgen
, topo
, tc_name
, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
1061 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1063 step("Send the IGMP group (225.100.100.100) from receiver connected to FRR")
1064 GROUP_ADDRESS
= "225.200.100.100"
1066 # Use scapy to send pre-defined packet from senser to receiver
1067 step("Configure cisco-1 as BSR1")
1068 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet8")
1069 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1071 bsr_ip
= topo
["routers"]["b1"]["bsm"]["bsr_packets"]["packet8"]["bsr"].split("/")[0]
1074 result
= app_helper
.run_join("r1", GROUP_ADDRESS
, "l1")
1075 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
1079 "Groups are shown with candidate RP with correct mask length 'show ip pim bsrp-info'"
1081 step("Verify if b1 chosen as BSR in f1")
1082 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip
)
1083 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1085 group
= topo
["routers"]["b1"]["bsm"]["bsr_packets"]["packet9"]["group"]
1086 step("Find the elected rp from bsrp-info in LHR l1")
1087 rp
= find_rp_from_bsrp_info(tgen
, dut
, bsr_ip
, group
)
1088 assert rp
is not {}, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1090 step("Verify RP in LHR")
1091 result
= verify_pim_grp_rp_source(tgen
, topo
, dut
, group
, "BSR", rp
[group
])
1092 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
1094 step("clear BSM database before moving to next case")
1095 clear_bsrp_data(tgen
, topo
)
1097 write_test_footer(tc_name
)
1100 if __name__
== "__main__":
1101 args
= ["-s"] + sys
.argv
[1:]
1102 sys
.exit(pytest
.main(args
))