]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_vrf_lite_ipv6_rtadv/test_bgp_vrf_lite_ipv6_rtadv.py
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[mirror_frr.git] / tests / topotests / bgp_vrf_lite_ipv6_rtadv / test_bgp_vrf_lite_ipv6_rtadv.py
1 #!/usr/bin/env python
2
3 #
4 # test_bgp_ipv6_rtadv.py
5 # Part of NetDEF Topology Tests
6 #
7 # Copyright (c) 2019 by 6WIND
8 #
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
12 # in all copies.
13 #
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
21 # OF THIS SOFTWARE.
22 #
23
24 """
25 test_bgp_ipv6_rtadv.py: Test the FRR BGP daemon with BGP IPv6 interface
26 with route advertisements on a separate netns.
27 """
28
29 import os
30 import sys
31 import json
32 from functools import partial
33 import pytest
34
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, "../"))
38
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
45
46 # Required to instantiate the topology builder class.
47
48 pytestmark = [pytest.mark.bgpd]
49
50
51 def build_topo(tgen):
52 "Build function"
53
54 # Create 2 routers.
55 tgen.add_router("r1")
56 tgen.add_router("r2")
57
58 switch = tgen.add_switch("s1")
59 switch.add_link(tgen.gears["r1"])
60 switch.add_link(tgen.gears["r2"])
61
62
63 def setup_module(mod):
64 "Sets up the pytest environment"
65
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")
70
71 tgen = Topogen(build_topo, mod.__name__)
72 tgen.start_topology()
73
74 router_list = tgen.routers()
75
76 logger.info("Testing with VRF Lite support")
77
78 cmds = [
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",
83 ]
84
85 for rname, router in router_list.items():
86 for cmd in cmds:
87 output = tgen.net[rname].cmd(cmd.format(rname))
88
89 for rname, router in router_list.items():
90 router.load_config(
91 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
92 )
93 router.load_config(
94 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
95 )
96
97 # Initialize all routers.
98 tgen.start_router()
99
100
101 def teardown_module(_mod):
102 "Teardown the pytest environment"
103 tgen = get_topogen()
104
105 tgen.stop_topology()
106
107
108 def test_protocols_convergence():
109 """
110 Assert that all protocols have converged
111 statuses as they depend on it.
112 """
113 tgen = get_topogen()
114 if tgen.routers_have_failure():
115 pytest.skip(tgen.errors)
116
117 # Check IPv4 routing tables.
118 logger.info("Checking IPv4 routes for convergence")
119
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))
124 continue
125
126 expected = json.loads(open(json_file).read())
127 test_func = partial(
128 topotest.router_json_cmp,
129 router,
130 "show ip route vrf {}-cust1 json".format(router.name),
131 expected,
132 )
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
136
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))
143 continue
144
145 expected = json.loads(open(json_file).read())
146 test_func = partial(
147 topotest.router_json_cmp,
148 router,
149 "show ipv6 route vrf {}-cust1 json".format(router.name),
150 expected,
151 )
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
155
156
157 def test_memory_leak():
158 "Run the memory leak test and report results."
159 tgen = get_topogen()
160 if not tgen.is_memleak_enabled():
161 pytest.skip("Memory leak test/report is disabled")
162
163 tgen.report_memory_leaks()
164
165
166 if __name__ == "__main__":
167 args = ["-s"] + sys.argv[1:]
168 sys.exit(pytest.main(args))