]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_suppress_fib/test_bgp_suppress_fib.py
4 # test_bgp_suppress_fib.py
6 # Copyright (c) 2019 by
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
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
30 from functools
import partial
31 from time
import sleep
32 from lib
.topolog
import logger
34 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
35 sys
.path
.append(os
.path
.join(CWD
, "../"))
37 # pylint: disable=C0413
38 from lib
import topotest
39 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
41 pytestmark
= [pytest
.mark
.bgpd
]
45 for routern
in range(1, 4):
46 tgen
.add_router("r{}".format(routern
))
48 switch
= tgen
.add_switch("s1")
49 switch
.add_link(tgen
.gears
["r1"])
50 switch
.add_link(tgen
.gears
["r2"])
52 switch
= tgen
.add_switch("s2")
53 switch
.add_link(tgen
.gears
["r2"])
54 switch
.add_link(tgen
.gears
["r3"])
57 def setup_module(mod
):
58 tgen
= Topogen(build_topo
, mod
.__name
__)
61 router_list
= tgen
.routers()
63 for i
, (rname
, router
) in enumerate(router_list
.items(), 1):
65 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
68 TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
))
74 def teardown_module(mod
):
82 if tgen
.routers_have_failure():
83 pytest
.skip(tgen
.errors
)
89 json_file
= "{}/r3/v4_route.json".format(CWD
)
90 expected
= json
.loads(open(json_file
).read())
93 topotest
.router_json_cmp
,
95 "show ip route 40.0.0.0 json",
98 _
, result
= topotest
.run_and_expect(test_func
, None, count
=2, wait
=0.5)
99 assertmsg
= '"r3" JSON output mismatches'
100 assert result
is None, assertmsg
102 json_file
= "{}/r3/v4_route2.json".format(CWD
)
103 expected
= json
.loads(open(json_file
).read())
106 topotest
.router_json_cmp
,
108 "show ip route 50.0.0.0 json",
111 _
, result
= topotest
.run_and_expect(test_func
, None, count
=3, wait
=0.5)
112 assertmsg
= '"r3" JSON output mismatches'
113 assert result
is None, assertmsg
116 def test_bgp_better_admin_won():
117 "A better Admin distance protocol may come along and knock us out"
121 if tgen
.routers_have_failure():
122 pytest
.skip(tgen
.errors
)
124 r2
= tgen
.gears
["r2"]
125 r2
.vtysh_cmd("conf\nip route 40.0.0.0/8 10.0.0.10")
127 json_file
= "{}/r2/v4_override.json".format(CWD
)
128 expected
= json
.loads(open(json_file
).read())
130 logger
.info(expected
)
132 topotest
.router_json_cmp
, r2
, "show ip route 40.0.0.0 json", expected
135 _
, result
= topotest
.run_and_expect(test_func
, None, count
=10, wait
=0.5)
136 assertmsg
= '"r2" static route did not take over'
137 assert result
is None, assertmsg
139 r3
= tgen
.gears
["r3"]
141 json_file
= "{}/r3/v4_override.json".format(CWD
)
142 expected
= json
.loads(open(json_file
).read())
145 topotest
.router_json_cmp
, r3
, "show ip route 40.0.0.0 json", expected
148 _
, result
= topotest
.run_and_expect(test_func
, None, count
=10, wait
=0.5)
149 assertmsg
= '"r3" route to 40.0.0.0 should have been lost'
150 assert result
is None, assertmsg
152 r2
.vtysh_cmd("conf\nno ip route 40.0.0.0/8 10.0.0.10")
154 json_file
= "{}/r3/v4_route.json".format(CWD
)
155 expected
= json
.loads(open(json_file
).read())
158 topotest
.router_json_cmp
,
160 "show ip route 40.0.0.0 json",
163 _
, result
= topotest
.run_and_expect(test_func
, None, count
=10, wait
=0.5)
164 assertmsg
= '"r3" route to 40.0.0.0 did not come back'
165 assert result
is None, assertmsg
168 def test_bgp_allow_as_in():
171 if tgen
.routers_have_failure():
172 pytest
.skip(tgen
.errors
)
174 r2
= tgen
.gears
["r2"]
176 config_file
= "{}/r2/bgpd.allowas_in.conf".format(CWD
)
177 r2
.run("vtysh -f {}".format(config_file
))
179 json_file
= "{}/r2/bgp_ipv4_allowas.json".format(CWD
)
180 expected
= json
.loads(open(json_file
).read())
183 topotest
.router_json_cmp
,
185 "show bgp ipv4 uni 192.168.1.1/32 json",
188 _
, result
= topotest
.run_and_expect(test_func
, None, count
=10, wait
=0.5)
189 assertmsg
= '"r2" static redistribution failed into bgp'
190 assert result
is None, assertmsg
192 r1
= tgen
.gears
["r1"]
194 json_file
= "{}/r1/bgp_ipv4_allowas.json".format(CWD
)
195 expected
= json
.loads(open(json_file
).read())
198 topotest
.router_json_cmp
,
200 "show bgp ipv4 uni 192.168.1.1/32 json",
204 _
, result
= topotest
.run_and_expect(test_func
, None, count
=10, wait
=0.5)
205 assertmsg
= '"r1" 192.168.1.1/32 route should have arrived'
206 assert result
is None, assertmsg
208 r2
.vtysh_cmd("conf\nno ip route 192.168.1.1/32 10.0.0.10")
210 json_file
= "{}/r2/no_bgp_ipv4_allowas.json".format(CWD
)
211 expected
= json
.loads(open(json_file
).read())
214 topotest
.router_json_cmp
,
216 "show bgp ipv4 uni 192.168.1.1/32 json",
220 _
, result
= topotest
.run_and_expect(test_func
, None, count
=10, wait
=0.5)
221 assertmsg
= '"r2" 192.168.1.1/32 route should be gone'
222 assert result
is None, assertmsg
225 if __name__
== "__main__":
226 args
= ["-s"] + sys
.argv
[1:]
227 sys
.exit(pytest
.main(args
))