]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/ospf_topo2/test_ospf_topo2.py
6 # Copyright (c) 2019 by
7 # Cumulus Networks, Inc
10 # Permission to use, copy, modify, and/or distribute this software
11 # for any purpose with or without fee is hereby granted, provided
12 # that the above copyright notice and this permission notice appear
15 # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
16 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
17 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
18 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
19 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
21 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
26 test_ospf_topo2.py: Test the OSPF unnumbered.
31 from functools
import partial
35 # Save the Current Working Directory to find configuration files.
36 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
37 sys
.path
.append(os
.path
.join(CWD
, "../"))
39 # pylint: disable=C0413
40 # Import topogen and topotest helpers
41 from lib
import topotest
42 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
43 from lib
.topolog
import logger
45 # Required to instantiate the topology builder class.
47 pytestmark
= [pytest
.mark
.ospfd
]
50 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
57 for routern
in range(1, 3):
58 tgen
.add_router("r{}".format(routern
))
60 # Create a empty network for router 1
61 switch
= tgen
.add_switch("s1")
62 switch
.add_link(tgen
.gears
["r1"])
64 # Create a empty network for router 2
65 switch
= tgen
.add_switch("s2")
66 switch
.add_link(tgen
.gears
["r2"])
68 # Interconect router 1, 2
69 switch
= tgen
.add_switch("s3")
70 switch
.add_link(tgen
.gears
["r1"])
71 switch
.add_link(tgen
.gears
["r2"])
74 def setup_module(mod
):
75 "Sets up the pytest environment"
76 tgen
= Topogen(build_topo
, mod
.__name
__)
79 router_list
= tgen
.routers()
80 for rname
, router
in router_list
.items():
82 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
85 TopoRouter
.RD_OSPF
, os
.path
.join(CWD
, "{}/ospfd.conf".format(rname
))
88 # What is this? OSPF Unnumbered depends on the rp_filter
89 # being set appropriately( HA! )
90 # Effectively we are putting different /32's on the interface
91 # the multicast packet delivery is somewhat controlled by
92 # the rp_filter. Setting it to '0' allows the OS to pass
93 # up the mcast packet not destined for the local routers
95 topotest
.sysctl_assure(tgen
.net
["r1"], "net.ipv4.conf.r1-eth1.rp_filter", 0)
96 topotest
.sysctl_assure(tgen
.net
["r1"], "net.ipv4.conf.all.rp_filter", 0)
97 topotest
.sysctl_assure(tgen
.net
["r2"], "net.ipv4.conf.r2-eth1.rp_filter", 0)
98 topotest
.sysctl_assure(tgen
.net
["r2"], "net.ipv4.conf.all.rp_filter", 0)
100 # Initialize all routers.
105 def teardown_module(mod
):
106 "Teardown the pytest environment"
111 def test_ospf_convergence():
112 "Test OSPF daemon convergence and that we have received the ospf routes"
114 if tgen
.routers_have_failure():
115 pytest
.skip("skipped because of router(s) failure")
117 for router
, rnode
in tgen
.routers().items():
118 logger
.info('Waiting for router "%s" convergence', router
)
120 json_file
= "{}/{}/ospf-route.json".format(CWD
, router
)
121 expected
= json
.loads(open(json_file
).read())
124 topotest
.router_json_cmp
, rnode
, "show ip ospf route json", expected
126 _
, result
= topotest
.run_and_expect(test_func
, None, count
=160, wait
=0.5)
127 assertmsg
= '"{}" JSON output mismatches'.format(router
)
128 assert result
is None, assertmsg
132 def test_ospf_kernel_route():
133 "Test OSPF kernel route installation and we have the onlink success"
135 if tgen
.routers_have_failure():
136 pytest
.skip("skipped because of router(s) failure")
138 rlist
= tgen
.routers().values()
140 logger
.info('Checking OSPF IPv4 kernel routes in "%s"', router
.name
)
142 json_file
= "{}/{}/v4_route.json".format(CWD
, router
.name
)
143 expected
= json
.loads(open(json_file
).read())
146 topotest
.router_json_cmp
, router
, "show ip route json", expected
148 _
, result
= topotest
.run_and_expect(test_func
, None, count
=10, wait
=0.5)
149 assertmsg
= '"{}" JSON output mistmatches'.format(router
)
150 assert result
is None, assertmsg
154 def test_memory_leak():
155 "Run the memory leak test and report results."
157 if not tgen
.is_memleak_enabled():
158 pytest
.skip("Memory leak test/report is disabled")
160 tgen
.report_memory_leaks()
163 if __name__
== "__main__":
164 args
= ["-s"] + sys
.argv
[1:]
165 sys
.exit(pytest
.main(args
))