4 # Copyright (c) 2020 by VMware, Inc. ("VMware")
5 # Used Copyright (c) 2018 by Network Device Education Foundation, Inc.
6 # ("NetDEF") in this file.
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
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
24 """OSPF Basic Functionality Automation."""
29 from time
import sleep
30 from copy
import deepcopy
31 from lib
.topotest
import frr_unicode
33 # Save the Current Working Directory to find configuration files.
34 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
35 sys
.path
.append(os
.path
.join(CWD
, "../"))
36 sys
.path
.append(os
.path
.join(CWD
, "../lib/"))
38 # pylint: disable=C0413
39 # Import topogen and topotest helpers
40 from lib
.topogen
import Topogen
, get_topogen
42 # Import topoJson from lib, to create topology and initial configuration
43 from lib
.common_config
import (
47 reset_config_on_routers
,
49 shutdown_bringup_interface
,
52 from lib
.topolog
import logger
53 from lib
.topojson
import build_config_from_json
54 from lib
.ospf
import verify_ospf_neighbor
, config_ospf_interface
, clear_ospf
55 from ipaddress
import IPv4Address
57 pytestmark
= [pytest
.mark
.ospfd
]
64 Please view in a fixed-width font such as Courier.
66 +R1 +------------+R2 |
75 +R0 +-------------+R3 |
79 1. Verify ospf authentication with Simple password authentication.
80 2. Verify ospf authentication with MD5 authentication.
81 3. Verify ospf authentication with different authentication methods.
86 def setup_module(mod
):
88 Sets up the pytest environment
92 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
93 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
96 logger
.info("Running setup_module to create topology")
98 # This function initiates the topology build with Topogen...
99 json_file
= "{}/ospf_authentication.json".format(CWD
)
100 tgen
= Topogen(json_file
, mod
.__name
__)
102 topo
= tgen
.json_topo
103 # ... and here it calls Mininet initialization functions.
105 # get list of daemons needs to be started for this suite.
106 daemons
= topo_daemons(tgen
, topo
)
108 # Starting topology, create tmp files which are loaded to routers
109 # to start deamons and then start routers
110 start_topology(tgen
, daemons
)
112 # Creating configuration from JSON
113 build_config_from_json(tgen
, topo
)
115 # Don't run this test if we have any failure.
116 if tgen
.routers_have_failure():
117 pytest
.skip(tgen
.errors
)
119 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
)
120 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
124 logger
.info("Running setup_module() done")
127 def teardown_module(mod
):
129 Teardown the pytest environment.
134 logger
.info("Running teardown_module to delete topology")
138 # Stop toplogy and Remove tmp files
142 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
144 logger
.info("=" * 40)
147 # ##################################
148 # Test cases start here.
149 # ##################################
152 def test_ospf_authentication_simple_pass_tc28_p1(request
):
154 OSPF Authentication - Verify ospf authentication with Simple
155 password authentication.
158 tc_name
= request
.node
.name
159 write_test_header(tc_name
)
162 step("Bring up the base config.")
163 reset_config_on_routers(tgen
)
165 "Configure ospf with on R1 and R2, enable ospf on R1 interface"
166 "connected to R2 with simple password authentication using ip ospf "
167 "authentication Simple password cmd."
173 "r2": {"ospf": {"authentication": True, "authentication-key": "ospf"}}
177 result
= config_ospf_interface(tgen
, topo
, r1_ospf_auth
)
178 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
180 step("clear ip ospf after configuring the authentication.")
181 clear_ospf(tgen
, "r1")
183 step("Verify that the neighbour is not FULL between R1 and R2.")
185 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
, expected
=False)
186 assert ospf_covergence
is not True, "setup_module :Failed \n Error:" " {}".format(
191 "On R2 enable ospf on interface with simple password authentication "
192 "using ip ospf authentication Simple password cmd."
198 "r1": {"ospf": {"authentication": True, "authentication-key": "ospf"}}
202 result
= config_ospf_interface(tgen
, topo
, r2_ospf_auth
)
203 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
206 "Verify that the neighbour is FULL between R1 and R2 "
207 "using show ip ospf neighbor cmd."
211 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
)
212 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
217 "Disable simple password authentication on R2 using no ip ospf "
218 "authentication Simple password cmd."
225 "authentication": True,
226 "authentication-key": "ospf",
233 result
= config_ospf_interface(tgen
, topo
, r2_ospf_auth
)
234 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
236 step("Verify on R1 neighbour is deleted for R2 after dead interval expiry")
237 # wait till the dead time expiry
240 ospf_covergence
= verify_ospf_neighbor(
241 tgen
, topo
, dut
=dut
, expected
=False, retry_timeout
=10
243 assert ospf_covergence
is not True, "setup_module :Failed \n Error:" " {}".format(
247 step("Again On R2 enable ospf on interface with Simple password auth")
251 "r1": {"ospf": {"authentication": True, "authentication-key": "ospf"}}
255 result
= config_ospf_interface(tgen
, topo
, r2_ospf_auth
)
256 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
259 "Verify that the neighbour is FULL between R1 and R2 using"
260 " show ip ospf neighbor cmd."
264 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
)
265 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
269 step("Shut no shut interface on R1")
271 intf
= topo
["routers"]["r1"]["links"]["r2"]["interface"]
272 shutdown_bringup_interface(tgen
, dut
, intf
, False)
276 "Verify that the neighbour is not FULL between R1 and R2 using "
277 "show ip ospf neighbor cmd."
279 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
, expected
=False)
280 assert ospf_covergence
is not True, "setup_module :Failed \n Error:" " {}".format(
285 shutdown_bringup_interface(tgen
, dut
, intf
, True)
288 "Verify that the neighbour is FULL between R1 and R2 using "
289 "show ip ospf neighbor cmd."
293 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
)
294 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
298 step("Change Ip address on R1 and R2")
300 topo_modify_change_ip
= deepcopy(topo
)
301 intf_ip
= topo_modify_change_ip
["routers"]["r1"]["links"]["r2"]["ipv4"]
302 topo_modify_change_ip
["routers"]["r1"]["links"]["r2"]["ipv4"] = str(
303 IPv4Address(frr_unicode(intf_ip
.split("/")[0])) + 3
304 ) + "/{}".format(intf_ip
.split("/")[1])
306 build_config_from_json(tgen
, topo_modify_change_ip
, save_bkup
=False)
308 reset_config_on_routers(tgen
, routerName
="r1")
310 intf
= topo
["routers"]["r1"]["links"]["r2"]["interface"]
311 shutdown_bringup_interface(tgen
, dut
, intf
, False)
312 shutdown_bringup_interface(tgen
, dut
, intf
, True)
314 # clear ip ospf after configuring the authentication.
315 clear_ospf(tgen
, "r1")
320 "r2": {"ospf": {"authentication": True, "authentication-key": "ospf"}}
324 result
= config_ospf_interface(tgen
, topo
, r1_ospf_auth
)
325 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
328 "Verify that the neighbour is FULL between R1 and R2 with new "
329 "ip address using show ip ospf "
333 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
)
334 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
338 write_test_footer(tc_name
)
341 def test_ospf_authentication_md5_tc29_p1(request
):
343 OSPF Authentication - Verify ospf authentication with MD5 authentication.
346 tc_name
= request
.node
.name
347 write_test_header(tc_name
)
350 step("Bring up the base config.")
351 reset_config_on_routers(tgen
)
353 "Configure ospf with on R1 and R2, enable ospf on R1 interface "
354 "connected to R2 with message-digest authentication using ip "
355 "ospf authentication message-digest cmd."
363 "authentication": "message-digest",
364 "authentication-key": "ospf",
365 "message-digest-key": "10",
371 result
= config_ospf_interface(tgen
, topo
, r1_ospf_auth
)
372 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
374 step("Verify that the neighbour is not FULL between R1 and R2.")
375 # wait for dead time expiry.
378 ospf_covergence
= verify_ospf_neighbor(
379 tgen
, topo
, dut
=dut
, expected
=False, retry_timeout
=6
381 assert ospf_covergence
is not True, "setup_module :Failed \n Error:" " {}".format(
386 "On R2 enable ospf on interface with message-digest authentication"
387 " using ip ospf authentication message-digest password cmd."
395 "authentication": "message-digest",
396 "authentication-key": "ospf",
397 "message-digest-key": "10",
403 result
= config_ospf_interface(tgen
, topo
, r2_ospf_auth
)
404 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
407 "Verify that the neighbour is FULL between R1 and R2 "
408 "using show ip ospf neighbor cmd."
412 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
)
413 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
418 "Disable message-digest authentication on R2 using no ip ospf "
419 "authentication message-digest password cmd."
427 "authentication": "message-digest",
428 "authentication-key": "ospf",
429 "message-digest-key": "10",
436 result
= config_ospf_interface(tgen
, topo
, r2_ospf_auth
)
437 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
439 step("Verify on R1 ,nbr is deleted for R2 after dead interval expiry")
440 # wait till the dead timer expiry
443 ospf_covergence
= verify_ospf_neighbor(
444 tgen
, topo
, dut
=dut
, expected
=False, retry_timeout
=10
446 assert ospf_covergence
is not True, "setup_module :Failed \n Error:" " {}".format(
450 step("Again On R2 enable ospf on interface with message-digest auth")
456 "authentication": "message-digest",
457 "authentication-key": "ospf",
458 "message-digest-key": "10",
464 result
= config_ospf_interface(tgen
, topo
, r2_ospf_auth
)
465 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
468 "Verify that the neighbour is FULL between R1 and R2 using"
469 " show ip ospf neighbor cmd."
473 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
)
474 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
478 step("Shut no shut interface on R1")
480 intf
= topo
["routers"]["r1"]["links"]["r2"]["interface"]
481 shutdown_bringup_interface(tgen
, dut
, intf
, False)
485 "Verify that the neighbour is not FULL between R1 and R2 using "
486 "show ip ospf neighbor cmd."
488 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
, expected
=False)
489 assert ospf_covergence
is not True, "setup_module :Failed \n Error:" " {}".format(
494 shutdown_bringup_interface(tgen
, dut
, intf
, True)
497 "Verify that the neighbour is FULL between R1 and R2 using "
498 "show ip ospf neighbor cmd."
502 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
)
503 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
507 step("Change Ip address on R1 and R2")
509 topo_modify_change_ip
= deepcopy(topo
)
511 intf_ip
= topo_modify_change_ip
["routers"]["r1"]["links"]["r2"]["ipv4"]
513 topo_modify_change_ip
["routers"]["r1"]["links"]["r2"]["ipv4"] = str(
514 IPv4Address(frr_unicode(intf_ip
.split("/")[0])) + 3
515 ) + "/{}".format(intf_ip
.split("/")[1])
517 build_config_from_json(tgen
, topo_modify_change_ip
, save_bkup
=False)
519 reset_config_on_routers(tgen
, routerName
="r1")
521 intf
= topo
["routers"]["r1"]["links"]["r2"]["interface"]
522 shutdown_bringup_interface(tgen
, dut
, intf
, False)
523 shutdown_bringup_interface(tgen
, dut
, intf
, True)
524 clear_ospf(tgen
, "r1")
530 "authentication": "message-digest",
531 "authentication-key": "ospf",
532 "message-digest-key": "10",
538 result
= config_ospf_interface(tgen
, topo
, r1_ospf_auth
)
539 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
542 "Verify that the neighbour is FULL between R1 and R2 with new "
543 "ip address using show ip ospf "
547 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
)
548 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
552 write_test_footer(tc_name
)
555 def test_ospf_authentication_different_auths_tc30_p1(request
):
557 OSPF Authentication - Verify ospf authentication with different
558 authentication methods.
561 tc_name
= request
.node
.name
562 write_test_header(tc_name
)
565 step("Bring up the base config.")
566 reset_config_on_routers(tgen
)
568 "Configure ospf with on R1 and R2, enable ospf on R1 interface "
569 "connected to R2 with message-digest authentication using ip "
570 "ospf authentication message-digest cmd."
578 "authentication": "message-digest",
579 "authentication-key": "ospf",
580 "message-digest-key": "10",
586 result
= config_ospf_interface(tgen
, topo
, r1_ospf_auth
)
587 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
589 # wait for dead timer expiry
591 step("Verify that the neighbour is not FULL between R1 and R2.")
593 ospf_covergence
= verify_ospf_neighbor(
594 tgen
, topo
, dut
=dut
, expected
=False, retry_timeout
=10
596 assert ospf_covergence
is not True, "setup_module :Failed \n Error:" " {}".format(
601 "On R2 enable ospf on interface with message-digest authentication"
602 " using ip ospf authentication message-digest password cmd."
610 "authentication": "message-digest",
611 "authentication-key": "ospf",
612 "message-digest-key": "10",
618 result
= config_ospf_interface(tgen
, topo
, r2_ospf_auth
)
619 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
622 "Verify that the neighbour is FULL between R1 and R2 "
623 "using show ip ospf neighbor cmd."
627 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
)
628 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
632 step(" Delete the configured password on both the routers.")
639 "authentication": "message-digest",
640 "authentication-key": "ospf",
641 "message-digest-key": "10",
648 result
= config_ospf_interface(tgen
, topo
, r2_ospf_auth
)
649 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
656 "authentication": "message-digest",
657 "authentication-key": "ospf",
658 "message-digest-key": "10",
665 result
= config_ospf_interface(tgen
, topo
, r1_ospf_auth
)
666 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
669 "Verify that the deletion is successful and neighbour is FULL"
670 " between R1 and R2 using show ip ospf neighbor cmd."
674 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
)
675 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
679 step("Change the authentication type to simple password.")
683 "r2": {"ospf": {"authentication": True, "authentication-key": "ospf"}}
687 result
= config_ospf_interface(tgen
, topo
, r1_ospf_auth
)
688 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
693 "r1": {"ospf": {"authentication": True, "authentication-key": "ospf"}}
697 result
= config_ospf_interface(tgen
, topo
, r2_ospf_auth
)
698 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
701 "Verify that the deletion is successful and neighbour is"
702 " FULL between R1 and R2 using show ip "
706 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
)
707 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
711 step("Change the password in simple password.")
716 "r2": {"ospf": {"authentication": True, "authentication-key": "OSPFv4"}}
720 result
= config_ospf_interface(tgen
, topo
, r1_ospf_auth
)
721 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
726 "r1": {"ospf": {"authentication": True, "authentication-key": "OSPFv4"}}
730 result
= config_ospf_interface(tgen
, topo
, r2_ospf_auth
)
731 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
734 "Verify that the deletion is successful and neighbour is"
735 " FULL between R1 and R2 using show ip "
739 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
)
740 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
744 step("Delete the password authentication on the interface ")
751 "authentication": True,
752 "authentication-key": "OSPFv4",
759 result
= config_ospf_interface(tgen
, topo
, r1_ospf_auth
)
760 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
767 "authentication": True,
768 "authentication-key": "OSPFv4",
775 result
= config_ospf_interface(tgen
, topo
, r2_ospf_auth
)
776 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
779 "Verify that the deletion is successful and neighbour is"
780 " FULL between R1 and R2 using show ip "
784 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
)
785 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
789 step("Enable Md5 authentication on the interface")
796 "authentication": "message-digest",
797 "authentication-key": "ospf",
798 "message-digest-key": "10",
804 result
= config_ospf_interface(tgen
, topo
, r1_ospf_auth
)
805 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
812 "authentication": "message-digest",
813 "authentication-key": "ospf",
814 "message-digest-key": "10",
820 result
= config_ospf_interface(tgen
, topo
, r2_ospf_auth
)
821 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
824 "Verify that the neighbour is FULL between R1 and R2 using"
825 " show ip ospf neighbor cmd."
829 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, dut
=dut
)
830 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
834 step("Change the MD5 authentication password")
841 "authentication": "message-digest",
842 "authentication-key": "OSPFv4",
843 "message-digest-key": "10",
849 result
= config_ospf_interface(tgen
, topo
, r1_ospf_auth
)
850 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
857 "authentication": "message-digest",
858 "authentication-key": "OSPFv4",
859 "message-digest-key": "10",
865 result
= config_ospf_interface(tgen
, topo
, r2_ospf_auth
)
866 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
868 write_test_footer(tc_name
)
871 if __name__
== "__main__":
872 args
= ["-s"] + sys
.argv
[1:]
873 sys
.exit(pytest
.main(args
))