]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/ldp-oc-acl-topo1/test_ldp_oc_acl_topo1.py
Merge pull request #6079 from sarav511/regstop_exp
[mirror_frr.git] / tests / topotests / ldp-oc-acl-topo1 / test_ldp_oc_acl_topo1.py
CommitLineData
418b2885
KS
1#!/usr/bin/env python
2
3#
4# test_ldp_oc_acl_topo1.py
5# Part of NetDEF Topology Tests
6#
7# Copyright (c) 2020 by Volta Networks
8#
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
12# in all copies.
13#
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
21# OF THIS SOFTWARE.
22#
23
24"""
25test_ldp_oc_acl_topo1.py: Simple FRR/Quagga LDP Test
26
27 +---------+
28 | r1 |
29 | 1.1.1.1 |
30 +----+----+
31 | .1 r1-eth0
32 |
33 ~~~~~~~~~~~~~
34 ~~ sw0 ~~
35 ~~ 10.0.1.0/24 ~~
36 ~~~~~~~~~~~~~
37 |10.0.1.0/24
38 |
39 | .2 r2-eth0
40 +----+----+
41 | r2 |
42 | 2.2.2.2 |
43 +--+---+--+
44 r2-eth2 .2 | | .2 r2-eth1
45 ______/ \______
46 / \
47 ~~~~~~~~~~~~~ ~~~~~~~~~~~~~
48~~ sw2 ~~ ~~ sw1 ~~
49~~ 10.0.3.0/24 ~~ ~~ 10.0.2.0/24 ~~
50 ~~~~~~~~~~~~~ ~~~~~~~~~~~~~
51 | / |
52 \ _________/ |
53 \ / \
54r3-eth1 .3 | | .3 r3-eth0 | .4 r4-eth0
55 +----+--+---+ +----+----+
56 | r3 | | r4 |
57 | 3.3.3.3 | | 4.4.4.4 |
58 +-----------+ +---------+
59"""
60
61import os
62import sys
63import pytest
64import json
65from time import sleep
66from functools import partial
67
68# Save the Current Working Directory to find configuration files.
69CWD = os.path.dirname(os.path.realpath(__file__))
70sys.path.append(os.path.join(CWD, '../'))
71
72# pylint: disable=C0413
73# Import topogen and topotest helpers
74from lib import topotest
75from lib.topogen import Topogen, TopoRouter, get_topogen
76from lib.topolog import logger
77
78# Required to instantiate the topology builder class.
79from mininet.topo import Topo
80
81class TemplateTopo(Topo):
82 "Test topology builder"
83 def build(self, *_args, **_opts):
84 "Build function"
85 tgen = get_topogen(self)
86
87 #
88 # Define FRR Routers
89 #
90 for router in ['r1', 'r2', 'r3', 'r4']:
91 tgen.add_router(router)
92
93 #
94 # Define connections
95 #
96 switch = tgen.add_switch('s0')
97 switch.add_link(tgen.gears['r1'])
98 switch.add_link(tgen.gears['r2'])
99
100 switch = tgen.add_switch('s1')
101 switch.add_link(tgen.gears['r2'])
102 switch.add_link(tgen.gears['r3'])
103 switch.add_link(tgen.gears['r4'])
104
105 switch = tgen.add_switch('s2')
106 switch.add_link(tgen.gears['r2'])
107 switch.add_link(tgen.gears['r3'])
108
109def setup_module(mod):
110 "Sets up the pytest environment"
111 tgen = Topogen(TemplateTopo, mod.__name__)
112 tgen.start_topology()
113
114 router_list = tgen.routers()
115
116 # For all registered routers, load the zebra configuration file
117 for rname, router in router_list.iteritems():
118 router.load_config(
119 TopoRouter.RD_ZEBRA,
120 os.path.join(CWD, '{}/zebra.conf'.format(rname))
121 )
122 # Don't start ospfd and ldpd in the CE nodes
123 if router.name[0] == 'r':
124 router.load_config(
125 TopoRouter.RD_OSPF,
126 os.path.join(CWD, '{}/ospfd.conf'.format(rname))
127 )
128 router.load_config(
129 TopoRouter.RD_LDP,
130 os.path.join(CWD, '{}/ldpd.conf'.format(rname))
131 )
132
133 tgen.start_router()
134
135def teardown_module(mod):
136 "Teardown the pytest environment"
137 tgen = get_topogen()
138
139 # This function tears down the whole topology.
140 tgen.stop_topology()
141
142
143def router_compare_json_output(rname, command, reference):
144 "Compare router JSON output"
145
146 logger.info('Comparing router "%s" "%s" output', rname, command)
147
148 tgen = get_topogen()
149 filename = '{}/{}/{}'.format(CWD, rname, reference)
150 expected = json.loads(open(filename).read())
151
152 # Run test function until we get an result. Wait at most 80 seconds.
153 test_func = partial(topotest.router_json_cmp,
154 tgen.gears[rname], command, expected)
155 _, diff = topotest.run_and_expect(test_func, None, count=160, wait=0.5)
156
157 assertmsg = '"{}" JSON output mismatches the expected result'.format(rname)
158 assert diff is None, assertmsg
159
160def test_ospf_convergence():
161 logger.info("Test: check OSPF adjacencies")
162
163 tgen = get_topogen()
164
165 # Skip if previous fatal error condition is raised
166 if tgen.routers_have_failure():
167 pytest.skip(tgen.errors)
168
169 for rname in ['r1', 'r2', 'r3', 'r4']:
170 router_compare_json_output(rname, "show ip ospf neighbor json", "show_ip_ospf_neighbor.json")
171
172def test_rib():
173 logger.info("Test: verify RIB")
174 tgen = get_topogen()
175
176 # Skip if previous fatal error condition is raised
177 if tgen.routers_have_failure():
178 pytest.skip(tgen.errors)
179
180 for rname in ['r1', 'r2', 'r3', 'r4']:
181 router_compare_json_output(rname, "show ip route json", "show_ip_route.ref")
182
183def test_ldp_adjacencies():
184 logger.info("Test: verify LDP adjacencies")
185 tgen = get_topogen()
186
187 # Skip if previous fatal error condition is raised
188 if tgen.routers_have_failure():
189 pytest.skip(tgen.errors)
190
191 for rname in ['r1', 'r2', 'r3', 'r4']:
192 router_compare_json_output(rname, "show mpls ldp discovery json", "show_ldp_discovery.ref")
193
194def test_ldp_neighbors():
195 logger.info("Test: verify LDP neighbors")
196 tgen = get_topogen()
197
198 # Skip if previous fatal error condition is raised
199 if tgen.routers_have_failure():
200 pytest.skip(tgen.errors)
201
202 for rname in ['r1', 'r2', 'r3', 'r4']:
203 router_compare_json_output(rname, "show mpls ldp neighbor json", "show_ldp_neighbor.ref")
204
205def test_ldp_bindings():
206 logger.info("Test: verify LDP bindings")
207 tgen = get_topogen()
208
209 # Skip if previous fatal error condition is raised
210 if tgen.routers_have_failure():
211 pytest.skip(tgen.errors)
212
213 for rname in ['r1', 'r2', 'r3', 'r4']:
214 router_compare_json_output(rname, "show mpls ldp binding json", "show_ldp_binding.ref")
215
216# Memory leak test template
217def test_memory_leak():
218 "Run the memory leak test and report results."
219 tgen = get_topogen()
220 if not tgen.is_memleak_enabled():
221 pytest.skip('Memory leak test/report is disabled')
222
223 tgen.report_memory_leaks()
224
225if __name__ == '__main__':
226 args = ["-s"] + sys.argv[1:]
227 sys.exit(pytest.main(args))