]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/evpn-pim-1/test_evpn_pim_topo1.py
Merge pull request #7550 from volta-networks/fix_bfd_isis
[mirror_frr.git] / tests / topotests / evpn-pim-1 / test_evpn_pim_topo1.py
CommitLineData
94bd5b93
AK
1#!/usr/bin/env python
2
3#
4# test_evpn-pim_topo1.py
5#
6# Copyright (c) 2017 by
7# Cumulus Networks, Inc.
8# Donald Sharp
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"""
26test_evpn_pim_topo1.py: Testing evpn-pim
27
28"""
29
30import os
31import re
32import sys
33import pytest
34import json
35from functools import partial
36
37# Save the Current Working Directory to find configuration files.
38CWD = os.path.dirname(os.path.realpath(__file__))
787e7624 39sys.path.append(os.path.join(CWD, "../"))
94bd5b93
AK
40
41# pylint: disable=C0413
42# Import topogen and topotest helpers
43from lib import topotest
44from lib.topogen import Topogen, TopoRouter, get_topogen
45from lib.topolog import logger
46
47# Required to instantiate the topology builder class.
48from mininet.topo import Topo
49
50#####################################################
51##
52## Network Topology Definition
53##
54#####################################################
55
787e7624 56
94bd5b93
AK
57class NetworkTopo(Topo):
58 "evpn-pim Topology 1"
59
60 def build(self, **_opts):
61 "Build function"
62
63 tgen = get_topogen(self)
64
787e7624 65 tgen.add_router("spine")
66 tgen.add_router("leaf1")
67 tgen.add_router("leaf2")
68 tgen.add_router("host1")
69 tgen.add_router("host2")
94bd5b93
AK
70
71 # On main router
72 # First switch is for a dummy interface (for local network)
73 # spine-eth0 is connected to leaf1-eth0
787e7624 74 switch = tgen.add_switch("sw1")
75 switch.add_link(tgen.gears["spine"])
76 switch.add_link(tgen.gears["leaf1"])
94bd5b93
AK
77
78 # spine-eth1 is connected to leaf2-eth0
787e7624 79 switch = tgen.add_switch("sw2")
80 switch.add_link(tgen.gears["spine"])
81 switch.add_link(tgen.gears["leaf2"])
94bd5b93
AK
82
83 # leaf1-eth1 is connected to host1-eth0
787e7624 84 switch = tgen.add_switch("sw3")
85 switch.add_link(tgen.gears["leaf1"])
86 switch.add_link(tgen.gears["host1"])
94bd5b93
AK
87
88 # leaf2-eth1 is connected to host2-eth0
787e7624 89 switch = tgen.add_switch("sw4")
90 switch.add_link(tgen.gears["leaf2"])
91 switch.add_link(tgen.gears["host2"])
94bd5b93
AK
92
93
94#####################################################
95##
96## Tests starting
97##
98#####################################################
99
b9f3e47f 100@pytest.mark.pim
94bd5b93
AK
101def setup_module(module):
102 "Setup topology"
103 tgen = Topogen(NetworkTopo, module.__name__)
104 tgen.start_topology()
105
787e7624 106 leaf1 = tgen.gears["leaf1"]
107 leaf2 = tgen.gears["leaf2"]
108
109 leaf1.run("brctl addbr brleaf1")
110 leaf2.run("brctl addbr brleaf2")
111 leaf1.run("ip link set dev brleaf1 up")
112 leaf2.run("ip link set dev brleaf2 up")
113 leaf1.run(
114 "ip link add vxlan0 type vxlan id 42 group 239.1.1.1 dev leaf1-eth1 dstport 4789"
115 )
116 leaf2.run(
117 "ip link add vxlan0 type vxlan id 42 group 239.1.1.1 dev leaf2-eth1 dstport 4789"
118 )
119 leaf1.run("brctl addif brleaf1 vxlan0")
120 leaf2.run("brctl addif brleaf2 vxlan0")
121 leaf1.run("ip link set up dev vxlan0")
122 leaf2.run("ip link set up dev vxlan0")
123 # tgen.mininet_cli()
94bd5b93
AK
124 # This is a sample of configuration loading.
125 router_list = tgen.routers()
e5f0ed14 126 for rname, router in router_list.items():
94bd5b93 127 router.load_config(
787e7624 128 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
94bd5b93
AK
129 )
130 router.load_config(
787e7624 131 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
94bd5b93
AK
132 )
133 router.load_config(
787e7624 134 TopoRouter.RD_PIM, os.path.join(CWD, "{}/pimd.conf".format(rname))
94bd5b93
AK
135 )
136 tgen.start_router()
787e7624 137 # tgen.mininet_cli()
138
94bd5b93
AK
139
140def teardown_module(_mod):
141 "Teardown the pytest environment"
142 tgen = get_topogen()
143
144 # This function tears down the whole topology.
145 tgen.stop_topology()
146
147
148def test_converge_protocols():
149 "Wait for protocol convergence"
150
151 tgen = get_topogen()
152 # Don't run this test if we have any failure.
153 if tgen.routers_have_failure():
154 pytest.skip(tgen.errors)
155
787e7624 156 spine = tgen.gears["spine"]
157 json_file = "{}/{}/bgp.summ.json".format(CWD, spine.name)
94bd5b93
AK
158 expected = json.loads(open(json_file).read())
159
787e7624 160 test_func = partial(
161 topotest.router_json_cmp, spine, "show bgp ipv4 uni summ json", expected
162 )
94bd5b93
AK
163 _, result = topotest.run_and_expect(test_func, None, count=125, wait=1)
164 assertmsg = '"{}" JSON output mismatches'.format(spine.name)
165 assert result is None, assertmsg
787e7624 166 # tgen.mininet_cli()
167
94bd5b93
AK
168
169def test_multicast_groups_on_rp():
170 "Ensure the multicast groups show up on the spine"
171 # This test implicitly tests the auto mcast groups
172 # of the created vlans and then the auto-joins that
173 # pim will do to the RP( spine )
174
175 tgen = get_topogen()
176
177 if tgen.routers_have_failure():
178 pytest.skip(tgen.errors)
179
787e7624 180 spine = tgen.gears["spine"]
181 json_file = "{}/{}/join-info.json".format(CWD, spine.name)
94bd5b93
AK
182 expected = json.loads(open(json_file).read())
183
787e7624 184 test_func = partial(
185 topotest.router_json_cmp, spine, "show ip pim join json", expected
186 )
94bd5b93
AK
187 _, result = topotest.run_and_expect(test_func, None, count=30, wait=1)
188 assertmsg = '"{}" JSON output mismatches'.format(spine.name)
189 assert result is None, assertmsg
787e7624 190 # tgen.mininet_cli()
191
94bd5b93
AK
192
193def test_shutdown_check_stderr():
787e7624 194 if os.environ.get("TOPOTESTS_CHECK_STDERR") is None:
195 pytest.skip("Skipping test for Stderr output and memory leaks")
94bd5b93
AK
196
197 tgen = get_topogen()
198 # Don't run this test if we have any failure.
199 if tgen.routers_have_failure():
200 pytest.skip(tgen.errors)
201
202 logger.info("Verifying unexpected STDERR output from daemons")
203
204 router_list = tgen.routers().values()
205 for router in router_list:
206 router.stop()
207
787e7624 208 log = tgen.net[router.name].getStdErr("pimd")
94bd5b93 209 if log:
787e7624 210 logger.error("PIMd StdErr Log:" + log)
211 log = tgen.net[router.name].getStdErr("bgpd")
94bd5b93 212 if log:
787e7624 213 logger.error("BGPd StdErr Log:" + log)
214 log = tgen.net[router.name].getStdErr("zebra")
94bd5b93 215 if log:
787e7624 216 logger.error("Zebra StdErr Log:" + log)
94bd5b93
AK
217
218
787e7624 219if __name__ == "__main__":
94bd5b93
AK
220 args = ["-s"] + sys.argv[1:]
221 sys.exit(pytest.main(args))