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
)
63 "show bgp ipv4 unicast neighbor 192.168.1.1 advertised-routes json"
72 "totalPrefixCounter": 1,
74 return topotest
.json_cmp(output
, expected
)
76 test_func
= functools
.partial(
79 _
, result
= topotest
.run_and_expect(test_func
, None, count
=30, wait
=1)
80 assert result
is None, "Can't converge"
82 step("Append prefix-list to advertise 10.10.10.2/32")
87 ip prefix-list advertise seq 10 permit 10.10.10.2/32
91 def _bgp_check_advertised_after_update():
94 "show bgp ipv4 unicast neighbor 192.168.1.1 advertised-routes json"
106 "totalPrefixCounter": 2,
108 return topotest
.json_cmp(output
, expected
)
110 test_func
= functools
.partial(
111 _bgp_check_advertised_after_update
,
113 _
, result
= topotest
.run_and_expect(test_func
, None, count
=30, wait
=1)
114 assert result
is None, "10.10.10.2/32 is not advertised after prefix-list update"
116 def _bgp_check_received_routes():
117 output
= json
.loads(r1
.vtysh_cmd("show bgp ipv4 unicast 10.10.10.1/32 json"))
127 return topotest
.json_cmp(output
, expected
)
129 test_func
= functools
.partial(
130 _bgp_check_received_routes
,
132 _
, result
= topotest
.run_and_expect(test_func
, None, count
=30, wait
=1)
133 assert result
is None, "10.10.10.1/32 does not have 65000:1 community attached"
136 if __name__
== "__main__":
137 args
= ["-s"] + sys
.argv
[1:]
138 sys
.exit(pytest
.main(args
))