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