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