]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_local_as_private_remove/test_bgp_local_as_private_remove.py
4 # bgp_local_as_private_remove.py
5 # Part of NetDEF Topology Tests
7 # Copyright (c) 2019 by
8 # Network Device Education Foundation, Inc. ("NetDEF")
10 # Permission to use, copy, modify, and/or distribute this software
11 # for any purpose with or without fee is hereby granted, provided
12 # that the above copyright notice and this permission notice appear
15 # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
16 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
17 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
18 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
19 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
21 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
26 bgp_local_as_private_remove.py:
27 Test if primary AS number is not removed in cases when `local-as`
28 used together with `remove-private-AS`.
37 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
38 sys
.path
.append(os
.path
.join(CWD
, "../"))
40 # pylint: disable=C0413
41 from lib
import topotest
42 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
44 pytestmark
= [pytest
.mark
.bgpd
]
48 for routern
in range(1, 5):
49 tgen
.add_router("r{}".format(routern
))
51 switch
= tgen
.add_switch("s1")
52 switch
.add_link(tgen
.gears
["r1"])
53 switch
.add_link(tgen
.gears
["r2"])
55 switch
= tgen
.add_switch("s2")
56 switch
.add_link(tgen
.gears
["r3"])
57 switch
.add_link(tgen
.gears
["r4"])
60 def setup_module(mod
):
61 tgen
= Topogen(build_topo
, mod
.__name
__)
64 router_list
= tgen
.routers()
66 for i
, (rname
, router
) in enumerate(router_list
.items(), 1):
68 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
71 TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
))
77 def teardown_module(mod
):
82 def test_bgp_remove_private_as():
85 if tgen
.routers_have_failure():
86 pytest
.skip(tgen
.errors
)
92 output
= json
.loads(r2
.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json"))
95 "bgpState": "Established",
98 return topotest
.json_cmp(output
, expected
)
100 test_func
= functools
.partial(_bgp_converge
)
101 _
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
102 assert result
is None, "Can't converge initially"
104 def _bgp_as_path(router
, asn_path
, asn_length
):
105 output
= json
.loads(router
.vtysh_cmd("show ip bgp 172.16.255.254/32 json"))
111 "length": asn_length
,
116 return topotest
.json_cmp(output
, expected
)
118 test_func
= functools
.partial(_bgp_as_path
, r2
, "500", 1)
119 _
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
120 assert result
is None, "Private ASNs not stripped"
122 test_func
= functools
.partial(_bgp_as_path
, r4
, "500 3000", 2)
123 _
, result
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=0.5)
124 assert result
is None, "Private ASNs not stripped"
127 if __name__
== "__main__":
128 args
= ["-s"] + sys
.argv
[1:]
129 sys
.exit(pytest
.main(args
))