]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_route_map_match_ipv6_nexthop/test_bgp_route_map_match_ipv6_nexthop.py
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / tests / topotests / bgp_route_map_match_ipv6_nexthop / test_bgp_route_map_match_ipv6_nexthop.py
1 #!/usr/bin/env python
2 # SPDX-License-Identifier: ISC
3
4 # Copyright (c) 2021 by
5 # Donatas Abraitis <donatas.abraitis@gmail.com>
6 #
7
8 """
9 Test if we can match BGP prefixes by next-hop which is
10 specified by an IPv6 Access-list, prefix-list or just an address.
11 """
12
13 import os
14 import sys
15 import json
16 import pytest
17 import functools
18
19 pytestmark = pytest.mark.bgpd
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
28 pytestmark = [pytest.mark.bgpd]
29
30
31 def build_topo(tgen):
32 for routern in range(1, 3):
33 tgen.add_router("r{}".format(routern))
34
35 switch = tgen.add_switch("s1")
36 switch.add_link(tgen.gears["r1"])
37 switch.add_link(tgen.gears["r2"])
38
39
40 def setup_module(mod):
41 tgen = Topogen(build_topo, mod.__name__)
42 tgen.start_topology()
43
44 router_list = tgen.routers()
45
46 for i, (rname, router) in enumerate(router_list.items(), 1):
47 router.load_config(
48 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
49 )
50 router.load_config(
51 TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
52 )
53
54 tgen.start_router()
55
56
57 def teardown_module(mod):
58 tgen = get_topogen()
59 tgen.stop_topology()
60
61
62 def test_bgp_route_map_match_ipv6_next_hop_access_list():
63 tgen = get_topogen()
64
65 if tgen.routers_have_failure():
66 pytest.skip(tgen.errors)
67
68 router = tgen.gears["r1"]
69
70 def _bgp_converge(router):
71 output = json.loads(router.vtysh_cmd("show ipv6 route json"))
72 expected = {
73 "2001:db8:1::1/128": [
74 {
75 "communities": "65002:1",
76 }
77 ],
78 "2001:db8:2::1/128": [
79 {
80 "communities": "65002:2",
81 }
82 ],
83 "2001:db8:3::1/128": [
84 {
85 "communities": "65002:3",
86 }
87 ],
88 "2001:db8:4::1/128": [
89 {
90 "communities": "65002:4",
91 }
92 ],
93 "2001:db8:5::1/128": [
94 {
95 "communities": "65002:5",
96 }
97 ],
98 }
99 return topotest.json_cmp(output, expected)
100
101 test_func = functools.partial(_bgp_converge, router)
102 success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
103 assert result is None, "Can't match routes using ipv6 next-hop access-list"
104
105
106 if __name__ == "__main__":
107 args = ["-s"] + sys.argv[1:]
108 sys.exit(pytest.main(args))