]>
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
)
241 "Configure External Route summary in R0 to summarise 5" " routes to one route."
248 {"prefix": SUMMARY
["ipv4"][0].split("/")[0], "mask": "8"}
253 result
= create_router_ospf(tgen
, topo
, ospf_summ_r0
)
254 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
257 "Verify that external routes are summarised to configured summary "
258 "address on R0 after 5 secs of delay timer expiry and only one "
259 "route is sent to R1."
263 "Configure summary & redistribute static/connected route with " "metric type 2"
266 input_dict_summary
= {"r0": {"static_routes": [{"network": SUMMARY
["ipv4"][3]}]}}
269 result
= verify_ospf_rib(tgen
, dut
, input_dict_summary
)
270 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
272 result
= verify_rib(tgen
, "ipv4", dut
, input_dict_summary
, protocol
=protocol
)
275 ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name
)
277 step("Verify that show ip ospf summary should show the summaries.")
279 SUMMARY
["ipv4"][3]: {
280 "summaryAddress": SUMMARY
["ipv4"][3],
284 "externalRouteCount": 5,
288 result
= verify_ospf_summary(tgen
, topo
, dut
, input_dict
)
291 ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name
)
293 step("Learn type 7 lsa from neighbours")
299 input_dict_static_rtes
= {
301 "static_routes": [{"network": NETWORK3
["ipv4"], "next_hop": "blackhole"}]
304 result
= create_static_routes(tgen
, input_dict_static_rtes
)
305 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
307 step("Verify that routes are learnt on R0.")
310 result
= verify_ospf_rib(tgen
, dut
, input_dict_static_rtes
)
311 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
312 result
= verify_rib(tgen
, "ipv4", dut
, input_dict_static_rtes
, protocol
=protocol
)
315 ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name
)
321 {"prefix": SUMMARY
["ipv4"][2].split("/")[0], "mask": "8"}
326 result
= create_router_ospf(tgen
, topo
, ospf_summ_r0
)
327 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
329 step("Verify that type7 LSAs received from neighbor are not summarised.")
332 "summaryAddress": "13.0.0.0/8",
336 "externalRouteCount": 0,
340 result
= verify_ospf_summary(tgen
, topo
, dut
, input_dict
)
343 ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name
)
345 step("Verify that already originated summary is intact.")
347 SUMMARY
["ipv4"][3]: {
348 "summaryAddress": SUMMARY
["ipv4"][3],
352 "externalRouteCount": 5,
356 result
= verify_ospf_summary(tgen
, topo
, dut
, input_dict
)
359 ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name
)
362 aggr_timer
= {"r1": {"ospf": {"aggr_timer": 6}}}
363 result
= create_router_ospf(tgen
, topo
, aggr_timer
)
364 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
369 {"prefix": SUMMARY
["ipv4"][2].split("/")[0], "mask": "8"}
374 result
= create_router_ospf(tgen
, topo
, ospf_summ_r0
)
375 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
378 "wait for 6+1 seconds as ospf aggregation start after 6 secs as "
379 "per the above aggr_timer command"
383 aggr_timer
= {"r1": {"ospf": {"del_aggr_timer": 6}}}
384 result
= create_router_ospf(tgen
, topo
, aggr_timer
)
385 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
387 write_test_footer(tc_name
)
390 if __name__
== "__main__":
391 args
= ["-s"] + sys
.argv
[1:]
392 sys
.exit(pytest
.main(args
))