]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/multicast_pim_bsm_topo2/test_mcast_pim_bsmp_02.py
Merge pull request #11351 from kuldeepkash/uplink_mcast_tests
[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 fhr: {"static_routes": [{"network": bsr_route, "next_hop": next_hop}]},
249 rp: {"static_routes": [{"network": bsr_route, "next_hop": next_hop_rp}]},
250 lhr: {"static_routes": [{"network": bsr_route, "next_hop": next_hop_lhr}]},
251 }
252
253 result = create_static_routes(tgen, input_dict)
254 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
255
256 # Verifying static routes are installed
257 for dut, _nexthop in zip([fhr, rp, lhr], [next_hop, next_hop_rp, next_hop_lhr]):
258 input_routes = {dut: input_dict[dut]}
259 result = verify_rib(tgen, "ipv4", dut, input_routes, _nexthop)
260 assert result is True, "Testcase {} : Failed \n Error {}".format(
261 tc_name, result
262 )
263
264 # Add kernel route for source
265 group = topo["routers"][bsr]["bsm"]["bsr_packets"][packet]["pkt_dst"]
266 bsr_interface = topo["routers"][bsr]["links"][fhr]["interface"]
267 result = addKernelRoute(tgen, bsr, bsr_interface, group)
268 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
269
270 # RP Mapping
271 rp_mapping = topo["routers"][bsr]["bsm"]["bsr_packets"][packet]["rp_mapping"]
272
273 # Add interfaces in RP for all the RPs
274 result = add_rp_interfaces_and_pim_config(tgen, topo, "lo", rp, rp_mapping)
275 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
276
277 # Add kernel routes to sender and receiver
278 for group, rp_list in rp_mapping.items():
279 mask = group.split("/")[1]
280 if int(mask) == 32:
281 group = group.split("/")[0]
282
283 # Add kernel routes for sender
284 s_interface = topo["routers"][sender]["links"][fhr]["interface"]
285 result = addKernelRoute(tgen, sender, s_interface, group)
286 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
287
288 # Add kernel routes for receiver
289 r_interface = topo["routers"][receiver]["links"][lhr]["interface"]
290 result = addKernelRoute(tgen, receiver, r_interface, group)
291 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
292
293 # Add static routes for RPs in FHR and LHR
294 next_hop_fhr = topo["routers"][rp]["links"][fhr]["ipv4"].split("/")[0]
295 next_hop_lhr = topo["routers"][rp]["links"][lhr]["ipv4"].split("/")[0]
296 input_dict = {
297 fhr: {"static_routes": [{"network": rp_list, "next_hop": next_hop_fhr}]},
298 }
299 result = create_static_routes(tgen, input_dict)
300 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
301
302 # Verifying static routes are installed
303 result = verify_rib(tgen, "ipv4", fhr, input_dict, next_hop_fhr)
304 assert result is True, "Testcase {} : Failed \n Error {}".format(
305 tc_name, result
306 )
307
308 input_dict = {
309 lhr: {"static_routes": [{"network": rp_list, "next_hop": next_hop_lhr}]},
310 }
311 result = create_static_routes(tgen, input_dict)
312 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
313
314 # Verifying static routes are installed
315 result = verify_rib(tgen, "ipv4", lhr, input_dict, next_hop_lhr)
316 assert result is True, "Testcase {} : Failed \n Error {}".format(
317 tc_name, result
318 )
319
320 return True
321
322
323 #####################################################
324 #
325 # Testcases
326 #
327 #####################################################
328
329
330 def test_starg_mroute_p0(request):
331 """
332 1. Verify (*,G) mroute detail on FRR router after BSM rp installed
333
334 Topology used:
335 b1_____
336 |
337 |
338 s1-----f1-----i1-----l1----r1
339 |
340 ______|
341 b2
342
343 b1 - BSR 1
344 b2 - BSR 2
345 s1 - Source
346 f1 - FHR
347 i1 - Intermediate Router (also RP)
348 r1 - Receiver
349
350 """
351
352 tgen = get_topogen()
353 tc_name = request.node.name
354 write_test_header(tc_name)
355
356 # Don"t run this test if we have any failure.
357 if tgen.routers_have_failure():
358 pytest.skip(tgen.errors)
359
360 app_helper.stop_all_hosts()
361 clear_mroute(tgen)
362 reset_config_on_routers(tgen)
363 clear_pim_interface_traffic(tgen, topo)
364
365 result = pre_config_to_bsm(
366 tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
367 )
368 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
369
370 result = pre_config_to_bsm(
371 tgen, topo, tc_name, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
372 )
373 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
374
375 GROUP_ADDRESS = "226.1.1.1"
376
377 # Use scapy to send pre-defined packet from senser to receiver
378 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet1")
379 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
380
381 bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
382 time.sleep(1)
383
384 result = app_helper.run_join("r1", GROUP_ADDRESS, "l1")
385 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
386
387 # Verify bsr state in FHR
388 result = verify_pim_bsr(tgen, topo, "f1", bsr_ip)
389 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
390
391 # Check igmp groups
392 step("Verify IGMP groups in LHR l1")
393 dut = "l1"
394 intf = "l1-r1-eth1"
395 result = verify_igmp_groups(tgen, dut, intf, GROUP_ADDRESS)
396 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
397
398 group = "226.1.1.1/32"
399 src_addr = "*"
400
401 # Find the elected rp from bsrp-info
402 step("Find the elected rp from bsrp-info in LHR in l1")
403 rp = find_rp_from_bsrp_info(tgen, dut, bsr_ip, group)
404 assert rp is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
405
406 # Check RP detail in LHR
407 step("Verify RP in LHR in l1")
408 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp[group])
409 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
410
411 # Verify join state and join timer
412 step("Verify join state and join timer in l1")
413 iif = "l1-i1-eth0"
414 result = verify_join_state_and_timer(tgen, dut, iif, src_addr, GROUP_ADDRESS)
415 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
416
417 # Verify upstream IIF interface
418 step("Verify upstream IIF interface in l1")
419 result = verify_upstream_iif(tgen, dut, iif, src_addr, GROUP_ADDRESS)
420 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
421
422 # Verify IIF/OIL in pim state
423 oil = "l1-r1-eth1"
424 result = verify_pim_state(tgen, dut, iif, oil, GROUP_ADDRESS)
425 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
426
427 # Verify ip mroute
428 step("Verify ip mroute in l1")
429 src_addr = "*"
430 result = verify_mroutes(tgen, dut, src_addr, GROUP_ADDRESS, iif, oil)
431 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
432
433 # Remove the group rp mapping and send bsm
434 step("Remove the grp-rp mapping by sending bsm with hold time 0 for grp-rp")
435 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet2")
436 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
437
438 # Check RP unreachable
439 step("Check RP unreachability in l1")
440 iif = "Unknown"
441 result = verify_upstream_iif(
442 tgen, dut, iif, src_addr, GROUP_ADDRESS, joinState="NotJoined"
443 )
444 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
445
446 # Verify that it is not installed
447 step("Verify that iif is not installed in l1")
448 iif = "<iif?>"
449 result = verify_pim_state(tgen, dut, iif, oil, GROUP_ADDRESS, installed_fl=0)
450 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
451
452 # Verify mroute not installed
453 step("Verify mroute not installed in l1")
454 result = verify_mroutes(
455 tgen, dut, src_addr, GROUP_ADDRESS, iif, oil, retry_timeout=20, expected=False
456 )
457 assert (
458 result is not True
459 ), "Testcase {} : Failed \n " "mroute installed in l1 \n Error: {}".format(
460 tc_name, result
461 )
462
463 # Send BSM again to configure rp
464 step("Add back RP by sending BSM from b1")
465 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet1")
466 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
467
468 # Verify that (*,G) installed in mroute again
469 iif = "l1-i1-eth0"
470 result = verify_mroutes(tgen, dut, src_addr, GROUP_ADDRESS, iif, oil)
471 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
472
473 step("clear BSM database before moving to next case")
474 clear_bsrp_data(tgen, topo)
475
476 write_test_footer(tc_name)
477
478
479 def test_overlapping_group_p0(request):
480 """
481 Verify group to RP updated correctly on FRR router, when BSR advertising
482 the overlapping group address
483
484 Topology used:
485 b1_____
486 |
487 |
488 s1-----f1-----i1-----l1----r1
489 |
490 ______|
491 b2
492
493 b1 - BSR 1
494 b2 - BSR 2
495 s1 - Source
496 f1 - FHR
497 i1 - Intermediate Router (also RP)
498 r1 - Receiver
499
500 """
501
502 tgen = get_topogen()
503 tc_name = request.node.name
504 write_test_header(tc_name)
505
506 # Don"t run this test if we have any failure.
507 if tgen.routers_have_failure():
508 pytest.skip(tgen.errors)
509
510 app_helper.stop_all_hosts()
511 clear_mroute(tgen)
512 reset_config_on_routers(tgen)
513 clear_pim_interface_traffic(tgen, topo)
514
515 result = pre_config_to_bsm(
516 tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
517 )
518 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
519
520 result = pre_config_to_bsm(
521 tgen, topo, tc_name, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
522 )
523 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
524
525 GROUP_ADDRESS = "225.1.1.1"
526
527 # Use scapy to send pre-defined packet from senser to receiver
528 step("Send BSR packet from b1 to FHR")
529 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet4")
530 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
531
532 bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
533 time.sleep(1)
534
535 result = app_helper.run_join("r1", GROUP_ADDRESS, "l1")
536 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
537
538 # Verify bsr state in FHR
539 step("Verify if b1 is chosen as bsr in f1")
540 result = verify_pim_bsr(tgen, topo, "f1", bsr_ip)
541 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
542
543 dut = "l1"
544 group1 = "225.1.1.1/32"
545 # Find the elected rp from bsrp-info fro group 225.1.1.1/32
546 step("Find the elected rp from bsrp-info in LHR for 225.1.1.1/32")
547 rp1 = find_rp_from_bsrp_info(tgen, dut, bsr_ip, group1)
548 assert rp1 is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
549
550 group2 = "225.1.1.0/24"
551 # Find the elected rp from bsrp-info fro group 225.1.1.0/24
552 step("Find the elected rp from bsrp-info in LHR for 225.1.1.0/24")
553 rp2 = find_rp_from_bsrp_info(tgen, dut, bsr_ip, group2)
554 assert rp2 is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
555
556 iif = "l1-i1-eth0"
557 # Verify upstream rpf for 225.1.1.1 is chosen as rp1
558 step("Verify upstream rpf for 225.1.1.1 is chosen as rp1 in l1")
559 result = verify_pim_upstream_rpf(tgen, topo, dut, iif, GROUP_ADDRESS, rp1)
560 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
561
562 # Send BSR packet from b1 with rp for 225.1.1.1/32 removed
563 step("Send BSR packet from b1 with rp for 225.1.1.1/32 removed")
564 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet5")
565 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
566
567 # Verify upstream rpf for 225.1.1.1 is chosen as rp1
568 step("Verify upstream rpf for 225.1.1.1 is chosen as rp2 in l1")
569 result = verify_pim_upstream_rpf(tgen, topo, dut, iif, GROUP_ADDRESS, rp2)
570 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
571
572 # Verify IIF/OIL in pim state
573 step("Verify iif is installed after rp change in l1")
574 oil = "l1-r1-eth1"
575 result = verify_pim_state(tgen, dut, iif, oil, GROUP_ADDRESS)
576 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
577
578 step("clear BSM database before moving to next case")
579 clear_bsrp_data(tgen, topo)
580
581 write_test_footer(tc_name)
582
583
584 def test_RP_priority_p0(request):
585 """
586 Verify group to RP info is updated correctly, when BSR advertising the
587 same RP with different priority
588
589 Topology used:
590 b1_____
591 |
592 |
593 s1-----f1-----i1-----l1----r1
594 |
595 ______|
596 b2
597
598 b1 - BSR 1
599 b2 - BSR 2
600 s1 - Source
601 f1 - FHR
602 i1 - Intermediate Router (also RP)
603 r1 - Receiver
604 """
605
606 tgen = get_topogen()
607 tc_name = request.node.name
608 write_test_header(tc_name)
609
610 # Don"t run this test if we have any failure.
611 if tgen.routers_have_failure():
612 pytest.skip(tgen.errors)
613
614 app_helper.stop_all_hosts()
615 clear_mroute(tgen)
616 reset_config_on_routers(tgen)
617 clear_pim_interface_traffic(tgen, topo)
618
619 result = pre_config_to_bsm(
620 tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
621 )
622 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
623
624 result = pre_config_to_bsm(
625 tgen, topo, tc_name, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
626 )
627 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
628
629 GROUP_ADDRESS = "225.1.1.1"
630
631 # Use scapy to send pre-defined packet from senser to receiver
632 step("Send BSR packet from b1 to FHR")
633 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet1")
634 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
635
636 bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
637 time.sleep(1)
638
639 result = app_helper.run_join("r1", GROUP_ADDRESS, "l1")
640 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
641
642 # Verify bsr state in FHR
643 step("Verify if b1 is chosen as bsr in f1")
644 result = verify_pim_bsr(tgen, topo, "f1", bsr_ip)
645 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
646
647 dut = "l1"
648 group = "225.1.1.0/24"
649 # Find the elected rp from bsrp-info
650 step("Find the elected rp from bsrp-info in LHR l1")
651 rp1 = find_rp_from_bsrp_info(tgen, dut, bsr_ip, group)
652 assert rp1 is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
653
654 # Check RP detail in LHR
655 step("Verify RP in LHR l1")
656 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp1[group])
657 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
658
659 # Send BSR packet from b1 after deleting high prio rp for 225.1.1.0/24
660 step("Send BSM from b1 to FHR deleting high prio rp for 225.1.1.0/24")
661 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet6")
662 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
663
664 # Find the elected rp from bsrp-info
665 step("Find the elected rp from bsrp-info in LHR l1")
666 rp2 = find_rp_from_bsrp_info(tgen, dut, bsr_ip, group)
667 assert rp2 is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
668 logger.info("RP old: {} RP2 new: {} ".format(rp1[group], rp2[group]))
669
670 # Verify is the rp is different now
671 assert rp1[group] != rp2[group], "Testcase {} :Failed \n Error {}".format(
672 tc_name, result
673 )
674
675 rp_add1 = rp1[group]
676 rp_add2 = rp2[group]
677
678 # Verify if that rp is installed
679 step("Verify new RP in LHR installed")
680 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp_add2)
681 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
682
683 # Send BSR packet from b1 after putting back high prio rp for 225.1.1.0/24
684 step("Send BSM from b1 to FHR put back old high prio rp for 225.1.1.0/24")
685 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet1")
686 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
687
688 # Find the elected rp from bsrp-info
689 step("Find the elected rp from bsrp-info in LHR")
690 rp2 = find_rp_from_bsrp_info(tgen, dut, bsr_ip, group)
691 assert rp2 is not {}, "Testcase {} :Failed \n Error : RP not Found".format(tc_name)
692
693 # Verify is the rp is different now
694 step("Verify now old RP is elected again")
695 assert (
696 rp_add1 == rp2[group]
697 ), "Testcase {} :Failed \n Error : rp expected {} rp received {}".format(
698 tc_name, rp_add1, rp2[group] if group in rp2 else None
699 )
700
701 # Verify if that rp is installed
702 step("Verify new RP in LHR installed")
703 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp_add1)
704 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
705
706 step("clear BSM database before moving to next case")
707 clear_bsrp_data(tgen, topo)
708
709 write_test_footer(tc_name)
710
711
712 def test_BSR_election_p0(request):
713 """
714 Verify group to RP mapping in FRR node when 2 BSR are present in the network
715 and both are having same BSR priority
716
717 Topology used:
718 b1_____
719 |
720 |
721 s1-----f1-----i1-----l1----r1
722 |
723 ______|
724 b2
725
726 b1 - BSR 1
727 b2 - BSR 2
728 s1 - Source
729 f1 - FHR
730 i1 - Intermediate Router (also RP)
731 r1 - Receiver
732
733 """
734
735 tgen = get_topogen()
736 tc_name = request.node.name
737 write_test_header(tc_name)
738
739 app_helper.stop_all_hosts()
740 clear_mroute(tgen)
741 reset_config_on_routers(tgen)
742 clear_pim_interface_traffic(tgen, topo)
743
744 # Don"t run this test if we have any failure.
745 if tgen.routers_have_failure():
746 pytest.skip(tgen.errors)
747
748 result = pre_config_to_bsm(
749 tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
750 )
751 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
752
753 result = pre_config_to_bsm(
754 tgen, topo, tc_name, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
755 )
756 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
757
758 GROUP_ADDRESS = "225.1.1.1"
759
760 # Use scapy to send pre-defined packet from senser to receiver
761 step("Send BSR packet from b1 to FHR")
762 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet3")
763 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
764
765 bsr_ip1 = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[
766 0
767 ]
768 time.sleep(1)
769
770 result = app_helper.run_join("r1", GROUP_ADDRESS, "l1")
771 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
772
773 # Verify bsr state in FHR
774 step("Verify if b1 is chosen as bsr in f1")
775 result = verify_pim_bsr(tgen, topo, "f1", bsr_ip1)
776 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
777
778 dut = "l1"
779 group = "225.1.1.0/24"
780 # Find the elected rp from bsrp-info
781 step("Find the elected rp from bsrp-info in LHR in l1")
782 rp = find_rp_from_bsrp_info(tgen, dut, bsr_ip1, group)
783 assert rp is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
784
785 # Check RP detail in LHR
786 step("Verify RP in LHR l1")
787 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp[group])
788 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
789
790 # Send BSR packet from b2 with same priority
791 step("Send BSR packet from b2 to FHR with same priority")
792 result = scapy_send_bsr_raw_packet(tgen, topo, "b2", "f1", "packet1")
793 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
794
795 bsr_ip2 = topo["routers"]["b2"]["bsm"]["bsr_packets"]["packet2"]["bsr"].split("/")[
796 0
797 ]
798 time.sleep(1)
799
800 logger.info("BSR b1:" + bsr_ip1 + " BSR b2:" + bsr_ip2)
801 # Verify bsr state in FHR
802 step("Verify if b2 is not chosen as bsr in f1")
803 result = verify_pim_bsr(tgen, topo, "f1", bsr_ip2, expected=False)
804 assert (
805 result is not True
806 ), "Testcase {} : Failed \n " "b2 is chosen as bsr in f1 \n Error: {}".format(
807 tc_name, result
808 )
809
810 # Verify if b1 is still chosen as bsr
811 step("Verify if b1 is still chosen as bsr in f1")
812 result = verify_pim_bsr(tgen, topo, "f1", bsr_ip1)
813 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
814
815 # Verify if that rp is installed
816 step("Verify that same RP in istalled in LHR l1")
817 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp[group])
818 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
819
820 step("clear BSM database before moving to next case")
821 clear_bsrp_data(tgen, topo)
822
823 write_test_footer(tc_name)
824
825
826 def test_RP_hash_p0(request):
827 """
828 Verify RP is selected based on hash function, when BSR advertising the group
829 to RP mapping with same priority
830
831 Topology used:
832 b1_____
833 |
834 |
835 s1-----f1-----i1-----l1----r1
836 |
837 ______|
838 b2
839
840 b1 - BSR 1
841 b2 - BSR 2
842 s1 - Source
843 f1 - FHR
844 i1 - Intermediate Router (also RP)
845 r1 - Receiver
846
847 """
848
849 tgen = get_topogen()
850 tc_name = request.node.name
851 write_test_header(tc_name)
852
853 # Don"t run this test if we have any failure.
854 if tgen.routers_have_failure():
855 pytest.skip(tgen.errors)
856
857 app_helper.stop_all_hosts()
858 clear_mroute(tgen)
859 reset_config_on_routers(tgen)
860 clear_pim_interface_traffic(tgen, topo)
861
862 result = pre_config_to_bsm(
863 tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
864 )
865 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
866
867 result = pre_config_to_bsm(
868 tgen, topo, tc_name, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
869 )
870 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
871
872 GROUP_ADDRESS = "225.1.1.1"
873
874 # Use scapy to send pre-defined packet from senser to receiver
875 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet7")
876 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
877
878 bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
879 time.sleep(1)
880
881 result = app_helper.run_join("r1", GROUP_ADDRESS, "l1")
882 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
883
884 dut = "l1"
885
886 # Verify bsr state in FHR
887 step("Verify if b1 chosen as BSR in f1")
888 result = verify_pim_bsr(tgen, topo, "f1", bsr_ip)
889 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
890
891 group = "225.1.1.0/24"
892
893 # Find the elected rp from bsrp-info
894 step("Find the elected rp from bsrp-info in LHR l1")
895 rp = find_rp_from_bsrp_info(tgen, dut, bsr_ip, group)
896 assert rp is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
897
898 # Verify if RP with highest hash value is chosen
899 step("Verify if RP(2.2.2.2) with highest hash value is chosen in l1")
900 if rp[group] == "2.2.2.2":
901 result = True
902 else:
903 result = "rp expected: 2.2.2.2 got:" + rp[group]
904
905 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
906
907 # Check RP detail in LHR
908 step("Verify RP in LHR")
909 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp[group])
910 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
911
912 step("clear BSM database before moving to next case")
913 clear_bsrp_data(tgen, topo)
914
915 write_test_footer(tc_name)
916
917
918 def test_BSM_fragmentation_p1(request):
919 """
920 Verify fragmentation of bootstrap message
921
922 Topology used:
923 b1_____
924 |
925 |
926 s1-----f1-----i1-----l1----r1
927 |
928 ______|
929 b2
930
931 b1 - BSR 1
932 b2 - BSR 2
933 s1 - Source
934 f1 - FHR
935 i1 - Intermediate Router (also RP)
936 r1 - Receiver
937
938 """
939
940 tgen = get_topogen()
941 tc_name = request.node.name
942 write_test_header(tc_name)
943
944 # Don"t run this test if we have any failure.
945 if tgen.routers_have_failure():
946 pytest.skip(tgen.errors)
947
948 app_helper.stop_all_hosts()
949 clear_mroute(tgen)
950 reset_config_on_routers(tgen)
951 clear_pim_interface_traffic(tgen, topo)
952
953 result = pre_config_to_bsm(
954 tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
955 )
956 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
957
958 result = pre_config_to_bsm(
959 tgen, topo, tc_name, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
960 )
961 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
962
963 GROUP_ADDRESS = "225.1.1.1"
964
965 bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
966
967 step("Send BSM and verify if all routers have same bsrp before fragment")
968 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet1")
969 # Verify bsr state in FHR
970 step("Verify if b1 chosen as BSR in f1")
971 result = verify_pim_bsr(tgen, topo, "f1", bsr_ip)
972 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
973
974 fhr_node = tgen.routers()["f1"]
975 inter_node = tgen.routers()["i1"]
976 lhr_node = tgen.routers()["l1"]
977
978 # Verify if bsrp list is same across f1, i1 and l1
979 step("Verify if bsrp list is same across f1, i1 and l1")
980 bsrp_f1 = fhr_node.vtysh_cmd("show ip pim bsrp-info json", isjson=True)
981 logger.info("show_ip_pim_bsrp_info_json f1: \n %s", bsrp_f1)
982 bsrp_i1 = inter_node.vtysh_cmd("show ip pim bsrp-info json", isjson=True)
983 logger.info("show_ip_pim_bsrp_info_json i1: \n %s", bsrp_i1)
984 bsrp_l1 = lhr_node.vtysh_cmd("show ip pim bsrp-info json", isjson=True)
985 logger.info("show_ip_pim_bsrp_info_json l1: \n %s", bsrp_l1)
986
987 if bsrp_f1 == bsrp_l1:
988 result = True
989 else:
990 result = "bsrp info in f1 is not same in l1"
991
992 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
993
994 # set mtu of fhr(f1) to i1 interface to 100 so that bsm fragments
995 step("set mtu of fhr(f1) to i1 interface to 100 so that bsm fragments")
996 fhr_node.run("ip link set f1-i1-eth2 mtu 100")
997 inter_node.run("ip link set i1-f1-eth0 mtu 100")
998
999 # Use scapy to send pre-defined packet from senser to receiver
1000 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet2")
1001 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1002
1003 result = app_helper.run_join("r1", GROUP_ADDRESS, "l1")
1004 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1005
1006 # Verify bsr state in FHR
1007 step("Verify if b1 chosen as BSR")
1008 result = verify_pim_bsr(tgen, topo, "f1", bsr_ip)
1009 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1010
1011 # Verify if bsrp list is same across f1, i1 and l1
1012 step("Verify if bsrp list is same across f1, i1 and l1 after fragmentation")
1013 bsrp_f1 = fhr_node.vtysh_cmd("show ip pim bsrp-info json", isjson=True)
1014 logger.info("show_ip_pim_bsrp_info_json f1: \n %s", bsrp_f1)
1015 bsrp_i1 = inter_node.vtysh_cmd("show ip pim bsrp-info json", isjson=True)
1016 logger.info("show_ip_pim_bsrp_info_json i1: \n %s", bsrp_i1)
1017 bsrp_l1 = lhr_node.vtysh_cmd("show ip pim bsrp-info json", isjson=True)
1018 logger.info("show_ip_pim_bsrp_info_json l1: \n %s", bsrp_l1)
1019
1020 if bsrp_f1 == bsrp_l1:
1021 result = True
1022 else:
1023 result = "bsrp info in f1 is not same in l1"
1024
1025 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1026
1027 step("clear BSM database before moving to next case")
1028 clear_bsrp_data(tgen, topo)
1029
1030 write_test_footer(tc_name)
1031
1032
1033 def test_RP_with_all_ip_octet_p1(request):
1034 """
1035 Verify when candidate RP advertised with 32 mask length
1036 and contain all the contacts
1037
1038 Topology used:
1039 b1_____
1040 |
1041 |
1042 s1-----f1-----i1-----l1----r1
1043 |
1044 ______|
1045 b2
1046
1047 b1 - BSR 1
1048 b2 - BSR 2
1049 s1 - Source
1050 f1 - FHR
1051 i1 - Intermediate Router (also RP)
1052 r1 - Receiver
1053
1054 """
1055
1056 tgen = get_topogen()
1057 tc_name = request.node.name
1058 write_test_header(tc_name)
1059
1060 # Don"t run this test if we have any failure.
1061 if tgen.routers_have_failure():
1062 pytest.skip(tgen.errors)
1063
1064 app_helper.stop_all_hosts()
1065 clear_mroute(tgen)
1066 reset_config_on_routers(tgen)
1067 clear_pim_interface_traffic(tgen, topo)
1068
1069 step("pre-configure BSM packet")
1070 result = pre_config_to_bsm(
1071 tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
1072 )
1073 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1074
1075 step("Send the IGMP group (225.100.100.100) from receiver connected to FRR")
1076 GROUP_ADDRESS = "225.200.100.100"
1077
1078 # Use scapy to send pre-defined packet from senser to receiver
1079 step("Configure cisco-1 as BSR1")
1080 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet8")
1081 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1082
1083 bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet8"]["bsr"].split("/")[0]
1084 time.sleep(1)
1085
1086 result = app_helper.run_join("r1", GROUP_ADDRESS, "l1")
1087 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1088
1089 dut = "l1"
1090 step(
1091 "Groups are shown with candidate RP with correct mask length 'show ip pim bsrp-info'"
1092 )
1093 step("Verify if b1 chosen as BSR in f1")
1094 result = verify_pim_bsr(tgen, topo, "f1", bsr_ip)
1095 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1096
1097 group = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet9"]["group"]
1098 step("Find the elected rp from bsrp-info in LHR l1")
1099 rp = find_rp_from_bsrp_info(tgen, dut, bsr_ip, group)
1100 assert rp is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1101
1102 step("Verify RP in LHR")
1103 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp[group])
1104 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1105
1106 step("clear BSM database before moving to next case")
1107 clear_bsrp_data(tgen, topo)
1108
1109 write_test_footer(tc_name)
1110
1111
1112 if __name__ == "__main__":
1113 args = ["-s"] + sys.argv[1:]
1114 sys.exit(pytest.main(args))