]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/ospf_gr_helper/test_ospf_gr_helper1.py
2 # SPDX-License-Identifier: ISC
5 # Copyright (c) 2021 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."""
17 # Save the Current Working Directory to find configuration files.
18 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
19 sys
.path
.append(os
.path
.join(CWD
, "../"))
21 # pylint: disable=C0413
22 # Import topogen and topotest helpers
23 from lib
.topogen
import Topogen
, get_topogen
25 # Import topoJson from lib, to create topology and initial configuration
26 from lib
.common_config
import (
30 reset_config_on_routers
,
32 create_interfaces_cfg
,
33 scapy_send_raw_packet
,
36 from lib
.topolog
import logger
37 from lib
.topojson
import build_config_from_json
39 from lib
.ospf
import (
42 verify_ospf_gr_helper
,
46 pytestmark
= [pytest
.mark
.ospfd
]
59 Please view in a fixed-width font such as Courier.
60 Topo : Broadcast Networks
62 +---+ +---+ +---+ +---+
63 |R0 + +R1 + +R2 + +R3 |
64 +-+-+ +-+-+ +-+-+ +-+-+
67 --+-----------+--------------+---------------+-----
72 TC1. Verify by default helper support is disabled for FRR ospf
73 TC2. OSPF GR on Broadcast : Verify DUT enters Helper mode when neighbor
74 sends grace lsa, helps RR to restart gracefully (RR = DR)
75 TC3. OSPF GR on Broadcast : Verify DUT enters Helper mode when neighbor
76 sends grace lsa, helps RR to restart gracefully (RR = BDR)
77 TC4. OSPF GR on Broadcast : Verify DUT enters Helper mode when neighbor
78 sends grace lsa, helps RR to restart gracefully (RR = DRother)
79 TC5. OSPF GR on P2P : Verify DUT enters Helper mode when neighbor sends
80 grace lsa, helps RR to restart gracefully.
81 TC6. Verify all the show commands newly introducted as part of ospf
82 helper support - Json Key verification wrt to show commands.
83 TC7. Verify helper when grace lsa is received with different configured
84 value in process level (higher, lower, grace lsa timer above 1800)
85 TC8. Verify helper functionality when dut is helping RR and new grace lsa
90 def setup_module(mod
):
92 Sets up the pytest environment
96 global topo
, intf
, intf1
, sw_name
, pkt
97 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
98 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
101 logger
.info("Running setup_module to create topology")
103 # This function initiates the topology build with Topogen...
104 json_file
= "{}/ospf_gr_helper.json".format(CWD
)
105 tgen
= Topogen(json_file
, mod
.__name
__)
107 topo
= tgen
.json_topo
108 # ... and here it calls Mininet initialization functions.
110 # Starting topology, create tmp files which are loaded to routers
111 # to start daemons and then start routers
114 # Creating configuration from JSON
115 build_config_from_json(tgen
, topo
)
117 # Don't run this test if we have any failure.
118 if tgen
.routers_have_failure():
119 pytest
.skip(tgen
.errors
)
121 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, lan
=True)
122 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
127 intf
= topo
["routers"]["r0"]["links"][sw_name
]["interface"]
128 intf1
= topo
["routers"]["r1"]["links"][sw_name
]["interface"]
129 pkt
= topo
["routers"]["r1"]["opq_lsa_hex"]
131 logger
.info("Running setup_module() done")
134 def teardown_module():
135 """Teardown the pytest environment"""
137 logger
.info("Running teardown_module to delete topology")
142 # Stop toplogy and Remove tmp files
146 # OSError exception is raised when mininet tries to stop switch
147 # though switch is stopped once but mininet tries to stop same
148 # switch again, where it ended up with exception
153 """delete ospf process after each test"""
155 step("Delete ospf process")
156 for rtr
in topo
["routers"]:
157 ospf_del
= {rtr
: {"ospf": {"delete": True}}}
158 result
= create_router_ospf(tgen
, topo
, ospf_del
)
159 assert result
is True, "Testcase: Failed \n Error: {}".format(result
)
162 # ##################################
163 # Test cases start here.
164 # ##################################
167 def test_ospf_gr_helper_tc1_p0(request
):
168 """Verify by default helper support is disabled for FRR ospf"""
170 tc_name
= request
.node
.name
171 write_test_header(tc_name
)
174 # Don't run this test if we have any failure.
175 if tgen
.routers_have_failure():
176 pytest
.skip(tgen
.errors
)
178 global topo
, intf
, intf1
, pkt
180 step("Bring up the base config as per the topology")
181 reset_config_on_routers(tgen
)
182 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, lan
=True)
184 ospf_covergence
is True
185 ), "OSPF is not after reset config \n Error:" " {}".format(ospf_covergence
)
187 step("Verify that GR helper route is disabled by default to the in" "the DUT.")
189 "helperSupport": "Disabled",
190 "strictLsaCheck": "Enabled",
191 "restartSupoort": "Planned and Unplanned Restarts",
192 "supportedGracePeriod": 1800,
195 result
= verify_ospf_gr_helper(tgen
, topo
, dut
, input_dict
)
196 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
198 step("Verify that DUT does not enter helper mode upon receiving the " "grace lsa.")
201 scapy_send_raw_packet(tgen
, topo
, "r1", intf1
, pkt
)
203 input_dict
= {"activeRestarterCnt": 1}
205 result
= verify_ospf_gr_helper(tgen
, topo
, dut
, input_dict
, expected
=False)
208 ), "Testcase {} : Failed. DUT entered helper role " " \n Error: {}".format(
212 step("Configure graceful restart in the DUT")
214 "r0": {"ospf": {"graceful-restart": {"helper enable": [], "opaque": True}}}
216 result
= create_router_ospf(tgen
, topo
, ospf_gr_r0
)
217 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
219 step("Verify that GR helper route is enabled in the DUT.")
221 "helperSupport": "Enabled",
222 "strictLsaCheck": "Enabled",
223 "restartSupoort": "Planned and Unplanned Restarts",
224 "supportedGracePeriod": 1800,
227 result
= verify_ospf_gr_helper(tgen
, topo
, dut
, input_dict
)
228 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
231 "r1": {"ospf": {"graceful-restart": {"helper enable": [], "opaque": True}}}
233 result
= create_router_ospf(tgen
, topo
, ospf_gr_r1
)
234 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
236 step("Perform GR in RR.")
237 step("Verify that DUT does enter helper mode upon receiving" " the grace lsa.")
238 input_dict
= {"activeRestarterCnt": 1}
239 gracelsa_sent
= False
242 while not gracelsa_sent
and repeat
< Iters
:
243 gracelsa_sent
= scapy_send_raw_packet(tgen
, topo
, "r1", intf1
, pkt
)
244 result
= verify_ospf_gr_helper(tgen
, topo
, dut
, input_dict
)
245 if isinstance(result
, str):
247 gracelsa_sent
= False
249 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
251 step("Unconfigure the GR helper command.")
255 "graceful-restart": {
263 result
= create_router_ospf(tgen
, topo
, ospf_gr_r0
)
264 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
266 input_dict
= {"helperSupport": "Disabled"}
268 result
= verify_ospf_gr_helper(tgen
, topo
, dut
, input_dict
)
269 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
271 step("Configure gr helper using the router id")
274 "ospf": {"graceful-restart": {"helper enable": ["1.1.1.1"], "opaque": True}}
277 result
= create_router_ospf(tgen
, topo
, ospf_gr_r0
)
278 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
280 step("Verify that DUT does enter helper mode upon receiving" " the grace lsa.")
281 input_dict
= {"activeRestarterCnt": 1}
282 gracelsa_sent
= False
285 while not gracelsa_sent
and repeat
< Iters
:
286 gracelsa_sent
= scapy_send_raw_packet(tgen
, topo
, "r1", intf1
, pkt
)
287 result
= verify_ospf_gr_helper(tgen
, topo
, dut
, input_dict
)
288 if isinstance(result
, str):
290 gracelsa_sent
= False
292 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
294 step("Un Configure gr helper using the router id")
298 "graceful-restart": {
299 "helper enable": ["1.1.1.1"],
306 result
= create_router_ospf(tgen
, topo
, ospf_gr_r0
)
307 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
309 step("Verify that GR helper router is disabled in the DUT for" " router id x.x.x.x")
310 input_dict
= {"enabledRouterIds": [{"routerId": "1.1.1.1"}]}
312 result
= verify_ospf_gr_helper(tgen
, topo
, dut
, input_dict
, expected
=False)
315 ), "Testcase {} : Failed, Helper role enabled for RR\n Error: {}".format(
319 write_test_footer(tc_name
)
322 def test_ospf_gr_helper_tc2_p0(request
):
324 OSPF GR on Broadcast : Verify DUT enters Helper mode when neighbor
325 sends grace lsa, helps RR to restart gracefully (RR = DR)
327 tc_name
= request
.node
.name
328 write_test_header(tc_name
)
331 # Don't run this test if we have any failure.
332 if tgen
.routers_have_failure():
333 pytest
.skip(tgen
.errors
)
335 global topo
, intf
, intf1
, pkt
337 step("Bring up the base config as per the topology")
339 "Configure DR priority as 99 in RR , DUT dr priority = 98 "
340 "& reset ospf process in all the routers"
342 reset_config_on_routers(tgen
)
343 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, lan
=True)
345 ospf_covergence
is True
346 ), "OSPF is not after reset config \n Error:" " {}".format(ospf_covergence
)
348 "r0": {"ospf": {"graceful-restart": {"helper enable": [], "opaque": True}}}
350 result
= create_router_ospf(tgen
, topo
, ospf_gr_r0
)
351 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
354 "r1": {"ospf": {"graceful-restart": {"helper enable": [], "opaque": True}}}
356 result
= create_router_ospf(tgen
, topo
, ospf_gr_r1
)
357 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
359 step("Verify that DUT enters into helper mode.")
361 input_dict
= {"activeRestarterCnt": 1}
362 gracelsa_sent
= False
365 while not gracelsa_sent
and repeat
< Iters
:
366 gracelsa_sent
= scapy_send_raw_packet(tgen
, topo
, "r1", intf1
, pkt
)
367 result
= verify_ospf_gr_helper(tgen
, topo
, dut
, input_dict
)
368 if isinstance(result
, str):
370 gracelsa_sent
= False
372 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
375 write_test_footer(tc_name
)
378 if __name__
== "__main__":
379 args
= ["-s"] + sys
.argv
[1:]
380 sys
.exit(pytest
.main(args
))