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
,
74 add_rp_interfaces_and_pim_config
,
76 scapy_send_bsr_raw_packet
,
77 find_rp_from_bsrp_info
,
78 verify_pim_grp_rp_source
,
81 verify_join_state_and_timer
,
85 verify_pim_upstream_rpf
,
87 clear_pim_interface_traffic
,
91 from lib
.topolog
import logger
92 from lib
.topojson
import build_config_from_json
94 pytestmark
= [pytest
.mark
.pimd
, pytest
.mark
.staticd
]
102 s1-----f1-----i1-----l1----r1
111 i1 - Intermediate Router (also RP)
116 NEXT_HOP1
= "70.0.0.1"
117 NEXT_HOP2
= "65.0.0.1"
119 BSR_IP_2
= "10.2.1.1"
120 BSR1_ADDR
= "1.1.2.7/32"
121 BSR2_ADDR
= "10.2.1.1/32"
124 def setup_module(mod
):
126 Sets up the pytest environment
131 # Required linux kernel version for this suite to run.
132 result
= required_linux_kernel_version("4.15")
133 if result
is not True:
134 pytest
.skip("Kernel version should be >= 4.15")
136 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
137 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
138 logger
.info("=" * 40)
139 logger
.info("Master Topology: \n {}".format(TOPOLOGY
))
141 logger
.info("Running setup_module to create topology")
143 # This function initiates the topology build with Topogen...
144 json_file
= "{}/mcast_pim_bsmp_02.json".format(CWD
)
145 tgen
= Topogen(json_file
, mod
.__name
__)
147 topo
= tgen
.json_topo
148 # ... and here it calls Mininet initialization functions.
150 # Starting topology, create tmp files which are loaded to routers
151 # to start daemons and then start routers
154 # Don"t run this test if we have any failure.
155 if tgen
.routers_have_failure():
156 pytest
.skip(tgen
.errors
)
158 # Creating configuration from JSON
159 build_config_from_json(tgen
, topo
)
161 # Verify PIM neighbors
162 result
= verify_pim_neighbors(tgen
, topo
)
163 assert result
is True, " Verify PIM neighbor: Failed Error: {}".format(result
)
165 # XXX Replace this using "with McastTesterHelper()... " in each test if possible.
167 app_helper
= McastTesterHelper(tgen
)
169 logger
.info("Running setup_module() done")
172 def teardown_module():
173 """Teardown the pytest environment"""
175 logger
.info("Running teardown_module to delete topology")
181 # Stop toplogy and Remove tmp files
185 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
187 logger
.info("=" * 40)
190 #####################################################
194 #####################################################
197 def clear_bsrp_data(tgen
, topo
):
200 clear bsm databas after test"
203 * `tgen`: topogen object
207 result = clear_bsrp_data(tgen, topo)
210 errormsg(str) or True
213 for dut
in tgen
.routers():
215 rnode
= tgen
.routers()[dut
]
217 logger
.info("[DUT: %s]: clear_bsrp_data")
219 run_frr_cmd(rnode
, "clear ip pim bsr-data")
224 def pre_config_to_bsm(tgen
, topo
, tc_name
, bsr
, sender
, receiver
, fhr
, rp
, lhr
, packet
):
226 API to do required configuration to send and receive BSR packet
229 # Re-configure interfaces as per BSR packet
230 result
= reconfig_interfaces(tgen
, topo
, bsr
, fhr
, packet
)
231 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
233 # Create static routes
234 if "bsr" in topo
["routers"][bsr
]["bsm"]["bsr_packets"][packet
]:
235 bsr_route
= topo
["routers"][bsr
]["bsm"]["bsr_packets"][packet
]["bsr"]
236 next_hop
= topo
["routers"][bsr
]["bsm"]["bsr_packets"][packet
]["src_ip"].split(
239 next_hop_rp
= topo
["routers"][fhr
]["links"][rp
]["ipv4"].split("/")[0]
240 next_hop_lhr
= topo
["routers"][rp
]["links"][lhr
]["ipv4"].split("/")[0]
244 rp
: {"static_routes": [{"network": bsr_route
, "next_hop": next_hop_rp
}]},
245 lhr
: {"static_routes": [{"network": bsr_route
, "next_hop": next_hop_lhr
}]},
248 result
= create_static_routes(tgen
, input_dict
)
249 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
251 # Verifying static routes are installed
252 for dut
, _nexthop
in zip([rp
, lhr
], [next_hop_rp
, next_hop_lhr
]):
253 input_routes
= {dut
: input_dict
[dut
]}
255 tgen
, "ipv4", dut
, input_routes
, _nexthop
, protocol
="static"
257 assert result
is True, "Testcase {} : Failed \n Error {}".format(
261 # Add kernel route for source
262 group
= topo
["routers"][bsr
]["bsm"]["bsr_packets"][packet
]["pkt_dst"]
263 bsr_interface
= topo
["routers"][bsr
]["links"][fhr
]["interface"]
264 result
= addKernelRoute(tgen
, bsr
, bsr_interface
, group
)
265 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
268 rp_mapping
= topo
["routers"][bsr
]["bsm"]["bsr_packets"][packet
]["rp_mapping"]
270 # Add interfaces in RP for all the RPs
271 result
= add_rp_interfaces_and_pim_config(tgen
, topo
, "lo", rp
, rp_mapping
)
272 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
274 # Add kernel routes to sender and receiver
275 for group
, rp_list
in rp_mapping
.items():
276 mask
= group
.split("/")[1]
278 group
= group
.split("/")[0]
280 # Add kernel routes for sender
281 s_interface
= topo
["routers"][sender
]["links"][fhr
]["interface"]
282 result
= addKernelRoute(tgen
, sender
, s_interface
, group
)
283 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
285 # Add kernel routes for receiver
286 r_interface
= topo
["routers"][receiver
]["links"][lhr
]["interface"]
287 result
= addKernelRoute(tgen
, receiver
, r_interface
, group
)
288 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
290 # Add static routes for RPs in FHR and LHR
291 next_hop_fhr
= topo
["routers"][rp
]["links"][fhr
]["ipv4"].split("/")[0]
292 next_hop_lhr
= topo
["routers"][rp
]["links"][lhr
]["ipv4"].split("/")[0]
294 fhr
: {"static_routes": [{"network": rp_list
, "next_hop": next_hop_fhr
}]},
296 result
= create_static_routes(tgen
, input_dict
)
297 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
299 # Verifying static routes are installed
301 tgen
, "ipv4", fhr
, input_dict
, next_hop_fhr
, protocol
="static"
303 assert result
is True, "Testcase {} : Failed \n Error {}".format(
308 lhr
: {"static_routes": [{"network": rp_list
, "next_hop": next_hop_lhr
}]},
310 result
= create_static_routes(tgen
, input_dict
)
311 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
313 # Verifying static routes are installed
315 tgen
, "ipv4", lhr
, input_dict
, next_hop_lhr
, protocol
="static"
317 assert result
is True, "Testcase {} : Failed \n Error {}".format(
324 #####################################################
328 #####################################################
331 def test_starg_mroute_p0(request
):
333 1. Verify (*,G) mroute detail on FRR router after BSM rp installed
339 s1-----f1-----i1-----l1----r1
348 i1 - Intermediate Router (also RP)
354 tc_name
= request
.node
.name
355 write_test_header(tc_name
)
357 # Don"t run this test if we have any failure.
358 if tgen
.routers_have_failure():
359 pytest
.skip(tgen
.errors
)
361 app_helper
.stop_all_hosts()
363 reset_config_on_routers(tgen
)
364 clear_pim_interface_traffic(tgen
, topo
)
366 result
= pre_config_to_bsm(
367 tgen
, topo
, tc_name
, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
369 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
371 result
= pre_config_to_bsm(
372 tgen
, topo
, tc_name
, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
374 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
376 GROUP_ADDRESS
= "226.1.1.1"
378 # Use scapy to send pre-defined packet from senser to receiver
379 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet1")
380 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
382 bsr_ip
= topo
["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
385 result
= app_helper
.run_join("r1", GROUP_ADDRESS
, "l1")
386 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
388 # Verify bsr state in FHR
389 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip
)
390 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
393 step("Verify IGMP groups in LHR l1")
396 result
= verify_igmp_groups(tgen
, dut
, intf
, GROUP_ADDRESS
)
397 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
399 group
= "226.1.1.1/32"
402 # Find the elected rp from bsrp-info
403 step("Find the elected rp from bsrp-info in LHR in l1")
404 rp
= find_rp_from_bsrp_info(tgen
, dut
, bsr_ip
, group
)
405 assert rp
is not {}, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
407 # Check RP detail in LHR
408 step("Verify RP in LHR in l1")
409 result
= verify_pim_grp_rp_source(tgen
, topo
, dut
, group
, "BSR", rp
[group
])
410 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
412 # Verify join state and join timer
413 step("Verify join state and join timer in l1")
415 result
= verify_join_state_and_timer(tgen
, dut
, iif
, src_addr
, GROUP_ADDRESS
)
416 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
418 # Verify upstream IIF interface
419 step("Verify upstream IIF interface in l1")
420 result
= verify_upstream_iif(tgen
, dut
, iif
, src_addr
, GROUP_ADDRESS
)
421 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
423 # Verify IIF/OIL in pim state
425 result
= verify_pim_state(tgen
, dut
, iif
, oil
, GROUP_ADDRESS
)
426 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
429 step("Verify ip mroute in l1")
431 result
= verify_mroutes(tgen
, dut
, src_addr
, GROUP_ADDRESS
, iif
, oil
)
432 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
434 # Remove the group rp mapping and send bsm
435 step("Remove the grp-rp mapping by sending bsm with hold time 0 for grp-rp")
436 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet2")
437 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
439 # Check RP unreachable
440 step("Check RP unreachability in l1")
442 result
= verify_upstream_iif(
443 tgen
, dut
, iif
, src_addr
, GROUP_ADDRESS
, joinState
="NotJoined"
445 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
447 # Verify that it is not installed
448 step("Verify that iif is not installed in l1")
450 result
= verify_pim_state(tgen
, dut
, iif
, oil
, GROUP_ADDRESS
, installed_fl
=0)
451 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
453 # Verify mroute not installed
454 step("Verify mroute not installed in l1")
455 result
= verify_mroutes(
456 tgen
, dut
, src_addr
, GROUP_ADDRESS
, iif
, oil
, retry_timeout
=20, expected
=False
458 assert result
is not True, (
459 "Testcase {} : Failed \n "
460 "Expected: [{}]: mroute (S, G) should not be installed \n "
461 "Found: {}".format(tc_name
, dut
, result
)
464 # Send BSM again to configure rp
465 step("Add back RP by sending BSM from b1")
466 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet1")
467 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
469 # Verify that (*,G) installed in mroute again
471 result
= verify_mroutes(tgen
, dut
, src_addr
, GROUP_ADDRESS
, iif
, oil
)
472 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
474 step("clear BSM database before moving to next case")
475 clear_bsrp_data(tgen
, topo
)
477 write_test_footer(tc_name
)
480 def test_overlapping_group_p0(request
):
482 Verify group to RP updated correctly on FRR router, when BSR advertising
483 the overlapping group address
489 s1-----f1-----i1-----l1----r1
498 i1 - Intermediate Router (also RP)
504 tc_name
= request
.node
.name
505 write_test_header(tc_name
)
507 # Don"t run this test if we have any failure.
508 if tgen
.routers_have_failure():
509 pytest
.skip(tgen
.errors
)
511 app_helper
.stop_all_hosts()
513 reset_config_on_routers(tgen
)
514 clear_pim_interface_traffic(tgen
, topo
)
516 result
= pre_config_to_bsm(
517 tgen
, topo
, tc_name
, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
519 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
521 result
= pre_config_to_bsm(
522 tgen
, topo
, tc_name
, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
524 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
526 GROUP_ADDRESS
= "225.1.1.1"
528 # Use scapy to send pre-defined packet from senser to receiver
529 step("Send BSR packet from b1 to FHR")
530 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet4")
531 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
533 bsr_ip
= topo
["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
536 result
= app_helper
.run_join("r1", GROUP_ADDRESS
, "l1")
537 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
539 # Verify bsr state in FHR
540 step("Verify if b1 is chosen as bsr in f1")
541 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip
)
542 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
545 group1
= "225.1.1.1/32"
546 # Find the elected rp from bsrp-info fro group 225.1.1.1/32
547 step("Find the elected rp from bsrp-info in LHR for 225.1.1.1/32")
548 rp1
= find_rp_from_bsrp_info(tgen
, dut
, bsr_ip
, group1
)
549 assert rp1
is not {}, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
551 group2
= "225.1.1.0/24"
552 # Find the elected rp from bsrp-info fro group 225.1.1.0/24
553 step("Find the elected rp from bsrp-info in LHR for 225.1.1.0/24")
554 rp2
= find_rp_from_bsrp_info(tgen
, dut
, bsr_ip
, group2
)
555 assert rp2
is not {}, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
558 # Verify upstream rpf for 225.1.1.1 is chosen as rp1
559 step("Verify upstream rpf for 225.1.1.1 is chosen as rp1 in l1")
560 result
= verify_pim_upstream_rpf(tgen
, topo
, dut
, iif
, GROUP_ADDRESS
, rp1
)
561 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
563 # Send BSR packet from b1 with rp for 225.1.1.1/32 removed
564 step("Send BSR packet from b1 with rp for 225.1.1.1/32 removed")
565 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet5")
566 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
568 # Verify upstream rpf for 225.1.1.1 is chosen as rp1
569 step("Verify upstream rpf for 225.1.1.1 is chosen as rp2 in l1")
570 result
= verify_pim_upstream_rpf(tgen
, topo
, dut
, iif
, GROUP_ADDRESS
, rp2
)
571 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
573 # Verify IIF/OIL in pim state
574 step("Verify iif is installed after rp change in l1")
576 result
= verify_pim_state(tgen
, dut
, iif
, oil
, GROUP_ADDRESS
)
577 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
579 step("clear BSM database before moving to next case")
580 clear_bsrp_data(tgen
, topo
)
582 write_test_footer(tc_name
)
585 def test_RP_priority_p0(request
):
587 Verify group to RP info is updated correctly, when BSR advertising the
588 same RP with different priority
594 s1-----f1-----i1-----l1----r1
603 i1 - Intermediate Router (also RP)
608 tc_name
= request
.node
.name
609 write_test_header(tc_name
)
611 # Don"t run this test if we have any failure.
612 if tgen
.routers_have_failure():
613 pytest
.skip(tgen
.errors
)
615 app_helper
.stop_all_hosts()
617 reset_config_on_routers(tgen
)
618 clear_pim_interface_traffic(tgen
, topo
)
620 result
= pre_config_to_bsm(
621 tgen
, topo
, tc_name
, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
623 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
625 result
= pre_config_to_bsm(
626 tgen
, topo
, tc_name
, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
628 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
630 GROUP_ADDRESS
= "225.1.1.1"
632 # Use scapy to send pre-defined packet from senser to receiver
633 step("Send BSR packet from b1 to FHR")
634 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet1")
635 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
637 bsr_ip
= topo
["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
640 result
= app_helper
.run_join("r1", GROUP_ADDRESS
, "l1")
641 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
643 # Verify bsr state in FHR
644 step("Verify if b1 is chosen as bsr in f1")
645 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip
)
646 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
649 group
= "225.1.1.0/24"
650 # Find the elected rp from bsrp-info
651 step("Find the elected rp from bsrp-info in LHR l1")
652 rp1
= find_rp_from_bsrp_info(tgen
, dut
, bsr_ip
, group
)
653 assert rp1
is not {}, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
655 # Check RP detail in LHR
656 step("Verify RP in LHR l1")
657 result
= verify_pim_grp_rp_source(tgen
, topo
, dut
, group
, "BSR", rp1
[group
])
658 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
660 # Send BSR packet from b1 after deleting high prio rp for 225.1.1.0/24
661 step("Send BSM from b1 to FHR deleting high prio rp for 225.1.1.0/24")
662 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet6")
663 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
665 # Find the elected rp from bsrp-info
666 step("Find the elected rp from bsrp-info in LHR l1")
667 rp2
= find_rp_from_bsrp_info(tgen
, dut
, bsr_ip
, group
)
668 assert rp2
is not {}, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
669 logger
.info("RP old: {} RP2 new: {} ".format(rp1
[group
], rp2
[group
]))
671 # Verify is the rp is different now
672 assert rp1
[group
] != rp2
[group
], "Testcase {} :Failed \n Error {}".format(
679 # Verify if that rp is installed
680 step("Verify new RP in LHR installed")
681 result
= verify_pim_grp_rp_source(tgen
, topo
, dut
, group
, "BSR", rp_add2
)
682 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
684 # Send BSR packet from b1 after putting back high prio rp for 225.1.1.0/24
685 step("Send BSM from b1 to FHR put back old high prio rp for 225.1.1.0/24")
686 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet1")
687 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
689 # Find the elected rp from bsrp-info
690 step("Find the elected rp from bsrp-info in LHR")
691 rp2
= find_rp_from_bsrp_info(tgen
, dut
, bsr_ip
, group
)
692 assert rp2
is not {}, "Testcase {} :Failed \n Error : RP not Found".format(tc_name
)
694 # Verify is the rp is different now
695 step("Verify now old RP is elected again")
697 rp_add1
== rp2
[group
]
698 ), "Testcase {} :Failed \n Error : rp expected {} rp received {}".format(
699 tc_name
, rp_add1
, rp2
[group
] if group
in rp2
else None
702 # Verify if that rp is installed
703 step("Verify new RP in LHR installed")
704 result
= verify_pim_grp_rp_source(tgen
, topo
, dut
, group
, "BSR", rp_add1
)
705 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
707 step("clear BSM database before moving to next case")
708 clear_bsrp_data(tgen
, topo
)
710 write_test_footer(tc_name
)
713 def test_BSR_election_p0(request
):
715 Verify group to RP mapping in FRR node when 2 BSR are present in the network
716 and both are having same BSR priority
722 s1-----f1-----i1-----l1----r1
731 i1 - Intermediate Router (also RP)
737 tc_name
= request
.node
.name
738 write_test_header(tc_name
)
740 app_helper
.stop_all_hosts()
742 reset_config_on_routers(tgen
)
743 clear_pim_interface_traffic(tgen
, topo
)
745 # Don"t run this test if we have any failure.
746 if tgen
.routers_have_failure():
747 pytest
.skip(tgen
.errors
)
749 result
= pre_config_to_bsm(
750 tgen
, topo
, tc_name
, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
752 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
754 result
= pre_config_to_bsm(
755 tgen
, topo
, tc_name
, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
757 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
759 GROUP_ADDRESS
= "225.1.1.1"
761 # Use scapy to send pre-defined packet from senser to receiver
762 step("Send BSR packet from b1 to FHR")
763 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet3")
764 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
766 bsr_ip1
= topo
["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[
771 result
= app_helper
.run_join("r1", GROUP_ADDRESS
, "l1")
772 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
774 # Verify bsr state in FHR
775 step("Verify if b1 is chosen as bsr in f1")
776 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip1
)
777 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
780 group
= "225.1.1.0/24"
781 # Find the elected rp from bsrp-info
782 step("Find the elected rp from bsrp-info in LHR in l1")
783 rp
= find_rp_from_bsrp_info(tgen
, dut
, bsr_ip1
, group
)
784 assert rp
is not {}, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
786 # Check RP detail in LHR
787 step("Verify RP in LHR l1")
788 result
= verify_pim_grp_rp_source(tgen
, topo
, dut
, group
, "BSR", rp
[group
])
789 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
791 # Send BSR packet from b2 with same priority
792 step("Send BSR packet from b2 to FHR with same priority")
793 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b2", "f1", "packet1")
794 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
796 bsr_ip2
= topo
["routers"]["b2"]["bsm"]["bsr_packets"]["packet2"]["bsr"].split("/")[
801 logger
.info("BSR b1:" + bsr_ip1
+ " BSR b2:" + bsr_ip2
)
802 # Verify bsr state in FHR
803 step("Verify if b2 is not chosen as bsr in f1")
804 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip2
, expected
=False)
805 assert result
is not True, (
806 "Testcase {} : Failed \n "
807 "Expected: [{}]: b2 should not be chosen as bsr \n "
808 "Found: {}".format(tc_name
, "f1", result
)
811 # Verify if b1 is still chosen as bsr
812 step("Verify if b1 is still chosen as bsr in f1")
813 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip1
)
814 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
816 # Verify if that rp is installed
817 step("Verify that same RP in istalled in LHR l1")
818 result
= verify_pim_grp_rp_source(tgen
, topo
, dut
, group
, "BSR", rp
[group
])
819 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
821 step("clear BSM database before moving to next case")
822 clear_bsrp_data(tgen
, topo
)
824 write_test_footer(tc_name
)
827 def test_RP_hash_p0(request
):
829 Verify RP is selected based on hash function, when BSR advertising the group
830 to RP mapping with same priority
836 s1-----f1-----i1-----l1----r1
845 i1 - Intermediate Router (also RP)
851 tc_name
= request
.node
.name
852 write_test_header(tc_name
)
854 # Don"t run this test if we have any failure.
855 if tgen
.routers_have_failure():
856 pytest
.skip(tgen
.errors
)
858 app_helper
.stop_all_hosts()
860 reset_config_on_routers(tgen
)
861 clear_pim_interface_traffic(tgen
, topo
)
863 result
= pre_config_to_bsm(
864 tgen
, topo
, tc_name
, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
866 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
868 result
= pre_config_to_bsm(
869 tgen
, topo
, tc_name
, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
871 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
873 GROUP_ADDRESS
= "225.1.1.1"
875 # Use scapy to send pre-defined packet from senser to receiver
876 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet7")
877 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
879 bsr_ip
= topo
["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
882 result
= app_helper
.run_join("r1", GROUP_ADDRESS
, "l1")
883 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
887 # Verify bsr state in FHR
888 step("Verify if b1 chosen as BSR in f1")
889 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip
)
890 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
892 group
= "225.1.1.0/24"
894 # Find the elected rp from bsrp-info
895 step("Find the elected rp from bsrp-info in LHR l1")
896 rp
= find_rp_from_bsrp_info(tgen
, dut
, bsr_ip
, group
)
897 assert rp
is not {}, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
899 # Verify if RP with highest hash value is chosen
900 step("Verify if RP(2.2.2.2) with highest hash value is chosen in l1")
901 if rp
[group
] == "2.2.2.2":
904 result
= "rp expected: 2.2.2.2 got:" + rp
[group
]
906 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
908 # Check RP detail in LHR
909 step("Verify RP in LHR")
910 result
= verify_pim_grp_rp_source(tgen
, topo
, dut
, group
, "BSR", rp
[group
])
911 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
913 step("clear BSM database before moving to next case")
914 clear_bsrp_data(tgen
, topo
)
916 write_test_footer(tc_name
)
919 def test_BSM_fragmentation_p1(request
):
921 Verify fragmentation of bootstrap message
927 s1-----f1-----i1-----l1----r1
936 i1 - Intermediate Router (also RP)
942 tc_name
= request
.node
.name
943 write_test_header(tc_name
)
945 # Don"t run this test if we have any failure.
946 if tgen
.routers_have_failure():
947 pytest
.skip(tgen
.errors
)
949 app_helper
.stop_all_hosts()
951 reset_config_on_routers(tgen
)
952 clear_pim_interface_traffic(tgen
, topo
)
954 result
= pre_config_to_bsm(
955 tgen
, topo
, tc_name
, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
957 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
959 result
= pre_config_to_bsm(
960 tgen
, topo
, tc_name
, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
962 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
964 GROUP_ADDRESS
= "225.1.1.1"
966 bsr_ip
= topo
["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
968 step("Send BSM and verify if all routers have same bsrp before fragment")
969 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet1")
970 # Verify bsr state in FHR
971 step("Verify if b1 chosen as BSR in f1")
972 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip
)
973 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
975 fhr_node
= tgen
.routers()["f1"]
976 inter_node
= tgen
.routers()["i1"]
977 lhr_node
= tgen
.routers()["l1"]
979 # Verify if bsrp list is same across f1, i1 and l1
980 step("Verify if bsrp list is same across f1, i1 and l1")
981 bsrp_f1
= fhr_node
.vtysh_cmd("show ip pim bsrp-info json", isjson
=True)
982 logger
.info("show_ip_pim_bsrp_info_json f1: \n %s", bsrp_f1
)
983 bsrp_i1
= inter_node
.vtysh_cmd("show ip pim bsrp-info json", isjson
=True)
984 logger
.info("show_ip_pim_bsrp_info_json i1: \n %s", bsrp_i1
)
985 bsrp_l1
= lhr_node
.vtysh_cmd("show ip pim bsrp-info json", isjson
=True)
986 logger
.info("show_ip_pim_bsrp_info_json l1: \n %s", bsrp_l1
)
988 if bsrp_f1
== bsrp_l1
:
991 result
= "bsrp info in f1 is not same in l1"
993 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
995 # set mtu of fhr(f1) to i1 interface to 100 so that bsm fragments
996 step("set mtu of fhr(f1) to i1 interface to 100 so that bsm fragments")
997 fhr_node
.run("ip link set f1-i1-eth2 mtu 100")
998 inter_node
.run("ip link set i1-f1-eth0 mtu 100")
1000 # Use scapy to send pre-defined packet from senser to receiver
1001 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet2")
1002 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1004 result
= app_helper
.run_join("r1", GROUP_ADDRESS
, "l1")
1005 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
1007 # Verify bsr state in FHR
1008 step("Verify if b1 chosen as BSR")
1009 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip
)
1010 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1012 # Verify if bsrp list is same across f1, i1 and l1
1013 step("Verify if bsrp list is same across f1, i1 and l1 after fragmentation")
1014 bsrp_f1
= fhr_node
.vtysh_cmd("show ip pim bsrp-info json", isjson
=True)
1015 logger
.info("show_ip_pim_bsrp_info_json f1: \n %s", bsrp_f1
)
1016 bsrp_i1
= inter_node
.vtysh_cmd("show ip pim bsrp-info json", isjson
=True)
1017 logger
.info("show_ip_pim_bsrp_info_json i1: \n %s", bsrp_i1
)
1018 bsrp_l1
= lhr_node
.vtysh_cmd("show ip pim bsrp-info json", isjson
=True)
1019 logger
.info("show_ip_pim_bsrp_info_json l1: \n %s", bsrp_l1
)
1021 if bsrp_f1
== bsrp_l1
:
1024 result
= "bsrp info in f1 is not same in l1"
1026 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1028 step("clear BSM database before moving to next case")
1029 clear_bsrp_data(tgen
, topo
)
1031 write_test_footer(tc_name
)
1034 def test_RP_with_all_ip_octet_p1(request
):
1036 Verify when candidate RP advertised with 32 mask length
1037 and contain all the contacts
1043 s1-----f1-----i1-----l1----r1
1052 i1 - Intermediate Router (also RP)
1057 tgen
= get_topogen()
1058 tc_name
= request
.node
.name
1059 write_test_header(tc_name
)
1061 # Don"t run this test if we have any failure.
1062 if tgen
.routers_have_failure():
1063 pytest
.skip(tgen
.errors
)
1065 app_helper
.stop_all_hosts()
1067 reset_config_on_routers(tgen
)
1068 clear_pim_interface_traffic(tgen
, topo
)
1070 step("pre-configure BSM packet")
1071 result
= pre_config_to_bsm(
1072 tgen
, topo
, tc_name
, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
1074 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1076 step("Send the IGMP group (225.100.100.100) from receiver connected to FRR")
1077 GROUP_ADDRESS
= "225.200.100.100"
1079 # Use scapy to send pre-defined packet from senser to receiver
1080 step("Configure cisco-1 as BSR1")
1081 result
= scapy_send_bsr_raw_packet(tgen
, topo
, "b1", "f1", "packet8")
1082 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1084 bsr_ip
= topo
["routers"]["b1"]["bsm"]["bsr_packets"]["packet8"]["bsr"].split("/")[0]
1087 result
= app_helper
.run_join("r1", GROUP_ADDRESS
, "l1")
1088 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
1092 "Groups are shown with candidate RP with correct mask length 'show ip pim bsrp-info'"
1094 step("Verify if b1 chosen as BSR in f1")
1095 result
= verify_pim_bsr(tgen
, topo
, "f1", bsr_ip
)
1096 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1098 group
= topo
["routers"]["b1"]["bsm"]["bsr_packets"]["packet9"]["group"]
1099 step("Find the elected rp from bsrp-info in LHR l1")
1100 rp
= find_rp_from_bsrp_info(tgen
, dut
, bsr_ip
, group
)
1101 assert rp
is not {}, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1103 step("Verify RP in LHR")
1104 result
= verify_pim_grp_rp_source(tgen
, topo
, dut
, group
, "BSR", rp
[group
])
1105 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
1107 step("clear BSM database before moving to next case")
1108 clear_bsrp_data(tgen
, topo
)
1110 write_test_footer(tc_name
)
1113 if __name__
== "__main__":
1114 args
= ["-s"] + sys
.argv
[1:]
1115 sys
.exit(pytest
.main(args
))