]>
Commit | Line | Data |
---|---|---|
1c2ba4a2 | 1 | #!/usr/bin/env python |
acddc0ed | 2 | # SPDX-License-Identifier: ISC |
1c2ba4a2 DA |
3 | |
4 | # | |
5 | # Copyright (c) 2022 by | |
6 | # Donatas Abraitis <donatas@opensourcerouting.org> | |
7 | # | |
1c2ba4a2 DA |
8 | |
9 | """ | |
10 | Test if `route-map vpn import NAME` works by setting/matching via route-maps. | |
11 | Routes from VRF Customer to VRF Service MUST be leaked and modified later | |
12 | with `route-map vpn import`. | |
13 | """ | |
14 | ||
15 | import os | |
16 | import sys | |
17 | import json | |
18 | import pytest | |
19 | import functools | |
20 | ||
21 | CWD = os.path.dirname(os.path.realpath(__file__)) | |
22 | sys.path.append(os.path.join(CWD, "../")) | |
23 | ||
24 | # pylint: disable=C0413 | |
25 | from lib import topotest | |
26 | from lib.topogen import Topogen, TopoRouter, get_topogen | |
27 | from lib.common_config import step | |
28 | ||
29 | pytestmark = [pytest.mark.bgpd] | |
30 | ||
31 | ||
32 | def build_topo(tgen): | |
33 | tgen.add_router("r1") | |
34 | ||
35 | switch = tgen.add_switch("s1") | |
36 | switch.add_link(tgen.gears["r1"]) | |
37 | ||
38 | switch = tgen.add_switch("s2") | |
39 | switch.add_link(tgen.gears["r1"]) | |
40 | ||
41 | switch = tgen.add_switch("s3") | |
42 | switch.add_link(tgen.gears["r1"]) | |
43 | ||
44 | switch = tgen.add_switch("s4") | |
45 | switch.add_link(tgen.gears["r1"]) | |
46 | ||
47 | ||
48 | def setup_module(mod): | |
49 | tgen = Topogen(build_topo, mod.__name__) | |
50 | tgen.start_topology() | |
51 | ||
52 | r1 = tgen.gears["r1"] | |
53 | ||
54 | r1.run("ip link add Customer type vrf table 1001") | |
55 | r1.run("ip link set up dev Customer") | |
56 | r1.run("ip link set r1-eth0 master Customer") | |
57 | r1.run("ip link add Service type vrf table 1002") | |
58 | r1.run("ip link set up dev Service") | |
59 | r1.run("ip link set r1-eth1 master Service") | |
60 | r1.run("ip link set r1-eth3 master Customer") | |
61 | ||
62 | router_list = tgen.routers() | |
63 | ||
64 | for i, (rname, router) in enumerate(router_list.items(), 1): | |
65 | router.load_config( | |
66 | TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) | |
67 | ) | |
68 | router.load_config( | |
69 | TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) | |
70 | ) | |
71 | ||
72 | tgen.start_router() | |
73 | ||
74 | ||
75 | def teardown_module(mod): | |
76 | tgen = get_topogen() | |
77 | tgen.stop_topology() | |
78 | ||
79 | ||
80 | def test_bgp_route_map_vpn_import(): | |
81 | tgen = get_topogen() | |
82 | ||
83 | if tgen.routers_have_failure(): | |
84 | pytest.skip(tgen.errors) | |
85 | ||
86 | r1 = tgen.gears["r1"] | |
87 | ||
88 | def _bgp_check_received_leaked_with_vpn_import(): | |
89 | output = json.loads(r1.vtysh_cmd("show bgp vrf Service ipv4 unicast json")) | |
90 | expected = { | |
91 | "routes": { | |
92 | "192.0.2.0/24": [ | |
93 | { | |
94 | "locPrf": 123, | |
95 | }, | |
96 | ], | |
97 | "192.168.1.0/24": [ | |
98 | { | |
99 | "locPrf": None, | |
100 | } | |
101 | ], | |
102 | } | |
103 | } | |
104 | return topotest.json_cmp(output, expected) | |
105 | ||
106 | test_func = functools.partial(_bgp_check_received_leaked_with_vpn_import) | |
107 | _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) | |
108 | assert result is None, "Failed, imported routes are not modified" | |
109 | ||
110 | ||
111 | if __name__ == "__main__": | |
112 | args = ["-s"] + sys.argv[1:] | |
113 | sys.exit(pytest.main(args)) |