]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/bgp_unique_rid/test_bgp_unique_rid_vrf.py
*: auto-convert to SPDX License IDs
[mirror_frr.git] / tests / topotests / bgp_unique_rid / test_bgp_unique_rid_vrf.py
CommitLineData
441875ea 1#!/usr/bin/env python
acddc0ed 2# SPDX-License-Identifier: ISC
441875ea 3
4#
5# Copyright (c) 2022 by VMware, Inc. ("VMware")
6# Used Copyright (c) 2018 by Network Device Education Foundation,
7# Inc. ("NetDEF") in this file.
8#
441875ea 9
10import sys
11import time
12import pytest
13import inspect
14import os
15from copy import deepcopy
16
17# Save the Current Working Directory to find configuration files.
18CWD = os.path.dirname(os.path.realpath(__file__))
19sys.path.append(os.path.join(CWD, "../"))
20sys.path.append(os.path.join(CWD, "../lib/"))
21
22"""Following tests are covered to test bgp unique rid functionality.
231. Verify iBGP session when same and different router ID is configured in user VRF(GREEN).
242. Verify eBGP session when same and different router ID is configured in user vrf (VRF RED)
253. Verify two different eBGP sessions initiated with same router ID in user VRf (RED and GREEN)
26"""
27
28#################################
29# TOPOLOGY
30#################################
31"""
32
33 +-------+
34 +--------- | R2 |
35 | +-------+
36 |iBGP |
37 +-------+ |
38 | R1 | |iBGP
39 +-------+ |
40 | |
41 | iBGP +-------+ eBGP +-------+
42 +---------- | R3 |========= | R4 |
43 +-------+ +-------+
44 |
45 |eBGP
46 |
47 +-------+
48 | R5 |
49 +-------+
50
51
52"""
53
54# pylint: disable=C0413
55# Import topogen and topotest helpers
56from lib.topogen import Topogen, get_topogen
57from lib.topojson import build_config_from_json
58from lib.topolog import logger
59
60pytestmark = [pytest.mark.bgpd, pytest.mark.staticd]
61
62# Required to instantiate the topology builder class.
63from lib.common_config import (
64 start_topology,
65 write_test_header,
66 step,
67 write_test_footer,
68 check_address_types,
69 reset_config_on_routers,
70 check_router_status,
71)
72from lib.topolog import logger
73from lib.bgp import (
74 verify_bgp_convergence,
75 create_router_bgp,
76 clear_bgp_and_verify,
77)
78
79# Global variables
80topo = None
81bgp_convergence = False
82NETWORK = {
83 "ipv4": [
84 "192.168.20.1/32",
85 "192.168.20.2/32",
86 "192.168.21.1/32",
87 "192.168.21.2/32",
88 "192.168.22.1/32",
89 "192.168.22.2/32",
90 ],
91 "ipv6": [
92 "fc07:50::1/128",
93 "fc07:50::2/128",
94 "fc07:150::1/128",
95 "fc07:150::2/128",
96 "fc07:1::1/128",
97 "fc07:1::2/128",
98 ],
99}
100
101bgp_convergence = False
102ADDR_TYPES = check_address_types()
103
104
105def setup_module(mod):
106 """setup_module.
107
108 Set up the pytest environment
109 * `mod`: module name
110 """
111 global topo
112 testsuite_run_time = time.asctime(time.localtime(time.time()))
113 logger.info("Testsuite start time: {}".format(testsuite_run_time))
114 logger.info("=" * 40)
115
116 logger.info("Running setup_module to create topology")
117
118 # This function initiates the topology build with Topogen...
119 json_file = "{}/bgp_unique_rid_vrf.json".format(CWD)
120 tgen = Topogen(json_file, mod.__name__)
121 global topo
122 topo = tgen.json_topo
123 # ... and here it calls Mininet initialization functions.
124
125 # Starting topology, create tmp files which are loaded to routers
126 # to start daemons and then start routers
127 start_topology(tgen)
128
129 # Creating configuration from JSON
130 build_config_from_json(tgen, topo)
131
132 # Checking BGP convergence
133 global bgp_convergence
134 global ADDR_TYPES
135
136 # Don't run this test if we have any failure.
137 if tgen.routers_have_failure():
138 pytest.skip(tgen.errors)
139
140 # Api call verify whether BGP is converged
141 bgp_convergence = verify_bgp_convergence(tgen, topo)
142 assert bgp_convergence is True, "setup_module :Failed \n Error:" " {}".format(
143 bgp_convergence
144 )
145 logger.info("Running setup_module() done")
146
147
148def teardown_module():
149 """Teardown the pytest environment"""
150
151 logger.info("Running teardown_module to delete topology")
152
153 tgen = get_topogen()
154
155 # Stop toplogy and Remove tmp files
156 tgen.stop_topology()
157
158 logger.info(
159 "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
160 )
161 logger.info("=" * 40)
162
163
164#####################################################
165# Tests starting
166#####################################################
167
168
169def test_bgp_unique_rid_ebgp_vrf_p0():
170 """
171 TC: 1
172 Verify iBGP session when same and different router ID is configured in user VRF(GREEN).
173 """
174 tgen = get_topogen()
175 global bgp_convergence
176
177 if bgp_convergence is not True:
178 pytest.skip("skipped because of BGP Convergence failure")
179
180 # test case name
181 tc_name = inspect.stack()[0][3]
182 write_test_header(tc_name)
183 if tgen.routers_have_failure():
184 check_router_status(tgen)
185
186 step("Configure base config as per the topology")
187 reset_config_on_routers(tgen)
188
189 step(
190 "Base config should be up, verify using BGP convergence on all \
191 the routers for IPv4 and IPv6 nbrs"
192 )
193
194 result = verify_bgp_convergence(tgen, topo)
195 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
196
197 step("Configure the same router id between R4 and R3 10.10.10.10")
198 input_dict = {
199 "r3": {"bgp": {"router_id": "10.10.10.10", "local_as": 100, "vrf": "RED"}},
200 "r4": {"bgp": {"router_id": "10.10.10.10", "local_as": 200, "vrf": "RED"}},
201 }
202 result = create_router_bgp(tgen, topo, input_dict)
203 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
204
205 step("Verify neighbours are in ESTAB state.")
206 result = verify_bgp_convergence(tgen, topo)
207 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
208
209 step("Configure the same router id between R5 and R3 (10.10.10.10)")
210 input_dict = {
211 "r3": {"bgp": {"router_id": "10.10.10.10", "local_as": 100, "vrf": "RED"}},
212 "r5": {"bgp": {"router_id": "10.10.10.10", "local_as": 300, "vrf": "RED"}},
213 }
214 result = create_router_bgp(tgen, topo, input_dict)
215 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
216
217 step("Verify neighbours are in ESTAB state.")
218 result = verify_bgp_convergence(tgen, topo)
219 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
220
221 step("modify the router id on r3 to different router id (11.11.11.11)")
222 input_dict = {
223 "r3": {"bgp": {"router_id": "11.11.11.11", "local_as": 100, "vrf": "RED"}}
224 }
225 result = create_router_bgp(tgen, topo, input_dict)
226 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
227
228 step("Verify neighbours are in ESTAB state.")
229 result = verify_bgp_convergence(tgen, topo)
230 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
231
232 step("Reset bgp process")
233 step("Verify neighbours are in ESTAB state.")
234 dut = "r3"
235 result = clear_bgp_and_verify(tgen, topo, router="r3")
236 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
237
238 step("Clear ip bgp process with *")
239 step("Verify neighbours are in ESTAB state.")
240 result = clear_bgp_and_verify(tgen, topo, dut)
241 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
242
243 step("Configure neighbours between R3 and R4 in EVPN address family.")
244 input_dict = {
245 "r3": {
246 "bgp": {
247 "local_as": 100,
248 "vrf": "RED",
249 "address_family": {
250 "l2vpn": {
251 "evpn": {
252 "advertise": {
253 "ipv4": {"unicast": {}},
254 "ipv6": {"unicast": {}},
255 }
256 }
257 }
258 },
259 }
260 },
261 "r4": {
262 "bgp": {
263 "local_as": 200,
264 "vrf": "RED",
265 "address_family": {
266 "l2vpn": {
267 "evpn": {
268 "advertise": {
269 "ipv4": {"unicast": {}},
270 "ipv6": {"unicast": {}},
271 }
272 }
273 }
274 },
275 }
276 },
277 }
278 result = create_router_bgp(tgen, topo, input_dict)
279 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
280
281 step("Verify neighbours are in ESTAB state.")
282 result = clear_bgp_and_verify(tgen, topo, dut)
283 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
284
285 write_test_footer(tc_name)
286
287
288def test_bgp_unique_rid_ibgp_vrf_p0():
289 """
290 TC: 2
291 Verify eBGP session when same and different router ID is configured in user vrf (VRF RED)
292 """
293 tgen = get_topogen()
294 global bgp_convergence
295
296 if bgp_convergence is not True:
297 pytest.skip("skipped because of BGP Convergence failure")
298
299 # test case name
300 tc_name = inspect.stack()[0][3]
301 write_test_header(tc_name)
302 if tgen.routers_have_failure():
303 check_router_status(tgen)
304
305 step("Configure base config as per the topology")
306 reset_config_on_routers(tgen)
307
308 step(
309 "Base config should be up, verify using BGP convergence on all \
310 the routers for IPv4 and IPv6 nbrs"
311 )
312
313 result = verify_bgp_convergence(tgen, topo)
314 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
315
316 step("Configure the same router id between R1 and R3 (10.10.10.10)")
317 input_dict = {
318 "r3": {"bgp": {"router_id": "10.10.10.10", "local_as": 100, "vrf": "RED"}},
319 "r1": {"bgp": {"router_id": "10.10.10.10", "local_as": 100, "vrf": "RED"}},
320 }
321 result = create_router_bgp(tgen, topo, input_dict)
322 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
323
324 step("Verify neighbours are in ESTAB state.")
325 result = verify_bgp_convergence(tgen, topo)
326 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
327
328 step("Configure the same router id between R2 and R3 (10.10.10.10)")
329 input_dict = {
330 "r3": {"bgp": {"router_id": "10.10.10.10", "local_as": 100, "vrf": "RED"}},
331 "r2": {"bgp": {"router_id": "10.10.10.10", "local_as": 100, "vrf": "RED"}},
332 }
333 result = create_router_bgp(tgen, topo, input_dict)
334 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
335
336 step("Verify neighbours are in ESTAB state.")
337 result = verify_bgp_convergence(tgen, topo)
338 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
339
340 step("modify the router id on r3 to different router id (11.11.11.11)")
341 input_dict = {
342 "r3": {"bgp": {"router_id": "11.11.11.11", "local_as": 100, "vrf": "RED"}}
343 }
344 result = create_router_bgp(tgen, topo, input_dict)
345 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
346
347 step("Verify neighbours are in ESTAB state.")
348 result = verify_bgp_convergence(tgen, topo, dut="r3")
349 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
350
351 step("Reset bgp process")
352 step("Verify neighbours are in ESTAB state.")
353 dut = "r3"
354 result = clear_bgp_and_verify(tgen, topo, dut)
355 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
356
357 step("Clear ip bgp process with *")
358 result = clear_bgp_and_verify(tgen, topo, dut)
359 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
360
361 write_test_footer(tc_name)
362
363
364def test_bgp_unique_rid_multi_bgp_nbrs_vrf_p0():
365 """
366 TC: 3
367 Verify two different eBGP sessions initiated with same router ID in user VRf (RED and GREEN)
368
369 """
370 tgen = get_topogen()
371 global bgp_convergence, topo
372
373 if bgp_convergence is not True:
374 pytest.skip("skipped because of BGP Convergence failure")
375
376 # test case name
377 tc_name = inspect.stack()[0][3]
378 write_test_header(tc_name)
379 if tgen.routers_have_failure():
380 check_router_status(tgen)
381
382 step("Configure base config as per the topology")
383 reset_config_on_routers(tgen)
384
385 step(
386 "Base config should be up, verify using BGP convergence on all \
387 the routers for IPv4 and IPv6 nbrs"
388 )
389
390 result = verify_bgp_convergence(tgen, topo)
391 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
392
393 step("Configure the same router id between R3, R4 and R5 (10.10.10.10)")
394 input_dict = {
395 "r3": {"bgp": {"router_id": "10.10.10.10", "local_as": 100, "vrf": "RED"}},
396 "r4": {"bgp": {"router_id": "10.10.10.10", "local_as": 200, "vrf": "RED"}},
397 "r5": {"bgp": {"router_id": "10.10.10.10", "local_as": 300, "vrf": "RED"}},
398 }
399 result = create_router_bgp(tgen, topo, input_dict)
400 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
401
402 step("Verify neighbours are in ESTAB state.")
403 result = verify_bgp_convergence(tgen, topo)
404 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
405
406 step(
407 "Configure the same IP address on on R4 and R5 loopback address and \
408 change the neighborship to loopback neighbours between R3 to R4 \
409 and R3 to R5 respectively."
410 )
411
412 topo1 = deepcopy(topo)
413
414 for rtr in ["r4", "r5"]:
415 topo1["routers"][rtr]["links"]["lo"]["ipv4"] = "192.168.1.1/32"
416
417 topo1["routers"]["r3"]["links"]["lo"]["ipv4"] = "192.168.1.3/32"
418 build_config_from_json(tgen, topo1, save_bkup=False)
419
420 step(
421 "change the neighborship to loopback neighbours between R3 to R4 and R3 to R5 respectively."
422 )
423 for rtr in ["r4", "r5"]:
424 configure_bgp_on_rtr = {
425 "r3": {
426 "bgp": {
427 "local_as": 100,
428 "vrf": "RED",
429 "address_family": {
430 "ipv4": {
431 "unicast": {"neighbor": {rtr: {"dest_link": {"lo": {}}}}}
432 }
433 },
434 },
435 }
436 }
437 result = create_router_bgp(tgen, topo1, configure_bgp_on_rtr)
438 assert result is True, "Testcase {} : Failed \n Error: {}".format(
439 tc_name, result
440 )
441
442 bgp_convergence = verify_bgp_convergence(tgen, topo1, dut="r3")
443 assert bgp_convergence is True, "Testcase {} : Failed \n Error: {}".format(
444 tc_name, bgp_convergence
445 )
446
447 step("Change the IP address on the R4 loopback.")
448 topo1["routers"]["r4"]["links"]["lo"]["ipv4"] = "192.168.1.4/32"
449 build_config_from_json(tgen, topo1, save_bkup=False)
450
451 step("Verify neighbours should be again in ESTAB state. (show ip bgp neighbours)")
452 bgp_convergence = verify_bgp_convergence(tgen, topo1, dut="r3")
453 assert bgp_convergence is True, "Testcase {} : Failed \n Error: {}".format(
454 tc_name, bgp_convergence
455 )
456
457 step("Clear ip bgp process with *")
458 result = clear_bgp_and_verify(tgen, topo, router="r3")
459 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
460
461 write_test_footer(tc_name)
462
463
464if __name__ == "__main__":
465 args = ["-s"] + sys.argv[1:]
466 sys.exit(pytest.main(args))