]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_local_as_private_remove/test_bgp_local_as_private_remove.py
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[mirror_frr.git] / tests / topotests / bgp_local_as_private_remove / test_bgp_local_as_private_remove.py
1 #!/usr/bin/env python
2
3 #
4 # bgp_local_as_private_remove.py
5 # Part of NetDEF Topology Tests
6 #
7 # Copyright (c) 2019 by
8 # Network Device Education Foundation, Inc. ("NetDEF")
9 #
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
13 # in all copies.
14 #
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
22 # OF THIS SOFTWARE.
23 #
24
25 """
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`.
29 """
30
31 import os
32 import sys
33 import json
34 import pytest
35 import functools
36
37 CWD = os.path.dirname(os.path.realpath(__file__))
38 sys.path.append(os.path.join(CWD, "../"))
39
40 # pylint: disable=C0413
41 from lib import topotest
42 from lib.topogen import Topogen, TopoRouter, get_topogen
43
44 pytestmark = [pytest.mark.bgpd]
45
46
47 def build_topo(tgen):
48 for routern in range(1, 5):
49 tgen.add_router("r{}".format(routern))
50
51 switch = tgen.add_switch("s1")
52 switch.add_link(tgen.gears["r1"])
53 switch.add_link(tgen.gears["r2"])
54
55 switch = tgen.add_switch("s2")
56 switch.add_link(tgen.gears["r3"])
57 switch.add_link(tgen.gears["r4"])
58
59
60 def setup_module(mod):
61 tgen = Topogen(build_topo, mod.__name__)
62 tgen.start_topology()
63
64 router_list = tgen.routers()
65
66 for i, (rname, router) in enumerate(router_list.items(), 1):
67 router.load_config(
68 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
69 )
70 router.load_config(
71 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
72 )
73
74 tgen.start_router()
75
76
77 def teardown_module(mod):
78 tgen = get_topogen()
79 tgen.stop_topology()
80
81
82 def test_bgp_remove_private_as():
83 tgen = get_topogen()
84
85 if tgen.routers_have_failure():
86 pytest.skip(tgen.errors)
87
88 r2 = tgen.gears["r2"]
89 r4 = tgen.gears["r4"]
90
91 def _bgp_converge():
92 output = json.loads(r2.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json"))
93 expected = {
94 "192.168.255.1": {
95 "bgpState": "Established",
96 }
97 }
98 return topotest.json_cmp(output, expected)
99
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"
103
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"))
106 expected = {
107 "paths": [
108 {
109 "aspath": {
110 "string": asn_path,
111 "length": asn_length,
112 }
113 }
114 ]
115 }
116 return topotest.json_cmp(output, expected)
117
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"
121
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"
125
126
127 if __name__ == "__main__":
128 args = ["-s"] + sys.argv[1:]
129 sys.exit(pytest.main(args))