2 # SPDX-License-Identifier: ISC
4 # Copyright (c) 2021 by
5 # Donatas Abraitis <donatas.abraitis@gmail.com>
9 Test if BGP Long-lived Graceful Restart capability works:
10 Check if we can see 172.16.1.1/32 after initial converge in R3.
11 Check if we can see 172.16.1.1/32 as best selected due to higher weigth in R2.
13 Check if we can see 172.16.1.1/32 as stale in R2.
14 Check if we can see 172.16.1.1/32 depreferenced due to LLGR_STALE in R2.
15 Check if we can see 172.16.1.1/32 after R1 was killed in R3.
24 pytestmark
= [pytest
.mark
.bgpd
]
26 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
27 sys
.path
.append(os
.path
.join(CWD
, "../"))
29 # pylint: disable=C0413
30 from lib
import topotest
31 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
33 from lib
.common_config
import (
39 pytestmark
= [pytest
.mark
.bgpd
]
43 for routern
in range(0, 6):
44 tgen
.add_router("r{}".format(routern
))
46 switch
= tgen
.add_switch("s0")
47 switch
.add_link(tgen
.gears
["r0"])
48 switch
.add_link(tgen
.gears
["r2"])
50 switch
= tgen
.add_switch("s1")
51 switch
.add_link(tgen
.gears
["r1"])
52 switch
.add_link(tgen
.gears
["r2"])
54 switch
= tgen
.add_switch("s2")
55 switch
.add_link(tgen
.gears
["r2"])
56 switch
.add_link(tgen
.gears
["r3"])
59 switch
= tgen
.add_switch("s3")
60 switch
.add_link(tgen
.gears
["r2"])
61 switch
.add_link(tgen
.gears
["r4"])
64 def setup_module(mod
):
65 tgen
= Topogen(build_topo
, mod
.__name
__)
68 router_list
= tgen
.routers()
70 for i
, (rname
, router
) in enumerate(router_list
.items(), 1):
72 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
75 TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
))
81 def teardown_module(mod
):
89 if tgen
.routers_have_failure():
90 pytest
.skip(tgen
.errors
)
95 def _bgp_converge(router
):
96 output
= json
.loads(router
.vtysh_cmd("show ip bgp json"))
99 "172.16.1.1/32": [{"nexthops": [{"ip": "192.168.2.2", "used": True}]}],
100 "172.16.1.2/32": [{"nexthops": [{"ip": "192.168.2.2", "used": True}]}],
103 return topotest
.json_cmp(output
, expected
)
105 step("Check if we can see 172.16.1.1/32 after initial converge in R3")
106 test_func
= functools
.partial(_bgp_converge
, r3
)
107 _
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
108 assert result
is None, "Cannot see 172.16.1.1/32 in r3"
110 def _bgp_weight_prefered_route(router
):
111 output
= json
.loads(router
.vtysh_cmd("show ip bgp 172.16.1.1/32 json"))
115 "bestpath": {"selectionReason": "Weight"},
124 return topotest
.json_cmp(output
, expected
)
127 "Check if we can see 172.16.1.1/32 as best selected due to higher weigth in R2"
129 test_func
= functools
.partial(_bgp_weight_prefered_route
, r2
)
130 _
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
133 ), "Prefix 172.16.1.1/32 is not selected as bests path due to weight"
135 step("Kill bgpd in R1")
136 kill_router_daemons(tgen
, "r1", ["bgpd"])
138 def _bgp_stale_route(router
, prefix
):
139 output
= json
.loads(router
.vtysh_cmd("show ip bgp {} json".format(prefix
)))
140 expected
= {"paths": [{"community": {"string": "llgr-stale"}, "stale": True}]}
141 return topotest
.json_cmp(output
, expected
)
143 step("Check if we can see 172.16.1.1/32 as stale in R2")
144 test_func
= functools
.partial(_bgp_stale_route
, r2
, "172.16.1.1/32")
145 _
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
146 assert result
is None, "Prefix 172.16.1.1/32 is not stale"
148 def _bgp_llgr_depreference_route(router
):
149 output
= json
.loads(router
.vtysh_cmd("show ip bgp 172.16.1.1/32 json"))
153 "bestpath": {"selectionReason": "First path received"},
162 return topotest
.json_cmp(output
, expected
)
164 step("Check if we can see 172.16.1.1/32 depreferenced due to LLGR_STALE in R2")
165 test_func
= functools
.partial(_bgp_llgr_depreference_route
, r2
)
166 _
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
167 assert result
is None, "Prefix 172.16.1.1/32 is not depreferenced due to LLGR_STALE"
169 step("Check if we can see 172.16.1.1/32 after R1 was killed in R3")
170 test_func
= functools
.partial(_bgp_converge
, r3
)
171 _
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
172 assert result
is None, "Cannot see 172.16.1.1/32 in r3"
174 step("Kill bgpd in R4 (dynamic peer)")
175 kill_router_daemons(tgen
, "r4", ["bgpd"])
177 step("Check if we can see 172.16.1.2/32 after R4 (dynamic peer) was killed")
178 test_func
= functools
.partial(_bgp_stale_route
, r2
, "172.16.1.2/32")
179 _
, result
= topotest
.run_and_expect(test_func
, None, count
=120, wait
=0.5)
180 assert result
is None, "Cannot see 172.16.1.2/32 in r2"
183 if __name__
== "__main__":
184 args
= ["-s"] + sys
.argv
[1:]
185 sys
.exit(pytest
.main(args
))