]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/bgp_ecmp_topo3/test_ibgp_ecmp_topo3.py
tests: cleanup: rerun changed files through black
[mirror_frr.git] / tests / topotests / bgp_ecmp_topo3 / test_ibgp_ecmp_topo3.py
CommitLineData
57ea1920
PG
1#!/usr/bin/env python
2
3#
4# Copyright (c) 2019 by VMware, Inc. ("VMware")
5# Used Copyright (c) 2018 by Network Device Education Foundation, Inc.
6# ("NetDEF") in this file.
7#
8# Permission to use, copy, modify, and/or distribute this software
9# for any purpose with or without fee is hereby granted, provided
10# that the above copyright notice and this permission notice appear
11# in all copies.
12#
13# THE SOFTWARE IS PROVIDED "AS IS" AND VMWARE DISCLAIMS ALL WARRANTIES
14# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL VMWARE BE LIABLE FOR
16# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
17# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
18# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
19# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20# OF THIS SOFTWARE.
21#
22
23
24"""
25Following tests are covered to test ecmp functionality on iBGP.
261. Verify bgp fast-convergence functionality
27"""
28import os
29import sys
30import time
57ea1920
PG
31import pytest
32from time import sleep
33
34# Save the Current Working Directory to find configuration files.
35CWD = os.path.dirname(os.path.realpath(__file__))
36sys.path.append(os.path.join(CWD, "../"))
37sys.path.append(os.path.join(CWD, "../../"))
38
39# pylint: disable=C0413
40# Import topogen and topotest helpers
4953ca97 41from lib.topogen import get_topogen
e82b531d 42from lib import topojson
57ea1920
PG
43
44from lib.common_config import (
57ea1920
PG
45 write_test_header,
46 write_test_footer,
47 verify_rib,
48 create_static_routes,
49 check_address_types,
57ea1920 50 reset_config_on_routers,
57ea1920
PG
51 shutdown_bringup_interface,
52 apply_raw_config,
53)
54from lib.topolog import logger
4953ca97 55from lib.bgp import create_router_bgp, verify_bgp_convergence
57ea1920
PG
56
57
58pytestmark = [pytest.mark.bgpd, pytest.mark.staticd]
59
60
57ea1920
PG
61# Global variables
62NEXT_HOPS = {"ipv4": [], "ipv6": []}
63NETWORK = {"ipv4": "192.168.1.10/32", "ipv6": "fd00:0:0:1::10/128"}
64NEXT_HOP_IP = {"ipv4": "10.0.0.1", "ipv6": "fd00::1"}
65BGP_CONVERGENCE = False
66
67
57ea1920
PG
68def setup_module(mod):
69 """
70 Sets up the pytest environment.
71
72 * `mod`: module name
73 """
57ea1920
PG
74 global ADDR_TYPES
75
76 testsuite_run_time = time.asctime(time.localtime(time.time()))
77 logger.info("Testsuite start time: {}".format(testsuite_run_time))
78 logger.info("=" * 40)
79
e82b531d
CH
80 tgen = topojson.setup_module_from_json(mod.__file__)
81 topo = tgen.json_topo
57ea1920
PG
82
83 # Don't run this test if we have any failure.
84 if tgen.routers_have_failure():
85 pytest.skip(tgen.errors)
86
87 # Api call verify whether BGP is converged
88 ADDR_TYPES = check_address_types()
89
90 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
91 assert BGP_CONVERGENCE is True, "setup_module :Failed \n Error:" " {}".format(
92 BGP_CONVERGENCE
93 )
94
95 # STATIC_ROUTE = True
96 logger.info("Running setup_module() done")
97
98
99def teardown_module():
e82b531d 100 get_topogen().stop_topology()
57ea1920
PG
101
102
103def static_or_nw(tgen, topo, tc_name, test_type, dut):
104
105 if test_type == "redist_static":
106 input_dict_static = {
107 dut: {
108 "static_routes": [
109 {"network": NETWORK["ipv4"], "next_hop": NEXT_HOP_IP["ipv4"]},
110 {"network": NETWORK["ipv6"], "next_hop": NEXT_HOP_IP["ipv6"]},
111 ]
112 }
113 }
114 logger.info("Configuring static route on router %s", dut)
115 result = create_static_routes(tgen, input_dict_static)
116 assert result is True, "Testcase {} : Failed \n Error: {}".format(
117 tc_name, result
118 )
119
120 input_dict_2 = {
121 dut: {
122 "bgp": {
123 "address_family": {
124 "ipv4": {
125 "unicast": {"redistribute": [{"redist_type": "static"}]}
126 },
127 "ipv6": {
128 "unicast": {"redistribute": [{"redist_type": "static"}]}
129 },
130 }
131 }
132 }
133 }
134
135 logger.info("Configuring redistribute static route on router %s", dut)
136 result = create_router_bgp(tgen, topo, input_dict_2)
137 assert result is True, "Testcase {} : Failed \n Error: {}".format(
138 tc_name, result
139 )
140
141 elif test_type == "advertise_nw":
142 input_dict_nw = {
143 dut: {
144 "bgp": {
145 "address_family": {
146 "ipv4": {
147 "unicast": {
148 "advertise_networks": [{"network": NETWORK["ipv4"]}]
149 }
150 },
151 "ipv6": {
152 "unicast": {
153 "advertise_networks": [{"network": NETWORK["ipv6"]}]
154 }
155 },
156 }
157 }
158 }
159 }
160
161 logger.info(
162 "Advertising networks %s %s from router %s",
163 NETWORK["ipv4"],
164 NETWORK["ipv6"],
165 dut,
166 )
167 result = create_router_bgp(tgen, topo, input_dict_nw)
168 assert result is True, "Testcase {} : Failed \n Error: {}".format(
169 tc_name, result
170 )
171
172
173@pytest.mark.parametrize("test_type", ["redist_static"])
e82b531d 174def test_ecmp_fast_convergence(request, test_type, tgen, topo):
57ea1920
PG
175 """This test is to verify bgp fast-convergence cli functionality"""
176
177 tc_name = request.node.name
178 write_test_header(tc_name)
57ea1920
PG
179
180 # Verifying RIB routes
181 dut = "r3"
182 protocol = "bgp"
183
184 reset_config_on_routers(tgen)
185 static_or_nw(tgen, topo, tc_name, test_type, "r2")
186
187 for addr_type in ADDR_TYPES:
188 input_dict = {"r3": {"static_routes": [{"network": NETWORK[addr_type]}]}}
189
190 logger.info("Verifying %s routes on r3", addr_type)
191 result = verify_rib(
192 tgen,
193 addr_type,
194 dut,
195 input_dict,
196 protocol=protocol,
197 )
198 assert result is True, "Testcase {} : Failed \n Error: {}".format(
199 tc_name, result
200 )
201
202 intf1 = topo["routers"]["r2"]["links"]["r3-link1"]["interface"]
203 intf2 = topo["routers"]["r2"]["links"]["r3-link2"]["interface"]
204
205 logger.info("Shutdown one of the link b/w r2 and r3")
206 shutdown_bringup_interface(tgen, "r2", intf1, False)
207
208 logger.info("Verify bgp neighbors are still up")
209 result = verify_bgp_convergence(tgen, topo)
210 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
211
212 logger.info("Shutdown another link b/w r2 and r3")
213 shutdown_bringup_interface(tgen, "r2", intf2, False)
214
215 logger.info("Wait for 10 sec and make sure bgp neighbors are still up")
216 sleep(10)
217 result = verify_bgp_convergence(tgen, topo)
218 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
219
220 logger.info("No shut links b/w r2 and r3")
221 shutdown_bringup_interface(tgen, "r2", intf1, True)
222 shutdown_bringup_interface(tgen, "r2", intf2, True)
223
224 logger.info("Enable bgp fast-convergence cli")
225 raw_config = {
a53c08bc
CH
226 "r2": {
227 "raw_config": [
228 "router bgp {}".format(topo["routers"]["r2"]["bgp"]["local_as"]),
229 "bgp fast-convergence",
230 ]
231 }
57ea1920
PG
232 }
233 result = apply_raw_config(tgen, raw_config)
234 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
235
236 logger.info("Shutdown one link b/w r2 and r3")
237 shutdown_bringup_interface(tgen, "r2", intf1, False)
238
239 logger.info("Verify bgp neighbors goes down immediately")
240 result = verify_bgp_convergence(tgen, topo, dut="r2", expected=False)
241 assert result is not True, "Testcase {} : Failed \n Error: {}".format(
242 tc_name, result
243 )
244
245 logger.info("Shutdown second link b/w r2 and r3")
246 shutdown_bringup_interface(tgen, "r2", intf2, False)
247
248 logger.info("Verify bgp neighbors goes down immediately")
249 result = verify_bgp_convergence(tgen, topo, dut="r2", expected=False)
250 assert result is not True, "Testcase {} : Failed \n Error: {}".format(
251 tc_name, result
252 )
253
254 write_test_footer(tc_name)
255
256
257if __name__ == "__main__":
258 args = ["-s"] + sys.argv[1:]
259 sys.exit(pytest.main(args))