]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/multicast_pim_bsm_topo2/test_mcast_pim_bsmp_02.py
Merge pull request #11605 from LabNConsulting/improve-valgrind
[mirror_frr.git] / tests / topotests / multicast_pim_bsm_topo2 / test_mcast_pim_bsmp_02.py
1 #!/usr/bin/env python
2 #
3 # Copyright (c) 2020 by VMware, Inc. ("VMware")
4 # Used Copyright (c) 2018 by Network Device Education Foundation,
5 # Inc. ("NetDEF") in this file.
6 #
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
10 # in all copies.
11 #
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
19 # OF THIS SOFTWARE.
20 #
21
22 """
23 Following tests are covered to test PIM BSM processing basic functionality:
24
25 Test steps
26 - Create topology (setup module)
27 - Bring up topology
28
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
42 """
43
44 import os
45 import sys
46 import time
47 import pytest
48
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/"))
53
54 # Required to instantiate the topology builder class.
55
56 # pylint: disable=C0413
57 # Import topogen and topotest helpers
58 from lib.topogen import Topogen, get_topogen
59
60 from lib.common_config import (
61 start_topology,
62 write_test_header,
63 write_test_footer,
64 step,
65 addKernelRoute,
66 create_static_routes,
67 reset_config_on_routers,
68 run_frr_cmd,
69 required_linux_kernel_version,
70 topo_daemons,
71 verify_rib,
72 )
73
74 from lib.pim import (
75 add_rp_interfaces_and_pim_config,
76 reconfig_interfaces,
77 scapy_send_bsr_raw_packet,
78 find_rp_from_bsrp_info,
79 verify_pim_grp_rp_source,
80 verify_pim_bsr,
81 verify_mroutes,
82 verify_join_state_and_timer,
83 verify_pim_state,
84 verify_upstream_iif,
85 verify_igmp_groups,
86 verify_pim_upstream_rpf,
87 clear_mroute,
88 clear_pim_interface_traffic,
89 McastTesterHelper,
90 verify_pim_neighbors,
91 )
92 from lib.topolog import logger
93 from lib.topojson import build_config_from_json
94
95 pytestmark = [pytest.mark.pimd, pytest.mark.staticd]
96
97
98 TOPOLOGY = """
99
100 b1_____
101 |
102 |
103 s1-----f1-----i1-----l1----r1
104 |
105 ______|
106 b2
107
108 b1 - BSR 1
109 b2 - BSR 2
110 s1 - Source
111 f1 - FHR
112 i1 - Intermediate Router (also RP)
113 r1 - Receiver
114
115 """
116 # Global variables
117 NEXT_HOP1 = "70.0.0.1"
118 NEXT_HOP2 = "65.0.0.1"
119 BSR_IP_1 = "1.1.2.7"
120 BSR_IP_2 = "10.2.1.1"
121 BSR1_ADDR = "1.1.2.7/32"
122 BSR2_ADDR = "10.2.1.1/32"
123
124
125 def setup_module(mod):
126 """
127 Sets up the pytest environment
128
129 * `mod`: module name
130 """
131
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")
136
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))
141
142 logger.info("Running setup_module to create topology")
143
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__)
147 global topo
148 topo = tgen.json_topo
149 # ... and here it calls Mininet initialization functions.
150
151 # get list of daemons needs to be started for this suite.
152 daemons = topo_daemons(tgen, topo)
153
154 # Starting topology, create tmp files which are loaded to routers
155 # to start daemons and then start routers
156 start_topology(tgen, daemons)
157
158 # Don"t run this test if we have any failure.
159 if tgen.routers_have_failure():
160 pytest.skip(tgen.errors)
161
162 # Creating configuration from JSON
163 build_config_from_json(tgen, topo)
164
165 # Verify PIM neighbors
166 result = verify_pim_neighbors(tgen, topo)
167 assert result is True, " Verify PIM neighbor: Failed Error: {}".format(result)
168
169 # XXX Replace this using "with McastTesterHelper()... " in each test if possible.
170 global app_helper
171 app_helper = McastTesterHelper(tgen)
172
173 logger.info("Running setup_module() done")
174
175
176 def teardown_module():
177 """Teardown the pytest environment"""
178
179 logger.info("Running teardown_module to delete topology")
180
181 tgen = get_topogen()
182
183 app_helper.cleanup()
184
185 # Stop toplogy and Remove tmp files
186 tgen.stop_topology()
187
188 logger.info(
189 "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
190 )
191 logger.info("=" * 40)
192
193
194 #####################################################
195 #
196 # Local APIs
197 #
198 #####################################################
199
200
201 def clear_bsrp_data(tgen, topo):
202
203 """
204 clear bsm databas after test"
205 Parameters
206 ----------
207 * `tgen`: topogen object
208
209 Usage
210 -----
211 result = clear_bsrp_data(tgen, topo)
212 Returns
213 -------
214 errormsg(str) or True
215 """
216
217 for dut in tgen.routers():
218
219 rnode = tgen.routers()[dut]
220
221 logger.info("[DUT: %s]: clear_bsrp_data")
222
223 run_frr_cmd(rnode, "clear ip pim bsr-data")
224
225 return True
226
227
228 def pre_config_to_bsm(tgen, topo, tc_name, bsr, sender, receiver, fhr, rp, lhr, packet):
229 """
230 API to do required configuration to send and receive BSR packet
231 """
232
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)
236
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(
241 "/"
242 )[0]
243 next_hop_rp = topo["routers"][fhr]["links"][rp]["ipv4"].split("/")[0]
244 next_hop_lhr = topo["routers"][rp]["links"][lhr]["ipv4"].split("/")[0]
245
246 # Add static routes
247 input_dict = {
248 rp: {"static_routes": [{"network": bsr_route, "next_hop": next_hop_rp}]},
249 lhr: {"static_routes": [{"network": bsr_route, "next_hop": next_hop_lhr}]},
250 }
251
252 result = create_static_routes(tgen, input_dict)
253 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
254
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]}
258 result = verify_rib(
259 tgen, "ipv4", dut, input_routes, _nexthop, protocol="static"
260 )
261 assert result is True, "Testcase {} : Failed \n Error {}".format(
262 tc_name, result
263 )
264
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)
270
271 # RP Mapping
272 rp_mapping = topo["routers"][bsr]["bsm"]["bsr_packets"][packet]["rp_mapping"]
273
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)
277
278 # Add kernel routes to sender and receiver
279 for group, rp_list in rp_mapping.items():
280 mask = group.split("/")[1]
281 if int(mask) == 32:
282 group = group.split("/")[0]
283
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)
288
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)
293
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]
297 input_dict = {
298 fhr: {"static_routes": [{"network": rp_list, "next_hop": next_hop_fhr}]},
299 }
300 result = create_static_routes(tgen, input_dict)
301 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
302
303 # Verifying static routes are installed
304 result = verify_rib(
305 tgen, "ipv4", fhr, input_dict, next_hop_fhr, protocol="static"
306 )
307 assert result is True, "Testcase {} : Failed \n Error {}".format(
308 tc_name, result
309 )
310
311 input_dict = {
312 lhr: {"static_routes": [{"network": rp_list, "next_hop": next_hop_lhr}]},
313 }
314 result = create_static_routes(tgen, input_dict)
315 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
316
317 # Verifying static routes are installed
318 result = verify_rib(
319 tgen, "ipv4", lhr, input_dict, next_hop_lhr, protocol="static"
320 )
321 assert result is True, "Testcase {} : Failed \n Error {}".format(
322 tc_name, result
323 )
324
325 return True
326
327
328 #####################################################
329 #
330 # Testcases
331 #
332 #####################################################
333
334
335 def test_starg_mroute_p0(request):
336 """
337 1. Verify (*,G) mroute detail on FRR router after BSM rp installed
338
339 Topology used:
340 b1_____
341 |
342 |
343 s1-----f1-----i1-----l1----r1
344 |
345 ______|
346 b2
347
348 b1 - BSR 1
349 b2 - BSR 2
350 s1 - Source
351 f1 - FHR
352 i1 - Intermediate Router (also RP)
353 r1 - Receiver
354
355 """
356
357 tgen = get_topogen()
358 tc_name = request.node.name
359 write_test_header(tc_name)
360
361 # Don"t run this test if we have any failure.
362 if tgen.routers_have_failure():
363 pytest.skip(tgen.errors)
364
365 app_helper.stop_all_hosts()
366 clear_mroute(tgen)
367 reset_config_on_routers(tgen)
368 clear_pim_interface_traffic(tgen, topo)
369
370 result = pre_config_to_bsm(
371 tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
372 )
373 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
374
375 result = pre_config_to_bsm(
376 tgen, topo, tc_name, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
377 )
378 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
379
380 GROUP_ADDRESS = "226.1.1.1"
381
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)
385
386 bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
387 time.sleep(1)
388
389 result = app_helper.run_join("r1", GROUP_ADDRESS, "l1")
390 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
391
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)
395
396 # Check igmp groups
397 step("Verify IGMP groups in LHR l1")
398 dut = "l1"
399 intf = "l1-r1-eth1"
400 result = verify_igmp_groups(tgen, dut, intf, GROUP_ADDRESS)
401 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
402
403 group = "226.1.1.1/32"
404 src_addr = "*"
405
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)
410
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)
415
416 # Verify join state and join timer
417 step("Verify join state and join timer in l1")
418 iif = "l1-i1-eth0"
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)
421
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)
426
427 # Verify IIF/OIL in pim state
428 oil = "l1-r1-eth1"
429 result = verify_pim_state(tgen, dut, iif, oil, GROUP_ADDRESS)
430 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
431
432 # Verify ip mroute
433 step("Verify ip mroute in l1")
434 src_addr = "*"
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)
437
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)
442
443 # Check RP unreachable
444 step("Check RP unreachability in l1")
445 iif = "Unknown"
446 result = verify_upstream_iif(
447 tgen, dut, iif, src_addr, GROUP_ADDRESS, joinState="NotJoined"
448 )
449 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
450
451 # Verify that it is not installed
452 step("Verify that iif is not installed in l1")
453 iif = "<iif?>"
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)
456
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
461 )
462 assert (
463 result is not True
464 ), "Testcase {} : Failed \n " "mroute installed in l1 \n Error: {}".format(
465 tc_name, result
466 )
467
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)
472
473 # Verify that (*,G) installed in mroute again
474 iif = "l1-i1-eth0"
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)
477
478 step("clear BSM database before moving to next case")
479 clear_bsrp_data(tgen, topo)
480
481 write_test_footer(tc_name)
482
483
484 def test_overlapping_group_p0(request):
485 """
486 Verify group to RP updated correctly on FRR router, when BSR advertising
487 the overlapping group address
488
489 Topology used:
490 b1_____
491 |
492 |
493 s1-----f1-----i1-----l1----r1
494 |
495 ______|
496 b2
497
498 b1 - BSR 1
499 b2 - BSR 2
500 s1 - Source
501 f1 - FHR
502 i1 - Intermediate Router (also RP)
503 r1 - Receiver
504
505 """
506
507 tgen = get_topogen()
508 tc_name = request.node.name
509 write_test_header(tc_name)
510
511 # Don"t run this test if we have any failure.
512 if tgen.routers_have_failure():
513 pytest.skip(tgen.errors)
514
515 app_helper.stop_all_hosts()
516 clear_mroute(tgen)
517 reset_config_on_routers(tgen)
518 clear_pim_interface_traffic(tgen, topo)
519
520 result = pre_config_to_bsm(
521 tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
522 )
523 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
524
525 result = pre_config_to_bsm(
526 tgen, topo, tc_name, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
527 )
528 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
529
530 GROUP_ADDRESS = "225.1.1.1"
531
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)
536
537 bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
538 time.sleep(1)
539
540 result = app_helper.run_join("r1", GROUP_ADDRESS, "l1")
541 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
542
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)
547
548 dut = "l1"
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)
554
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)
560
561 iif = "l1-i1-eth0"
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)
566
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)
571
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)
576
577 # Verify IIF/OIL in pim state
578 step("Verify iif is installed after rp change in l1")
579 oil = "l1-r1-eth1"
580 result = verify_pim_state(tgen, dut, iif, oil, GROUP_ADDRESS)
581 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
582
583 step("clear BSM database before moving to next case")
584 clear_bsrp_data(tgen, topo)
585
586 write_test_footer(tc_name)
587
588
589 def test_RP_priority_p0(request):
590 """
591 Verify group to RP info is updated correctly, when BSR advertising the
592 same RP with different priority
593
594 Topology used:
595 b1_____
596 |
597 |
598 s1-----f1-----i1-----l1----r1
599 |
600 ______|
601 b2
602
603 b1 - BSR 1
604 b2 - BSR 2
605 s1 - Source
606 f1 - FHR
607 i1 - Intermediate Router (also RP)
608 r1 - Receiver
609 """
610
611 tgen = get_topogen()
612 tc_name = request.node.name
613 write_test_header(tc_name)
614
615 # Don"t run this test if we have any failure.
616 if tgen.routers_have_failure():
617 pytest.skip(tgen.errors)
618
619 app_helper.stop_all_hosts()
620 clear_mroute(tgen)
621 reset_config_on_routers(tgen)
622 clear_pim_interface_traffic(tgen, topo)
623
624 result = pre_config_to_bsm(
625 tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
626 )
627 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
628
629 result = pre_config_to_bsm(
630 tgen, topo, tc_name, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
631 )
632 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
633
634 GROUP_ADDRESS = "225.1.1.1"
635
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)
640
641 bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
642 time.sleep(1)
643
644 result = app_helper.run_join("r1", GROUP_ADDRESS, "l1")
645 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
646
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)
651
652 dut = "l1"
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)
658
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)
663
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)
668
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]))
674
675 # Verify is the rp is different now
676 assert rp1[group] != rp2[group], "Testcase {} :Failed \n Error {}".format(
677 tc_name, result
678 )
679
680 rp_add1 = rp1[group]
681 rp_add2 = rp2[group]
682
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)
687
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)
692
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)
697
698 # Verify is the rp is different now
699 step("Verify now old RP is elected again")
700 assert (
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
704 )
705
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)
710
711 step("clear BSM database before moving to next case")
712 clear_bsrp_data(tgen, topo)
713
714 write_test_footer(tc_name)
715
716
717 def test_BSR_election_p0(request):
718 """
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
721
722 Topology used:
723 b1_____
724 |
725 |
726 s1-----f1-----i1-----l1----r1
727 |
728 ______|
729 b2
730
731 b1 - BSR 1
732 b2 - BSR 2
733 s1 - Source
734 f1 - FHR
735 i1 - Intermediate Router (also RP)
736 r1 - Receiver
737
738 """
739
740 tgen = get_topogen()
741 tc_name = request.node.name
742 write_test_header(tc_name)
743
744 app_helper.stop_all_hosts()
745 clear_mroute(tgen)
746 reset_config_on_routers(tgen)
747 clear_pim_interface_traffic(tgen, topo)
748
749 # Don"t run this test if we have any failure.
750 if tgen.routers_have_failure():
751 pytest.skip(tgen.errors)
752
753 result = pre_config_to_bsm(
754 tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
755 )
756 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
757
758 result = pre_config_to_bsm(
759 tgen, topo, tc_name, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
760 )
761 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
762
763 GROUP_ADDRESS = "225.1.1.1"
764
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)
769
770 bsr_ip1 = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[
771 0
772 ]
773 time.sleep(1)
774
775 result = app_helper.run_join("r1", GROUP_ADDRESS, "l1")
776 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
777
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)
782
783 dut = "l1"
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)
789
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)
794
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)
799
800 bsr_ip2 = topo["routers"]["b2"]["bsm"]["bsr_packets"]["packet2"]["bsr"].split("/")[
801 0
802 ]
803 time.sleep(1)
804
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)
809 assert (
810 result is not True
811 ), "Testcase {} : Failed \n " "b2 is chosen as bsr in f1 \n Error: {}".format(
812 tc_name, result
813 )
814
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)
819
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)
824
825 step("clear BSM database before moving to next case")
826 clear_bsrp_data(tgen, topo)
827
828 write_test_footer(tc_name)
829
830
831 def test_RP_hash_p0(request):
832 """
833 Verify RP is selected based on hash function, when BSR advertising the group
834 to RP mapping with same priority
835
836 Topology used:
837 b1_____
838 |
839 |
840 s1-----f1-----i1-----l1----r1
841 |
842 ______|
843 b2
844
845 b1 - BSR 1
846 b2 - BSR 2
847 s1 - Source
848 f1 - FHR
849 i1 - Intermediate Router (also RP)
850 r1 - Receiver
851
852 """
853
854 tgen = get_topogen()
855 tc_name = request.node.name
856 write_test_header(tc_name)
857
858 # Don"t run this test if we have any failure.
859 if tgen.routers_have_failure():
860 pytest.skip(tgen.errors)
861
862 app_helper.stop_all_hosts()
863 clear_mroute(tgen)
864 reset_config_on_routers(tgen)
865 clear_pim_interface_traffic(tgen, topo)
866
867 result = pre_config_to_bsm(
868 tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
869 )
870 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
871
872 result = pre_config_to_bsm(
873 tgen, topo, tc_name, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
874 )
875 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
876
877 GROUP_ADDRESS = "225.1.1.1"
878
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)
882
883 bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
884 time.sleep(1)
885
886 result = app_helper.run_join("r1", GROUP_ADDRESS, "l1")
887 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
888
889 dut = "l1"
890
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)
895
896 group = "225.1.1.0/24"
897
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)
902
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":
906 result = True
907 else:
908 result = "rp expected: 2.2.2.2 got:" + rp[group]
909
910 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
911
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)
916
917 step("clear BSM database before moving to next case")
918 clear_bsrp_data(tgen, topo)
919
920 write_test_footer(tc_name)
921
922
923 def test_BSM_fragmentation_p1(request):
924 """
925 Verify fragmentation of bootstrap message
926
927 Topology used:
928 b1_____
929 |
930 |
931 s1-----f1-----i1-----l1----r1
932 |
933 ______|
934 b2
935
936 b1 - BSR 1
937 b2 - BSR 2
938 s1 - Source
939 f1 - FHR
940 i1 - Intermediate Router (also RP)
941 r1 - Receiver
942
943 """
944
945 tgen = get_topogen()
946 tc_name = request.node.name
947 write_test_header(tc_name)
948
949 # Don"t run this test if we have any failure.
950 if tgen.routers_have_failure():
951 pytest.skip(tgen.errors)
952
953 app_helper.stop_all_hosts()
954 clear_mroute(tgen)
955 reset_config_on_routers(tgen)
956 clear_pim_interface_traffic(tgen, topo)
957
958 result = pre_config_to_bsm(
959 tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
960 )
961 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
962
963 result = pre_config_to_bsm(
964 tgen, topo, tc_name, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
965 )
966 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
967
968 GROUP_ADDRESS = "225.1.1.1"
969
970 bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
971
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)
978
979 fhr_node = tgen.routers()["f1"]
980 inter_node = tgen.routers()["i1"]
981 lhr_node = tgen.routers()["l1"]
982
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)
991
992 if bsrp_f1 == bsrp_l1:
993 result = True
994 else:
995 result = "bsrp info in f1 is not same in l1"
996
997 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
998
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")
1003
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)
1007
1008 result = app_helper.run_join("r1", GROUP_ADDRESS, "l1")
1009 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1010
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)
1015
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)
1024
1025 if bsrp_f1 == bsrp_l1:
1026 result = True
1027 else:
1028 result = "bsrp info in f1 is not same in l1"
1029
1030 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1031
1032 step("clear BSM database before moving to next case")
1033 clear_bsrp_data(tgen, topo)
1034
1035 write_test_footer(tc_name)
1036
1037
1038 def test_RP_with_all_ip_octet_p1(request):
1039 """
1040 Verify when candidate RP advertised with 32 mask length
1041 and contain all the contacts
1042
1043 Topology used:
1044 b1_____
1045 |
1046 |
1047 s1-----f1-----i1-----l1----r1
1048 |
1049 ______|
1050 b2
1051
1052 b1 - BSR 1
1053 b2 - BSR 2
1054 s1 - Source
1055 f1 - FHR
1056 i1 - Intermediate Router (also RP)
1057 r1 - Receiver
1058
1059 """
1060
1061 tgen = get_topogen()
1062 tc_name = request.node.name
1063 write_test_header(tc_name)
1064
1065 # Don"t run this test if we have any failure.
1066 if tgen.routers_have_failure():
1067 pytest.skip(tgen.errors)
1068
1069 app_helper.stop_all_hosts()
1070 clear_mroute(tgen)
1071 reset_config_on_routers(tgen)
1072 clear_pim_interface_traffic(tgen, topo)
1073
1074 step("pre-configure BSM packet")
1075 result = pre_config_to_bsm(
1076 tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
1077 )
1078 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1079
1080 step("Send the IGMP group (225.100.100.100) from receiver connected to FRR")
1081 GROUP_ADDRESS = "225.200.100.100"
1082
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)
1087
1088 bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet8"]["bsr"].split("/")[0]
1089 time.sleep(1)
1090
1091 result = app_helper.run_join("r1", GROUP_ADDRESS, "l1")
1092 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1093
1094 dut = "l1"
1095 step(
1096 "Groups are shown with candidate RP with correct mask length 'show ip pim bsrp-info'"
1097 )
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)
1101
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)
1106
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)
1110
1111 step("clear BSM database before moving to next case")
1112 clear_bsrp_data(tgen, topo)
1113
1114 write_test_footer(tc_name)
1115
1116
1117 if __name__ == "__main__":
1118 args = ["-s"] + sys.argv[1:]
1119 sys.exit(pytest.main(args))