]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_aggregate_address_matching_med/test_bgp_aggregate_address_matching_med.py
Merge pull request #9998 from pguibert6WIND/bgp_tcp_keepalive
[mirror_frr.git] / tests / topotests / bgp_aggregate_address_matching_med / test_bgp_aggregate_address_matching_med.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 aggregate-address command works fine when suppressing summary-only
24 and using matching-MED-only together.
25 """
26
27 import os
28 import sys
29 import json
30 import pytest
31 import functools
32 from lib.common_config import (
33 step,
34 )
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 CWD = os.path.dirname(os.path.realpath(__file__))
43 sys.path.append(os.path.join(CWD, "../"))
44
45
46 def build_topo(tgen):
47 for routern in range(1, 5):
48 tgen.add_router("r{}".format(routern))
49
50 switch = tgen.add_switch("s1")
51 switch.add_link(tgen.gears["r1"])
52 switch.add_link(tgen.gears["r2"])
53
54 switch = tgen.add_switch("s2")
55 switch.add_link(tgen.gears["r2"])
56 switch.add_link(tgen.gears["r3"])
57
58
59 def setup_module(mod):
60 tgen = Topogen(build_topo, mod.__name__)
61 tgen.start_topology()
62
63 router_list = tgen.routers()
64
65 for i, (rname, router) in enumerate(router_list.items(), 1):
66 router.load_config(
67 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
68 )
69 router.load_config(
70 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
71 )
72
73 tgen.start_router()
74
75
76 def teardown_module(mod):
77 tgen = get_topogen()
78 tgen.stop_topology()
79
80
81 def test_aggregate_address_matching_med():
82 tgen = get_topogen()
83
84 if tgen.routers_have_failure():
85 pytest.skip(tgen.errors)
86
87 r1 = tgen.gears["r1"]
88 r3 = tgen.gears["r3"]
89
90 def _bgp_converge():
91 output = json.loads(r3.vtysh_cmd("show bgp ipv4 unicast json"))
92 expected = {
93 "routes": {
94 "172.16.255.0/24": None,
95 "172.16.255.1/32": [{"path": "65002 65001"}],
96 "172.16.255.2/32": [{"path": "65002 65001"}],
97 "172.16.255.3/32": [{"path": "65002 65001"}],
98 }
99 }
100 return topotest.json_cmp(output, expected)
101
102 test_func = functools.partial(_bgp_converge)
103 _, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5)
104 assert result is None, "Failed to see unsuppressed routes from R2"
105
106 step("Change MED for 172.16.255.3/32 from 400 to 300")
107 r1.vtysh_cmd(
108 """
109 configure terminal
110 route-map r2 permit 20
111 set metric 300
112 """
113 )
114
115 step("Check if 172.16.255.0/24 aggregated route was created and others suppressed")
116
117 def _bgp_aggregated_summary_only_med_match():
118 output = json.loads(r3.vtysh_cmd("show bgp ipv4 unicast json"))
119 expected = {
120 "routes": {
121 "172.16.255.0/24": [{"path": "65002"}],
122 "172.16.255.1/32": None,
123 "172.16.255.2/32": None,
124 "172.16.255.3/32": None,
125 }
126 }
127 return topotest.json_cmp(output, expected)
128
129 test_func = functools.partial(_bgp_aggregated_summary_only_med_match)
130 _, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5)
131 assert result is None, "Failed to see unsuppressed routes from R2"
132
133 step("Change MED for 172.16.255.3/32 back to 400 from 300")
134 r1.vtysh_cmd(
135 """
136 configure terminal
137 route-map r2 permit 20
138 set metric 400
139 """
140 )
141 test_func = functools.partial(_bgp_converge)
142 _, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5)
143 assert result is None, "Failed to see unsuppressed routes from R2"
144
145
146 if __name__ == "__main__":
147 args = ["-s"] + sys.argv[1:]
148 sys.exit(pytest.main(args))