]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_vpnv4_gre/test_bgp_vpnv4_gre.py
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[mirror_frr.git] / tests / topotests / bgp_vpnv4_gre / test_bgp_vpnv4_gre.py
1 #!/usr/bin/env python
2
3 #
4 # test_bgp_vpnv4_gre.py
5 # Part of NetDEF Topology Tests
6 #
7 # Copyright (c) 2021 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_vpnv4_gre.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
45 # Required to instantiate the topology builder class.
46
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 switch = tgen.add_switch("s2")
63 switch.add_link(tgen.gears["r1"])
64
65 switch = tgen.add_switch("s3")
66 switch.add_link(tgen.gears["r2"])
67
68 def _populate_iface():
69 tgen = get_topogen()
70 cmds_list = [
71 'ip link add vrf1 type vrf table 10',
72 'echo 10 > /proc/sys/net/mpls/platform_labels',
73 'ip link set dev vrf1 up',
74 'ip link set dev {0}-eth1 master vrf1',
75 'echo 1 > /proc/sys/net/mpls/conf/{0}-eth0/input',
76 'ip tunnel add {0}-gre0 mode gre ttl 64 dev {0}-eth0 local 10.125.0.{1} remote 10.125.0.{2}',
77 'ip link set dev {0}-gre0 up',
78 'echo 1 > /proc/sys/net/mpls/conf/{0}-gre0/input',
79 ]
80
81 for cmd in cmds_list:
82 input = cmd.format('r1', '1', '2')
83 logger.info('input: ' + cmd)
84 output = tgen.net['r1'].cmd(cmd.format('r1', '1', '2'))
85 logger.info('output: ' + output)
86
87 for cmd in cmds_list:
88 input = cmd.format('r2', '2', '1')
89 logger.info('input: ' + cmd)
90 output = tgen.net['r2'].cmd(cmd.format('r2', '2', '1'))
91 logger.info('output: ' + output)
92
93 def setup_module(mod):
94 "Sets up the pytest environment"
95 tgen = Topogen(build_topo, mod.__name__)
96 tgen.start_topology()
97
98 router_list = tgen.routers()
99 _populate_iface()
100
101 for rname, router in router_list.items():
102 router.load_config(
103 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
104 )
105 router.load_config(
106 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
107 )
108
109 # Initialize all routers.
110 tgen.start_router()
111
112
113 def teardown_module(_mod):
114 "Teardown the pytest environment"
115 tgen = get_topogen()
116
117 tgen.stop_topology()
118
119
120 def test_protocols_convergence():
121 """
122 Assert that all protocols have converged
123 statuses as they depend on it.
124 """
125 tgen = get_topogen()
126 if tgen.routers_have_failure():
127 pytest.skip(tgen.errors)
128
129 router = tgen.gears['r1']
130 logger.info("Dump some context for r1")
131 router.vtysh_cmd("show bgp ipv4 vpn")
132 router.vtysh_cmd("show bgp summary")
133 router.vtysh_cmd("show bgp vrf vrf1 ipv4")
134 router.vtysh_cmd("show running-config")
135 router = tgen.gears['r2']
136 logger.info("Dump some context for r2")
137 router.vtysh_cmd("show bgp ipv4 vpn")
138 router.vtysh_cmd("show bgp summary")
139 router.vtysh_cmd("show bgp vrf vrf1 ipv4")
140 router.vtysh_cmd("show running-config")
141
142 # Check IPv4 routing tables on r1
143 logger.info("Checking IPv4 routes for convergence on r1")
144 router = tgen.gears['r1']
145 json_file = "{}/{}/ipv4_routes.json".format(CWD, router.name)
146 if not os.path.isfile(json_file):
147 logger.info("skipping file {}".format(json_file))
148 assert 0, 'ipv4_routes.json file not found'
149 return
150
151 expected = json.loads(open(json_file).read())
152 test_func = partial(
153 topotest.router_json_cmp,
154 router,
155 "show ip route vrf vrf1 json",
156 expected,
157 )
158 _, result = topotest.run_and_expect(test_func, None, count=40, wait=2)
159 assertmsg = '"{}" JSON output mismatches'.format(router.name)
160 assert result is None, assertmsg
161
162 # Check BGP IPv4 routing tables on r2 not installed
163 logger.info("Checking BGP IPv4 routes for convergence on r2")
164 router = tgen.gears['r2']
165 json_file = "{}/{}/bgp_ipv4_routes.json".format(CWD, router.name)
166 if not os.path.isfile(json_file):
167 assert 0, 'bgp_ipv4_routes.json file not found'
168
169 expected = json.loads(open(json_file).read())
170 test_func = partial(
171 topotest.router_json_cmp,
172 router,
173 "show bgp vrf vrf1 ipv4 json",
174 expected,
175 )
176 _, result = topotest.run_and_expect(test_func, None, count=40, wait=2)
177 assertmsg = '"{}" JSON output mismatches'.format(router.name)
178 assert result is None, assertmsg
179
180 def test_memory_leak():
181 "Run the memory leak test and report results."
182 tgen = get_topogen()
183 if not tgen.is_memleak_enabled():
184 pytest.skip("Memory leak test/report is disabled")
185
186 tgen.report_memory_leaks()
187
188
189 if __name__ == "__main__":
190 args = ["-s"] + sys.argv[1:]
191 sys.exit(pytest.main(args))