3 # Copyright (c) 2020 by VMware, Inc. ("VMware")
4 # Used Copyright (c) 2018 by Network Device Education Foundation,
5 # Inc. ("NetDEF") in this file.
7 # Permission to use, copy, modify, and/or distribute this software
8 # for any purpose with or without fee is hereby granted, provided
9 # that the above copyright notice and this permission notice appear
12 # THE SOFTWARE IS PROVIDED "AS IS" AND VMWARE DISCLAIMS ALL WARRANTIES
13 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL VMWARE BE LIABLE FOR
15 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
16 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
17 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
18 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
23 Following tests are covered to test PIM BSM processing basic functionality:
26 - Create topology (setup module)
29 Tests covered in this suite
30 1. Verify (*,G) mroute detail on FRR router after BSM rp installed
31 2. Verify group to RP updated correctly on FRR router, when BSR advertising
32 the overlapping group address
33 3. Verify group to RP info is updated correctly, when BSR advertising the
34 same RP with different priority
35 4. Verify group to RP mapping in FRR node when 2 BSR are present in the network
36 and both are having same BSR priority
37 5. Verify RP is selected based on hash function, when BSR advertising the group
38 to RP mapping with same priority
39 6. Verify fragmentation of bootstrap message
40 7. Verify when candidate RP advertised with 32 mask length
41 and contain all the contacts
49 # Save the Current Working Directory to find configuration files.
50 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
51 sys
.path
.append(os
.path
.join(CWD
, "../"))
52 sys
.path
.append(os
.path
.join(CWD
, "../lib/"))
54 # Required to instantiate the topology builder class.
56 # pylint: disable=C0413
57 # Import topogen and topotest helpers
58 from lib
.topogen
import Topogen
, get_topogen
60 from lib
.common_config
import (
67 reset_config_on_routers
,
69 required_linux_kernel_version
,
75 add_rp_interfaces_and_pim_config
,
77 scapy_send_bsr_raw_packet
,
78 find_rp_from_bsrp_info
,
79 verify_pim_grp_rp_source
,
82 verify_join_state_and_timer
,
86 verify_pim_upstream_rpf
,
88 clear_pim_interface_traffic
,
92 from lib
.topolog
import logger
93 from lib
.topojson
import build_config_from_json
95 pytestmark
= [pytest
.mark
.pimd
, pytest
.mark
.staticd
]
103 s1-----f1-----i1-----l1----r1
112 i1 - Intermediate Router (also RP)
117 NEXT_HOP1
= "70.0.0.1"
118 NEXT_HOP2
= "65.0.0.1"
120 BSR_IP_2
= "10.2.1.1"
121 BSR1_ADDR
= "1.1.2.7/32"
122 BSR2_ADDR
= "10.2.1.1/32"
125 def setup_module(mod
):
127 Sets up the pytest environment
132 # Required linux kernel version for this suite to run.
133 result
= required_linux_kernel_version("4.15")
134 if result
is not True:
135 pytest
.skip("Kernel requirements are not met")
137 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
138 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
139 logger
.info("=" * 40)
140 logger
.info("Master Topology: \n {}".format(TOPOLOGY
))
142 logger
.info("Running setup_module to create topology")
144 # This function initiates the topology build with Topogen...
145 json_file
= "{}/mcast_pim_bsmp_02.json".format(CWD
)
146 tgen
= Topogen(json_file
, mod
.__name
__)
148 topo
= tgen
.json_topo
149 # ... and here it calls Mininet initialization functions.
151 # get list of daemons needs to be started for this suite.
152 daemons
= topo_daemons(tgen
, topo
)
154 # Starting topology, create tmp files which are loaded to routers
155 # to start daemons and then start routers
156 start_topology(tgen
, daemons
)
158 # Don"t run this test if we have any failure.
159 if tgen
.routers_have_failure():
160 pytest
.skip(tgen
.errors
)
162 # Creating configuration from JSON
163 build_config_from_json(tgen
, topo
)
165 # Verify PIM neighbors
166 result
= verify_pim_neighbors(tgen
, topo
)
167 assert result
is True, " Verify PIM neighbor: Failed Error: {}".format(result
)
169 # XXX Replace this using "with McastTesterHelper()... " in each test if possible.
171 app_helper
= McastTesterHelper(tgen
)
173 logger
.info("Running setup_module() done")
176 def teardown_module():
177 """Teardown the pytest environment"""
179 logger
.info("Running teardown_module to delete topology")
185 # Stop toplogy and Remove tmp files
189 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
191 logger
.info("=" * 40)
194 #####################################################
198 #####################################################
201 def clear_bsrp_data(tgen
, topo
):
204 clear bsm databas after test"
207 * `tgen`: topogen object
211 result = clear_bsrp_data(tgen, topo)
214 errormsg(str) or True
217 for dut
in tgen
.routers():
219 rnode
= tgen
.routers()[dut
]
221 logger
.info("[DUT: %s]: clear_bsrp_data")
223 run_frr_cmd(rnode
, "clear ip pim bsr-data")
228 def pre_config_to_bsm(tgen
, topo
, tc_name
, bsr
, sender
, receiver
, fhr
, rp
, lhr
, packet
):
230 API to do required configuration to send and receive BSR packet
233 # Re-configure interfaces as per BSR packet
234 result
= reconfig_interfaces(tgen
, topo
, bsr
, fhr
, packet
)
235 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
237 # Create static routes
238 if "bsr" in topo
["routers"][bsr
]["bsm"]["bsr_packets"][packet
]:
239 bsr_route
= topo
["routers"][bsr
]["bsm"]["bsr_packets"][packet
]["bsr"]
240 next_hop
= topo
["routers"][bsr
]["bsm"]["bsr_packets"][packet
]["src_ip"].split(
243 next_hop_rp
= topo
["routers"][fhr
]["links"][rp
]["ipv4"].split("/")[0]
244 next_hop_lhr
= topo
["routers"][rp
]["links"][lhr
]["ipv4"].split("/")[0]
248 fhr
: {"static_routes": [{"network": bsr_route
, "next_hop": next_hop
}]},
249 rp
: {"static_routes": [{"network": bsr_route
, "next_hop": next_hop_rp
}]},
250 lhr
: {"static_routes": [{"network": bsr_route
, "next_hop": next_hop_lhr
}]},
253 result
= create_static_routes(tgen
, input_dict
)
254 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
256 # Verifying static routes are installed
257 for dut
, _nexthop
in zip([fhr
, rp
, lhr
], [next_hop
, next_hop_rp
, next_hop_lhr
]):
258 input_routes
= {dut
: input_dict
[dut
]}
259 result
= verify_rib(tgen
, "ipv4", dut
, input_routes
, _nexthop
)
260 assert result
is True, "Testcase {} : Failed \n Error {}".format(
264 # Add kernel route for source
265 group
= topo
["routers"][bsr
]["bsm"]["bsr_packets"][packet
]["pkt_dst"]
266 bsr_interface
= topo
["routers"][bsr
]["links"][fhr
]["interface"]
267 result
= addKernelRoute(tgen
, bsr
, bsr_interface
, group
)
268 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
271 rp_mapping
= topo
["routers"][bsr
]["bsm"]["bsr_packets"][packet
]["rp_mapping"]
273 # Add interfaces in RP for all the RPs
274 result
= add_rp_interfaces_and_pim_config(tgen
, topo
, "lo", rp
, rp_mapping
)
275 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
277 # Add kernel routes to sender and receiver
278 for group
, rp_list
in rp_mapping
.items():
279 mask
= group
.split("/")[1]
281 group
= group
.split("/")[0]
283 # Add kernel routes for sender
284 s_interface
= topo
["routers"][sender
]["links"][fhr
]["interface"]
285 result
= addKernelRoute(tgen
, sender
, s_interface
, group
)
286 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
288 # Add kernel routes for receiver
289 r_interface
= topo
["routers"][receiver
]["links"][lhr
]["interface"]
290 result
= addKernelRoute(tgen
, receiver
, r_interface
, group
)
291 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
293 # Add static routes for RPs in FHR and LHR
294 next_hop_fhr
= topo
["routers"][rp
]["links"][fhr
]["ipv4"].split("/")[0]
295 next_hop_lhr
= topo
["routers"][rp
]["links"][lhr
]["ipv4"].split("/")[0]
297 fhr
: {"static_routes": [{"network": rp_list
, "next_hop": next_hop_fhr
}]},
299 result
= create_static_routes(tgen
, input_dict
)
300 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
302 # Verifying static routes are installed
303 result
= verify_rib(tgen
, "ipv4", fhr
, input_dict
, next_hop_fhr
)
304 assert result
is True, "Testcase {} : Failed \n Error {}".format(
309 lhr
: {"static_routes": [{"network": rp_list
, "next_hop": next_hop_lhr
}]},
311 result
= create_static_routes(tgen
, input_dict
)
312 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
314 # Verifying static routes are installed
315 result
= verify_rib(tgen
, "ipv4", lhr
, input_dict
, next_hop_lhr
)
316 assert result
is True, "Testcase {} : Failed \n Error {}".format(
323 #####################################################
327 #####################################################
330 def test_starg_mroute_p0(request
):
332 1. Verify (*,G) mroute detail on FRR router after BSM rp installed
338 s1-----f1-----i1-----l1----r1
347 i1 - Intermediate Router (also RP)
353 tc_name
= request
.node
.name
354 write_test_header(tc_name
)
356 # Don"t run this test if we have any failure.
357 if tgen
.routers_have_failure():
358 pytest
.skip(tgen
.errors
)
360 app_helper
.stop_all_hosts()
362 reset_config_on_routers(tgen
)
363 clear_pim_interface_traffic(tgen
, topo
)
365 result
= pre_config_to_bsm(
366 tgen
, topo
, tc_name
, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
368 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
370 result
= pre_config_to_bsm(
371 tgen
, topo
, tc_name
, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
373 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
375 GROUP_ADDRESS
= "226.1.1.1"
377 # Use scapy to send pre-defined packet from senser to receiver
378 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet1")
379 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
381 bsr_ip
= topo
["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
384 result
= app_helper
.run_join("r1", GROUP_ADDRESS
, "l1")
385 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
387 # Verify bsr state in FHR
388 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip
)
389 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
392 step("Verify IGMP groups in LHR l1")
395 result
= verify_igmp_groups(tgen
, dut
, intf
, GROUP_ADDRESS
)
396 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
398 group
= "226.1.1.1/32"
401 # Find the elected rp from bsrp-info
402 step("Find the elected rp from bsrp-info in LHR in l1")
403 rp
= find_rp_from_bsrp_info(tgen
, dut
, bsr_ip
, group
)
404 assert rp
is not {}, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
406 # Check RP detail in LHR
407 step("Verify RP in LHR in l1")
408 result
= verify_pim_grp_rp_source(tgen
, topo
, dut
, group
, "BSR", rp
[group
])
409 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
411 # Verify join state and join timer
412 step("Verify join state and join timer in l1")
414 result
= verify_join_state_and_timer(tgen
, dut
, iif
, src_addr
, GROUP_ADDRESS
)
415 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
417 # Verify upstream IIF interface
418 step("Verify upstream IIF interface in l1")
419 result
= verify_upstream_iif(tgen
, dut
, iif
, src_addr
, GROUP_ADDRESS
)
420 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
422 # Verify IIF/OIL in pim state
424 result
= verify_pim_state(tgen
, dut
, iif
, oil
, GROUP_ADDRESS
)
425 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
428 step("Verify ip mroute in l1")
430 result
= verify_mroutes(tgen
, dut
, src_addr
, GROUP_ADDRESS
, iif
, oil
)
431 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
433 # Remove the group rp mapping and send bsm
434 step("Remove the grp-rp mapping by sending bsm with hold time 0 for grp-rp")
435 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet2")
436 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
438 # Check RP unreachable
439 step("Check RP unreachability in l1")
441 result
= verify_upstream_iif(
442 tgen
, dut
, iif
, src_addr
, GROUP_ADDRESS
, joinState
="NotJoined"
444 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
446 # Verify that it is not installed
447 step("Verify that iif is not installed in l1")
449 result
= verify_pim_state(tgen
, dut
, iif
, oil
, GROUP_ADDRESS
, installed_fl
=0)
450 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
452 # Verify mroute not installed
453 step("Verify mroute not installed in l1")
454 result
= verify_mroutes(
455 tgen
, dut
, src_addr
, GROUP_ADDRESS
, iif
, oil
, retry_timeout
=20, expected
=False
459 ), "Testcase {} : Failed \n " "mroute installed in l1 \n Error: {}".format(
463 # Send BSM again to configure rp
464 step("Add back RP by sending BSM from b1")
465 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet1")
466 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
468 # Verify that (*,G) installed in mroute again
470 result
= verify_mroutes(tgen
, dut
, src_addr
, GROUP_ADDRESS
, iif
, oil
)
471 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
473 step("clear BSM database before moving to next case")
474 clear_bsrp_data(tgen
, topo
)
476 write_test_footer(tc_name
)
479 def test_overlapping_group_p0(request
):
481 Verify group to RP updated correctly on FRR router, when BSR advertising
482 the overlapping group address
488 s1-----f1-----i1-----l1----r1
497 i1 - Intermediate Router (also RP)
503 tc_name
= request
.node
.name
504 write_test_header(tc_name
)
506 # Don"t run this test if we have any failure.
507 if tgen
.routers_have_failure():
508 pytest
.skip(tgen
.errors
)
510 app_helper
.stop_all_hosts()
512 reset_config_on_routers(tgen
)
513 clear_pim_interface_traffic(tgen
, topo
)
515 result
= pre_config_to_bsm(
516 tgen
, topo
, tc_name
, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
518 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
520 result
= pre_config_to_bsm(
521 tgen
, topo
, tc_name
, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
523 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
525 GROUP_ADDRESS
= "225.1.1.1"
527 # Use scapy to send pre-defined packet from senser to receiver
528 step("Send BSR packet from b1 to FHR")
529 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet4")
530 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
532 bsr_ip
= topo
["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
535 result
= app_helper
.run_join("r1", GROUP_ADDRESS
, "l1")
536 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
538 # Verify bsr state in FHR
539 step("Verify if b1 is chosen as bsr in f1")
540 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip
)
541 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
544 group1
= "225.1.1.1/32"
545 # Find the elected rp from bsrp-info fro group 225.1.1.1/32
546 step("Find the elected rp from bsrp-info in LHR for 225.1.1.1/32")
547 rp1
= find_rp_from_bsrp_info(tgen
, dut
, bsr_ip
, group1
)
548 assert rp1
is not {}, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
550 group2
= "225.1.1.0/24"
551 # Find the elected rp from bsrp-info fro group 225.1.1.0/24
552 step("Find the elected rp from bsrp-info in LHR for 225.1.1.0/24")
553 rp2
= find_rp_from_bsrp_info(tgen
, dut
, bsr_ip
, group2
)
554 assert rp2
is not {}, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
557 # Verify upstream rpf for 225.1.1.1 is chosen as rp1
558 step("Verify upstream rpf for 225.1.1.1 is chosen as rp1 in l1")
559 result
= verify_pim_upstream_rpf(tgen
, topo
, dut
, iif
, GROUP_ADDRESS
, rp1
)
560 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
562 # Send BSR packet from b1 with rp for 225.1.1.1/32 removed
563 step("Send BSR packet from b1 with rp for 225.1.1.1/32 removed")
564 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet5")
565 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
567 # Verify upstream rpf for 225.1.1.1 is chosen as rp1
568 step("Verify upstream rpf for 225.1.1.1 is chosen as rp2 in l1")
569 result
= verify_pim_upstream_rpf(tgen
, topo
, dut
, iif
, GROUP_ADDRESS
, rp2
)
570 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
572 # Verify IIF/OIL in pim state
573 step("Verify iif is installed after rp change in l1")
575 result
= verify_pim_state(tgen
, dut
, iif
, oil
, GROUP_ADDRESS
)
576 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
578 step("clear BSM database before moving to next case")
579 clear_bsrp_data(tgen
, topo
)
581 write_test_footer(tc_name
)
584 def test_RP_priority_p0(request
):
586 Verify group to RP info is updated correctly, when BSR advertising the
587 same RP with different priority
593 s1-----f1-----i1-----l1----r1
602 i1 - Intermediate Router (also RP)
607 tc_name
= request
.node
.name
608 write_test_header(tc_name
)
610 # Don"t run this test if we have any failure.
611 if tgen
.routers_have_failure():
612 pytest
.skip(tgen
.errors
)
614 app_helper
.stop_all_hosts()
616 reset_config_on_routers(tgen
)
617 clear_pim_interface_traffic(tgen
, topo
)
619 result
= pre_config_to_bsm(
620 tgen
, topo
, tc_name
, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
622 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
624 result
= pre_config_to_bsm(
625 tgen
, topo
, tc_name
, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
627 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
629 GROUP_ADDRESS
= "225.1.1.1"
631 # Use scapy to send pre-defined packet from senser to receiver
632 step("Send BSR packet from b1 to FHR")
633 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet1")
634 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
636 bsr_ip
= topo
["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
639 result
= app_helper
.run_join("r1", GROUP_ADDRESS
, "l1")
640 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
642 # Verify bsr state in FHR
643 step("Verify if b1 is chosen as bsr in f1")
644 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip
)
645 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
648 group
= "225.1.1.0/24"
649 # Find the elected rp from bsrp-info
650 step("Find the elected rp from bsrp-info in LHR l1")
651 rp1
= find_rp_from_bsrp_info(tgen
, dut
, bsr_ip
, group
)
652 assert rp1
is not {}, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
654 # Check RP detail in LHR
655 step("Verify RP in LHR l1")
656 result
= verify_pim_grp_rp_source(tgen
, topo
, dut
, group
, "BSR", rp1
[group
])
657 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
659 # Send BSR packet from b1 after deleting high prio rp for 225.1.1.0/24
660 step("Send BSM from b1 to FHR deleting high prio rp for 225.1.1.0/24")
661 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet6")
662 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
664 # Find the elected rp from bsrp-info
665 step("Find the elected rp from bsrp-info in LHR l1")
666 rp2
= find_rp_from_bsrp_info(tgen
, dut
, bsr_ip
, group
)
667 assert rp2
is not {}, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
668 logger
.info("RP old: {} RP2 new: {} ".format(rp1
[group
], rp2
[group
]))
670 # Verify is the rp is different now
671 assert rp1
[group
] != rp2
[group
], "Testcase {} :Failed \n Error {}".format(
678 # Verify if that rp is installed
679 step("Verify new RP in LHR installed")
680 result
= verify_pim_grp_rp_source(tgen
, topo
, dut
, group
, "BSR", rp_add2
)
681 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
683 # Send BSR packet from b1 after putting back high prio rp for 225.1.1.0/24
684 step("Send BSM from b1 to FHR put back old high prio rp for 225.1.1.0/24")
685 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet1")
686 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
688 # Find the elected rp from bsrp-info
689 step("Find the elected rp from bsrp-info in LHR")
690 rp2
= find_rp_from_bsrp_info(tgen
, dut
, bsr_ip
, group
)
691 assert rp2
is not {}, "Testcase {} :Failed \n Error : RP not Found".format(tc_name
)
693 # Verify is the rp is different now
694 step("Verify now old RP is elected again")
696 rp_add1
== rp2
[group
]
697 ), "Testcase {} :Failed \n Error : rp expected {} rp received {}".format(
698 tc_name
, rp_add1
, rp2
[group
] if group
in rp2
else None
701 # Verify if that rp is installed
702 step("Verify new RP in LHR installed")
703 result
= verify_pim_grp_rp_source(tgen
, topo
, dut
, group
, "BSR", rp_add1
)
704 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
706 step("clear BSM database before moving to next case")
707 clear_bsrp_data(tgen
, topo
)
709 write_test_footer(tc_name
)
712 def test_BSR_election_p0(request
):
714 Verify group to RP mapping in FRR node when 2 BSR are present in the network
715 and both are having same BSR priority
721 s1-----f1-----i1-----l1----r1
730 i1 - Intermediate Router (also RP)
736 tc_name
= request
.node
.name
737 write_test_header(tc_name
)
739 app_helper
.stop_all_hosts()
741 reset_config_on_routers(tgen
)
742 clear_pim_interface_traffic(tgen
, topo
)
744 # Don"t run this test if we have any failure.
745 if tgen
.routers_have_failure():
746 pytest
.skip(tgen
.errors
)
748 result
= pre_config_to_bsm(
749 tgen
, topo
, tc_name
, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
751 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
753 result
= pre_config_to_bsm(
754 tgen
, topo
, tc_name
, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
756 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
758 GROUP_ADDRESS
= "225.1.1.1"
760 # Use scapy to send pre-defined packet from senser to receiver
761 step("Send BSR packet from b1 to FHR")
762 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet3")
763 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
765 bsr_ip1
= topo
["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[
770 result
= app_helper
.run_join("r1", GROUP_ADDRESS
, "l1")
771 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
773 # Verify bsr state in FHR
774 step("Verify if b1 is chosen as bsr in f1")
775 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip1
)
776 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
779 group
= "225.1.1.0/24"
780 # Find the elected rp from bsrp-info
781 step("Find the elected rp from bsrp-info in LHR in l1")
782 rp
= find_rp_from_bsrp_info(tgen
, dut
, bsr_ip1
, group
)
783 assert rp
is not {}, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
785 # Check RP detail in LHR
786 step("Verify RP in LHR l1")
787 result
= verify_pim_grp_rp_source(tgen
, topo
, dut
, group
, "BSR", rp
[group
])
788 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
790 # Send BSR packet from b2 with same priority
791 step("Send BSR packet from b2 to FHR with same priority")
792 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b2", "f1", "packet1")
793 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
795 bsr_ip2
= topo
["routers"]["b2"]["bsm"]["bsr_packets"]["packet2"]["bsr"].split("/")[
800 logger
.info("BSR b1:" + bsr_ip1
+ " BSR b2:" + bsr_ip2
)
801 # Verify bsr state in FHR
802 step("Verify if b2 is not chosen as bsr in f1")
803 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip2
, expected
=False)
806 ), "Testcase {} : Failed \n " "b2 is chosen as bsr in f1 \n Error: {}".format(
810 # Verify if b1 is still chosen as bsr
811 step("Verify if b1 is still chosen as bsr in f1")
812 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip1
)
813 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
815 # Verify if that rp is installed
816 step("Verify that same RP in istalled in LHR l1")
817 result
= verify_pim_grp_rp_source(tgen
, topo
, dut
, group
, "BSR", rp
[group
])
818 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
820 step("clear BSM database before moving to next case")
821 clear_bsrp_data(tgen
, topo
)
823 write_test_footer(tc_name
)
826 def test_RP_hash_p0(request
):
828 Verify RP is selected based on hash function, when BSR advertising the group
829 to RP mapping with same priority
835 s1-----f1-----i1-----l1----r1
844 i1 - Intermediate Router (also RP)
850 tc_name
= request
.node
.name
851 write_test_header(tc_name
)
853 # Don"t run this test if we have any failure.
854 if tgen
.routers_have_failure():
855 pytest
.skip(tgen
.errors
)
857 app_helper
.stop_all_hosts()
859 reset_config_on_routers(tgen
)
860 clear_pim_interface_traffic(tgen
, topo
)
862 result
= pre_config_to_bsm(
863 tgen
, topo
, tc_name
, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
865 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
867 result
= pre_config_to_bsm(
868 tgen
, topo
, tc_name
, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
870 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
872 GROUP_ADDRESS
= "225.1.1.1"
874 # Use scapy to send pre-defined packet from senser to receiver
875 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet7")
876 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
878 bsr_ip
= topo
["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
881 result
= app_helper
.run_join("r1", GROUP_ADDRESS
, "l1")
882 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
886 # Verify bsr state in FHR
887 step("Verify if b1 chosen as BSR in f1")
888 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip
)
889 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
891 group
= "225.1.1.0/24"
893 # Find the elected rp from bsrp-info
894 step("Find the elected rp from bsrp-info in LHR l1")
895 rp
= find_rp_from_bsrp_info(tgen
, dut
, bsr_ip
, group
)
896 assert rp
is not {}, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
898 # Verify if RP with highest hash value is chosen
899 step("Verify if RP(2.2.2.2) with highest hash value is chosen in l1")
900 if rp
[group
] == "2.2.2.2":
903 result
= "rp expected: 2.2.2.2 got:" + rp
[group
]
905 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
907 # Check RP detail in LHR
908 step("Verify RP in LHR")
909 result
= verify_pim_grp_rp_source(tgen
, topo
, dut
, group
, "BSR", rp
[group
])
910 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
912 step("clear BSM database before moving to next case")
913 clear_bsrp_data(tgen
, topo
)
915 write_test_footer(tc_name
)
918 def test_BSM_fragmentation_p1(request
):
920 Verify fragmentation of bootstrap message
926 s1-----f1-----i1-----l1----r1
935 i1 - Intermediate Router (also RP)
941 tc_name
= request
.node
.name
942 write_test_header(tc_name
)
944 # Don"t run this test if we have any failure.
945 if tgen
.routers_have_failure():
946 pytest
.skip(tgen
.errors
)
948 app_helper
.stop_all_hosts()
950 reset_config_on_routers(tgen
)
951 clear_pim_interface_traffic(tgen
, topo
)
953 result
= pre_config_to_bsm(
954 tgen
, topo
, tc_name
, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
956 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
958 result
= pre_config_to_bsm(
959 tgen
, topo
, tc_name
, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
961 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
963 GROUP_ADDRESS
= "225.1.1.1"
965 bsr_ip
= topo
["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
967 step("Send BSM and verify if all routers have same bsrp before fragment")
968 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet1")
969 # Verify bsr state in FHR
970 step("Verify if b1 chosen as BSR in f1")
971 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip
)
972 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
974 fhr_node
= tgen
.routers()["f1"]
975 inter_node
= tgen
.routers()["i1"]
976 lhr_node
= tgen
.routers()["l1"]
978 # Verify if bsrp list is same across f1, i1 and l1
979 step("Verify if bsrp list is same across f1, i1 and l1")
980 bsrp_f1
= fhr_node
.vtysh_cmd("show ip pim bsrp-info json", isjson
=True)
981 logger
.info("show_ip_pim_bsrp_info_json f1: \n %s", bsrp_f1
)
982 bsrp_i1
= inter_node
.vtysh_cmd("show ip pim bsrp-info json", isjson
=True)
983 logger
.info("show_ip_pim_bsrp_info_json i1: \n %s", bsrp_i1
)
984 bsrp_l1
= lhr_node
.vtysh_cmd("show ip pim bsrp-info json", isjson
=True)
985 logger
.info("show_ip_pim_bsrp_info_json l1: \n %s", bsrp_l1
)
987 if bsrp_f1
== bsrp_l1
:
990 result
= "bsrp info in f1 is not same in l1"
992 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
994 # set mtu of fhr(f1) to i1 interface to 100 so that bsm fragments
995 step("set mtu of fhr(f1) to i1 interface to 100 so that bsm fragments")
996 fhr_node
.run("ip link set f1-i1-eth2 mtu 100")
997 inter_node
.run("ip link set i1-f1-eth0 mtu 100")
999 # Use scapy to send pre-defined packet from senser to receiver
1000 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet2")
1001 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1003 result
= app_helper
.run_join("r1", GROUP_ADDRESS
, "l1")
1004 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
1006 # Verify bsr state in FHR
1007 step("Verify if b1 chosen as BSR")
1008 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip
)
1009 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1011 # Verify if bsrp list is same across f1, i1 and l1
1012 step("Verify if bsrp list is same across f1, i1 and l1 after fragmentation")
1013 bsrp_f1
= fhr_node
.vtysh_cmd("show ip pim bsrp-info json", isjson
=True)
1014 logger
.info("show_ip_pim_bsrp_info_json f1: \n %s", bsrp_f1
)
1015 bsrp_i1
= inter_node
.vtysh_cmd("show ip pim bsrp-info json", isjson
=True)
1016 logger
.info("show_ip_pim_bsrp_info_json i1: \n %s", bsrp_i1
)
1017 bsrp_l1
= lhr_node
.vtysh_cmd("show ip pim bsrp-info json", isjson
=True)
1018 logger
.info("show_ip_pim_bsrp_info_json l1: \n %s", bsrp_l1
)
1020 if bsrp_f1
== bsrp_l1
:
1023 result
= "bsrp info in f1 is not same in l1"
1025 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1027 step("clear BSM database before moving to next case")
1028 clear_bsrp_data(tgen
, topo
)
1030 write_test_footer(tc_name
)
1033 def test_RP_with_all_ip_octet_p1(request
):
1035 Verify when candidate RP advertised with 32 mask length
1036 and contain all the contacts
1042 s1-----f1-----i1-----l1----r1
1051 i1 - Intermediate Router (also RP)
1056 tgen
= get_topogen()
1057 tc_name
= request
.node
.name
1058 write_test_header(tc_name
)
1060 # Don"t run this test if we have any failure.
1061 if tgen
.routers_have_failure():
1062 pytest
.skip(tgen
.errors
)
1064 app_helper
.stop_all_hosts()
1066 reset_config_on_routers(tgen
)
1067 clear_pim_interface_traffic(tgen
, topo
)
1069 step("pre-configure BSM packet")
1070 result
= pre_config_to_bsm(
1071 tgen
, topo
, tc_name
, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
1073 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1075 step("Send the IGMP group (225.100.100.100) from receiver connected to FRR")
1076 GROUP_ADDRESS
= "225.200.100.100"
1078 # Use scapy to send pre-defined packet from senser to receiver
1079 step("Configure cisco-1 as BSR1")
1080 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet8")
1081 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1083 bsr_ip
= topo
["routers"]["b1"]["bsm"]["bsr_packets"]["packet8"]["bsr"].split("/")[0]
1086 result
= app_helper
.run_join("r1", GROUP_ADDRESS
, "l1")
1087 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
1091 "Groups are shown with candidate RP with correct mask length 'show ip pim bsrp-info'"
1093 step("Verify if b1 chosen as BSR in f1")
1094 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip
)
1095 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1097 group
= topo
["routers"]["b1"]["bsm"]["bsr_packets"]["packet9"]["group"]
1098 step("Find the elected rp from bsrp-info in LHR l1")
1099 rp
= find_rp_from_bsrp_info(tgen
, dut
, bsr_ip
, group
)
1100 assert rp
is not {}, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1102 step("Verify RP in LHR")
1103 result
= verify_pim_grp_rp_source(tgen
, topo
, dut
, group
, "BSR", rp
[group
])
1104 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
1106 step("clear BSM database before moving to next case")
1107 clear_bsrp_data(tgen
, topo
)
1109 write_test_footer(tc_name
)
1112 if __name__
== "__main__":
1113 args
= ["-s"] + sys
.argv
[1:]
1114 sys
.exit(pytest
.main(args
))