2 # SPDX-License-Identifier: ISC
4 # Copyright (c) 2023 by
5 # Donatas Abraitis <donatas@opensourcerouting.org>
9 Test if static route with BGP conditional advertisement works correctly
10 if we modify the prefix-lists.
20 pytestmark
= pytest
.mark
.bgpd
22 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
23 sys
.path
.append(os
.path
.join(CWD
, "../"))
25 # pylint: disable=C0413
26 from lib
import topotest
27 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
28 from lib
.common_config
import step
30 pytestmark
= [pytest
.mark
.bgpd
]
33 def setup_module(mod
):
34 topodef
= {"s1": ("r1", "r2"), "s2": ("r2", "r3")}
35 tgen
= Topogen(topodef
, mod
.__name
__)
38 router_list
= tgen
.routers()
40 for _
, (rname
, router
) in enumerate(router_list
.items(), 1):
41 router
.load_frr_config(os
.path
.join(CWD
, "{}/frr.conf".format(rname
)))
46 def teardown_module(mod
):
51 def test_bgp_conditional_advertisements_static_route():
54 if tgen
.routers_have_failure():
55 pytest
.skip(tgen
.errors
)
62 "show bgp ipv4 unicast neighbor 192.168.1.1 advertised-routes json"
71 "totalPrefixCounter": 1,
73 return topotest
.json_cmp(output
, expected
)
75 test_func
= functools
.partial(
78 _
, result
= topotest
.run_and_expect(test_func
, None, count
=30, wait
=1)
79 assert result
is None, "Can't converge"
81 step("Append prefix-list to advertise 10.10.10.2/32")
86 ip prefix-list advertise seq 10 permit 10.10.10.2/32
90 def _bgp_check_advertised_after_update():
93 "show bgp ipv4 unicast neighbor 192.168.1.1 advertised-routes json"
105 "totalPrefixCounter": 2,
107 return topotest
.json_cmp(output
, expected
)
109 test_func
= functools
.partial(
110 _bgp_check_advertised_after_update
,
112 _
, result
= topotest
.run_and_expect(test_func
, None, count
=30, wait
=1)
113 assert result
is None, "10.10.10.2/32 is not advertised after prefix-list update"
116 if __name__
== "__main__":
117 args
= ["-s"] + sys
.argv
[1:]
118 sys
.exit(pytest
.main(args
))