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 rp
: {"static_routes": [{"network": bsr_route
, "next_hop": next_hop_rp
}]},
249 lhr
: {"static_routes": [{"network": bsr_route
, "next_hop": next_hop_lhr
}]},
252 result
= create_static_routes(tgen
, input_dict
)
253 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
255 # Verifying static routes are installed
256 for dut
, _nexthop
in zip([rp
, lhr
], [next_hop_rp
, next_hop_lhr
]):
257 input_routes
= {dut
: input_dict
[dut
]}
259 tgen
, "ipv4", dut
, input_routes
, _nexthop
, protocol
="static"
261 assert result
is True, "Testcase {} : Failed \n Error {}".format(
265 # Add kernel route for source
266 group
= topo
["routers"][bsr
]["bsm"]["bsr_packets"][packet
]["pkt_dst"]
267 bsr_interface
= topo
["routers"][bsr
]["links"][fhr
]["interface"]
268 result
= addKernelRoute(tgen
, bsr
, bsr_interface
, group
)
269 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
272 rp_mapping
= topo
["routers"][bsr
]["bsm"]["bsr_packets"][packet
]["rp_mapping"]
274 # Add interfaces in RP for all the RPs
275 result
= add_rp_interfaces_and_pim_config(tgen
, topo
, "lo", rp
, rp_mapping
)
276 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
278 # Add kernel routes to sender and receiver
279 for group
, rp_list
in rp_mapping
.items():
280 mask
= group
.split("/")[1]
282 group
= group
.split("/")[0]
284 # Add kernel routes for sender
285 s_interface
= topo
["routers"][sender
]["links"][fhr
]["interface"]
286 result
= addKernelRoute(tgen
, sender
, s_interface
, group
)
287 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
289 # Add kernel routes for receiver
290 r_interface
= topo
["routers"][receiver
]["links"][lhr
]["interface"]
291 result
= addKernelRoute(tgen
, receiver
, r_interface
, group
)
292 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
294 # Add static routes for RPs in FHR and LHR
295 next_hop_fhr
= topo
["routers"][rp
]["links"][fhr
]["ipv4"].split("/")[0]
296 next_hop_lhr
= topo
["routers"][rp
]["links"][lhr
]["ipv4"].split("/")[0]
298 fhr
: {"static_routes": [{"network": rp_list
, "next_hop": next_hop_fhr
}]},
300 result
= create_static_routes(tgen
, input_dict
)
301 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
303 # Verifying static routes are installed
305 tgen
, "ipv4", fhr
, input_dict
, next_hop_fhr
, protocol
="static"
307 assert result
is True, "Testcase {} : Failed \n Error {}".format(
312 lhr
: {"static_routes": [{"network": rp_list
, "next_hop": next_hop_lhr
}]},
314 result
= create_static_routes(tgen
, input_dict
)
315 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
317 # Verifying static routes are installed
319 tgen
, "ipv4", lhr
, input_dict
, next_hop_lhr
, protocol
="static"
321 assert result
is True, "Testcase {} : Failed \n Error {}".format(
328 #####################################################
332 #####################################################
335 def test_starg_mroute_p0(request
):
337 1. Verify (*,G) mroute detail on FRR router after BSM rp installed
343 s1-----f1-----i1-----l1----r1
352 i1 - Intermediate Router (also RP)
358 tc_name
= request
.node
.name
359 write_test_header(tc_name
)
361 # Don"t run this test if we have any failure.
362 if tgen
.routers_have_failure():
363 pytest
.skip(tgen
.errors
)
365 app_helper
.stop_all_hosts()
367 reset_config_on_routers(tgen
)
368 clear_pim_interface_traffic(tgen
, topo
)
370 result
= pre_config_to_bsm(
371 tgen
, topo
, tc_name
, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
373 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
375 result
= pre_config_to_bsm(
376 tgen
, topo
, tc_name
, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
378 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
380 GROUP_ADDRESS
= "226.1.1.1"
382 # Use scapy to send pre-defined packet from senser to receiver
383 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet1")
384 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
386 bsr_ip
= topo
["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
389 result
= app_helper
.run_join("r1", GROUP_ADDRESS
, "l1")
390 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
392 # Verify bsr state in FHR
393 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip
)
394 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
397 step("Verify IGMP groups in LHR l1")
400 result
= verify_igmp_groups(tgen
, dut
, intf
, GROUP_ADDRESS
)
401 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
403 group
= "226.1.1.1/32"
406 # Find the elected rp from bsrp-info
407 step("Find the elected rp from bsrp-info in LHR in l1")
408 rp
= find_rp_from_bsrp_info(tgen
, dut
, bsr_ip
, group
)
409 assert rp
is not {}, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
411 # Check RP detail in LHR
412 step("Verify RP in LHR in l1")
413 result
= verify_pim_grp_rp_source(tgen
, topo
, dut
, group
, "BSR", rp
[group
])
414 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
416 # Verify join state and join timer
417 step("Verify join state and join timer in l1")
419 result
= verify_join_state_and_timer(tgen
, dut
, iif
, src_addr
, GROUP_ADDRESS
)
420 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
422 # Verify upstream IIF interface
423 step("Verify upstream IIF interface in l1")
424 result
= verify_upstream_iif(tgen
, dut
, iif
, src_addr
, GROUP_ADDRESS
)
425 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
427 # Verify IIF/OIL in pim state
429 result
= verify_pim_state(tgen
, dut
, iif
, oil
, GROUP_ADDRESS
)
430 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
433 step("Verify ip mroute in l1")
435 result
= verify_mroutes(tgen
, dut
, src_addr
, GROUP_ADDRESS
, iif
, oil
)
436 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
438 # Remove the group rp mapping and send bsm
439 step("Remove the grp-rp mapping by sending bsm with hold time 0 for grp-rp")
440 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet2")
441 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
443 # Check RP unreachable
444 step("Check RP unreachability in l1")
446 result
= verify_upstream_iif(
447 tgen
, dut
, iif
, src_addr
, GROUP_ADDRESS
, joinState
="NotJoined"
449 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
451 # Verify that it is not installed
452 step("Verify that iif is not installed in l1")
454 result
= verify_pim_state(tgen
, dut
, iif
, oil
, GROUP_ADDRESS
, installed_fl
=0)
455 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
457 # Verify mroute not installed
458 step("Verify mroute not installed in l1")
459 result
= verify_mroutes(
460 tgen
, dut
, src_addr
, GROUP_ADDRESS
, iif
, oil
, retry_timeout
=20, expected
=False
464 ), "Testcase {} : Failed \n " "mroute installed in l1 \n Error: {}".format(
468 # Send BSM again to configure rp
469 step("Add back RP by sending BSM from b1")
470 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet1")
471 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
473 # Verify that (*,G) installed in mroute again
475 result
= verify_mroutes(tgen
, dut
, src_addr
, GROUP_ADDRESS
, iif
, oil
)
476 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
478 step("clear BSM database before moving to next case")
479 clear_bsrp_data(tgen
, topo
)
481 write_test_footer(tc_name
)
484 def test_overlapping_group_p0(request
):
486 Verify group to RP updated correctly on FRR router, when BSR advertising
487 the overlapping group address
493 s1-----f1-----i1-----l1----r1
502 i1 - Intermediate Router (also RP)
508 tc_name
= request
.node
.name
509 write_test_header(tc_name
)
511 # Don"t run this test if we have any failure.
512 if tgen
.routers_have_failure():
513 pytest
.skip(tgen
.errors
)
515 app_helper
.stop_all_hosts()
517 reset_config_on_routers(tgen
)
518 clear_pim_interface_traffic(tgen
, topo
)
520 result
= pre_config_to_bsm(
521 tgen
, topo
, tc_name
, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
523 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
525 result
= pre_config_to_bsm(
526 tgen
, topo
, tc_name
, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
528 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
530 GROUP_ADDRESS
= "225.1.1.1"
532 # Use scapy to send pre-defined packet from senser to receiver
533 step("Send BSR packet from b1 to FHR")
534 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet4")
535 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
537 bsr_ip
= topo
["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
540 result
= app_helper
.run_join("r1", GROUP_ADDRESS
, "l1")
541 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
543 # Verify bsr state in FHR
544 step("Verify if b1 is chosen as bsr in f1")
545 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip
)
546 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
549 group1
= "225.1.1.1/32"
550 # Find the elected rp from bsrp-info fro group 225.1.1.1/32
551 step("Find the elected rp from bsrp-info in LHR for 225.1.1.1/32")
552 rp1
= find_rp_from_bsrp_info(tgen
, dut
, bsr_ip
, group1
)
553 assert rp1
is not {}, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
555 group2
= "225.1.1.0/24"
556 # Find the elected rp from bsrp-info fro group 225.1.1.0/24
557 step("Find the elected rp from bsrp-info in LHR for 225.1.1.0/24")
558 rp2
= find_rp_from_bsrp_info(tgen
, dut
, bsr_ip
, group2
)
559 assert rp2
is not {}, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
562 # Verify upstream rpf for 225.1.1.1 is chosen as rp1
563 step("Verify upstream rpf for 225.1.1.1 is chosen as rp1 in l1")
564 result
= verify_pim_upstream_rpf(tgen
, topo
, dut
, iif
, GROUP_ADDRESS
, rp1
)
565 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
567 # Send BSR packet from b1 with rp for 225.1.1.1/32 removed
568 step("Send BSR packet from b1 with rp for 225.1.1.1/32 removed")
569 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet5")
570 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
572 # Verify upstream rpf for 225.1.1.1 is chosen as rp1
573 step("Verify upstream rpf for 225.1.1.1 is chosen as rp2 in l1")
574 result
= verify_pim_upstream_rpf(tgen
, topo
, dut
, iif
, GROUP_ADDRESS
, rp2
)
575 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
577 # Verify IIF/OIL in pim state
578 step("Verify iif is installed after rp change in l1")
580 result
= verify_pim_state(tgen
, dut
, iif
, oil
, GROUP_ADDRESS
)
581 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
583 step("clear BSM database before moving to next case")
584 clear_bsrp_data(tgen
, topo
)
586 write_test_footer(tc_name
)
589 def test_RP_priority_p0(request
):
591 Verify group to RP info is updated correctly, when BSR advertising the
592 same RP with different priority
598 s1-----f1-----i1-----l1----r1
607 i1 - Intermediate Router (also RP)
612 tc_name
= request
.node
.name
613 write_test_header(tc_name
)
615 # Don"t run this test if we have any failure.
616 if tgen
.routers_have_failure():
617 pytest
.skip(tgen
.errors
)
619 app_helper
.stop_all_hosts()
621 reset_config_on_routers(tgen
)
622 clear_pim_interface_traffic(tgen
, topo
)
624 result
= pre_config_to_bsm(
625 tgen
, topo
, tc_name
, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
627 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
629 result
= pre_config_to_bsm(
630 tgen
, topo
, tc_name
, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
632 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
634 GROUP_ADDRESS
= "225.1.1.1"
636 # Use scapy to send pre-defined packet from senser to receiver
637 step("Send BSR packet from b1 to FHR")
638 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet1")
639 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
641 bsr_ip
= topo
["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
644 result
= app_helper
.run_join("r1", GROUP_ADDRESS
, "l1")
645 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
647 # Verify bsr state in FHR
648 step("Verify if b1 is chosen as bsr in f1")
649 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip
)
650 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
653 group
= "225.1.1.0/24"
654 # Find the elected rp from bsrp-info
655 step("Find the elected rp from bsrp-info in LHR l1")
656 rp1
= find_rp_from_bsrp_info(tgen
, dut
, bsr_ip
, group
)
657 assert rp1
is not {}, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
659 # Check RP detail in LHR
660 step("Verify RP in LHR l1")
661 result
= verify_pim_grp_rp_source(tgen
, topo
, dut
, group
, "BSR", rp1
[group
])
662 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
664 # Send BSR packet from b1 after deleting high prio rp for 225.1.1.0/24
665 step("Send BSM from b1 to FHR deleting high prio rp for 225.1.1.0/24")
666 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet6")
667 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
669 # Find the elected rp from bsrp-info
670 step("Find the elected rp from bsrp-info in LHR l1")
671 rp2
= find_rp_from_bsrp_info(tgen
, dut
, bsr_ip
, group
)
672 assert rp2
is not {}, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
673 logger
.info("RP old: {} RP2 new: {} ".format(rp1
[group
], rp2
[group
]))
675 # Verify is the rp is different now
676 assert rp1
[group
] != rp2
[group
], "Testcase {} :Failed \n Error {}".format(
683 # Verify if that rp is installed
684 step("Verify new RP in LHR installed")
685 result
= verify_pim_grp_rp_source(tgen
, topo
, dut
, group
, "BSR", rp_add2
)
686 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
688 # Send BSR packet from b1 after putting back high prio rp for 225.1.1.0/24
689 step("Send BSM from b1 to FHR put back old high prio rp for 225.1.1.0/24")
690 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet1")
691 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
693 # Find the elected rp from bsrp-info
694 step("Find the elected rp from bsrp-info in LHR")
695 rp2
= find_rp_from_bsrp_info(tgen
, dut
, bsr_ip
, group
)
696 assert rp2
is not {}, "Testcase {} :Failed \n Error : RP not Found".format(tc_name
)
698 # Verify is the rp is different now
699 step("Verify now old RP is elected again")
701 rp_add1
== rp2
[group
]
702 ), "Testcase {} :Failed \n Error : rp expected {} rp received {}".format(
703 tc_name
, rp_add1
, rp2
[group
] if group
in rp2
else None
706 # Verify if that rp is installed
707 step("Verify new RP in LHR installed")
708 result
= verify_pim_grp_rp_source(tgen
, topo
, dut
, group
, "BSR", rp_add1
)
709 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
711 step("clear BSM database before moving to next case")
712 clear_bsrp_data(tgen
, topo
)
714 write_test_footer(tc_name
)
717 def test_BSR_election_p0(request
):
719 Verify group to RP mapping in FRR node when 2 BSR are present in the network
720 and both are having same BSR priority
726 s1-----f1-----i1-----l1----r1
735 i1 - Intermediate Router (also RP)
741 tc_name
= request
.node
.name
742 write_test_header(tc_name
)
744 app_helper
.stop_all_hosts()
746 reset_config_on_routers(tgen
)
747 clear_pim_interface_traffic(tgen
, topo
)
749 # Don"t run this test if we have any failure.
750 if tgen
.routers_have_failure():
751 pytest
.skip(tgen
.errors
)
753 result
= pre_config_to_bsm(
754 tgen
, topo
, tc_name
, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
756 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
758 result
= pre_config_to_bsm(
759 tgen
, topo
, tc_name
, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
761 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
763 GROUP_ADDRESS
= "225.1.1.1"
765 # Use scapy to send pre-defined packet from senser to receiver
766 step("Send BSR packet from b1 to FHR")
767 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet3")
768 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
770 bsr_ip1
= topo
["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[
775 result
= app_helper
.run_join("r1", GROUP_ADDRESS
, "l1")
776 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
778 # Verify bsr state in FHR
779 step("Verify if b1 is chosen as bsr in f1")
780 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip1
)
781 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
784 group
= "225.1.1.0/24"
785 # Find the elected rp from bsrp-info
786 step("Find the elected rp from bsrp-info in LHR in l1")
787 rp
= find_rp_from_bsrp_info(tgen
, dut
, bsr_ip1
, group
)
788 assert rp
is not {}, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
790 # Check RP detail in LHR
791 step("Verify RP in LHR l1")
792 result
= verify_pim_grp_rp_source(tgen
, topo
, dut
, group
, "BSR", rp
[group
])
793 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
795 # Send BSR packet from b2 with same priority
796 step("Send BSR packet from b2 to FHR with same priority")
797 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b2", "f1", "packet1")
798 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
800 bsr_ip2
= topo
["routers"]["b2"]["bsm"]["bsr_packets"]["packet2"]["bsr"].split("/")[
805 logger
.info("BSR b1:" + bsr_ip1
+ " BSR b2:" + bsr_ip2
)
806 # Verify bsr state in FHR
807 step("Verify if b2 is not chosen as bsr in f1")
808 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip2
, expected
=False)
811 ), "Testcase {} : Failed \n " "b2 is chosen as bsr in f1 \n Error: {}".format(
815 # Verify if b1 is still chosen as bsr
816 step("Verify if b1 is still chosen as bsr in f1")
817 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip1
)
818 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
820 # Verify if that rp is installed
821 step("Verify that same RP in istalled in LHR l1")
822 result
= verify_pim_grp_rp_source(tgen
, topo
, dut
, group
, "BSR", rp
[group
])
823 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
825 step("clear BSM database before moving to next case")
826 clear_bsrp_data(tgen
, topo
)
828 write_test_footer(tc_name
)
831 def test_RP_hash_p0(request
):
833 Verify RP is selected based on hash function, when BSR advertising the group
834 to RP mapping with same priority
840 s1-----f1-----i1-----l1----r1
849 i1 - Intermediate Router (also RP)
855 tc_name
= request
.node
.name
856 write_test_header(tc_name
)
858 # Don"t run this test if we have any failure.
859 if tgen
.routers_have_failure():
860 pytest
.skip(tgen
.errors
)
862 app_helper
.stop_all_hosts()
864 reset_config_on_routers(tgen
)
865 clear_pim_interface_traffic(tgen
, topo
)
867 result
= pre_config_to_bsm(
868 tgen
, topo
, tc_name
, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
870 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
872 result
= pre_config_to_bsm(
873 tgen
, topo
, tc_name
, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
875 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
877 GROUP_ADDRESS
= "225.1.1.1"
879 # Use scapy to send pre-defined packet from senser to receiver
880 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet7")
881 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
883 bsr_ip
= topo
["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
886 result
= app_helper
.run_join("r1", GROUP_ADDRESS
, "l1")
887 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
891 # Verify bsr state in FHR
892 step("Verify if b1 chosen as BSR in f1")
893 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip
)
894 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
896 group
= "225.1.1.0/24"
898 # Find the elected rp from bsrp-info
899 step("Find the elected rp from bsrp-info in LHR l1")
900 rp
= find_rp_from_bsrp_info(tgen
, dut
, bsr_ip
, group
)
901 assert rp
is not {}, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
903 # Verify if RP with highest hash value is chosen
904 step("Verify if RP(2.2.2.2) with highest hash value is chosen in l1")
905 if rp
[group
] == "2.2.2.2":
908 result
= "rp expected: 2.2.2.2 got:" + rp
[group
]
910 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
912 # Check RP detail in LHR
913 step("Verify RP in LHR")
914 result
= verify_pim_grp_rp_source(tgen
, topo
, dut
, group
, "BSR", rp
[group
])
915 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
917 step("clear BSM database before moving to next case")
918 clear_bsrp_data(tgen
, topo
)
920 write_test_footer(tc_name
)
923 def test_BSM_fragmentation_p1(request
):
925 Verify fragmentation of bootstrap message
931 s1-----f1-----i1-----l1----r1
940 i1 - Intermediate Router (also RP)
946 tc_name
= request
.node
.name
947 write_test_header(tc_name
)
949 # Don"t run this test if we have any failure.
950 if tgen
.routers_have_failure():
951 pytest
.skip(tgen
.errors
)
953 app_helper
.stop_all_hosts()
955 reset_config_on_routers(tgen
)
956 clear_pim_interface_traffic(tgen
, topo
)
958 result
= pre_config_to_bsm(
959 tgen
, topo
, tc_name
, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
961 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
963 result
= pre_config_to_bsm(
964 tgen
, topo
, tc_name
, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
966 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
968 GROUP_ADDRESS
= "225.1.1.1"
970 bsr_ip
= topo
["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
972 step("Send BSM and verify if all routers have same bsrp before fragment")
973 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet1")
974 # Verify bsr state in FHR
975 step("Verify if b1 chosen as BSR in f1")
976 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip
)
977 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
979 fhr_node
= tgen
.routers()["f1"]
980 inter_node
= tgen
.routers()["i1"]
981 lhr_node
= tgen
.routers()["l1"]
983 # Verify if bsrp list is same across f1, i1 and l1
984 step("Verify if bsrp list is same across f1, i1 and l1")
985 bsrp_f1
= fhr_node
.vtysh_cmd("show ip pim bsrp-info json", isjson
=True)
986 logger
.info("show_ip_pim_bsrp_info_json f1: \n %s", bsrp_f1
)
987 bsrp_i1
= inter_node
.vtysh_cmd("show ip pim bsrp-info json", isjson
=True)
988 logger
.info("show_ip_pim_bsrp_info_json i1: \n %s", bsrp_i1
)
989 bsrp_l1
= lhr_node
.vtysh_cmd("show ip pim bsrp-info json", isjson
=True)
990 logger
.info("show_ip_pim_bsrp_info_json l1: \n %s", bsrp_l1
)
992 if bsrp_f1
== bsrp_l1
:
995 result
= "bsrp info in f1 is not same in l1"
997 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
999 # set mtu of fhr(f1) to i1 interface to 100 so that bsm fragments
1000 step("set mtu of fhr(f1) to i1 interface to 100 so that bsm fragments")
1001 fhr_node
.run("ip link set f1-i1-eth2 mtu 100")
1002 inter_node
.run("ip link set i1-f1-eth0 mtu 100")
1004 # Use scapy to send pre-defined packet from senser to receiver
1005 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet2")
1006 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1008 result
= app_helper
.run_join("r1", GROUP_ADDRESS
, "l1")
1009 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
1011 # Verify bsr state in FHR
1012 step("Verify if b1 chosen as BSR")
1013 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip
)
1014 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1016 # Verify if bsrp list is same across f1, i1 and l1
1017 step("Verify if bsrp list is same across f1, i1 and l1 after fragmentation")
1018 bsrp_f1
= fhr_node
.vtysh_cmd("show ip pim bsrp-info json", isjson
=True)
1019 logger
.info("show_ip_pim_bsrp_info_json f1: \n %s", bsrp_f1
)
1020 bsrp_i1
= inter_node
.vtysh_cmd("show ip pim bsrp-info json", isjson
=True)
1021 logger
.info("show_ip_pim_bsrp_info_json i1: \n %s", bsrp_i1
)
1022 bsrp_l1
= lhr_node
.vtysh_cmd("show ip pim bsrp-info json", isjson
=True)
1023 logger
.info("show_ip_pim_bsrp_info_json l1: \n %s", bsrp_l1
)
1025 if bsrp_f1
== bsrp_l1
:
1028 result
= "bsrp info in f1 is not same in l1"
1030 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1032 step("clear BSM database before moving to next case")
1033 clear_bsrp_data(tgen
, topo
)
1035 write_test_footer(tc_name
)
1038 def test_RP_with_all_ip_octet_p1(request
):
1040 Verify when candidate RP advertised with 32 mask length
1041 and contain all the contacts
1047 s1-----f1-----i1-----l1----r1
1056 i1 - Intermediate Router (also RP)
1061 tgen
= get_topogen()
1062 tc_name
= request
.node
.name
1063 write_test_header(tc_name
)
1065 # Don"t run this test if we have any failure.
1066 if tgen
.routers_have_failure():
1067 pytest
.skip(tgen
.errors
)
1069 app_helper
.stop_all_hosts()
1071 reset_config_on_routers(tgen
)
1072 clear_pim_interface_traffic(tgen
, topo
)
1074 step("pre-configure BSM packet")
1075 result
= pre_config_to_bsm(
1076 tgen
, topo
, tc_name
, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
1078 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1080 step("Send the IGMP group (225.100.100.100) from receiver connected to FRR")
1081 GROUP_ADDRESS
= "225.200.100.100"
1083 # Use scapy to send pre-defined packet from senser to receiver
1084 step("Configure cisco-1 as BSR1")
1085 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet8")
1086 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1088 bsr_ip
= topo
["routers"]["b1"]["bsm"]["bsr_packets"]["packet8"]["bsr"].split("/")[0]
1091 result
= app_helper
.run_join("r1", GROUP_ADDRESS
, "l1")
1092 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
1096 "Groups are shown with candidate RP with correct mask length 'show ip pim bsrp-info'"
1098 step("Verify if b1 chosen as BSR in f1")
1099 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip
)
1100 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1102 group
= topo
["routers"]["b1"]["bsm"]["bsr_packets"]["packet9"]["group"]
1103 step("Find the elected rp from bsrp-info in LHR l1")
1104 rp
= find_rp_from_bsrp_info(tgen
, dut
, bsr_ip
, group
)
1105 assert rp
is not {}, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1107 step("Verify RP in LHR")
1108 result
= verify_pim_grp_rp_source(tgen
, topo
, dut
, group
, "BSR", rp
[group
])
1109 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
1111 step("clear BSM database before moving to next case")
1112 clear_bsrp_data(tgen
, topo
)
1114 write_test_footer(tc_name
)
1117 if __name__
== "__main__":
1118 args
= ["-s"] + sys
.argv
[1:]
1119 sys
.exit(pytest
.main(args
))