-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_bgp_route_map_match_ipv6_nexthop.py
172 lines (157 loc) Β· 4.39 KB
/
test_bgp_route_map_match_ipv6_nexthop.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2022 Nathan Mangar
"""
Test if we can match BGP prefixes by next-hop which is
specified by an IPv6 Access-list, prefix-list or just an address.
"""
__topotests_file__ = (
"bgp_route_map_match_ipv6_nexthop/test_bgp_route_map_match_ipv6_nexthop.py"
)
__topotests_gitrev__ = "c75d6ccbfe95d2708618ade7cc7198e46ee467dd"
# pylint: disable=wildcard-import, unused-wildcard-import
from topotato import *
@topology_fixture()
def topology(topo):
"""
[ r1 ]
|
{ s1 }
|
[ r2 ]
"""
topo.router("r1").iface_to("s1").ip6.append("2001:db8::1/64")
topo.router("r2").iface_to("s1").ip6.append("2001:db8::2/64")
class Configs(FRRConfigs):
routers = ["r1", "r2"]
zebra = """
#% extends "boilerplate.conf"
#% block main
#% if router.name == 'r1'
interface r1-eth0
ipv6 address 2001:db8::1/64
!
#% endif
#% if router.name == 'r2'
interface lo
ipv6 address 2001:db8:1::1/128
ipv6 address 2001:db8:2::1/128
ipv6 address 2001:db8:3::1/128
ipv6 address 2001:db8:4::1/128
ipv6 address 2001:db8:5::1/128
!
interface r2-eth0
ip address 2001:db8::2/64
!
#% endif
#% endblock
"""
bgpd = """
#% block main
#% if router.name == 'r2'
!
bgp send-extra-data zebra
!
router bgp 65002
bgp router-id 10.10.10.2
no bgp ebgp-requires-policy
neighbor 2001:db8::1 remote-as external
address-family ipv6 unicast
redistribute connected
neighbor 2001:db8::1 activate
neighbor 2001:db8::1 route-map r1 out
!
ipv6 prefix-list p1 permit 2001:db8:1::1/128
ipv6 prefix-list p2 permit 2001:db8:2::1/128
ipv6 prefix-list p3 permit 2001:db8:3::1/128
ipv6 prefix-list p4 permit 2001:db8:4::1/128
ipv6 prefix-list p5 permit 2001:db8:5::1/128
!
route-map r1 permit 10
match ipv6 address prefix-list p1
set ipv6 next-hop global 2001:db8:1::1
route-map r1 permit 20
match ipv6 address prefix-list p2
set ipv6 next-hop global 2001:db8:2::1
route-map r1 permit 30
match ipv6 address prefix-list p3
set ipv6 next-hop global 2001:db8:3::1
route-map r1 permit 40
match ipv6 address prefix-list p4
set ipv6 next-hop global 2001:db8:4::1
route-map r1 permit 50
match ipv6 address prefix-list p5
set ipv6 next-hop global 2001:db8:5::1
!
#% elif router.name == 'r1'
!
bgp send-extra-data zebra
!
ipv6 access-list nh1 permit 2001:db8:1::/64
ipv6 access-list nh2 permit 2001:db8:2::/64
ipv6 access-list nh3 permit 2001:db8:3::/64
!
ipv6 prefix-list nh4 permit 2001:db8:5::/64 le 128
!
router bgp 65001
bgp router-id 10.10.10.1
no bgp ebgp-requires-policy
neighbor 2001:db8::2 remote-as external
address-family ipv6 unicast
neighbor 2001:db8::2 activate
neighbor 2001:db8::2 route-map r2 in
!
route-map r2 permit 10
match ipv6 next-hop nh1
set community 65002:1
route-map r2 permit 20
match ipv6 next-hop nh2
set community 65002:2
route-map r2 permit 30
match ipv6 next-hop nh3
set community 65002:3
route-map r2 permit 40
match ipv6 next-hop address 2001:db8:4::1
set community 65002:4
route-map r2 permit 50
match ipv6 next-hop prefix-list nh4
set community 65002:5
!
#% endif
#% endblock
"""
class TestBGPRouteMapMatchIPV6NextHopAccessList(
TestBase, AutoFixture, topo=topology, configs=Configs
):
@topotatofunc
def bgp_converge(self, _, r1):
expected = {
"2001:db8:1::1/128": [
{
"communities": "65002:1",
}
],
"2001:db8:2::1/128": [
{
"communities": "65002:2",
}
],
"2001:db8:3::1/128": [
{
"communities": "65002:3",
}
],
"2001:db8:4::1/128": [
{
"communities": "65002:4",
}
],
"2001:db8:5::1/128": [
{
"communities": "65002:5",
}
],
}
yield from AssertVtysh.make(
r1, "zebra", "show ipv6 route json", maxwait=6.0, compare=expected
)