]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bfd_profiles_topo1/test_bfd_profiles_topo1.py
4 # test_bfd_profiles_topo1.py
5 # Part of NetDEF Topology Tests
7 # Copyright (c) 2020 by
8 # Network Device Education Foundation, Inc. ("NetDEF")
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_bfd_profiles_topo1.py: Test the FRR BFD profile protocol integration.
32 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.
46 from mininet
.topo
import Topo
48 pytestmark
= [pytest
.mark
.bfdd
, pytest
.mark
.bgpd
, pytest
.mark
.isisd
, pytest
.mark
.ospfd
]
51 class BFDProfTopo(Topo
):
52 "Test topology builder"
54 def build(self
, *_args
, **_opts
):
56 tgen
= get_topogen(self
)
59 for routern
in range(1, 7):
60 tgen
.add_router("r{}".format(routern
))
62 switch
= tgen
.add_switch("s1")
63 switch
.add_link(tgen
.gears
["r1"])
64 switch
.add_link(tgen
.gears
["r2"])
66 switch
= tgen
.add_switch("s2")
67 switch
.add_link(tgen
.gears
["r2"])
68 switch
.add_link(tgen
.gears
["r3"])
70 switch
= tgen
.add_switch("s3")
71 switch
.add_link(tgen
.gears
["r3"])
72 switch
.add_link(tgen
.gears
["r4"])
74 switch
= tgen
.add_switch("s4")
75 switch
.add_link(tgen
.gears
["r4"])
76 switch
.add_link(tgen
.gears
["r5"])
78 switch
= tgen
.add_switch("s5")
79 switch
.add_link(tgen
.gears
["r1"])
80 switch
.add_link(tgen
.gears
["r6"])
83 def setup_module(mod
):
84 "Sets up the pytest environment"
85 tgen
= Topogen(BFDProfTopo
, mod
.__name
__)
88 router_list
= tgen
.routers()
89 for rname
, router
in router_list
.items():
90 daemon_file
= "{}/{}/bfdd.conf".format(CWD
, rname
)
91 if os
.path
.isfile(daemon_file
):
92 router
.load_config(TopoRouter
.RD_BFD
, daemon_file
)
94 daemon_file
= "{}/{}/bgpd.conf".format(CWD
, rname
)
95 if os
.path
.isfile(daemon_file
):
96 router
.load_config(TopoRouter
.RD_BGP
, daemon_file
)
98 daemon_file
= "{}/{}/isisd.conf".format(CWD
, rname
)
99 if os
.path
.isfile(daemon_file
):
100 router
.load_config(TopoRouter
.RD_ISIS
, daemon_file
)
102 daemon_file
= "{}/{}/ospfd.conf".format(CWD
, rname
)
103 if os
.path
.isfile(daemon_file
):
104 router
.load_config(TopoRouter
.RD_OSPF
, daemon_file
)
106 daemon_file
= "{}/{}/ospf6d.conf".format(CWD
, rname
)
107 if os
.path
.isfile(daemon_file
):
108 router
.load_config(TopoRouter
.RD_OSPF6
, daemon_file
)
110 daemon_file
= "{}/{}/zebra.conf".format(CWD
, rname
)
111 if os
.path
.isfile(daemon_file
):
112 router
.load_config(TopoRouter
.RD_ZEBRA
, daemon_file
)
114 # Initialize all routers.
118 def teardown_module(_mod
):
119 "Teardown the pytest environment"
124 def test_wait_protocols_convergence():
125 "Wait for all protocols to converge"
127 if tgen
.routers_have_failure():
128 pytest
.skip(tgen
.errors
)
130 logger
.info("waiting for protocols to converge")
132 def expect_loopback_route(router
, iptype
, route
, proto
):
133 "Wait until route is present on RIB for protocol."
134 logger
.info("waiting route {} in {}".format(route
, router
))
136 topotest
.router_json_cmp
,
138 "show {} route json".format(iptype
),
139 {route
: [{"protocol": proto
}]},
141 _
, result
= topotest
.run_and_expect(test_func
, None, count
=130, wait
=1)
142 assertmsg
= '"{}" OSPF convergence failure'.format(router
)
143 assert result
is None, assertmsg
145 # Wait for R1 <-> R6 convergence.
146 expect_loopback_route("r1", "ip", "10.254.254.6/32", "ospf")
148 # Wait for R6 <-> R1 convergence.
149 expect_loopback_route("r6", "ip", "10.254.254.1/32", "ospf")
151 # Wait for R2 <-> R3 convergence.
152 expect_loopback_route("r2", "ip", "10.254.254.3/32", "bgp")
154 # Wait for R3 <-> R2 convergence.
155 expect_loopback_route("r3", "ip", "10.254.254.2/32", "bgp")
157 # Wait for R3 <-> R4 convergence.
158 expect_loopback_route("r3", "ipv6", "2001:db8:3::/64", "isis")
160 # Wait for R4 <-> R3 convergence.
161 expect_loopback_route("r4", "ipv6", "2001:db8:1::/64", "isis")
163 # Wait for R4 <-> R5 convergence.
164 expect_loopback_route("r4", "ipv6", "2001:db8:3::/64", "ospf6")
166 # Wait for R5 <-> R4 convergence.
167 expect_loopback_route("r5", "ipv6", "2001:db8:2::/64", "ospf6")
170 def test_bfd_profile_values():
171 "Assert that the BFD peers can find themselves."
173 if tgen
.routers_have_failure():
174 pytest
.skip(tgen
.errors
)
176 logger
.info("waiting for bfd peers to go up and checking profile values")
178 for router
in tgen
.routers().values():
179 json_file
= "{}/{}/bfd-peers-initial.json".format(CWD
, router
.name
)
180 expected
= json
.loads(open(json_file
).read())
182 topotest
.router_json_cmp
, router
, "show bfd peers json", expected
184 _
, result
= topotest
.run_and_expect(test_func
, None, count
=12, wait
=0.5)
185 assertmsg
= '"{}" JSON output mismatches'.format(router
.name
)
186 assert result
is None, assertmsg
189 def test_memory_leak():
190 "Run the memory leak test and report results."
192 if not tgen
.is_memleak_enabled():
193 pytest
.skip("Memory leak test/report is disabled")
195 tgen
.report_memory_leaks()
198 if __name__
== "__main__":
199 args
= ["-s"] + sys
.argv
[1:]
200 sys
.exit(pytest
.main(args
))