]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/bgp_suppress_fib/test_bgp_suppress_fib.py
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / tests / topotests / bgp_suppress_fib / test_bgp_suppress_fib.py
CommitLineData
1cc55938 1#!/usr/bin/env python
acddc0ed 2# SPDX-License-Identifier: ISC
1cc55938
S
3
4#
5# test_bgp_suppress_fib.py
6#
7# Copyright (c) 2019 by
8#
1cc55938
S
9
10"""
11"""
12
13import os
14import sys
15import json
1cc55938
S
16import pytest
17from functools import partial
18from time import sleep
be785e35 19from lib.topolog import logger
1cc55938
S
20
21CWD = os.path.dirname(os.path.realpath(__file__))
22sys.path.append(os.path.join(CWD, "../"))
23
24# pylint: disable=C0413
25from lib import topotest
26from lib.topogen import Topogen, TopoRouter, get_topogen
1cc55938 27
bf3a0a9a
DS
28pytestmark = [pytest.mark.bgpd]
29
1cc55938 30
e82b531d
CH
31def build_topo(tgen):
32 for routern in range(1, 4):
33 tgen.add_router("r{}".format(routern))
1cc55938 34
e82b531d
CH
35 switch = tgen.add_switch("s1")
36 switch.add_link(tgen.gears["r1"])
37 switch.add_link(tgen.gears["r2"])
1cc55938 38
e82b531d
CH
39 switch = tgen.add_switch("s2")
40 switch.add_link(tgen.gears["r2"])
41 switch.add_link(tgen.gears["r3"])
1cc55938 42
9fa6ec14 43
1cc55938 44def setup_module(mod):
e82b531d 45 tgen = Topogen(build_topo, mod.__name__)
1cc55938
S
46 tgen.start_topology()
47
48 router_list = tgen.routers()
49
50 for i, (rname, router) in enumerate(router_list.items(), 1):
51 router.load_config(
52 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
53 )
54 router.load_config(
55 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
56 )
57
58 tgen.start_router()
59
60
61def teardown_module(mod):
62 tgen = get_topogen()
63 tgen.stop_topology()
64
65
66def test_bgp_route():
67 tgen = get_topogen()
68
69 if tgen.routers_have_failure():
70 pytest.skip(tgen.errors)
71
72 r3 = tgen.gears["r3"]
73
1cc55938
S
74 json_file = "{}/r3/v4_route.json".format(CWD)
75 expected = json.loads(open(json_file).read())
76
77 test_func = partial(
78 topotest.router_json_cmp,
79 r3,
80 "show ip route 40.0.0.0 json",
81 expected,
82 )
4801fc46 83 _, result = topotest.run_and_expect(test_func, None, count=20, wait=0.5)
1cc55938
S
84 assertmsg = '"r3" JSON output mismatches'
85 assert result is None, assertmsg
86
87 json_file = "{}/r3/v4_route2.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 50.0.0.0 json",
94 expected,
95 )
c6653ab2 96 _, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5)
1cc55938
S
97 assertmsg = '"r3" JSON output mismatches'
98 assert result is None, assertmsg
99
4801fc46
DS
100 json_file = "{}/r3/v4_route3.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 10.0.0.3 json",
107 expected,
c6653ab2
DS
108 )
109 _, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5)
110
9fa6ec14 111
be785e35
DS
112def test_bgp_better_admin_won():
113 "A better Admin distance protocol may come along and knock us out"
114
115 tgen = get_topogen()
116
117 if tgen.routers_have_failure():
118 pytest.skip(tgen.errors)
119
120 r2 = tgen.gears["r2"]
121 r2.vtysh_cmd("conf\nip route 40.0.0.0/8 10.0.0.10")
122
123 json_file = "{}/r2/v4_override.json".format(CWD)
124 expected = json.loads(open(json_file).read())
125
126 logger.info(expected)
127 test_func = partial(
128 topotest.router_json_cmp, r2, "show ip route 40.0.0.0 json", expected
129 )
130
131 _, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5)
132 assertmsg = '"r2" static route did not take over'
133 assert result is None, assertmsg
134
135 r3 = tgen.gears["r3"]
136
137 json_file = "{}/r3/v4_override.json".format(CWD)
138 expected = json.loads(open(json_file).read())
139
140 test_func = partial(
141 topotest.router_json_cmp, r3, "show ip route 40.0.0.0 json", expected
142 )
143
144 _, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5)
145 assertmsg = '"r3" route to 40.0.0.0 should have been lost'
146 assert result is None, assertmsg
147
148 r2.vtysh_cmd("conf\nno ip route 40.0.0.0/8 10.0.0.10")
149
150 json_file = "{}/r3/v4_route.json".format(CWD)
151 expected = json.loads(open(json_file).read())
152
153 test_func = partial(
154 topotest.router_json_cmp,
155 r3,
156 "show ip route 40.0.0.0 json",
157 expected,
158 )
159 _, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5)
160 assertmsg = '"r3" route to 40.0.0.0 did not come back'
161 assert result is None, assertmsg
162
163
164def test_bgp_allow_as_in():
165 tgen = get_topogen()
166
167 if tgen.routers_have_failure():
168 pytest.skip(tgen.errors)
169
170 r2 = tgen.gears["r2"]
171
172 config_file = "{}/r2/bgpd.allowas_in.conf".format(CWD)
173 r2.run("vtysh -f {}".format(config_file))
174
175 json_file = "{}/r2/bgp_ipv4_allowas.json".format(CWD)
176 expected = json.loads(open(json_file).read())
177
178 test_func = partial(
179 topotest.router_json_cmp,
180 r2,
181 "show bgp ipv4 uni 192.168.1.1/32 json",
182 expected,
183 )
184 _, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5)
185 assertmsg = '"r2" static redistribution failed into bgp'
186 assert result is None, assertmsg
187
188 r1 = tgen.gears["r1"]
189
190 json_file = "{}/r1/bgp_ipv4_allowas.json".format(CWD)
191 expected = json.loads(open(json_file).read())
192
193 test_func = partial(
194 topotest.router_json_cmp,
195 r1,
196 "show bgp ipv4 uni 192.168.1.1/32 json",
197 expected,
198 )
199
200 _, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5)
201 assertmsg = '"r1" 192.168.1.1/32 route should have arrived'
202 assert result is None, assertmsg
203
204 r2.vtysh_cmd("conf\nno ip route 192.168.1.1/32 10.0.0.10")
205
206 json_file = "{}/r2/no_bgp_ipv4_allowas.json".format(CWD)
207 expected = json.loads(open(json_file).read())
208
209 test_func = partial(
210 topotest.router_json_cmp,
211 r2,
212 "show bgp ipv4 uni 192.168.1.1/32 json",
213 expected,
214 )
215
216 _, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5)
217 assertmsg = '"r2" 192.168.1.1/32 route should be gone'
218 assert result is None, assertmsg
219
220
1cc55938
S
221if __name__ == "__main__":
222 args = ["-s"] + sys.argv[1:]
223 sys.exit(pytest.main(args))