]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/ospf_unnumbered/test_ospf_unnumbered.py
2 # SPDX-License-Identifier: ISC
5 # test_ospf_unnumbered.py
7 # Copyright (c) 2019 by
8 # Cumulus Networks, Inc
13 test_ospf_unnumbered.py: Test the OSPF unnumbered.
18 from functools
import partial
22 # Save the Current Working Directory to find configuration files.
23 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
24 sys
.path
.append(os
.path
.join(CWD
, "../"))
26 # pylint: disable=C0413
27 # Import topogen and topotest helpers
28 from lib
import topotest
29 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
30 from lib
.topolog
import logger
32 # Required to instantiate the topology builder class.
34 pytestmark
= [pytest
.mark
.ospfd
]
37 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
44 for routern
in range(1, 3):
45 tgen
.add_router("r{}".format(routern
))
47 # Create a empty network for router 1
48 switch
= tgen
.add_switch("s1")
49 switch
.add_link(tgen
.gears
["r1"])
51 # Create a empty network for router 2
52 switch
= tgen
.add_switch("s2")
53 switch
.add_link(tgen
.gears
["r2"])
55 # Interconect router 1, 2
56 switch
= tgen
.add_switch("s3")
57 switch
.add_link(tgen
.gears
["r1"])
58 switch
.add_link(tgen
.gears
["r2"])
61 def setup_module(mod
):
62 "Sets up the pytest environment"
63 tgen
= Topogen(build_topo
, mod
.__name
__)
66 router_list
= tgen
.routers()
67 for rname
, router
in router_list
.items():
69 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
72 TopoRouter
.RD_OSPF
, os
.path
.join(CWD
, "{}/ospfd.conf".format(rname
))
75 # What is this? OSPF Unnumbered depends on the rp_filter
76 # being set appropriately( HA! )
77 # Effectively we are putting different /32's on the interface
78 # the multicast packet delivery is somewhat controlled by
79 # the rp_filter. Setting it to '0' allows the OS to pass
80 # up the mcast packet not destined for the local routers
82 topotest
.sysctl_assure(tgen
.net
["r1"], "net.ipv4.conf.r1-eth1.rp_filter", 0)
83 topotest
.sysctl_assure(tgen
.net
["r1"], "net.ipv4.conf.all.rp_filter", 0)
84 topotest
.sysctl_assure(tgen
.net
["r2"], "net.ipv4.conf.r2-eth1.rp_filter", 0)
85 topotest
.sysctl_assure(tgen
.net
["r2"], "net.ipv4.conf.all.rp_filter", 0)
87 # Initialize all routers.
92 def teardown_module(mod
):
93 "Teardown the pytest environment"
98 def test_ospf_convergence():
99 "Test OSPF daemon convergence and that we have received the ospf routes"
101 if tgen
.routers_have_failure():
102 pytest
.skip("skipped because of router(s) failure")
104 for router
, rnode
in tgen
.routers().items():
105 logger
.info('Waiting for router "%s" convergence', router
)
107 json_file
= "{}/{}/ospf-route.json".format(CWD
, router
)
108 expected
= json
.loads(open(json_file
).read())
111 topotest
.router_json_cmp
, rnode
, "show ip ospf route json", expected
113 _
, result
= topotest
.run_and_expect(test_func
, None, count
=160, wait
=0.5)
114 assertmsg
= '"{}" JSON output mismatches'.format(router
)
115 assert result
is None, assertmsg
119 def test_ospf_kernel_route():
120 "Test OSPF kernel route installation and we have the onlink success"
122 if tgen
.routers_have_failure():
123 pytest
.skip("skipped because of router(s) failure")
125 rlist
= tgen
.routers().values()
127 logger
.info('Checking OSPF IPv4 kernel routes in "%s"', router
.name
)
129 json_file
= "{}/{}/v4_route.json".format(CWD
, router
.name
)
130 expected
= json
.loads(open(json_file
).read())
133 topotest
.router_json_cmp
, router
, "show ip route json", expected
135 _
, result
= topotest
.run_and_expect(test_func
, None, count
=10, wait
=0.5)
136 assertmsg
= '"{}" JSON output mistmatches'.format(router
)
137 assert result
is None, assertmsg
141 def test_memory_leak():
142 "Run the memory leak test and report results."
144 if not tgen
.is_memleak_enabled():
145 pytest
.skip("Memory leak test/report is disabled")
147 tgen
.report_memory_leaks()
150 if __name__
== "__main__":
151 args
= ["-s"] + sys
.argv
[1:]
152 sys
.exit(pytest
.main(args
))