]>
Commit | Line | Data |
---|---|---|
3af858bb | 1 | #!/usr/bin/python |
2 | ||
3 | from lib.topogen import Topogen, get_topogen | |
4 | from lib.common_config import ( | |
5 | start_topology, | |
6 | write_test_header, | |
7 | write_test_footer, | |
8 | reset_config_on_routers, | |
9 | step, | |
3af858bb | 10 | ) |
11 | from lib.topolog import logger | |
12 | from lib.topojson import build_config_from_json | |
13 | from lib.ospf import create_router_ospf, verify_ospf6_neighbor | |
14 | import os | |
15 | import sys | |
16 | import time | |
17 | import pytest | |
18 | ||
19 | # Save the Current Working Directory to find configuration files. | |
20 | CWD = os.path.dirname(os.path.realpath(__file__)) | |
21 | sys.path.append(os.path.join(CWD, "../")) | |
22 | sys.path.append(os.path.join(CWD, "../lib/")) | |
23 | ||
24 | # pylint: disable=C0413 | |
25 | ||
26 | pytestmark = [pytest.mark.ospfd] | |
27 | ||
28 | ||
29 | # Global variables | |
30 | topo = None | |
31 | ||
32 | """ | |
33 | TOPOOLOGY | |
34 | ||
35 | +---+ 0.0.0.0 +---+ 1.1.1.1 +---+ | |
36 | +R1 +------------+R2 |------------+R3 | | |
37 | +-+-+ +--++ +--++ | |
38 | ||
39 | TESTCASES = | |
40 | 1. OSPF Verify E-bit mismatch between R2 and R3 | |
41 | 2. OSPF Verify N-bit mismatch between R2 and R3 | |
42 | """ | |
43 | ||
44 | ||
45 | def 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 | ||
81 | def 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 | ||
106 | def 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 | ||
156 | if __name__ == "__main__": | |
157 | args = ["-s"] + sys.argv[1:] | |
158 | sys.exit(pytest.main(args)) |