]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/test_bgp_srv6l3vpn_to_bgp_vrf.py
tests: fix pylint test errors
[mirror_frr.git] / tests / topotests / bgp_srv6l3vpn_to_bgp_vrf / test_bgp_srv6l3vpn_to_bgp_vrf.py
CommitLineData
7c653fc5
HS
1#!/usr/bin/env python
2
3#
4# Part of NetDEF Topology Tests
5#
6# Copyright (c) 2018, LabN Consulting, L.L.C.
7# Authored by Lou Berger <lberger@labn.net>
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
24import os
25import re
26import sys
27import json
28import functools
29import pytest
30
31CWD = os.path.dirname(os.path.realpath(__file__))
32sys.path.append(os.path.join(CWD, "../"))
33
34# pylint: disable=C0413
35# Import topogen and topotest helpers
36from lib import topotest
37from lib.topogen import Topogen, TopoRouter, get_topogen
38from lib.topolog import logger
39from lib.common_config import required_linux_kernel_version
8db751b8 40from lib.micronet_compat import Topo
7c653fc5 41
bf3a0a9a
DS
42pytestmark = [pytest.mark.bgpd]
43
7c653fc5
HS
44
45class Topology(Topo):
46 """
47 CE1 CE3 CE5
48 (eth0) (eth0) (eth0)
49 :2 :2 :2
50 | | |
51 2001: 2001: 2001:
52 1::/64 3::/64 5::/64
53 | | |
54 :1 :1 :1
55 +-(eth1)--(eth2)---(eth3)-+
56 | \ / | |
57 | (vrf10) (vrf20) |
58 | R1 |
59 +----------(eth0)---------+
60 :1
61 |
62 2001::/64
63 |
64 :2
65 (eth0)
66 +----------(eth0)--------------+
67 | R2 |
68 | (vrf10) (vrf20) |
69 | / / \ |
70 +-(eth1)-----(eth2)-----(eth3)-+
71 :1 :1 :1
72 | | |
73 +------+ +------+ +------+
74 / 2001: \ / 2001: \ / 2001: \
75 \ 2::/64 / \ 4::/64 / \ 6::/64 /
76 +------+ +------+ +------+
77 | | |
78 :2 :2 :2
79 (eth0) (eth0) (eth0)
80 CE2 CE4 CE6
81 """
82 def build(self, *_args, **_opts):
83 tgen = get_topogen(self)
84 tgen.add_router("r1")
85 tgen.add_router("r2")
86 tgen.add_router("ce1")
87 tgen.add_router("ce2")
88 tgen.add_router("ce3")
89 tgen.add_router("ce4")
90 tgen.add_router("ce5")
91 tgen.add_router("ce6")
92
93 tgen.add_link(tgen.gears["r1"], tgen.gears["r2"], "eth0", "eth0")
94 tgen.add_link(tgen.gears["ce1"], tgen.gears["r1"], "eth0", "eth1")
95 tgen.add_link(tgen.gears["ce2"], tgen.gears["r2"], "eth0", "eth1")
96 tgen.add_link(tgen.gears["ce3"], tgen.gears["r1"], "eth0", "eth2")
97 tgen.add_link(tgen.gears["ce4"], tgen.gears["r2"], "eth0", "eth2")
98 tgen.add_link(tgen.gears["ce5"], tgen.gears["r1"], "eth0", "eth3")
99 tgen.add_link(tgen.gears["ce6"], tgen.gears["r2"], "eth0", "eth3")
100
101
102def setup_module(mod):
103 result = required_linux_kernel_version("4.15")
104 if result is not True:
105 pytest.skip("Kernel requirements are not met")
106
107 tgen = Topogen(Topology, mod.__name__)
108 tgen.start_topology()
109 router_list = tgen.routers()
110 for rname, router in tgen.routers().items():
111 router.run("/bin/bash {}/{}/setup.sh".format(CWD, rname))
112 router.load_config(TopoRouter.RD_ZEBRA,
113 os.path.join(CWD, '{}/zebra.conf'.format(rname)))
114 router.load_config(TopoRouter.RD_BGP,
115 os.path.join(CWD, '{}/bgpd.conf'.format(rname)))
116
117 tgen.gears["r1"].run("ip link add vrf10 type vrf table 10")
118 tgen.gears["r1"].run("ip link set vrf10 up")
119 tgen.gears["r1"].run("ip link add vrf20 type vrf table 20")
120 tgen.gears["r1"].run("ip link set vrf20 up")
121 tgen.gears["r1"].run("ip link set eth1 master vrf10")
122 tgen.gears["r1"].run("ip link set eth2 master vrf10")
123 tgen.gears["r1"].run("ip link set eth3 master vrf20")
124
125 tgen.gears["r2"].run("ip link add vrf10 type vrf table 10")
126 tgen.gears["r2"].run("ip link set vrf10 up")
127 tgen.gears["r2"].run("ip link add vrf20 type vrf table 20")
128 tgen.gears["r2"].run("ip link set vrf20 up")
129 tgen.gears["r2"].run("ip link set eth1 master vrf10")
130 tgen.gears["r2"].run("ip link set eth2 master vrf20")
131 tgen.gears["r2"].run("ip link set eth3 master vrf20")
132 tgen.start_router()
133
134
135def teardown_module(mod):
136 tgen = get_topogen()
137 tgen.stop_topology()
138
139
140def open_json_file(filename):
141 try:
142 with open(filename, "r") as f:
143 return json.load(f)
144 except IOError:
145 assert False, "Could not read file {}".format(filename)
146
147
148def test_rib():
149 def _check(name, cmd, expected_file):
150 logger.info("polling")
151 tgen = get_topogen()
152 router = tgen.gears[name]
153 output = json.loads(router.vtysh_cmd(cmd))
154 expected = open_json_file("{}/{}".format(CWD, expected_file))
155 return topotest.json_cmp(output, expected)
156
157 def check(name, cmd, expected_file):
158 logger.info("[+] check {} \"{}\" {}".format(name, cmd, expected_file))
159 tgen = get_topogen()
160 func = functools.partial(_check, name, cmd, expected_file)
161 success, result = topotest.run_and_expect(func, None, count=10, wait=0.5)
162 assert result is None, 'Failed'
163
164 check("r1", "show bgp ipv6 vpn json", "r1/vpnv6_rib.json")
165 check("r2", "show bgp ipv6 vpn json", "r2/vpnv6_rib.json")
166 check("r1", "show ipv6 route vrf vrf10 json", "r1/vrf10_rib.json")
167 check("r1", "show ipv6 route vrf vrf20 json", "r1/vrf20_rib.json")
168 check("r2", "show ipv6 route vrf vrf10 json", "r2/vrf10_rib.json")
169 check("r2", "show ipv6 route vrf vrf20 json", "r2/vrf20_rib.json")
170 check("ce1", "show ipv6 route json", "ce1/ipv6_rib.json")
171 check("ce2", "show ipv6 route json", "ce2/ipv6_rib.json")
172 check("ce3", "show ipv6 route json", "ce3/ipv6_rib.json")
173 check("ce4", "show ipv6 route json", "ce4/ipv6_rib.json")
174 check("ce5", "show ipv6 route json", "ce5/ipv6_rib.json")
175 check("ce6", "show ipv6 route json", "ce6/ipv6_rib.json")
176
177
178def test_ping():
179 def _check(name, dest_addr, match):
180 tgen = get_topogen()
181 output = tgen.gears[name].run("ping6 {} -c 1 -w 1".format(dest_addr))
182 logger.info(output)
183 assert match in output, "ping fail"
184
185 def check(name, dest_addr, match):
186 logger.info("[+] check {} {} {}".format(name, dest_addr, match))
187 tgen = get_topogen()
188 func = functools.partial(_check, name, dest_addr, match)
189 success, result = topotest.run_and_expect(func, None, count=10, wait=0.5)
190 assert result is None, 'Failed'
191
192 check("ce1", "2001:2::2", " 0% packet loss")
193 check("ce1", "2001:3::2", " 0% packet loss")
194 check("ce1", "2001:4::2", " 100% packet loss")
195 check("ce1", "2001:5::2", " 100% packet loss")
196 check("ce1", "2001:6::2", " 100% packet loss")
197 check("ce4", "2001:1::2", " 100% packet loss")
198 check("ce4", "2001:2::2", " 100% packet loss")
199 check("ce4", "2001:3::2", " 100% packet loss")
200 check("ce4", "2001:5::2", " 0% packet loss")
201 check("ce4", "2001:6::2", " 0% packet loss")
202
203
204if __name__ == "__main__":
205 args = ["-s"] + sys.argv[1:]
206 sys.exit(pytest.main(args))