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 treat-as-withdraw` command works correctly,
24 can withdraw unwanted prefixes from BGP table.
33 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
34 sys
.path
.append(os
.path
.join(CWD
, "../"))
36 # pylint: disable=C0413
37 from lib
import topotest
38 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
39 from lib
.common_config
import step
41 pytestmark
= [pytest
.mark
.bgpd
]
45 r1
= tgen
.add_router("r1")
46 r2
= tgen
.add_router("r2")
48 switch
= tgen
.add_switch("s1")
53 def setup_module(mod
):
54 tgen
= Topogen(build_topo
, mod
.__name
__)
58 r1
.load_config(TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "r1/zebra.conf"))
59 r1
.load_config(TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "r1/bgpd.conf"))
63 r2
.load_config(TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "r2/zebra.conf"))
64 r2
.load_config(TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "r2/bgpd.conf"))
68 def teardown_module(mod
):
73 def test_bgp_path_attribute_treat_as_withdraw():
76 if tgen
.routers_have_failure():
77 pytest
.skip(tgen
.errors
)
82 output
= json
.loads(r2
.vtysh_cmd("show bgp ipv4 unicast json detail"))
89 "atomicAggregate": True,
102 return topotest
.json_cmp(output
, expected
)
104 test_func
= functools
.partial(_bgp_converge
)
105 _
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
106 assert result
is None, "Failed bgp convergence"
108 step("Withdraw prefixes with atomic-aggregate from r1")
113 neighbor 10.0.0.1 path-attribute treat-as-withdraw 6
117 def _bgp_check_if_route_withdrawn():
118 output
= json
.loads(r2
.vtysh_cmd("show bgp ipv4 unicast json detail"))
121 "10.10.10.10/32": None,
131 return topotest
.json_cmp(output
, expected
)
133 test_func
= functools
.partial(_bgp_check_if_route_withdrawn
)
134 _
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
135 assert result
is None, "Failed to withdraw prefixes with atomic-aggregate attribute"
138 def test_memory_leak():
139 "Run the memory leak test and report results."
141 if not tgen
.is_memleak_enabled():
142 pytest
.skip("Memory leak test/report is disabled")
144 tgen
.report_memory_leaks()
147 if __name__
== "__main__":
148 args
= ["-s"] + sys
.argv
[1:]
149 sys
.exit(pytest
.main(args
))