]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/ospf_gr_helper/test_ospf_gr_helper2.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
,
60 pytestmark
= [pytest
.mark
.ospfd
]
73 Please view in a fixed-width font such as Courier.
74 Topo : Broadcast Networks
76 +---+ +---+ +---+ +---+
77 |R0 + +R1 + +R2 + +R3 |
78 +-+-+ +-+-+ +-+-+ +-+-+
81 --+-----------+--------------+---------------+-----
86 TC1. Verify by default helper support is disabled for FRR ospf
87 TC2. OSPF GR on Broadcast : Verify DUT enters Helper mode when neighbor
88 sends grace lsa, helps RR to restart gracefully (RR = DR)
89 TC3. OSPF GR on Broadcast : Verify DUT enters Helper mode when neighbor
90 sends grace lsa, helps RR to restart gracefully (RR = BDR)
91 TC4. OSPF GR on Broadcast : Verify DUT enters Helper mode when neighbor
92 sends grace lsa, helps RR to restart gracefully (RR = DRother)
93 TC5. OSPF GR on P2P : Verify DUT enters Helper mode when neighbor sends
94 grace lsa, helps RR to restart gracefully.
95 TC6. Verify all the show commands newly introducted as part of ospf
96 helper support - Json Key verification wrt to show commands.
97 TC7. Verify helper when grace lsa is received with different configured
98 value in process level (higher, lower, grace lsa timer above 1800)
99 TC8. Verify helper functionality when dut is helping RR and new grace lsa
104 def setup_module(mod
):
106 Sets up the pytest environment
110 global topo
, intf
, intf1
, sw_name
, pkt
111 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
112 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
113 logger
.info("=" * 40)
115 logger
.info("Running setup_module to create topology")
117 # This function initiates the topology build with Topogen...
118 json_file
= "{}/ospf_gr_helper.json".format(CWD
)
119 tgen
= Topogen(json_file
, mod
.__name
__)
121 topo
= tgen
.json_topo
122 # ... and here it calls Mininet initialization functions.
124 # get list of daemons needs to be started for this suite.
125 daemons
= topo_daemons(tgen
, topo
)
127 # Starting topology, create tmp files which are loaded to routers
128 # to start daemons and then start routers
129 start_topology(tgen
, daemons
)
131 # Creating configuration from JSON
132 build_config_from_json(tgen
, topo
)
134 # Don't run this test if we have any failure.
135 if tgen
.routers_have_failure():
136 pytest
.skip(tgen
.errors
)
138 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, lan
=True)
139 assert ospf_covergence
is True, "setup_module :Failed \n Error:" " {}".format(
144 intf
= topo
["routers"]["r0"]["links"][sw_name
]["interface"]
145 intf1
= topo
["routers"]["r1"]["links"][sw_name
]["interface"]
146 pkt
= topo
["routers"]["r1"]["opq_lsa_hex"]
148 logger
.info("Running setup_module() done")
151 def teardown_module():
152 """Teardown the pytest environment"""
154 logger
.info("Running teardown_module to delete topology")
159 # Stop toplogy and Remove tmp files
163 # OSError exception is raised when mininet tries to stop switch
164 # though switch is stopped once but mininet tries to stop same
165 # switch again, where it ended up with exception
170 """delete ospf process after each test"""
172 step("Delete ospf process")
173 for rtr
in topo
["routers"]:
174 ospf_del
= {rtr
: {"ospf": {"delete": True}}}
175 result
= create_router_ospf(tgen
, topo
, ospf_del
)
176 assert result
is True, "Testcase: Failed \n Error: {}".format(result
)
179 # ##################################
180 # Test cases start here.
181 # ##################################
184 def test_ospf_gr_helper_tc3_p1(request
):
186 OSPF GR on Broadcast : Verify DUT enters Helper mode when neighbor
187 sends grace lsa, helps RR to restart gracefully (RR = BDR)
189 tc_name
= request
.node
.name
190 write_test_header(tc_name
)
193 # Don't run this test if we have any failure.
194 if tgen
.routers_have_failure():
195 pytest
.skip(tgen
.errors
)
197 global topo
, intf
, intf1
, pkt
199 step("Bring up the base config as per the topology")
201 "Configure DR priority as 99 in RR , DUT dr priority = 98 "
202 "& reset ospf process in all the routers"
204 reset_config_on_routers(tgen
)
205 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, lan
=True)
207 ospf_covergence
is True
208 ), "OSPF is not after reset config \n Error:" " {}".format(ospf_covergence
)
210 "Configure DR pririty 100 on R0 and clear ospf neighbors " "on all the routers."
217 "interface": topo
["routers"]["r0"]["links"][sw_name
]["interface"],
218 "ospf": {"priority": 100},
224 result
= create_interfaces_cfg(tgen
, input_dict
)
225 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
227 step("Clear ospf neighbours in all routers")
228 for rtr
in topo
["routers"]:
229 clear_ospf(tgen
, rtr
)
231 step("Verify that DR election is triggered and R0 is elected as DR")
236 "r1": {"state": "Full", "role": "Backup"},
237 "r2": {"state": "Full", "role": "DROther"},
238 "r3": {"state": "Full", "role": "DROther"},
244 result
= verify_ospf_neighbor(tgen
, topo
, dut
, input_dict
, lan
=True)
245 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
248 "r0": {"ospf": {"graceful-restart": {"helper enable": [], "opaque": True}}}
250 result
= create_router_ospf(tgen
, topo
, ospf_gr_r0
)
251 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
254 "r1": {"ospf": {"graceful-restart": {"helper enable": [], "opaque": True}}}
256 result
= create_router_ospf(tgen
, topo
, ospf_gr_r1
)
257 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
259 step("Verify that DUT enters into helper mode.")
261 input_dict
= {"activeRestarterCnt": 1}
262 gracelsa_sent
= False
265 while not gracelsa_sent
and repeat
< Iters
:
266 gracelsa_sent
= scapy_send_raw_packet(tgen
, topo
, "r1", intf1
, pkt
)
267 result
= verify_ospf_gr_helper(tgen
, topo
, dut
, input_dict
)
268 if isinstance(result
, str):
270 gracelsa_sent
= False
272 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
275 write_test_footer(tc_name
)
278 def test_ospf_gr_helper_tc4_p1(request
):
280 OSPF GR on Broadcast : Verify DUT enters Helper mode when neighbor
281 sends grace lsa, helps RR to restart gracefully (RR = DRother)
283 tc_name
= request
.node
.name
284 write_test_header(tc_name
)
287 # Don't run this test if we have any failure.
288 if tgen
.routers_have_failure():
289 pytest
.skip(tgen
.errors
)
291 global topo
, intf
, intf1
, pkt
293 step("Bring up the base config as per the topology")
295 "Configure DR priority as 99 in RR , DUT dr priority = 98 "
296 "& reset ospf process in all the routers"
298 reset_config_on_routers(tgen
)
299 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
, lan
=True)
301 ospf_covergence
is True
302 ), "OSPF is not after reset config \n Error:" " {}".format(ospf_covergence
)
304 "Configure DR pririty 100 on R0 and clear ospf neighbors " "on all the routers."
311 "interface": topo
["routers"]["r0"]["links"][sw_name
]["interface"],
312 "ospf": {"priority": 0},
318 result
= create_interfaces_cfg(tgen
, input_dict
)
319 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
321 step("Clear ospf neighbours in all routers")
322 for rtr
in topo
["routers"]:
323 clear_ospf(tgen
, rtr
)
325 step("Verify that DR election is triggered and R0 is elected as 2-Way")
330 "r1": {"state": "Full", "role": "DR"},
331 "r2": {"state": "2-Way", "role": "DROther"},
332 "r3": {"state": "2-Way", "role": "DROther"},
338 result
= verify_ospf_neighbor(tgen
, topo
, dut
, input_dict
, lan
=True)
339 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
342 "r0": {"ospf": {"graceful-restart": {"helper enable": [], "opaque": True}}}
344 result
= create_router_ospf(tgen
, topo
, ospf_gr_r0
)
345 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
348 "r1": {"ospf": {"graceful-restart": {"helper enable": [], "opaque": True}}}
350 result
= create_router_ospf(tgen
, topo
, ospf_gr_r1
)
351 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
353 step("Verify that DUT enters into helper mode.")
355 input_dict
= {"activeRestarterCnt": 1}
356 gracelsa_sent
= False
359 while not gracelsa_sent
and repeat
< Iters
:
360 gracelsa_sent
= scapy_send_raw_packet(tgen
, topo
, "r1", intf1
, pkt
)
361 result
= verify_ospf_gr_helper(tgen
, topo
, dut
, input_dict
)
362 if isinstance(result
, str):
364 gracelsa_sent
= False
366 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
370 write_test_footer(tc_name
)
373 if __name__
== "__main__":
374 args
= ["-s"] + sys
.argv
[1:]
375 sys
.exit(pytest
.main(args
))