2 # SPDX-License-Identifier: ISC
5 # Copyright (c) 2022 by
6 # Donatas Abraitis <donatas@opensourcerouting.org>
10 Test if `neighbor path-attribute discard` command works correctly,
11 can discard unwanted attributes from UPDATE messages, and ignore them
12 by continuing to process UPDATE messages.
21 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
22 sys
.path
.append(os
.path
.join(CWD
, "../"))
24 # pylint: disable=C0413
25 from lib
import topotest
26 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
27 from lib
.common_config
import step
29 pytestmark
= [pytest
.mark
.bgpd
]
33 r1
= tgen
.add_router("r1")
34 peer1
= tgen
.add_exabgp_peer("peer1", ip
="10.0.0.2", defaultRoute
="via 10.0.0.1")
36 switch
= tgen
.add_switch("s1")
38 switch
.add_link(peer1
)
41 def setup_module(mod
):
42 tgen
= Topogen(build_topo
, mod
.__name
__)
45 router
= tgen
.gears
["r1"]
46 router
.load_config(TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "r1/zebra.conf"))
47 router
.load_config(TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "r1/bgpd.conf"))
50 peer
= tgen
.gears
["peer1"]
51 peer
.start(os
.path
.join(CWD
, "peer1"), os
.path
.join(CWD
, "exabgp.env"))
54 def teardown_module(mod
):
59 def test_bgp_path_attribute_discard():
62 if tgen
.routers_have_failure():
63 pytest
.skip(tgen
.errors
)
68 output
= json
.loads(r1
.vtysh_cmd("show bgp ipv4 unicast json detail"))
71 "192.168.100.101/32": [
74 "atomicAggregate": True,
76 "string": "65001:101",
80 "192.168.100.102/32": [
83 "originatorId": "10.0.0.2",
85 "string": "65001:102",
91 return topotest
.json_cmp(output
, expected
)
93 test_func
= functools
.partial(_bgp_converge
)
94 _
, result
= topotest
.run_and_expect(test_func
, None, count
=30, wait
=0.5)
95 assert result
is None, "Failed bgp convergence"
97 step("Discard atomic-aggregate, community, and originator-id attributes from peer1")
102 neighbor 10.0.0.2 path-attribute discard 6 8 9
106 def _bgp_check_if_attributes_discarded():
107 output
= json
.loads(r1
.vtysh_cmd("show bgp ipv4 unicast json detail"))
110 "192.168.100.101/32": [
113 "atomicAggregate": None,
117 "192.168.100.102/32": [
120 "originatorId": None,
126 return topotest
.json_cmp(output
, expected
)
128 test_func
= functools
.partial(_bgp_check_if_attributes_discarded
)
129 _
, result
= topotest
.run_and_expect(test_func
, None, count
=30, wait
=0.5)
132 ), "Failed to discard path attributes (atomic-aggregate, community, and originator-id)"
135 def test_memory_leak():
136 "Run the memory leak test and report results."
138 if not tgen
.is_memleak_enabled():
139 pytest
.skip("Memory leak test/report is disabled")
141 tgen
.report_memory_leaks()
144 if __name__
== "__main__":
145 args
= ["-s"] + sys
.argv
[1:]
146 sys
.exit(pytest
.main(args
))