]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/bgp_rr_ibgp/test_bgp_rr_ibgp_topo1.py
tests: Add pytest.mark.bgpd for tests missing this mark
[mirror_frr.git] / tests / topotests / bgp_rr_ibgp / test_bgp_rr_ibgp_topo1.py
CommitLineData
aa2a0498
DS
1#!/usr/bin/env python
2
3#
4# test_bgp_rr_ibgp_topo1.py
5#
6# Copyright (c) 2019 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_bgp_rr_ibgp_topo1.py: Testing IBGP with RR and no IGP
27
a19aca16
DS
28Ensure that a basic rr topology comes up and correctly passes
29routes around
aa2a0498
DS
30
31"""
32
33import os
34import re
35import sys
36import pytest
37import json
38
39# Save the Current Working Directory to find configuration files.
40CWD = os.path.dirname(os.path.realpath(__file__))
787e7624 41sys.path.append(os.path.join(CWD, "../"))
aa2a0498
DS
42
43# pylint: disable=C0413
44# Import topogen and topotest helpers
45from lib import topotest
46from lib.topogen import Topogen, TopoRouter, get_topogen
47from lib.topolog import logger
48
49# Required to instantiate the topology builder class.
50from mininet.topo import Topo
51
bf3a0a9a
DS
52pytestmark = [pytest.mark.bgpd]
53
54
aa2a0498
DS
55#####################################################
56##
57## Network Topology Definition
58##
59#####################################################
60
787e7624 61
aa2a0498
DS
62class NetworkTopo(Topo):
63 "BGP_RR_IBGP Topology 1"
64
65 def build(self, **_opts):
66 "Build function"
67
68 tgen = get_topogen(self)
69
787e7624 70 tgen.add_router("tor1")
71 tgen.add_router("tor2")
72 tgen.add_router("spine1")
aa2a0498
DS
73
74 # First switch is for a dummy interface (for local network)
75 # on tor1
787e7624 76 # 192.168.1.0/24
77 switch = tgen.add_switch("sw1")
78 switch.add_link(tgen.gears["tor1"])
aa2a0498 79
787e7624 80 # 192.168.2.0/24 - tor1 <-> spine1 connection
81 switch = tgen.add_switch("sw2")
82 switch.add_link(tgen.gears["tor1"])
83 switch.add_link(tgen.gears["spine1"])
aa2a0498
DS
84
85 # 3rd switch is for a dummy interface (for local netwokr)
787e7624 86 # 192.168.3.0/24 - tor2
87 switch = tgen.add_switch("sw3")
88 switch.add_link(tgen.gears["tor2"])
aa2a0498 89
787e7624 90 # 192.168.4.0/24 - tor2 <-> spine1 connection
91 switch = tgen.add_switch("sw4")
92 switch.add_link(tgen.gears["tor2"])
93 switch.add_link(tgen.gears["spine1"])
aa2a0498 94
aa2a0498
DS
95
96#####################################################
97##
98## Tests starting
99##
100#####################################################
101
787e7624 102
aa2a0498
DS
103def setup_module(module):
104 "Setup topology"
105 tgen = Topogen(NetworkTopo, module.__name__)
106 tgen.start_topology()
107
108 # This is a sample of configuration loading.
109 router_list = tgen.routers()
e5f0ed14 110 for rname, router in router_list.items():
aa2a0498 111 router.load_config(
787e7624 112 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
aa2a0498
DS
113 )
114 router.load_config(
787e7624 115 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
aa2a0498
DS
116 )
117
118 tgen.start_router()
119 # tgen.mininet_cli()
120
121
122def teardown_module(_mod):
123 "Teardown the pytest environment"
124 tgen = get_topogen()
125
126 # This function tears down the whole topology.
127 tgen.stop_topology()
128
129
130def test_converge_protocols():
131 "Wait for protocol convergence"
132
133 tgen = get_topogen()
134 # Don't run this test if we have any failure.
135 if tgen.routers_have_failure():
136 pytest.skip(tgen.errors)
137
787e7624 138 topotest.sleep(5, "Waiting for BGP_RR_IBGP convergence")
aa2a0498
DS
139
140
141def test_bgp_rr_ibgp_routes():
142 "Test Route Reflection"
143
144 tgen = get_topogen()
145 # Don't run this test if we have any failure.
146 if tgen.routers_have_failure():
147 pytest.skip(tgen.errors)
148
149 # Verify BGP_RR_IBGP Status
150 logger.info("Verifying BGP_RR_IBGP routes")
151
787e7624 152
aa2a0498
DS
153def test_zebra_ipv4_routingTable():
154 "Test 'show ip route'"
155
156 tgen = get_topogen()
157 # Don't run this test if we have any failure.
158 if tgen.routers_have_failure():
159 pytest.skip(tgen.errors)
160
161 failures = 0
162 router_list = tgen.routers().values()
163 for router in router_list:
787e7624 164 output = router.vtysh_cmd("show ip route json", isjson=True)
165 refTableFile = "{}/{}/show_ip_route.json_ref".format(CWD, router.name)
aa2a0498
DS
166 expected = json.loads(open(refTableFile).read())
167
787e7624 168 assertmsg = "Zebra IPv4 Routing Table verification failed for router {}".format(
169 router.name
170 )
aa2a0498
DS
171 assert topotest.json_cmp(output, expected) is None, assertmsg
172
787e7624 173
aa2a0498 174def test_shutdown_check_stderr():
787e7624 175 if os.environ.get("TOPOTESTS_CHECK_STDERR") is None:
176 pytest.skip("Skipping test for Stderr output and memory leaks")
aa2a0498
DS
177
178 tgen = get_topogen()
179 # Don't run this test if we have any failure.
180 if tgen.routers_have_failure():
181 pytest.skip(tgen.errors)
182
183 logger.info("Verifying unexpected STDERR output from daemons")
184
185 router_list = tgen.routers().values()
186 for router in router_list:
187 router.stop()
188
787e7624 189 log = tgen.net[router.name].getStdErr("bgpd")
aa2a0498 190 if log:
787e7624 191 logger.error("BGPd StdErr Log:" + log)
192 log = tgen.net[router.name].getStdErr("zebra")
aa2a0498 193 if log:
787e7624 194 logger.error("Zebra StdErr Log:" + log)
aa2a0498
DS
195
196
787e7624 197if __name__ == "__main__":
aa2a0498
DS
198 args = ["-s"] + sys.argv[1:]
199 sys.exit(pytest.main(args))
200
201#
202# Auxiliary Functions
203#