2 # SPDX-License-Identifier: ISC
4 # Copyright (c) 2021 by
5 # Donatas Abraitis <donatas.abraitis@gmail.com>
9 Test if AddPath RX direction is not negotiated via AddPath capability.
18 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
19 sys
.path
.append(os
.path
.join(CWD
, "../"))
21 # pylint: disable=C0413
22 from lib
import topotest
23 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
24 from lib
.common_config
import step
26 pytestmark
= [pytest
.mark
.bgpd
]
30 for routern
in range(1, 5):
31 tgen
.add_router("r{}".format(routern
))
33 switch
= tgen
.add_switch("s1")
34 switch
.add_link(tgen
.gears
["r1"])
35 switch
.add_link(tgen
.gears
["r2"])
37 switch
= tgen
.add_switch("s2")
38 switch
.add_link(tgen
.gears
["r2"])
39 switch
.add_link(tgen
.gears
["r3"])
40 switch
.add_link(tgen
.gears
["r4"])
43 def setup_module(mod
):
44 tgen
= Topogen(build_topo
, mod
.__name
__)
47 router_list
= tgen
.routers()
49 for i
, (rname
, router
) in enumerate(router_list
.items(), 1):
51 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
54 TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
))
60 def teardown_module(mod
):
65 def test_bgp_disable_addpath_rx():
68 if tgen
.routers_have_failure():
69 pytest
.skip(tgen
.errors
)
75 "Check if r2 advertised only 2 paths to r1 (despite addpath-tx-all-paths enabled on r2)."
78 def check_bgp_advertised_routes(router
):
81 "show bgp ipv4 unicast neighbor 192.168.1.1 advertised-routes json"
87 "addrPrefix": "172.16.16.254",
91 "addrPrefix": "192.168.2.0",
95 "totalPrefixCounter": 2,
98 return topotest
.json_cmp(output
, expected
)
100 test_func
= functools
.partial(check_bgp_advertised_routes
, r2
)
101 success
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
102 assert result
is None, "AddPath TX not working."
104 step("Check if AddPath RX is disabled on r1 and we receive only 2 paths.")
106 def check_bgp_disabled_addpath_rx(router
):
107 output
= json
.loads(router
.vtysh_cmd("show bgp neighbor 192.168.1.2 json"))
110 "bgpState": "Established",
111 "neighborCapabilities": {
113 "ipv4Unicast": {"txReceived": True, "rxReceived": True}
116 "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 2}},
120 return topotest
.json_cmp(output
, expected
)
122 test_func
= functools
.partial(check_bgp_disabled_addpath_rx
, r1
)
123 success
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
124 assert result
is None, "AddPath RX advertised, but should not."
127 if __name__
== "__main__":
128 args
= ["-s"] + sys
.argv
[1:]
129 sys
.exit(pytest
.main(args
))