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