]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/bfd_topo2/test_bfd_topo2.py
Merge pull request #8878 from idryzhov/fix-ospf6-neighbor-detail
[mirror_frr.git] / tests / topotests / bfd_topo2 / test_bfd_topo2.py
CommitLineData
812f5a3d
RZ
1#!/usr/bin/env python
2
3#
4# test_bfd_topo2.py
5# Part of NetDEF Topology Tests
6#
7# Copyright (c) 2019 by
8# Network Device Education Foundation, Inc. ("NetDEF")
9#
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
13# in all copies.
14#
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
22# OF THIS SOFTWARE.
23#
24
25"""
622c4996 26test_bfd_topo2.py: Test the FRR BFD daemon with multihop and BGP
812f5a3d
RZ
27unnumbered.
28"""
29
30import os
31import sys
32import json
33from functools import partial
34import pytest
35
36# Save the Current Working Directory to find configuration files.
37CWD = os.path.dirname(os.path.realpath(__file__))
787e7624 38sys.path.append(os.path.join(CWD, "../"))
812f5a3d
RZ
39
40# pylint: disable=C0413
41# Import topogen and topotest helpers
42from lib import topotest
43from lib.topogen import Topogen, TopoRouter, get_topogen
44from lib.topolog import logger
45
46# Required to instantiate the topology builder class.
47from mininet.topo import Topo
48
5ad1fd54
DS
49pytestmark = [pytest.mark.bfdd, pytest.mark.bgpd, pytest.mark.ospfd]
50
812f5a3d
RZ
51
52class BFDTopo(Topo):
53 "Test topology builder"
787e7624 54
812f5a3d
RZ
55 def build(self, *_args, **_opts):
56 "Build function"
57 tgen = get_topogen(self)
58
59 # Create 4 routers.
60 for routern in range(1, 5):
787e7624 61 tgen.add_router("r{}".format(routern))
812f5a3d 62
787e7624 63 switch = tgen.add_switch("s1")
64 switch.add_link(tgen.gears["r1"])
65 switch.add_link(tgen.gears["r2"])
812f5a3d 66
787e7624 67 switch = tgen.add_switch("s2")
68 switch.add_link(tgen.gears["r2"])
69 switch.add_link(tgen.gears["r3"])
812f5a3d 70
787e7624 71 switch = tgen.add_switch("s3")
72 switch.add_link(tgen.gears["r2"])
73 switch.add_link(tgen.gears["r4"])
812f5a3d 74
6907ac7e 75
812f5a3d
RZ
76def setup_module(mod):
77 "Sets up the pytest environment"
78 tgen = Topogen(BFDTopo, mod.__name__)
79 tgen.start_topology()
80
81 router_list = tgen.routers()
e5f0ed14 82 for rname, router in router_list.items():
812f5a3d 83 router.load_config(
787e7624 84 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
812f5a3d
RZ
85 )
86 router.load_config(
787e7624 87 TopoRouter.RD_BFD, os.path.join(CWD, "{}/bfdd.conf".format(rname))
812f5a3d
RZ
88 )
89 router.load_config(
787e7624 90 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
812f5a3d
RZ
91 )
92 router.load_config(
787e7624 93 TopoRouter.RD_OSPF, os.path.join(CWD, "{}/ospfd.conf".format(rname))
812f5a3d
RZ
94 )
95 router.load_config(
787e7624 96 TopoRouter.RD_OSPF6, os.path.join(CWD, "{}/ospf6d.conf".format(rname))
812f5a3d
RZ
97 )
98
99 # Initialize all routers.
100 tgen.start_router()
101
102 # Verify that we are using the proper version and that the BFD
103 # daemon exists.
104 for router in router_list.values():
105 # Check for Version
787e7624 106 if router.has_version("<", "5.1"):
107 tgen.set_error("Unsupported FRR version")
812f5a3d
RZ
108 break
109
110
111def teardown_module(_mod):
112 "Teardown the pytest environment"
113 tgen = get_topogen()
114 tgen.stop_topology()
115
116
117def test_protocols_convergence():
118 """
119 Assert that all protocols have converged before checking for the BFD
120 statuses as they depend on it.
121 """
122 tgen = get_topogen()
123 if tgen.routers_have_failure():
124 pytest.skip(tgen.errors)
125
126 # Check IPv4 routing tables.
127 logger.info("Checking IPv4 routes for convergence")
128 for router in tgen.routers().values():
787e7624 129 json_file = "{}/{}/ipv4_routes.json".format(CWD, router.name)
812f5a3d 130 if not os.path.isfile(json_file):
787e7624 131 logger.info("skipping file {}".format(json_file))
812f5a3d
RZ
132 continue
133
134 expected = json.loads(open(json_file).read())
787e7624 135 test_func = partial(
136 topotest.router_json_cmp, router, "show ip route json", expected
137 )
138 _, result = topotest.run_and_expect(test_func, None, count=160, wait=0.5)
812f5a3d
RZ
139 assertmsg = '"{}" JSON output mismatches'.format(router.name)
140 assert result is None, assertmsg
141
142 # Check IPv6 routing tables.
143 logger.info("Checking IPv6 routes for convergence")
144 for router in tgen.routers().values():
787e7624 145 json_file = "{}/{}/ipv6_routes.json".format(CWD, router.name)
812f5a3d 146 if not os.path.isfile(json_file):
787e7624 147 logger.info("skipping file {}".format(json_file))
812f5a3d
RZ
148 continue
149
150 expected = json.loads(open(json_file).read())
787e7624 151 test_func = partial(
152 topotest.router_json_cmp, router, "show ipv6 route json", expected
153 )
154 _, result = topotest.run_and_expect(test_func, None, count=160, wait=0.5)
812f5a3d
RZ
155 assertmsg = '"{}" JSON output mismatches'.format(router.name)
156 assert result is None, assertmsg
157
158
159def test_bfd_connection():
160 "Assert that the BFD peers can find themselves."
161 tgen = get_topogen()
162 if tgen.routers_have_failure():
163 pytest.skip(tgen.errors)
164
787e7624 165 logger.info("waiting for bfd peers to go up")
812f5a3d
RZ
166
167 for router in tgen.routers().values():
787e7624 168 json_file = "{}/{}/peers.json".format(CWD, router.name)
812f5a3d
RZ
169 expected = json.loads(open(json_file).read())
170
787e7624 171 test_func = partial(
172 topotest.router_json_cmp, router, "show bfd peers json", expected
173 )
812f5a3d
RZ
174 _, result = topotest.run_and_expect(test_func, None, count=8, wait=0.5)
175 assertmsg = '"{}" JSON output mismatches'.format(router.name)
176 assert result is None, assertmsg
177
178
179def test_memory_leak():
180 "Run the memory leak test and report results."
181 tgen = get_topogen()
182 if not tgen.is_memleak_enabled():
787e7624 183 pytest.skip("Memory leak test/report is disabled")
812f5a3d
RZ
184
185 tgen.report_memory_leaks()
186
187
787e7624 188if __name__ == "__main__":
812f5a3d
RZ
189 args = ["-s"] + sys.argv[1:]
190 sys.exit(pytest.main(args))