]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/multicast_pim_bsm_topo1/test_mcast_pim_bsmp_01.py
tests: micronet: update infra
[mirror_frr.git] / tests / topotests / multicast_pim_bsm_topo1 / test_mcast_pim_bsmp_01.py
CommitLineData
df94c7e8
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 FRR router select higher IP BSR , when 2 BSR present in the network
312. Verify BSR and RP updated correctly after configuring as black hole address
323.1 Verify when new router added to the topology, FRR node will send
33 unicast BSM to new router
343.2 Verify if no forwarding bit is set , FRR is not forwarding the
35 BSM to other PIM nbrs
363.3 Verify multicast BSM is sent to new router when unicast BSM is disabled
374.1 Verfiy BSM arrived on non bsm capable interface is dropped and
38 not processed
394.2 Verify group to RP info updated correctly in FRR node, after shut and
40 no-shut of BSM enable interfaces
415. Verify static RP is preferred over BSR
426.1 Verify adding/deleting the group to rp mapping and RP priority
43 multiple times
446.2 Verify RP and (*,G) detail after PIM process restart on FRR node
457.1 Verify BSM timeout on FRR1
467.2 Verify RP state in FRR1 after Bootstrap timer expiry
478.1 Verify upstream interfaces(IIF) and join state are updated properly
48 after BSM received for FRR
498.2 Verify IIF and OIL in "show ip pim state" updated properly after
50 BSM received
51"""
52
53import os
54import sys
55import json
56import time
57import pytest
58
59# Save the Current Working Directory to find configuration files.
60CWD = os.path.dirname(os.path.realpath(__file__))
61sys.path.append(os.path.join(CWD, "../"))
62sys.path.append(os.path.join(CWD, "../lib/"))
63
64# Required to instantiate the topology builder class.
65
66# pylint: disable=C0413
67# Import topogen and topotest helpers
68from lib.topogen import Topogen, get_topogen
69from mininet.topo import Topo
70
71from lib.common_config import (
72 start_topology,
73 write_test_header,
74 write_test_footer,
75 step,
76 addKernelRoute,
77 create_static_routes,
78 iperfSendIGMPJoin,
79 stop_router,
80 start_router,
81 shutdown_bringup_interface,
82 kill_router_daemons,
83 start_router_daemons,
84 reset_config_on_routers,
85 do_countdown,
86 apply_raw_config,
87 kill_iperf,
88 run_frr_cmd,
89 required_linux_kernel_version,
90 topo_daemons,
91)
92
93from lib.pim import (
94 create_pim_config,
95 add_rp_interfaces_and_pim_config,
96 reconfig_interfaces,
97 scapy_send_bsr_raw_packet,
98 find_rp_from_bsrp_info,
99 verify_pim_grp_rp_source,
100 verify_pim_bsr,
101 verify_ip_mroutes,
102 verify_join_state_and_timer,
103 verify_pim_state,
104 verify_upstream_iif,
105 verify_igmp_groups,
106 verify_ip_pim_upstream_rpf,
107 enable_disable_pim_unicast_bsm,
108 enable_disable_pim_bsm,
109 clear_ip_mroute,
110 clear_ip_pim_interface_traffic,
111 verify_pim_interface_traffic,
112)
113from lib.topolog import logger
114from lib.topojson import build_topo_from_json, build_config_from_json
115
4be92408
DS
116pytestmark = [pytest.mark.pimd, pytest.mark.staticd]
117
118
df94c7e8
KK
119# Reading the data from JSON File for topology creation
120jsonFile = "{}/mcast_pim_bsmp_01.json".format(CWD)
121try:
122 with open(jsonFile, "r") as topoJson:
123 topo = json.load(topoJson)
124except IOError:
125 assert False, "Could not read file {}".format(jsonFile)
126
127TOPOLOGY = """
128
129 b1_____
130 |
131 |
132 s1-----f1-----i1-----l1----r1
133 |
134 ______|
135 b2
136
137 b1 - BSR 1
138 b2 - BSR 2
139 s1 - Source
140 f1 - FHR
141 i1 - Intermediate Router (also RP)
142 r1 - Receiver
143
144"""
145# Global variables
146NEXT_HOP1 = "70.0.0.1"
147NEXT_HOP2 = "65.0.0.1"
148BSR_IP_1 = "1.1.2.7"
149BSR_IP_2 = "10.2.1.1"
150BSR1_ADDR = "1.1.2.7/32"
151BSR2_ADDR = "10.2.1.1/32"
152
153
154class CreateTopo(Topo):
155 """
156 Test BasicTopo - topology 1
157
158 * `Topo`: Topology object
159 """
160
161 def build(self, *_args, **_opts):
162 """Build function"""
163 tgen = get_topogen(self)
164
165 # Building topology from json file
166 build_topo_from_json(tgen, topo)
167
168
169def setup_module(mod):
170 """
171 Sets up the pytest environment
172
173 * `mod`: module name
174 """
175
176 # Required linux kernel version for this suite to run.
177 result = required_linux_kernel_version("4.15")
178 if result is not True:
179 pytest.skip("Kernel requirements are not met")
180
181 testsuite_run_time = time.asctime(time.localtime(time.time()))
182 logger.info("Testsuite start time: {}".format(testsuite_run_time))
183 logger.info("=" * 40)
184 logger.info("Master Topology: \n {}".format(TOPOLOGY))
185
186 logger.info("Running setup_module to create topology")
187
188 # This function initiates the topology build with Topogen...
189 tgen = Topogen(CreateTopo, mod.__name__)
190 # ... and here it calls Mininet initialization functions.
191
192 # get list of daemons needs to be started for this suite.
193 daemons = topo_daemons(tgen, topo)
194
195 # Starting topology, create tmp files which are loaded to routers
196 # to start deamons and then start routers
197 start_topology(tgen, daemons)
198
199 # Don"t run this test if we have any failure.
200 if tgen.routers_have_failure():
201 pytest.skip(tgen.errors)
202
203 # Creating configuration from JSON
204 build_config_from_json(tgen, topo)
205
206 logger.info("Running setup_module() done")
207
208
209def teardown_module():
210 """Teardown the pytest environment"""
211
212 logger.info("Running teardown_module to delete topology")
213
214 tgen = get_topogen()
215
216 # Stop toplogy and Remove tmp files
217 tgen.stop_topology()
218
219 logger.info(
220 "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
221 )
222 logger.info("=" * 40)
223
224
225#####################################################
226#
227# Local APIs
228#
229#####################################################
230
231
232def clear_bsrp_data(tgen, topo):
233
234 """
235 clear bsm databas after test"
236 Parameters
237 ----------
238 * `tgen`: topogen object
239
240 Usage
241 -----
242 result = clear_bsrp_data(tgen, topo)
243 Returns
244 -------
245 errormsg(str) or True
246 """
247
248 for dut in tgen.routers():
249
250 rnode = tgen.routers()[dut]
251
252 logger.info("[DUT: %s]: clear_bsrp_data")
253
254 run_frr_cmd(rnode, "clear ip pim bsr-data")
255
256 return True
257
258
259def verify_state_incremented(state_before, state_after):
260 """
261 API to compare interface traffic state incrementing
262
263 Parameters
264 ----------
265 * `state_before` : State dictionary for any particular instance
266 * `state_after` : State dictionary for any particular instance
267 """
268
269 for router, state_data in state_before.items():
270 for state, value in state_data.items():
271 if state_before[router][state] >= state_after[router][state]:
272 errormsg = (
273 "[DUT: %s]: state %s value has not"
274 " incremented, Initial value: %s, "
275 "Current value: %s [FAILED!!]"
276 % (
277 router,
278 state,
279 state_before[router][state],
280 state_after[router][state],
281 )
282 )
283 return errormsg
284
285 logger.info(
286 "[DUT: %s]: State %s value is "
287 "incremented, Initial value: %s, Current value: %s"
288 " [PASSED!!]",
289 router,
290 state,
291 state_before[router][state],
292 state_after[router][state],
293 )
294
295 return True
296
297
298def pre_config_to_bsm(tgen, topo, tc_name, bsr, sender, receiver, fhr, rp, lhr, packet):
299 """
300 API to do required configuration to send and receive BSR packet
301 """
302
303 # Re-configure interfaces as per BSR packet
304 result = reconfig_interfaces(tgen, topo, bsr, fhr, packet)
305 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
306
307 # Create static routes
308 if "bsr" in topo["routers"][bsr]["bsm"]["bsr_packets"][packet]:
309 bsr_route = topo["routers"][bsr]["bsm"]["bsr_packets"][packet]["bsr"]
310 next_hop = topo["routers"][bsr]["bsm"]["bsr_packets"][packet]["src_ip"].split(
311 "/"
312 )[0]
313 next_hop_rp = topo["routers"][fhr]["links"][rp]["ipv4"].split("/")[0]
314 next_hop_lhr = topo["routers"][rp]["links"][lhr]["ipv4"].split("/")[0]
315
316 # Add static routes
317 input_dict = {
318 fhr: {"static_routes": [{"network": bsr_route, "next_hop": next_hop}]},
319 rp: {"static_routes": [{"network": bsr_route, "next_hop": next_hop_rp}]},
320 lhr: {"static_routes": [{"network": bsr_route, "next_hop": next_hop_lhr}]},
321 }
322
323 result = create_static_routes(tgen, input_dict)
324 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
325
326 # Add kernal route for source
327 group = topo["routers"][bsr]["bsm"]["bsr_packets"][packet]["pkt_dst"]
328 bsr_interface = topo["routers"][bsr]["links"][fhr]["interface"]
329 result = addKernelRoute(tgen, bsr, bsr_interface, group)
330 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
331
332 # RP Mapping
333 rp_mapping = topo["routers"][bsr]["bsm"]["bsr_packets"][packet]["rp_mapping"]
334
335 # Add interfaces in RP for all the RPs
336 result = add_rp_interfaces_and_pim_config(tgen, topo, "lo", rp, rp_mapping)
337 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
338
339 # Add kernal routes to sender and receiver
340 for group, rp_list in rp_mapping.items():
341 mask = group.split("/")[1]
342 if int(mask) == 32:
343 group = group.split("/")[0]
344
345 # Add kernal routes for sender
346 s_interface = topo["routers"][sender]["links"][fhr]["interface"]
347 result = addKernelRoute(tgen, sender, s_interface, group)
348 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
349
350 # Add kernal routes for receiver
351 r_interface = topo["routers"][receiver]["links"][lhr]["interface"]
352 result = addKernelRoute(tgen, receiver, r_interface, group)
353 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
354
355 # Add static routes for RPs in FHR and LHR
356 next_hop_fhr = topo["routers"][rp]["links"][fhr]["ipv4"].split("/")[0]
357 next_hop_lhr = topo["routers"][rp]["links"][lhr]["ipv4"].split("/")[0]
358 input_dict = {
359 fhr: {"static_routes": [{"network": rp_list, "next_hop": next_hop_fhr}]},
360 }
361 result = create_static_routes(tgen, input_dict)
362 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
363
364 input_dict = {
365 lhr: {"static_routes": [{"network": rp_list, "next_hop": next_hop_lhr}]},
366 }
367 result = create_static_routes(tgen, input_dict)
368 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
369 return True
370
371
372#####################################################
373#
374# Testcases
375#
376#####################################################
377
378
379def test_BSR_higher_prefer_ip_p0(request):
380 """
381 Verify FRR router select higher IP BSR , when 2 BSR present in the network
382
383 Topology used:
384 b1_____
385 |
386 |
387 s1-----f1-----i1-----l1----r1
388 |
389 ______|
390 b2
391
392 b1 - BSR 1
393 b2 - BSR 2
394 s1 - Source
395 f1 - FHR
396 i1 - Intermediate Router (also RP)
397 r1 - Receiver
398 """
399
400 tgen = get_topogen()
401 tc_name = request.node.name
402 write_test_header(tc_name)
403
404 kill_iperf(tgen)
405 clear_ip_mroute(tgen)
406 reset_config_on_routers(tgen)
407 clear_ip_pim_interface_traffic(tgen, topo)
408
409 # Don"t run this test if we have any failure.
410 if tgen.routers_have_failure():
411 pytest.skip(tgen.errors)
412
413 reset_config_on_routers(tgen)
414 step("pre-configure BSM packet")
415 step("Configure cisco-1 as BSR1 1.1.2.7")
416 result = pre_config_to_bsm(
417 tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
418 )
419 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
420 step("Configure cisco-1 as BSR1 10.2.1.1")
421 result = pre_config_to_bsm(
422 tgen, topo, tc_name, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
423 )
424 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
425 step("configuring loopback address of b1 and b2 as BSR")
426 intf_lo_addr_b1 = topo["routers"]["b1"]["links"]["lo"]["ipv4"]
427 intf_lo_addr_b2 = topo["routers"]["b2"]["links"]["lo"]["ipv4"]
428
429 raw_config = {
430 "b1": {
431 "raw_config": [
432 "interface lo",
433 "no ip address {}".format(intf_lo_addr_b1),
434 "ip address {}".format(BSR1_ADDR),
435 "ip pim",
436 ]
437 },
438 "b2": {
439 "raw_config": [
440 "interface lo",
441 "no ip address {}".format(intf_lo_addr_b2),
442 "ip address {}".format(BSR2_ADDR),
443 "ip pim",
444 ]
445 },
446 }
447 result = apply_raw_config(tgen, raw_config)
448 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
449
450 GROUP_ADDRESS = "225.200.100.100"
451 step("configuring static routes for both the BSR")
452
453 next_hop_rp = topo["routers"]["f1"]["links"]["i1"]["ipv4"].split("/")[0]
454 next_hop_lhr = topo["routers"]["i1"]["links"]["l1"]["ipv4"].split("/")[0]
455
456 input_dict = {
457 "f1": {
458 "static_routes": [
459 {"network": BSR1_ADDR, "next_hop": NEXT_HOP1},
460 {"network": BSR2_ADDR, "next_hop": NEXT_HOP2},
461 ]
462 },
463 "i1": {
464 "static_routes": [
465 {"network": BSR1_ADDR, "next_hop": next_hop_rp},
466 {"network": BSR2_ADDR, "next_hop": next_hop_rp},
467 ]
468 },
469 "l1": {
470 "static_routes": [
471 {"network": BSR1_ADDR, "next_hop": next_hop_lhr},
472 {"network": BSR2_ADDR, "next_hop": next_hop_lhr},
473 ]
474 },
475 }
476
477 result = create_static_routes(tgen, input_dict)
478 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
479
480 # Use scapy to send pre-defined packet from senser to receiver
481 step("Send BSR packet from b1 to FHR")
482 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet9")
483 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
484
485 result = iperfSendIGMPJoin(tgen, "r1", GROUP_ADDRESS, join_interval=1)
486 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
487 do_countdown(5)
488
489 dut = "l1"
490 step("Verify if b1 chosen as BSR in f1")
491 result = verify_pim_bsr(tgen, topo, "f1", BSR_IP_1)
492 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
493
494 group = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet9"]["group"]
495 step("Find the elected rp from bsrp-info in LHR l1")
496 rp = find_rp_from_bsrp_info(tgen, dut, BSR_IP_1, group)
497 assert rp is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
498
499 step("Verify RP in LHR")
500 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp[group])
501 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
502
503 step("Send BSR packet from b2 to FHR")
504 result = scapy_send_bsr_raw_packet(tgen, topo, "b2", "f1", "packet3")
505 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
506
507 dut = "l1"
508 step("Verify if b2 chosen as BSR in f1")
509 result = verify_pim_bsr(tgen, topo, "f1", BSR_IP_2)
510 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
511
512 step("Find the elected rp from bsrp-info in LHR l1")
513 rp = find_rp_from_bsrp_info(tgen, dut, BSR_IP_2, group)
514 assert rp is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
515
516 step("Verify RP in LHR")
517 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp[group])
518 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
519
520 step("Shut higher prefer BSR2 link f1 to b2")
521
522 f1_b2_eth1 = topo["routers"]["f1"]["links"]["b2"]["interface"]
523 shutdown_bringup_interface(tgen, "f1", "f1-b2-eth1", False)
524
525 step("clearing bsr to timeout old BSR")
526 clear_bsrp_data(tgen, topo)
527
528 step("Send BSR packet from b1 and b2 to FHR")
529 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet9")
530 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
531
532 result = scapy_send_bsr_raw_packet(tgen, topo, "b2", "f1", "packet3")
533 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
534
535 step("sleeping for 3 sec to leran new packet")
536 do_countdown(3)
537 step("verify BSR1 is become prefered RP")
538 dut = "l1"
539
540 step("Verify if b1 chosen as BSR in f1")
541 result = verify_pim_bsr(tgen, topo, "f1", BSR_IP_1)
542 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
543
544 step("Find the elected rp from bsrp-info in LHR l1")
545 rp = find_rp_from_bsrp_info(tgen, dut, BSR_IP_1, group)
546 assert rp is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
547
548 step("Verify RP in LHR")
549 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp[group])
550 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
551
552 step("NoShut higher prefer BSR2 link f1 to b2")
553 step("sleeping for 3 min to leran new packet")
554 do_countdown(3)
555 f1_b2_eth1 = topo["routers"]["f1"]["links"]["b2"]["interface"]
556 shutdown_bringup_interface(tgen, "f1", "f1-b2-eth1", True)
557 step("verify BSR2 is become prefered RP")
558 dut = "l1"
559
560 step("Send BSR packet from b1 and b2 to FHR")
561 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet9")
562 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
563
564 result = scapy_send_bsr_raw_packet(tgen, topo, "b2", "f1", "packet3")
565 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
566
567 step("Verify if b2 chosen as BSR in f1")
568 result = verify_pim_bsr(tgen, topo, "f1", BSR_IP_2)
569 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
570
571 step("Find the elected rp from bsrp-info in LHR l1")
572 rp = find_rp_from_bsrp_info(tgen, dut, BSR_IP_2, group)
573 assert rp is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
574
575 step("Verify RP in LHR")
576 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp[group])
577 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
578
579 step("Clear BSM database before moving to next case")
580 clear_bsrp_data(tgen, topo)
581
582 write_test_footer(tc_name)
583
584
585def test_BSR_CRP_with_blackhole_address_p1(request):
586 """
587 Verify BSR and RP updated correctly after configuring as black hole address
588
589 Topology used:
590 b1_____
591 |
592 |
593 s1-----f1-----i1-----l1----r1
594 |
595 ______|
596 b2
597
598 b1 - BSR 1
599 b2 - BSR 2
600 s1 - Source
601 f1 - FHR
602 i1 - Intermediate Router (also RP)
603 r1 - Receiver
604 """
605
606 tgen = get_topogen()
607 tc_name = request.node.name
608 write_test_header(tc_name)
609
610 kill_iperf(tgen)
611 clear_ip_mroute(tgen)
612 reset_config_on_routers(tgen)
613 clear_ip_pim_interface_traffic(tgen, topo)
614
615 # Don"t run this test if we have any failure.
616 if tgen.routers_have_failure():
617 pytest.skip(tgen.errors)
618
619 reset_config_on_routers(tgen)
620 step("pre-configure BSM packet")
621 step("Configure cisco-1 as BSR1 1.1.2.7")
622 result = pre_config_to_bsm(
623 tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
624 )
625 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
626
627 step("configuring loopback address of b1 and b2 as BSR")
628 intf_lo_addr_b1 = topo["routers"]["b1"]["links"]["lo"]["ipv4"]
629
630 raw_config = {
631 "b1": {
632 "raw_config": [
633 "interface lo",
634 "no ip address {}".format(intf_lo_addr_b1),
635 "ip address {}".format(BSR1_ADDR),
636 "ip pim",
637 ]
638 }
639 }
640 result = apply_raw_config(tgen, raw_config)
641 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
642
643 GROUP_ADDRESS = "225.200.100.100"
644 step("configuring static routes for both the BSR")
645
646 next_hop_rp = topo["routers"]["f1"]["links"]["i1"]["ipv4"].split("/")[0]
647 next_hop_lhr = topo["routers"]["i1"]["links"]["l1"]["ipv4"].split("/")[0]
d99438d2
KK
648 next_hop_fhr = topo["routers"]["i1"]["links"]["f1"]["ipv4"].split("/")[0]
649 CRP = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet9"]["candidate_rp"]
df94c7e8
KK
650
651 input_dict = {
df94c7e8
KK
652 "i1": {"static_routes": [{"network": BSR1_ADDR, "next_hop": next_hop_rp}]},
653 "l1": {"static_routes": [{"network": BSR1_ADDR, "next_hop": next_hop_lhr}]},
0b25370e
DS
654 "f1": {
655 "static_routes": [
656 {"network": CRP, "next_hop": next_hop_fhr, "delete": True}
657 ]
658 },
df94c7e8
KK
659 }
660
661 result = create_static_routes(tgen, input_dict)
662 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
663
664 # Use scapy to send pre-defined packet from senser to receiver
665
666 group = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet9"]["group"]
df94c7e8
KK
667 step("waiting for BSR to timeout before configuring blackhole route")
668 clear_bsrp_data(tgen, topo)
669
670 step("Configure black-hole address for BSR and candidate RP")
671 input_dict = {
672 "f1": {
673 "static_routes": [{"network": [BSR1_ADDR, CRP], "next_hop": "blackhole"}]
674 }
675 }
676
677 result = create_static_routes(tgen, input_dict)
678 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
679
680 intf_f1_i1 = topo["routers"]["f1"]["links"]["i1"]["interface"]
681 step("Verify bsm transit count is not increamented" "show ip pim interface traffic")
682 state_dict = {"f1": {intf_f1_i1: ["bsmTx"]}}
683
684 state_before = verify_pim_interface_traffic(tgen, state_dict)
685 assert isinstance(
686 state_before, dict
687 ), "Testcase{} : Failed \n state_before is not dictionary \n "
688 "Error: {}".format(tc_name, result)
689
690 step("Sending BSR after Configure black hole address for BSR and candidate RP")
691 step("Send BSR packet from b1 to FHR")
692 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet9")
693 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
694
695 dut = "l1"
696 step("Find the elected rp from bsrp-info in LHR l1")
697 rp = find_rp_from_bsrp_info(tgen, dut, BSR_IP_1, group)
698 assert rp is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
699
700 step("Verify if b1 chosen as BSR in l1")
701 result = verify_pim_bsr(tgen, topo, "l1", BSR_IP_1, expected=False)
0b25370e
DS
702 assert (
703 result is not True
704 ), "Testcase {} : Failed \n " "b1 is not chosen as BSR in l1 \n Error: {}".format(
5cbb02eb 705 tc_name, result
0b25370e 706 )
df94c7e8
KK
707
708 state_after = verify_pim_interface_traffic(tgen, state_dict)
709 assert isinstance(
710 state_after, dict
711 ), "Testcase{} : Failed \n state_before is not dictionary \n "
712 "Error: {}".format(tc_name, result)
713
714 result = verify_state_incremented(state_before, state_after)
715 assert result is not True, "Testcase{} : Failed Error: {}".format(tc_name, result)
716
717 step("Remove black-hole address for BSR and candidate RP")
718 input_dict = {
719 "f1": {
720 "static_routes": [
5900cf46 721 {"network": [BSR1_ADDR, CRP], "next_hop": "blackhole", "delete": True},
5980ad0a 722 {"network": BSR1_ADDR, "next_hop": NEXT_HOP1},
df94c7e8
KK
723 ]
724 }
725 }
726
727 result = create_static_routes(tgen, input_dict)
728 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
729
730 step("Sending BSR after removing black-hole address for BSR and candidate RP")
731 step("Send BSR packet from b1 to FHR")
732 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet9")
733 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
734
735 step("Verify if b1 chosen as BSR in f1")
736 result = verify_pim_bsr(tgen, topo, "f1", BSR_IP_1)
737 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
738
739 dut = "l1"
740 group = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet9"]["group"]
741 step("Find the elected rp from bsrp-info in LHR l1")
742 rp = find_rp_from_bsrp_info(tgen, dut, BSR_IP_1, group)
743 assert rp is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
744
745 step("Verify RP in LHR l1")
746 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp[group])
747 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
748
749 step("clear BSM database before moving to next case")
750 clear_bsrp_data(tgen, topo)
751
752 write_test_footer(tc_name)
753
754
755def test_new_router_fwd_p0(request):
756 """
757 1. Verify when new router added to the topology, FRR node will send
758 unicast BSM to new router
759 2. Verify if no forwarding bit is set , FRR is not forwarding the
760 BSM to other PIM nbrs
761 3. Verify multicast BSM is sent to new router when unicast BSM is disabled
762
763 Topology used:
764 b1_____
765 |
766 |
767 s1-----f1-----i1-----l1----r1
768 |
769 ______|
770 b2
771
772 b1 - BSR 1
773 b2 - BSR 2
774 s1 - Source
775 f1 - FHR
776 i1 - Intermediate Router (also RP)
777 r1 - Receiver
778
779 """
780
781 tgen = get_topogen()
782 tc_name = request.node.name
783 write_test_header(tc_name)
784
785 kill_iperf(tgen)
786 clear_ip_mroute(tgen)
787 reset_config_on_routers(tgen)
788 clear_ip_pim_interface_traffic(tgen, topo)
789
790 # Don"t run this test if we have any failure.
791 if tgen.routers_have_failure():
792 pytest.skip(tgen.errors)
793
794 reset_config_on_routers(tgen)
795
796 result = pre_config_to_bsm(
797 tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
798 )
799 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
800
801 result = pre_config_to_bsm(
802 tgen, topo, tc_name, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
803 )
804 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
805
806 GROUP_ADDRESS = "225.1.1.1"
807
808 # Use scapy to send pre-defined packet from senser to receiver
809 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet1")
810 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
811
812 bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
813 time.sleep(1)
814
815 result = iperfSendIGMPJoin(tgen, "r1", GROUP_ADDRESS, join_interval=1)
816 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
817
818 # Verify bsr state in FHR
819 step("Verify if b1 chosen as BSR in f1")
820 result = verify_pim_bsr(tgen, topo, "f1", bsr_ip)
821 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
822
823 # Verify bsr state in i1
824 step("Verify if b1 chosen as BSR in i1")
825 result = verify_pim_bsr(tgen, topo, "i1", bsr_ip)
826 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
827
828 # Verify ip mroute
829 iif = "l1-i1-eth0"
830 src_addr = "*"
831 oil = "l1-r1-eth1"
832
833 step("Verify mroute populated on l1")
834 result = verify_ip_mroutes(tgen, "l1", src_addr, GROUP_ADDRESS, iif, oil)
835 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
836
837 # Reload i1 and l1
838 step("Reloading i1 and l1. Stop both. bring up l1 and then i1")
839 stop_router(tgen, "i1")
840 start_router(tgen, "i1")
841 stop_router(tgen, "l1")
842 start_router(tgen, "l1")
843
844 # Verify bsr state in i1
845 step("Verify BSR in i1 after restart while no new bsm sent from b1")
846 result = verify_pim_bsr(tgen, topo, "i1", bsr_ip)
847 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
848
849 # Verify bsr state in l1
850 step("Verify no BSR in l1 as i1 would not forward the no-forward bsm")
851 result = verify_pim_bsr(tgen, topo, "l1", bsr_ip, expected=False)
0b25370e
DS
852 assert result is not True, (
853 "Testcase {} : Failed \n "
5cbb02eb 854 "BSR data is present after no-forward bsm also \n Error: {}".format(
0b25370e
DS
855 tc_name, result
856 )
857 )
df94c7e8
KK
858
859 # unconfigure unicast bsm on f1-i1-eth2
860 step("unconfigure unicast bsm on f1-i1-eth2, will forward with only mcast")
861 enable_disable_pim_unicast_bsm(tgen, "f1", "f1-i1-eth2", enable=False)
862
863 # Reboot i1 to check if still bsm received with multicast address
864 step("Reboot i1 to check if still bsm received with multicast address")
865 stop_router(tgen, "i1")
866 start_router(tgen, "i1")
867
868 result = iperfSendIGMPJoin(tgen, "r1", GROUP_ADDRESS, join_interval=1)
869 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
870
871 # Verify again if BSR is installed from bsm forwarded by f1
872 step("Verify again if BSR is installed from bsm forwarded by f1")
873 result = verify_pim_bsr(tgen, topo, "i1", bsr_ip)
874 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
875
876 # Use scapy to send pre-defined packet from senser to receiver
877 step("Send another BSM packet from b1 which will reach l1(LHR)")
878 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet2")
879 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
880 do_countdown(5)
881
882 # Verify ip mroute populated again
883 step("Verify mroute again on l1 (lhr)")
884 result = verify_ip_mroutes(tgen, "l1", src_addr, GROUP_ADDRESS, iif, oil)
885 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
886
887 step("clear BSM database before moving to next case")
888 clear_bsrp_data(tgen, topo)
889
890 write_test_footer(tc_name)
891
892
893def test_int_bsm_config_p1(request):
894 """
895 1. Verfiy BSM arrived on non bsm capable interface is dropped and
896 not processed
897 2. Verify group to RP info updated correctly in FRR node, after shut and
898 no-shut of BSM enable interfaces
899
900 Topology used:
901 b1_____
902 |
903 |
904 s1-----f1-----i1-----l1----r1
905 |
906 ______|
907 b2
908
909 b1 - BSR 1
910 b2 - BSR 2
911 s1 - Source
912 f1 - FHR
913 i1 - Intermediate Router (also RP)
914 r1 - Receiver
915
916 """
917
918 tgen = get_topogen()
919 tc_name = request.node.name
920 write_test_header(tc_name)
921
922 kill_iperf(tgen)
923 clear_ip_mroute(tgen)
924 reset_config_on_routers(tgen)
925 clear_ip_pim_interface_traffic(tgen, topo)
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 reset_config_on_routers(tgen)
932
933 result = pre_config_to_bsm(
934 tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
935 )
936 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
937
938 result = pre_config_to_bsm(
939 tgen, topo, tc_name, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
940 )
941 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
942
943 GROUP_ADDRESS = "225.1.1.1"
944
945 bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
946 time.sleep(1)
947
948 result = iperfSendIGMPJoin(tgen, "r1", GROUP_ADDRESS, join_interval=1)
949 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
950
951 # Use scapy to send pre-defined packet from senser to receiver
952 step("Send BSM packet from b1")
953 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet1")
954 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
955
956 # Verify bsr state in i1
957 step("Verify if b1 is chosen as BSR in i1")
958 result = verify_pim_bsr(tgen, topo, "i1", bsr_ip)
959 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
960
961 # check if mroute installed
962 step("check if mroute installed in i1")
963 iif = "lo"
964 src_addr = "*"
965 oil = "i1-l1-eth1"
966
967 result = verify_ip_mroutes(tgen, "i1", src_addr, GROUP_ADDRESS, iif, oil)
968 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
969
970 # wait till bsm rp age out
971 step("wait till bsm rp age out")
972 clear_bsrp_data(tgen, topo)
973
974 # check if mroute uninstalled because of rp age out
975 step("check if mroute uninstalled because of rp age out in i1")
976 result = verify_ip_mroutes(
977 tgen, "i1", src_addr, GROUP_ADDRESS, iif, oil, expected=False
978 )
0b25370e
DS
979 assert (
980 result is not True
981 ), "Testcase {} : Failed \n " "Mroutes are still present \n Error: {}".format(
5cbb02eb 982 tc_name, result
0b25370e 983 )
df94c7e8
KK
984
985 # unconfigure bsm processing on f1 on f1-i1-eth2
986 step("unconfigure bsm processing on f1 in f1-i1-eth2, will drop bsm")
987 result = enable_disable_pim_bsm(tgen, "f1", "f1-i1-eth2", enable=False)
988 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
989
990 # Use scapy to send pre-defined packet from senser to receiver
991 step("Send BSM packet from b1")
992 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet1")
993 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
994
995 # Verify bsr state in FHR
996 step("Verify if b1 chosen as BSR in f1")
997 result = verify_pim_bsr(tgen, topo, "f1", bsr_ip)
998 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
999
1000 # Verify bsr state in i1
1001 step("Verify if b1 is not chosen as BSR in i1")
1002 result = verify_pim_bsr(tgen, topo, "i1", bsr_ip, expected=False)
0b25370e
DS
1003 assert (
1004 result is not True
1005 ), "Testcase {} : Failed \n " "b1 is chosen as BSR in i1 \n Error: {}".format(
5cbb02eb 1006 tc_name, result
0b25370e 1007 )
df94c7e8
KK
1008
1009 # check if mroute still not installed because of rp not available
1010 step("check if mroute still not installed because of rp not available")
1011 result = verify_ip_mroutes(
1012 tgen, "i1", src_addr, GROUP_ADDRESS, iif, oil, expected=False
1013 )
0b25370e
DS
1014 assert result is not True, (
1015 "Testcase {} : Failed \n "
1016 "mroute installed but rp not available \n Error: {}".format(tc_name, result)
1017 )
df94c7e8
KK
1018
1019 # configure bsm processing on i1 on f1-i1-eth2
1020 step("configure bsm processing on f1 in f1-i1-eth2, will accept bsm")
1021 result = enable_disable_pim_bsm(tgen, "f1", "f1-i1-eth2", enable=True)
1022 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1023
1024 # Use scapy to send pre-defined packet from senser to receiver
1025 step("Send BSM packet again from b1")
1026 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet2")
1027 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1028
1029 # Verify again if BSR is installed from bsm forwarded by f1
1030 step("Verify again if BSR is installed from bsm forwarded by f1")
1031 result = verify_pim_bsr(tgen, topo, "i1", bsr_ip)
1032 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1033
1034 # verify ip mroute populated
1035 step("Verify ip mroute")
1036 result = verify_ip_mroutes(tgen, "i1", src_addr, GROUP_ADDRESS, iif, oil)
1037 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1038
1039 # Shut/No shut the bsm rpf interface and check mroute on lhr(l1)
1040 step("Shut/No shut the bsm rpf interface and check mroute on lhr(l1)")
1041 intf = "l1-i1-eth0"
1042 shutdown_bringup_interface(tgen, "l1", intf, False)
1043 shutdown_bringup_interface(tgen, "l1", intf, True)
1044
1045 iif = "l1-i1-eth0"
1046 oil = "l1-r1-eth1"
1047
1048 result = verify_ip_mroutes(tgen, "l1", src_addr, GROUP_ADDRESS, iif, oil)
1049 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1050
1051 step("clear BSM database before moving to next case")
1052 clear_bsrp_data(tgen, topo)
1053
1054 write_test_footer(tc_name)
1055
1056
1057def test_static_rp_override_p1(request):
1058 """
1059 Verify static RP is preferred over BSR
1060
1061 Topology used:
1062 b1_____
1063 |
1064 |
1065 s1-----f1-----i1-----l1----r1
1066 |
1067 ______|
1068 b2
1069
1070 b1 - BSR 1
1071 b2 - BSR 2
1072 s1 - Source
1073 f1 - FHR
1074 i1 - Intermediate Router (also RP)
1075 r1 - Receiver
1076
1077 """
1078
1079 tgen = get_topogen()
1080 tc_name = request.node.name
1081 write_test_header(tc_name)
1082
1083 kill_iperf(tgen)
1084 clear_ip_mroute(tgen)
1085 reset_config_on_routers(tgen)
1086 clear_ip_pim_interface_traffic(tgen, topo)
1087
1088 # Don"t run this test if we have any failure.
1089 if tgen.routers_have_failure():
1090 pytest.skip(tgen.errors)
1091
1092 reset_config_on_routers(tgen)
1093
1094 result = pre_config_to_bsm(
1095 tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
1096 )
1097 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1098
1099 result = pre_config_to_bsm(
1100 tgen, topo, tc_name, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
1101 )
1102 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1103
1104 GROUP_ADDRESS = "225.1.1.1"
1105 # Use scapy to send pre-defined packet from senser to receiver
1106 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet1")
1107 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1108
1109 bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
1110 time.sleep(1)
1111
1112 result = iperfSendIGMPJoin(tgen, "r1", GROUP_ADDRESS, join_interval=1)
1113 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1114
1115 # Verify bsr state in FHR
1116 result = verify_pim_bsr(tgen, topo, "f1", bsr_ip)
1117 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1118
1119 # Check igmp groups
1120 step("Verify IGMP groups in LHR")
1121 dut = "l1"
1122 intf = "l1-r1-eth1"
1123 result = verify_igmp_groups(tgen, dut, intf, GROUP_ADDRESS)
1124 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1125
1126 group = "225.1.1.1/32"
1127
1128 # Find the elected rp from bsrp-info
1129 step("Find the elected rp from bsrp-info in LHR l1")
1130 rp = find_rp_from_bsrp_info(tgen, dut, bsr_ip, group)
1131 assert rp is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1132
1133 # Check RP detail in LHR
1134 step("Verify that BS RP in LHR l1")
1135 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp[group])
1136 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1137
1138 iif = "l1-i1-eth0"
1139 # Verify upstream rpf for 225.1.1.1 is chosen as rp1
1140 step("Verify upstream rpf for 225.1.1.1 is chosen as bsrp")
1141 result = verify_ip_pim_upstream_rpf(tgen, topo, dut, iif, GROUP_ADDRESS, rp[group])
1142 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1143
1144 # Configure a static rp for the group 225.1.1.1/32
1145 step("Configure a static rp 33.33.33.33 for the group 225.1.1.1/32 in l1")
1146 input_dict = {
1147 "l1": {
1148 "pim": {
1149 "rp": [
5980ad0a
DS
1150 {
1151 "rp_addr": "33.33.33.33",
1152 "group_addr_range": ["225.1.1.1/32"],
1153 }
df94c7e8
KK
1154 ]
1155 }
1156 }
1157 }
1158 result = create_pim_config(tgen, topo, input_dict)
1159 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
1160
1161 # Verify that static rp is configured over bsrp
1162 static_rp = "33.33.33.33"
1163 step("Verify that Static RP in LHR in l1")
1164 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "Static", static_rp)
1165 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1166
1167 # Verify if upstream also reflects the static rp
1168 step("Verify upstream rpf for 225.1.1.1 is chosen as static in l1")
1169 result = verify_ip_pim_upstream_rpf(tgen, topo, dut, iif, GROUP_ADDRESS, static_rp)
1170 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1171
1172 # delete static rp for the group 225.1.1.1/32
1173 step("Delete static rp 33.33.33.33 for the group 225.1.1.1/32 in l1")
1174 input_dict = {
1175 "l1": {
1176 "pim": {
1177 "rp": [
1178 {
1179 "rp_addr": "33.33.33.33",
1180 "group_addr_range": ["225.1.1.1/32"],
1181 "delete": True,
1182 }
1183 ]
1184 }
1185 }
1186 }
1187 result = create_pim_config(tgen, topo, input_dict)
1188 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
1189
1190 # Verify if bsrp is installed back for the group 225.1.1.1/32
1191 step("Verify that BS RP in installed in LHR")
1192 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp[group])
1193 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1194
1195 # Verify upstream rpf for 225.1.1.1 is chosen as bsrp
1196 step("Verify upstream rpf for 225.1.1.1 is chosen as bsrp in l1")
1197 result = verify_ip_pim_upstream_rpf(tgen, topo, dut, iif, GROUP_ADDRESS, rp[group])
1198 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1199
1200 step("clear BSM database before moving to next case")
1201 clear_bsrp_data(tgen, topo)
1202
1203 write_test_footer(tc_name)
1204
1205
1206def test_bsmp_stress_add_del_restart_p2(request):
1207 """
1208 1. Verify adding/deleting the group to rp mapping and RP priority
1209 multiple times
1210 2. Verify RP and (*,G) detail after PIM process restart on FRR node
1211
1212 Topology used:
1213 b1_____
1214 |
1215 |
1216 s1-----f1-----i1-----l1----r1
1217 |
1218 ______|
1219 b2
1220
1221 b1 - BSR 1
1222 b2 - BSR 2
1223 s1 - Source
1224 f1 - FHR
1225 i1 - Intermediate Router (also RP)
1226 r1 - Receiver
1227
1228 """
1229
1230 tgen = get_topogen()
1231 tc_name = request.node.name
1232 write_test_header(tc_name)
1233
1234 kill_iperf(tgen)
1235 clear_ip_mroute(tgen)
1236 reset_config_on_routers(tgen)
1237 clear_ip_pim_interface_traffic(tgen, topo)
1238
1239 # Don"t run this test if we have any failure.
1240 if tgen.routers_have_failure():
1241 pytest.skip(tgen.errors)
1242
1243 reset_config_on_routers(tgen)
1244
1245 result = pre_config_to_bsm(
1246 tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
1247 )
1248 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1249
1250 result = pre_config_to_bsm(
1251 tgen, topo, tc_name, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
1252 )
1253 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1254
1255 GROUP_ADDRESS = "225.1.1.1"
1256
1257 # Use scapy to send pre-defined packet from senser to receiver
1258 step("Send BSR packet from b1 to FHR")
1259 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet1")
1260 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1261
1262 bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
1263 time.sleep(1)
1264
1265 result = iperfSendIGMPJoin(tgen, "r1", GROUP_ADDRESS, join_interval=1)
1266 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1267
1268 # Verify bsr state in FHR
1269 step("Verify if b1 is chosen as bsr in f1")
1270 result = verify_pim_bsr(tgen, topo, "f1", bsr_ip)
1271 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1272
1273 dut = "l1"
1274 group = "225.1.1.0/24"
1275 # Find the elected rp from bsrp-info
1276 step("Find the elected rp from bsrp-info in LHR l1")
1277 rp1 = find_rp_from_bsrp_info(tgen, dut, bsr_ip, group)
1278 assert rp1 is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1279
1280 # Check RP detail in LHR
1281 step("Verify RP in LHR l1")
1282 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp1[group])
1283 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1284
1285 # Send BSR packet from b1 after deleting high prio rp for 225.1.1.0/24
1286 step("Send BSM from b1 to FHR deleting high prio rp for 225.1.1.0/24")
1287 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet6")
1288 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1289
1290 # Find the elected rp from bsrp-info
1291 step("Find the elected rp from bsrp-info in LHR l1")
1292 rp2 = find_rp_from_bsrp_info(tgen, dut, bsr_ip, group)
1293 assert rp2 is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1294 logger.info("RP old: %s RP2 new: %s", rp1[group], rp2[group])
1295
1296 # Verify is the rp is different now
1297 assert rp1[group] != rp2[group], "Testcase {} :Failed \n Error {}".format(
1298 tc_name, result
1299 )
1300
1301 rp_add1 = rp1[group]
1302 rp_add2 = rp2[group]
1303
1304 # Verify if that rp is installed
1305 step("Verify new RP in LHR installed")
1306 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp_add2)
1307 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1308
1309 step("Change rp priority in the bsm and send multiple times")
1310
1311 for i in range(4):
1312 # Send BSR pkt from b1 after putting back high prio rp for 225.1.1.0/24
1313 step("Send BSM from b1 to FHR put back high prio rp for 225.1.1.0/24")
1314 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet1")
1315 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1316
1317 # Find the elected rp from bsrp-info
1318 step("Find the elected rp from bsrp-info in LHR")
1319 rp2 = find_rp_from_bsrp_info(tgen, dut, bsr_ip, group)
1320 assert rp2 is not {}, "Testcase {} :Failed \n Error : RP not Found".format(
1321 tc_name
1322 )
1323
1324 # Verify is the rp is different now
1325 step("Verify now old RP is elected again")
1326 assert (
1327 rp_add1 == rp2[group]
1328 ), "Testcase {} :Failed \n Error : rp expected {} rp received {}".format(
5980ad0a
DS
1329 tc_name,
1330 rp_add1,
df94c7e8
KK
1331 )
1332
1333 # Verify if that rp is installed
1334 step("Verify old RP in LHR installed")
1335 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp_add1)
1336 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1337
1338 # Send BSR packet from b1 after deleting high prio rp for 225.1.1.0/24
1339 step("Send BSM from b1 to FHR deleting high prio rp for 225.1.1.0/24")
1340 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet6")
1341 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1342
1343 # Verify if that rp is installed
1344 step("Verify new RP(rp2) in LHR installed")
1345 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp_add2)
1346 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1347
1348 # Restart pimd
1349 step("Restarting pimd in LHR")
1350 kill_router_daemons(tgen, "l1", ["pimd"])
1351 start_router_daemons(tgen, "l1", ["pimd"])
1352 logger.info("Restarting done")
1353
1354 # Verify if that rp is installed
1355 step("Verify old RP in LHR installed")
1356 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp_add2)
1357 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1358
1359 # Send IGMP join to LHR
1360 result = iperfSendIGMPJoin(tgen, "r1", GROUP_ADDRESS, join_interval=1)
1361 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1362
1363 do_countdown(5)
1364
1365 # VErify mroute created after pimd restart
1366 step("VErify mroute created after pimd restart")
1367 iif = "l1-i1-eth0"
1368 src_addr = "*"
1369 oil = "l1-r1-eth1"
1370 result = verify_ip_mroutes(tgen, "l1", src_addr, GROUP_ADDRESS, iif, oil)
1371 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
1372
1373 write_test_footer(tc_name)
1374
1375
1376def test_BSM_timeout_p0(request):
1377 """
1378 Verify BSM timeout on FRR1
1379 Verify RP state in FRR1 after Bootstrap timer expiry
1380
1381 Topology used:
1382 b1_____
1383 |
1384 |
1385 s1-----f1-----i1-----l1----r1
1386 |
1387 ______|
1388 b2
1389
1390 b1 - BSR 1
1391 b2 - BSR 2
1392 s1 - Source
1393 f1 - FHR
1394 i1 - Intermediate Router (also RP)
1395 r1 - Receiver
1396
1397 """
1398
1399 tgen = get_topogen()
1400 tc_name = request.node.name
1401 write_test_header(tc_name)
1402
1403 kill_iperf(tgen)
1404 clear_ip_mroute(tgen)
1405 reset_config_on_routers(tgen)
1406 clear_ip_pim_interface_traffic(tgen, topo)
1407
1408 # Don"t run this test if we have any failure.
1409 if tgen.routers_have_failure():
1410 pytest.skip(tgen.errors)
1411
1412 result = pre_config_to_bsm(
1413 tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
1414 )
1415 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1416
1417 result = pre_config_to_bsm(
1418 tgen, topo, tc_name, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
1419 )
1420 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1421
1422 GROUP_ADDRESS = "225.1.1.1"
1423
1424 bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
1425
1426 # Use scapy to send pre-defined packet from senser to receiver
1427 step("send BSR packet from b1")
1428 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet1")
1429 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1430
1431 # Send IGMP join for group 225.1.1.1 from receiver
1432 result = iperfSendIGMPJoin(tgen, "r1", GROUP_ADDRESS, join_interval=1)
1433 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1434
1435 # Verify bsr state in FHR
1436 step("Verify bsr state in FHR f1")
1437 result = verify_pim_bsr(tgen, topo, "f1", bsr_ip)
1438 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1439
1440 # Verify ip mroute in LHR
1441 step(" Verify ip mroute in LHR l1")
1442 dut = "l1"
1443 iif = "l1-i1-eth0"
1444 src_addr = "*"
1445 oil = "l1-r1-eth1"
1446 result = verify_ip_mroutes(tgen, dut, src_addr, GROUP_ADDRESS, iif, oil)
1447 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1448
1449 # Verify join state and join timer
1450 step("Verify join state and join timer in lhr l1")
1451 result = verify_join_state_and_timer(tgen, dut, iif, src_addr, GROUP_ADDRESS)
1452 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1453
1454 # Verify upstream IIF interface
1455 step("Verify upstream IIF interface in LHR l1")
1456 result = verify_upstream_iif(tgen, dut, iif, src_addr, GROUP_ADDRESS)
1457 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1458
1459 # Verify RP mapping
1460 dut = "l1"
1461 group = "225.1.1.1/32"
1462 step("Verify RP mapping in LHR l1")
1463 rp = find_rp_from_bsrp_info(tgen, dut, bsr_ip, group)
1464 assert rp != {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1465
1466 logger.info("Waiting for 130 secs to check BSR timeout")
1467 clear_bsrp_data(tgen, topo)
1468
1469 # Verify if bsr has aged out
1470 step("Verify if bsr has aged out in f1")
1471 no_bsr_ip = "0.0.0.0"
1472 result = verify_pim_bsr(tgen, topo, "f1", no_bsr_ip)
1473 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1474
1475 result = verify_pim_grp_rp_source(
1476 tgen, topo, "f1", group, rp_source="BSR", expected=False
1477 )
1478
0b25370e
DS
1479 assert (
1480 result is not True
1481 ), "Testcase {} : Failed \n " "bsr has not aged out in f1 \n Error: {}".format(
5cbb02eb 1482 tc_name, result
0b25370e 1483 )
df94c7e8
KK
1484
1485 # Verify RP mapping removed after hold timer expires
1486 group = "225.1.1.1/32"
1487 step("Verify RP mapping removed after hold timer expires in l1")
1488 rp = find_rp_from_bsrp_info(tgen, dut, bsr_ip, group)
1489 assert rp == {}, "Testcase {} :Failed \n Error : RP found when not expected".format(
1490 tc_name
1491 )
1492
1493 # Verify iif is unknown after RP timeout
1494 step("Verify iif is unknown after RP timeout in l1")
1495 iif = "Unknown"
1496 result = verify_upstream_iif(
1497 tgen, dut, iif, src_addr, GROUP_ADDRESS, joinState="NotJoined"
1498 )
1499 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1500
1501 # Verify join state and join timer
1502 step("Verify join state and join timer in l1")
1503 iif = "l1-i1-eth0"
1504 result = verify_join_state_and_timer(
1505 tgen, dut, iif, src_addr, GROUP_ADDRESS, expected=False
1506 )
0b25370e
DS
1507 assert result is not True, (
1508 "Testcase {} : Failed \n "
5cbb02eb 1509 "join state is up and join timer is running in l1 \n Error: {}".format(
0b25370e
DS
1510 tc_name, result
1511 )
1512 )
df94c7e8
KK
1513
1514 # Verify ip mroute is not installed
1515 step("Verify mroute not installed in l1")
1516 result = verify_ip_mroutes(
1517 tgen, dut, src_addr, GROUP_ADDRESS, iif, oil, expected=False
1518 )
0b25370e
DS
1519 assert (
1520 result is not True
1521 ), "Testcase {} : Failed \n " "mroute installed in l1 \n Error: {}".format(
5cbb02eb 1522 tc_name, result
0b25370e 1523 )
df94c7e8
KK
1524
1525 step("clear BSM database before moving to next case")
1526 clear_bsrp_data(tgen, topo)
1527
1528 write_test_footer(tc_name)
1529
1530
1531def test_iif_join_state_p0(request):
1532 """
1533 1. Verify upstream interfaces(IIF) and join state are updated properly
1534 after BSM received for FRR
1535 2. Verify IIF and OIL in "show ip pim state" updated properly after
1536 BSM received
1537
1538 Topology used:
1539 b1_____
1540 |
1541 |
1542 s1-----f1-----i1-----l1----r1
1543 |
1544 ______|
1545 b2
1546
1547 b1 - BSR 1
1548 b2 - BSR 2
1549 s1 - Source
1550 f1 - FHR
1551 i1 - Intermediate Router (also RP)
1552 r1 - Receiver
1553
1554 """
1555
1556 tgen = get_topogen()
1557 tc_name = request.node.name
1558 write_test_header(tc_name)
1559
1560 kill_iperf(tgen)
1561 clear_ip_mroute(tgen)
1562 reset_config_on_routers(tgen)
1563 clear_ip_pim_interface_traffic(tgen, topo)
1564
1565 # Don"t run this test if we have any failure.
1566 if tgen.routers_have_failure():
1567 pytest.skip(tgen.errors)
1568
1569 reset_config_on_routers(tgen)
1570
1571 result = pre_config_to_bsm(
1572 tgen, topo, tc_name, "b1", "s1", "r1", "f1", "i1", "l1", "packet1"
1573 )
1574 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1575
1576 result = pre_config_to_bsm(
1577 tgen, topo, tc_name, "b2", "s1", "r1", "f1", "i1", "l1", "packet1"
1578 )
1579 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1580
1581 GROUP_ADDRESS = "225.1.1.1"
1582
1583 # Use scapy to send pre-defined packet from senser to receiver
1584 result = scapy_send_bsr_raw_packet(tgen, topo, "b1", "f1", "packet1")
1585 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1586
1587 bsr_ip = topo["routers"]["b1"]["bsm"]["bsr_packets"]["packet1"]["bsr"].split("/")[0]
1588 time.sleep(1)
1589
1590 result = iperfSendIGMPJoin(tgen, "r1", GROUP_ADDRESS, join_interval=1)
1591 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1592
1593 # Verify bsr state in FHR
1594 result = verify_pim_bsr(tgen, topo, "f1", bsr_ip)
1595 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1596
1597 # Check igmp groups
1598 step("Verify IGMP groups in LHR l1")
1599 dut = "l1"
1600 intf = "l1-r1-eth1"
1601 result = verify_igmp_groups(tgen, dut, intf, GROUP_ADDRESS)
1602 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1603
1604 group = "225.1.1.1/32"
1605
1606 # Find the elected rp from bsrp-info
1607 step("Find the elected rp from bsrp-info in LHR l1")
1608 rp = find_rp_from_bsrp_info(tgen, dut, bsr_ip, group)
1609 assert rp is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1610
1611 # Check RP detail in LHR
1612 step("Verify RP in LHR l1")
1613 result = verify_pim_grp_rp_source(tgen, topo, dut, group, "BSR", rp[group])
1614 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1615
1616 # Verify join state and join timer
1617 step("Verify join state and join timer l1")
1618 iif = "l1-i1-eth0"
1619 src_addr = "*"
1620 result = verify_join_state_and_timer(tgen, dut, iif, src_addr, GROUP_ADDRESS)
1621 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1622
1623 # Verify upstream IIF interface
1624 step("Verify upstream IIF interface l1")
1625 result = verify_upstream_iif(tgen, dut, iif, src_addr, GROUP_ADDRESS)
1626 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1627
1628 # Verify IIF/OIL in pim state
1629 oil = "l1-r1-eth1"
1630 result = verify_pim_state(tgen, dut, iif, oil, GROUP_ADDRESS)
1631 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1632
1633 # Verify ip mroute
1634 src_addr = "*"
1635 step("Verify ip mroute in l1")
1636 result = verify_ip_mroutes(tgen, dut, src_addr, GROUP_ADDRESS, iif, oil)
1637 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1638
1639 # Make RP unreachanble in LHR
1640 step("Make RP unreachanble in LHR l1")
1641 rp = find_rp_from_bsrp_info(tgen, dut, bsr_ip, group)
1642 assert rp is not {}, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1643
1644 next_hop_lhr = topo["routers"]["i1"]["links"]["l1"]["ipv4"].split("/")[0]
1645
1646 rp_ip = rp[group] + "/32"
1647 input_dict = {
1648 "l1": {
1649 "static_routes": [
1650 {"network": rp_ip, "next_hop": next_hop_lhr, "delete": True}
1651 ]
1652 }
1653 }
1654 result = create_static_routes(tgen, input_dict)
1655 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1656
1657 # Check RP unreachable
1658 step("Check RP unreachability")
1659 iif = "Unknown"
1660 result = verify_upstream_iif(
1661 tgen, dut, iif, src_addr, GROUP_ADDRESS, joinState="NotJoined"
1662 )
1663 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1664
1665 # Verify that it is not installed
1666 step("Verify that it is not installed")
1667 iif = "<iif?>"
1668 result = verify_pim_state(tgen, dut, iif, oil, GROUP_ADDRESS, installed_fl=0)
1669 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1670
1671 # Verify mroute not installed
1672 step("Verify mroute not installed")
1673 result = verify_ip_mroutes(
1674 tgen, dut, src_addr, GROUP_ADDRESS, iif, oil, expected=False
1675 )
0b25370e
DS
1676 assert (
1677 result is not True
1678 ), "Testcase {} : Failed \n " "mroute installed in l1 \n Error: {}".format(
5cbb02eb 1679 tc_name, result
0b25370e 1680 )
df94c7e8
KK
1681
1682 # Add back route for RP to make it reachable
1683 step("Add back route for RP to make it reachable")
1684 input_dict = {
5980ad0a
DS
1685 "l1": {
1686 "static_routes": [
1687 {
1688 "network": rp_ip,
1689 "next_hop": next_hop_lhr,
1690 }
1691 ]
1692 }
df94c7e8
KK
1693 }
1694 result = create_static_routes(tgen, input_dict)
1695 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1696
1697 # Verify that (*,G) installed in mroute again
1698 iif = "l1-i1-eth0"
1699 result = verify_ip_mroutes(tgen, dut, src_addr, GROUP_ADDRESS, iif, oil)
1700 assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)
1701
1702 step("clear BSM database before moving to next case")
1703 clear_bsrp_data(tgen, topo)
1704
1705 write_test_footer(tc_name)
1706
1707
1708if __name__ == "__main__":
1709 args = ["-s"] + sys.argv[1:]
1710 sys.exit(pytest.main(args))