]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_suppress_fib/test_bgp_suppress_fib.py
Merge pull request #8647 from sworleys/DVNI-Config-Changes
[mirror_frr.git] / tests / topotests / bgp_suppress_fib / test_bgp_suppress_fib.py
1 #!/usr/bin/env python
2
3 #
4 # test_bgp_suppress_fib.py
5 #
6 # Copyright (c) 2019 by
7 #
8 # Permission to use, copy, modify, and/or distribute this software
9 # for any purpose with or without fee is hereby granted, provided
10 # that the above copyright notice and this permission notice appear
11 # in all copies.
12 #
13 # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
14 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
16 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
17 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
18 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
19 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20 # OF THIS SOFTWARE.
21 #
22
23 """
24 """
25
26 import os
27 import sys
28 import json
29 import pytest
30 from functools import partial
31 from time import sleep
32 from lib.topolog import logger
33
34 CWD = os.path.dirname(os.path.realpath(__file__))
35 sys.path.append(os.path.join(CWD, "../"))
36
37 # pylint: disable=C0413
38 from lib import topotest
39 from lib.topogen import Topogen, TopoRouter, get_topogen
40
41 pytestmark = [pytest.mark.bgpd]
42
43
44 def build_topo(tgen):
45 for routern in range(1, 4):
46 tgen.add_router("r{}".format(routern))
47
48 switch = tgen.add_switch("s1")
49 switch.add_link(tgen.gears["r1"])
50 switch.add_link(tgen.gears["r2"])
51
52 switch = tgen.add_switch("s2")
53 switch.add_link(tgen.gears["r2"])
54 switch.add_link(tgen.gears["r3"])
55
56
57 def setup_module(mod):
58 tgen = Topogen(build_topo, mod.__name__)
59 tgen.start_topology()
60
61 router_list = tgen.routers()
62
63 for i, (rname, router) in enumerate(router_list.items(), 1):
64 router.load_config(
65 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
66 )
67 router.load_config(
68 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
69 )
70
71 tgen.start_router()
72
73
74 def teardown_module(mod):
75 tgen = get_topogen()
76 tgen.stop_topology()
77
78
79 def test_bgp_route():
80 tgen = get_topogen()
81
82 if tgen.routers_have_failure():
83 pytest.skip(tgen.errors)
84
85 r3 = tgen.gears["r3"]
86
87 json_file = "{}/r3/v4_route.json".format(CWD)
88 expected = json.loads(open(json_file).read())
89
90 test_func = partial(
91 topotest.router_json_cmp,
92 r3,
93 "show ip route 40.0.0.0 json",
94 expected,
95 )
96 _, result = topotest.run_and_expect(test_func, None, count=20, wait=0.5)
97 assertmsg = '"r3" JSON output mismatches'
98 assert result is None, assertmsg
99
100 json_file = "{}/r3/v4_route2.json".format(CWD)
101 expected = json.loads(open(json_file).read())
102
103 test_func = partial(
104 topotest.router_json_cmp,
105 r3,
106 "show ip route 50.0.0.0 json",
107 expected,
108 )
109 _, result = topotest.run_and_expect(test_func, None, count=3, wait=0.5)
110 assertmsg = '"r3" JSON output mismatches'
111 assert result is None, assertmsg
112
113 json_file = "{}/r3/v4_route3.json".format(CWD)
114 expected = json.loads(open(json_file).read())
115
116 test_func = partial(
117 topotest.router_json_cmp,
118 r3,
119 "show ip route 10.0.0.3 json",
120 expected,
121 )
122 _, result = topotest.run_and_expect(test_func, None, count=3, wait=0.5)
123
124 def test_bgp_better_admin_won():
125 "A better Admin distance protocol may come along and knock us out"
126
127 tgen = get_topogen()
128
129 if tgen.routers_have_failure():
130 pytest.skip(tgen.errors)
131
132 r2 = tgen.gears["r2"]
133 r2.vtysh_cmd("conf\nip route 40.0.0.0/8 10.0.0.10")
134
135 json_file = "{}/r2/v4_override.json".format(CWD)
136 expected = json.loads(open(json_file).read())
137
138 logger.info(expected)
139 test_func = partial(
140 topotest.router_json_cmp, r2, "show ip route 40.0.0.0 json", expected
141 )
142
143 _, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5)
144 assertmsg = '"r2" static route did not take over'
145 assert result is None, assertmsg
146
147 r3 = tgen.gears["r3"]
148
149 json_file = "{}/r3/v4_override.json".format(CWD)
150 expected = json.loads(open(json_file).read())
151
152 test_func = partial(
153 topotest.router_json_cmp, r3, "show ip route 40.0.0.0 json", expected
154 )
155
156 _, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5)
157 assertmsg = '"r3" route to 40.0.0.0 should have been lost'
158 assert result is None, assertmsg
159
160 r2.vtysh_cmd("conf\nno ip route 40.0.0.0/8 10.0.0.10")
161
162 json_file = "{}/r3/v4_route.json".format(CWD)
163 expected = json.loads(open(json_file).read())
164
165 test_func = partial(
166 topotest.router_json_cmp,
167 r3,
168 "show ip route 40.0.0.0 json",
169 expected,
170 )
171 _, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5)
172 assertmsg = '"r3" route to 40.0.0.0 did not come back'
173 assert result is None, assertmsg
174
175
176 def test_bgp_allow_as_in():
177 tgen = get_topogen()
178
179 if tgen.routers_have_failure():
180 pytest.skip(tgen.errors)
181
182 r2 = tgen.gears["r2"]
183
184 config_file = "{}/r2/bgpd.allowas_in.conf".format(CWD)
185 r2.run("vtysh -f {}".format(config_file))
186
187 json_file = "{}/r2/bgp_ipv4_allowas.json".format(CWD)
188 expected = json.loads(open(json_file).read())
189
190 test_func = partial(
191 topotest.router_json_cmp,
192 r2,
193 "show bgp ipv4 uni 192.168.1.1/32 json",
194 expected,
195 )
196 _, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5)
197 assertmsg = '"r2" static redistribution failed into bgp'
198 assert result is None, assertmsg
199
200 r1 = tgen.gears["r1"]
201
202 json_file = "{}/r1/bgp_ipv4_allowas.json".format(CWD)
203 expected = json.loads(open(json_file).read())
204
205 test_func = partial(
206 topotest.router_json_cmp,
207 r1,
208 "show bgp ipv4 uni 192.168.1.1/32 json",
209 expected,
210 )
211
212 _, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5)
213 assertmsg = '"r1" 192.168.1.1/32 route should have arrived'
214 assert result is None, assertmsg
215
216 r2.vtysh_cmd("conf\nno ip route 192.168.1.1/32 10.0.0.10")
217
218 json_file = "{}/r2/no_bgp_ipv4_allowas.json".format(CWD)
219 expected = json.loads(open(json_file).read())
220
221 test_func = partial(
222 topotest.router_json_cmp,
223 r2,
224 "show bgp ipv4 uni 192.168.1.1/32 json",
225 expected,
226 )
227
228 _, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5)
229 assertmsg = '"r2" 192.168.1.1/32 route should be gone'
230 assert result is None, assertmsg
231
232
233 if __name__ == "__main__":
234 args = ["-s"] + sys.argv[1:]
235 sys.exit(pytest.main(args))