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 Test if `neighbor path-attribute discard` command works correctly,
24 can discard unwanted attributes from UPDATE messages, and ignore them
25 by continuing to process UPDATE messages.
34 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
35 sys
.path
.append(os
.path
.join(CWD
, "../"))
37 # pylint: disable=C0413
38 from lib
import topotest
39 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
40 from lib
.common_config
import step
42 pytestmark
= [pytest
.mark
.bgpd
]
46 r1
= tgen
.add_router("r1")
47 peer1
= tgen
.add_exabgp_peer("peer1", ip
="10.0.0.2", defaultRoute
="via 10.0.0.1")
49 switch
= tgen
.add_switch("s1")
51 switch
.add_link(peer1
)
54 def setup_module(mod
):
55 tgen
= Topogen(build_topo
, mod
.__name
__)
58 router
= tgen
.gears
["r1"]
59 router
.load_config(TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "r1/zebra.conf"))
60 router
.load_config(TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "r1/bgpd.conf"))
63 peer
= tgen
.gears
["peer1"]
64 peer
.start(os
.path
.join(CWD
, "peer1"), os
.path
.join(CWD
, "exabgp.env"))
67 def teardown_module(mod
):
72 def test_bgp_path_attribute_discard():
75 if tgen
.routers_have_failure():
76 pytest
.skip(tgen
.errors
)
81 output
= json
.loads(r1
.vtysh_cmd("show bgp ipv4 unicast json detail"))
84 "192.168.100.101/32": [
87 "atomicAggregate": True,
89 "string": "65001:101",
93 "192.168.100.102/32": [
96 "originatorId": "10.0.0.2",
98 "string": "65001:102",
104 return topotest
.json_cmp(output
, expected
)
106 test_func
= functools
.partial(_bgp_converge
)
107 _
, result
= topotest
.run_and_expect(test_func
, None, count
=30, wait
=0.5)
108 assert result
is None, "Failed bgp convergence"
110 step("Discard atomic-aggregate, community, and originator-id attributes from peer1")
115 neighbor 10.0.0.2 path-attribute discard 6 8 9
119 def _bgp_check_if_attributes_discarded():
120 output
= json
.loads(r1
.vtysh_cmd("show bgp ipv4 unicast json detail"))
123 "192.168.100.101/32": [
126 "atomicAggregate": None,
130 "192.168.100.102/32": [
133 "originatorId": None,
139 return topotest
.json_cmp(output
, expected
)
141 test_func
= functools
.partial(_bgp_check_if_attributes_discarded
)
142 _
, result
= topotest
.run_and_expect(test_func
, None, count
=30, wait
=0.5)
145 ), "Failed to discard path attributes (atomic-aggregate, community, and originator-id)"
148 def test_memory_leak():
149 "Run the memory leak test and report results."
151 if not tgen
.is_memleak_enabled():
152 pytest
.skip("Memory leak test/report is disabled")
154 tgen
.report_memory_leaks()
157 if __name__
== "__main__":
158 args
= ["-s"] + sys
.argv
[1:]
159 sys
.exit(pytest
.main(args
))