]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/check_routes.py
6cc41103ef25f5a43c018365a2249727d340156c
[mirror_frr.git] / tests / topotests / bgp_l3vpn_to_bgp_vrf / scripts / check_routes.py
1 from lutil import luCommand
2 from bgprib import bgpribRequireVpnRoutes,bgpribRequireUnicastRoutes
3
4 ########################################################################
5 # CE routers: contain routes they originate
6 ########################################################################
7 #
8 # mininet CLI commands
9 # ce1 vtysh -c "show bgp ipv4 uni"
10 # ce2 vtysh -c "show bgp ipv4 uni"
11 # ce3 vtysh -c "show bgp ipv4 uni"
12 # ce4 vtysh -c "show bgp ipv4 uni"
13
14 want = [
15 {'p':'5.1.0.0/24', 'n':'99.0.0.1'},
16 {'p':'5.1.1.0/24', 'n':'99.0.0.1'},
17 {'p':'99.0.0.1/32', 'n':'0.0.0.0'},
18 ]
19 bgpribRequireUnicastRoutes('ce1','ipv4','','Cust 1 routes in ce1',want)
20
21 want = [
22 {'p':'5.1.0.0/24', 'n':'99.0.0.2'},
23 {'p':'5.1.1.0/24', 'n':'99.0.0.2'},
24 {'p':'99.0.0.2/32', 'n':'0.0.0.0'},
25 ]
26 bgpribRequireUnicastRoutes('ce2','ipv4','','Cust 2 routes in ce1',want)
27
28 want = [
29 {'p':'5.1.2.0/24', 'n':'99.0.0.3'},
30 {'p':'5.1.3.0/24', 'n':'99.0.0.3'},
31 {'p':'99.0.0.3/32', 'n':'0.0.0.0'},
32 ]
33 bgpribRequireUnicastRoutes('ce3','ipv4','','Cust 3 routes in ce1',want)
34
35 want = [
36 {'p':'5.4.2.0/24', 'n':'99.0.0.4'},
37 {'p':'5.4.3.0/24', 'n':'99.0.0.4'},
38 {'p':'99.0.0.4/32', 'n':'0.0.0.0'},
39 ]
40 bgpribRequireUnicastRoutes('ce4','ipv4','','Cust 4 routes in ce1',want)
41
42
43 ########################################################################
44 # PE routers: VRFs contain routes from locally-attached customer nets
45 ########################################################################
46 #
47 # r1 vtysh -c "show bgp vrf r1-cust1 ipv4"
48 #
49 want_r1_cust1_routes = [
50 {'p':'5.1.0.0/24', 'n':'99.0.0.1'},
51 {'p':'5.1.1.0/24', 'n':'99.0.0.1'},
52 {'p':'99.0.0.1/32', 'n':'192.168.1.2'},
53 ]
54 bgpribRequireUnicastRoutes('r1','ipv4','r1-cust1','Customer 1 routes in r1 vrf',want_r1_cust1_routes)
55
56 want_r3_cust1_routes = [
57 {'p':'5.1.0.0/24', 'n':'99.0.0.2'},
58 {'p':'5.1.1.0/24', 'n':'99.0.0.2'},
59 {'p':'99.0.0.2/32', 'n':'192.168.1.2'},
60 ]
61 bgpribRequireUnicastRoutes('r3','ipv4','r3-cust1','Customer 1 routes in r3 vrf',want_r3_cust1_routes)
62
63 want_r4_cust1_routes = [
64 {'p':'5.1.2.0/24', 'n':'99.0.0.3'},
65 {'p':'5.1.3.0/24', 'n':'99.0.0.3'},
66 {'p':'99.0.0.3/32', 'n':'192.168.1.2'},
67 ]
68 bgpribRequireUnicastRoutes('r4','ipv4','r4-cust1','Customer 1 routes in r4 vrf',want_r4_cust1_routes)
69
70 want_r4_cust2_routes = [
71 {'p':'5.4.2.0/24', 'n':'99.0.0.4'},
72 {'p':'5.4.3.0/24', 'n':'99.0.0.4'},
73 {'p':'99.0.0.4/32', 'n':'192.168.2.2'},
74 ]
75 bgpribRequireUnicastRoutes('r4','ipv4','r4-cust2','Customer 2 routes in r4 vrf',want_r4_cust2_routes)
76
77 ########################################################################
78 # PE routers: core unicast routes are empty
79 ########################################################################
80
81 luCommand('r1','vtysh -c "show bgp ipv4 uni"','No BGP prefixes displayed','pass','Core Unicast SAFI clean')
82 luCommand('r2','vtysh -c "show bgp ipv4 uni"','No BGP prefixes displayed','pass','Core Unicast SAFI clean')
83 luCommand('r3','vtysh -c "show bgp ipv4 uni"','No BGP prefixes displayed','pass','Core Unicast SAFI clean')
84 luCommand('r4','vtysh -c "show bgp ipv4 uni"','No BGP prefixes displayed','pass','Core Unicast SAFI clean')
85
86 ########################################################################
87 # PE routers: local ce-originated routes are leaked to vpn
88 ########################################################################
89
90 # nhzero is for the new code that sets nh of locally-leaked routes to 0
91 nhzero = 1
92 #nhzero = 0
93
94 if nhzero:
95 luCommand('r1','vtysh -c "show bgp ipv4 vpn"',
96 'Distinguisher: *10:1.*5.1.0.0/24 *0.0.0.0 .*5.1.1.0/24 *0.0.0.0 .*99.0.0.1/32 *0.0.0.0 ',
97 'pass','vrf->vpn routes')
98 luCommand('r3','vtysh -c "show bgp ipv4 vpn"',
99 'Distinguisher: *10:3.*5.1.0.0/24 *0.0.0.0 .*5.1.1.0/24 *0.0.0.0 .*99.0.0.2/32 *0.0.0.0 ',
100 'pass','vrf->vpn routes')
101 want = [
102 {'rd':'10:41', 'p':'5.1.2.0/24', 'n':'0.0.0.0'},
103 {'rd':'10:41', 'p':'5.1.3.0/24', 'n':'0.0.0.0'},
104 {'rd':'10:41', 'p':'99.0.0.3/32', 'n':'0.0.0.0'},
105
106 {'rd':'10:42', 'p':'5.4.2.0/24', 'n':'0.0.0.0'},
107 {'rd':'10:42', 'p':'5.4.3.0/24', 'n':'0.0.0.0'},
108 {'rd':'10:42', 'p':'99.0.0.4/32', 'n':'0.0.0.0'},
109 ]
110 bgpribRequireVpnRoutes('r4','vrf->vpn routes',want)
111
112 else:
113 luCommand('r1','vtysh -c "show bgp ipv4 vpn"',
114 'Distinguisher: *10:1.*5.1.0.0/24 *1.1.1.1 .*5.1.1.0/24 *1.1.1.1 .*99.0.0.1/32 *1.1.1.1 ',
115 'pass','vrf->vpn routes')
116 luCommand('r3','vtysh -c "show bgp ipv4 vpn"',
117 'Distinguisher: *10:3.*5.1.0.0/24 *3.3.3.3 .*5.1.1.0/24 *3.3.3.3 .*99.0.0.2/32 *3.3.3.3 ',
118 'pass','vrf->vpn routes')
119 want = [
120 {'rd':'10:41', 'p':'5.1.2.0/24', 'n':'4.4.4.4'},
121 {'rd':'10:41', 'p':'5.1.3.0/24', 'n':'4.4.4.4'},
122 {'rd':'10:41', 'p':'99.0.0.3/32', 'n':'4.4.4.4'},
123
124 {'rd':'10:42', 'p':'5.4.2.0/24', 'n':'4.4.4.4'},
125 {'rd':'10:42', 'p':'5.4.3.0/24', 'n':'4.4.4.4'},
126 {'rd':'10:42', 'p':'99.0.0.4/32', 'n':'4.4.4.4'},
127 ]
128 bgpribRequireVpnRoutes('r4','vrf->vpn routes',want)
129
130 ########################################################################
131 # PE routers: exporting vrfs set MPLS vrf labels in kernel
132 ########################################################################
133
134 luCommand('r1','vtysh -c "show mpls table"',' 101 *BGP *r1-cust1','pass','vrf labels')
135 luCommand('r3','vtysh -c "show mpls table"',' 103 *BGP *r3-cust1','pass','vrf labels')
136 luCommand('r4','vtysh -c "show mpls table"',' 1041 *BGP *r4-cust1 .*1042 *BGP *r4-cust2','pass','vrf labels')
137
138 ########################################################################
139 # Core VPN router: all customer routes
140 ########################################################################
141
142 want_rd_routes = [
143 {'rd':'10:1', 'p':'5.1.0.0/24', 'n':'1.1.1.1'},
144 {'rd':'10:1', 'p':'5.1.0.0/24', 'n':'1.1.1.1'},
145 {'rd':'10:1', 'p':'99.0.0.1/32', 'n':'1.1.1.1'},
146
147 {'rd':'10:3', 'p':'5.1.0.0/24', 'n':'3.3.3.3'},
148 {'rd':'10:3', 'p':'5.1.0.0/24', 'n':'3.3.3.3'},
149 {'rd':'10:3', 'p':'99.0.0.2/32', 'n':'3.3.3.3'},
150
151 {'rd':'10:41', 'p':'5.1.2.0/24', 'n':'4.4.4.4'},
152 {'rd':'10:41', 'p':'5.1.3.0/24', 'n':'4.4.4.4'},
153 {'rd':'10:41', 'p':'99.0.0.3/32', 'n':'4.4.4.4'},
154
155 {'rd':'10:42', 'p':'5.4.2.0/24', 'n':'4.4.4.4'},
156 {'rd':'10:42', 'p':'5.4.3.0/24', 'n':'4.4.4.4'},
157 {'rd':'10:42', 'p':'99.0.0.4/32', 'n':'4.4.4.4'},
158 ]
159 bgpribRequireVpnRoutes('r2','Customer routes in provider vpn core',want_rd_routes)
160
161 ########################################################################
162 # PE routers: VPN routes from remote customers
163 ########################################################################
164 #
165 # r1 vtysh -c "show bgp ipv4 vpn"
166 #
167 want_r1_remote_vpn_routes = [
168 {'rd':'10:3', 'p':'5.1.0.0/24', 'n':'3.3.3.3'},
169 {'rd':'10:3', 'p':'5.1.1.0/24', 'n':'3.3.3.3'},
170 {'rd':'10:3', 'p':'99.0.0.2/32', 'n':'3.3.3.3'},
171
172 {'rd':'10:41', 'p':'5.1.2.0/24', 'n':'4.4.4.4'},
173 {'rd':'10:41', 'p':'5.1.3.0/24', 'n':'4.4.4.4'},
174 {'rd':'10:41', 'p':'99.0.0.3/32', 'n':'4.4.4.4'},
175
176 {'rd':'10:42', 'p':'5.4.2.0/24', 'n':'4.4.4.4'},
177 {'rd':'10:42', 'p':'5.4.3.0/24', 'n':'4.4.4.4'},
178 {'rd':'10:42', 'p':'99.0.0.4/32', 'n':'4.4.4.4'},
179 ]
180 bgpribRequireVpnRoutes('r1','Remote Customer routes in R1 vpn',want_r1_remote_vpn_routes)
181
182 want_r3_remote_vpn_routes = [
183 {'rd':'10:1', 'p':'5.1.0.0/24', 'n':'1.1.1.1'},
184 {'rd':'10:1', 'p':'5.1.1.0/24', 'n':'1.1.1.1'},
185 {'rd':'10:1', 'p':'99.0.0.1/32', 'n':'1.1.1.1'},
186
187 {'rd':'10:41', 'p':'5.1.2.0/24', 'n':'4.4.4.4'},
188 {'rd':'10:41', 'p':'5.1.3.0/24', 'n':'4.4.4.4'},
189 {'rd':'10:41', 'p':'99.0.0.3/32', 'n':'4.4.4.4'},
190
191 {'rd':'10:42', 'p':'5.4.2.0/24', 'n':'4.4.4.4'},
192 {'rd':'10:42', 'p':'5.4.3.0/24', 'n':'4.4.4.4'},
193 {'rd':'10:42', 'p':'99.0.0.4/32', 'n':'4.4.4.4'},
194 ]
195 bgpribRequireVpnRoutes('r3','Remote Customer routes in R3 vpn',want_r3_remote_vpn_routes)
196
197 want_r4_remote_vpn_routes = [
198 {'rd':'10:1', 'p':'5.1.0.0/24', 'n':'1.1.1.1'},
199 {'rd':'10:1', 'p':'5.1.1.0/24', 'n':'1.1.1.1'},
200 {'rd':'10:1', 'p':'99.0.0.1/32', 'n':'1.1.1.1'},
201
202 {'rd':'10:3', 'p':'5.1.0.0/24', 'n':'3.3.3.3'},
203 {'rd':'10:3', 'p':'5.1.1.0/24', 'n':'3.3.3.3'},
204 {'rd':'10:3', 'p':'99.0.0.2/32', 'n':'3.3.3.3'},
205 ]
206 bgpribRequireVpnRoutes('r4','Remote Customer routes in R4 vpn',want_r4_remote_vpn_routes)
207
208
209
210 # r1 vtysh -c "show bgp vrf r1-cust1 ipv4"
211
212 ########################################################################
213 # PE routers: VRFs contain routes from remote customer nets
214 ########################################################################
215 want_r1_remote_cust1_routes = [
216 {'p':'5.1.0.0/24', 'n':'0.0.0.0'},
217 {'p':'5.1.1.0/24', 'n':'0.0.0.0'},
218 {'p':'99.0.0.2/32', 'n':'0.0.0.0'},
219
220 {'p':'5.1.2.0/24', 'n':'0.0.0.0'},
221 {'p':'5.1.3.0/24', 'n':'0.0.0.0'},
222 {'p':'99.0.0.3/32', 'n':'0.0.0.0'},
223
224 {'p':'5.4.2.0/24', 'n':'0.0.0.0'},
225 {'p':'5.4.3.0/24', 'n':'0.0.0.0'},
226 {'p':'99.0.0.3/32', 'n':'0.0.0.0'},
227 ]
228 bgpribRequireUnicastRoutes('r1','ipv4','r1-cust1','Customer 1 routes in r1 vrf',want_r1_remote_cust1_routes)
229
230 want_r3_remote_cust1_routes = [
231 {'p':'5.1.0.0/24', 'n':'0.0.0.0'},
232 {'p':'5.1.1.0/24', 'n':'0.0.0.0'},
233 {'p':'99.0.0.1/32', 'n':'0.0.0.0'},
234
235 {'p':'5.1.2.0/24', 'n':'0.0.0.0'},
236 {'p':'5.1.3.0/24', 'n':'0.0.0.0'},
237 {'p':'99.0.0.3/32', 'n':'0.0.0.0'},
238
239 {'p':'5.4.2.0/24', 'n':'0.0.0.0'},
240 {'p':'5.4.3.0/24', 'n':'0.0.0.0'},
241 {'p':'99.0.0.3/32', 'n':'0.0.0.0'},
242 ]
243 bgpribRequireUnicastRoutes('r3','ipv4','r3-cust1','Customer 1 routes in r3 vrf',want_r3_remote_cust1_routes)
244
245 want_r4_remote_cust1_routes = [
246 {'p':'5.1.0.0/24', 'n':'0.0.0.0'},
247 {'p':'5.1.1.0/24', 'n':'0.0.0.0'},
248 {'p':'99.0.0.1/32', 'n':'0.0.0.0'},
249 {'p':'99.0.0.2/32', 'n':'0.0.0.0'},
250 ]
251 bgpribRequireUnicastRoutes('r4','ipv4','r4-cust1','Customer 1 routes in r4 vrf',want_r4_remote_cust1_routes)
252
253 want_r4_remote_cust2_routes = [
254 {'p':'5.1.0.0/24', 'n':'0.0.0.0'},
255 {'p':'5.1.1.0/24', 'n':'0.0.0.0'},
256 {'p':'99.0.0.1/32', 'n':'0.0.0.0'},
257 {'p':'99.0.0.2/32', 'n':'0.0.0.0'},
258 ]
259 bgpribRequireUnicastRoutes('r4','ipv4','r4-cust2','Customer 2 routes in r4 vrf',want_r4_remote_cust2_routes)
260
261
262 #########################################################################
263 # CE routers: contain routes from remote customer nets
264 #########################################################################
265 # ce1 vtysh -c "show bgp ipv4 uni"
266 # r1 vtysh -c "show bgp vrf r1-cust1 ipv4"
267 # r1 vtysh -c "show bgp vrf r1-cust1 ipv4 5.1.2.0/24"
268
269 want = [
270 {'p':'5.1.2.0/24', 'n':'192.168.1.1'},
271 {'p':'5.1.3.0/24', 'n':'192.168.1.1'},
272 {'p':'5.4.2.0/24', 'n':'192.168.1.1'},
273 {'p':'5.4.3.0/24', 'n':'192.168.1.1'},
274 ]
275 bgpribRequireUnicastRoutes('ce1','ipv4','','Cust 1 routes from remote',want)
276
277 want = [
278 {'p':'5.1.0.0/24', 'n':'192.168.1.1'},
279 {'p':'5.1.1.0/24', 'n':'192.168.1.1'},
280 {'p':'5.1.2.0/24', 'n':'192.168.1.1'},
281 {'p':'5.1.3.0/24', 'n':'192.168.1.1'},
282 {'p':'5.4.2.0/24', 'n':'192.168.1.1'},
283 {'p':'5.4.3.0/24', 'n':'192.168.1.1'},
284 ]
285 bgpribRequireUnicastRoutes('ce2','ipv4','','Cust 1 routes from remote',want)
286
287 want = [
288 {'p':'5.1.0.0/24', 'n':'192.168.1.1'},
289 {'p':'5.1.1.0/24', 'n':'192.168.1.1'},
290 {'p':'5.4.2.0/24', 'n':'192.168.1.1'},
291 {'p':'5.4.3.0/24', 'n':'192.168.1.1'},
292 ]
293 bgpribRequireUnicastRoutes('ce3','ipv4','','Cust 1 routes from remote',want)
294
295 want = [
296 {'p':'5.1.0.0/24', 'n':'192.168.2.1'},
297 {'p':'5.1.1.0/24', 'n':'192.168.2.1'},
298 {'p':'5.1.2.0/24', 'n':'192.168.2.1'},
299 {'p':'5.1.3.0/24', 'n':'192.168.2.1'},
300 ]
301 bgpribRequireUnicastRoutes('ce4','ipv4','','Cust 2 routes from remote',want)
302