]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_community_alias/test_bgp-community-alias.py
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[mirror_frr.git] / tests / topotests / bgp_community_alias / test_bgp-community-alias.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 2021 by
4 # Donatas Abraitis <donatas.abraitis@gmail.com>
5 #
6 # Permission to use, copy, modify, and/or distribute this software
7 # for any purpose with or without fee is hereby granted, provided
8 # that the above copyright notice and this permission notice appear
9 # in all copies.
10 #
11 # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
12 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
14 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
15 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
16 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
17 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
18 # OF THIS SOFTWARE.
19 #
20
21 """
22 Test if BGP community alias is visible in CLI outputs
23 """
24
25 import os
26 import sys
27 import json
28 import pytest
29 import functools
30
31 pytestmark = pytest.mark.bgpd
32
33 CWD = os.path.dirname(os.path.realpath(__file__))
34 sys.path.append(os.path.join(CWD, "../"))
35
36 # pylint: disable=C0413
37 from lib import topotest
38 from lib.topogen import Topogen, TopoRouter, get_topogen
39
40 pytestmark = [pytest.mark.bgpd]
41
42
43 def build_topo(tgen):
44 for routern in range(1, 3):
45 tgen.add_router("r{}".format(routern))
46
47 switch = tgen.add_switch("s1")
48 switch.add_link(tgen.gears["r1"])
49 switch.add_link(tgen.gears["r2"])
50
51
52 def setup_module(mod):
53 tgen = Topogen(build_topo, mod.__name__)
54 tgen.start_topology()
55
56 router_list = tgen.routers()
57
58 for i, (rname, router) in enumerate(router_list.items(), 1):
59 router.load_config(
60 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
61 )
62 router.load_config(
63 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
64 )
65
66 tgen.start_router()
67
68
69 def teardown_module(mod):
70 tgen = get_topogen()
71 tgen.stop_topology()
72
73
74 def test_bgp_community_alias():
75 tgen = get_topogen()
76
77 if tgen.routers_have_failure():
78 pytest.skip(tgen.errors)
79
80 router = tgen.gears["r1"]
81
82 def _bgp_converge(router):
83 output = json.loads(router.vtysh_cmd("show ip route json"))
84 expected = {
85 "172.16.16.1/32": [
86 {
87 "tag": 10,
88 "communities": "community-r2-1 65001:2",
89 "largeCommunities": "large-community-r2-1 65001:1:2",
90 }
91 ],
92 "172.16.16.2/32": [
93 {
94 "tag": 20,
95 "communities": "65002:1 community-r2-2",
96 "largeCommunities": "",
97 }
98 ],
99 "172.16.16.3/32": [
100 {
101 "tag": 100,
102 "communities": "",
103 "largeCommunities": "",
104 }
105 ],
106 }
107 return topotest.json_cmp(output, expected)
108
109 test_func = functools.partial(_bgp_converge, router)
110 success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
111 assert result is None, "Cannot see BGP community aliases at r1"
112
113 def _bgp_show_prefixes_by_alias(router):
114 output = json.loads(
115 router.vtysh_cmd(
116 "show bgp ipv4 unicast alias large-community-r2-1 json detail"
117 )
118 )
119 expected = {
120 "routes": {
121 "172.16.16.1/32": [
122 {
123 "community": {"string": "community-r2-1 65001:2"},
124 "largeCommunity": {"string": "large-community-r2-1 65001:1:2"},
125 }
126 ]
127 }
128 }
129 return topotest.json_cmp(output, expected)
130
131 test_func = functools.partial(_bgp_show_prefixes_by_alias, router)
132 success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
133 assert result is None, "Cannot see BGP prefixes by community alias at r1"
134
135 def _bgp_show_prefixes_by_large_community_list(router):
136 output = json.loads(
137 router.vtysh_cmd("show bgp ipv4 unicast large-community-list r2 json")
138 )
139 expected = {"routes": {"172.16.16.1/32": [{"valid": True}]}}
140 return topotest.json_cmp(output, expected)
141
142 test_func = functools.partial(_bgp_show_prefixes_by_large_community_list, router)
143 success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
144 assert result is None, "Cannot see BGP prefixes by large community list at r1"
145
146
147 if __name__ == "__main__":
148 args = ["-s"] + sys.argv[1:]
149 sys.exit(pytest.main(args))