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