]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_path_attribute_discard/test_bgp_path_attribute_discard.py
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[mirror_frr.git] / tests / topotests / bgp_path_attribute_discard / test_bgp_path_attribute_discard.py
1 #!/usr/bin/env python
2
3 #
4 # Copyright (c) 2022 by
5 # Donatas Abraitis <donatas@opensourcerouting.org>
6 #
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
10 # in all copies.
11 #
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
19 # OF THIS SOFTWARE.
20 #
21
22 """
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.
26 """
27
28 import os
29 import sys
30 import json
31 import pytest
32 import functools
33
34 CWD = os.path.dirname(os.path.realpath(__file__))
35 sys.path.append(os.path.join(CWD, "../"))
36
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
41
42 pytestmark = [pytest.mark.bgpd]
43
44
45 def build_topo(tgen):
46 r1 = tgen.add_router("r1")
47 peer1 = tgen.add_exabgp_peer("peer1", ip="10.0.0.2", defaultRoute="via 10.0.0.1")
48
49 switch = tgen.add_switch("s1")
50 switch.add_link(r1)
51 switch.add_link(peer1)
52
53
54 def setup_module(mod):
55 tgen = Topogen(build_topo, mod.__name__)
56 tgen.start_topology()
57
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"))
61 router.start()
62
63 peer = tgen.gears["peer1"]
64 peer.start(os.path.join(CWD, "peer1"), os.path.join(CWD, "exabgp.env"))
65
66
67 def teardown_module(mod):
68 tgen = get_topogen()
69 tgen.stop_topology()
70
71
72 def test_bgp_path_attribute_discard():
73 tgen = get_topogen()
74
75 if tgen.routers_have_failure():
76 pytest.skip(tgen.errors)
77
78 r1 = tgen.gears["r1"]
79
80 def _bgp_converge():
81 output = json.loads(r1.vtysh_cmd("show bgp ipv4 unicast json detail"))
82 expected = {
83 "routes": {
84 "192.168.100.101/32": [
85 {
86 "valid": True,
87 "atomicAggregate": True,
88 "community": {
89 "string": "65001:101",
90 },
91 }
92 ],
93 "192.168.100.102/32": [
94 {
95 "valid": True,
96 "originatorId": "10.0.0.2",
97 "community": {
98 "string": "65001:102",
99 },
100 }
101 ],
102 }
103 }
104 return topotest.json_cmp(output, expected)
105
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"
109
110 step("Discard atomic-aggregate, community, and originator-id attributes from peer1")
111 r1.vtysh_cmd(
112 """
113 configure terminal
114 router bgp
115 neighbor 10.0.0.2 path-attribute discard 6 8 9
116 """
117 )
118
119 def _bgp_check_if_attributes_discarded():
120 output = json.loads(r1.vtysh_cmd("show bgp ipv4 unicast json detail"))
121 expected = {
122 "routes": {
123 "192.168.100.101/32": [
124 {
125 "valid": True,
126 "atomicAggregate": None,
127 "community": None,
128 }
129 ],
130 "192.168.100.102/32": [
131 {
132 "valid": True,
133 "originatorId": None,
134 "community": None,
135 }
136 ],
137 }
138 }
139 return topotest.json_cmp(output, expected)
140
141 test_func = functools.partial(_bgp_check_if_attributes_discarded)
142 _, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5)
143 assert (
144 result is None
145 ), "Failed to discard path attributes (atomic-aggregate, community, and originator-id)"
146
147
148 def test_memory_leak():
149 "Run the memory leak test and report results."
150 tgen = get_topogen()
151 if not tgen.is_memleak_enabled():
152 pytest.skip("Memory leak test/report is disabled")
153
154 tgen.report_memory_leaks()
155
156
157 if __name__ == "__main__":
158 args = ["-s"] + sys.argv[1:]
159 sys.exit(pytest.main(args))