]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/multicast_pim_bsm_topo2/test_mcast_pim_bsmp_02.py
Merge pull request #11314 from chiragshah6/fdev2
[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 )
72
73 from lib.pim import (
74 add_rp_interfaces_and_pim_config,
75 reconfig_interfaces,
76 scapy_send_bsr_raw_packet,
77 find_rp_from_bsrp_info,
78 verify_pim_grp_rp_source,
79 verify_pim_bsr,
80 verify_mroutes,
81 verify_join_state_and_timer,
82 verify_pim_state,
83 verify_upstream_iif,
84 verify_igmp_groups,
85 verify_pim_upstream_rpf,
86 clear_mroute,
87 clear_pim_interface_traffic,
88 McastTesterHelper,
89 )
90 from lib.topolog import logger
91 from lib.topojson import build_config_from_json
92
93 pytestmark = [pytest.mark.pimd, pytest.mark.staticd]
94
95
96 TOPOLOGY = """
97
98 b1_____
99 |
100 |
101 s1-----f1-----i1-----l1----r1
102 |
103 ______|
104 b2
105
106 b1 - BSR 1
107 b2 - BSR 2
108 s1 - Source
109 f1 - FHR
110 i1 - Intermediate Router (also RP)
111 r1 - Receiver
112
113 """
114 # Global variables
115 NEXT_HOP1 = "70.0.0.1"
116 NEXT_HOP2 = "65.0.0.1"
117 BSR_IP_1 = "1.1.2.7"
118 BSR_IP_2 = "10.2.1.1"
119 BSR1_ADDR = "1.1.2.7/32"
120 BSR2_ADDR = "10.2.1.1/32"
121
122
123 def setup_module(mod):
124 """
125 Sets up the pytest environment
126
127 * `mod`: module name
128 """
129
130 # Required linux kernel version for this suite to run.
131 result = required_linux_kernel_version("4.15")
132 if result is not True:
133 pytest.skip("Kernel requirements are not met")
134
135 testsuite_run_time = time.asctime(time.localtime(time.time()))
136 logger.info("Testsuite start time: {}".format(testsuite_run_time))
137 logger.info("=" * 40)
138 logger.info("Master Topology: \n {}".format(TOPOLOGY))
139
140 logger.info("Running setup_module to create topology")
141
142 # This function initiates the topology build with Topogen...
143 json_file = "{}/mcast_pim_bsmp_02.json".format(CWD)
144 tgen = Topogen(json_file, mod.__name__)
145 global topo
146 topo = tgen.json_topo
147 # ... and here it calls Mininet initialization functions.
148
149 # get list of daemons needs to be started for this suite.
150 daemons = topo_daemons(tgen, topo)
151
152 # Starting topology, create tmp files which are loaded to routers
153 # to start daemons and then start routers
154 start_topology(tgen, daemons)
155
156 # Don"t run this test if we have any failure.
157 if tgen.routers_have_failure():
158 pytest.skip(tgen.errors)
159
160 # Creating configuration from JSON
161 build_config_from_json(tgen, topo)
162
163 # XXX Replace this using "with McastTesterHelper()... " in each test if possible.
164 global app_helper
165 app_helper = McastTesterHelper(tgen)
166
167 logger.info("Running setup_module() done")
168
169
170 def teardown_module():
171 """Teardown the pytest environment"""
172
173 logger.info("Running teardown_module to delete topology")
174
175 tgen = get_topogen()
176
177 app_helper.cleanup()
178
179 # Stop toplogy and Remove tmp files
180 tgen.stop_topology()
181
182 logger.info(
183 "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
184 )
185 logger.info("=" * 40)
186
187
188 #####################################################
189 #
190 # Local APIs
191 #
192 #####################################################
193
194
195 def clear_bsrp_data(tgen, topo):
196
197 """
198 clear bsm databas after test"
199 Parameters
200 ----------
201 * `tgen`: topogen object
202
203 Usage
204 -----
205 result = clear_bsrp_data(tgen, topo)
206 Returns
207 -------
208 errormsg(str) or True
209 """
210
211 for dut in tgen.routers():
212
213 rnode = tgen.routers()[dut]
214
215 logger.info("[DUT: %s]: clear_bsrp_data")
216
217 run_frr_cmd(rnode, "clear ip pim bsr-data")
218
219 return True
220
221
222 def pre_config_to_bsm(tgen, topo, tc_name, bsr, sender, receiver, fhr, rp, lhr, packet):
223 """
224 API to do required configuration to send and receive BSR packet
225 """
226
227 # Re-configure interfaces as per BSR packet
228 result = reconfig_interfaces(tgen, topo, bsr, fhr, packet)
229 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
230
231 # Create static routes
232 if "bsr" in topo["routers"][bsr]["bsm"]["bsr_packets"][packet]:
233 bsr_route = topo["routers"][bsr]["bsm"]["bsr_packets"][packet]["bsr"]
234 next_hop = topo["routers"][bsr]["bsm"]["bsr_packets"][packet]["src_ip"].split(
235 "/"
236 )[0]
237 next_hop_rp = topo["routers"][fhr]["links"][rp]["ipv4"].split("/")[0]
238 next_hop_lhr = topo["routers"][rp]["links"][lhr]["ipv4"].split("/")[0]
239
240 # Add static routes
241 input_dict = {
242 fhr: {"static_routes": [{"network": bsr_route, "next_hop": next_hop}]},
243 rp: {"static_routes": [{"network": bsr_route, "next_hop": next_hop_rp}]},
244 lhr: {"static_routes": [{"network": bsr_route, "next_hop": next_hop_lhr}]},
245 }
246
247 result = create_static_routes(tgen, input_dict)
248 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
249
250 # Add kernel route for source
251 group = topo["routers"][bsr]["bsm"]["bsr_packets"][packet]["pkt_dst"]
252 bsr_interface = topo["routers"][bsr]["links"][fhr]["interface"]
253 result = addKernelRoute(tgen, bsr, bsr_interface, group)
254 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
255
256 # RP Mapping
257 rp_mapping = topo["routers"][bsr]["bsm"]["bsr_packets"][packet]["rp_mapping"]
258
259 # Add interfaces in RP for all the RPs
260 result = add_rp_interfaces_and_pim_config(tgen, topo, "lo", rp, rp_mapping)
261 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
262
263 # Add kernel routes to sender and receiver
264 for group, rp_list in rp_mapping.items():
265 mask = group.split("/")[1]
266 if int(mask) == 32:
267 group = group.split("/")[0]
268
269 # Add kernel routes for sender
270 s_interface = topo["routers"][sender]["links"][fhr]["interface"]
271 result = addKernelRoute(tgen, sender, s_interface, group)
272 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
273
274 # Add kernel routes for receiver
275 r_interface = topo["routers"][receiver]["links"][lhr]["interface"]
276 result = addKernelRoute(tgen, receiver, r_interface, group)
277 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
278
279 # Add static routes for RPs in FHR and LHR
280 next_hop_fhr = topo["routers"][rp]["links"][fhr]["ipv4"].split("/")[0]
281 next_hop_lhr = topo["routers"][rp]["links"][lhr]["ipv4"].split("/")[0]
282 input_dict = {
283 fhr: {"static_routes": [{"network": rp_list, "next_hop": next_hop_fhr}]},
284 }
285 result = create_static_routes(tgen, input_dict)
286 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
287
288 input_dict = {
289 lhr: {"static_routes": [{"network": rp_list, "next_hop": next_hop_lhr}]},
290 }
291 result = create_static_routes(tgen, input_dict)
292 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
293 return True
294
295
296 #####################################################
297 #
298 # Testcases
299 #
300 #####################################################
301
302
303 def test_starg_mroute_p0(request):
304 """
305 1. Verify (*,G) mroute detail on FRR router after BSM rp installed
306
307 Topology used:
308 b1_____
309 |
310 |
311 s1-----f1-----i1-----l1----r1
312 |
313 ______|
314 b2
315
316 b1 - BSR 1
317 b2 - BSR 2
318 s1 - Source
319 f1 - FHR
320 i1 - Intermediate Router (also RP)
321 r1 - Receiver
322
323 """
324
325 tgen = get_topogen()
326 tc_name = request.node.name
327 write_test_header(tc_name)
328
329 # Don"t run this test if we have any failure.
330 if tgen.routers_have_failure():
331 pytest.skip(tgen.errors)
332
333 app_helper.stop_all_hosts()
334 clear_mroute(tgen)
335 reset_config_on_routers(tgen)
336 clear_pim_interface_traffic(tgen, topo)
337
338 result = pre_config_to_bsm(
339 tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
340 )
341 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
342
343 result = pre_config_to_bsm(
344 tgen, topo, tc_name, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
345 )
346 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
347
348 GROUP_ADDRESS = "226.1.1.1"
349
350 # Use scapy to send pre-defined packet from senser to receiver
351 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet1")
352 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
353
354 bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
355 time.sleep(1)
356
357 result = app_helper.run_join("r1", GROUP_ADDRESS, "l1")
358 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
359
360 # Verify bsr state in FHR
361 result = verify_pim_bsr(tgen, topo, "f1", bsr_ip)
362 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
363
364 # Check igmp groups
365 step("Verify IGMP groups in LHR l1")
366 dut = "l1"
367 intf = "l1-r1-eth1"
368 result = verify_igmp_groups(tgen, dut, intf, GROUP_ADDRESS)
369 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
370
371 group = "226.1.1.1/32"
372 src_addr = "*"
373
374 # Find the elected rp from bsrp-info
375 step("Find the elected rp from bsrp-info in LHR in l1")
376 rp = find_rp_from_bsrp_info(tgen, dut, bsr_ip, group)
377 assert rp is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
378
379 # Check RP detail in LHR
380 step("Verify RP in LHR in l1")
381 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp[group])
382 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
383
384 # Verify join state and join timer
385 step("Verify join state and join timer in l1")
386 iif = "l1-i1-eth0"
387 result = verify_join_state_and_timer(tgen, dut, iif, src_addr, GROUP_ADDRESS)
388 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
389
390 # Verify upstream IIF interface
391 step("Verify upstream IIF interface in l1")
392 result = verify_upstream_iif(tgen, dut, iif, src_addr, GROUP_ADDRESS)
393 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
394
395 # Verify IIF/OIL in pim state
396 oil = "l1-r1-eth1"
397 result = verify_pim_state(tgen, dut, iif, oil, GROUP_ADDRESS)
398 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
399
400 # Verify ip mroute
401 step("Verify ip mroute in l1")
402 src_addr = "*"
403 result = verify_mroutes(tgen, dut, src_addr, GROUP_ADDRESS, iif, oil)
404 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
405
406 # Remove the group rp mapping and send bsm
407 step("Remove the grp-rp mapping by sending bsm with hold time 0 for grp-rp")
408 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet2")
409 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
410
411 # Check RP unreachable
412 step("Check RP unreachability in l1")
413 iif = "Unknown"
414 result = verify_upstream_iif(
415 tgen, dut, iif, src_addr, GROUP_ADDRESS, joinState="NotJoined"
416 )
417 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
418
419 # Verify that it is not installed
420 step("Verify that iif is not installed in l1")
421 iif = "<iif?>"
422 result = verify_pim_state(tgen, dut, iif, oil, GROUP_ADDRESS, installed_fl=0)
423 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
424
425 # Verify mroute not installed
426 step("Verify mroute not installed in l1")
427 result = verify_mroutes(
428 tgen, dut, src_addr, GROUP_ADDRESS, iif, oil, retry_timeout=20, expected=False
429 )
430 assert (
431 result is not True
432 ), "Testcase {} : Failed \n " "mroute installed in l1 \n Error: {}".format(
433 tc_name, result
434 )
435
436 # Send BSM again to configure rp
437 step("Add back RP by sending BSM from b1")
438 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet1")
439 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
440
441 # Verify that (*,G) installed in mroute again
442 iif = "l1-i1-eth0"
443 result = verify_mroutes(tgen, dut, src_addr, GROUP_ADDRESS, iif, oil)
444 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
445
446 step("clear BSM database before moving to next case")
447 clear_bsrp_data(tgen, topo)
448
449 write_test_footer(tc_name)
450
451
452 def test_overlapping_group_p0(request):
453 """
454 Verify group to RP updated correctly on FRR router, when BSR advertising
455 the overlapping group address
456
457 Topology used:
458 b1_____
459 |
460 |
461 s1-----f1-----i1-----l1----r1
462 |
463 ______|
464 b2
465
466 b1 - BSR 1
467 b2 - BSR 2
468 s1 - Source
469 f1 - FHR
470 i1 - Intermediate Router (also RP)
471 r1 - Receiver
472
473 """
474
475 tgen = get_topogen()
476 tc_name = request.node.name
477 write_test_header(tc_name)
478
479 # Don"t run this test if we have any failure.
480 if tgen.routers_have_failure():
481 pytest.skip(tgen.errors)
482
483 app_helper.stop_all_hosts()
484 clear_mroute(tgen)
485 reset_config_on_routers(tgen)
486 clear_pim_interface_traffic(tgen, topo)
487
488 result = pre_config_to_bsm(
489 tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
490 )
491 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
492
493 result = pre_config_to_bsm(
494 tgen, topo, tc_name, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
495 )
496 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
497
498 GROUP_ADDRESS = "225.1.1.1"
499
500 # Use scapy to send pre-defined packet from senser to receiver
501 step("Send BSR packet from b1 to FHR")
502 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet4")
503 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
504
505 bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
506 time.sleep(1)
507
508 result = app_helper.run_join("r1", GROUP_ADDRESS, "l1")
509 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
510
511 # Verify bsr state in FHR
512 step("Verify if b1 is chosen as bsr in f1")
513 result = verify_pim_bsr(tgen, topo, "f1", bsr_ip)
514 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
515
516 dut = "l1"
517 group1 = "225.1.1.1/32"
518 # Find the elected rp from bsrp-info fro group 225.1.1.1/32
519 step("Find the elected rp from bsrp-info in LHR for 225.1.1.1/32")
520 rp1 = find_rp_from_bsrp_info(tgen, dut, bsr_ip, group1)
521 assert rp1 is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
522
523 group2 = "225.1.1.0/24"
524 # Find the elected rp from bsrp-info fro group 225.1.1.0/24
525 step("Find the elected rp from bsrp-info in LHR for 225.1.1.0/24")
526 rp2 = find_rp_from_bsrp_info(tgen, dut, bsr_ip, group2)
527 assert rp2 is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
528
529 iif = "l1-i1-eth0"
530 # Verify upstream rpf for 225.1.1.1 is chosen as rp1
531 step("Verify upstream rpf for 225.1.1.1 is chosen as rp1 in l1")
532 result = verify_pim_upstream_rpf(tgen, topo, dut, iif, GROUP_ADDRESS, rp1)
533 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
534
535 # Send BSR packet from b1 with rp for 225.1.1.1/32 removed
536 step("Send BSR packet from b1 with rp for 225.1.1.1/32 removed")
537 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet5")
538 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
539
540 # Verify upstream rpf for 225.1.1.1 is chosen as rp1
541 step("Verify upstream rpf for 225.1.1.1 is chosen as rp2 in l1")
542 result = verify_pim_upstream_rpf(tgen, topo, dut, iif, GROUP_ADDRESS, rp2)
543 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
544
545 # Verify IIF/OIL in pim state
546 step("Verify iif is installed after rp change in l1")
547 oil = "l1-r1-eth1"
548 result = verify_pim_state(tgen, dut, iif, oil, GROUP_ADDRESS)
549 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
550
551 step("clear BSM database before moving to next case")
552 clear_bsrp_data(tgen, topo)
553
554 write_test_footer(tc_name)
555
556
557 def test_RP_priority_p0(request):
558 """
559 Verify group to RP info is updated correctly, when BSR advertising the
560 same RP with different priority
561
562 Topology used:
563 b1_____
564 |
565 |
566 s1-----f1-----i1-----l1----r1
567 |
568 ______|
569 b2
570
571 b1 - BSR 1
572 b2 - BSR 2
573 s1 - Source
574 f1 - FHR
575 i1 - Intermediate Router (also RP)
576 r1 - Receiver
577 """
578
579 tgen = get_topogen()
580 tc_name = request.node.name
581 write_test_header(tc_name)
582
583 # Don"t run this test if we have any failure.
584 if tgen.routers_have_failure():
585 pytest.skip(tgen.errors)
586
587 app_helper.stop_all_hosts()
588 clear_mroute(tgen)
589 reset_config_on_routers(tgen)
590 clear_pim_interface_traffic(tgen, topo)
591
592 result = pre_config_to_bsm(
593 tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
594 )
595 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
596
597 result = pre_config_to_bsm(
598 tgen, topo, tc_name, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
599 )
600 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
601
602 GROUP_ADDRESS = "225.1.1.1"
603
604 # Use scapy to send pre-defined packet from senser to receiver
605 step("Send BSR packet from b1 to FHR")
606 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet1")
607 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
608
609 bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
610 time.sleep(1)
611
612 result = app_helper.run_join("r1", GROUP_ADDRESS, "l1")
613 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
614
615 # Verify bsr state in FHR
616 step("Verify if b1 is chosen as bsr in f1")
617 result = verify_pim_bsr(tgen, topo, "f1", bsr_ip)
618 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
619
620 dut = "l1"
621 group = "225.1.1.0/24"
622 # Find the elected rp from bsrp-info
623 step("Find the elected rp from bsrp-info in LHR l1")
624 rp1 = find_rp_from_bsrp_info(tgen, dut, bsr_ip, group)
625 assert rp1 is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
626
627 # Check RP detail in LHR
628 step("Verify RP in LHR l1")
629 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp1[group])
630 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
631
632 # Send BSR packet from b1 after deleting high prio rp for 225.1.1.0/24
633 step("Send BSM from b1 to FHR deleting high prio rp for 225.1.1.0/24")
634 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet6")
635 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
636
637 # Find the elected rp from bsrp-info
638 step("Find the elected rp from bsrp-info in LHR l1")
639 rp2 = find_rp_from_bsrp_info(tgen, dut, bsr_ip, group)
640 assert rp2 is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
641 logger.info("RP old: {} RP2 new: {} ".format(rp1[group], rp2[group]))
642
643 # Verify is the rp is different now
644 assert rp1[group] != rp2[group], "Testcase {} :Failed \n Error {}".format(
645 tc_name, result
646 )
647
648 rp_add1 = rp1[group]
649 rp_add2 = rp2[group]
650
651 # Verify if that rp is installed
652 step("Verify new RP in LHR installed")
653 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp_add2)
654 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
655
656 # Send BSR packet from b1 after putting back high prio rp for 225.1.1.0/24
657 step("Send BSM from b1 to FHR put back old high prio rp for 225.1.1.0/24")
658 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet1")
659 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
660
661 # Find the elected rp from bsrp-info
662 step("Find the elected rp from bsrp-info in LHR")
663 rp2 = find_rp_from_bsrp_info(tgen, dut, bsr_ip, group)
664 assert rp2 is not {}, "Testcase {} :Failed \n Error : RP not Found".format(tc_name)
665
666 # Verify is the rp is different now
667 step("Verify now old RP is elected again")
668 assert (
669 rp_add1 == rp2[group]
670 ), "Testcase {} :Failed \n Error : rp expected {} rp received {}".format(
671 tc_name, rp_add1, rp2[group] if group in rp2 else None
672 )
673
674 # Verify if that rp is installed
675 step("Verify new RP in LHR installed")
676 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp_add1)
677 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
678
679 step("clear BSM database before moving to next case")
680 clear_bsrp_data(tgen, topo)
681
682 write_test_footer(tc_name)
683
684
685 def test_BSR_election_p0(request):
686 """
687 Verify group to RP mapping in FRR node when 2 BSR are present in the network
688 and both are having same BSR priority
689
690 Topology used:
691 b1_____
692 |
693 |
694 s1-----f1-----i1-----l1----r1
695 |
696 ______|
697 b2
698
699 b1 - BSR 1
700 b2 - BSR 2
701 s1 - Source
702 f1 - FHR
703 i1 - Intermediate Router (also RP)
704 r1 - Receiver
705
706 """
707
708 tgen = get_topogen()
709 tc_name = request.node.name
710 write_test_header(tc_name)
711
712 app_helper.stop_all_hosts()
713 clear_mroute(tgen)
714 reset_config_on_routers(tgen)
715 clear_pim_interface_traffic(tgen, topo)
716
717 # Don"t run this test if we have any failure.
718 if tgen.routers_have_failure():
719 pytest.skip(tgen.errors)
720
721 result = pre_config_to_bsm(
722 tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
723 )
724 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
725
726 result = pre_config_to_bsm(
727 tgen, topo, tc_name, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
728 )
729 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
730
731 GROUP_ADDRESS = "225.1.1.1"
732
733 # Use scapy to send pre-defined packet from senser to receiver
734 step("Send BSR packet from b1 to FHR")
735 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet3")
736 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
737
738 bsr_ip1 = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[
739 0
740 ]
741 time.sleep(1)
742
743 result = app_helper.run_join("r1", GROUP_ADDRESS, "l1")
744 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
745
746 # Verify bsr state in FHR
747 step("Verify if b1 is chosen as bsr in f1")
748 result = verify_pim_bsr(tgen, topo, "f1", bsr_ip1)
749 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
750
751 dut = "l1"
752 group = "225.1.1.0/24"
753 # Find the elected rp from bsrp-info
754 step("Find the elected rp from bsrp-info in LHR in l1")
755 rp = find_rp_from_bsrp_info(tgen, dut, bsr_ip1, group)
756 assert rp is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
757
758 # Check RP detail in LHR
759 step("Verify RP in LHR l1")
760 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp[group])
761 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
762
763 # Send BSR packet from b2 with same priority
764 step("Send BSR packet from b2 to FHR with same priority")
765 result = scapy_send_bsr_raw_packet(tgen, topo, "b2", "f1", "packet1")
766 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
767
768 bsr_ip2 = topo["routers"]["b2"]["bsm"]["bsr_packets"]["packet2"]["bsr"].split("/")[
769 0
770 ]
771 time.sleep(1)
772
773 logger.info("BSR b1:" + bsr_ip1 + " BSR b2:" + bsr_ip2)
774 # Verify bsr state in FHR
775 step("Verify if b2 is not chosen as bsr in f1")
776 result = verify_pim_bsr(tgen, topo, "f1", bsr_ip2, expected=False)
777 assert (
778 result is not True
779 ), "Testcase {} : Failed \n " "b2 is chosen as bsr in f1 \n Error: {}".format(
780 tc_name, result
781 )
782
783 # Verify if b1 is still chosen as bsr
784 step("Verify if b1 is still chosen as bsr in f1")
785 result = verify_pim_bsr(tgen, topo, "f1", bsr_ip1)
786 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
787
788 # Verify if that rp is installed
789 step("Verify that same RP in istalled in LHR l1")
790 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp[group])
791 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
792
793 step("clear BSM database before moving to next case")
794 clear_bsrp_data(tgen, topo)
795
796 write_test_footer(tc_name)
797
798
799 def test_RP_hash_p0(request):
800 """
801 Verify RP is selected based on hash function, when BSR advertising the group
802 to RP mapping with same priority
803
804 Topology used:
805 b1_____
806 |
807 |
808 s1-----f1-----i1-----l1----r1
809 |
810 ______|
811 b2
812
813 b1 - BSR 1
814 b2 - BSR 2
815 s1 - Source
816 f1 - FHR
817 i1 - Intermediate Router (also RP)
818 r1 - Receiver
819
820 """
821
822 tgen = get_topogen()
823 tc_name = request.node.name
824 write_test_header(tc_name)
825
826 # Don"t run this test if we have any failure.
827 if tgen.routers_have_failure():
828 pytest.skip(tgen.errors)
829
830 app_helper.stop_all_hosts()
831 clear_mroute(tgen)
832 reset_config_on_routers(tgen)
833 clear_pim_interface_traffic(tgen, topo)
834
835 result = pre_config_to_bsm(
836 tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
837 )
838 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
839
840 result = pre_config_to_bsm(
841 tgen, topo, tc_name, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
842 )
843 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
844
845 GROUP_ADDRESS = "225.1.1.1"
846
847 # Use scapy to send pre-defined packet from senser to receiver
848 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet7")
849 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
850
851 bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
852 time.sleep(1)
853
854 result = app_helper.run_join("r1", GROUP_ADDRESS, "l1")
855 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
856
857 dut = "l1"
858
859 # Verify bsr state in FHR
860 step("Verify if b1 chosen as BSR in f1")
861 result = verify_pim_bsr(tgen, topo, "f1", bsr_ip)
862 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
863
864 group = "225.1.1.0/24"
865
866 # Find the elected rp from bsrp-info
867 step("Find the elected rp from bsrp-info in LHR l1")
868 rp = find_rp_from_bsrp_info(tgen, dut, bsr_ip, group)
869 assert rp is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
870
871 # Verify if RP with highest hash value is chosen
872 step("Verify if RP(2.2.2.2) with highest hash value is chosen in l1")
873 if rp[group] == "2.2.2.2":
874 result = True
875 else:
876 result = "rp expected: 2.2.2.2 got:" + rp[group]
877
878 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
879
880 # Check RP detail in LHR
881 step("Verify RP in LHR")
882 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp[group])
883 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
884
885 step("clear BSM database before moving to next case")
886 clear_bsrp_data(tgen, topo)
887
888 write_test_footer(tc_name)
889
890
891 def test_BSM_fragmentation_p1(request):
892 """
893 Verify fragmentation of bootstrap message
894
895 Topology used:
896 b1_____
897 |
898 |
899 s1-----f1-----i1-----l1----r1
900 |
901 ______|
902 b2
903
904 b1 - BSR 1
905 b2 - BSR 2
906 s1 - Source
907 f1 - FHR
908 i1 - Intermediate Router (also RP)
909 r1 - Receiver
910
911 """
912
913 tgen = get_topogen()
914 tc_name = request.node.name
915 write_test_header(tc_name)
916
917 # Don"t run this test if we have any failure.
918 if tgen.routers_have_failure():
919 pytest.skip(tgen.errors)
920
921 app_helper.stop_all_hosts()
922 clear_mroute(tgen)
923 reset_config_on_routers(tgen)
924 clear_pim_interface_traffic(tgen, topo)
925
926 result = pre_config_to_bsm(
927 tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
928 )
929 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
930
931 result = pre_config_to_bsm(
932 tgen, topo, tc_name, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
933 )
934 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
935
936 GROUP_ADDRESS = "225.1.1.1"
937
938 bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
939
940 step("Send BSM and verify if all routers have same bsrp before fragment")
941 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet1")
942 # Verify bsr state in FHR
943 step("Verify if b1 chosen as BSR in f1")
944 result = verify_pim_bsr(tgen, topo, "f1", bsr_ip)
945 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
946
947 fhr_node = tgen.routers()["f1"]
948 inter_node = tgen.routers()["i1"]
949 lhr_node = tgen.routers()["l1"]
950
951 # Verify if bsrp list is same across f1, i1 and l1
952 step("Verify if bsrp list is same across f1, i1 and l1")
953 bsrp_f1 = fhr_node.vtysh_cmd("show ip pim bsrp-info json", isjson=True)
954 logger.info("show_ip_pim_bsrp_info_json f1: \n %s", bsrp_f1)
955 bsrp_i1 = inter_node.vtysh_cmd("show ip pim bsrp-info json", isjson=True)
956 logger.info("show_ip_pim_bsrp_info_json i1: \n %s", bsrp_i1)
957 bsrp_l1 = lhr_node.vtysh_cmd("show ip pim bsrp-info json", isjson=True)
958 logger.info("show_ip_pim_bsrp_info_json l1: \n %s", bsrp_l1)
959
960 if bsrp_f1 == bsrp_l1:
961 result = True
962 else:
963 result = "bsrp info in f1 is not same in l1"
964
965 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
966
967 # set mtu of fhr(f1) to i1 interface to 100 so that bsm fragments
968 step("set mtu of fhr(f1) to i1 interface to 100 so that bsm fragments")
969 fhr_node.run("ip link set f1-i1-eth2 mtu 100")
970 inter_node.run("ip link set i1-f1-eth0 mtu 100")
971
972 # Use scapy to send pre-defined packet from senser to receiver
973 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet2")
974 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
975
976 result = app_helper.run_join("r1", GROUP_ADDRESS, "l1")
977 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
978
979 # Verify bsr state in FHR
980 step("Verify if b1 chosen as BSR")
981 result = verify_pim_bsr(tgen, topo, "f1", bsr_ip)
982 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
983
984 # Verify if bsrp list is same across f1, i1 and l1
985 step("Verify if bsrp list is same across f1, i1 and l1 after fragmentation")
986 bsrp_f1 = fhr_node.vtysh_cmd("show ip pim bsrp-info json", isjson=True)
987 logger.info("show_ip_pim_bsrp_info_json f1: \n %s", bsrp_f1)
988 bsrp_i1 = inter_node.vtysh_cmd("show ip pim bsrp-info json", isjson=True)
989 logger.info("show_ip_pim_bsrp_info_json i1: \n %s", bsrp_i1)
990 bsrp_l1 = lhr_node.vtysh_cmd("show ip pim bsrp-info json", isjson=True)
991 logger.info("show_ip_pim_bsrp_info_json l1: \n %s", bsrp_l1)
992
993 if bsrp_f1 == bsrp_l1:
994 result = True
995 else:
996 result = "bsrp info in f1 is not same in l1"
997
998 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
999
1000 step("clear BSM database before moving to next case")
1001 clear_bsrp_data(tgen, topo)
1002
1003 write_test_footer(tc_name)
1004
1005
1006 def test_RP_with_all_ip_octet_p1(request):
1007 """
1008 Verify when candidate RP advertised with 32 mask length
1009 and contain all the contacts
1010
1011 Topology used:
1012 b1_____
1013 |
1014 |
1015 s1-----f1-----i1-----l1----r1
1016 |
1017 ______|
1018 b2
1019
1020 b1 - BSR 1
1021 b2 - BSR 2
1022 s1 - Source
1023 f1 - FHR
1024 i1 - Intermediate Router (also RP)
1025 r1 - Receiver
1026
1027 """
1028
1029 tgen = get_topogen()
1030 tc_name = request.node.name
1031 write_test_header(tc_name)
1032
1033 # Don"t run this test if we have any failure.
1034 if tgen.routers_have_failure():
1035 pytest.skip(tgen.errors)
1036
1037 app_helper.stop_all_hosts()
1038 clear_mroute(tgen)
1039 reset_config_on_routers(tgen)
1040 clear_pim_interface_traffic(tgen, topo)
1041
1042 step("pre-configure BSM packet")
1043 result = pre_config_to_bsm(
1044 tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
1045 )
1046 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1047
1048 step("Send the IGMP group (225.100.100.100) from receiver connected to FRR")
1049 GROUP_ADDRESS = "225.200.100.100"
1050
1051 # Use scapy to send pre-defined packet from senser to receiver
1052 step("Configure cisco-1 as BSR1")
1053 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet8")
1054 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1055
1056 bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet8"]["bsr"].split("/")[0]
1057 time.sleep(1)
1058
1059 result = app_helper.run_join("r1", GROUP_ADDRESS, "l1")
1060 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1061
1062 dut = "l1"
1063 step(
1064 "Groups are shown with candidate RP with correct mask length 'show ip pim bsrp-info'"
1065 )
1066 step("Verify if b1 chosen as BSR in f1")
1067 result = verify_pim_bsr(tgen, topo, "f1", bsr_ip)
1068 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1069
1070 group = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet9"]["group"]
1071 step("Find the elected rp from bsrp-info in LHR l1")
1072 rp = find_rp_from_bsrp_info(tgen, dut, bsr_ip, group)
1073 assert rp is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1074
1075 step("Verify RP in LHR")
1076 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp[group])
1077 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1078
1079 step("clear BSM database before moving to next case")
1080 clear_bsrp_data(tgen, topo)
1081
1082 write_test_footer(tc_name)
1083
1084
1085 if __name__ == "__main__":
1086 args = ["-s"] + sys.argv[1:]
1087 sys.exit(pytest.main(args))