2 # SPDX-License-Identifier: ISC
5 # test_bgp_ipv6_rtadv.py
6 # Part of NetDEF Topology Tests
8 # Copyright (c) 2019 by 6WIND
12 test_bgp_ipv6_rtadv.py: Test the FRR BGP daemon with BGP IPv6 interface
13 with route advertisements on a separate netns.
19 from functools
import partial
22 # Save the Current Working Directory to find configuration files.
23 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
24 sys
.path
.append(os
.path
.join(CWD
, "../"))
26 # pylint: disable=C0413
27 # Import topogen and topotest helpers
28 from lib
import topotest
29 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
30 from lib
.topolog
import logger
31 from lib
.common_config
import required_linux_kernel_version
33 # Required to instantiate the topology builder class.
35 pytestmark
= [pytest
.mark
.bgpd
]
45 switch
= tgen
.add_switch("s1")
46 switch
.add_link(tgen
.gears
["r1"])
47 switch
.add_link(tgen
.gears
["r2"])
50 def setup_module(mod
):
51 "Sets up the pytest environment"
53 # Required linux kernel version for this suite to run.
54 result
= required_linux_kernel_version("5.0")
55 if result
is not True:
56 pytest
.skip("Kernel requirements are not met")
58 tgen
= Topogen(build_topo
, mod
.__name
__)
61 router_list
= tgen
.routers()
63 logger
.info("Testing with VRF Lite support")
66 "ip link add {0}-cust1 type vrf table 1001",
67 "ip link add loop1 type dummy",
68 "ip link set loop1 master {0}-cust1",
69 "ip link set {0}-eth0 master {0}-cust1",
72 for rname
, router
in router_list
.items():
74 output
= tgen
.net
[rname
].cmd(cmd
.format(rname
))
76 for rname
, router
in router_list
.items():
78 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
81 TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
))
84 # Initialize all routers.
88 def teardown_module(_mod
):
89 "Teardown the pytest environment"
95 def test_protocols_convergence():
97 Assert that all protocols have converged
98 statuses as they depend on it.
101 if tgen
.routers_have_failure():
102 pytest
.skip(tgen
.errors
)
104 # Check IPv4 routing tables.
105 logger
.info("Checking IPv4 routes for convergence")
107 for router
in tgen
.routers().values():
108 json_file
= "{}/{}/ipv4_routes.json".format(CWD
, router
.name
)
109 if not os
.path
.isfile(json_file
):
110 logger
.info("skipping file {}".format(json_file
))
113 expected
= json
.loads(open(json_file
).read())
115 topotest
.router_json_cmp
,
117 "show ip route vrf {}-cust1 json".format(router
.name
),
120 _
, result
= topotest
.run_and_expect(test_func
, None, count
=160, wait
=0.5)
121 assertmsg
= '"{}" JSON output mismatches'.format(router
.name
)
122 assert result
is None, assertmsg
124 # Check IPv6 routing tables.
125 logger
.info("Checking IPv6 routes for convergence")
126 for router
in tgen
.routers().values():
127 json_file
= "{}/{}/ipv6_routes.json".format(CWD
, router
.name
)
128 if not os
.path
.isfile(json_file
):
129 logger
.info("skipping file {}".format(json_file
))
132 expected
= json
.loads(open(json_file
).read())
134 topotest
.router_json_cmp
,
136 "show ipv6 route vrf {}-cust1 json".format(router
.name
),
139 _
, result
= topotest
.run_and_expect(test_func
, None, count
=160, wait
=0.5)
140 assertmsg
= '"{}" JSON output mismatches'.format(router
.name
)
141 assert result
is None, assertmsg
144 def test_memory_leak():
145 "Run the memory leak test and report results."
147 if not tgen
.is_memleak_enabled():
148 pytest
.skip("Memory leak test/report is disabled")
150 tgen
.report_memory_leaks()
153 if __name__
== "__main__":
154 args
= ["-s"] + sys
.argv
[1:]
155 sys
.exit(pytest
.main(args
))