4 # Copyright (c) 2022 by
5 # Donatas Abraitis <donatas@opensourcerouting.org>
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
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
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`.
34 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
35 sys
.path
.append(os
.path
.join(CWD
, "../"))
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
42 pytestmark
= [pytest
.mark
.bgpd
]
48 switch
= tgen
.add_switch("s1")
49 switch
.add_link(tgen
.gears
["r1"])
51 switch
= tgen
.add_switch("s2")
52 switch
.add_link(tgen
.gears
["r1"])
54 switch
= tgen
.add_switch("s3")
55 switch
.add_link(tgen
.gears
["r1"])
57 switch
= tgen
.add_switch("s4")
58 switch
.add_link(tgen
.gears
["r1"])
61 def setup_module(mod
):
62 tgen
= Topogen(build_topo
, mod
.__name
__)
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")
75 router_list
= tgen
.routers()
77 for i
, (rname
, router
) in enumerate(router_list
.items(), 1):
79 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
82 TopoRouter
.RD_BGP
, os
.path
.join(CWD
, "{}/bgpd.conf".format(rname
))
88 def teardown_module(mod
):
93 def test_bgp_route_map_vpn_import():
96 if tgen
.routers_have_failure():
97 pytest
.skip(tgen
.errors
)
101 def _bgp_check_received_leaked_with_vpn_import():
102 output
= json
.loads(r1
.vtysh_cmd("show bgp vrf Service ipv4 unicast json"))
117 return topotest
.json_cmp(output
, expected
)
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"
124 if __name__
== "__main__":
125 args
= ["-s"] + sys
.argv
[1:]
126 sys
.exit(pytest
.main(args
))