4 # Copyright (c) 2022 by
5 # Donatas Abraitis <donatas@opensourcerouting.org>
7 # Permission to use, copy, modify, and/or distribute this software
8 # for any purpose with or without fee is hereby granted, provided
9 # that the above copyright notice and this permission notice appear
12 # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
13 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
15 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
16 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
17 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
18 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
23 Check if labeled-unicast works correctly with addpath capability.
24 Initially R3 MUST announce 10.0.0.1/32 multipath(2) from R1 + R2.
25 Later, we enable R5 and 10.0.0.1/32 multipath(3) MUST be announced,
35 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
36 sys
.path
.append(os
.path
.join(CWD
, "../"))
38 # pylint: disable=C0413
39 from lib
import topotest
40 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
41 from lib
.common_config
import step
43 pytestmark
= [pytest
.mark
.bgpd
]
47 for routern
in range(1, 6):
48 tgen
.add_router("r{}".format(routern
))
50 switch
= tgen
.add_switch("s1")
51 switch
.add_link(tgen
.gears
["r1"])
52 switch
.add_link(tgen
.gears
["r3"])
54 switch
= tgen
.add_switch("s2")
55 switch
.add_link(tgen
.gears
["r2"])
56 switch
.add_link(tgen
.gears
["r3"])
58 switch
= tgen
.add_switch("s3")
59 switch
.add_link(tgen
.gears
["r3"])
60 switch
.add_link(tgen
.gears
["r4"])
62 switch
= tgen
.add_switch("s4")
63 switch
.add_link(tgen
.gears
["r3"])
64 switch
.add_link(tgen
.gears
["r5"])
67 def setup_module(mod
):
68 tgen
= Topogen(build_topo
, mod
.__name
__)
71 router_list
= tgen
.routers()
73 for i
, (rname
, router
) in enumerate(router_list
.items(), 1):
75 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
78 TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
))
84 def teardown_module(mod
):
89 def test_bgp_addpath_labeled_unicast():
92 if tgen
.routers_have_failure():
93 pytest
.skip(tgen
.errors
)
98 def _bgp_check_advertised_routes(prefix_num
):
101 "show bgp ipv4 labeled-unicast neighbors 192.168.34.4 advertised-routes json"
105 "advertisedRoutes": {
107 "appliedStatusSymbols": {
114 "totalPrefixCounter": prefix_num
,
116 return topotest
.json_cmp(output
, expected
)
118 test_func
= functools
.partial(_bgp_check_advertised_routes
, 2)
119 _
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
122 ), "Failed to advertise labeled-unicast with addpath (multipath)"
124 def _bgp_check_received_routes():
125 output
= json
.loads(r4
.vtysh_cmd("show bgp ipv4 labeled-unicast json"))
131 "path": "65003 65001",
135 "path": "65003 65002",
140 return topotest
.json_cmp(output
, expected
)
142 test_func
= functools
.partial(_bgp_check_received_routes
)
143 _
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
144 assert result
is None, "Failed to receive labeled-unicast with addpath (multipath)"
146 step("Enable BGP session for R5")
151 no neighbor 192.168.35.5 shutdown
155 test_func
= functools
.partial(_bgp_check_advertised_routes
, 3)
156 _
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
159 ), "Failed to advertise labeled-unicast with addpath (multipath)"
161 step("Disable BGP session for R5")
166 neighbor 192.168.35.5 shutdown
170 test_func
= functools
.partial(_bgp_check_advertised_routes
, 2)
171 _
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
174 ), "Failed to advertise labeled-unicast with addpath (multipath)"
177 if __name__
== "__main__":
178 args
= ["-s"] + sys
.argv
[1:]
179 sys
.exit(pytest
.main(args
))