]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/ospf_basic_functionality/test_ospf_asbr_summary_type7_lsa.py
2 # SPDX-License-Identifier: ISC
5 # Copyright (c) 2020 by VMware, Inc. ("VMware")
6 # Used Copyright (c) 2018 by Network Device Education Foundation, Inc.
7 # ("NetDEF") in this file.
11 """OSPF Summarisation 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
, "../"))
20 sys
.path
.append(os
.path
.join(CWD
, "../lib/"))
22 # pylint: disable=C0413
23 # Import topogen and topotest helpers
24 from lib
.topogen
import Topogen
, get_topogen
25 from time
import sleep
27 # Import topoJson from lib, to create topology and initial configuration
28 from lib
.common_config
import (
32 reset_config_on_routers
,
37 from lib
.topolog
import logger
38 from lib
.topojson
import build_config_from_json
39 from lib
.ospf
import (
46 pytestmark
= [pytest
.mark
.ospfd
, pytest
.mark
.staticd
]
79 SUMMARY
= {"ipv4": ["11.0.20.1/8", "12.0.0.0/8", "13.0.0.0/8", "11.0.0.0/8"]}
82 Please view in a fixed-width font such as Courier.
84 +R1 +------------+R2 |
93 +R0 +-------------+R3 |
99 1. OSPF summarisation with type7 LSAs.
104 def setup_module(mod
):
106 Sets up the pytest environment
110 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
111 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
112 logger
.info("=" * 40)
114 logger
.info("Running setup_module to create topology")
116 # This function initiates the topology build with Topogen...
117 json_file
= "{}/ospf_asbr_summary_type7_lsa.json".format(CWD
)
118 tgen
= Topogen(json_file
, mod
.__name
__)
120 topo
= tgen
.json_topo
121 # ... and here it calls Mininet initialization functions.
123 # Starting topology, create tmp files which are loaded to routers
124 # to start daemons and then start routers
127 # Creating configuration from JSON
128 build_config_from_json(tgen
, topo
)
130 # Don't run this test if we have any failure.
131 if tgen
.routers_have_failure():
132 pytest
.skip(tgen
.errors
)
133 # Api call verify whether OSPF is converged
134 ospf_covergence
= verify_ospf_neighbor(tgen
, topo
)
135 assert ospf_covergence
is True, "setup_module :Failed \n Error {}".format(
139 logger
.info("Running setup_module() done")
142 def teardown_module(mod
):
144 Teardown the pytest environment.
149 logger
.info("Running teardown_module to delete topology")
153 # Stop toplogy and Remove tmp files
157 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
159 logger
.info("=" * 40)
162 def red_static(dut
, config
=True):
163 """Local def for Redstribute static routes inside ospf."""
167 ospf_red
= {dut
: {"ospf": {"redistribute": [{"redist_type": "static"}]}}}
170 dut
: {"ospf": {"redistribute": [{"redist_type": "static", "delete": True}]}}
172 result
= create_router_ospf(tgen
, topo
, ospf_red
)
173 assert result
is True, "Testcase : Failed \n Error: {}".format(result
)
176 def red_connected(dut
, config
=True):
177 """Local def for Redstribute connected routes inside ospf."""
181 ospf_red
= {dut
: {"ospf": {"redistribute": [{"redist_type": "connected"}]}}}
186 "redistribute": [{"redist_type": "connected", "del_action": True}]
190 result
= create_router_ospf(tgen
, topo
, ospf_red
)
191 assert result
is True, "Testcase: Failed \n Error: {}".format(result
)
194 # ##################################
195 # Test cases start here.
196 # ##################################
199 def test_ospf_type5_summary_tc44_p0(request
):
200 """OSPF summarisation with type7 LSAs"""
202 tc_name
= request
.node
.name
203 write_test_header(tc_name
)
206 # Don't run this test if we have any failure.
207 if tgen
.routers_have_failure():
208 pytest
.skip(tgen
.errors
)
210 step("Bring up the base config as per the topology")
211 step("Configure area 1 as NSSA Area")
213 reset_config_on_routers(tgen
)
219 input_dict_static_rtes
= {
222 {"network": NETWORK
["ipv4"], "next_hop": "blackhole"},
223 {"network": NETWORK2
["ipv4"], "next_hop": "blackhole"},
227 result
= create_static_routes(tgen
, input_dict_static_rtes
)
228 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
230 step("Verify that routes are learnt on R1.")
233 result
= verify_ospf_rib(tgen
, dut
, input_dict_static_rtes
)
234 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
235 result
= verify_rib(tgen
, "ipv4", dut
, input_dict_static_rtes
, protocol
=protocol
)
238 ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name
)
240 step("Configure External Route summary in R0 to summarise 5 routes to one route.")
246 {"prefix": SUMMARY
["ipv4"][0].split("/")[0], "mask": "8"}
251 result
= create_router_ospf(tgen
, topo
, ospf_summ_r0
)
252 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
255 "Verify that external routes are summarised to configured summary "
256 "address on R0 after 5 secs of delay timer expiry and only one "
257 "route is sent to R1."
260 step("Configure summary & redistribute static/connected route with metric type 2")
262 input_dict_summary
= {"r0": {"static_routes": [{"network": SUMMARY
["ipv4"][3]}]}}
265 result
= verify_ospf_rib(tgen
, dut
, input_dict_summary
)
266 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
268 result
= verify_rib(tgen
, "ipv4", dut
, input_dict_summary
, protocol
=protocol
)
271 ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name
)
273 step("Verify that show ip ospf summary should show the summaries.")
275 SUMMARY
["ipv4"][3]: {
276 "summaryAddress": SUMMARY
["ipv4"][3],
280 "externalRouteCount": 5,
284 result
= verify_ospf_summary(tgen
, topo
, dut
, input_dict
)
287 ), "Testcase {} : Failed. Error: Summary missing in OSPF DB".format(tc_name
)
289 step("Learn type 7 lsa from neighbours")
295 input_dict_static_rtes
= {
297 "static_routes": [{"network": NETWORK3
["ipv4"], "next_hop": "blackhole"}]
300 result
= create_static_routes(tgen
, input_dict_static_rtes
)
301 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
303 step("Verify that routes are learnt on R0.")
306 result
= verify_ospf_rib(tgen
, dut
, input_dict_static_rtes
)
307 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
308 result
= verify_rib(tgen
, "ipv4", dut
, input_dict_static_rtes
, protocol
=protocol
)
311 ), "Testcase {} : Failed. Error: Routes is missing in RIB".format(tc_name
)
317 {"prefix": SUMMARY
["ipv4"][2].split("/")[0], "mask": "8"}
322 result
= create_router_ospf(tgen
, topo
, ospf_summ_r0
)
323 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
325 step("Verify that type7 LSAs received from neighbor are not summarised.")
328 "summaryAddress": "13.0.0.0/8",
332 "externalRouteCount": 0,
336 result
= verify_ospf_summary(tgen
, topo
, dut
, input_dict
)
339 ), "Testcase {} : Failed. Error: Summary missing in OSPF DB".format(tc_name
)
341 step("Verify that already originated summary is intact.")
343 SUMMARY
["ipv4"][3]: {
344 "summaryAddress": SUMMARY
["ipv4"][3],
348 "externalRouteCount": 5,
352 result
= verify_ospf_summary(tgen
, topo
, dut
, input_dict
)
355 ), "Testcase {} : Failed. Error: Summary missing in OSPF DB".format(tc_name
)
358 aggr_timer
= {"r1": {"ospf": {"aggr_timer": 6}}}
359 result
= create_router_ospf(tgen
, topo
, aggr_timer
)
360 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
365 {"prefix": SUMMARY
["ipv4"][2].split("/")[0], "mask": "8"}
370 result
= create_router_ospf(tgen
, topo
, ospf_summ_r0
)
371 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
374 "wait for 6+1 seconds as ospf aggregation start after 6 secs as "
375 "per the above aggr_timer command"
379 aggr_timer
= {"r1": {"ospf": {"del_aggr_timer": 6}}}
380 result
= create_router_ospf(tgen
, topo
, aggr_timer
)
381 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
383 write_test_footer(tc_name
)
386 if __name__
== "__main__":
387 args
= ["-s"] + sys
.argv
[1:]
388 sys
.exit(pytest
.main(args
))