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