]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/ospfv3_basic_functionality/test_ospfv3_nssa.py
Merge pull request #12837 from donaldsharp/unlikely_routemap
[mirror_frr.git] / tests / topotests / ospfv3_basic_functionality / test_ospfv3_nssa.py
CommitLineData
3af858bb 1#!/usr/bin/python
2
3from lib.topogen import Topogen, get_topogen
4from lib.common_config import (
5 start_topology,
6 write_test_header,
7 write_test_footer,
8 reset_config_on_routers,
9 step,
3af858bb 10)
11from lib.topolog import logger
12from lib.topojson import build_config_from_json
13from lib.ospf import create_router_ospf, verify_ospf6_neighbor
14import os
15import sys
16import time
17import pytest
18
19# Save the Current Working Directory to find configuration files.
20CWD = os.path.dirname(os.path.realpath(__file__))
21sys.path.append(os.path.join(CWD, "../"))
22sys.path.append(os.path.join(CWD, "../lib/"))
23
24# pylint: disable=C0413
25
26pytestmark = [pytest.mark.ospfd]
27
28
29# Global variables
30topo = None
31
32"""
33TOPOOLOGY
34
35 +---+ 0.0.0.0 +---+ 1.1.1.1 +---+
36 +R1 +------------+R2 |------------+R3 |
37 +-+-+ +--++ +--++
38
39TESTCASES =
401. OSPF Verify E-bit mismatch between R2 and R3
412. OSPF Verify N-bit mismatch between R2 and R3
42"""
43
44
45def setup_module(mod):
46 """
47 Sets up the pytest environment
48
49 * `mod`: module name
50 """
51 testsuite_run_time = time.asctime(time.localtime(time.time()))
52 logger.info("Testsuite start time: {}".format(testsuite_run_time))
53 logger.info("=" * 40)
54
55 logger.info("Running setup_module to create topology")
56
57 # This function initiates the topology build with Topogen...
58 json_file = "{}/ospfv3_nssa.json".format(CWD)
59 tgen = Topogen(json_file, mod.__name__)
60 global topo
61 topo = tgen.json_topo
62 # ... and here it calls Mininet initialization functions.
63
3af858bb 64 # Starting topology, create tmp files which are loaded to routers
d60a3f0e 65 # to start daemons and then start routers
991a971f 66 start_topology(tgen)
3af858bb 67
68 # Creating configuration from JSON
69 build_config_from_json(tgen, topo)
70
71 # Don't run this test if we have any failure.
72 if tgen.routers_have_failure():
73 pytest.skip(tgen.errors)
74
75 result = verify_ospf6_neighbor(tgen, topo)
74dd0c84 76 assert result is True, "setup_module: Failed \n Error: {}".format(result)
3af858bb 77
78 logger.info("Running setup_module() done")
79
80
81def teardown_module(mod):
82 """
83 Teardown the pytest environment.
84
85 * `mod`: module name
86 """
87
88 logger.info("Running teardown_module to delete topology")
89
90 tgen = get_topogen()
91
92 # Stop toplogy and Remove tmp files
93 tgen.stop_topology()
94
95 logger.info(
96 "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
97 )
98 logger.info("=" * 40)
99
100
101# ##################################
102# Test cases start here.
103# ##################################
104
105
106def test_ospfv3_bit_mismatch(request):
107 """OSPF verify E-bit and N-bit mismatch."""
108
109 tc_name = request.node.name
110 write_test_header(tc_name)
111 tgen = get_topogen()
112
113 # Don't run this test if we have any failure.
114 if tgen.routers_have_failure():
115 pytest.skip(tgen.errors)
116
117 global topo
118 step("Bring up the base config as per the topology")
119 reset_config_on_routers(tgen)
120
121 input_dict = {"r3": {"ospf6": {"neighbors": []}}}
122
123 step("Configure r3 as stub router")
124 stub = {"r3": {"ospf6": {"area": [{"id": "1.1.1.1", "type": "stub"}]}}}
125 result = create_router_ospf(tgen, topo, stub)
126 assert result is True, "Testcase {}: Failed \n Error: {}".format(tc_name, result)
127 # Verify r3 lost its adjacency with r2 due to E-bit mismatch
128 result = verify_ospf6_neighbor(tgen, topo, dut="r3", input_dict=input_dict)
129 assert result is True, "Testcase {}: Failed \n Error: {}".format(tc_name, result)
130
131 step("Configure r2 as stub router")
132 stub = {"r2": {"ospf6": {"area": [{"id": "1.1.1.1", "type": "stub"}]}}}
133 result = create_router_ospf(tgen, topo, stub)
134 assert result is True, "Testcase {}: Failed \n Error: {}".format(tc_name, result)
135 # Verify r3 has an adjacency up with r2 again
136 result = verify_ospf6_neighbor(tgen, topo, dut="r3")
137 assert result is True, "Testcase {}: Failed \n Error: {}".format(tc_name, result)
138
139 step("Configure r3 as NSSA router")
140 nssa = {"r3": {"ospf6": {"area": [{"id": "1.1.1.1", "type": "nssa"}]}}}
141 result = create_router_ospf(tgen, topo, nssa)
142 # Verify r3 lost its adjacency with r2 due to N-bit mismatch
143 result = verify_ospf6_neighbor(tgen, topo, dut="r3", input_dict=input_dict)
144 assert result is True, "Testcase {}: Failed \n Error: {}".format(tc_name, result)
145
146 step("Configure r2 as NSSA router")
147 nssa = {"r2": {"ospf6": {"area": [{"id": "1.1.1.1", "type": "nssa"}]}}}
148 result = create_router_ospf(tgen, topo, nssa)
149 # Verify r3 has an adjacency up with r2 again
150 result = verify_ospf6_neighbor(tgen, topo, dut="r3")
151 assert result is True, "Testcase {}: Failed \n Error: {}".format(tc_name, result)
152
153 write_test_footer(tc_name)
154
155
156if __name__ == "__main__":
157 args = ["-s"] + sys.argv[1:]
158 sys.exit(pytest.main(args))