]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_local_asn/test_bgp_local_asn_ecmp.py
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / tests / topotests / bgp_local_asn / test_bgp_local_asn_ecmp.py
1 #!/usr/bin/env python3
2 # SPDX-License-Identifier: ISC
3 #
4 # Copyright (c) 2022 by VMware, Inc. ("VMware")
5 # Used Copyright (c) 2018 by Network Device Education Foundation,
6 # Inc. ("NetDEF") in this file.
7 #
8 #
9 ##########################################################################################################################################
10 #
11 # Testcases
12 #
13 ###########################################################################################################################################
14 ###########################################################################################################################################
15 #
16 # 1.10.1.7. Verify the BGP Local AS functionality with ECMP on 8 links by adding no-prepend and replace-as command in between eBGP Peers.
17 #
18 #################################################################################################################################################
19
20 import os
21 import sys
22 import time
23 import pytest
24 import platform
25
26 # Save the Current Working Directory to find configuration files.
27 CWD = os.path.dirname(os.path.realpath(__file__))
28 sys.path.append(os.path.join(CWD, "../"))
29 sys.path.append(os.path.join(CWD, "../lib/"))
30
31 # pylint: disable=C0413
32 # Import topogen and topotest helpers
33 from lib.topogen import Topogen, get_topogen
34 from lib.topotest import version_cmp
35
36 from lib.common_config import (
37 start_topology,
38 write_test_header,
39 create_static_routes,
40 write_test_footer,
41 reset_config_on_routers,
42 verify_rib,
43 step,
44 check_address_types,
45 check_router_status,
46 create_static_routes,
47 verify_fib_routes,
48 )
49
50 from lib.topolog import logger
51 from lib.bgp import (
52 verify_bgp_convergence,
53 verify_bgp_rib,
54 create_router_bgp,
55 )
56 from lib.topojson import build_config_from_json
57
58 pytestmark = [pytest.mark.bgpd, pytest.mark.staticd]
59
60 # Global variables
61 BGP_CONVERGENCE = False
62 NETWORK = {"ipv4": "10.1.1.0/32", "ipv6": "10:1::1:0/128"}
63 NEXT_HOP_IP = {"ipv4": "Null0", "ipv6": "Null0"}
64
65
66 def setup_module(mod):
67 """
68 Sets up the pytest environment
69
70 * `mod`: module name
71 """
72
73 testsuite_run_time = time.asctime(time.localtime(time.time()))
74 logger.info("Testsuite start time: {}".format(testsuite_run_time))
75 logger.info("=" * 40)
76
77 logger.info("Running setup_module to create topology")
78
79 # This function initiates the topology build with Topogen...
80 json_file = "{}/bgp_local_asn_ecmp.json".format(CWD)
81 tgen = Topogen(json_file, mod.__name__)
82 global topo
83 topo = tgen.json_topo
84 # ... and here it calls Mininet initialization functions.
85
86 # Starting topology, create tmp files which are loaded to routers
87 # to start daemons and then start routers
88 start_topology(tgen)
89
90 # Creating configuration from JSON
91 build_config_from_json(tgen, topo)
92
93 global BGP_CONVERGENCE
94 global ADDR_TYPES
95 ADDR_TYPES = check_address_types()
96
97 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
98 assert BGP_CONVERGENCE is True, "setup_module : Failed \n Error: {}".format(
99 BGP_CONVERGENCE
100 )
101
102 logger.info("Running setup_module() done")
103
104
105 def teardown_module():
106 """Teardown the pytest environment"""
107
108 logger.info("Running teardown_module to delete topology")
109
110 tgen = get_topogen()
111
112 # Stop toplogy and Remove tmp files
113 tgen.stop_topology()
114
115 logger.info(
116 "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
117 )
118 logger.info("=" * 40)
119
120
121 ##########################################################################################################################################
122 #
123 # Testcases
124 #
125 ###########################################################################################################################################
126
127
128 def test_verify_bgp_local_as_in_ecmp_EBGP_p0(request):
129 """
130 Verify the BGP Local AS functionality with ECMP on 8 links by
131 adding no-prepend and replace-as command in between eBGP Peers.
132 """
133
134 tgen = get_topogen()
135 global BGP_CONVERGENCE
136 if BGP_CONVERGENCE != True:
137 pytest.skip("skipped because of BGP Convergence failure")
138 # test case name
139 tc_name = request.node.name
140 write_test_header(tc_name)
141 if tgen.routers_have_failure():
142 check_router_status(tgen)
143 reset_config_on_routers(tgen)
144
145 step("Base config is done as part of JSON")
146 dut = "r1"
147 for addr_type in ADDR_TYPES:
148 # Enable static routes
149 input_dict_static_route = {
150 "r1": {
151 "static_routes": [
152 {"network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type]}
153 ]
154 }
155 }
156
157 logger.info("Configure static routes")
158 result = create_static_routes(tgen, input_dict_static_route)
159 assert result is True, "Testcase {} : Failed \n Error: {}".format(
160 tc_name, result
161 )
162
163 step("configure redistribute static in Router BGP in R1")
164 input_dict_static_route_redist = {
165 "r1": {
166 "bgp": [
167 {
168 "address_family": {
169 addr_type: {
170 "unicast": {"redistribute": [{"redist_type": "static"}]}
171 }
172 }
173 }
174 ]
175 }
176 }
177 result = create_router_bgp(tgen, topo, input_dict_static_route_redist)
178 assert result is True, "Testcase {} : Failed \n Error: {}".format(
179 tc_name, result
180 )
181
182 step("Verify IPv4 and IPv6 static routes received on R1")
183 result = verify_rib(tgen, addr_type, "r1", input_dict_static_route)
184 assert result is True, "Testcase {}: Failed \n Error: {}".format(
185 tc_name, result
186 )
187 result = verify_bgp_rib(tgen, addr_type, "r1", input_dict_static_route)
188 assert result is True, "Testcase {} : Failed \n Error: {}".format(
189 tc_name, result
190 )
191 result = verify_fib_routes(tgen, addr_type, "r1", input_dict_static_route)
192 assert result is True, "Testcase {} : Failed \n Error: {}".format(
193 tc_name, result
194 )
195
196 step("Configure local-as at R3 towards R2.")
197 for addr_type in ADDR_TYPES:
198 input_dict_r3_to_r2 = {
199 "r3": {
200 "bgp": [
201 {
202 "local_as": "300",
203 "address_family": {
204 addr_type: {
205 "unicast": {
206 "neighbor": {
207 "r2": {
208 "dest_link": {
209 "r3-link1": {
210 "local_asn": {"local_as": "110"}
211 }
212 }
213 }
214 }
215 }
216 }
217 },
218 }
219 ]
220 }
221 }
222 result = create_router_bgp(tgen, topo, input_dict_r3_to_r2)
223 assert result is True, "Testcase {} :Failed \n Error: {}".format(
224 tc_name, result
225 )
226
227 step("Configure local-as at R3 towards R4.")
228 dest_link = {}
229 for link_no in range(1, 9):
230 link = "r3-link" + str(link_no)
231 dest_link[link] = {"local_asn": {"local_as": "110"}}
232 for addr_type in ADDR_TYPES:
233 input_dict_r3_to_r4 = {
234 "r3": {
235 "bgp": [
236 {
237 "local_as": "300",
238 "address_family": {
239 addr_type: {
240 "unicast": {
241 "neighbor": {"r4": {"dest_link": dest_link}}
242 }
243 }
244 },
245 }
246 ]
247 }
248 }
249 result = create_router_bgp(tgen, topo, input_dict_r3_to_r4)
250 assert result is True, "Testcase {} :Failed \n Error: {}".format(
251 tc_name, result
252 )
253
254 step("Configure remote-as at R2 towards R3.")
255 for addr_type in ADDR_TYPES:
256 input_dict_r2_to_r3 = {
257 "r2": {
258 "bgp": [
259 {
260 "local_as": "200",
261 "address_family": {
262 addr_type: {
263 "unicast": {
264 "neighbor": {
265 "r3": {
266 "dest_link": {
267 "r2-link1": {
268 "local_asn": {"remote_as": "110"}
269 }
270 }
271 }
272 }
273 }
274 }
275 },
276 }
277 ]
278 }
279 }
280 result = create_router_bgp(tgen, topo, input_dict_r2_to_r3)
281 assert result is True, "Testcase {} :Failed \n Error: {}".format(
282 tc_name, result
283 )
284
285 step("Configure remote-as at R4 towards R3.")
286 dest_link = {}
287 for link_no in range(1, 9):
288 link = "r4-link" + str(link_no)
289 dest_link[link] = {"local_asn": {"remote_as": "110"}}
290 for addr_type in ADDR_TYPES:
291 input_dict_r4_to_r3 = {
292 "r4": {
293 "bgp": [
294 {
295 "local_as": "400",
296 "address_family": {
297 addr_type: {
298 "unicast": {
299 "neighbor": {"r3": {"dest_link": dest_link}}
300 }
301 }
302 },
303 }
304 ]
305 }
306 }
307 result = create_router_bgp(tgen, topo, input_dict_r4_to_r3)
308 assert result is True, "Testcase {} :Failed \n Error: {}".format(
309 tc_name, result
310 )
311
312 step("BGP neighborship is verified by following commands in R3 routers")
313 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
314 assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format(
315 BGP_CONVERGENCE
316 )
317
318 step("Verify IPv4 and IPv6 static routes received on R3 & R4")
319 for addr_type in ADDR_TYPES:
320 static_routes_input = {
321 "r1": {
322 "static_routes": [
323 {"network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type]}
324 ]
325 }
326 }
327 for dut in ["r3", "r4"]:
328 result = verify_fib_routes(tgen, addr_type, dut, static_routes_input)
329 assert result is True, "Testcase {} : Failed \n Error: {}".format(
330 tc_name, result
331 )
332
333 result = verify_bgp_rib(tgen, addr_type, dut, static_routes_input)
334 assert result is True, "Testcase {} : Failed \n Error: {}".format(
335 tc_name, result
336 )
337
338 step(
339 "Verify that AS-110 is got added in the AS list 110 200 100 by following "
340 " commands at R3 router."
341 )
342 dut = "r3"
343 aspath = "110 200 100"
344 for addr_type in ADDR_TYPES:
345 input_static_r1 = {"r1": {"static_routes": [{"network": NETWORK[addr_type]}]}}
346 result = verify_bgp_rib(tgen, addr_type, dut, input_static_r1, aspath=aspath)
347 assert result is True, "Testcase {} : Failed \n Error: {}".format(
348 tc_name, result
349 )
350
351 step("Configure local-as with no-prepend at R3 towards R2.")
352 for addr_type in ADDR_TYPES:
353 input_dict_no_prep_r3_to_r2 = {
354 "r3": {
355 "bgp": [
356 {
357 "local_as": "300",
358 "address_family": {
359 addr_type: {
360 "unicast": {
361 "neighbor": {
362 "r2": {
363 "dest_link": {
364 "r3-link1": {
365 "local_asn": {
366 "local_as": "110",
367 "no_prepend": True,
368 }
369 }
370 }
371 }
372 }
373 }
374 }
375 },
376 }
377 ]
378 }
379 }
380 result = create_router_bgp(tgen, topo, input_dict_no_prep_r3_to_r2)
381 assert result is True, "Testcase {} :Failed \n Error: {}".format(
382 tc_name, result
383 )
384
385 step("Configure local-as with no-prepend at R3 towards R4.")
386 dest_link = {}
387 for link_no in range(1, 9):
388 link = "r3-link" + str(link_no)
389 dest_link[link] = {"local_asn": {"local_as": "110"}}
390 for addr_type in ADDR_TYPES:
391 input_dict_no_prep_r3_to_r4 = {
392 "r3": {
393 "bgp": [
394 {
395 "local_as": "300",
396 "address_family": {
397 addr_type: {
398 "unicast": {
399 "neighbor": {"r4": {"dest_link": dest_link}}
400 }
401 }
402 },
403 }
404 ]
405 }
406 }
407 result = create_router_bgp(tgen, topo, input_dict_no_prep_r3_to_r4)
408 assert result is True, "Testcase {} :Failed \n Error: {}".format(
409 tc_name, result
410 )
411
412 step("BGP neighborship is verified by following commands in R3 routers")
413 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
414 assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format(
415 BGP_CONVERGENCE
416 )
417
418 dut = "r3"
419 aspath = "200 100"
420 for addr_type in ADDR_TYPES:
421 input_static_r1 = {"r2": {"static_routes": [{"network": NETWORK[addr_type]}]}}
422 result = verify_bgp_rib(tgen, addr_type, dut, input_static_r1, aspath=aspath)
423 assert result is True, "Testcase {} : Failed \n Error: {}".format(
424 tc_name, result
425 )
426
427 step("Configure local-as with no-prepend and replace-as at R3 towards R2")
428 for addr_type in ADDR_TYPES:
429 input_dict_no_prep_rep_as_r3_to_r2 = {
430 "r3": {
431 "bgp": [
432 {
433 "local_as": "300",
434 "address_family": {
435 addr_type: {
436 "unicast": {
437 "neighbor": {
438 "r2": {
439 "dest_link": {
440 "r3-link1": {
441 "local_asn": {
442 "local_as": "110",
443 "no_prepend": True,
444 "replace_as": True,
445 }
446 }
447 }
448 }
449 }
450 }
451 }
452 },
453 }
454 ]
455 }
456 }
457 result = create_router_bgp(tgen, topo, input_dict_no_prep_rep_as_r3_to_r2)
458 assert result is True, "Testcase {} :Failed \n Error: {}".format(
459 tc_name, result
460 )
461
462 step("Configure local-as with no-prepend and replace-as at R3 towards R4")
463 dest_link = {}
464 for link_no in range(1, 9):
465 link = "r3-link" + str(link_no)
466 dest_link[link] = {
467 "local_asn": {"local_as": "110", "no_prepend": True, "replace_as": True}
468 }
469 for addr_type in ADDR_TYPES:
470 input_dict_no_prep_rep_as_r3_to_r4 = {
471 "r3": {
472 "bgp": [
473 {
474 "local_as": "300",
475 "address_family": {
476 addr_type: {
477 "unicast": {
478 "neighbor": {"r4": {"dest_link": dest_link}}
479 }
480 }
481 },
482 }
483 ]
484 }
485 }
486 result = create_router_bgp(tgen, topo, input_dict_no_prep_rep_as_r3_to_r4)
487 assert result is True, "Testcase {} :Failed \n Error: {}".format(
488 tc_name, result
489 )
490
491 step("BGP neighborship is verified by following commands in R3 routers")
492 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
493 assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format(
494 BGP_CONVERGENCE
495 )
496
497 dut = "r4"
498 aspath = "110 200 100"
499 for addr_type in ADDR_TYPES:
500 input_static_r1 = {"r1": {"static_routes": [{"network": NETWORK[addr_type]}]}}
501 result = verify_bgp_rib(tgen, addr_type, dut, input_static_r1, aspath=aspath)
502 assert result is True, "Testcase {} : Failed \n Error: {}".format(
503 tc_name, result
504 )
505
506 write_test_footer(tc_name)
507
508
509 if __name__ == "__main__":
510 args = ["-s"] + sys.argv[1:]
511 sys.exit(pytest.main(args))