2 # SPDX-License-Identifier: ISC
5 # Copyright (c) 2020 by VMware, Inc. ("VMware")
6 # Used Copyright (c) 2018 by Network Device Education Foundation, Inc.
7 # ("NetDEF") in this file.
11 """OSPF Basic Functionality Automation."""
16 from time
import sleep
17 from copy
import deepcopy
18 from lib
.topotest
import frr_unicode
20 # Save the Current Working Directory to find configuration files.
21 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
22 sys
.path
.append(os
.path
.join(CWD
, "../"))
23 sys
.path
.append(os
.path
.join(CWD
, "../lib/"))
25 # pylint: disable=C0413
26 # Import topogen and topotest helpers
27 from lib
.topogen
import Topogen
, get_topogen
29 # Import topoJson from lib, to create topology and initial configuration
30 from lib
.common_config
import (
34 reset_config_on_routers
,
36 shutdown_bringup_interface
,
38 from lib
.topolog
import logger
39 from lib
.topojson
import build_config_from_json
40 from lib
.ospf
import verify_ospf_neighbor
, config_ospf_interface
, clear_ospf
41 from ipaddress
import IPv4Address
43 pytestmark
= [pytest
.mark
.ospfd
]
50 Please view in a fixed-width font such as Courier.
52 +R1 +------------+R2 |
61 +R0 +-------------+R3 |
65 1. Verify ospf authentication with Simple password authentication.
66 2. Verify ospf authentication with MD5 authentication.
67 3. Verify ospf authentication with different authentication methods.
72 def setup_module(mod
):
74 Sets up the pytest environment
78 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
79 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
82 logger
.info("Running setup_module to create topology")
84 # This function initiates the topology build with Topogen...
85 json_file
= "{}/ospf_authentication.json".format(CWD
)
86 tgen
= Topogen(json_file
, mod
.__name
__)
89 # ... and here it calls Mininet initialization functions.
91 # Starting topology, create tmp files which are loaded to routers
92 # to start daemons and then start routers
95 # Creating configuration from JSON
96 build_config_from_json(tgen
, topo
)
98 # Don't run this test if we have any failure.
99 if tgen
.routers_have_failure():
100 pytest
.skip(tgen
.errors
)
102 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
)
103 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
107 logger
.info("Running setup_module() done")
110 def teardown_module(mod
):
112 Teardown the pytest environment.
117 logger
.info("Running teardown_module to delete topology")
121 # Stop toplogy and Remove tmp files
125 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
127 logger
.info("=" * 40)
130 # ##################################
131 # Test cases start here.
132 # ##################################
135 def test_ospf_authentication_simple_pass_tc28_p1(request
):
137 OSPF Authentication - Verify ospf authentication with Simple
138 password authentication.
141 tc_name
= request
.node
.name
142 write_test_header(tc_name
)
145 step("Bring up the base config.")
146 reset_config_on_routers(tgen
)
148 "Configure ospf with on R1 and R2, enable ospf on R1 interface"
149 "connected to R2 with simple password authentication using ip ospf "
150 "authentication Simple password cmd."
156 "r2": {"ospf": {"authentication": True, "authentication-key": "ospf"}}
160 result
= config_ospf_interface(tgen
, topo
, r1_ospf_auth
)
161 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
163 step("clear ip ospf after configuring the authentication.")
164 clear_ospf(tgen
, "r1")
166 step("Verify that the neighbour is not FULL between R1 and R2.")
168 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
, expected
=False)
169 assert ospf_covergence
is not True, "setup_module :Failed \n Error:" " {}".format(
174 "On R2 enable ospf on interface with simple password authentication "
175 "using ip ospf authentication Simple password cmd."
181 "r1": {"ospf": {"authentication": True, "authentication-key": "ospf"}}
185 result
= config_ospf_interface(tgen
, topo
, r2_ospf_auth
)
186 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
189 "Verify that the neighbour is FULL between R1 and R2 "
190 "using show ip ospf neighbor cmd."
194 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
)
195 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
200 "Disable simple password authentication on R2 using no ip ospf "
201 "authentication Simple password cmd."
208 "authentication": True,
209 "authentication-key": "ospf",
216 result
= config_ospf_interface(tgen
, topo
, r2_ospf_auth
)
217 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
219 step("Verify on R1 neighbour is deleted for R2 after dead interval expiry")
220 # wait till the dead time expiry
223 ospf_covergence
= verify_ospf_neighbor(
224 tgen
, topo
, dut
=dut
, expected
=False, retry_timeout
=10
226 assert ospf_covergence
is not True, "setup_module :Failed \n Error:" " {}".format(
230 step("Again On R2 enable ospf on interface with Simple password auth")
234 "r1": {"ospf": {"authentication": True, "authentication-key": "ospf"}}
238 result
= config_ospf_interface(tgen
, topo
, r2_ospf_auth
)
239 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
242 "Verify that the neighbour is FULL between R1 and R2 using"
243 " show ip ospf neighbor cmd."
247 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
)
248 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
252 step("Shut no shut interface on R1")
254 intf
= topo
["routers"]["r1"]["links"]["r2"]["interface"]
255 shutdown_bringup_interface(tgen
, dut
, intf
, False)
259 "Verify that the neighbour is not FULL between R1 and R2 using "
260 "show ip ospf neighbor cmd."
262 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
, expected
=False)
263 assert ospf_covergence
is not True, "setup_module :Failed \n Error:" " {}".format(
268 shutdown_bringup_interface(tgen
, dut
, intf
, True)
271 "Verify that the neighbour is FULL between R1 and R2 using "
272 "show ip ospf neighbor cmd."
276 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
)
277 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
281 step("Change Ip address on R1 and R2")
283 topo_modify_change_ip
= deepcopy(topo
)
284 intf_ip
= topo_modify_change_ip
["routers"]["r1"]["links"]["r2"]["ipv4"]
285 topo_modify_change_ip
["routers"]["r1"]["links"]["r2"]["ipv4"] = str(
286 IPv4Address(frr_unicode(intf_ip
.split("/")[0])) + 3
287 ) + "/{}".format(intf_ip
.split("/")[1])
289 build_config_from_json(tgen
, topo_modify_change_ip
, save_bkup
=False)
291 reset_config_on_routers(tgen
, routerName
="r1")
293 intf
= topo
["routers"]["r1"]["links"]["r2"]["interface"]
294 shutdown_bringup_interface(tgen
, dut
, intf
, False)
295 shutdown_bringup_interface(tgen
, dut
, intf
, True)
297 # clear ip ospf after configuring the authentication.
298 clear_ospf(tgen
, "r1")
303 "r2": {"ospf": {"authentication": True, "authentication-key": "ospf"}}
307 result
= config_ospf_interface(tgen
, topo
, r1_ospf_auth
)
308 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
311 "Verify that the neighbour is FULL between R1 and R2 with new "
312 "ip address using show ip ospf "
316 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
)
317 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
321 write_test_footer(tc_name
)
324 def test_ospf_authentication_md5_tc29_p1(request
):
326 OSPF Authentication - Verify ospf authentication with MD5 authentication.
329 tc_name
= request
.node
.name
330 write_test_header(tc_name
)
333 step("Bring up the base config.")
334 reset_config_on_routers(tgen
)
336 "Configure ospf with on R1 and R2, enable ospf on R1 interface "
337 "connected to R2 with message-digest authentication using ip "
338 "ospf authentication message-digest cmd."
346 "authentication": "message-digest",
347 "authentication-key": "ospf",
348 "message-digest-key": "10",
354 result
= config_ospf_interface(tgen
, topo
, r1_ospf_auth
)
355 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
357 step("Verify that the neighbour is not FULL between R1 and R2.")
358 # wait for dead time expiry.
361 ospf_covergence
= verify_ospf_neighbor(
362 tgen
, topo
, dut
=dut
, expected
=False, retry_timeout
=6
364 assert ospf_covergence
is not True, "setup_module :Failed \n Error:" " {}".format(
369 "On R2 enable ospf on interface with message-digest authentication"
370 " using ip ospf authentication message-digest password cmd."
378 "authentication": "message-digest",
379 "authentication-key": "ospf",
380 "message-digest-key": "10",
386 result
= config_ospf_interface(tgen
, topo
, r2_ospf_auth
)
387 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
390 "Verify that the neighbour is FULL between R1 and R2 "
391 "using show ip ospf neighbor cmd."
395 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
)
396 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
401 "Disable message-digest authentication on R2 using no ip ospf "
402 "authentication message-digest password cmd."
410 "authentication": "message-digest",
411 "authentication-key": "ospf",
412 "message-digest-key": "10",
419 result
= config_ospf_interface(tgen
, topo
, r2_ospf_auth
)
420 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
422 step("Verify on R1 ,nbr is deleted for R2 after dead interval expiry")
423 # wait till the dead timer expiry
426 ospf_covergence
= verify_ospf_neighbor(
427 tgen
, topo
, dut
=dut
, expected
=False, retry_timeout
=10
429 assert ospf_covergence
is not True, "setup_module :Failed \n Error:" " {}".format(
433 step("Again On R2 enable ospf on interface with message-digest auth")
439 "authentication": "message-digest",
440 "authentication-key": "ospf",
441 "message-digest-key": "10",
447 result
= config_ospf_interface(tgen
, topo
, r2_ospf_auth
)
448 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
451 "Verify that the neighbour is FULL between R1 and R2 using"
452 " show ip ospf neighbor cmd."
456 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
)
457 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
461 step("Shut no shut interface on R1")
463 intf
= topo
["routers"]["r1"]["links"]["r2"]["interface"]
464 shutdown_bringup_interface(tgen
, dut
, intf
, False)
468 "Verify that the neighbour is not FULL between R1 and R2 using "
469 "show ip ospf neighbor cmd."
471 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
, expected
=False)
472 assert ospf_covergence
is not True, "setup_module :Failed \n Error:" " {}".format(
477 shutdown_bringup_interface(tgen
, dut
, intf
, True)
480 "Verify that the neighbour is FULL between R1 and R2 using "
481 "show ip ospf neighbor cmd."
485 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
)
486 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
490 step("Change Ip address on R1 and R2")
492 topo_modify_change_ip
= deepcopy(topo
)
494 intf_ip
= topo_modify_change_ip
["routers"]["r1"]["links"]["r2"]["ipv4"]
496 topo_modify_change_ip
["routers"]["r1"]["links"]["r2"]["ipv4"] = str(
497 IPv4Address(frr_unicode(intf_ip
.split("/")[0])) + 3
498 ) + "/{}".format(intf_ip
.split("/")[1])
500 build_config_from_json(tgen
, topo_modify_change_ip
, save_bkup
=False)
502 reset_config_on_routers(tgen
, routerName
="r1")
504 intf
= topo
["routers"]["r1"]["links"]["r2"]["interface"]
505 shutdown_bringup_interface(tgen
, dut
, intf
, False)
506 shutdown_bringup_interface(tgen
, dut
, intf
, True)
507 clear_ospf(tgen
, "r1")
513 "authentication": "message-digest",
514 "authentication-key": "ospf",
515 "message-digest-key": "10",
521 result
= config_ospf_interface(tgen
, topo
, r1_ospf_auth
)
522 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
525 "Verify that the neighbour is FULL between R1 and R2 with new "
526 "ip address using show ip ospf "
530 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
)
531 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
535 write_test_footer(tc_name
)
538 def test_ospf_authentication_different_auths_tc30_p1(request
):
540 OSPF Authentication - Verify ospf authentication with different
541 authentication methods.
544 tc_name
= request
.node
.name
545 write_test_header(tc_name
)
548 step("Bring up the base config.")
549 reset_config_on_routers(tgen
)
551 "Configure ospf with on R1 and R2, enable ospf on R1 interface "
552 "connected to R2 with message-digest authentication using ip "
553 "ospf authentication message-digest cmd."
561 "authentication": "message-digest",
562 "authentication-key": "ospf",
563 "message-digest-key": "10",
569 result
= config_ospf_interface(tgen
, topo
, r1_ospf_auth
)
570 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
572 # wait for dead timer expiry
574 step("Verify that the neighbour is not FULL between R1 and R2.")
576 ospf_covergence
= verify_ospf_neighbor(
577 tgen
, topo
, dut
=dut
, expected
=False, retry_timeout
=10
579 assert ospf_covergence
is not True, "setup_module :Failed \n Error:" " {}".format(
584 "On R2 enable ospf on interface with message-digest authentication"
585 " using ip ospf authentication message-digest password cmd."
593 "authentication": "message-digest",
594 "authentication-key": "ospf",
595 "message-digest-key": "10",
601 result
= config_ospf_interface(tgen
, topo
, r2_ospf_auth
)
602 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
605 "Verify that the neighbour is FULL between R1 and R2 "
606 "using show ip ospf neighbor cmd."
610 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
)
611 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
615 step(" Delete the configured password on both the routers.")
622 "authentication": "message-digest",
623 "authentication-key": "ospf",
624 "message-digest-key": "10",
631 result
= config_ospf_interface(tgen
, topo
, r2_ospf_auth
)
632 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
639 "authentication": "message-digest",
640 "authentication-key": "ospf",
641 "message-digest-key": "10",
648 result
= config_ospf_interface(tgen
, topo
, r1_ospf_auth
)
649 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
652 "Verify that the deletion is successful and neighbour is FULL"
653 " between R1 and R2 using show ip ospf neighbor cmd."
657 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
)
658 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
662 step("Change the authentication type to simple password.")
666 "r2": {"ospf": {"authentication": True, "authentication-key": "ospf"}}
670 result
= config_ospf_interface(tgen
, topo
, r1_ospf_auth
)
671 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
676 "r1": {"ospf": {"authentication": True, "authentication-key": "ospf"}}
680 result
= config_ospf_interface(tgen
, topo
, r2_ospf_auth
)
681 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
684 "Verify that the deletion is successful and neighbour is"
685 " FULL between R1 and R2 using show ip "
689 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
)
690 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
694 step("Change the password in simple password.")
699 "r2": {"ospf": {"authentication": True, "authentication-key": "OSPFv4"}}
703 result
= config_ospf_interface(tgen
, topo
, r1_ospf_auth
)
704 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
709 "r1": {"ospf": {"authentication": True, "authentication-key": "OSPFv4"}}
713 result
= config_ospf_interface(tgen
, topo
, r2_ospf_auth
)
714 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
717 "Verify that the deletion is successful and neighbour is"
718 " FULL between R1 and R2 using show ip "
722 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
)
723 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
727 step("Delete the password authentication on the interface ")
734 "authentication": True,
735 "authentication-key": "OSPFv4",
742 result
= config_ospf_interface(tgen
, topo
, r1_ospf_auth
)
743 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
750 "authentication": True,
751 "authentication-key": "OSPFv4",
758 result
= config_ospf_interface(tgen
, topo
, r2_ospf_auth
)
759 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
762 "Verify that the deletion is successful and neighbour is"
763 " FULL between R1 and R2 using show ip "
767 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
)
768 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
772 step("Enable Md5 authentication on the interface")
779 "authentication": "message-digest",
780 "authentication-key": "ospf",
781 "message-digest-key": "10",
787 result
= config_ospf_interface(tgen
, topo
, r1_ospf_auth
)
788 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
795 "authentication": "message-digest",
796 "authentication-key": "ospf",
797 "message-digest-key": "10",
803 result
= config_ospf_interface(tgen
, topo
, r2_ospf_auth
)
804 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
807 "Verify that the neighbour is FULL between R1 and R2 using"
808 " show ip ospf neighbor cmd."
812 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
)
813 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
817 step("Change the MD5 authentication password")
824 "authentication": "message-digest",
825 "authentication-key": "OSPFv4",
826 "message-digest-key": "10",
832 result
= config_ospf_interface(tgen
, topo
, r1_ospf_auth
)
833 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
840 "authentication": "message-digest",
841 "authentication-key": "OSPFv4",
842 "message-digest-key": "10",
848 result
= config_ospf_interface(tgen
, topo
, r2_ospf_auth
)
849 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
851 write_test_footer(tc_name
)
854 if __name__
== "__main__":
855 args
= ["-s"] + sys
.argv
[1:]
856 sys
.exit(pytest
.main(args
))