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