]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_route_map_vpn_import/test_bgp_route_map_vpn_import.py
Merge pull request #12762 from sri-mohan1/sri-bable
[mirror_frr.git] / tests / topotests / bgp_route_map_vpn_import / test_bgp_route_map_vpn_import.py
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 """
23 Test if `route-map vpn import NAME` works by setting/matching via route-maps.
24 Routes from VRF Customer to VRF Service MUST be leaked and modified later
25 with `route-map vpn import`.
26 """
27
28 import os
29 import sys
30 import json
31 import pytest
32 import functools
33
34 CWD = os.path.dirname(os.path.realpath(__file__))
35 sys.path.append(os.path.join(CWD, "../"))
36
37 # pylint: disable=C0413
38 from lib import topotest
39 from lib.topogen import Topogen, TopoRouter, get_topogen
40 from lib.common_config import step
41
42 pytestmark = [pytest.mark.bgpd]
43
44
45 def build_topo(tgen):
46 tgen.add_router("r1")
47
48 switch = tgen.add_switch("s1")
49 switch.add_link(tgen.gears["r1"])
50
51 switch = tgen.add_switch("s2")
52 switch.add_link(tgen.gears["r1"])
53
54 switch = tgen.add_switch("s3")
55 switch.add_link(tgen.gears["r1"])
56
57 switch = tgen.add_switch("s4")
58 switch.add_link(tgen.gears["r1"])
59
60
61 def setup_module(mod):
62 tgen = Topogen(build_topo, mod.__name__)
63 tgen.start_topology()
64
65 r1 = tgen.gears["r1"]
66
67 r1.run("ip link add Customer type vrf table 1001")
68 r1.run("ip link set up dev Customer")
69 r1.run("ip link set r1-eth0 master Customer")
70 r1.run("ip link add Service type vrf table 1002")
71 r1.run("ip link set up dev Service")
72 r1.run("ip link set r1-eth1 master Service")
73 r1.run("ip link set r1-eth3 master Customer")
74
75 router_list = tgen.routers()
76
77 for i, (rname, router) in enumerate(router_list.items(), 1):
78 router.load_config(
79 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
80 )
81 router.load_config(
82 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
83 )
84
85 tgen.start_router()
86
87
88 def teardown_module(mod):
89 tgen = get_topogen()
90 tgen.stop_topology()
91
92
93 def test_bgp_route_map_vpn_import():
94 tgen = get_topogen()
95
96 if tgen.routers_have_failure():
97 pytest.skip(tgen.errors)
98
99 r1 = tgen.gears["r1"]
100
101 def _bgp_check_received_leaked_with_vpn_import():
102 output = json.loads(r1.vtysh_cmd("show bgp vrf Service ipv4 unicast json"))
103 expected = {
104 "routes": {
105 "192.0.2.0/24": [
106 {
107 "locPrf": 123,
108 },
109 ],
110 "192.168.1.0/24": [
111 {
112 "locPrf": None,
113 }
114 ],
115 }
116 }
117 return topotest.json_cmp(output, expected)
118
119 test_func = functools.partial(_bgp_check_received_leaked_with_vpn_import)
120 _, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
121 assert result is None, "Failed, imported routes are not modified"
122
123
124 if __name__ == "__main__":
125 args = ["-s"] + sys.argv[1:]
126 sys.exit(pytest.main(args))