2 # SPDX-License-Identifier: ISC
5 # Copyright (c) 2022 by
6 # Donatas Abraitis <donatas@opensourcerouting.org>
10 Check if labeled-unicast works correctly with addpath capability.
11 Initially R3 MUST announce 10.0.0.1/32 multipath(2) from R1 + R2.
12 Later, we enable R5 and 10.0.0.1/32 multipath(3) MUST be announced,
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
]
34 for routern
in range(1, 6):
35 tgen
.add_router("r{}".format(routern
))
37 switch
= tgen
.add_switch("s1")
38 switch
.add_link(tgen
.gears
["r1"])
39 switch
.add_link(tgen
.gears
["r3"])
41 switch
= tgen
.add_switch("s2")
42 switch
.add_link(tgen
.gears
["r2"])
43 switch
.add_link(tgen
.gears
["r3"])
45 switch
= tgen
.add_switch("s3")
46 switch
.add_link(tgen
.gears
["r3"])
47 switch
.add_link(tgen
.gears
["r4"])
49 switch
= tgen
.add_switch("s4")
50 switch
.add_link(tgen
.gears
["r3"])
51 switch
.add_link(tgen
.gears
["r5"])
54 def setup_module(mod
):
55 tgen
= Topogen(build_topo
, mod
.__name
__)
58 router_list
= tgen
.routers()
60 for i
, (rname
, router
) in enumerate(router_list
.items(), 1):
62 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
65 TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
))
71 def teardown_module(mod
):
76 def test_bgp_addpath_labeled_unicast():
79 if tgen
.routers_have_failure():
80 pytest
.skip(tgen
.errors
)
85 def _bgp_check_advertised_routes(prefix_num
):
88 "show bgp ipv4 labeled-unicast neighbors 192.168.34.4 advertised-routes json"
94 "appliedStatusSymbols": {
101 "totalPrefixCounter": prefix_num
,
103 return topotest
.json_cmp(output
, expected
)
105 test_func
= functools
.partial(_bgp_check_advertised_routes
, 2)
106 _
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
109 ), "Failed to advertise labeled-unicast with addpath (multipath)"
111 def _bgp_check_received_routes():
112 output
= json
.loads(r4
.vtysh_cmd("show bgp ipv4 labeled-unicast json"))
118 "path": "65003 65001",
122 "path": "65003 65002",
127 return topotest
.json_cmp(output
, expected
)
129 test_func
= functools
.partial(_bgp_check_received_routes
)
130 _
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
131 assert result
is None, "Failed to receive labeled-unicast with addpath (multipath)"
133 step("Enable BGP session for R5")
138 no neighbor 192.168.35.5 shutdown
142 test_func
= functools
.partial(_bgp_check_advertised_routes
, 3)
143 _
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
146 ), "Failed to advertise labeled-unicast with addpath (multipath)"
148 step("Disable BGP session for R5")
153 neighbor 192.168.35.5 shutdown
157 test_func
= functools
.partial(_bgp_check_advertised_routes
, 2)
158 _
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
161 ), "Failed to advertise labeled-unicast with addpath (multipath)"
164 if __name__
== "__main__":
165 args
= ["-s"] + sys
.argv
[1:]
166 sys
.exit(pytest
.main(args
))