]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/bgp_vpn_5549_route_map/test_bgp_vpn_5549_route_map.py
tests: Check if we can override IPv6 next-hop for VPN networks in route-map
[mirror_frr.git] / tests / topotests / bgp_vpn_5549_route_map / test_bgp_vpn_5549_route_map.py
CommitLineData
9a84cb61
DA
1#!/usr/bin/env python
2
3#
4# Copyright (c) 2022 by
5# Donatas Abraitis <donatas@opensourcerouting.org>
6#
7# Permission to use, copy, modify, and/or distribute this software
8# for any purpose with or without fee is hereby granted, provided
9# that the above copyright notice and this permission notice appear
10# in all copies.
11#
12# THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
13# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
15# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
16# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
17# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
18# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
19# OF THIS SOFTWARE.
20#
21
22"""
23Check if we can override VPN underlay next-hop from PE1 to PE2.
24"""
25
26import os
27import sys
28import json
29import pytest
30import functools
31
32CWD = os.path.dirname(os.path.realpath(__file__))
33sys.path.append(os.path.join(CWD, "../"))
34
35# pylint: disable=C0413
36from lib import topotest
37from lib.topogen import Topogen, TopoRouter, get_topogen
38from lib.common_config import step
39
40pytestmark = [pytest.mark.bgpd]
41
42
43def build_topo(tgen):
44 tgen.add_router("cpe1")
45 tgen.add_router("cpe2")
46 tgen.add_router("pe1")
47 tgen.add_router("pe2")
48
49 switch = tgen.add_switch("s1")
50 switch.add_link(tgen.gears["cpe1"])
51 switch.add_link(tgen.gears["pe1"])
52
53 switch = tgen.add_switch("s2")
54 switch.add_link(tgen.gears["pe1"])
55 switch.add_link(tgen.gears["pe2"])
56
57 switch = tgen.add_switch("s3")
58 switch.add_link(tgen.gears["pe2"])
59 switch.add_link(tgen.gears["cpe2"])
60
61
62def setup_module(mod):
63 tgen = Topogen(build_topo, mod.__name__)
64 tgen.start_topology()
65
66 pe1 = tgen.gears["pe1"]
67 pe2 = tgen.gears["pe2"]
68
69 pe1.run("ip link add RED type vrf table 1001")
70 pe1.run("ip link set up dev RED")
71 pe2.run("ip link add RED type vrf table 1001")
72 pe2.run("ip link set up dev RED")
73 pe1.run("ip link set pe1-eth0 master RED")
74 pe2.run("ip link set pe2-eth1 master RED")
75
76 pe1.run("sysctl -w net.ipv4.ip_forward=1")
77 pe2.run("sysctl -w net.ipv4.ip_forward=1")
78 pe1.run("sysctl -w net.mpls.conf.pe1-eth0.input=1")
79 pe2.run("sysctl -w net.mpls.conf.pe2-eth1.input=1")
80
81 router_list = tgen.routers()
82
83 for i, (rname, router) in enumerate(router_list.items(), 1):
84 router.load_config(
85 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
86 )
87 router.load_config(
88 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
89 )
90 router.load_config(
91 TopoRouter.RD_OSPF6, os.path.join(CWD, "{}/ospf6d.conf".format(rname))
92 )
93 router.load_config(
94 TopoRouter.RD_LDP, os.path.join(CWD, "{}/ldpd.conf".format(rname))
95 )
96
97 tgen.start_router()
98
99
100def teardown_module(mod):
101 tgen = get_topogen()
102 tgen.stop_topology()
103
104
105def test_bgp_vpn_5549():
106 tgen = get_topogen()
107
108 pe2 = tgen.gears["pe2"]
109
110 if tgen.routers_have_failure():
111 pytest.skip(tgen.errors)
112
113 def _bgp_vpn_nexthop_changed():
114 output = json.loads(pe2.vtysh_cmd("show bgp ipv4 vpn json"))
115 expected = {
116 "routes": {
117 "routeDistinguishers": {
118 "192.168.1.2:2": {
119 "172.16.255.1/32": [
120 {"valid": True, "nexthops": [{"ip": "2001:db8::1"}]}
121 ],
122 "192.168.1.0/24": [
123 {"valid": True, "nexthops": [{"ip": "2001:db8:1::1"}]}
124 ],
125 }
126 }
127 }
128 }
129 return topotest.json_cmp(output, expected)
130
131 test_func = functools.partial(_bgp_vpn_nexthop_changed)
132 _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
133 assert result is None, "Failed overriding IPv6 next-hop for VPN underlay"
134
135
136if __name__ == "__main__":
137 args = ["-s"] + sys.argv[1:]
138 sys.exit(pytest.main(args))