4 # test_bgp_ipv6_rtadv.py
5 # Part of NetDEF Topology Tests
7 # Copyright (c) 2019 by 6WIND
9 # Permission to use, copy, modify, and/or distribute this software
10 # for any purpose with or without fee is hereby granted, provided
11 # that the above copyright notice and this permission notice appear
14 # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
15 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
17 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
18 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
19 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
20 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
25 test_bgp_ipv6_rtadv.py: Test the FRR BGP daemon with BGP IPv6 interface
26 with route advertisements on a separate netns.
32 from functools
import partial
35 # Save the Current Working Directory to find configuration files.
36 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
37 sys
.path
.append(os
.path
.join(CWD
, "../"))
39 # pylint: disable=C0413
40 # Import topogen and topotest helpers
41 from lib
import topotest
42 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
43 from lib
.topolog
import logger
44 from lib
.common_config
import required_linux_kernel_version
46 # Required to instantiate the topology builder class.
48 pytestmark
= [pytest
.mark
.bgpd
]
58 switch
= tgen
.add_switch("s1")
59 switch
.add_link(tgen
.gears
["r1"])
60 switch
.add_link(tgen
.gears
["r2"])
63 def setup_module(mod
):
64 "Sets up the pytest environment"
66 # Required linux kernel version for this suite to run.
67 result
= required_linux_kernel_version("5.0")
68 if result
is not True:
69 pytest
.skip("Kernel requirements are not met")
71 tgen
= Topogen(build_topo
, mod
.__name
__)
74 router_list
= tgen
.routers()
76 logger
.info("Testing with VRF Lite support")
79 "ip link add {0}-cust1 type vrf table 1001",
80 "ip link add loop1 type dummy",
81 "ip link set loop1 master {0}-cust1",
82 "ip link set {0}-eth0 master {0}-cust1",
85 for rname
, router
in router_list
.items():
87 output
= tgen
.net
[rname
].cmd(cmd
.format(rname
))
89 for rname
, router
in router_list
.items():
91 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
94 TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
))
97 # Initialize all routers.
101 def teardown_module(_mod
):
102 "Teardown the pytest environment"
108 def test_protocols_convergence():
110 Assert that all protocols have converged
111 statuses as they depend on it.
114 if tgen
.routers_have_failure():
115 pytest
.skip(tgen
.errors
)
117 # Check IPv4 routing tables.
118 logger
.info("Checking IPv4 routes for convergence")
120 for router
in tgen
.routers().values():
121 json_file
= "{}/{}/ipv4_routes.json".format(CWD
, router
.name
)
122 if not os
.path
.isfile(json_file
):
123 logger
.info("skipping file {}".format(json_file
))
126 expected
= json
.loads(open(json_file
).read())
128 topotest
.router_json_cmp
,
130 "show ip route vrf {}-cust1 json".format(router
.name
),
133 _
, result
= topotest
.run_and_expect(test_func
, None, count
=160, wait
=0.5)
134 assertmsg
= '"{}" JSON output mismatches'.format(router
.name
)
135 assert result
is None, assertmsg
137 # Check IPv6 routing tables.
138 logger
.info("Checking IPv6 routes for convergence")
139 for router
in tgen
.routers().values():
140 json_file
= "{}/{}/ipv6_routes.json".format(CWD
, router
.name
)
141 if not os
.path
.isfile(json_file
):
142 logger
.info("skipping file {}".format(json_file
))
145 expected
= json
.loads(open(json_file
).read())
147 topotest
.router_json_cmp
,
149 "show ipv6 route vrf {}-cust1 json".format(router
.name
),
152 _
, result
= topotest
.run_and_expect(test_func
, None, count
=160, wait
=0.5)
153 assertmsg
= '"{}" JSON output mismatches'.format(router
.name
)
154 assert result
is None, assertmsg
157 def test_memory_leak():
158 "Run the memory leak test and report results."
160 if not tgen
.is_memleak_enabled():
161 pytest
.skip("Memory leak test/report is disabled")
163 tgen
.report_memory_leaks()
166 if __name__
== "__main__":
167 args
= ["-s"] + sys
.argv
[1:]
168 sys
.exit(pytest
.main(args
))