]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/ospf_gr_helper/test_ospf_gr_helper3.py
4 # Copyright (c) 2021 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."""
30 # Save the Current Working Directory to find configuration files.
31 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
32 sys
.path
.append(os
.path
.join(CWD
, "../"))
34 # pylint: disable=C0413
35 # Import topogen and topotest helpers
36 from lib
.topogen
import Topogen
, get_topogen
38 # Import topoJson from lib, to create topology and initial configuration
39 from lib
.common_config
import (
43 reset_config_on_routers
,
45 create_interfaces_cfg
,
47 scapy_send_raw_packet
,
50 from lib
.topolog
import logger
51 from lib
.topojson
import build_config_from_json
53 from lib
.ospf
import (
56 verify_ospf_gr_helper
,
71 Please view in a fixed-width font such as Courier.
72 Topo : Broadcast Networks
74 +---+ +---+ +---+ +---+
75 |R0 + +R1 + +R2 + +R3 |
76 +-+-+ +-+-+ +-+-+ +-+-+
79 --+-----------+--------------+---------------+-----
84 TC1. Verify by default helper support is disabled for FRR ospf
85 TC2. OSPF GR on Broadcast : Verify DUT enters Helper mode when neighbor
86 sends grace lsa, helps RR to restart gracefully (RR = DR)
87 TC3. OSPF GR on Broadcast : Verify DUT enters Helper mode when neighbor
88 sends grace lsa, helps RR to restart gracefully (RR = BDR)
89 TC4. OSPF GR on Broadcast : Verify DUT enters Helper mode when neighbor
90 sends grace lsa, helps RR to restart gracefully (RR = DRother)
91 TC5. OSPF GR on P2P : Verify DUT enters Helper mode when neighbor sends
92 grace lsa, helps RR to restart gracefully.
93 TC6. Verify all the show commands newly introducted as part of ospf
94 helper support - Json Key verification wrt to show commands.
95 TC7. Verify helper when grace lsa is received with different configured
96 value in process level (higher, lower, grace lsa timer above 1800)
97 TC8. Verify helper functionality when dut is helping RR and new grace lsa
102 def setup_module(mod
):
104 Sets up the pytest environment
108 global topo
, intf
, intf1
, sw_name
, pkt
109 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
110 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
111 logger
.info("=" * 40)
113 logger
.info("Running setup_module to create topology")
115 # This function initiates the topology build with Topogen...
116 json_file
= "{}/ospf_gr_helper.json".format(CWD
)
117 tgen
= Topogen(json_file
, mod
.__name
__)
119 topo
= tgen
.json_topo
120 # ... and here it calls Mininet initialization functions.
122 # get list of daemons needs to be started for this suite.
123 daemons
= topo_daemons(tgen
, topo
)
125 # Starting topology, create tmp files which are loaded to routers
126 # to start daemons and then start routers
127 start_topology(tgen
, daemons
)
129 # Creating configuration from JSON
130 build_config_from_json(tgen
, topo
)
132 # Don't run this test if we have any failure.
133 if tgen
.routers_have_failure():
134 pytest
.skip(tgen
.errors
)
136 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, lan
=True)
137 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
142 intf
= topo
["routers"]["r0"]["links"][sw_name
]["interface"]
143 intf1
= topo
["routers"]["r1"]["links"][sw_name
]["interface"]
144 pkt
= topo
["routers"]["r1"]["opq_lsa_hex"]
146 logger
.info("Running setup_module() done")
149 def teardown_module():
150 """Teardown the pytest environment"""
152 logger
.info("Running teardown_module to delete topology")
157 # Stop toplogy and Remove tmp files
161 # OSError exception is raised when mininet tries to stop switch
162 # though switch is stopped once but mininet tries to stop same
163 # switch again, where it ended up with exception
168 """delete ospf process after each test"""
170 step("Delete ospf process")
171 for rtr
in topo
["routers"]:
172 ospf_del
= {rtr
: {"ospf": {"delete": True}}}
173 result
= create_router_ospf(tgen
, topo
, ospf_del
)
174 assert result
is True, "Testcase: Failed \n Error: {}".format(result
)
177 # ##################################
178 # Test cases start here.
179 # ##################################
182 def test_ospf_gr_helper_tc7_p1(request
):
185 Verify helper when grace lsa is received with different configured
186 value in process level (higher, lower, grace lsa timer above 1800)
188 tc_name
= request
.node
.name
189 write_test_header(tc_name
)
192 # Don't run this test if we have any failure.
193 if tgen
.routers_have_failure():
194 pytest
.skip(tgen
.errors
)
196 global topo
, intf
, intf1
, pkt
198 step("Bring up the base config as per the topology")
200 "Configure DR priority as 99 in RR , DUT dr priority = 98 "
201 "& reset ospf process in all the routers"
204 "Enable GR on RR and DUT with grace period on RR = 333"
205 "and grace period on DUT = 300"
207 reset_config_on_routers(tgen
)
208 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, lan
=True)
210 ospf_covergence
is True
211 ), "OSPF is not after reset config \n Error:" " {}".format(ospf_covergence
)
213 "r0": {"ospf": {"graceful-restart": {"helper enable": [], "opaque": True}}}
215 result
= create_router_ospf(tgen
, topo
, ospf_gr_r0
)
216 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
219 "r1": {"ospf": {"graceful-restart": {"helper enable": [], "opaque": True}}}
221 result
= create_router_ospf(tgen
, topo
, ospf_gr_r1
)
222 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
224 input_dict
= {"supportedGracePeriod": 1800}
226 result
= verify_ospf_gr_helper(tgen
, topo
, dut
, input_dict
)
227 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
229 step("Configure grace period = 1801 on RR and restart ospf .")
230 grace_period_1801
= "01005e00000570708bd051ef080045c0005cbeb10000015907d111010101e00000050204004801010101000000009714000000000000000000000000000100010209030000000101010180000001c8e9002c000100040000016800020001010000000003000411010101"
231 gracelsa_sent
= scapy_send_raw_packet(tgen
, topo
, "r1", intf1
, grace_period_1801
)
233 step("Verify R0 does not enter helper mode.")
234 input_dict
= {"activeRestarterCnt": 1}
236 result
= verify_ospf_gr_helper(tgen
, topo
, dut
, input_dict
, expected
=False)
239 ), "Testcase {} : Failed. DUT entered helper role " " \n Error: {}".format(
245 write_test_footer(tc_name
)
248 def test_ospf_gr_helper_tc8_p1(request
):
252 Verify helper functionality when dut is helping RR and new grace lsa
255 tc_name
= request
.node
.name
256 write_test_header(tc_name
)
259 # Don't run this test if we have any failure.
260 if tgen
.routers_have_failure():
261 pytest
.skip(tgen
.errors
)
263 global topo
, intf
, intf1
, pkt
265 step("Bring up the base config as per the topology")
267 reset_config_on_routers(tgen
)
268 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, lan
=True)
270 ospf_covergence
is True
271 ), "OSPF is not after reset config \n Error:" " {}".format(ospf_covergence
)
273 "r0": {"ospf": {"graceful-restart": {"helper enable": [], "opaque": True}}}
275 result
= create_router_ospf(tgen
, topo
, ospf_gr_r0
)
276 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
279 "r1": {"ospf": {"graceful-restart": {"helper enable": [], "opaque": True}}}
281 result
= create_router_ospf(tgen
, topo
, ospf_gr_r1
)
282 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
284 input_dict
= {"supportedGracePeriod": 1800}
286 result
= verify_ospf_gr_helper(tgen
, topo
, dut
, input_dict
)
287 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
289 step("Verify that DUT enters into helper mode.")
291 input_dict
= {"activeRestarterCnt": 1}
292 gracelsa_sent
= False
295 while not gracelsa_sent
and repeat
< Iters
:
296 gracelsa_sent
= scapy_send_raw_packet(tgen
, topo
, "r1", intf1
, pkt
)
297 result
= verify_ospf_gr_helper(tgen
, topo
, dut
, input_dict
)
298 if isinstance(result
, str):
300 gracelsa_sent
= False
302 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
304 step("Send the Grace LSA again to DUT when RR is in GR.")
305 input_dict
= {"activeRestarterCnt": 1}
306 gracelsa_sent
= False
309 while not gracelsa_sent
and repeat
< Iters
:
310 gracelsa_sent
= scapy_send_raw_packet(tgen
, topo
, "r1", intf1
, pkt
)
311 result
= verify_ospf_gr_helper(tgen
, topo
, dut
, input_dict
)
312 if isinstance(result
, str):
314 gracelsa_sent
= False
316 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
320 write_test_footer(tc_name
)
323 if __name__
== "__main__":
324 args
= ["-s"] + sys
.argv
[1:]
325 sys
.exit(pytest
.main(args
))