]>
Commit | Line | Data |
---|---|---|
784d3a42 | 1 | /* Ethernet-VPN Packet and vty Processing File |
896014f4 DL |
2 | * Copyright (C) 2017 6WIND |
3 | * | |
4 | * This file is part of FRRouting | |
5 | * | |
6 | * FRRouting is free software; you can redistribute it and/or modify it | |
7 | * under the terms of the GNU General Public License as published by the | |
8 | * Free Software Foundation; either version 2, or (at your option) any | |
9 | * later version. | |
10 | * | |
11 | * FRRouting is distributed in the hope that it will be useful, but | |
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License along | |
17 | * with this program; see the file COPYING; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
19 | */ | |
784d3a42 PG |
20 | |
21 | #include <zebra.h> | |
22 | #include "command.h" | |
23 | #include "prefix.h" | |
24 | #include "lib/json.h" | |
25 | ||
26 | #include "bgpd/bgpd.h" | |
27 | #include "bgpd/bgp_table.h" | |
28 | #include "bgpd/bgp_attr.h" | |
29 | #include "bgpd/bgp_route.h" | |
30 | #include "bgpd/bgp_mplsvpn.h" | |
31 | #include "bgpd/bgp_vpn.h" | |
32 | #include "bgpd/bgp_evpn_vty.h" | |
3da6fcd5 | 33 | #include "bgpd/bgp_evpn.h" |
784d3a42 | 34 | |
784d3a42 PG |
35 | #define SHOW_DISPLAY_STANDARD 0 |
36 | #define SHOW_DISPLAY_TAGS 1 | |
37 | #define SHOW_DISPLAY_OVERLAY 2 | |
38 | ||
39 | static int | |
4d0e6ece PG |
40 | bgp_show_ethernet_vpn(struct vty *vty, struct prefix_rd *prd, |
41 | enum bgp_show_type type, void *output_arg, int option, | |
42 | u_char use_json) | |
784d3a42 | 43 | { |
4d0e6ece PG |
44 | afi_t afi = AFI_L2VPN; |
45 | struct bgp *bgp; | |
46 | struct bgp_table *table; | |
47 | struct bgp_node *rn; | |
48 | struct bgp_node *rm; | |
49 | struct bgp_info *ri; | |
50 | int rd_header; | |
51 | int header = 1; | |
52 | char v4_header[] = | |
53 | " Network Next Hop Metric LocPrf Weight Path%s"; | |
54 | char v4_header_tag[] = | |
55 | " Network Next Hop In tag/Out tag%s"; | |
56 | char v4_header_overlay[] = | |
57 | " Network Next Hop EthTag Overlay Index RouterMac%s"; | |
58 | ||
59 | unsigned long output_count = 0; | |
60 | unsigned long total_count = 0; | |
61 | json_object *json = NULL; | |
62 | json_object *json_nroute = NULL; | |
63 | json_object *json_array = NULL; | |
64 | json_object *json_scode = NULL; | |
65 | json_object *json_ocode = NULL; | |
66 | ||
67 | bgp = bgp_get_default(); | |
68 | if (bgp == NULL) { | |
69 | if (!use_json) | |
70 | vty_out(vty, "No BGP process is configured%s", | |
71 | VTY_NEWLINE); | |
72 | return CMD_WARNING; | |
73 | } | |
74 | ||
75 | if (use_json) { | |
76 | json_scode = json_object_new_object(); | |
77 | json_ocode = json_object_new_object(); | |
78 | json = json_object_new_object(); | |
79 | json_nroute = json_object_new_object(); | |
80 | ||
81 | json_object_string_add(json_scode, "suppressed", "s"); | |
82 | json_object_string_add(json_scode, "damped", "d"); | |
83 | json_object_string_add(json_scode, "history", "h"); | |
84 | json_object_string_add(json_scode, "valid", "*"); | |
85 | json_object_string_add(json_scode, "best", ">"); | |
86 | json_object_string_add(json_scode, "internal", "i"); | |
87 | ||
88 | json_object_string_add(json_ocode, "igp", "i"); | |
89 | json_object_string_add(json_ocode, "egp", "e"); | |
90 | json_object_string_add(json_ocode, "incomplete", "?"); | |
91 | } | |
92 | ||
93 | for (rn = bgp_table_top(bgp->rib[afi][SAFI_EVPN]); rn; | |
94 | rn = bgp_route_next(rn)) { | |
95 | if (use_json) | |
96 | continue; /* XXX json TODO */ | |
97 | ||
98 | if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0) | |
99 | continue; | |
100 | ||
101 | if ((table = rn->info) != NULL) { | |
102 | rd_header = 1; | |
103 | ||
104 | for (rm = bgp_table_top(table); rm; | |
105 | rm = bgp_route_next(rm)) | |
106 | for (ri = rm->info; ri; ri = ri->next) { | |
107 | total_count++; | |
108 | if (type == bgp_show_type_neighbor) { | |
109 | union sockunion *su = | |
110 | output_arg; | |
111 | ||
112 | if (ri->peer->su_remote == NULL | |
113 | || !sockunion_same(ri-> | |
114 | peer-> | |
115 | su_remote, | |
116 | su)) | |
117 | continue; | |
118 | } | |
119 | if (header == 0) { | |
120 | if (use_json) { | |
121 | if (option == | |
122 | SHOW_DISPLAY_TAGS) { | |
123 | json_object_int_add | |
124 | (json, | |
125 | "bgpTableVersion", | |
126 | 0); | |
127 | json_object_string_add | |
128 | (json, | |
129 | "bgpLocalRouterId", | |
130 | inet_ntoa | |
131 | (bgp-> | |
132 | router_id)); | |
133 | json_object_object_add | |
134 | (json, | |
135 | "bgpStatusCodes", | |
136 | json_scode); | |
137 | json_object_object_add | |
138 | (json, | |
139 | "bgpOriginCodes", | |
140 | json_ocode); | |
141 | } | |
142 | } else { | |
143 | if (option == | |
144 | SHOW_DISPLAY_TAGS) | |
145 | vty_out(vty, | |
146 | v4_header_tag, | |
147 | VTY_NEWLINE); | |
148 | else if (option == | |
149 | SHOW_DISPLAY_OVERLAY) | |
150 | vty_out(vty, | |
151 | v4_header_overlay, | |
152 | VTY_NEWLINE); | |
153 | else { | |
154 | vty_out(vty, | |
155 | "BGP table version is 0, local router ID is %s%s", | |
156 | inet_ntoa | |
157 | (bgp-> | |
158 | router_id), | |
159 | VTY_NEWLINE); | |
160 | vty_out(vty, | |
161 | "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s", | |
162 | VTY_NEWLINE); | |
163 | vty_out(vty, | |
164 | "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s", | |
165 | VTY_NEWLINE, | |
166 | VTY_NEWLINE); | |
167 | vty_out(vty, | |
168 | v4_header, | |
169 | VTY_NEWLINE); | |
170 | } | |
171 | } | |
172 | header = 0; | |
173 | } | |
174 | if (rd_header) { | |
175 | u_int16_t type; | |
176 | struct rd_as rd_as; | |
177 | struct rd_ip rd_ip; | |
178 | u_char *pnt; | |
179 | ||
180 | pnt = rn->p.u.val; | |
181 | ||
182 | /* Decode RD type. */ | |
183 | type = decode_rd_type(pnt); | |
184 | /* Decode RD value. */ | |
185 | if (type == RD_TYPE_AS) | |
186 | decode_rd_as(pnt + 2, | |
187 | &rd_as); | |
188 | else if (type == RD_TYPE_AS4) | |
189 | decode_rd_as4(pnt + 2, | |
190 | &rd_as); | |
191 | else if (type == RD_TYPE_IP) | |
192 | decode_rd_ip(pnt + 2, | |
193 | &rd_ip); | |
194 | if (use_json) { | |
195 | char buffer[BUFSIZ]; | |
196 | if (type == RD_TYPE_AS | |
197 | || type == | |
198 | RD_TYPE_AS4) | |
199 | sprintf(buffer, | |
200 | "%u:%d", | |
201 | rd_as. | |
202 | as, | |
203 | rd_as. | |
204 | val); | |
205 | else if (type == | |
206 | RD_TYPE_IP) | |
207 | sprintf(buffer, | |
208 | "%s:%d", | |
209 | inet_ntoa | |
210 | (rd_ip. | |
211 | ip), | |
212 | rd_ip. | |
213 | val); | |
214 | json_object_string_add | |
215 | (json_nroute, | |
216 | "routeDistinguisher", | |
217 | buffer); | |
218 | } else { | |
219 | vty_out(vty, | |
220 | "Route Distinguisher: "); | |
221 | if (type == RD_TYPE_AS) | |
222 | vty_out(vty, | |
223 | "as2 %u:%d", | |
224 | rd_as. | |
225 | as, | |
226 | rd_as. | |
227 | val); | |
228 | else if (type == | |
229 | RD_TYPE_AS4) | |
230 | vty_out(vty, | |
231 | "as4 %u:%d", | |
232 | rd_as. | |
233 | as, | |
234 | rd_as. | |
235 | val); | |
236 | else if (type == | |
237 | RD_TYPE_IP) | |
238 | vty_out(vty, | |
239 | "ip %s:%d", | |
240 | inet_ntoa | |
241 | (rd_ip. | |
242 | ip), | |
243 | rd_ip. | |
244 | val); | |
245 | vty_out(vty, "%s", | |
246 | VTY_NEWLINE); | |
247 | } | |
248 | rd_header = 0; | |
249 | } | |
250 | if (use_json) | |
251 | json_array = | |
252 | json_object_new_array(); | |
253 | else | |
254 | json_array = NULL; | |
255 | if (option == SHOW_DISPLAY_TAGS) | |
256 | route_vty_out_tag(vty, &rm->p, | |
257 | ri, 0, | |
258 | SAFI_EVPN, | |
259 | json_array); | |
260 | else if (option == SHOW_DISPLAY_OVERLAY) | |
261 | route_vty_out_overlay(vty, | |
262 | &rm->p, | |
263 | ri, 0, | |
264 | json_array); | |
265 | else | |
266 | route_vty_out(vty, &rm->p, ri, | |
267 | 0, SAFI_EVPN, | |
268 | json_array); | |
269 | output_count++; | |
270 | } | |
271 | /* XXX json */ | |
272 | } | |
273 | } | |
274 | if (output_count == 0) | |
275 | vty_out(vty, "No prefixes displayed, %ld exist%s", total_count, | |
276 | VTY_NEWLINE); | |
277 | else | |
278 | vty_out(vty, "%sDisplayed %ld out of %ld total prefixes%s", | |
279 | VTY_NEWLINE, output_count, total_count, VTY_NEWLINE); | |
280 | return CMD_SUCCESS; | |
784d3a42 PG |
281 | } |
282 | ||
4d0e6ece PG |
283 | DEFUN(show_ip_bgp_l2vpn_evpn, |
284 | show_ip_bgp_l2vpn_evpn_cmd, | |
285 | "show [ip] bgp l2vpn evpn [json]", | |
286 | SHOW_STR IP_STR BGP_STR L2VPN_HELP_STR EVPN_HELP_STR JSON_STR) | |
784d3a42 | 287 | { |
4d0e6ece PG |
288 | return bgp_show_ethernet_vpn(vty, NULL, bgp_show_type_normal, NULL, 0, |
289 | use_json(argc, argv)); | |
784d3a42 PG |
290 | } |
291 | ||
4d0e6ece PG |
292 | DEFUN(show_ip_bgp_l2vpn_evpn_rd, |
293 | show_ip_bgp_l2vpn_evpn_rd_cmd, | |
294 | "show [ip] bgp l2vpn evpn rd ASN:nn_or_IP-address:nn [json]", | |
295 | SHOW_STR | |
296 | IP_STR | |
297 | BGP_STR | |
298 | L2VPN_HELP_STR | |
299 | EVPN_HELP_STR | |
300 | "Display information for a route distinguisher\n" | |
301 | "VPN Route Distinguisher\n" JSON_STR) | |
784d3a42 | 302 | { |
313605cb | 303 | int idx_ext_community = 0; |
4d0e6ece PG |
304 | int ret; |
305 | struct prefix_rd prd; | |
306 | ||
313605cb RW |
307 | argv_find (argv, argc, "ASN:nn_or_IP-address:nn", &idx_ext_community); |
308 | ||
4d0e6ece PG |
309 | ret = str2prefix_rd(argv[idx_ext_community]->arg, &prd); |
310 | if (!ret) { | |
311 | vty_out(vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); | |
312 | return CMD_WARNING; | |
313 | } | |
314 | return bgp_show_ethernet_vpn(vty, &prd, bgp_show_type_normal, NULL, 0, | |
315 | use_json(argc, argv)); | |
784d3a42 PG |
316 | } |
317 | ||
4d0e6ece PG |
318 | DEFUN(show_ip_bgp_l2vpn_evpn_all_tags, |
319 | show_ip_bgp_l2vpn_evpn_all_tags_cmd, | |
320 | "show [ip] bgp l2vpn evpn all tags", | |
321 | SHOW_STR | |
322 | IP_STR | |
323 | BGP_STR | |
324 | L2VPN_HELP_STR | |
325 | EVPN_HELP_STR | |
326 | "Display information about all EVPN NLRIs\n" | |
327 | "Display BGP tags for prefixes\n") | |
784d3a42 | 328 | { |
4d0e6ece PG |
329 | return bgp_show_ethernet_vpn(vty, NULL, bgp_show_type_normal, NULL, 1, |
330 | 0); | |
784d3a42 PG |
331 | } |
332 | ||
4d0e6ece PG |
333 | DEFUN(show_ip_bgp_l2vpn_evpn_rd_tags, |
334 | show_ip_bgp_l2vpn_evpn_rd_tags_cmd, | |
335 | "show [ip] bgp l2vpn evpn rd ASN:nn_or_IP-address:nn tags", | |
336 | SHOW_STR | |
337 | IP_STR | |
338 | BGP_STR | |
339 | L2VPN_HELP_STR | |
340 | EVPN_HELP_STR | |
341 | "Display information for a route distinguisher\n" | |
342 | "VPN Route Distinguisher\n" "Display BGP tags for prefixes\n") | |
784d3a42 | 343 | { |
313605cb | 344 | int idx_ext_community = 0; |
4d0e6ece PG |
345 | int ret; |
346 | struct prefix_rd prd; | |
347 | ||
313605cb RW |
348 | argv_find (argv, argc, "ASN:nn_or_IP-address:nn", &idx_ext_community); |
349 | ||
4d0e6ece PG |
350 | ret = str2prefix_rd(argv[idx_ext_community]->arg, &prd); |
351 | if (!ret) { | |
352 | vty_out(vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); | |
353 | return CMD_WARNING; | |
354 | } | |
355 | return bgp_show_ethernet_vpn(vty, &prd, bgp_show_type_normal, NULL, 1, | |
356 | 0); | |
784d3a42 PG |
357 | } |
358 | ||
4d0e6ece PG |
359 | DEFUN(show_ip_bgp_l2vpn_evpn_all_neighbor_routes, |
360 | show_ip_bgp_l2vpn_evpn_all_neighbor_routes_cmd, | |
361 | "show [ip] bgp l2vpn evpn all neighbors A.B.C.D routes [json]", | |
362 | SHOW_STR | |
363 | IP_STR | |
364 | BGP_STR | |
365 | L2VPN_HELP_STR | |
366 | EVPN_HELP_STR | |
367 | "Display information about all EVPN NLRIs\n" | |
368 | "Detailed information on TCP and BGP neighbor connections\n" | |
369 | "Neighbor to display information about\n" | |
370 | "Display routes learned from neighbor\n" JSON_STR) | |
784d3a42 | 371 | { |
313605cb | 372 | int idx_ipv4 = 0; |
4d0e6ece PG |
373 | union sockunion su; |
374 | struct peer *peer; | |
375 | int ret; | |
376 | u_char uj = use_json(argc, argv); | |
377 | ||
313605cb RW |
378 | argv_find (argv, argc, "A.B.C.D", &idx_ipv4); |
379 | ||
4d0e6ece PG |
380 | ret = str2sockunion(argv[idx_ipv4]->arg, &su); |
381 | if (ret < 0) { | |
382 | if (uj) { | |
383 | json_object *json_no = NULL; | |
384 | json_no = json_object_new_object(); | |
385 | json_object_string_add(json_no, "warning", | |
386 | "Malformed address"); | |
387 | vty_out(vty, "%s%s", | |
388 | json_object_to_json_string(json_no), | |
389 | VTY_NEWLINE); | |
390 | json_object_free(json_no); | |
391 | } else | |
392 | vty_out(vty, "Malformed address: %s%s", | |
393 | argv[idx_ipv4]->arg, VTY_NEWLINE); | |
394 | return CMD_WARNING; | |
395 | } | |
396 | ||
397 | peer = peer_lookup(NULL, &su); | |
398 | if (!peer || !peer->afc[AFI_L2VPN][SAFI_EVPN]) { | |
399 | if (uj) { | |
400 | json_object *json_no = NULL; | |
401 | json_no = json_object_new_object(); | |
402 | json_object_string_add(json_no, "warning", | |
403 | "No such neighbor or address family"); | |
404 | vty_out(vty, "%s%s", | |
405 | json_object_to_json_string(json_no), | |
406 | VTY_NEWLINE); | |
407 | json_object_free(json_no); | |
408 | } else | |
409 | vty_out(vty, "%% No such neighbor or address family%s", | |
410 | VTY_NEWLINE); | |
411 | return CMD_WARNING; | |
412 | } | |
413 | ||
414 | return bgp_show_ethernet_vpn(vty, NULL, bgp_show_type_neighbor, &su, 0, | |
415 | uj); | |
784d3a42 PG |
416 | } |
417 | ||
4d0e6ece PG |
418 | DEFUN(show_ip_bgp_l2vpn_evpn_rd_neighbor_routes, |
419 | show_ip_bgp_l2vpn_evpn_rd_neighbor_routes_cmd, | |
420 | "show [ip] bgp l2vpn evpn rd ASN:nn_or_IP-address:nn neighbors A.B.C.D routes [json]", | |
421 | SHOW_STR | |
422 | IP_STR | |
423 | BGP_STR | |
424 | L2VPN_HELP_STR | |
425 | EVPN_HELP_STR | |
426 | "Display information for a route distinguisher\n" | |
427 | "VPN Route Distinguisher\n" | |
428 | "Detailed information on TCP and BGP neighbor connections\n" | |
429 | "Neighbor to display information about\n" | |
430 | "Display routes learned from neighbor\n" JSON_STR) | |
784d3a42 | 431 | { |
313605cb RW |
432 | int idx_ext_community = 0; |
433 | int idx_ipv4 = 0; | |
4d0e6ece PG |
434 | int ret; |
435 | union sockunion su; | |
436 | struct peer *peer; | |
437 | struct prefix_rd prd; | |
438 | u_char uj = use_json(argc, argv); | |
439 | ||
313605cb RW |
440 | argv_find (argv, argc, "ASN:nn_or_IP-address:nn", &idx_ext_community); |
441 | argv_find (argv, argc, "A.B.C.D", &idx_ipv4); | |
442 | ||
4d0e6ece PG |
443 | ret = str2prefix_rd(argv[idx_ext_community]->arg, &prd); |
444 | if (!ret) { | |
445 | if (uj) { | |
446 | json_object *json_no = NULL; | |
447 | json_no = json_object_new_object(); | |
448 | json_object_string_add(json_no, "warning", | |
449 | "Malformed Route Distinguisher"); | |
450 | vty_out(vty, "%s%s", | |
451 | json_object_to_json_string(json_no), | |
452 | VTY_NEWLINE); | |
453 | json_object_free(json_no); | |
454 | } else | |
455 | vty_out(vty, "%% Malformed Route Distinguisher%s", | |
456 | VTY_NEWLINE); | |
457 | return CMD_WARNING; | |
458 | } | |
459 | ||
460 | ret = str2sockunion(argv[idx_ipv4]->arg, &su); | |
461 | if (ret < 0) { | |
462 | if (uj) { | |
463 | json_object *json_no = NULL; | |
464 | json_no = json_object_new_object(); | |
465 | json_object_string_add(json_no, "warning", | |
466 | "Malformed address"); | |
467 | vty_out(vty, "%s%s", | |
468 | json_object_to_json_string(json_no), | |
469 | VTY_NEWLINE); | |
470 | json_object_free(json_no); | |
471 | } else | |
472 | vty_out(vty, "Malformed address: %s%s", | |
473 | argv[idx_ext_community]->arg, VTY_NEWLINE); | |
474 | return CMD_WARNING; | |
475 | } | |
476 | ||
477 | peer = peer_lookup(NULL, &su); | |
478 | if (!peer || !peer->afc[AFI_L2VPN][SAFI_EVPN]) { | |
479 | if (uj) { | |
480 | json_object *json_no = NULL; | |
481 | json_no = json_object_new_object(); | |
482 | json_object_string_add(json_no, "warning", | |
483 | "No such neighbor or address family"); | |
484 | vty_out(vty, "%s%s", | |
485 | json_object_to_json_string(json_no), | |
486 | VTY_NEWLINE); | |
487 | json_object_free(json_no); | |
488 | } else | |
489 | vty_out(vty, "%% No such neighbor or address family%s", | |
490 | VTY_NEWLINE); | |
491 | return CMD_WARNING; | |
492 | } | |
493 | ||
494 | return bgp_show_ethernet_vpn(vty, &prd, bgp_show_type_neighbor, &su, 0, | |
495 | uj); | |
784d3a42 PG |
496 | } |
497 | ||
4d0e6ece PG |
498 | DEFUN(show_ip_bgp_l2vpn_evpn_all_neighbor_advertised_routes, |
499 | show_ip_bgp_l2vpn_evpn_all_neighbor_advertised_routes_cmd, | |
500 | "show [ip] bgp l2vpn evpn all neighbors A.B.C.D advertised-routes [json]", | |
501 | SHOW_STR | |
502 | IP_STR | |
503 | BGP_STR | |
504 | L2VPN_HELP_STR | |
505 | EVPN_HELP_STR | |
506 | "Display information about all EVPN NLRIs\n" | |
507 | "Detailed information on TCP and BGP neighbor connections\n" | |
508 | "Neighbor to display information about\n" | |
509 | "Display the routes advertised to a BGP neighbor\n" JSON_STR) | |
784d3a42 | 510 | { |
313605cb | 511 | int idx_ipv4 = 0; |
4d0e6ece PG |
512 | int ret; |
513 | struct peer *peer; | |
514 | union sockunion su; | |
515 | u_char uj = use_json(argc, argv); | |
516 | ||
313605cb RW |
517 | argv_find (argv, argc, "A.B.C.D", &idx_ipv4); |
518 | ||
4d0e6ece PG |
519 | ret = str2sockunion(argv[idx_ipv4]->arg, &su); |
520 | if (ret < 0) { | |
521 | if (uj) { | |
522 | json_object *json_no = NULL; | |
523 | json_no = json_object_new_object(); | |
524 | json_object_string_add(json_no, "warning", | |
525 | "Malformed address"); | |
526 | vty_out(vty, "%s%s", | |
527 | json_object_to_json_string(json_no), | |
528 | VTY_NEWLINE); | |
529 | json_object_free(json_no); | |
530 | } else | |
531 | vty_out(vty, "Malformed address: %s%s", | |
532 | argv[idx_ipv4]->arg, VTY_NEWLINE); | |
533 | return CMD_WARNING; | |
534 | } | |
535 | peer = peer_lookup(NULL, &su); | |
536 | if (!peer || !peer->afc[AFI_L2VPN][SAFI_EVPN]) { | |
537 | if (uj) { | |
538 | json_object *json_no = NULL; | |
539 | json_no = json_object_new_object(); | |
540 | json_object_string_add(json_no, "warning", | |
541 | "No such neighbor or address family"); | |
542 | vty_out(vty, "%s%s", | |
543 | json_object_to_json_string(json_no), | |
544 | VTY_NEWLINE); | |
545 | json_object_free(json_no); | |
546 | } else | |
547 | vty_out(vty, "%% No such neighbor or address family%s", | |
548 | VTY_NEWLINE); | |
549 | return CMD_WARNING; | |
550 | } | |
551 | ||
552 | return show_adj_route_vpn(vty, peer, NULL, AFI_L2VPN, SAFI_EVPN, uj); | |
784d3a42 PG |
553 | } |
554 | ||
4d0e6ece PG |
555 | DEFUN(show_ip_bgp_l2vpn_evpn_rd_neighbor_advertised_routes, |
556 | show_ip_bgp_l2vpn_evpn_rd_neighbor_advertised_routes_cmd, | |
557 | "show [ip] bgp l2vpn evpn rd ASN:nn_or_IP-address:nn neighbors A.B.C.D advertised-routes [json]", | |
558 | SHOW_STR | |
559 | IP_STR | |
560 | BGP_STR | |
561 | L2VPN_HELP_STR | |
562 | EVPN_HELP_STR | |
563 | "Display information for a route distinguisher\n" | |
564 | "VPN Route Distinguisher\n" | |
565 | "Detailed information on TCP and BGP neighbor connections\n" | |
566 | "Neighbor to display information about\n" | |
567 | "Display the routes advertised to a BGP neighbor\n" JSON_STR) | |
784d3a42 | 568 | { |
313605cb RW |
569 | int idx_ext_community = 0; |
570 | int idx_ipv4 = 0; | |
4d0e6ece PG |
571 | int ret; |
572 | struct peer *peer; | |
573 | struct prefix_rd prd; | |
574 | union sockunion su; | |
575 | u_char uj = use_json(argc, argv); | |
576 | ||
313605cb RW |
577 | argv_find (argv, argc, "ASN:nn_or_IP-address:nn", &idx_ext_community); |
578 | argv_find (argv, argc, "A.B.C.D", &idx_ipv4); | |
579 | ||
4d0e6ece PG |
580 | ret = str2sockunion(argv[idx_ipv4]->arg, &su); |
581 | if (ret < 0) { | |
582 | if (uj) { | |
583 | json_object *json_no = NULL; | |
584 | json_no = json_object_new_object(); | |
585 | json_object_string_add(json_no, "warning", | |
586 | "Malformed address"); | |
587 | vty_out(vty, "%s%s", | |
588 | json_object_to_json_string(json_no), | |
589 | VTY_NEWLINE); | |
590 | json_object_free(json_no); | |
591 | } else | |
592 | vty_out(vty, "Malformed address: %s%s", | |
593 | argv[idx_ext_community]->arg, VTY_NEWLINE); | |
594 | return CMD_WARNING; | |
595 | } | |
596 | peer = peer_lookup(NULL, &su); | |
597 | if (!peer || !peer->afc[AFI_L2VPN][SAFI_EVPN]) { | |
598 | if (uj) { | |
599 | json_object *json_no = NULL; | |
600 | json_no = json_object_new_object(); | |
601 | json_object_string_add(json_no, "warning", | |
602 | "No such neighbor or address family"); | |
603 | vty_out(vty, "%s%s", | |
604 | json_object_to_json_string(json_no), | |
605 | VTY_NEWLINE); | |
606 | json_object_free(json_no); | |
607 | } else | |
608 | vty_out(vty, "%% No such neighbor or address family%s", | |
609 | VTY_NEWLINE); | |
610 | return CMD_WARNING; | |
611 | } | |
612 | ||
613 | ret = str2prefix_rd(argv[idx_ext_community]->arg, &prd); | |
614 | if (!ret) { | |
615 | if (uj) { | |
616 | json_object *json_no = NULL; | |
617 | json_no = json_object_new_object(); | |
618 | json_object_string_add(json_no, "warning", | |
619 | "Malformed Route Distinguisher"); | |
620 | vty_out(vty, "%s%s", | |
621 | json_object_to_json_string(json_no), | |
622 | VTY_NEWLINE); | |
623 | json_object_free(json_no); | |
624 | } else | |
625 | vty_out(vty, "%% Malformed Route Distinguisher%s", | |
626 | VTY_NEWLINE); | |
627 | return CMD_WARNING; | |
628 | } | |
629 | ||
630 | return show_adj_route_vpn(vty, peer, &prd, AFI_L2VPN, SAFI_EVPN, uj); | |
784d3a42 PG |
631 | } |
632 | ||
4d0e6ece PG |
633 | DEFUN(show_ip_bgp_l2vpn_evpn_all_overlay, |
634 | show_ip_bgp_l2vpn_evpn_all_overlay_cmd, | |
635 | "show [ip] bgp l2vpn evpn all overlay", | |
636 | SHOW_STR | |
637 | IP_STR | |
638 | BGP_STR | |
639 | L2VPN_HELP_STR | |
640 | EVPN_HELP_STR | |
641 | "Display information about all EVPN NLRIs\n" | |
642 | "Display BGP Overlay Information for prefixes\n") | |
784d3a42 | 643 | { |
4d0e6ece PG |
644 | return bgp_show_ethernet_vpn(vty, NULL, bgp_show_type_normal, NULL, |
645 | SHOW_DISPLAY_OVERLAY, use_json(argc, | |
646 | argv)); | |
784d3a42 PG |
647 | } |
648 | ||
4d0e6ece PG |
649 | DEFUN(show_ip_bgp_evpn_rd_overlay, |
650 | show_ip_bgp_evpn_rd_overlay_cmd, | |
651 | "show [ip] bgp l2vpn evpn rd ASN:nn_or_IP-address:nn overlay", | |
652 | SHOW_STR | |
653 | IP_STR | |
654 | BGP_STR | |
655 | L2VPN_HELP_STR | |
656 | EVPN_HELP_STR | |
657 | "Display information for a route distinguisher\n" | |
658 | "VPN Route Distinguisher\n" | |
659 | "Display BGP Overlay Information for prefixes\n") | |
784d3a42 | 660 | { |
313605cb | 661 | int idx_ext_community = 0; |
4d0e6ece PG |
662 | int ret; |
663 | struct prefix_rd prd; | |
664 | ||
313605cb RW |
665 | argv_find (argv, argc, "ASN:nn_or_IP-address:nn", &idx_ext_community); |
666 | ||
4d0e6ece PG |
667 | ret = str2prefix_rd(argv[idx_ext_community]->arg, &prd); |
668 | if (!ret) { | |
669 | vty_out(vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); | |
670 | return CMD_WARNING; | |
671 | } | |
672 | return bgp_show_ethernet_vpn(vty, &prd, bgp_show_type_normal, NULL, | |
673 | SHOW_DISPLAY_OVERLAY, use_json(argc, | |
674 | argv)); | |
784d3a42 PG |
675 | } |
676 | ||
3da6fcd5 | 677 | /* For testing purpose, static route of MPLS-VPN. */ |
4d0e6ece PG |
678 | DEFUN(evpnrt5_network, |
679 | evpnrt5_network_cmd, | |
680 | "network <A.B.C.D/M|X:X::X:X/M> rd ASN:nn_or_IP-address:nn ethtag WORD label WORD esi WORD gwip <A.B.C.D|X:X::X:X> routermac WORD [route-map WORD]", | |
681 | "Specify a network to announce via BGP\n" | |
682 | "IP prefix\n" | |
683 | "IPv6 prefix\n" | |
684 | "Specify Route Distinguisher\n" | |
685 | "VPN Route Distinguisher\n" | |
686 | "Ethernet Tag\n" | |
687 | "Ethernet Tag Value\n" | |
688 | "BGP label\n" | |
689 | "label value\n" | |
690 | "Ethernet Segment Identifier\n" | |
691 | "ESI value ( 00:11:22:33:44:55:66:77:88:99 format) \n" | |
692 | "Gateway IP\n" | |
693 | "Gateway IP ( A.B.C.D )\n" | |
694 | "Gateway IPv6 ( X:X::X:X )\n" | |
695 | "Router Mac Ext Comm\n" | |
55daa605 DS |
696 | "Router Mac address Value ( aa:bb:cc:dd:ee:ff format)\n" |
697 | "Route-map to modify the attributes\n" | |
698 | "Name of the route map\n") | |
3da6fcd5 | 699 | { |
4d0e6ece PG |
700 | int idx_ipv4_prefixlen = 1; |
701 | int idx_ext_community = 3; | |
702 | int idx_word = 7; | |
703 | int idx_esi = 9; | |
704 | int idx_gwip = 11; | |
705 | int idx_ethtag = 5; | |
706 | int idx_routermac = 13; | |
707 | int idx_rmap = 15; | |
708 | return bgp_static_set_safi(SAFI_EVPN, vty, | |
709 | argv[idx_ipv4_prefixlen]->arg, | |
710 | argv[idx_ext_community]->arg, | |
711 | argv[idx_word]->arg, | |
712 | argv[idx_rmap] ? argv[idx_gwip]->arg : NULL, | |
713 | EVPN_IP_PREFIX, argv[idx_esi]->arg, | |
714 | argv[idx_gwip]->arg, argv[idx_ethtag]->arg, | |
715 | argv[idx_routermac]->arg); | |
3da6fcd5 PG |
716 | } |
717 | ||
718 | /* For testing purpose, static route of MPLS-VPN. */ | |
4d0e6ece PG |
719 | DEFUN(no_evpnrt5_network, |
720 | no_evpnrt5_network_cmd, | |
721 | "no network <A.B.C.D/M|X:X::X:X/M> rd ASN:nn_or_IP-address:nn ethtag WORD label WORD esi WORD gwip <A.B.C.D|X:X::X:X>", | |
722 | NO_STR | |
723 | "Specify a network to announce via BGP\n" | |
724 | "IP prefix\n" | |
725 | "IPv6 prefix\n" | |
726 | "Specify Route Distinguisher\n" | |
727 | "VPN Route Distinguisher\n" | |
728 | "Ethernet Tag\n" | |
729 | "Ethernet Tag Value\n" | |
730 | "BGP label\n" | |
731 | "label value\n" | |
732 | "Ethernet Segment Identifier\n" | |
733 | "ESI value ( 00:11:22:33:44:55:66:77:88:99 format) \n" | |
734 | "Gateway IP\n" "Gateway IP ( A.B.C.D )\n" "Gateway IPv6 ( X:X::X:X )\n") | |
3da6fcd5 | 735 | { |
4d0e6ece PG |
736 | int idx_ipv4_prefixlen = 2; |
737 | int idx_ext_community = 4; | |
738 | int idx_label = 8; | |
739 | int idx_ethtag = 6; | |
740 | int idx_esi = 10; | |
741 | int idx_gwip = 12; | |
742 | return bgp_static_unset_safi(SAFI_EVPN, vty, | |
743 | argv[idx_ipv4_prefixlen]->arg, | |
744 | argv[idx_ext_community]->arg, | |
745 | argv[idx_label]->arg, EVPN_IP_PREFIX, | |
746 | argv[idx_esi]->arg, argv[idx_gwip]->arg, | |
747 | argv[idx_ethtag]->arg); | |
3da6fcd5 PG |
748 | } |
749 | ||
4d0e6ece | 750 | void bgp_ethernetvpn_init(void) |
784d3a42 | 751 | { |
4d0e6ece PG |
752 | install_element(VIEW_NODE, &show_ip_bgp_l2vpn_evpn_cmd); |
753 | install_element(VIEW_NODE, &show_ip_bgp_l2vpn_evpn_rd_cmd); | |
754 | install_element(VIEW_NODE, &show_ip_bgp_l2vpn_evpn_all_tags_cmd); | |
755 | install_element(VIEW_NODE, &show_ip_bgp_l2vpn_evpn_rd_tags_cmd); | |
756 | install_element(VIEW_NODE, | |
757 | &show_ip_bgp_l2vpn_evpn_all_neighbor_routes_cmd); | |
758 | install_element(VIEW_NODE, | |
759 | &show_ip_bgp_l2vpn_evpn_rd_neighbor_routes_cmd); | |
760 | install_element(VIEW_NODE, | |
761 | &show_ip_bgp_l2vpn_evpn_all_neighbor_advertised_routes_cmd); | |
762 | install_element(VIEW_NODE, | |
763 | &show_ip_bgp_l2vpn_evpn_rd_neighbor_advertised_routes_cmd); | |
764 | install_element(VIEW_NODE, &show_ip_bgp_evpn_rd_overlay_cmd); | |
765 | install_element(VIEW_NODE, &show_ip_bgp_l2vpn_evpn_all_overlay_cmd); | |
766 | install_element(BGP_EVPN_NODE, &no_evpnrt5_network_cmd); | |
767 | install_element(BGP_EVPN_NODE, &evpnrt5_network_cmd); | |
784d3a42 | 768 | } |