]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ebgp_unnumbered_nbr.py
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / tests / topotests / bgp_ipv4_over_ipv6 / test_rfc5549_ebgp_unnumbered_nbr.py
CommitLineData
9e3bab5f 1#!/usr/bin/env python
acddc0ed 2# SPDX-License-Identifier: ISC
9e3bab5f 3
4#
5# Copyright (c) 2021 by VMware, Inc. ("VMware")
6# Used Copyright (c) 2018 by Network Device Education Foundation, Inc.
7# ("NetDEF") in this file.
8#
9e3bab5f 9
10
11"""RFC5549 Automation."""
12import os
13import sys
14import time
9e3bab5f 15import pytest
bc6d1b15
P
16import functools
17import json
9e3bab5f 18
19# Save the Current Working Directory to find configuration files.
20CWD = os.path.dirname(os.path.realpath(__file__))
21sys.path.append(os.path.join(CWD, "../"))
22sys.path.append(os.path.join(CWD, "../../"))
23
bc6d1b15
P
24
25from lib import topotest
26from lib.topogen import Topogen, TopoRouter, get_topogen
9e3bab5f 27
28from lib.common_config import (
29 write_test_header,
30 start_topology,
9e3bab5f 31 write_test_footer,
32 start_router,
33 stop_router,
34 verify_rib,
35 create_static_routes,
36 check_address_types,
37 reset_config_on_routers,
38 step,
9e3bab5f 39 get_frr_ipv6_linklocal,
40)
41from lib.topolog import logger
4953ca97 42from lib.bgp import create_router_bgp, verify_bgp_convergence, verify_bgp_rib
9e3bab5f 43
4953ca97 44from lib.topojson import build_config_from_json
9e3bab5f 45
cbdecd68
DS
46pytestmark = [pytest.mark.bgpd, pytest.mark.staticd]
47
9e3bab5f 48# Global variables
49topo = None
9e3bab5f 50
51# Global variables
52NO_OF_RTES = 2
53NETWORK_CMD_IP = "1.0.1.17/32"
54NETWORK = {
55 "ipv4": [
56 "11.0.20.1/32",
57 "11.0.20.2/32",
58 "11.0.20.3/32",
59 "11.0.20.4/32",
60 "11.0.20.5/32",
61 ],
62 "ipv6": ["1::1/128", "1::2/128", "1::3/128", "1::4/128", "1::5/128"],
63}
64MASK = {"ipv4": "32", "ipv6": "128"}
65NEXT_HOP = {
66 "ipv4": ["10.0.0.1", "10.0.1.1", "10.0.2.1", "10.0.3.1", "10.0.4.1"],
67 "ipv6": ["Null0", "Null0", "Null0", "Null0", "Null0"],
68}
69INTF_LIST = [
70 "r2-link0",
71 "r2-link1",
72 "r2-link2",
73 "r2-link3",
74 "r2-link4",
75 "r2-link5",
76 "r2-link6",
77 "r2-link7",
78]
79ADDR_TYPES = check_address_types()
80TOPOOLOGY = """
81 Please view in a fixed-width font such as Courier.
82
83 +----+
84 | R4 |
85 | |
86 +--+-+
87 | ipv4 nbr
88 no bgp ebgp/ibgp |
89 | ebgp/ibgp
90 +----+ 5links +----+ 8links +--+-+ +----+
91 |R0 +----------+ R1 +------------+ R2 | ipv6 nbr |R3 |
92 | +----------+ +------------+ +-------------+ |
93 +----+ +----+ ipv6 nbr +----+ +----+
94"""
95
96TESTCASES = """
971. Verify IPv4 routes are advertised when IPv6 EBGP loopback session
98 established using Unnumbered interface
992. Verify IPv4 routes are installed with correct nexthop after
100shut / no shut of nexthop and BGP peer interfaces
1013. Verify IPv4 routes are intact after stop and start the FRR services
102 """
103
104
9e3bab5f 105def setup_module(mod):
106 """Set up the pytest environment."""
107 global topo, ADDR_TYPES
108
109 testsuite_run_time = time.asctime(time.localtime(time.time()))
110 logger.info("Testsuite start time: {}".format(testsuite_run_time))
111 logger.info("=" * 40)
112
113 logger.info("Running setup_module to create topology")
114
115 # This function initiates the topology build with Topogen...
e82b531d
CH
116 json_file = "{}/rfc5549_ebgp_unnumbered_nbr.json".format(CWD)
117 tgen = Topogen(json_file, mod.__name__)
118 global topo
119 topo = tgen.json_topo
9e3bab5f 120
121 # Starting topology, create tmp files which are loaded to routers
d60a3f0e 122 # to start daemons and then start routers
9e3bab5f 123 start_topology(tgen)
124
125 # Creating configuration from JSON
126 build_config_from_json(tgen, topo)
127 # Don't run this test if we have any failure.
128 if tgen.routers_have_failure():
129 pytest.skip(tgen.errors)
130
131 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
132 assert BGP_CONVERGENCE is True, "setup_module :Failed \n Error:" " {}".format(
133 BGP_CONVERGENCE
134 )
135 logger.info("Running setup_module() done")
136
137
138def teardown_module():
139 """Teardown the pytest environment."""
140 logger.info("Running teardown_module to delete topology")
141
142 tgen = get_topogen()
143
144 # Stop toplogy and Remove tmp files
145 tgen.stop_topology()
146
147
148def get_llip(onrouter, intf):
149 """
dea6dce3 150 API to get the link local ipv6 address of a particular interface
9e3bab5f 151
152 Parameters
153 ----------
154 * `fromnode`: Source node
155 * `tonode` : interface for which link local ip needs to be returned.
156
157 Usage
158 -----
159 result = get_llip('r1', 'r2-link0')
160
161 Returns
162 -------
163 1) link local ipv6 address from the interface.
164 2) errormsg - when link local ip not found.
165 """
166 tgen = get_topogen()
167 intf = topo["routers"][onrouter]["links"][intf]["interface"]
168 llip = get_frr_ipv6_linklocal(tgen, onrouter, intf)
169 if llip:
170 logger.info("llip ipv6 address to be set as NH is %s", llip)
171 return llip
172 return None
173
174
175def get_glipv6(onrouter, intf):
176 """
dea6dce3 177 API to get the global ipv6 address of a particular interface
9e3bab5f 178
179 Parameters
180 ----------
181 * `onrouter`: Source node
182 * `intf` : interface for which link local ip needs to be returned.
183
184 Usage
185 -----
186 result = get_glipv6('r1', 'r2-link0')
187
188 Returns
189 -------
190 1) global ipv6 address from the interface.
191 2) errormsg - when link local ip not found.
192 """
193 glipv6 = (topo["routers"][onrouter]["links"][intf]["ipv6"]).split("/")[0]
194 if glipv6:
195 logger.info("Global ipv6 address to be set as NH is %s", glipv6)
196 return glipv6
197 return None
198
199
200# ##################################
201# Test cases start here.
202# ##################################
203
204
205def test_unnumbered_loopback_ebgp_nbr_p0(request):
206 """
207
208 Test extended capability nexthop with un numbered ebgp.
209
210 Verify IPv4 routes are advertised when IPv6 EBGP loopback
211 session established using Unnumbered interface
212 """
213 tc_name = request.node.name
214 write_test_header(tc_name)
215 tgen = get_topogen()
216 # Don't run this test if we have any failure.
217 if tgen.routers_have_failure():
218 pytest.skip(tgen.errors)
219 reset_config_on_routers(tgen)
220
221 step("Configure IPv6 EBGP Unnumbered session between R1 and R2")
222 step("Enable capability extended-nexthop on both the IPv6 BGP peers")
223 step("Activate same IPv6 nbr from IPv4 unicast family")
224 step("Enable cap ext nh on r1 and r2 and activate in ipv4 addr family")
225 step("Verify bgp convergence as ipv6 nbr is enabled on ipv4 addr family.")
226
227 bgp_convergence = verify_bgp_convergence(tgen, topo)
228 assert bgp_convergence is True, "Testcase {} :Failed \n Error: {}".format(
229 tc_name, bgp_convergence
230 )
231
232 step(" Configure 5 IPv4 static" " routes on R1, Nexthop as different links of R0")
233 for rte in range(0, NO_OF_RTES):
234 # Create Static routes
235 input_dict = {
236 "r1": {
237 "static_routes": [
238 {
239 "network": NETWORK["ipv4"][rte],
240 "no_of_ip": 1,
241 "next_hop": NEXT_HOP["ipv4"][rte],
242 }
243 ]
244 }
245 }
246 result = create_static_routes(tgen, input_dict)
247 assert result is True, "Testcase {} : Failed \n Error: {}".format(
248 tc_name, result
249 )
250
251 step(
252 "Advertise static routes from IPv4 unicast family and IPv6 "
253 "unicast family respectively from R1 using red static cmd "
254 "Advertise loopback from IPv4 unicast family using network command "
255 "from R1"
256 )
257
258 configure_bgp_on_r1 = {
259 "r1": {
260 "bgp": {
261 "address_family": {
262 "ipv4": {
263 "unicast": {
264 "redistribute": [{"redist_type": "static"}],
265 "advertise_networks": [
266 {"network": NETWORK_CMD_IP, "no_of_network": 1}
267 ],
268 }
269 },
270 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
271 }
272 }
273 }
274 }
275 result = create_router_bgp(tgen, topo, configure_bgp_on_r1)
276 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
277 step(
278 "IPv4 routes advertised using static and network command are "
279 " received on R2 BGP and routing table , "
280 "verify using show ip bgp, show ip route for IPv4 routes ."
281 )
9e3bab5f 282 llip = get_llip("r1", "r2-link0")
283 assert llip is not None, "Testcase {} : Failed \n Error: {}".format(tc_name, llip)
284
285 dut = "r2"
286 protocol = "bgp"
287 for rte in range(0, NO_OF_RTES):
288 # verify the routes with nh as ext_nh
289 verify_nh_for_static_rtes = {
290 "r1": {
291 "static_routes": [
292 {"network": NETWORK["ipv4"][rte], "no_of_ip": 1, "next_hop": llip}
293 ]
294 }
295 }
296 """ interface_list = ['r1-link0','r1-link1']
297 nh_list =[]
298 for i in range(NO_OF_RTES):
299 nh_list.append(topo['routers']['r2']['links'][i][
300 'interface']) """
301 bgp_rib = verify_rib(
302 tgen,
303 "ipv4",
304 dut,
305 # verify_nh_for_static_rtes, next_hop='r2-r1-eth0')
306 verify_nh_for_static_rtes,
307 next_hop=llip,
308 )
309 assert bgp_rib is True, "Testcase {} : Failed \n Error: {}".format(
310 tc_name, bgp_rib
311 )
312 result = verify_rib(
313 tgen,
314 "ipv4",
315 dut,
316 verify_nh_for_static_rtes,
317 next_hop=llip,
318 protocol=protocol,
319 )
320 assert result is True, "Testcase {} : Failed \n Error: {}".format(
321 tc_name, result
322 )
323
324 # verify the routes with nh as ext_nh
325 verify_nh_for_nw_rtes = {
326 "r1": {
327 "static_routes": [
328 {"network": NETWORK_CMD_IP, "no_of_ip": 1, "next_hop": llip}
329 ]
330 }
331 }
332
333 bgp_rib = verify_rib(
334 tgen,
335 "ipv4",
336 dut,
337 # verify_nh_for_nw_rtes, next_hop='r2-r1-eth0')
338 verify_nh_for_nw_rtes,
339 next_hop=llip,
340 )
341 assert bgp_rib is True, "Testcase {} : Failed \n Error: {}".format(tc_name, bgp_rib)
342 result = verify_rib(
343 tgen, "ipv4", dut, verify_nh_for_nw_rtes, next_hop=llip, protocol=protocol
344 )
345 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
346 # stop/start -> restart FRR router and verify
347 stop_router(tgen, "r1")
348 stop_router(tgen, "r2")
349 start_router(tgen, "r1")
350 start_router(tgen, "r2")
351 step(
352 "After stop/start of FRR services , verify session up and routes "
353 "came up fine ,nh is proper using show bgp & show ipv6 route on R2 "
354 )
355 bgp_convergence = verify_bgp_convergence(tgen, topo)
356 assert bgp_convergence is True, "Testcase {} :Failed \n Error: {}".format(
357 tc_name, bgp_convergence
358 )
359
360 llip = get_llip("r1", "r2-link0")
361 assert llip is not None, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
362
363 # verify the routes with nh as ext_nh
364 verify_nh_for_static_rtes = {
365 "r1": {
366 "static_routes": [
367 {
368 "network": NETWORK["ipv4"][0],
369 "no_of_ip": NO_OF_RTES,
370 "next_hop": llip,
371 }
372 ]
373 }
374 }
375 bgp_rib = verify_bgp_rib(
376 tgen,
377 "ipv4",
378 dut,
379 # verify_nh_for_static_rtes, next_hop='r2-r1-eth0')
380 verify_nh_for_static_rtes,
381 next_hop=llip,
382 )
383 assert bgp_rib is True, "Testcase {} : Failed \n Error: {}".format(tc_name, bgp_rib)
384 result = verify_rib(
385 tgen, "ipv4", dut, verify_nh_for_static_rtes, next_hop=llip, protocol=protocol
386 )
387 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
388
389 verify_nh_for_nw_rtes = {
390 "r1": {
391 "static_routes": [
392 {"network": NETWORK_CMD_IP, "no_of_ip": 1, "next_hop": llip}
393 ]
394 }
395 }
396 bgp_rib = verify_rib(
397 tgen,
398 "ipv4",
399 dut,
400 # verify_nh_for_nw_rtes, next_hop='r2-r1-eth0')
401 verify_nh_for_nw_rtes,
402 next_hop=llip,
403 )
404 assert bgp_rib is True, "Testcase {} : Failed \n Error: {}".format(tc_name, bgp_rib)
405 result = verify_rib(
406 tgen, "ipv4", dut, verify_nh_for_nw_rtes, next_hop=llip, protocol=protocol
407 )
408 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
409 write_test_footer(tc_name)
410
411
412def test_restart_frr_p2(request):
413 """
414
415 Test extended capability nexthop , restart frr.
416
417 Verify IPv4 routes are intact after stop and start the FRR services
418 """
419 tc_name = request.node.name
420 write_test_header(tc_name)
421 tgen = get_topogen()
422 # Don't run this test if we have any failure.
423 if tgen.routers_have_failure():
424 pytest.skip(tgen.errors)
425 reset_config_on_routers(tgen)
426 step("Configure IPv6 EBGP Unnumbered session between R1 and R2")
427 step("Enable capability extended-nexthop on both the IPv6 BGP peers")
428 step("Activate same IPv6 nbr from IPv4 unicast family")
429 step("Enable cap ext nh on r1 and r2 and activate in ipv4 addr family")
430 step("Verify bgp convergence as ipv6 nbr is enabled on ipv4 addr family.")
9e3bab5f 431 bgp_convergence = verify_bgp_convergence(tgen, topo)
432 assert bgp_convergence is True, "Testcase {} :Failed \n Error: {}".format(
433 tc_name, bgp_convergence
434 )
435
436 step(" Configure 5 IPv4 static" " routes on R1, Nexthop as different links of R0")
437 for rte in range(0, NO_OF_RTES):
438 # Create Static routes
439 input_dict = {
440 "r1": {
441 "static_routes": [
442 {
443 "network": NETWORK["ipv4"][rte],
444 "no_of_ip": 1,
445 "next_hop": NEXT_HOP["ipv4"][rte],
446 }
447 ]
448 }
449 }
450 result = create_static_routes(tgen, input_dict)
451 assert result is True, "Testcase {} : Failed \n Error: {}".format(
452 tc_name, result
453 )
454
455 step(
456 "Advertise static routes from IPv4 unicast family and IPv6 "
457 "unicast family respectively from R1 using red static cmd "
458 "Advertise loopback from IPv4 unicast family using network command "
459 "from R1"
460 )
461
462 configure_bgp_on_r1 = {
463 "r1": {
464 "bgp": {
465 "address_family": {
466 "ipv4": {
467 "unicast": {
468 "redistribute": [{"redist_type": "static"}],
469 "advertise_networks": [
470 {"network": NETWORK_CMD_IP, "no_of_network": 1}
471 ],
472 }
473 },
474 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
475 }
476 }
477 }
478 }
479 result = create_router_bgp(tgen, topo, configure_bgp_on_r1)
480 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
481 step(
482 "IPv4 routes advertised using static and network command are "
483 " received on R2 BGP and routing table , "
484 "verify using show ip bgp, show ip route for IPv4 routes ."
485 )
486
487 llip = get_llip("r1", "r2-link0")
488 assert llip is not None, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
489
490 dut = "r2"
491 protocol = "bgp"
492 verify_nh_for_static_rtes = {
493 "r1": {
494 "static_routes": [
495 {
496 "network": NETWORK["ipv4"][0],
497 "no_of_ip": NO_OF_RTES,
498 "next_hop": llip,
499 }
500 ]
501 }
502 }
503 bgp_rib = verify_rib(tgen, "ipv4", dut, verify_nh_for_static_rtes, next_hop=llip)
504 assert bgp_rib is True, "Testcase {} : Failed \n Error: {}".format(tc_name, bgp_rib)
505 result = verify_rib(
506 tgen, "ipv4", dut, verify_nh_for_static_rtes, next_hop=llip, protocol=protocol
507 )
508 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
509
510 verify_nh_for_nw_rtes = {
511 "r1": {
512 "static_routes": [
513 {"network": NETWORK_CMD_IP, "no_of_ip": 1, "next_hop": llip}
514 ]
515 }
516 }
517
518 bgp_rib = verify_rib(tgen, "ipv4", dut, verify_nh_for_nw_rtes, next_hop=llip)
519 assert bgp_rib is True, "Testcase {} : Failed \n Error: {}".format(tc_name, bgp_rib)
520 result = verify_rib(
521 tgen, "ipv4", dut, verify_nh_for_nw_rtes, next_hop=llip, protocol=protocol
522 )
523 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
524
525 # stop/start -> restart FRR router and verify
526 stop_router(tgen, "r1")
527 stop_router(tgen, "r2")
528 start_router(tgen, "r1")
529 start_router(tgen, "r2")
530
531 step(
532 "After stop/start of FRR services , verify session up and routes "
533 "came up fine ,nh is proper using show bgp & show ipv6 route on R2 "
534 )
535 bgp_convergence = verify_bgp_convergence(tgen, topo)
536 assert bgp_convergence is True, "Testcase {} :Failed \n Error: {}".format(
537 tc_name, bgp_convergence
538 )
539
540 llip = get_llip("r1", "r2-link0")
541 assert llip is not None, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
542
543 # verify the routes with nh as ext_nh
544 verify_nh_for_static_rtes = {
545 "r1": {
546 "static_routes": [
547 {"network": NETWORK["ipv4"][0], "no_of_ip": 1, "next_hop": llip}
548 ]
549 }
550 }
551 bgp_rib = verify_rib(tgen, "ipv4", dut, verify_nh_for_static_rtes, next_hop=llip)
552 assert bgp_rib is True, "Testcase {} : Failed \n Error: {}".format(tc_name, bgp_rib)
553 result = verify_rib(
554 tgen, "ipv4", dut, verify_nh_for_static_rtes, next_hop=llip, protocol=protocol
555 )
556 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
557
558 # verify the routes with nh as ext_nh
559 verify_nh_for_nw_rtes = {
560 "r1": {
561 "static_routes": [
562 {"network": NETWORK_CMD_IP, "no_of_ip": 1, "next_hop": llip}
563 ]
564 }
565 }
566 bgp_rib = verify_rib(tgen, "ipv4", dut, verify_nh_for_nw_rtes, next_hop=llip)
567 assert bgp_rib is True, "Testcase {} : Failed \n Error: {}".format(tc_name, bgp_rib)
568 result = verify_rib(
569 tgen, "ipv4", dut, verify_nh_for_nw_rtes, next_hop=llip, protocol=protocol
570 )
571 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
572 write_test_footer(tc_name)
573
574
bc6d1b15
P
575def test_configure_gua_on_unnumbered_intf(request):
576 """
577 Configure a global V6 address on an unnumbered interface on R1
578
579 """
580 tc_name = request.node.name
581 write_test_header(tc_name)
582 tgen = get_topogen()
583 # Don't run this test if we have any failure.
584 if tgen.routers_have_failure():
585 pytest.skip(tgen.errors)
586 reset_config_on_routers(tgen)
587
588 step("Configure IPv6 EBGP Unnumbered session between R1 and R2")
589 step("Enable capability extended-nexthop on both the IPv6 BGP peers")
590 step("Activate same IPv6 nbr from IPv4 unicast family")
591 step("Enable cap ext nh on r1 and r2 and activate in ipv4 addr family")
592 step("Verify bgp convergence as ipv6 nbr is enabled on ipv4 addr family.")
593 bgp_convergence = verify_bgp_convergence(tgen, topo)
594 assert bgp_convergence is True, "Testcase {} :Failed \n Error: {}".format(
595 tc_name, bgp_convergence
596 )
597
598 step(" Configure 5 IPv4 static" " routes on R1, Nexthop as different links of R0")
599 for rte in range(0, NO_OF_RTES):
600 # Create Static routes
601 input_dict = {
602 "r1": {
603 "static_routes": [
604 {
605 "network": NETWORK["ipv4"][rte],
606 "no_of_ip": 1,
607 "next_hop": NEXT_HOP["ipv4"][rte],
608 }
609 ]
610 }
611 }
612 result = create_static_routes(tgen, input_dict)
613 assert result is True, "Testcase {} : Failed \n Error: {}".format(
614 tc_name, result
615 )
616
617 step(
618 "Advertise static routes from IPv4 unicast family and IPv6 "
619 "unicast family respectively from R1 using red static cmd "
620 "Advertise loopback from IPv4 unicast family using network command "
621 "from R1"
622 )
623
624 configure_bgp_on_r1 = {
625 "r1": {
626 "bgp": {
627 "address_family": {
628 "ipv4": {
629 "unicast": {
630 "redistribute": [{"redist_type": "static"}],
631 "advertise_networks": [
632 {"network": NETWORK_CMD_IP, "no_of_network": 1}
633 ],
634 }
635 },
636 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
637 }
638 }
639 }
640 }
641 result = create_router_bgp(tgen, topo, configure_bgp_on_r1)
642 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
643
644 r2 = tgen.gears["r2"]
645
646 def bgp_prefix_received_gua_nh(router):
647 output = json.loads(router.vtysh_cmd("show bgp ipv4 unicast 11.0.20.1/32 json"))
648 expected = {
649 "prefix": "11.0.20.1/32",
650 "paths": [
651 {
652 "nexthops": [
653 {
654 "ip": "5001:dead:beef::1",
655 "hostname": "r1",
656 "afi": "ipv6",
657 "scope": "global",
658 }
659 ]
660 }
661 ],
662 }
663 return topotest.json_cmp(output, expected)
664
665 def bgp_prefix_received_v4_mapped_v6_nh(router):
666 output = json.loads(router.vtysh_cmd("show bgp ipv4 unicast 11.0.20.1/32 json"))
667 expected = {
668 "prefix": "11.0.20.1/32",
669 "paths": [
670 {
671 "nexthops": [
672 {
673 "ip": "::ffff:a00:501",
674 "hostname": "r1",
675 "afi": "ipv6",
676 "scope": "global",
677 }
678 ]
679 }
680 ],
681 }
682 return topotest.json_cmp(output, expected)
683
684 step("Configure a global V6 address on an unnumbered interface on R1")
685 output = tgen.gears["r1"].vtysh_cmd(
686 """
687 configure terminal
688 interface r1-r2-eth5
689 ipv6 address 5001:dead:beef::1/126
690 !
691 """
692 )
693
694 # verify that r2 has received prefix with GUA as nexthop
695 test_func = functools.partial(bgp_prefix_received_gua_nh, r2)
696 _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
697 assert (
698 result is None
699 ), "Testcase {} : Failed \n Error: Nexthop for prefix 11.0.20.1 \
700 is not 5001:dead:beef::1".format(
701 tc_name
702 )
703
704 step("Configure a secondary global V6 address on an unnumbered interface on R1")
705 output = tgen.gears["r1"].vtysh_cmd(
706 """
707 configure terminal
708 interface r1-r2-eth5
709 ipv6 address 7771:dead:beef::1/126
710 !
711 """
712 )
713 # verify that r1 did not readvertise the prefix with secondary V6 address as the nexthop
714 test_func = functools.partial(bgp_prefix_received_gua_nh, r2)
715 _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
716 assert (
717 result is None
718 ), "Testcase {} : Failed \n Error: Nexthop for prefix 11.0.20.1 \
719 is not 5001:dead:beef::1".format(
720 tc_name
721 )
722
723 step("Unconfigure the secondary global V6 address from unnumbered interface on R1")
724 output = tgen.gears["r1"].vtysh_cmd(
725 """
726 configure terminal
727 interface r1-r2-eth5
728 no ipv6 address 7771:dead:beef::1/126
729 !
730 """
731 )
732 # verify that r1 still has the prefix with primary GUA as the nexthop
733 test_func = functools.partial(bgp_prefix_received_gua_nh, r2)
734 _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
735 assert (
736 result is None
737 ), "Testcase {} : Failed \n Error: Nexthop for prefix 11.0.20.1 \
738 is not 5001:dead:beef::1".format(
739 tc_name
740 )
741
742 step("Unconfigure the primary global V6 address from unnumbered interface on R1")
743 output = tgen.gears["r1"].vtysh_cmd(
744 """
745 configure terminal
746 interface r1-r2-eth5
747 no ipv6 address 5001:dead:beef::1/126
748 !
749 """
750 )
751 # verify that r1 has rcvd the prefix with v4-mapped-v6 address as the nexthop
752 test_func = functools.partial(bgp_prefix_received_v4_mapped_v6_nh, r2)
753 _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
754 assert (
755 result is None
756 ), "Testcase {} : Failed \n Error: Nexthop for prefix 11.0.20.1 \
757 is not ::ffff:a00:501".format(
758 tc_name
759 )
760
761 write_test_footer(tc_name)
762
763
9e3bab5f 764if __name__ == "__main__":
765 args = ["-s"] + sys.argv[1:]
766 sys.exit(pytest.main(args))