]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/ldp_oc_topo1/test_ldp_oc_topo1.py
5 # Part of NetDEF Topology Tests
7 # Copyright (c) 2020 by by Volta Networks
9 # Permission to use, copy, modify, and/or distribute this software
10 # for any purpose with or without fee is hereby granted, provided
11 # that the above copyright notice and this permission notice appear
14 # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
15 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
17 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
18 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
19 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
20 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
25 test_ldp_oc_topo1.py: Simple FRR LDP Test
44 r2-eth2 .2 | | .2 r2-eth1
47 ~~~~~~~~~~~~~ ~~~~~~~~~~~~~
49 ~~ 10.0.3.0/24 ~~ ~~ 10.0.2.0/24 ~~
50 ~~~~~~~~~~~~~ ~~~~~~~~~~~~~
54 r3-eth1 .3 | | .3 r3-eth0 | .4 r4-eth0
55 +----+--+---+ +----+----+
57 | 3.3.3.3 | | 4.4.4.4 |
58 +-----------+ +---------+
65 from time
import sleep
66 from functools
import partial
68 # Save the Current Working Directory to find configuration files.
69 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
70 sys
.path
.append(os
.path
.join(CWD
, "../"))
72 # pylint: disable=C0413
73 # Import topogen and topotest helpers
74 from lib
import topotest
75 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
76 from lib
.topolog
import logger
78 # Required to instantiate the topology builder class.
79 from mininet
.topo
import Topo
81 pytestmark
= [pytest
.mark
.ldpd
, pytest
.mark
.ospfd
]
84 class TemplateTopo(Topo
):
85 "Test topology builder"
87 def build(self
, *_args
, **_opts
):
89 tgen
= get_topogen(self
)
94 for router
in ["r1", "r2", "r3", "r4"]:
95 tgen
.add_router(router
)
100 switch
= tgen
.add_switch("s0")
101 switch
.add_link(tgen
.gears
["r1"])
102 switch
.add_link(tgen
.gears
["r2"])
104 switch
= tgen
.add_switch("s1")
105 switch
.add_link(tgen
.gears
["r2"])
106 switch
.add_link(tgen
.gears
["r3"])
107 switch
.add_link(tgen
.gears
["r4"])
109 switch
= tgen
.add_switch("s2")
110 switch
.add_link(tgen
.gears
["r2"])
111 switch
.add_link(tgen
.gears
["r3"])
114 def setup_module(mod
):
115 "Sets up the pytest environment"
116 tgen
= Topogen(TemplateTopo
, mod
.__name
__)
117 tgen
.start_topology()
119 router_list
= tgen
.routers()
121 # For all registered routers, load the zebra configuration file
122 for rname
, router
in router_list
.items():
124 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
126 # Don't start ospfd and ldpd in the CE nodes
127 if router
.name
[0] == "r":
129 TopoRouter
.RD_OSPF
, os
.path
.join(CWD
, "{}/ospfd.conf".format(rname
))
132 TopoRouter
.RD_LDP
, os
.path
.join(CWD
, "{}/ldpd.conf".format(rname
))
138 def teardown_module(mod
):
139 "Teardown the pytest environment"
142 # This function tears down the whole topology.
146 def router_compare_json_output(rname
, command
, reference
):
147 "Compare router JSON output"
149 logger
.info('Comparing router "%s" "%s" output', rname
, command
)
152 filename
= "{}/{}/{}".format(CWD
, rname
, reference
)
153 expected
= json
.loads(open(filename
).read())
155 # Run test function until we get an result. Wait at most 80 seconds.
156 test_func
= partial(topotest
.router_json_cmp
, tgen
.gears
[rname
], command
, expected
)
157 _
, diff
= topotest
.run_and_expect(test_func
, None, count
=160, wait
=0.5)
159 assertmsg
= '"{}" JSON output mismatches the expected result'.format(rname
)
160 assert diff
is None, assertmsg
163 def test_ospf_convergence():
164 logger
.info("Test: check OSPF adjacencies")
168 # Skip if previous fatal error condition is raised
169 if tgen
.routers_have_failure():
170 pytest
.skip(tgen
.errors
)
172 for rname
in ["r1", "r2", "r3", "r4"]:
173 router_compare_json_output(
174 rname
, "show ip ospf neighbor json", "show_ip_ospf_neighbor.json"
179 logger
.info("Test: verify RIB")
182 # Skip if previous fatal error condition is raised
183 if tgen
.routers_have_failure():
184 pytest
.skip(tgen
.errors
)
186 for rname
in ["r1", "r2", "r3", "r4"]:
187 router_compare_json_output(rname
, "show ip route json", "show_ip_route.ref")
190 def test_ldp_adjacencies():
191 logger
.info("Test: verify LDP adjacencies")
194 # Skip if previous fatal error condition is raised
195 if tgen
.routers_have_failure():
196 pytest
.skip(tgen
.errors
)
198 for rname
in ["r1", "r2", "r3", "r4"]:
199 router_compare_json_output(
200 rname
, "show mpls ldp discovery json", "show_ldp_discovery.ref"
204 def test_ldp_neighbors():
205 logger
.info("Test: verify LDP neighbors")
208 # Skip if previous fatal error condition is raised
209 if tgen
.routers_have_failure():
210 pytest
.skip(tgen
.errors
)
212 for rname
in ["r1", "r2", "r3", "r4"]:
213 router_compare_json_output(
214 rname
, "show mpls ldp neighbor json", "show_ldp_neighbor.ref"
218 def test_ldp_bindings():
219 logger
.info("Test: verify LDP bindings")
222 # Skip if previous fatal error condition is raised
223 if tgen
.routers_have_failure():
224 pytest
.skip(tgen
.errors
)
226 for rname
in ["r1", "r2", "r3", "r4"]:
227 router_compare_json_output(
228 rname
, "show mpls ldp binding json", "show_ldp_binding.ref"
232 # Memory leak test template
233 def test_memory_leak():
234 "Run the memory leak test and report results."
236 if not tgen
.is_memleak_enabled():
237 pytest
.skip("Memory leak test/report is disabled")
239 tgen
.report_memory_leaks()
242 if __name__
== "__main__":
243 args
= ["-s"] + sys
.argv
[1:]
244 sys
.exit(pytest
.main(args
))