]>
Commit | Line | Data |
---|---|---|
27d9695d AP |
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 | """ | |
25 | Following tests are covered to test ecmp functionality on EBGP. | |
26 | 1. Verify routes installed as per maximum-paths configuration (8/16/32) | |
27 | 2. Disable/Shut selected paths nexthops and verify other next are installed in | |
28 | the RIB of DUT. Enable interfaces and verify RIB count. | |
29 | 3. Verify BGP table and RIB in DUT after clear BGP routes and neighbors. | |
30 | 4. Verify routes are cleared from BGP and RIB table of DUT when | |
31 | redistribute static configuration is removed. | |
32 | 5. Shut BGP neigbors one by one and verify BGP and routing table updated | |
33 | accordingly in DUT | |
34 | 6. Delete static routes and verify routers are cleared from BGP table and RIB | |
35 | of DUT. | |
36 | 7. Verify routes are cleared from BGP and RIB table of DUT when advertise | |
37 | network configuration is removed. | |
38 | """ | |
39 | import os | |
40 | import sys | |
41 | import time | |
42 | import json | |
43 | import pytest | |
44 | # Save the Current Working Directory to find configuration files. | |
45 | CWD = os.path.dirname(os.path.realpath(__file__)) | |
46 | sys.path.append(os.path.join(CWD, '../')) | |
47 | sys.path.append(os.path.join(CWD, '../../')) | |
48 | ||
49 | # pylint: disable=C0413 | |
50 | # Import topogen and topotest helpers | |
51 | from lib.topogen import Topogen, get_topogen | |
52 | from mininet.topo import Topo | |
53 | ||
54 | from lib.common_config import ( | |
55 | start_topology, write_test_header, | |
56 | write_test_footer, | |
57 | verify_rib, create_static_routes, check_address_types, | |
58 | interface_status, reset_config_on_routers | |
59 | ) | |
60 | from lib.topolog import logger | |
61 | from lib.bgp import ( | |
62 | verify_bgp_convergence, create_router_bgp, | |
63 | clear_bgp_and_verify) | |
64 | from lib.topojson import build_topo_from_json, build_config_from_json | |
65 | ||
66 | # Reading the data from JSON File for topology and configuration creation | |
67 | jsonFile = "{}/ibgp_ecmp_topo2.json".format(CWD) | |
68 | ||
69 | try: | |
70 | with open(jsonFile, "r") as topoJson: | |
71 | topo = json.load(topoJson) | |
72 | except IOError: | |
73 | assert False, "Could not read file {}".format(jsonFile) | |
74 | ||
75 | # Global variables | |
76 | NEXT_HOPS = {"ipv4": [], "ipv6": []} | |
77 | INTF_LIST_R3 = [] | |
78 | INTF_LIST_R2 = [] | |
79 | NETWORK = {"ipv4": "11.0.20.1/32", "ipv6": "1::/64"} | |
80 | NEXT_HOP_IP = {"ipv4": "10.0.0.1", "ipv6": "fd00::1"} | |
81 | BGP_CONVERGENCE = False | |
82 | ||
83 | ||
84 | class CreateTopo(Topo): | |
85 | """ | |
86 | Test topology builder. | |
87 | ||
88 | * `Topo`: Topology object | |
89 | """ | |
90 | ||
91 | def build(self, *_args, **_opts): | |
92 | """Build function.""" | |
93 | tgen = get_topogen(self) | |
94 | ||
95 | # Building topology from json file | |
96 | build_topo_from_json(tgen, topo) | |
97 | ||
98 | ||
99 | def setup_module(mod): | |
100 | """ | |
101 | Sets up the pytest environment. | |
102 | ||
103 | * `mod`: module name | |
104 | """ | |
105 | global NEXT_HOPS, INTF_LIST_R3, INTF_LIST_R2, TEST_STATIC | |
106 | global ADDR_TYPES | |
107 | ||
108 | testsuite_run_time = time.asctime(time.localtime(time.time())) | |
109 | logger.info("Testsuite start time: {}".format(testsuite_run_time)) | |
110 | logger.info("=" * 40) | |
111 | ||
112 | logger.info("Running setup_module to create topology") | |
113 | ||
114 | # This function initiates the topology build with Topogen... | |
115 | tgen = Topogen(CreateTopo, mod.__name__) | |
116 | ||
117 | # Starting topology, create tmp files which are loaded to routers | |
118 | # to start deamons and then start routers | |
119 | start_topology(tgen) | |
120 | ||
121 | # Creating configuration from JSON | |
122 | build_config_from_json(tgen, topo) | |
123 | ||
124 | # Don't run this test if we have any failure. | |
125 | if tgen.routers_have_failure(): | |
126 | pytest.skip(tgen.errors) | |
127 | ||
128 | # tgen.mininet_cli() | |
129 | # Api call verify whether BGP is converged | |
130 | ADDR_TYPES = check_address_types() | |
131 | ||
132 | for addr_type in ADDR_TYPES: | |
133 | BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo) | |
134 | assert BGP_CONVERGENCE is True, ("setup_module :Failed \n Error:" | |
135 | " {}".format(BGP_CONVERGENCE)) | |
136 | ||
137 | link_data = [val for links, val in | |
138 | topo["routers"]["r2"]["links"].iteritems() | |
139 | if "r3" in links] | |
140 | for adt in ADDR_TYPES: | |
141 | NEXT_HOPS[adt] = [val[adt].split("/")[0] for val in link_data] | |
142 | if adt == "ipv4": | |
143 | NEXT_HOPS[adt] = sorted( | |
144 | NEXT_HOPS[adt], key=lambda x: int(x.split(".")[2])) | |
145 | elif adt == "ipv6": | |
146 | NEXT_HOPS[adt] = sorted( | |
147 | NEXT_HOPS[adt], key=lambda x: int(x.split(':')[-3], 16)) | |
148 | ||
149 | INTF_LIST_R2 = [val["interface"].split("/")[0] for val in link_data] | |
150 | INTF_LIST_R2 = sorted(INTF_LIST_R2, key=lambda x: int(x.split("eth")[1])) | |
151 | ||
152 | link_data = [val for links, val in | |
153 | topo["routers"]["r3"]["links"].iteritems() | |
154 | if "r2" in links] | |
155 | INTF_LIST_R3 = [val["interface"].split("/")[0] for val in link_data] | |
156 | INTF_LIST_R3 = sorted(INTF_LIST_R3, key=lambda x: int(x.split("eth")[1])) | |
157 | ||
158 | # STATIC_ROUTE = True | |
159 | logger.info("Running setup_module() done") | |
160 | ||
161 | ||
162 | def teardown_module(): | |
163 | """ | |
164 | Teardown the pytest environment. | |
165 | ||
166 | * `mod`: module name | |
167 | """ | |
168 | ||
169 | logger.info("Running teardown_module to delete topology") | |
170 | ||
171 | tgen = get_topogen() | |
172 | ||
173 | # Stop toplogy and Remove tmp files | |
174 | tgen.stop_topology() | |
175 | ||
176 | ||
177 | def static_or_nw(tgen, topo, tc_name, test_type, dut): | |
178 | ||
179 | if test_type == "redist_static": | |
180 | input_dict_static = { | |
181 | dut: { | |
182 | "static_routes": [ | |
183 | { | |
184 | "network": NETWORK["ipv4"], | |
185 | "next_hop": NEXT_HOP_IP["ipv4"] | |
186 | }, | |
187 | { | |
188 | "network": NETWORK["ipv6"], | |
189 | "next_hop": NEXT_HOP_IP["ipv6"] | |
190 | } | |
191 | ] | |
192 | } | |
193 | } | |
194 | logger.info("Configuring static route on router %s", dut) | |
195 | result = create_static_routes(tgen, input_dict_static) | |
196 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
197 | tc_name, result) | |
198 | ||
199 | input_dict_2 = { | |
200 | dut: { | |
201 | "bgp": { | |
202 | "address_family": { | |
203 | "ipv4": { | |
204 | "unicast": { | |
205 | "redistribute": [{ | |
206 | "redist_type": "static" | |
207 | }] | |
208 | } | |
209 | }, | |
210 | "ipv6": { | |
211 | "unicast": { | |
212 | "redistribute": [{ | |
213 | "redist_type": "static" | |
214 | }] | |
215 | } | |
216 | } | |
217 | } | |
218 | } | |
219 | } | |
220 | } | |
221 | ||
222 | logger.info("Configuring redistribute static route on router %s", dut) | |
223 | result = create_router_bgp(tgen, topo, input_dict_2) | |
224 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
225 | tc_name, result) | |
226 | ||
227 | elif test_type == "advertise_nw": | |
228 | input_dict_nw = { | |
229 | dut: { | |
230 | "bgp": { | |
231 | "address_family": { | |
232 | "ipv4": { | |
233 | "unicast": { | |
234 | "advertise_networks": [ | |
235 | {"network": NETWORK["ipv4"]} | |
236 | ] | |
237 | } | |
238 | }, | |
239 | "ipv6": { | |
240 | "unicast": { | |
241 | "advertise_networks": [ | |
242 | {"network": NETWORK["ipv6"]} | |
243 | ] | |
244 | } | |
245 | } | |
246 | } | |
247 | } | |
248 | } | |
249 | } | |
250 | ||
251 | logger.info("Advertising networks %s %s from router %s", | |
252 | NETWORK["ipv4"], NETWORK["ipv6"], dut) | |
253 | result = create_router_bgp(tgen, topo, input_dict_nw) | |
254 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
255 | tc_name, result) | |
256 | ||
257 | ||
258 | @pytest.mark.parametrize("ecmp_num", ["8", "16", "32"]) | |
259 | @pytest.mark.parametrize("test_type", ["redist_static", "advertise_nw"]) | |
260 | def test_modify_ecmp_max_paths(request, ecmp_num, test_type): | |
261 | """ | |
262 | Verify routes installed as per maximum-paths | |
263 | configuration (8/16/32). | |
264 | """ | |
265 | ||
266 | tc_name = request.node.name | |
267 | write_test_header(tc_name) | |
268 | tgen = get_topogen() | |
269 | ||
270 | reset_config_on_routers(tgen) | |
271 | ||
272 | static_or_nw(tgen, topo, tc_name, test_type, "r2") | |
273 | ||
274 | input_dict = { | |
275 | "r3": { | |
276 | "bgp": { | |
277 | "address_family": { | |
278 | "ipv4": { | |
279 | "unicast": { | |
280 | "maximum_paths": { | |
281 | "ibgp": ecmp_num, | |
282 | } | |
283 | } | |
284 | }, | |
285 | "ipv6": { | |
286 | "unicast": { | |
287 | "maximum_paths": { | |
288 | "ibgp": ecmp_num, | |
289 | } | |
290 | } | |
291 | } | |
292 | } | |
293 | } | |
294 | } | |
295 | } | |
296 | ||
297 | logger.info("Configuring bgp maximum-paths %s on router r3", ecmp_num) | |
298 | result = create_router_bgp(tgen, topo, input_dict) | |
299 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
300 | tc_name, result) | |
301 | ||
302 | # Verifying RIB routes | |
303 | dut = "r3" | |
304 | protocol = "bgp" | |
305 | ||
306 | for addr_type in ADDR_TYPES: | |
307 | input_dict_1 = { | |
308 | "r3": { | |
309 | "static_routes": [ | |
310 | { | |
311 | "network": NETWORK[addr_type] | |
312 | } | |
313 | ] | |
314 | } | |
315 | } | |
316 | ||
317 | logger.info("Verifying %s routes on r3", addr_type) | |
318 | result = verify_rib(tgen, addr_type, dut, input_dict_1, | |
319 | next_hop=NEXT_HOPS[addr_type], | |
320 | protocol=protocol) | |
321 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
322 | tc_name, result) | |
323 | ||
324 | write_test_footer(tc_name) | |
325 | ||
326 | ||
327 | def test_ecmp_after_clear_bgp(request): | |
328 | """ Verify BGP table and RIB in DUT after clear BGP routes and neighbors""" | |
329 | ||
330 | tc_name = request.node.name | |
331 | write_test_header(tc_name) | |
332 | tgen = get_topogen() | |
333 | ||
334 | reset_config_on_routers(tgen) | |
335 | ||
336 | # Verifying RIB routes | |
337 | dut = "r3" | |
338 | protocol = "bgp" | |
339 | ||
340 | static_or_nw(tgen, topo, tc_name, "redist_static", "r2") | |
341 | for addr_type in ADDR_TYPES: | |
342 | input_dict_1 = { | |
343 | "r3": { | |
344 | "static_routes": [ | |
345 | { | |
346 | "network": NETWORK[addr_type] | |
347 | } | |
348 | ] | |
349 | } | |
350 | } | |
351 | ||
352 | logger.info("Verifying %s routes on r3", addr_type) | |
353 | result = verify_rib(tgen, addr_type, dut, input_dict_1, | |
354 | next_hop=NEXT_HOPS[addr_type], | |
355 | protocol=protocol) | |
356 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
357 | tc_name, result) | |
358 | ||
359 | # Clear bgp | |
360 | result = clear_bgp_and_verify(tgen, topo, dut) | |
361 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
362 | tc_name, result) | |
363 | ||
364 | for addr_type in ADDR_TYPES: | |
365 | input_dict_1 = { | |
366 | "r3": { | |
367 | "static_routes": [ | |
368 | { | |
369 | "network": NETWORK[addr_type] | |
370 | } | |
371 | ] | |
372 | } | |
373 | } | |
374 | logger.info("Verifying %s routes on r3", addr_type) | |
375 | result = verify_rib(tgen, addr_type, dut, input_dict_1, | |
376 | next_hop=NEXT_HOPS[addr_type], | |
377 | protocol=protocol) | |
378 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
379 | tc_name, result) | |
380 | ||
381 | write_test_footer(tc_name) | |
382 | ||
383 | ||
384 | def test_ecmp_remove_redistribute_static(request): | |
385 | """ Verify routes are cleared from BGP and RIB table of DUT when | |
386 | redistribute static configuration is removed.""" | |
387 | ||
388 | tc_name = request.node.name | |
389 | write_test_header(tc_name) | |
390 | tgen = get_topogen() | |
391 | ||
392 | reset_config_on_routers(tgen) | |
393 | static_or_nw(tgen, topo, tc_name, "redist_static", "r2") | |
394 | for addr_type in ADDR_TYPES: | |
395 | ||
396 | # Verifying RIB routes | |
397 | dut = "r3" | |
398 | protocol = "bgp" | |
399 | input_dict_1 = { | |
400 | "r3": { | |
401 | "static_routes": [ | |
402 | { | |
403 | "network": NETWORK[addr_type] | |
404 | } | |
405 | ] | |
406 | } | |
407 | } | |
408 | ||
409 | logger.info("Verifying %s routes on r3", addr_type) | |
410 | result = verify_rib(tgen, addr_type, dut, input_dict_1, | |
411 | next_hop=NEXT_HOPS[addr_type], | |
412 | protocol=protocol) | |
413 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
414 | tc_name, result) | |
415 | ||
416 | input_dict_2 = { | |
417 | "r2": { | |
418 | "bgp": { | |
419 | "address_family": { | |
420 | "ipv4": { | |
421 | "unicast": { | |
422 | "redistribute": [{ | |
423 | "redist_type": "static", | |
424 | "delete": True | |
425 | ||
426 | }] | |
427 | } | |
428 | }, | |
429 | "ipv6": { | |
430 | "unicast": { | |
431 | "redistribute": [{ | |
432 | "redist_type": "static", | |
433 | "delete": True | |
434 | ||
435 | }] | |
436 | } | |
437 | } | |
438 | } | |
439 | } | |
440 | } | |
441 | } | |
442 | ||
443 | logger.info("Remove redistribute static") | |
444 | result = create_router_bgp(tgen, topo, input_dict_2) | |
445 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
446 | tc_name, result) | |
447 | ||
448 | for addr_type in ADDR_TYPES: | |
449 | ||
450 | # Verifying RIB routes | |
451 | dut = "r3" | |
452 | protocol = "bgp" | |
453 | input_dict_1 = { | |
454 | "r3": { | |
455 | "static_routes": [ | |
456 | { | |
457 | "network": NETWORK[addr_type] | |
458 | } | |
459 | ] | |
460 | } | |
461 | } | |
462 | ||
463 | logger.info("Verifying %s routes on r3 are deleted", addr_type) | |
464 | result = verify_rib(tgen, addr_type, dut, input_dict_1, | |
465 | next_hop=[], protocol=protocol, expected=False) | |
466 | assert result is not True, "Testcase {} : Failed \n Routes still" \ | |
467 | " present in RIB".format(tc_name) | |
468 | ||
469 | logger.info("Enable redistribute static") | |
470 | input_dict_2 = { | |
471 | "r2": { | |
472 | "bgp": { | |
473 | "address_family": { | |
474 | "ipv4": { | |
475 | "unicast": { | |
476 | "redistribute": [{ | |
477 | "redist_type": "static" | |
478 | }] | |
479 | } | |
480 | }, | |
481 | "ipv6": { | |
482 | "unicast": { | |
483 | "redistribute": [{ | |
484 | "redist_type": "static" | |
485 | }] | |
486 | } | |
487 | } | |
488 | } | |
489 | } | |
490 | } | |
491 | } | |
492 | result = create_router_bgp(tgen, topo, input_dict_2) | |
493 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
494 | tc_name, result) | |
495 | ||
496 | for addr_type in ADDR_TYPES: | |
497 | # Verifying RIB routes | |
498 | dut = "r3" | |
499 | protocol = "bgp" | |
500 | input_dict_1 = { | |
501 | "r3": { | |
502 | "static_routes": [ | |
503 | { | |
504 | "network": NETWORK[addr_type] | |
505 | } | |
506 | ] | |
507 | } | |
508 | } | |
509 | logger.info("Verifying %s routes on r3", addr_type) | |
510 | result = verify_rib(tgen, addr_type, dut, input_dict_1, | |
511 | next_hop=NEXT_HOPS[addr_type], | |
512 | protocol=protocol) | |
513 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
514 | tc_name, result) | |
515 | ||
516 | write_test_footer(tc_name) | |
517 | ||
518 | ||
519 | def test_ecmp_shut_bgp_neighbor(request): | |
520 | """ Shut BGP neigbors one by one and verify BGP and routing table updated | |
521 | accordingly in DUT """ | |
522 | ||
523 | tc_name = request.node.name | |
524 | write_test_header(tc_name) | |
525 | tgen = get_topogen() | |
526 | ||
527 | logger.info(INTF_LIST_R2) | |
528 | # Verifying RIB routes | |
529 | dut = "r3" | |
530 | protocol = "bgp" | |
531 | ||
532 | reset_config_on_routers(tgen) | |
533 | static_or_nw(tgen, topo, tc_name, "redist_static", "r2") | |
534 | ||
535 | for addr_type in ADDR_TYPES: | |
536 | input_dict = { | |
537 | "r3": { | |
538 | "static_routes": [ | |
539 | { | |
540 | "network": NETWORK[addr_type] | |
541 | } | |
542 | ] | |
543 | } | |
544 | } | |
545 | ||
546 | logger.info("Verifying %s routes on r3", addr_type) | |
547 | result = verify_rib(tgen, addr_type, dut, input_dict, | |
548 | next_hop=NEXT_HOPS[addr_type], | |
549 | protocol=protocol) | |
550 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
551 | tc_name, result) | |
552 | ||
553 | for intf_num in range(len(INTF_LIST_R2)+1, 16): | |
554 | intf_val = INTF_LIST_R2[intf_num:intf_num+16] | |
555 | ||
556 | input_dict_1 = { | |
557 | "r2": { | |
558 | "interface_list": [intf_val], | |
559 | "status": "down" | |
560 | } | |
561 | } | |
562 | logger.info("Shutting down neighbor interface {} on r2". | |
563 | format(intf_val)) | |
564 | result = interface_status(tgen, topo, input_dict_1) | |
565 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
566 | tc_name, result) | |
567 | ||
568 | for addr_type in ADDR_TYPES: | |
569 | if intf_num + 16 < 32: | |
570 | check_hops = NEXT_HOPS[addr_type] | |
571 | else: | |
572 | check_hops = [] | |
573 | ||
574 | input_dict = { | |
575 | "r3": { | |
576 | "static_routes": [ | |
577 | { | |
578 | "network": NETWORK[addr_type] | |
579 | } | |
580 | ] | |
581 | } | |
582 | } | |
583 | logger.info("Verifying %s routes on r3", addr_type) | |
584 | result = verify_rib(tgen, addr_type, dut, input_dict, | |
585 | next_hop=check_hops, | |
586 | protocol=protocol) | |
587 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
588 | tc_name, result) | |
589 | ||
590 | input_dict_1 = { | |
591 | "r2": { | |
592 | "interface_list": INTF_LIST_R2, | |
593 | "status": "up" | |
594 | } | |
595 | } | |
596 | ||
597 | logger.info("Enabling all neighbor interface {} on r2") | |
598 | result = interface_status(tgen, topo, input_dict_1) | |
599 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
600 | tc_name, result) | |
601 | ||
602 | static_or_nw(tgen, topo, tc_name, "redist_static", "r2") | |
603 | for addr_type in ADDR_TYPES: | |
604 | input_dict = { | |
605 | "r3": { | |
606 | "static_routes": [ | |
607 | { | |
608 | "network": NETWORK[addr_type] | |
609 | } | |
610 | ] | |
611 | } | |
612 | } | |
613 | ||
614 | logger.info("Verifying %s routes on r3", addr_type) | |
615 | result = verify_rib(tgen, addr_type, dut, input_dict, | |
616 | next_hop=NEXT_HOPS[addr_type], | |
617 | protocol=protocol) | |
618 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
619 | tc_name, result) | |
620 | ||
621 | write_test_footer(tc_name) | |
622 | ||
623 | ||
624 | def test_ecmp_remove_static_route(request): | |
625 | """ | |
626 | Delete static routes and verify routers are cleared from BGP table, | |
627 | and RIB of DUT. | |
628 | """ | |
629 | ||
630 | tc_name = request.node.name | |
631 | write_test_header(tc_name) | |
632 | tgen = get_topogen() | |
633 | ||
634 | # Verifying RIB routes | |
635 | dut = "r3" | |
636 | protocol = "bgp" | |
637 | ||
638 | reset_config_on_routers(tgen) | |
639 | ||
640 | static_or_nw(tgen, topo, tc_name, "redist_static", "r2") | |
641 | for addr_type in ADDR_TYPES: | |
642 | input_dict_1 = { | |
643 | "r3": { | |
644 | "static_routes": [ | |
645 | { | |
646 | "network": NETWORK[addr_type] | |
647 | } | |
648 | ] | |
649 | } | |
650 | } | |
651 | ||
652 | logger.info("Verifying %s routes on r3", addr_type) | |
653 | result = verify_rib( | |
654 | tgen, addr_type, dut, input_dict_1, | |
655 | next_hop=NEXT_HOPS[addr_type], protocol=protocol) | |
656 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
657 | tc_name, result) | |
658 | ||
659 | for addr_type in ADDR_TYPES: | |
660 | input_dict_2 = { | |
661 | "r2": { | |
662 | "static_routes": [ | |
663 | { | |
664 | "network": NETWORK[addr_type], | |
665 | "next_hop": NEXT_HOP_IP[addr_type], | |
666 | "delete": True | |
667 | } | |
668 | ] | |
669 | } | |
670 | } | |
671 | ||
672 | logger.info("Remove static routes") | |
673 | result = create_static_routes(tgen, input_dict_2) | |
674 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
675 | tc_name, result) | |
676 | ||
677 | logger.info("Verifying %s routes on r3 are removed", addr_type) | |
678 | result = verify_rib(tgen, addr_type, dut, input_dict_2, | |
679 | next_hop=[], protocol=protocol, expected=False) | |
680 | assert result is not True, "Testcase {} : Failed \n Routes still" \ | |
681 | " present in RIB".format(tc_name) | |
682 | ||
683 | for addr_type in ADDR_TYPES: | |
684 | # Enable static routes | |
685 | input_dict_4 = { | |
686 | "r2": { | |
687 | "static_routes": [ | |
688 | { | |
689 | "network": NETWORK[addr_type], | |
690 | "next_hop": NEXT_HOP_IP[addr_type] | |
691 | } | |
692 | ] | |
693 | } | |
694 | } | |
695 | ||
696 | logger.info("Enable static route") | |
697 | result = create_static_routes(tgen, input_dict_4) | |
698 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
699 | tc_name, result) | |
700 | ||
701 | logger.info("Verifying %s routes on r3", addr_type) | |
702 | result = verify_rib(tgen, addr_type, dut, input_dict_4, | |
703 | next_hop=NEXT_HOPS[addr_type], | |
704 | protocol=protocol) | |
705 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
706 | tc_name, result) | |
707 | ||
708 | write_test_footer(tc_name) | |
709 | ||
710 | ||
711 | def test_ecmp_remove_nw_advertise(request): | |
712 | """ | |
713 | Verify routes are cleared from BGP and RIB table of DUT, | |
714 | when advertise network configuration is removed | |
715 | """ | |
716 | ||
717 | tc_name = request.node.name | |
718 | write_test_header(tc_name) | |
719 | tgen = get_topogen() | |
720 | ||
721 | # Verifying RIB routes | |
722 | dut = "r3" | |
723 | protocol = "bgp" | |
724 | ||
725 | reset_config_on_routers(tgen) | |
726 | static_or_nw(tgen, topo, tc_name, "advertise_nw", "r2") | |
727 | for addr_type in ADDR_TYPES: | |
728 | input_dict = { | |
729 | "r3": { | |
730 | "static_routes": [ | |
731 | { | |
732 | "network": NETWORK[addr_type] | |
733 | } | |
734 | ] | |
735 | } | |
736 | } | |
737 | ||
738 | logger.info("Verifying %s routes on r3", addr_type) | |
739 | result = verify_rib(tgen, addr_type, dut, input_dict, | |
740 | next_hop=NEXT_HOPS[addr_type], | |
741 | protocol=protocol) | |
742 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
743 | tc_name, result) | |
744 | ||
745 | input_dict_3 = { | |
746 | "r2": { | |
747 | "bgp": { | |
748 | "address_family": { | |
749 | "ipv4": { | |
750 | "unicast": { | |
751 | "advertise_networks": [{ | |
752 | "network": NETWORK["ipv4"], | |
753 | "delete": True | |
754 | }] | |
755 | } | |
756 | }, | |
757 | "ipv6": { | |
758 | "unicast": { | |
759 | "advertise_networks": [{ | |
760 | "network": NETWORK["ipv6"], | |
761 | "delete": True | |
762 | }] | |
763 | } | |
764 | } | |
765 | } | |
766 | } | |
767 | } | |
768 | } | |
769 | ||
770 | logger.info("Withdraw advertised networks") | |
771 | result = create_router_bgp(tgen, topo, input_dict_3) | |
772 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
773 | tc_name, result) | |
774 | ||
775 | for addr_type in ADDR_TYPES: | |
776 | input_dict = { | |
777 | "r3": { | |
778 | "static_routes": [ | |
779 | { | |
780 | "network": NETWORK[addr_type] | |
781 | } | |
782 | ] | |
783 | } | |
784 | } | |
785 | ||
786 | logger.info("Verifying %s routes on r3", addr_type) | |
787 | result = verify_rib(tgen, addr_type, dut, input_dict, | |
788 | next_hop=[], protocol=protocol, expected=False) | |
789 | assert result is not True, "Testcase {} : Failed \n Routes still" \ | |
790 | " present in RIB".format(tc_name) | |
791 | ||
792 | static_or_nw(tgen, topo, tc_name, "advertise_nw", "r2") | |
793 | for addr_type in ADDR_TYPES: | |
794 | input_dict = { | |
795 | "r3": { | |
796 | "static_routes": [ | |
797 | { | |
798 | "network": NETWORK[addr_type] | |
799 | } | |
800 | ] | |
801 | } | |
802 | } | |
803 | logger.info("Verifying %s routes on r3", addr_type) | |
804 | result = verify_rib(tgen, addr_type, dut, input_dict, | |
805 | next_hop=NEXT_HOPS[addr_type], | |
806 | protocol=protocol) | |
807 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
808 | tc_name, result) | |
809 | ||
810 | ||
811 | if __name__ == "__main__": | |
812 | args = ["-s"] + sys.argv[1:] | |
813 | sys.exit(pytest.main(args)) |