1 /* Ethernet-VPN Packet and vty Processing File
2 * Copyright (C) 2017 6WIND
4 * This file is part of FRRouting
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
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.
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
27 #include "bgpd/bgpd.h"
28 #include "bgpd/bgp_table.h"
29 #include "bgpd/bgp_attr.h"
30 #include "bgpd/bgp_route.h"
31 #include "bgpd/bgp_mplsvpn.h"
32 #include "bgpd/bgp_vpn.h"
33 #include "bgpd/bgp_evpn_vty.h"
34 #include "bgpd/bgp_evpn.h"
35 #include "bgpd/bgp_evpn_private.h"
36 #include "bgpd/bgp_zebra.h"
37 #include "bgpd/bgp_vty.h"
38 #include "bgpd/bgp_errors.h"
39 #include "bgpd/bgp_ecommunity.h"
41 #define SHOW_DISPLAY_STANDARD 0
42 #define SHOW_DISPLAY_TAGS 1
43 #define SHOW_DISPLAY_OVERLAY 2
44 #define VNI_STR_LEN 32
47 * Context for VNI hash walk - used by callbacks.
52 struct in_addr vtep_ip
;
56 static void display_vrf_import_rt(struct vty
*vty
, struct vrf_irt_node
*irt
,
60 uint8_t type
, sub_type
;
61 struct ecommunity_as eas
;
62 struct ecommunity_ip eip
;
63 struct listnode
*node
, *nnode
;
64 struct bgp
*tmp_bgp_vrf
= NULL
;
65 json_object
*json_rt
= NULL
;
66 json_object
*json_vrfs
= NULL
;
67 char rt_buf
[RT_ADDRSTRLEN
];
70 json_rt
= json_object_new_object();
71 json_vrfs
= json_object_new_array();
74 pnt
= (uint8_t *)&irt
->rt
.val
;
77 if (sub_type
!= ECOMMUNITY_ROUTE_TARGET
)
80 memset(&eas
, 0, sizeof(eas
));
82 case ECOMMUNITY_ENCODE_AS
:
83 eas
.as
= (*pnt
++ << 8);
85 ptr_get_be32(pnt
, &eas
.val
);
87 snprintf(rt_buf
, RT_ADDRSTRLEN
, "%u:%u", eas
.as
, eas
.val
);
90 json_object_string_add(json_rt
, "rt", rt_buf
);
92 vty_out(vty
, "Route-target: %s", rt_buf
);
96 case ECOMMUNITY_ENCODE_IP
:
97 memcpy(&eip
.ip
, pnt
, 4);
99 eip
.val
= (*pnt
++ << 8);
102 snprintf(rt_buf
, RT_ADDRSTRLEN
, "%s:%u", inet_ntoa(eip
.ip
),
106 json_object_string_add(json_rt
, "rt", rt_buf
);
108 vty_out(vty
, "Route-target: %s", rt_buf
);
112 case ECOMMUNITY_ENCODE_AS4
:
113 pnt
= ptr_get_be32(pnt
, &eas
.val
);
114 eas
.val
= (*pnt
++ << 8);
117 snprintf(rt_buf
, RT_ADDRSTRLEN
, "%u:%u", eas
.as
, eas
.val
);
120 json_object_string_add(json_rt
, "rt", rt_buf
);
122 vty_out(vty
, "Route-target: %s", rt_buf
);
132 "\nList of VRFs importing routes with this route-target:\n");
135 for (ALL_LIST_ELEMENTS(irt
->vrfs
, node
, nnode
, tmp_bgp_vrf
)) {
137 json_object_array_add(
139 json_object_new_string(
140 vrf_id_to_name(tmp_bgp_vrf
->vrf_id
)));
142 vty_out(vty
, " %s\n",
143 vrf_id_to_name(tmp_bgp_vrf
->vrf_id
));
147 json_object_object_add(json_rt
, "vrfs", json_vrfs
);
148 json_object_object_add(json
, rt_buf
, json_rt
);
152 static void show_vrf_import_rt_entry(struct hash_backet
*backet
, void *args
[])
154 json_object
*json
= NULL
;
155 struct vty
*vty
= NULL
;
156 struct vrf_irt_node
*irt
= (struct vrf_irt_node
*)backet
->data
;
158 vty
= (struct vty
*)args
[0];
159 json
= (struct json_object
*)args
[1];
161 display_vrf_import_rt(vty
, irt
, json
);
164 static void display_import_rt(struct vty
*vty
, struct irt_node
*irt
,
168 uint8_t type
, sub_type
;
169 struct ecommunity_as eas
;
170 struct ecommunity_ip eip
;
171 struct listnode
*node
, *nnode
;
172 struct bgpevpn
*tmp_vpn
;
173 json_object
*json_rt
= NULL
;
174 json_object
*json_vnis
= NULL
;
175 char rt_buf
[RT_ADDRSTRLEN
];
178 json_rt
= json_object_new_object();
179 json_vnis
= json_object_new_array();
182 /* TODO: This needs to go into a function */
184 pnt
= (uint8_t *)&irt
->rt
.val
;
187 if (sub_type
!= ECOMMUNITY_ROUTE_TARGET
)
190 memset(&eas
, 0, sizeof(eas
));
192 case ECOMMUNITY_ENCODE_AS
:
193 eas
.as
= (*pnt
++ << 8);
195 ptr_get_be32(pnt
, &eas
.val
);
197 snprintf(rt_buf
, RT_ADDRSTRLEN
, "%u:%u", eas
.as
, eas
.val
);
200 json_object_string_add(json_rt
, "rt", rt_buf
);
202 vty_out(vty
, "Route-target: %s", rt_buf
);
206 case ECOMMUNITY_ENCODE_IP
:
207 memcpy(&eip
.ip
, pnt
, 4);
209 eip
.val
= (*pnt
++ << 8);
212 snprintf(rt_buf
, RT_ADDRSTRLEN
, "%s:%u", inet_ntoa(eip
.ip
),
216 json_object_string_add(json_rt
, "rt", rt_buf
);
218 vty_out(vty
, "Route-target: %s", rt_buf
);
222 case ECOMMUNITY_ENCODE_AS4
:
223 pnt
= ptr_get_be32(pnt
, &eas
.val
);
224 eas
.val
= (*pnt
++ << 8);
227 snprintf(rt_buf
, RT_ADDRSTRLEN
, "%u:%u", eas
.as
, eas
.val
);
230 json_object_string_add(json_rt
, "rt", rt_buf
);
232 vty_out(vty
, "Route-target: %s", rt_buf
);
242 "\nList of VNIs importing routes with this route-target:\n");
245 for (ALL_LIST_ELEMENTS(irt
->vnis
, node
, nnode
, tmp_vpn
)) {
247 json_object_array_add(
248 json_vnis
, json_object_new_int(tmp_vpn
->vni
));
250 vty_out(vty
, " %u\n", tmp_vpn
->vni
);
254 json_object_object_add(json_rt
, "vnis", json_vnis
);
255 json_object_object_add(json
, rt_buf
, json_rt
);
259 static void show_import_rt_entry(struct hash_backet
*backet
, void *args
[])
261 json_object
*json
= NULL
;
262 struct vty
*vty
= NULL
;
263 struct irt_node
*irt
= (struct irt_node
*)backet
->data
;
268 display_import_rt(vty
, irt
, json
);
273 static void bgp_evpn_show_route_rd_header(struct vty
*vty
,
274 struct bgp_node
*rd_rn
,
281 char rd_str
[RD_ADDRSTRLEN
];
283 pnt
= rd_rn
->p
.u
.val
;
285 /* Decode RD type. */
286 type
= decode_rd_type(pnt
);
291 vty_out(vty
, "Route Distinguisher: ");
295 decode_rd_as(pnt
+ 2, &rd_as
);
296 snprintf(rd_str
, RD_ADDRSTRLEN
, "%u:%d", rd_as
.as
, rd_as
.val
);
300 decode_rd_ip(pnt
+ 2, &rd_ip
);
301 snprintf(rd_str
, RD_ADDRSTRLEN
, "%s:%d", inet_ntoa(rd_ip
.ip
),
306 snprintf(rd_str
, RD_ADDRSTRLEN
, "Unknown RD type");
310 vty_out(vty
, "%s\n", rd_str
);
313 static void bgp_evpn_show_route_header(struct vty
*vty
, struct bgp
*bgp
,
314 uint64_t tbl_ver
, json_object
*json
)
317 " Network Next Hop Metric LocPrf Weight Path\n";
322 vty_out(vty
, "BGP table version is %" PRIu64
", local router ID is %s\n",
323 tbl_ver
, inet_ntoa(bgp
->router_id
));
325 "Status codes: s suppressed, d damped, h history, "
326 "* valid, > best, i - internal\n");
327 vty_out(vty
, "Origin codes: i - IGP, e - EGP, ? - incomplete\n");
329 "EVPN type-2 prefix: [2]:[EthTag]:[MAClen]:[MAC]:[IPlen]:[IP]\n");
330 vty_out(vty
, "EVPN type-3 prefix: [3]:[EthTag]:[IPlen]:[OrigIP]\n");
331 vty_out(vty
, "EVPN type-4 prefix: [4]:[ESI]:[IPlen]:[OrigIP]\n");
332 vty_out(vty
, "EVPN type-5 prefix: [5]:[EthTag]:[IPlen]:[IP]\n\n");
333 vty_out(vty
, "%s", ri_header
);
336 static void display_l3vni(struct vty
*vty
, struct bgp
*bgp_vrf
,
339 char buf1
[INET6_ADDRSTRLEN
];
341 struct listnode
*node
, *nnode
;
342 struct ecommunity
*ecom
;
343 json_object
*json_import_rtl
= NULL
;
344 json_object
*json_export_rtl
= NULL
;
346 json_import_rtl
= json_export_rtl
= 0;
349 json_import_rtl
= json_object_new_array();
350 json_export_rtl
= json_object_new_array();
351 json_object_int_add(json
, "vni", bgp_vrf
->l3vni
);
352 json_object_string_add(json
, "type", "L3");
353 json_object_string_add(json
, "kernelFlag", "Yes");
354 json_object_string_add(
356 prefix_rd2str(&bgp_vrf
->vrf_prd
, buf1
, RD_ADDRSTRLEN
));
357 json_object_string_add(json
, "originatorIp",
358 inet_ntoa(bgp_vrf
->originator_ip
));
359 json_object_string_add(json
, "advertiseGatewayMacip", "n/a");
361 vty_out(vty
, "VNI: %d", bgp_vrf
->l3vni
);
362 vty_out(vty
, " (known to the kernel)");
365 vty_out(vty
, " Type: %s\n", "L3");
366 vty_out(vty
, " Tenant VRF: %s\n",
367 vrf_id_to_name(bgp_vrf
->vrf_id
));
368 vty_out(vty
, " RD: %s\n",
369 prefix_rd2str(&bgp_vrf
->vrf_prd
, buf1
, RD_ADDRSTRLEN
));
370 vty_out(vty
, " Originator IP: %s\n",
371 inet_ntoa(bgp_vrf
->originator_ip
));
372 vty_out(vty
, " Advertise-gw-macip : %s\n", "n/a");
376 vty_out(vty
, " Import Route Target:\n");
378 for (ALL_LIST_ELEMENTS(bgp_vrf
->vrf_import_rtl
, node
, nnode
, ecom
)) {
379 ecom_str
= ecommunity_ecom2str(ecom
,
380 ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
383 json_object_array_add(json_import_rtl
,
384 json_object_new_string(ecom_str
));
386 vty_out(vty
, " %s\n", ecom_str
);
388 XFREE(MTYPE_ECOMMUNITY_STR
, ecom_str
);
392 json_object_object_add(json
, "importRts", json_import_rtl
);
394 vty_out(vty
, " Export Route Target:\n");
396 for (ALL_LIST_ELEMENTS(bgp_vrf
->vrf_export_rtl
, node
, nnode
, ecom
)) {
397 ecom_str
= ecommunity_ecom2str(ecom
,
398 ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
401 json_object_array_add(json_export_rtl
,
402 json_object_new_string(ecom_str
));
404 vty_out(vty
, " %s\n", ecom_str
);
406 XFREE(MTYPE_ECOMMUNITY_STR
, ecom_str
);
410 json_object_object_add(json
, "exportRts", json_export_rtl
);
413 static void display_es(struct vty
*vty
, struct evpnes
*es
, json_object
*json
)
415 struct in_addr
*vtep
;
416 char buf
[ESI_STR_LEN
];
417 char buf1
[RD_ADDRSTRLEN
];
418 char buf2
[INET6_ADDRSTRLEN
];
419 struct listnode
*node
= NULL
;
420 json_object
*json_vteps
= NULL
;
423 json_vteps
= json_object_new_array();
424 json_object_string_add(json
, "esi",
425 esi_to_str(&es
->esi
, buf
, sizeof(buf
)));
426 json_object_string_add(json
, "rd",
427 prefix_rd2str(&es
->prd
, buf1
,
429 json_object_string_add(
430 json
, "originatorIp",
431 ipaddr2str(&es
->originator_ip
, buf2
, sizeof(buf2
)));
433 for (ALL_LIST_ELEMENTS_RO(es
->vtep_list
, node
, vtep
))
434 json_object_array_add(
435 json_vteps
, json_object_new_string(
438 json_object_object_add(json
, "vteps", json_vteps
);
440 vty_out(vty
, "ESI: %s\n",
441 esi_to_str(&es
->esi
, buf
, sizeof(buf
)));
442 vty_out(vty
, " RD: %s\n", prefix_rd2str(&es
->prd
, buf1
,
444 vty_out(vty
, " Originator-IP: %s\n",
445 ipaddr2str(&es
->originator_ip
, buf2
, sizeof(buf2
)));
447 vty_out(vty
, " VTEP List:\n");
448 for (ALL_LIST_ELEMENTS_RO(es
->vtep_list
, node
, vtep
))
449 vty_out(vty
, " %s\n", inet_ntoa(*vtep
));
454 static void display_vni(struct vty
*vty
, struct bgpevpn
*vpn
, json_object
*json
)
456 char buf1
[RD_ADDRSTRLEN
];
458 struct listnode
*node
, *nnode
;
459 struct ecommunity
*ecom
;
460 json_object
*json_import_rtl
= NULL
;
461 json_object
*json_export_rtl
= NULL
;
464 json_import_rtl
= json_object_new_array();
465 json_export_rtl
= json_object_new_array();
466 json_object_int_add(json
, "vni", vpn
->vni
);
467 json_object_string_add(json
, "type", "L2");
468 json_object_string_add(json
, "kernelFlag",
469 is_vni_live(vpn
) ? "Yes" : "No");
470 json_object_string_add(
472 prefix_rd2str(&vpn
->prd
, buf1
, sizeof(buf1
)));
473 json_object_string_add(json
, "originatorIp",
474 inet_ntoa(vpn
->originator_ip
));
475 json_object_string_add(json
, "advertiseGatewayMacip",
476 vpn
->advertise_gw_macip
? "Yes" : "No");
478 vty_out(vty
, "VNI: %d", vpn
->vni
);
479 if (is_vni_live(vpn
))
480 vty_out(vty
, " (known to the kernel)");
483 vty_out(vty
, " Type: %s\n", "L2");
484 vty_out(vty
, " Tenant-Vrf: %s\n",
485 vrf_id_to_name(vpn
->tenant_vrf_id
));
486 vty_out(vty
, " RD: %s\n",
487 prefix_rd2str(&vpn
->prd
, buf1
, sizeof(buf1
)));
488 vty_out(vty
, " Originator IP: %s\n",
489 inet_ntoa(vpn
->originator_ip
));
490 vty_out(vty
, " Advertise-gw-macip : %s\n",
491 vpn
->advertise_gw_macip
? "Yes" : "No");
495 vty_out(vty
, " Import Route Target:\n");
497 for (ALL_LIST_ELEMENTS(vpn
->import_rtl
, node
, nnode
, ecom
)) {
498 ecom_str
= ecommunity_ecom2str(ecom
,
499 ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
502 json_object_array_add(json_import_rtl
,
503 json_object_new_string(ecom_str
));
505 vty_out(vty
, " %s\n", ecom_str
);
507 XFREE(MTYPE_ECOMMUNITY_STR
, ecom_str
);
511 json_object_object_add(json
, "importRts", json_import_rtl
);
513 vty_out(vty
, " Export Route Target:\n");
515 for (ALL_LIST_ELEMENTS(vpn
->export_rtl
, node
, nnode
, ecom
)) {
516 ecom_str
= ecommunity_ecom2str(ecom
,
517 ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
520 json_object_array_add(json_export_rtl
,
521 json_object_new_string(ecom_str
));
523 vty_out(vty
, " %s\n", ecom_str
);
525 XFREE(MTYPE_ECOMMUNITY_STR
, ecom_str
);
529 json_object_object_add(json
, "exportRts", json_export_rtl
);
532 static void show_esi_routes(struct bgp
*bgp
,
539 struct bgp_path_info
*pi
;
540 uint32_t prefix_cnt
, path_cnt
;
543 prefix_cnt
= path_cnt
= 0;
545 tbl_ver
= es
->route_table
->version
;
546 for (rn
= bgp_table_top(es
->route_table
); rn
;
547 rn
= bgp_route_next(rn
)) {
548 int add_prefix_to_json
= 0;
549 char prefix_str
[BUFSIZ
];
550 json_object
*json_paths
= NULL
;
551 json_object
*json_prefix
= NULL
;
553 bgp_evpn_route2str((struct prefix_evpn
*)&rn
->p
, prefix_str
,
557 json_prefix
= json_object_new_object();
559 pi
= bgp_node_get_bgp_path_info(rn
);
561 /* Overall header/legend displayed once. */
563 bgp_evpn_show_route_header(vty
, bgp
,
572 json_paths
= json_object_new_array();
574 /* For EVPN, the prefix is displayed for each path (to fit in
575 * with code that already exists).
577 for (; pi
; pi
= pi
->next
) {
578 json_object
*json_path
= NULL
;
581 json_path
= json_object_new_array();
583 route_vty_out(vty
, &rn
->p
, pi
, 0, SAFI_EVPN
, json_path
);
586 json_object_array_add(json_paths
, json_path
);
589 add_prefix_to_json
= 1;
592 if (json
&& add_prefix_to_json
) {
593 json_object_string_add(json_prefix
, "prefix",
595 json_object_int_add(json_prefix
, "prefixLen",
597 json_object_object_add(json_prefix
, "paths",
599 json_object_object_add(json
, prefix_str
, json_prefix
);
604 json_object_int_add(json
, "numPrefix", prefix_cnt
);
605 json_object_int_add(json
, "numPaths", path_cnt
);
608 vty_out(vty
, "No EVPN prefixes exist for this ESI\n");
610 vty_out(vty
, "\nDisplayed %u prefixes (%u paths)\n",
611 prefix_cnt
, path_cnt
);
615 static void show_vni_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
, int type
,
616 struct vty
*vty
, struct in_addr vtep_ip
,
620 struct bgp_path_info
*pi
;
621 struct bgp_table
*table
;
624 uint32_t prefix_cnt
, path_cnt
;
626 prefix_cnt
= path_cnt
= 0;
628 table
= vpn
->route_table
;
629 tbl_ver
= table
->version
;
630 for (rn
= bgp_table_top(table
); rn
;
631 rn
= bgp_route_next(rn
)) {
632 struct prefix_evpn
*evp
= (struct prefix_evpn
*)&rn
->p
;
633 int add_prefix_to_json
= 0;
634 char prefix_str
[BUFSIZ
];
635 json_object
*json_paths
= NULL
;
636 json_object
*json_prefix
= NULL
;
638 bgp_evpn_route2str((struct prefix_evpn
*)&rn
->p
, prefix_str
,
641 if (type
&& evp
->prefix
.route_type
!= type
)
645 json_prefix
= json_object_new_object();
647 pi
= bgp_node_get_bgp_path_info(rn
);
649 /* Overall header/legend displayed once. */
651 bgp_evpn_show_route_header(vty
, bgp
,
660 json_paths
= json_object_new_array();
662 /* For EVPN, the prefix is displayed for each path (to fit in
663 * with code that already exists).
665 for (; pi
; pi
= pi
->next
) {
666 json_object
*json_path
= NULL
;
669 && !IPV4_ADDR_SAME(&(vtep_ip
),
670 &(pi
->attr
->nexthop
)))
674 json_path
= json_object_new_array();
676 route_vty_out(vty
, &rn
->p
, pi
, 0, SAFI_EVPN
, json_path
);
679 json_object_array_add(json_paths
, json_path
);
682 add_prefix_to_json
= 1;
685 if (json
&& add_prefix_to_json
) {
686 json_object_string_add(json_prefix
, "prefix",
688 json_object_int_add(json_prefix
, "prefixLen",
690 json_object_object_add(json_prefix
, "paths",
692 json_object_object_add(json
, prefix_str
, json_prefix
);
697 json_object_int_add(json
, "numPrefix", prefix_cnt
);
698 json_object_int_add(json
, "numPaths", path_cnt
);
701 vty_out(vty
, "No EVPN prefixes %sexist for this VNI",
702 type
? "(of requested type) " : "");
704 vty_out(vty
, "\nDisplayed %u prefixes (%u paths)%s\n",
705 prefix_cnt
, path_cnt
,
706 type
? " (of requested type)" : "");
710 static void show_vni_routes_hash(struct hash_backet
*backet
, void *arg
)
712 struct bgpevpn
*vpn
= (struct bgpevpn
*)backet
->data
;
713 struct vni_walk_ctx
*wctx
= arg
;
714 struct vty
*vty
= wctx
->vty
;
715 json_object
*json
= wctx
->json
;
716 json_object
*json_vni
= NULL
;
717 char vni_str
[VNI_STR_LEN
];
719 snprintf(vni_str
, VNI_STR_LEN
, "%d", vpn
->vni
);
721 json_vni
= json_object_new_object();
722 json_object_int_add(json_vni
, "vni", vpn
->vni
);
724 vty_out(vty
, "\nVNI: %d\n\n", vpn
->vni
);
727 show_vni_routes(wctx
->bgp
, vpn
, 0, wctx
->vty
, wctx
->vtep_ip
, json_vni
);
730 json_object_object_add(json
, vni_str
, json_vni
);
733 static void show_l3vni_entry(struct vty
*vty
, struct bgp
*bgp
,
736 json_object
*json_vni
= NULL
;
737 json_object
*json_import_rtl
= NULL
;
738 json_object
*json_export_rtl
= NULL
;
740 char buf2
[INET6_ADDRSTRLEN
];
743 struct listnode
*node
, *nnode
;
744 struct ecommunity
*ecom
;
750 json_vni
= json_object_new_object();
751 json_import_rtl
= json_object_new_array();
752 json_export_rtl
= json_object_new_array();
755 /* if an l3vni is present in bgp it is live */
760 json_object_int_add(json_vni
, "vni", bgp
->l3vni
);
761 json_object_string_add(json_vni
, "type", "L3");
762 json_object_string_add(json_vni
, "inKernel", "True");
763 json_object_string_add(json_vni
, "originatorIp",
764 inet_ntoa(bgp
->originator_ip
));
765 json_object_string_add(
767 prefix_rd2str(&bgp
->vrf_prd
, buf2
, RD_ADDRSTRLEN
));
769 vty_out(vty
, "%-1s %-10u %-4s %-21s", buf1
, bgp
->l3vni
, "L3",
770 prefix_rd2str(&bgp
->vrf_prd
, buf2
, RD_ADDRSTRLEN
));
773 for (ALL_LIST_ELEMENTS(bgp
->vrf_import_rtl
, node
, nnode
, ecom
)) {
774 ecom_str
= ecommunity_ecom2str(ecom
,
775 ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
778 json_object_array_add(json_import_rtl
,
779 json_object_new_string(ecom_str
));
781 if (listcount(bgp
->vrf_import_rtl
) > 1)
782 sprintf(rt_buf
, "%s, ...", ecom_str
);
784 sprintf(rt_buf
, "%s", ecom_str
);
785 vty_out(vty
, " %-25s", rt_buf
);
788 XFREE(MTYPE_ECOMMUNITY_STR
, ecom_str
);
790 /* If there are multiple import RTs we break here and show only
797 json_object_object_add(json_vni
, "importRTs", json_import_rtl
);
799 for (ALL_LIST_ELEMENTS(bgp
->vrf_export_rtl
, node
, nnode
, ecom
)) {
800 ecom_str
= ecommunity_ecom2str(ecom
,
801 ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
804 json_object_array_add(json_export_rtl
,
805 json_object_new_string(ecom_str
));
807 if (listcount(bgp
->vrf_export_rtl
) > 1)
808 sprintf(rt_buf
, "%s, ...", ecom_str
);
810 sprintf(rt_buf
, "%s", ecom_str
);
811 vty_out(vty
, " %-25s", rt_buf
);
814 XFREE(MTYPE_ECOMMUNITY_STR
, ecom_str
);
816 /* If there are multiple export RTs we break here and show only
823 vty_out(vty
, "%-37s", vrf_id_to_name(bgp
->vrf_id
));
826 char vni_str
[VNI_STR_LEN
];
828 json_object_object_add(json_vni
, "exportRTs", json_export_rtl
);
829 snprintf(vni_str
, VNI_STR_LEN
, "%u", bgp
->l3vni
);
830 json_object_object_add(json
, vni_str
, json_vni
);
836 static void show_es_entry(struct hash_backet
*backet
, void *args
[])
838 char buf
[ESI_STR_LEN
];
839 char buf1
[RD_ADDRSTRLEN
];
840 char buf2
[INET6_ADDRSTRLEN
];
841 struct in_addr
*vtep
= NULL
;
842 struct vty
*vty
= args
[0];
843 json_object
*json
= args
[1];
844 json_object
*json_vteps
= NULL
;
845 struct listnode
*node
= NULL
;
846 struct evpnes
*es
= (struct evpnes
*)backet
->data
;
849 json_vteps
= json_object_new_array();
850 json_object_string_add(json
, "esi",
851 esi_to_str(&es
->esi
, buf
, sizeof(buf
)));
852 json_object_string_add(json
, "type",
853 is_es_local(es
) ? "Local" : "Remote");
854 json_object_string_add(json
, "rd",
855 prefix_rd2str(&es
->prd
, buf1
,
857 json_object_string_add(
858 json
, "originatorIp",
859 ipaddr2str(&es
->originator_ip
, buf2
, sizeof(buf2
)));
861 for (ALL_LIST_ELEMENTS_RO(es
->vtep_list
, node
, vtep
))
862 json_object_array_add(json_vteps
,
863 json_object_new_string(
866 json_object_object_add(json
, "vteps", json_vteps
);
868 vty_out(vty
, "%-30s %-6s %-21s %-15s %-6d\n",
869 esi_to_str(&es
->esi
, buf
, sizeof(buf
)),
870 is_es_local(es
) ? "Local" : "Remote",
871 prefix_rd2str(&es
->prd
, buf1
, sizeof(buf1
)),
872 ipaddr2str(&es
->originator_ip
, buf2
,
874 es
->vtep_list
? listcount(es
->vtep_list
) : 0);
878 static void show_vni_entry(struct hash_backet
*backet
, void *args
[])
882 json_object
*json_vni
= NULL
;
883 json_object
*json_import_rtl
= NULL
;
884 json_object
*json_export_rtl
= NULL
;
885 struct bgpevpn
*vpn
= (struct bgpevpn
*)backet
->data
;
887 char buf2
[RD_ADDRSTRLEN
];
890 struct listnode
*node
, *nnode
;
891 struct ecommunity
*ecom
;
897 json_vni
= json_object_new_object();
898 json_import_rtl
= json_object_new_array();
899 json_export_rtl
= json_object_new_array();
903 if (is_vni_live(vpn
))
907 json_object_int_add(json_vni
, "vni", vpn
->vni
);
908 json_object_string_add(json_vni
, "type", "L2");
909 json_object_string_add(json_vni
, "inKernel",
910 is_vni_live(vpn
) ? "True" : "False");
911 json_object_string_add(json_vni
, "originatorIp",
912 inet_ntoa(vpn
->originator_ip
));
913 json_object_string_add(json_vni
, "originatorIp",
914 inet_ntoa(vpn
->originator_ip
));
915 json_object_string_add(
917 prefix_rd2str(&vpn
->prd
, buf2
, sizeof(buf2
)));
919 vty_out(vty
, "%-1s %-10u %-4s %-21s", buf1
, vpn
->vni
, "L2",
920 prefix_rd2str(&vpn
->prd
, buf2
, RD_ADDRSTRLEN
));
923 for (ALL_LIST_ELEMENTS(vpn
->import_rtl
, node
, nnode
, ecom
)) {
924 ecom_str
= ecommunity_ecom2str(ecom
,
925 ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
928 json_object_array_add(json_import_rtl
,
929 json_object_new_string(ecom_str
));
931 if (listcount(vpn
->import_rtl
) > 1)
932 sprintf(rt_buf
, "%s, ...", ecom_str
);
934 sprintf(rt_buf
, "%s", ecom_str
);
935 vty_out(vty
, " %-25s", rt_buf
);
938 XFREE(MTYPE_ECOMMUNITY_STR
, ecom_str
);
940 /* If there are multiple import RTs we break here and show only
947 json_object_object_add(json_vni
, "importRTs", json_import_rtl
);
949 for (ALL_LIST_ELEMENTS(vpn
->export_rtl
, node
, nnode
, ecom
)) {
950 ecom_str
= ecommunity_ecom2str(ecom
,
951 ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
954 json_object_array_add(json_export_rtl
,
955 json_object_new_string(ecom_str
));
957 if (listcount(vpn
->export_rtl
) > 1)
958 sprintf(rt_buf
, "%s, ...", ecom_str
);
960 sprintf(rt_buf
, "%s", ecom_str
);
961 vty_out(vty
, " %-25s", rt_buf
);
964 XFREE(MTYPE_ECOMMUNITY_STR
, ecom_str
);
966 /* If there are multiple export RTs we break here and show only
973 vty_out(vty
, "%-37s", vrf_id_to_name(vpn
->tenant_vrf_id
));
976 char vni_str
[VNI_STR_LEN
];
978 json_object_object_add(json_vni
, "exportRTs", json_export_rtl
);
979 snprintf(vni_str
, VNI_STR_LEN
, "%u", vpn
->vni
);
980 json_object_object_add(json
, vni_str
, json_vni
);
986 static int bgp_show_ethernet_vpn(struct vty
*vty
, struct prefix_rd
*prd
,
987 enum bgp_show_type type
, void *output_arg
,
988 int option
, bool use_json
)
990 afi_t afi
= AFI_L2VPN
;
992 struct bgp_table
*table
;
995 struct bgp_path_info
*pi
;
999 unsigned long output_count
= 0;
1000 unsigned long total_count
= 0;
1001 json_object
*json
= NULL
;
1002 json_object
*json_nroute
= NULL
;
1003 json_object
*json_array
= NULL
;
1004 json_object
*json_scode
= NULL
;
1005 json_object
*json_ocode
= NULL
;
1007 bgp
= bgp_get_default();
1010 vty_out(vty
, "No BGP process is configured\n");
1012 vty_out(vty
, "{}\n");
1017 json_scode
= json_object_new_object();
1018 json_ocode
= json_object_new_object();
1019 json
= json_object_new_object();
1020 json_nroute
= json_object_new_object();
1022 json_object_string_add(json_scode
, "suppressed", "s");
1023 json_object_string_add(json_scode
, "damped", "d");
1024 json_object_string_add(json_scode
, "history", "h");
1025 json_object_string_add(json_scode
, "valid", "*");
1026 json_object_string_add(json_scode
, "best", ">");
1027 json_object_string_add(json_scode
, "internal", "i");
1029 json_object_string_add(json_ocode
, "igp", "i");
1030 json_object_string_add(json_ocode
, "egp", "e");
1031 json_object_string_add(json_ocode
, "incomplete", "?");
1034 for (rn
= bgp_table_top(bgp
->rib
[afi
][SAFI_EVPN
]); rn
;
1035 rn
= bgp_route_next(rn
)) {
1039 continue; /* XXX json TODO */
1041 if (prd
&& memcmp(rn
->p
.u
.val
, prd
->val
, 8) != 0)
1044 table
= bgp_node_get_bgp_table_info(rn
);
1049 tbl_ver
= table
->version
;
1051 for (rm
= bgp_table_top(table
); rm
; rm
= bgp_route_next(rm
))
1052 for (pi
= bgp_node_get_bgp_path_info(rm
); pi
;
1055 if (type
== bgp_show_type_neighbor
) {
1056 union sockunion
*su
= output_arg
;
1058 if (pi
->peer
->su_remote
== NULL
1060 pi
->peer
->su_remote
, su
))
1066 == SHOW_DISPLAY_TAGS
) {
1067 json_object_int_add(
1071 json_object_string_add(
1076 json_object_object_add(
1080 json_object_object_add(
1086 if (option
== SHOW_DISPLAY_TAGS
)
1091 == SHOW_DISPLAY_OVERLAY
)
1096 "BGP table version is %" PRIu64
", local router ID is %s\n",
1101 "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal\n");
1103 "Origin codes: i - IGP, e - EGP, ? - incomplete\n\n");
1104 vty_out(vty
, V4_HEADER
);
1117 /* Decode RD type. */
1118 type
= decode_rd_type(pnt
);
1119 /* Decode RD value. */
1120 if (type
== RD_TYPE_AS
)
1121 decode_rd_as(pnt
+ 2, &rd_as
);
1122 else if (type
== RD_TYPE_AS4
)
1123 decode_rd_as4(pnt
+ 2, &rd_as
);
1124 else if (type
== RD_TYPE_IP
)
1125 decode_rd_ip(pnt
+ 2, &rd_ip
);
1127 char buffer
[BUFSIZ
];
1128 if (type
== RD_TYPE_AS
1129 || type
== RD_TYPE_AS4
)
1130 sprintf(buffer
, "%u:%d",
1133 else if (type
== RD_TYPE_IP
)
1134 sprintf(buffer
, "%s:%d",
1138 json_object_string_add(
1140 "routeDistinguisher",
1144 "Route Distinguisher: ");
1145 if (type
== RD_TYPE_AS
)
1150 else if (type
== RD_TYPE_AS4
)
1155 else if (type
== RD_TYPE_IP
)
1156 vty_out(vty
, "ip %s:%d",
1160 vty_out(vty
, "\n\n");
1165 json_array
= json_object_new_array();
1168 if (option
== SHOW_DISPLAY_TAGS
)
1169 route_vty_out_tag(vty
, &rm
->p
, pi
, 0,
1172 else if (option
== SHOW_DISPLAY_OVERLAY
)
1173 route_vty_out_overlay(vty
, &rm
->p
, pi
,
1176 route_vty_out(vty
, &rm
->p
, pi
, 0,
1177 SAFI_EVPN
, json_array
);
1182 if (output_count
== 0)
1183 vty_out(vty
, "No prefixes displayed, %ld exist\n", total_count
);
1185 vty_out(vty
, "\nDisplayed %ld out of %ld total prefixes\n",
1186 output_count
, total_count
);
1190 DEFUN(show_ip_bgp_l2vpn_evpn
,
1191 show_ip_bgp_l2vpn_evpn_cmd
,
1192 "show [ip] bgp l2vpn evpn [json]",
1193 SHOW_STR IP_STR BGP_STR L2VPN_HELP_STR EVPN_HELP_STR JSON_STR
)
1195 return bgp_show_ethernet_vpn(vty
, NULL
, bgp_show_type_normal
, NULL
, 0,
1196 use_json(argc
, argv
));
1199 DEFUN(show_ip_bgp_l2vpn_evpn_rd
,
1200 show_ip_bgp_l2vpn_evpn_rd_cmd
,
1201 "show [ip] bgp l2vpn evpn rd ASN:NN_OR_IP-ADDRESS:NN [json]",
1207 "Display information for a route distinguisher\n"
1208 "VPN Route Distinguisher\n" JSON_STR
)
1210 int idx_ext_community
= 0;
1212 struct prefix_rd prd
;
1214 argv_find(argv
, argc
, "ASN:NN_OR_IP-ADDRESS:NN", &idx_ext_community
);
1216 ret
= str2prefix_rd(argv
[idx_ext_community
]->arg
, &prd
);
1218 vty_out(vty
, "%% Malformed Route Distinguisher\n");
1221 return bgp_show_ethernet_vpn(vty
, &prd
, bgp_show_type_normal
, NULL
, 0,
1222 use_json(argc
, argv
));
1225 DEFUN(show_ip_bgp_l2vpn_evpn_all_tags
,
1226 show_ip_bgp_l2vpn_evpn_all_tags_cmd
,
1227 "show [ip] bgp l2vpn evpn all tags",
1233 "Display information about all EVPN NLRIs\n"
1234 "Display BGP tags for prefixes\n")
1236 return bgp_show_ethernet_vpn(vty
, NULL
, bgp_show_type_normal
, NULL
, 1,
1240 DEFUN(show_ip_bgp_l2vpn_evpn_rd_tags
,
1241 show_ip_bgp_l2vpn_evpn_rd_tags_cmd
,
1242 "show [ip] bgp l2vpn evpn rd ASN:NN_OR_IP-ADDRESS:NN tags",
1248 "Display information for a route distinguisher\n"
1249 "VPN Route Distinguisher\n" "Display BGP tags for prefixes\n")
1251 int idx_ext_community
= 0;
1253 struct prefix_rd prd
;
1255 argv_find(argv
, argc
, "ASN:NN_OR_IP-ADDRESS:NN", &idx_ext_community
);
1257 ret
= str2prefix_rd(argv
[idx_ext_community
]->arg
, &prd
);
1259 vty_out(vty
, "%% Malformed Route Distinguisher\n");
1262 return bgp_show_ethernet_vpn(vty
, &prd
, bgp_show_type_normal
, NULL
, 1,
1266 DEFUN(show_ip_bgp_l2vpn_evpn_all_neighbor_routes
,
1267 show_ip_bgp_l2vpn_evpn_all_neighbor_routes_cmd
,
1268 "show [ip] bgp l2vpn evpn all neighbors A.B.C.D routes [json]",
1274 "Display information about all EVPN NLRIs\n"
1275 "Detailed information on TCP and BGP neighbor connections\n"
1276 "Neighbor to display information about\n"
1277 "Display routes learned from neighbor\n" JSON_STR
)
1283 bool uj
= use_json(argc
, argv
);
1285 argv_find(argv
, argc
, "A.B.C.D", &idx_ipv4
);
1287 ret
= str2sockunion(argv
[idx_ipv4
]->arg
, &su
);
1290 json_object
*json_no
= NULL
;
1291 json_no
= json_object_new_object();
1292 json_object_string_add(json_no
, "warning",
1293 "Malformed address");
1294 vty_out(vty
, "%s\n",
1295 json_object_to_json_string(json_no
));
1296 json_object_free(json_no
);
1298 vty_out(vty
, "Malformed address: %s\n",
1299 argv
[idx_ipv4
]->arg
);
1303 peer
= peer_lookup(NULL
, &su
);
1304 if (!peer
|| !peer
->afc
[AFI_L2VPN
][SAFI_EVPN
]) {
1306 json_object
*json_no
= NULL
;
1307 json_no
= json_object_new_object();
1308 json_object_string_add(
1310 "No such neighbor or address family");
1311 vty_out(vty
, "%s\n",
1312 json_object_to_json_string(json_no
));
1313 json_object_free(json_no
);
1315 vty_out(vty
, "%% No such neighbor or address family\n");
1319 return bgp_show_ethernet_vpn(vty
, NULL
, bgp_show_type_neighbor
, &su
, 0,
1323 DEFUN(show_ip_bgp_l2vpn_evpn_rd_neighbor_routes
,
1324 show_ip_bgp_l2vpn_evpn_rd_neighbor_routes_cmd
,
1325 "show [ip] bgp l2vpn evpn rd ASN:NN_OR_IP-ADDRESS:NN neighbors A.B.C.D routes [json]",
1331 "Display information for a route distinguisher\n"
1332 "VPN Route Distinguisher\n"
1333 "Detailed information on TCP and BGP neighbor connections\n"
1334 "Neighbor to display information about\n"
1335 "Display routes learned from neighbor\n" JSON_STR
)
1337 int idx_ext_community
= 0;
1342 struct prefix_rd prd
;
1343 bool uj
= use_json(argc
, argv
);
1345 argv_find(argv
, argc
, "ASN:NN_OR_IP-ADDRESS:NN", &idx_ext_community
);
1346 argv_find(argv
, argc
, "A.B.C.D", &idx_ipv4
);
1348 ret
= str2prefix_rd(argv
[idx_ext_community
]->arg
, &prd
);
1351 json_object
*json_no
= NULL
;
1352 json_no
= json_object_new_object();
1353 json_object_string_add(json_no
, "warning",
1354 "Malformed Route Distinguisher");
1355 vty_out(vty
, "%s\n",
1356 json_object_to_json_string(json_no
));
1357 json_object_free(json_no
);
1359 vty_out(vty
, "%% Malformed Route Distinguisher\n");
1363 ret
= str2sockunion(argv
[idx_ipv4
]->arg
, &su
);
1366 json_object
*json_no
= NULL
;
1367 json_no
= json_object_new_object();
1368 json_object_string_add(json_no
, "warning",
1369 "Malformed address");
1370 vty_out(vty
, "%s\n",
1371 json_object_to_json_string(json_no
));
1372 json_object_free(json_no
);
1374 vty_out(vty
, "Malformed address: %s\n",
1375 argv
[idx_ext_community
]->arg
);
1379 peer
= peer_lookup(NULL
, &su
);
1380 if (!peer
|| !peer
->afc
[AFI_L2VPN
][SAFI_EVPN
]) {
1382 json_object
*json_no
= NULL
;
1383 json_no
= json_object_new_object();
1384 json_object_string_add(
1386 "No such neighbor or address family");
1387 vty_out(vty
, "%s\n",
1388 json_object_to_json_string(json_no
));
1389 json_object_free(json_no
);
1391 vty_out(vty
, "%% No such neighbor or address family\n");
1395 return bgp_show_ethernet_vpn(vty
, &prd
, bgp_show_type_neighbor
, &su
, 0,
1399 DEFUN(show_ip_bgp_l2vpn_evpn_all_neighbor_advertised_routes
,
1400 show_ip_bgp_l2vpn_evpn_all_neighbor_advertised_routes_cmd
,
1401 "show [ip] bgp l2vpn evpn all neighbors A.B.C.D advertised-routes [json]",
1407 "Display information about all EVPN NLRIs\n"
1408 "Detailed information on TCP and BGP neighbor connections\n"
1409 "Neighbor to display information about\n"
1410 "Display the routes advertised to a BGP neighbor\n" JSON_STR
)
1416 bool uj
= use_json(argc
, argv
);
1418 argv_find(argv
, argc
, "A.B.C.D", &idx_ipv4
);
1420 ret
= str2sockunion(argv
[idx_ipv4
]->arg
, &su
);
1423 json_object
*json_no
= NULL
;
1424 json_no
= json_object_new_object();
1425 json_object_string_add(json_no
, "warning",
1426 "Malformed address");
1427 vty_out(vty
, "%s\n",
1428 json_object_to_json_string(json_no
));
1429 json_object_free(json_no
);
1431 vty_out(vty
, "Malformed address: %s\n",
1432 argv
[idx_ipv4
]->arg
);
1435 peer
= peer_lookup(NULL
, &su
);
1436 if (!peer
|| !peer
->afc
[AFI_L2VPN
][SAFI_EVPN
]) {
1438 json_object
*json_no
= NULL
;
1439 json_no
= json_object_new_object();
1440 json_object_string_add(
1442 "No such neighbor or address family");
1443 vty_out(vty
, "%s\n",
1444 json_object_to_json_string(json_no
));
1445 json_object_free(json_no
);
1447 vty_out(vty
, "%% No such neighbor or address family\n");
1451 return show_adj_route_vpn(vty
, peer
, NULL
, AFI_L2VPN
, SAFI_EVPN
, uj
);
1454 DEFUN(show_ip_bgp_l2vpn_evpn_rd_neighbor_advertised_routes
,
1455 show_ip_bgp_l2vpn_evpn_rd_neighbor_advertised_routes_cmd
,
1456 "show [ip] bgp l2vpn evpn rd ASN:NN_OR_IP-ADDRESS:NN neighbors A.B.C.D advertised-routes [json]",
1462 "Display information for a route distinguisher\n"
1463 "VPN Route Distinguisher\n"
1464 "Detailed information on TCP and BGP neighbor connections\n"
1465 "Neighbor to display information about\n"
1466 "Display the routes advertised to a BGP neighbor\n" JSON_STR
)
1468 int idx_ext_community
= 0;
1472 struct prefix_rd prd
;
1474 bool uj
= use_json(argc
, argv
);
1476 argv_find(argv
, argc
, "ASN:NN_OR_IP-ADDRESS:NN", &idx_ext_community
);
1477 argv_find(argv
, argc
, "A.B.C.D", &idx_ipv4
);
1479 ret
= str2sockunion(argv
[idx_ipv4
]->arg
, &su
);
1482 json_object
*json_no
= NULL
;
1483 json_no
= json_object_new_object();
1484 json_object_string_add(json_no
, "warning",
1485 "Malformed address");
1486 vty_out(vty
, "%s\n",
1487 json_object_to_json_string(json_no
));
1488 json_object_free(json_no
);
1490 vty_out(vty
, "Malformed address: %s\n",
1491 argv
[idx_ext_community
]->arg
);
1494 peer
= peer_lookup(NULL
, &su
);
1495 if (!peer
|| !peer
->afc
[AFI_L2VPN
][SAFI_EVPN
]) {
1497 json_object
*json_no
= NULL
;
1498 json_no
= json_object_new_object();
1499 json_object_string_add(
1501 "No such neighbor or address family");
1502 vty_out(vty
, "%s\n",
1503 json_object_to_json_string(json_no
));
1504 json_object_free(json_no
);
1506 vty_out(vty
, "%% No such neighbor or address family\n");
1510 ret
= str2prefix_rd(argv
[idx_ext_community
]->arg
, &prd
);
1513 json_object
*json_no
= NULL
;
1514 json_no
= json_object_new_object();
1515 json_object_string_add(json_no
, "warning",
1516 "Malformed Route Distinguisher");
1517 vty_out(vty
, "%s\n",
1518 json_object_to_json_string(json_no
));
1519 json_object_free(json_no
);
1521 vty_out(vty
, "%% Malformed Route Distinguisher\n");
1525 return show_adj_route_vpn(vty
, peer
, &prd
, AFI_L2VPN
, SAFI_EVPN
, uj
);
1528 DEFUN(show_ip_bgp_l2vpn_evpn_all_overlay
,
1529 show_ip_bgp_l2vpn_evpn_all_overlay_cmd
,
1530 "show [ip] bgp l2vpn evpn all overlay",
1536 "Display information about all EVPN NLRIs\n"
1537 "Display BGP Overlay Information for prefixes\n")
1539 return bgp_show_ethernet_vpn(vty
, NULL
, bgp_show_type_normal
, NULL
,
1540 SHOW_DISPLAY_OVERLAY
,
1541 use_json(argc
, argv
));
1544 DEFUN(show_ip_bgp_evpn_rd_overlay
,
1545 show_ip_bgp_evpn_rd_overlay_cmd
,
1546 "show [ip] bgp l2vpn evpn rd ASN:NN_OR_IP-ADDRESS:NN overlay",
1552 "Display information for a route distinguisher\n"
1553 "VPN Route Distinguisher\n"
1554 "Display BGP Overlay Information for prefixes\n")
1556 int idx_ext_community
= 0;
1558 struct prefix_rd prd
;
1560 argv_find(argv
, argc
, "ASN:NN_OR_IP-ADDRESS:NN", &idx_ext_community
);
1562 ret
= str2prefix_rd(argv
[idx_ext_community
]->arg
, &prd
);
1564 vty_out(vty
, "%% Malformed Route Distinguisher\n");
1567 return bgp_show_ethernet_vpn(vty
, &prd
, bgp_show_type_normal
, NULL
,
1568 SHOW_DISPLAY_OVERLAY
,
1569 use_json(argc
, argv
));
1572 /* For testing purpose, static route of MPLS-VPN. */
1573 DEFUN(evpnrt5_network
,
1574 evpnrt5_network_cmd
,
1575 "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]",
1576 "Specify a network to announce via BGP\n"
1579 "Specify Route Distinguisher\n"
1580 "VPN Route Distinguisher\n"
1582 "Ethernet Tag Value\n"
1585 "Ethernet Segment Identifier\n"
1586 "ESI value ( 00:11:22:33:44:55:66:77:88:99 format) \n"
1588 "Gateway IP ( A.B.C.D )\n"
1589 "Gateway IPv6 ( X:X::X:X )\n"
1590 "Router Mac Ext Comm\n"
1591 "Router Mac address Value ( aa:bb:cc:dd:ee:ff format)\n"
1592 "Route-map to modify the attributes\n"
1593 "Name of the route map\n")
1595 int idx_ipv4_prefixlen
= 1;
1596 int idx_route_distinguisher
= 3;
1601 int idx_routermac
= 13;
1603 return bgp_static_set_safi(
1604 AFI_L2VPN
, SAFI_EVPN
, vty
, argv
[idx_ipv4_prefixlen
]->arg
,
1605 argv
[idx_route_distinguisher
]->arg
, argv
[idx_label
]->arg
, NULL
,
1606 BGP_EVPN_IP_PREFIX_ROUTE
, argv
[idx_esi
]->arg
,
1607 argv
[idx_gwip
]->arg
, argv
[idx_ethtag
]->arg
,
1608 argv
[idx_routermac
]->arg
);
1611 /* For testing purpose, static route of MPLS-VPN. */
1612 DEFUN(no_evpnrt5_network
,
1613 no_evpnrt5_network_cmd
,
1614 "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>",
1616 "Specify a network to announce via BGP\n"
1619 "Specify Route Distinguisher\n"
1620 "VPN Route Distinguisher\n"
1622 "Ethernet Tag Value\n"
1625 "Ethernet Segment Identifier\n"
1626 "ESI value ( 00:11:22:33:44:55:66:77:88:99 format) \n"
1627 "Gateway IP\n" "Gateway IP ( A.B.C.D )\n" "Gateway IPv6 ( X:X::X:X )\n")
1629 int idx_ipv4_prefixlen
= 2;
1630 int idx_ext_community
= 4;
1635 return bgp_static_unset_safi(
1636 AFI_L2VPN
, SAFI_EVPN
, vty
, argv
[idx_ipv4_prefixlen
]->arg
,
1637 argv
[idx_ext_community
]->arg
, argv
[idx_label
]->arg
,
1638 BGP_EVPN_IP_PREFIX_ROUTE
, argv
[idx_esi
]->arg
,
1639 argv
[idx_gwip
]->arg
, argv
[idx_ethtag
]->arg
);
1642 static void evpn_import_rt_delete_auto(struct bgp
*bgp
, struct bgpevpn
*vpn
)
1644 evpn_rt_delete_auto(bgp
, vpn
->vni
, vpn
->import_rtl
);
1647 static void evpn_export_rt_delete_auto(struct bgp
*bgp
, struct bgpevpn
*vpn
)
1649 evpn_rt_delete_auto(bgp
, vpn
->vni
, vpn
->export_rtl
);
1653 * Configure the Import RTs for a VNI (vty handler). Caller expected to
1654 * check that this is a change.
1656 static void evpn_configure_import_rt(struct bgp
*bgp
, struct bgpevpn
*vpn
,
1657 struct ecommunity
*ecomadd
)
1659 /* If the VNI is "live", we need to uninstall routes using the current
1660 * import RT(s) first before we update the import RT, and subsequently
1663 if (is_vni_live(vpn
))
1664 bgp_evpn_uninstall_routes(bgp
, vpn
);
1666 /* Cleanup the RT to VNI mapping and get rid of existing import RT. */
1667 bgp_evpn_unmap_vni_from_its_rts(bgp
, vpn
);
1669 /* If the auto route-target is in use we must remove it */
1670 evpn_import_rt_delete_auto(bgp
, vpn
);
1672 /* Add new RT and rebuild the RT to VNI mapping */
1673 listnode_add_sort(vpn
->import_rtl
, ecomadd
);
1675 SET_FLAG(vpn
->flags
, VNI_FLAG_IMPRT_CFGD
);
1676 bgp_evpn_map_vni_to_its_rts(bgp
, vpn
);
1678 /* Install routes that match new import RT */
1679 if (is_vni_live(vpn
))
1680 bgp_evpn_install_routes(bgp
, vpn
);
1684 * Unconfigure Import RT(s) for a VNI (vty handler).
1686 static void evpn_unconfigure_import_rt(struct bgp
*bgp
, struct bgpevpn
*vpn
,
1687 struct ecommunity
*ecomdel
)
1689 struct listnode
*node
, *nnode
, *node_to_del
;
1690 struct ecommunity
*ecom
;
1692 /* Along the lines of "configure" except we have to reset to the
1695 if (is_vni_live(vpn
))
1696 bgp_evpn_uninstall_routes(bgp
, vpn
);
1698 /* Cleanup the RT to VNI mapping and get rid of existing import RT. */
1699 bgp_evpn_unmap_vni_from_its_rts(bgp
, vpn
);
1701 /* Delete all import RTs */
1702 if (ecomdel
== NULL
) {
1703 for (ALL_LIST_ELEMENTS(vpn
->import_rtl
, node
, nnode
, ecom
))
1704 ecommunity_free(&ecom
);
1706 list_delete_all_node(vpn
->import_rtl
);
1709 /* Delete a specific import RT */
1713 for (ALL_LIST_ELEMENTS(vpn
->import_rtl
, node
, nnode
, ecom
)) {
1714 if (ecommunity_match(ecom
, ecomdel
)) {
1715 ecommunity_free(&ecom
);
1722 list_delete_node(vpn
->import_rtl
, node_to_del
);
1725 assert(vpn
->import_rtl
);
1726 /* Reset to auto RT - this also rebuilds the RT to VNI mapping */
1727 if (list_isempty(vpn
->import_rtl
)) {
1728 UNSET_FLAG(vpn
->flags
, VNI_FLAG_IMPRT_CFGD
);
1729 bgp_evpn_derive_auto_rt_import(bgp
, vpn
);
1731 /* Rebuild the RT to VNI mapping */
1733 bgp_evpn_map_vni_to_its_rts(bgp
, vpn
);
1735 /* Install routes that match new import RT */
1736 if (is_vni_live(vpn
))
1737 bgp_evpn_install_routes(bgp
, vpn
);
1741 * Configure the Export RT for a VNI (vty handler). Caller expected to
1742 * check that this is a change. Note that only a single export RT is
1743 * allowed for a VNI and any change to configuration is implemented as
1744 * a "replace" (similar to other configuration).
1746 static void evpn_configure_export_rt(struct bgp
*bgp
, struct bgpevpn
*vpn
,
1747 struct ecommunity
*ecomadd
)
1749 /* If the auto route-target is in use we must remove it */
1750 evpn_export_rt_delete_auto(bgp
, vpn
);
1752 listnode_add_sort(vpn
->export_rtl
, ecomadd
);
1753 SET_FLAG(vpn
->flags
, VNI_FLAG_EXPRT_CFGD
);
1755 if (is_vni_live(vpn
))
1756 bgp_evpn_handle_export_rt_change(bgp
, vpn
);
1760 * Unconfigure the Export RT for a VNI (vty handler)
1762 static void evpn_unconfigure_export_rt(struct bgp
*bgp
, struct bgpevpn
*vpn
,
1763 struct ecommunity
*ecomdel
)
1765 struct listnode
*node
, *nnode
, *node_to_del
;
1766 struct ecommunity
*ecom
;
1768 /* Delete all export RTs */
1769 if (ecomdel
== NULL
) {
1770 /* Reset to default and process all routes. */
1771 for (ALL_LIST_ELEMENTS(vpn
->export_rtl
, node
, nnode
, ecom
))
1772 ecommunity_free(&ecom
);
1774 list_delete_all_node(vpn
->export_rtl
);
1777 /* Delete a specific export RT */
1781 for (ALL_LIST_ELEMENTS(vpn
->export_rtl
, node
, nnode
, ecom
)) {
1782 if (ecommunity_match(ecom
, ecomdel
)) {
1783 ecommunity_free(&ecom
);
1790 list_delete_node(vpn
->export_rtl
, node_to_del
);
1793 assert(vpn
->export_rtl
);
1794 if (list_isempty(vpn
->export_rtl
)) {
1795 UNSET_FLAG(vpn
->flags
, VNI_FLAG_EXPRT_CFGD
);
1796 bgp_evpn_derive_auto_rt_export(bgp
, vpn
);
1799 if (is_vni_live(vpn
))
1800 bgp_evpn_handle_export_rt_change(bgp
, vpn
);
1804 * Configure RD for VRF
1806 static void evpn_configure_vrf_rd(struct bgp
*bgp_vrf
, struct prefix_rd
*rd
)
1808 /* If we have already advertise type-5 routes with a diffrent RD, we
1809 * have to delete and withdraw them firs
1811 bgp_evpn_handle_vrf_rd_change(bgp_vrf
, 1);
1814 memcpy(&bgp_vrf
->vrf_prd
, rd
, sizeof(struct prefix_rd
));
1815 SET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_RD_CFGD
);
1817 /* We have a new RD for VRF.
1818 * Advertise all type-5 routes again with the new RD
1820 bgp_evpn_handle_vrf_rd_change(bgp_vrf
, 0);
1824 * Unconfigure RD for VRF
1826 static void evpn_unconfigure_vrf_rd(struct bgp
*bgp_vrf
)
1828 /* If we have already advertise type-5 routes with a diffrent RD, we
1829 * have to delete and withdraw them firs
1831 bgp_evpn_handle_vrf_rd_change(bgp_vrf
, 1);
1833 /* fall back to default RD */
1834 bgp_evpn_derive_auto_rd_for_vrf(bgp_vrf
);
1835 UNSET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_RD_CFGD
);
1837 /* We have a new RD for VRF.
1838 * Advertise all type-5 routes again with the new RD
1840 bgp_evpn_handle_vrf_rd_change(bgp_vrf
, 0);
1844 * Configure RD for a VNI (vty handler)
1846 static void evpn_configure_rd(struct bgp
*bgp
, struct bgpevpn
*vpn
,
1847 struct prefix_rd
*rd
)
1849 /* If the VNI is "live", we need to delete and withdraw this VNI's
1850 * local routes with the prior RD first. Then, after updating RD,
1851 * need to re-advertise.
1853 if (is_vni_live(vpn
))
1854 bgp_evpn_handle_rd_change(bgp
, vpn
, 1);
1857 memcpy(&vpn
->prd
, rd
, sizeof(struct prefix_rd
));
1858 SET_FLAG(vpn
->flags
, VNI_FLAG_RD_CFGD
);
1860 if (is_vni_live(vpn
))
1861 bgp_evpn_handle_rd_change(bgp
, vpn
, 0);
1865 * Unconfigure RD for a VNI (vty handler)
1867 static void evpn_unconfigure_rd(struct bgp
*bgp
, struct bgpevpn
*vpn
)
1869 /* If the VNI is "live", we need to delete and withdraw this VNI's
1870 * local routes with the prior RD first. Then, after resetting RD
1871 * to automatic value, need to re-advertise.
1873 if (is_vni_live(vpn
))
1874 bgp_evpn_handle_rd_change(bgp
, vpn
, 1);
1876 /* reset RD to default */
1877 bgp_evpn_derive_auto_rd(bgp
, vpn
);
1879 if (is_vni_live(vpn
))
1880 bgp_evpn_handle_rd_change(bgp
, vpn
, 0);
1884 * Create VNI, if not already present (VTY handler). Mark as configured.
1886 static struct bgpevpn
*evpn_create_update_vni(struct bgp
*bgp
, vni_t vni
)
1888 struct bgpevpn
*vpn
;
1893 vpn
= bgp_evpn_lookup_vni(bgp
, vni
);
1895 /* Check if this L2VNI is already configured as L3VNI */
1896 if (bgp_evpn_lookup_l3vni_l2vni_table(vni
)) {
1899 "%u: Failed to create L2VNI %u, it is configured as L3VNI",
1904 /* tenant vrf will be updated when we get local_vni_add from
1907 vpn
= bgp_evpn_new(bgp
, vni
, bgp
->router_id
, 0);
1911 "%u: Failed to allocate VNI entry for VNI %u - at Config",
1917 /* Mark as configured. */
1918 SET_FLAG(vpn
->flags
, VNI_FLAG_CFGD
);
1923 * Delete VNI. If VNI does not exist in the system (i.e., just
1924 * configuration), all that is needed is to free it. Otherwise,
1925 * any parameters configured for the VNI need to be reset (with
1926 * appropriate action) and the VNI marked as unconfigured; the
1927 * VNI will continue to exist, purely as a "learnt" entity.
1929 static int evpn_delete_vni(struct bgp
*bgp
, struct bgpevpn
*vpn
)
1931 assert(bgp
->vnihash
);
1933 if (!is_vni_live(vpn
)) {
1934 bgp_evpn_free(bgp
, vpn
);
1938 /* We need to take the unconfigure action for each parameter of this VNI
1939 * that is configured. Some optimization is possible, but not worth the
1940 * additional code for an operation that should be pretty rare.
1942 UNSET_FLAG(vpn
->flags
, VNI_FLAG_CFGD
);
1944 /* First, deal with the export side - RD and export RT changes. */
1945 if (is_rd_configured(vpn
))
1946 evpn_unconfigure_rd(bgp
, vpn
);
1947 if (is_export_rt_configured(vpn
))
1948 evpn_unconfigure_export_rt(bgp
, vpn
, NULL
);
1950 /* Next, deal with the import side. */
1951 if (is_import_rt_configured(vpn
))
1952 evpn_unconfigure_import_rt(bgp
, vpn
, NULL
);
1958 * Display import RT mapping to VRFs (vty handler)
1959 * bgp_def: default bgp instance
1961 static void evpn_show_vrf_import_rts(struct vty
*vty
, struct bgp
*bgp_def
,
1969 hash_iterate(bgp_def
->vrf_import_rt_hash
,
1970 (void (*)(struct hash_backet
*,
1971 void *))show_vrf_import_rt_entry
,
1976 * Display import RT mapping to VNIs (vty handler)
1978 static void evpn_show_import_rts(struct vty
*vty
, struct bgp
*bgp
,
1987 bgp
->import_rt_hash
,
1988 (void (*)(struct hash_backet
*, void *))show_import_rt_entry
,
1993 * Display EVPN routes for all VNIs - vty handler.
1995 static void evpn_show_routes_vni_all(struct vty
*vty
, struct bgp
*bgp
,
1996 struct in_addr vtep_ip
, json_object
*json
)
1999 struct vni_walk_ctx wctx
;
2001 num_vnis
= hashcount(bgp
->vnihash
);
2004 memset(&wctx
, 0, sizeof(struct vni_walk_ctx
));
2007 wctx
.vtep_ip
= vtep_ip
;
2009 hash_iterate(bgp
->vnihash
, (void (*)(struct hash_backet
*,
2010 void *))show_vni_routes_hash
,
2015 * Display EVPN routes for a VNI -- for specific type-3 route (vty handler).
2017 static void evpn_show_route_vni_multicast(struct vty
*vty
, struct bgp
*bgp
,
2018 vni_t vni
, struct in_addr orig_ip
,
2021 struct bgpevpn
*vpn
;
2022 struct prefix_evpn p
;
2023 struct bgp_node
*rn
;
2024 struct bgp_path_info
*pi
;
2025 uint32_t path_cnt
= 0;
2028 json_object
*json_paths
= NULL
;
2034 vpn
= bgp_evpn_lookup_vni(bgp
, vni
);
2036 vty_out(vty
, "VNI not found\n");
2040 /* See if route exists. */
2041 build_evpn_type3_prefix(&p
, orig_ip
);
2042 rn
= bgp_node_lookup(vpn
->route_table
, (struct prefix
*)&p
);
2043 if (!rn
|| !bgp_node_has_bgp_path_info_data(rn
)) {
2045 vty_out(vty
, "%% Network not in table\n");
2050 json_paths
= json_object_new_array();
2052 /* Prefix and num paths displayed once per prefix. */
2053 route_vty_out_detail_header(vty
, bgp
, rn
, NULL
, afi
, safi
, json
);
2055 /* Display each path for this prefix. */
2056 for (pi
= bgp_node_get_bgp_path_info(rn
); pi
; pi
= pi
->next
) {
2057 json_object
*json_path
= NULL
;
2060 json_path
= json_object_new_array();
2062 route_vty_out_detail(vty
, bgp
, &rn
->p
, pi
, afi
, safi
,
2066 json_object_array_add(json_paths
, json_path
);
2073 json_object_object_add(json
, "paths", json_paths
);
2075 json_object_int_add(json
, "numPaths", path_cnt
);
2077 vty_out(vty
, "\nDisplayed %u paths for requested prefix\n",
2083 * Display EVPN routes for a VNI -- for specific MAC and/or IP (vty handler).
2084 * By definition, only matching type-2 route will be displayed.
2086 static void evpn_show_route_vni_macip(struct vty
*vty
, struct bgp
*bgp
,
2087 vni_t vni
, struct ethaddr
*mac
,
2088 struct ipaddr
*ip
, json_object
*json
)
2090 struct bgpevpn
*vpn
;
2091 struct prefix_evpn p
;
2092 struct bgp_node
*rn
;
2093 struct bgp_path_info
*pi
;
2094 uint32_t path_cnt
= 0;
2097 json_object
*json_paths
= NULL
;
2103 vpn
= bgp_evpn_lookup_vni(bgp
, vni
);
2106 vty_out(vty
, "VNI not found\n");
2110 /* See if route exists. Look for both non-sticky and sticky. */
2111 build_evpn_type2_prefix(&p
, mac
, ip
);
2112 rn
= bgp_node_lookup(vpn
->route_table
, (struct prefix
*)&p
);
2113 if (!rn
|| !bgp_node_has_bgp_path_info_data(rn
)) {
2115 vty_out(vty
, "%% Network not in table\n");
2120 json_paths
= json_object_new_array();
2122 /* Prefix and num paths displayed once per prefix. */
2123 route_vty_out_detail_header(vty
, bgp
, rn
, NULL
, afi
, safi
, json
);
2125 /* Display each path for this prefix. */
2126 for (pi
= bgp_node_get_bgp_path_info(rn
); pi
; pi
= pi
->next
) {
2127 json_object
*json_path
= NULL
;
2130 json_path
= json_object_new_array();
2132 route_vty_out_detail(vty
, bgp
, &rn
->p
, pi
, afi
, safi
,
2136 json_object_array_add(json_paths
, json_path
);
2143 json_object_object_add(json
, "paths", json_paths
);
2145 json_object_int_add(json
, "numPaths", path_cnt
);
2147 vty_out(vty
, "\nDisplayed %u paths for requested prefix\n",
2152 /* Disaplay EVPN routes for a ESI - VTY handler */
2153 static void evpn_show_routes_esi(struct vty
*vty
, struct bgp
*bgp
,
2154 esi_t
*esi
, json_object
*json
)
2156 struct evpnes
*es
= NULL
;
2159 es
= bgp_evpn_lookup_es(bgp
, esi
);
2162 vty_out(vty
, "ESI not found\n");
2166 show_esi_routes(bgp
, es
, vty
, json
);
2170 * Display EVPN routes for a VNI - vty handler.
2171 * If 'type' is non-zero, only routes matching that type are shown.
2172 * If the vtep_ip is non zero, only routes behind that vtep are shown
2174 static void evpn_show_routes_vni(struct vty
*vty
, struct bgp
*bgp
, vni_t vni
,
2175 int type
, struct in_addr vtep_ip
,
2178 struct bgpevpn
*vpn
;
2181 vpn
= bgp_evpn_lookup_vni(bgp
, vni
);
2184 vty_out(vty
, "VNI not found\n");
2188 /* Walk this VNI's route table and display appropriate routes. */
2189 show_vni_routes(bgp
, vpn
, type
, vty
, vtep_ip
, json
);
2193 * Display BGP EVPN routing table -- for specific RD and MAC and/or
2194 * IP (vty handler). By definition, only matching type-2 route will be
2197 static void evpn_show_route_rd_macip(struct vty
*vty
, struct bgp
*bgp
,
2198 struct prefix_rd
*prd
, struct ethaddr
*mac
,
2199 struct ipaddr
*ip
, json_object
*json
)
2201 struct prefix_evpn p
;
2202 struct bgp_node
*rn
;
2203 struct bgp_path_info
*pi
;
2206 uint32_t path_cnt
= 0;
2207 json_object
*json_paths
= NULL
;
2208 char prefix_str
[BUFSIZ
];
2213 /* See if route exists. Look for both non-sticky and sticky. */
2214 build_evpn_type2_prefix(&p
, mac
, ip
);
2215 rn
= bgp_afi_node_lookup(bgp
->rib
[afi
][safi
], afi
, safi
,
2216 (struct prefix
*)&p
, prd
);
2217 if (!rn
|| !bgp_node_has_bgp_path_info_data(rn
)) {
2219 vty_out(vty
, "%% Network not in table\n");
2223 bgp_evpn_route2str((struct prefix_evpn
*)&p
, prefix_str
,
2224 sizeof(prefix_str
));
2226 /* Prefix and num paths displayed once per prefix. */
2227 route_vty_out_detail_header(vty
, bgp
, rn
, prd
, afi
, safi
, json
);
2230 json_paths
= json_object_new_array();
2232 /* Display each path for this prefix. */
2233 for (pi
= bgp_node_get_bgp_path_info(rn
); pi
; pi
= pi
->next
) {
2234 json_object
*json_path
= NULL
;
2237 json_path
= json_object_new_array();
2239 route_vty_out_detail(vty
, bgp
, &rn
->p
, pi
, afi
, safi
,
2243 json_object_array_add(json_paths
, json_path
);
2248 if (json
&& path_cnt
) {
2250 json_object_object_add(json
, prefix_str
, json_paths
);
2251 json_object_int_add(json
, "numPaths", path_cnt
);
2253 vty_out(vty
, "\nDisplayed %u paths for requested prefix\n",
2259 * Display BGP EVPN routing table -- for specific RD (vty handler)
2260 * If 'type' is non-zero, only routes matching that type are shown.
2262 static void evpn_show_route_rd(struct vty
*vty
, struct bgp
*bgp
,
2263 struct prefix_rd
*prd
, int type
,
2266 struct bgp_node
*rd_rn
;
2267 struct bgp_table
*table
;
2268 struct bgp_node
*rn
;
2269 struct bgp_path_info
*pi
;
2273 uint32_t prefix_cnt
, path_cnt
;
2274 char rd_str
[RD_ADDRSTRLEN
];
2275 json_object
*json_rd
= NULL
;
2276 int add_rd_to_json
= 0;
2280 prefix_cnt
= path_cnt
= 0;
2282 prefix_rd2str((struct prefix_rd
*)prd
, rd_str
, sizeof(rd_str
));
2284 rd_rn
= bgp_node_lookup(bgp
->rib
[afi
][safi
], (struct prefix
*)prd
);
2288 table
= bgp_node_get_bgp_table_info(rd_rn
);
2293 json_rd
= json_object_new_object();
2294 json_object_string_add(json_rd
, "rd", rd_str
);
2297 /* Display all prefixes with this RD. */
2298 for (rn
= bgp_table_top(table
); rn
; rn
= bgp_route_next(rn
)) {
2299 struct prefix_evpn
*evp
= (struct prefix_evpn
*)&rn
->p
;
2300 json_object
*json_prefix
= NULL
;
2301 json_object
*json_paths
= NULL
;
2302 char prefix_str
[BUFSIZ
];
2303 int add_prefix_to_json
= 0;
2305 bgp_evpn_route2str((struct prefix_evpn
*)&rn
->p
, prefix_str
,
2306 sizeof(prefix_str
));
2308 if (type
&& evp
->prefix
.route_type
!= type
)
2312 json_prefix
= json_object_new_object();
2314 pi
= bgp_node_get_bgp_path_info(rn
);
2316 /* RD header and legend - once overall. */
2317 if (rd_header
&& !json
) {
2319 "EVPN type-2 prefix: [2]:[EthTag]:[MAClen]:[MAC]\n");
2321 "EVPN type-3 prefix: [3]:[EthTag]:[IPlen]:[OrigIP]\n");
2323 "EVPN type-5 prefix: [5]:[EthTag]:[IPlen]:[IP]\n\n");
2327 /* Prefix and num paths displayed once per prefix. */
2328 route_vty_out_detail_header(vty
, bgp
, rn
, prd
, afi
,
2335 json_paths
= json_object_new_array();
2337 /* Display each path for this prefix. */
2338 for (; pi
; pi
= pi
->next
) {
2339 json_object
*json_path
= NULL
;
2342 json_path
= json_object_new_array();
2344 route_vty_out_detail(vty
, bgp
, &rn
->p
, pi
, afi
, safi
,
2348 json_object_array_add(json_paths
, json_path
);
2351 add_prefix_to_json
= 1;
2355 if (json
&& add_prefix_to_json
) {
2356 json_object_object_add(json_prefix
, "paths",
2358 json_object_object_add(json_rd
, prefix_str
,
2363 if (json
&& add_rd_to_json
)
2364 json_object_object_add(json
, rd_str
, json_rd
);
2367 json_object_int_add(json
, "numPrefix", prefix_cnt
);
2368 json_object_int_add(json
, "numPaths", path_cnt
);
2370 if (prefix_cnt
== 0)
2371 vty_out(vty
, "No prefixes exist with this RD%s\n",
2372 type
? " (of requested type)" : "");
2375 "\nDisplayed %u prefixes (%u paths) with this RD%s\n",
2376 prefix_cnt
, path_cnt
,
2377 type
? " (of requested type)" : "");
2382 * Display BGP EVPN routing table - all routes (vty handler).
2383 * If 'type' is non-zero, only routes matching that type are shown.
2385 static void evpn_show_all_routes(struct vty
*vty
, struct bgp
*bgp
, int type
,
2388 struct bgp_node
*rd_rn
;
2389 struct bgp_table
*table
;
2390 struct bgp_node
*rn
;
2391 struct bgp_path_info
*pi
;
2396 uint32_t prefix_cnt
, path_cnt
;
2400 prefix_cnt
= path_cnt
= 0;
2402 /* EVPN routing table is a 2-level table with the first level being
2405 for (rd_rn
= bgp_table_top(bgp
->rib
[afi
][safi
]); rd_rn
;
2406 rd_rn
= bgp_route_next(rd_rn
)) {
2407 char rd_str
[RD_ADDRSTRLEN
];
2408 json_object
*json_rd
= NULL
; /* contains routes for an RD */
2409 int add_rd_to_json
= 0;
2412 table
= bgp_node_get_bgp_table_info(rd_rn
);
2416 tbl_ver
= table
->version
;
2417 prefix_rd2str((struct prefix_rd
*)&rd_rn
->p
, rd_str
,
2421 json_rd
= json_object_new_object();
2422 json_object_string_add(json_rd
, "rd", rd_str
);
2427 /* Display all prefixes for an RD */
2428 for (rn
= bgp_table_top(table
); rn
; rn
= bgp_route_next(rn
)) {
2429 json_object
*json_prefix
=
2430 NULL
; /* contains prefix under a RD */
2431 json_object
*json_paths
=
2432 NULL
; /* array of paths under a prefix*/
2433 struct prefix_evpn
*evp
= (struct prefix_evpn
*)&rn
->p
;
2434 char prefix_str
[BUFSIZ
];
2435 int add_prefix_to_json
= 0;
2437 bgp_evpn_route2str((struct prefix_evpn
*)&rn
->p
,
2438 prefix_str
, sizeof(prefix_str
));
2440 if (type
&& evp
->prefix
.route_type
!= type
)
2443 pi
= bgp_node_get_bgp_path_info(rn
);
2445 /* Overall header/legend displayed once. */
2447 bgp_evpn_show_route_header(vty
, bgp
,
2453 /* RD header - per RD. */
2455 bgp_evpn_show_route_rd_header(
2464 json_prefix
= json_object_new_object();
2465 json_paths
= json_object_new_array();
2466 json_object_string_add(json_prefix
, "prefix",
2468 json_object_int_add(json_prefix
, "prefixLen",
2472 /* For EVPN, the prefix is displayed for each path (to
2474 * with code that already exists).
2476 for (; pi
; pi
= pi
->next
) {
2477 json_object
*json_path
= NULL
;
2479 add_prefix_to_json
= 1;
2483 json_path
= json_object_new_array();
2485 route_vty_out(vty
, &rn
->p
, pi
, 0, SAFI_EVPN
,
2489 json_object_array_add(json_paths
,
2493 if (json
&& add_prefix_to_json
) {
2494 json_object_object_add(json_prefix
, "paths",
2496 json_object_object_add(json_rd
, prefix_str
,
2501 if (json
&& add_rd_to_json
)
2502 json_object_object_add(json
, rd_str
, json_rd
);
2506 json_object_int_add(json
, "numPrefix", prefix_cnt
);
2507 json_object_int_add(json
, "numPaths", path_cnt
);
2509 if (prefix_cnt
== 0) {
2510 vty_out(vty
, "No EVPN prefixes %sexist\n",
2511 type
? "(of requested type) " : "");
2513 vty_out(vty
, "\nDisplayed %u prefixes (%u paths)%s\n",
2514 prefix_cnt
, path_cnt
,
2515 type
? " (of requested type)" : "");
2520 /* Display specific ES */
2521 static void evpn_show_es(struct vty
*vty
, struct bgp
*bgp
, esi_t
*esi
,
2524 struct evpnes
*es
= NULL
;
2526 es
= bgp_evpn_lookup_es(bgp
, esi
);
2528 display_es(vty
, es
, json
);
2531 vty_out(vty
, "{}\n");
2533 vty_out(vty
, "ESI not found\n");
2539 /* Display all ESs */
2540 static void evpn_show_all_es(struct vty
*vty
, struct bgp
*bgp
,
2546 vty_out(vty
, "%-30s %-6s %-21s %-15s %-6s\n",
2547 "ESI", "Type", "RD", "Originator-IP", "#VTEPs");
2552 hash_iterate(bgp
->esihash
,
2553 (void (*)(struct hash_backet
*, void *))show_es_entry
,
2558 * Display specified VNI (vty handler)
2560 static void evpn_show_vni(struct vty
*vty
, struct bgp
*bgp
, vni_t vni
,
2564 struct bgpevpn
*vpn
;
2566 vpn
= bgp_evpn_lookup_vni(bgp
, vni
);
2569 display_vni(vty
, vpn
, json
);
2571 struct bgp
*bgp_temp
;
2572 struct listnode
*node
= NULL
;
2574 for (ALL_LIST_ELEMENTS_RO(bm
->bgp
, node
, bgp_temp
)) {
2575 if (bgp_temp
->l3vni
== vni
) {
2577 display_l3vni(vty
, bgp_temp
, json
);
2584 vty_out(vty
, "{}\n");
2586 vty_out(vty
, "VNI not found\n");
2593 * Display a VNI (upon user query).
2595 static void evpn_show_all_vnis(struct vty
*vty
, struct bgp
*bgp
,
2599 struct bgp
*bgp_temp
= NULL
;
2600 struct listnode
*node
;
2604 vty_out(vty
, "Flags: * - Kernel\n");
2605 vty_out(vty
, " %-10s %-4s %-21s %-25s %-25s %-37s\n", "VNI",
2606 "Type", "RD", "Import RT", "Export RT", "Tenant VRF");
2609 /* print all L2 VNIS */
2612 hash_iterate(bgp
->vnihash
,
2613 (void (*)(struct hash_backet
*, void *))show_vni_entry
,
2616 /* print all L3 VNIs */
2617 for (ALL_LIST_ELEMENTS_RO(bm
->bgp
, node
, bgp_temp
))
2618 show_l3vni_entry(vty
, bgp_temp
, json
);
2622 * evpn - enable advertisement of default g/w
2624 static void evpn_set_advertise_default_gw(struct bgp
*bgp
, struct bgpevpn
*vpn
)
2627 if (bgp
->advertise_gw_macip
)
2630 bgp
->advertise_gw_macip
= 1;
2631 bgp_zebra_advertise_gw_macip(bgp
, bgp
->advertise_gw_macip
, 0);
2633 if (vpn
->advertise_gw_macip
)
2636 vpn
->advertise_gw_macip
= 1;
2637 bgp_zebra_advertise_gw_macip(bgp
, vpn
->advertise_gw_macip
,
2644 * evpn - disable advertisement of default g/w
2646 static void evpn_unset_advertise_default_gw(struct bgp
*bgp
,
2647 struct bgpevpn
*vpn
)
2650 if (!bgp
->advertise_gw_macip
)
2653 bgp
->advertise_gw_macip
= 0;
2654 bgp_zebra_advertise_gw_macip(bgp
, bgp
->advertise_gw_macip
, 0);
2656 if (!vpn
->advertise_gw_macip
)
2659 vpn
->advertise_gw_macip
= 0;
2660 bgp_zebra_advertise_gw_macip(bgp
, vpn
->advertise_gw_macip
,
2667 * evpn - enable advertisement of default g/w
2669 static void evpn_process_default_originate_cmd(struct bgp
*bgp_vrf
,
2672 struct prefix ip_prefix
;
2673 safi_t safi
= SAFI_UNICAST
; /* ipv4/ipv6 unicast */
2675 /* form the default prefix 0.0.0.0/0 */
2676 memset(&ip_prefix
, 0, sizeof(struct prefix
));
2677 ip_prefix
.family
= afi2family(afi
);
2678 ip_prefix
.prefixlen
= 0;
2681 /* bail if we are already advertising default route */
2682 if (evpn_default_originate_set(bgp_vrf
, afi
, safi
))
2686 SET_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
2687 BGP_L2VPN_EVPN_DEFAULT_ORIGINATE_IPV4
);
2688 else if (afi
== AFI_IP6
)
2689 SET_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
2690 BGP_L2VPN_EVPN_DEFAULT_ORIGINATE_IPV6
);
2691 bgp_evpn_advertise_type5_route(bgp_vrf
, &ip_prefix
,
2694 /* bail out if we havent advertised the default route */
2695 if (!evpn_default_originate_set(bgp_vrf
, afi
, safi
))
2698 UNSET_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
2699 BGP_L2VPN_EVPN_DEFAULT_ORIGINATE_IPV4
);
2700 else if (afi
== AFI_IP6
)
2701 UNSET_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
2702 BGP_L2VPN_EVPN_DEFAULT_ORIGINATE_IPV6
);
2703 bgp_evpn_withdraw_type5_route(bgp_vrf
, &ip_prefix
,
2709 * evpn - enable advertisement of default g/w
2711 static void evpn_set_advertise_subnet(struct bgp
*bgp
,
2712 struct bgpevpn
*vpn
)
2714 if (vpn
->advertise_subnet
)
2717 vpn
->advertise_subnet
= 1;
2718 bgp_zebra_advertise_subnet(bgp
, vpn
->advertise_subnet
, vpn
->vni
);
2722 * evpn - disable advertisement of default g/w
2724 static void evpn_unset_advertise_subnet(struct bgp
*bgp
, struct bgpevpn
*vpn
)
2726 if (!vpn
->advertise_subnet
)
2729 vpn
->advertise_subnet
= 0;
2730 bgp_zebra_advertise_subnet(bgp
, vpn
->advertise_subnet
, vpn
->vni
);
2734 * EVPN (VNI advertisement) enabled. Register with zebra.
2736 static void evpn_set_advertise_all_vni(struct bgp
*bgp
)
2738 bgp
->advertise_all_vni
= 1;
2739 bgp_zebra_advertise_all_vni(bgp
, bgp
->advertise_all_vni
);
2743 * EVPN (VNI advertisement) disabled. De-register with zebra. Cleanup VNI
2744 * cache, EVPN routes (delete and withdraw from peers).
2746 static void evpn_unset_advertise_all_vni(struct bgp
*bgp
)
2748 bgp
->advertise_all_vni
= 0;
2749 bgp_zebra_advertise_all_vni(bgp
, bgp
->advertise_all_vni
);
2750 bgp_evpn_cleanup_on_disable(bgp
);
2754 * EVPN - use RFC8365 to auto-derive RT
2756 static void evpn_set_advertise_autort_rfc8365(struct bgp
*bgp
)
2758 bgp
->advertise_autort_rfc8365
= 1;
2759 bgp_evpn_handle_autort_change(bgp
);
2763 * EVPN - don't use RFC8365 to auto-derive RT
2765 static void evpn_unset_advertise_autort_rfc8365(struct bgp
*bgp
)
2767 bgp
->advertise_autort_rfc8365
= 0;
2768 bgp_evpn_handle_autort_change(bgp
);
2771 static void write_vni_config(struct vty
*vty
, struct bgpevpn
*vpn
)
2773 char buf1
[RD_ADDRSTRLEN
];
2775 struct listnode
*node
, *nnode
;
2776 struct ecommunity
*ecom
;
2778 if (is_vni_configured(vpn
)) {
2779 vty_out(vty
, " vni %d\n", vpn
->vni
);
2780 if (is_rd_configured(vpn
))
2781 vty_out(vty
, " rd %s\n",
2782 prefix_rd2str(&vpn
->prd
, buf1
, sizeof(buf1
)));
2784 if (is_import_rt_configured(vpn
)) {
2785 for (ALL_LIST_ELEMENTS(vpn
->import_rtl
, node
, nnode
,
2787 ecom_str
= ecommunity_ecom2str(
2788 ecom
, ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
2789 vty_out(vty
, " route-target import %s\n",
2791 XFREE(MTYPE_ECOMMUNITY_STR
, ecom_str
);
2795 if (is_export_rt_configured(vpn
)) {
2796 for (ALL_LIST_ELEMENTS(vpn
->export_rtl
, node
, nnode
,
2798 ecom_str
= ecommunity_ecom2str(
2799 ecom
, ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
2800 vty_out(vty
, " route-target export %s\n",
2802 XFREE(MTYPE_ECOMMUNITY_STR
, ecom_str
);
2806 if (vpn
->advertise_gw_macip
)
2807 vty_out(vty
, " advertise-default-gw\n");
2809 if (vpn
->advertise_subnet
)
2810 vty_out(vty
, " advertise-subnet\n");
2812 vty_out(vty
, " exit-vni\n");
2816 #ifndef VTYSH_EXTRACT_PL
2817 #include "bgpd/bgp_evpn_vty_clippy.c"
2820 DEFPY(bgp_evpn_flood_control
,
2821 bgp_evpn_flood_control_cmd
,
2822 "[no$no] flooding <disable$disable|head-end-replication$her>",
2824 "Specify handling for BUM packets\n"
2825 "Do not flood any BUM packets\n"
2826 "Flood BUM packets using head-end replication\n")
2828 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
2829 enum vxlan_flood_control flood_ctrl
;
2835 flood_ctrl
= VXLAN_FLOOD_DISABLED
;
2837 flood_ctrl
= VXLAN_FLOOD_HEAD_END_REPL
;
2841 if (bgp
->vxlan_flood_ctrl
== flood_ctrl
)
2844 bgp
->vxlan_flood_ctrl
= flood_ctrl
;
2845 bgp_evpn_flood_control_change(bgp
);
2850 DEFUN (bgp_evpn_advertise_default_gw_vni
,
2851 bgp_evpn_advertise_default_gw_vni_cmd
,
2852 "advertise-default-gw",
2853 "Advertise default g/w mac-ip routes in EVPN for a VNI\n")
2855 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
2856 VTY_DECLVAR_CONTEXT_SUB(bgpevpn
, vpn
);
2861 evpn_set_advertise_default_gw(bgp
, vpn
);
2866 DEFUN (no_bgp_evpn_advertise_default_vni_gw
,
2867 no_bgp_evpn_advertise_default_gw_vni_cmd
,
2868 "no advertise-default-gw",
2870 "Withdraw default g/w mac-ip routes from EVPN for a VNI\n")
2872 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
2873 VTY_DECLVAR_CONTEXT_SUB(bgpevpn
, vpn
);
2878 evpn_unset_advertise_default_gw(bgp
, vpn
);
2884 DEFUN (bgp_evpn_advertise_default_gw
,
2885 bgp_evpn_advertise_default_gw_cmd
,
2886 "advertise-default-gw",
2887 "Advertise All default g/w mac-ip routes in EVPN\n")
2889 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
2894 evpn_set_advertise_default_gw(bgp
, NULL
);
2899 DEFUN (no_bgp_evpn_advertise_default_gw
,
2900 no_bgp_evpn_advertise_default_gw_cmd
,
2901 "no advertise-default-gw",
2903 "Withdraw All default g/w mac-ip routes from EVPN\n")
2905 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
2910 evpn_unset_advertise_default_gw(bgp
, NULL
);
2915 DEFUN (bgp_evpn_advertise_all_vni
,
2916 bgp_evpn_advertise_all_vni_cmd
,
2917 "advertise-all-vni",
2918 "Advertise All local VNIs\n")
2920 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
2924 evpn_set_advertise_all_vni(bgp
);
2928 DEFUN (no_bgp_evpn_advertise_all_vni
,
2929 no_bgp_evpn_advertise_all_vni_cmd
,
2930 "no advertise-all-vni",
2932 "Advertise All local VNIs\n")
2934 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
2938 evpn_unset_advertise_all_vni(bgp
);
2942 DEFUN (bgp_evpn_advertise_autort_rfc8365
,
2943 bgp_evpn_advertise_autort_rfc8365_cmd
,
2944 "autort rfc8365-compatible",
2945 "Auto-derivation of RT\n"
2946 "Auto-derivation of RT using RFC8365\n")
2948 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
2952 evpn_set_advertise_autort_rfc8365(bgp
);
2956 DEFUN (no_bgp_evpn_advertise_autort_rfc8365
,
2957 no_bgp_evpn_advertise_autort_rfc8365_cmd
,
2958 "no autort rfc8365-compatible",
2960 "Auto-derivation of RT\n"
2961 "Auto-derivation of RT using RFC8365\n")
2963 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
2967 evpn_unset_advertise_autort_rfc8365(bgp
);
2971 DEFUN (bgp_evpn_default_originate
,
2972 bgp_evpn_default_originate_cmd
,
2973 "default-originate <ipv4 | ipv6>",
2974 "originate a default route\n"
2975 "ipv4 address family\n"
2976 "ipv6 address family\n")
2980 struct bgp
*bgp_vrf
= VTY_GET_CONTEXT(bgp
);
2984 argv_find_and_parse_afi(argv
, argc
, &idx_afi
, &afi
);
2985 evpn_process_default_originate_cmd(bgp_vrf
, afi
, 1);
2989 DEFUN (no_bgp_evpn_default_originate
,
2990 no_bgp_evpn_default_originate_cmd
,
2991 "no default-originate <ipv4 | ipv6>",
2993 "withdraw a default route\n"
2994 "ipv4 address family\n"
2995 "ipv6 address family\n")
2999 struct bgp
*bgp_vrf
= VTY_GET_CONTEXT(bgp
);
3003 argv_find_and_parse_afi(argv
, argc
, &idx_afi
, &afi
);
3004 evpn_process_default_originate_cmd(bgp_vrf
, afi
, 0);
3008 DEFUN_HIDDEN (bgp_evpn_advertise_vni_subnet
,
3009 bgp_evpn_advertise_vni_subnet_cmd
,
3011 "Advertise the subnet corresponding to VNI\n")
3013 struct bgp
*bgp_vrf
= NULL
;
3014 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
3015 VTY_DECLVAR_CONTEXT_SUB(bgpevpn
, vpn
);
3020 bgp_vrf
= bgp_lookup_by_vrf_id(vpn
->tenant_vrf_id
);
3024 evpn_set_advertise_subnet(bgp
, vpn
);
3028 DEFUN_HIDDEN (no_bgp_evpn_advertise_vni_subnet
,
3029 no_bgp_evpn_advertise_vni_subnet_cmd
,
3030 "no advertise-subnet",
3032 "Advertise All local VNIs\n")
3034 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
3035 VTY_DECLVAR_CONTEXT_SUB(bgpevpn
, vpn
);
3040 evpn_unset_advertise_subnet(bgp
, vpn
);
3044 DEFUN (bgp_evpn_advertise_type5
,
3045 bgp_evpn_advertise_type5_cmd
,
3046 "advertise " BGP_AFI_CMD_STR
"" BGP_SAFI_CMD_STR
" [route-map WORD]",
3047 "Advertise prefix routes\n"
3050 "route-map for filtering specific routes\n"
3051 "Name of the route map\n")
3053 struct bgp
*bgp_vrf
= VTY_GET_CONTEXT(bgp
); /* bgp vrf instance */
3060 int rmap_changed
= 0;
3062 argv_find_and_parse_afi(argv
, argc
, &idx_afi
, &afi
);
3063 argv_find_and_parse_safi(argv
, argc
, &idx_safi
, &safi
);
3064 ret
= argv_find(argv
, argc
, "route-map", &idx_rmap
);
3066 if (!bgp_vrf
->adv_cmd_rmap
[afi
][safi
].name
)
3068 else if (strcmp(argv
[idx_rmap
+ 1]->arg
,
3069 bgp_vrf
->adv_cmd_rmap
[afi
][safi
].name
)
3072 } else if (bgp_vrf
->adv_cmd_rmap
[afi
][safi
].name
) {
3076 if (!(afi
== AFI_IP
|| afi
== AFI_IP6
)) {
3078 "%%only ipv4 or ipv6 address families are supported");
3082 if (safi
!= SAFI_UNICAST
) {
3084 "%%only ipv4 unicast or ipv6 unicast are supported");
3088 if (afi
== AFI_IP
) {
3090 /* if we are already advertising ipv4 prefix as type-5
3093 if (!rmap_changed
&&
3094 CHECK_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
3095 BGP_L2VPN_EVPN_ADVERTISE_IPV4_UNICAST
))
3097 SET_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
3098 BGP_L2VPN_EVPN_ADVERTISE_IPV4_UNICAST
);
3101 /* if we are already advertising ipv6 prefix as type-5
3104 if (!rmap_changed
&&
3105 CHECK_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
3106 BGP_L2VPN_EVPN_ADVERTISE_IPV6_UNICAST
))
3108 SET_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
3109 BGP_L2VPN_EVPN_ADVERTISE_IPV6_UNICAST
);
3113 bgp_evpn_withdraw_type5_routes(bgp_vrf
, afi
, safi
);
3114 if (bgp_vrf
->adv_cmd_rmap
[afi
][safi
].name
) {
3115 XFREE(MTYPE_ROUTE_MAP_NAME
,
3116 bgp_vrf
->adv_cmd_rmap
[afi
][safi
].name
);
3117 bgp_vrf
->adv_cmd_rmap
[afi
][safi
].name
= NULL
;
3118 bgp_vrf
->adv_cmd_rmap
[afi
][safi
].map
= NULL
;
3122 /* set the route-map for advertise command */
3123 if (ret
&& argv
[idx_rmap
+ 1]->arg
) {
3124 bgp_vrf
->adv_cmd_rmap
[afi
][safi
].name
=
3125 XSTRDUP(MTYPE_ROUTE_MAP_NAME
, argv
[idx_rmap
+ 1]->arg
);
3126 bgp_vrf
->adv_cmd_rmap
[afi
][safi
].map
=
3127 route_map_lookup_by_name(argv
[idx_rmap
+ 1]->arg
);
3130 /* advertise type-5 routes */
3131 bgp_evpn_advertise_type5_routes(bgp_vrf
, afi
, safi
);
3135 DEFUN (no_bgp_evpn_advertise_type5
,
3136 no_bgp_evpn_advertise_type5_cmd
,
3137 "no advertise " BGP_AFI_CMD_STR
"" BGP_SAFI_CMD_STR
,
3139 "Advertise prefix routes\n"
3143 struct bgp
*bgp_vrf
= VTY_GET_CONTEXT(bgp
); /* bgp vrf instance */
3149 argv_find_and_parse_afi(argv
, argc
, &idx_afi
, &afi
);
3150 argv_find_and_parse_safi(argv
, argc
, &idx_safi
, &safi
);
3152 if (!(afi
== AFI_IP
|| afi
== AFI_IP6
)) {
3154 "%%only ipv4 or ipv6 address families are supported");
3158 if (safi
!= SAFI_UNICAST
) {
3160 "%%only ipv4 unicast or ipv6 unicast are supported");
3164 if (afi
== AFI_IP
) {
3166 /* if we are not advertising ipv4 prefix as type-5
3169 if (CHECK_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
3170 BGP_L2VPN_EVPN_ADVERTISE_IPV4_UNICAST
)) {
3171 bgp_evpn_withdraw_type5_routes(bgp_vrf
, afi
, safi
);
3172 UNSET_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
3173 BGP_L2VPN_EVPN_ADVERTISE_IPV4_UNICAST
);
3177 /* if we are not advertising ipv6 prefix as type-5
3180 if (CHECK_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
3181 BGP_L2VPN_EVPN_ADVERTISE_IPV6_UNICAST
)) {
3182 bgp_evpn_withdraw_type5_routes(bgp_vrf
, afi
, safi
);
3183 UNSET_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
3184 BGP_L2VPN_EVPN_ADVERTISE_IPV6_UNICAST
);
3188 /* clear the route-map information for advertise ipv4/ipv6 unicast */
3189 if (bgp_vrf
->adv_cmd_rmap
[afi
][safi
].name
) {
3190 XFREE(MTYPE_ROUTE_MAP_NAME
,
3191 bgp_vrf
->adv_cmd_rmap
[afi
][safi
].name
);
3192 bgp_vrf
->adv_cmd_rmap
[afi
][safi
].name
= NULL
;
3193 bgp_vrf
->adv_cmd_rmap
[afi
][safi
].map
= NULL
;
3200 * Display VNI information - for all or a specific VNI
3202 DEFUN(show_bgp_l2vpn_evpn_vni
,
3203 show_bgp_l2vpn_evpn_vni_cmd
,
3204 "show bgp l2vpn evpn vni [" CMD_VNI_RANGE
"] [json]",
3213 struct bgp
*bgp_def
;
3217 json_object
*json
= NULL
;
3218 uint32_t num_l2vnis
= 0;
3219 uint32_t num_l3vnis
= 0;
3220 uint32_t num_vnis
= 0;
3221 struct listnode
*node
= NULL
;
3222 struct bgp
*bgp_temp
= NULL
;
3224 uj
= use_json(argc
, argv
);
3226 bgp_def
= bgp_get_default();
3230 if (!argv_find(argv
, argc
, "evpn", &idx
))
3234 json
= json_object_new_object();
3236 if ((uj
&& argc
== ((idx
+ 1) + 2)) || (!uj
&& argc
== (idx
+ 1) + 1)) {
3238 num_l2vnis
= hashcount(bgp_def
->vnihash
);
3240 for (ALL_LIST_ELEMENTS_RO(bm
->bgp
, node
, bgp_temp
)) {
3241 if (bgp_temp
->l3vni
)
3244 num_vnis
= num_l2vnis
+ num_l3vnis
;
3246 json_object_string_add(json
, "advertiseGatewayMacip",
3247 bgp_def
->advertise_gw_macip
3250 json_object_string_add(json
, "advertiseAllVnis",
3251 is_evpn_enabled() ? "Enabled"
3253 json_object_string_add(
3255 bgp_def
->vxlan_flood_ctrl
3256 == VXLAN_FLOOD_HEAD_END_REPL
3257 ? "Head-end replication"
3259 json_object_int_add(json
, "numVnis", num_vnis
);
3260 json_object_int_add(json
, "numL2Vnis", num_l2vnis
);
3261 json_object_int_add(json
, "numL3Vnis", num_l3vnis
);
3263 vty_out(vty
, "Advertise Gateway Macip: %s\n",
3264 bgp_def
->advertise_gw_macip
? "Enabled"
3266 vty_out(vty
, "Advertise All VNI flag: %s\n",
3267 is_evpn_enabled() ? "Enabled" : "Disabled");
3268 vty_out(vty
, "BUM flooding: %s\n",
3269 bgp_def
->vxlan_flood_ctrl
3270 == VXLAN_FLOOD_HEAD_END_REPL
3271 ? "Head-end replication"
3273 vty_out(vty
, "Number of L2 VNIs: %u\n", num_l2vnis
);
3274 vty_out(vty
, "Number of L3 VNIs: %u\n", num_l3vnis
);
3276 evpn_show_all_vnis(vty
, bgp_def
, json
);
3280 if (!argv_find(argv
, argc
, "vni", &vni_idx
))
3283 /* Display specific VNI */
3284 vni
= strtoul(argv
[vni_idx
+ 1]->arg
, NULL
, 10);
3285 evpn_show_vni(vty
, bgp_def
, vni
, json
);
3289 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
3290 json
, JSON_C_TO_STRING_PRETTY
));
3291 json_object_free(json
);
3298 DEFUN(show_bgp_l2vpn_evpn_es
,
3299 show_bgp_l2vpn_evpn_es_cmd
,
3300 "show bgp l2vpn evpn es [ESI] [json]",
3305 "ethernet-Segment\n"
3306 "Ethernet-Segment Identifier\n"
3312 json_object
*json
= NULL
;
3313 struct bgp
*bgp
= NULL
;
3315 memset(&esi
, 0, sizeof(esi
));
3316 uj
= use_json(argc
, argv
);
3318 bgp
= bgp_get_default();
3322 if (!argv_find(argv
, argc
, "evpn", &idx
))
3325 if ((uj
&& argc
== ((idx
+ 1) + 2)) ||
3326 (!uj
&& argc
== (idx
+ 1) + 1)) {
3329 evpn_show_all_es(vty
, bgp
, json
);
3332 /* show a specific ES */
3334 /* get the ESI - ESI-ID is at argv[5] */
3335 if (!str_to_esi(argv
[idx
+ 2]->arg
, &esi
)) {
3336 vty_out(vty
, "%% Malformed ESI\n");
3339 evpn_show_es(vty
, bgp
, &esi
, json
);
3343 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
3344 json
, JSON_C_TO_STRING_PRETTY
));
3345 json_object_free(json
);
3352 * Display EVPN neighbor summary.
3354 DEFUN(show_bgp_l2vpn_evpn_summary
,
3355 show_bgp_l2vpn_evpn_summary_cmd
,
3356 "show bgp [vrf VRFNAME] l2vpn evpn summary [json]",
3363 "Summary of BGP neighbor status\n"
3367 bool uj
= use_json(argc
, argv
);
3370 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
3371 vrf
= argv
[++idx_vrf
]->arg
;
3372 return bgp_show_summary_vty(vty
, vrf
, AFI_L2VPN
, SAFI_EVPN
, uj
);
3376 * Display global EVPN routing table.
3378 DEFUN(show_bgp_l2vpn_evpn_route
,
3379 show_bgp_l2vpn_evpn_route_cmd
,
3380 "show bgp l2vpn evpn route [type <macip|multicast|es|prefix>] [json]",
3385 "EVPN route information\n"
3386 "Specify Route type\n"
3387 "MAC-IP (Type-2) route\n"
3388 "Multicast (Type-3) route\n"
3389 "Ethernet Segment (type-4) route \n"
3390 "Prefix (type-5 )route\n"
3397 json_object
*json
= NULL
;
3399 uj
= use_json(argc
, argv
);
3401 bgp
= bgp_get_default();
3406 json
= json_object_new_object();
3409 if (argv_find(argv
, argc
, "type", &type_idx
)) {
3410 /* Specific type is requested */
3411 if (strncmp(argv
[type_idx
+ 1]->arg
, "ma", 2) == 0)
3412 type
= BGP_EVPN_MAC_IP_ROUTE
;
3413 else if (strncmp(argv
[type_idx
+ 1]->arg
, "mu", 2) == 0)
3414 type
= BGP_EVPN_IMET_ROUTE
;
3415 else if (strncmp(argv
[type_idx
+ 1]->arg
, "es", 2) == 0)
3416 type
= BGP_EVPN_ES_ROUTE
;
3417 else if (strncmp(argv
[type_idx
+ 1]->arg
, "pr", 2) == 0)
3418 type
= BGP_EVPN_IP_PREFIX_ROUTE
;
3423 evpn_show_all_routes(vty
, bgp
, type
, json
);
3426 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
3427 json
, JSON_C_TO_STRING_PRETTY
));
3428 json_object_free(json
);
3434 * Display global EVPN routing table for specific RD.
3436 DEFUN(show_bgp_l2vpn_evpn_route_rd
,
3437 show_bgp_l2vpn_evpn_route_rd_cmd
,
3438 "show bgp l2vpn evpn route rd ASN:NN_OR_IP-ADDRESS:NN [type <macip|multicast|es|prefix>] [json]",
3443 "EVPN route information\n"
3444 "Route Distinguisher\n"
3445 "ASN:XX or A.B.C.D:XX\n"
3446 "Specify Route type\n"
3447 "MAC-IP (Type-2) route\n"
3448 "Multicast (Type-3) route\n"
3449 "Ethernet Segment route\n"
3455 struct prefix_rd prd
;
3460 json_object
*json
= NULL
;
3462 bgp
= bgp_get_default();
3466 /* check if we need json output */
3467 uj
= use_json(argc
, argv
);
3469 json
= json_object_new_object();
3472 if (argv_find(argv
, argc
, "rd", &rd_idx
)) {
3473 ret
= str2prefix_rd(argv
[rd_idx
+ 1]->arg
, &prd
);
3476 vty_out(vty
, "%% Malformed Route Distinguisher\n");
3482 if (argv_find(argv
, argc
, "type", &type_idx
)) {
3483 /* Specific type is requested */
3484 if (strncmp(argv
[type_idx
+ 1]->arg
, "ma", 2) == 0)
3485 type
= BGP_EVPN_MAC_IP_ROUTE
;
3486 else if (strncmp(argv
[type_idx
+ 1]->arg
, "mu", 2) == 0)
3487 type
= BGP_EVPN_IMET_ROUTE
;
3488 else if (strncmp(argv
[type_idx
+ 1]->arg
, "pr", 2) == 0)
3489 type
= BGP_EVPN_IP_PREFIX_ROUTE
;
3494 evpn_show_route_rd(vty
, bgp
, &prd
, type
, json
);
3497 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
3498 json
, JSON_C_TO_STRING_PRETTY
));
3499 json_object_free(json
);
3506 * Display global EVPN routing table for specific RD and MACIP.
3508 DEFUN(show_bgp_l2vpn_evpn_route_rd_macip
,
3509 show_bgp_l2vpn_evpn_route_rd_macip_cmd
,
3510 "show bgp l2vpn evpn route rd ASN:NN_OR_IP-ADDRESS:NN mac WORD [ip WORD] [json]",
3515 "EVPN route information\n"
3516 "Route Distinguisher\n"
3517 "ASN:XX or A.B.C.D:XX\n"
3519 "MAC address (e.g., 00:e0:ec:20:12:62)\n"
3521 "IP address (IPv4 or IPv6)\n"
3526 struct prefix_rd prd
;
3533 json_object
*json
= NULL
;
3535 memset(&mac
, 0, sizeof(struct ethaddr
));
3536 memset(&ip
, 0, sizeof(struct ipaddr
));
3538 bgp
= bgp_get_default();
3542 /* check if we need json output */
3543 uj
= use_json(argc
, argv
);
3545 json
= json_object_new_object();
3548 if (argv_find(argv
, argc
, "rd", &rd_idx
)) {
3549 ret
= str2prefix_rd(argv
[rd_idx
+ 1]->arg
, &prd
);
3551 vty_out(vty
, "%% Malformed Route Distinguisher\n");
3557 if (argv_find(argv
, argc
, "mac", &mac_idx
)) {
3558 if (!prefix_str2mac(argv
[mac_idx
+ 1]->arg
, &mac
)) {
3559 vty_out(vty
, "%% Malformed MAC address\n");
3564 /* get the ip if specified */
3565 if (argv_find(argv
, argc
, "ip", &ip_idx
)) {
3566 if (str2ipaddr(argv
[ip_idx
+ 1]->arg
, &ip
) != 0) {
3567 vty_out(vty
, "%% Malformed IP address\n");
3572 evpn_show_route_rd_macip(vty
, bgp
, &prd
, &mac
, &ip
, json
);
3575 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
3576 json
, JSON_C_TO_STRING_PRETTY
));
3577 json_object_free(json
);
3583 /* Display per ESI routing table */
3584 DEFUN(show_bgp_l2vpn_evpn_route_esi
,
3585 show_bgp_l2vpn_evpn_route_esi_cmd
,
3586 "show bgp l2vpn evpn route esi ESI [json]",
3591 "EVPN route information\n"
3592 "Ethernet Segment Identifier\n"
3598 struct bgp
*bgp
= NULL
;
3599 json_object
*json
= NULL
;
3601 memset(&esi
, 0, sizeof(esi
));
3602 bgp
= bgp_get_default();
3606 uj
= use_json(argc
, argv
);
3608 json
= json_object_new_object();
3610 /* get the ESI - ESI-ID is at argv[6] */
3611 if (!str_to_esi(argv
[6]->arg
, &esi
)) {
3612 vty_out(vty
, "%% Malformed ESI\n");
3616 evpn_show_routes_esi(vty
, bgp
, &esi
, json
);
3619 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
3620 json
, JSON_C_TO_STRING_PRETTY
));
3621 json_object_free(json
);
3629 * Display per-VNI EVPN routing table.
3631 DEFUN(show_bgp_l2vpn_evpn_route_vni
, show_bgp_l2vpn_evpn_route_vni_cmd
,
3632 "show bgp l2vpn evpn route vni " CMD_VNI_RANGE
" [<type <macip|multicast> | vtep A.B.C.D>] [json]",
3637 "EVPN route information\n"
3638 "VXLAN Network Identifier\n"
3640 "Specify Route type\n"
3641 "MAC-IP (Type-2) route\n"
3642 "Multicast (Type-3) route\n"
3644 "Remote VTEP IP address\n"
3649 struct in_addr vtep_ip
;
3653 json_object
*json
= NULL
;
3655 bgp
= bgp_get_default();
3659 /* check if we need json output */
3660 uj
= use_json(argc
, argv
);
3662 json
= json_object_new_object();
3664 if (!argv_find(argv
, argc
, "evpn", &idx
))
3669 vni
= strtoul(argv
[idx
+ 3]->arg
, NULL
, 10);
3671 if ((!uj
&& ((argc
== (idx
+ 1 + 5)) && argv
[idx
+ 4]->arg
))
3672 || (uj
&& ((argc
== (idx
+ 1 + 6)) && argv
[idx
+ 4]->arg
))) {
3673 if (strncmp(argv
[idx
+ 4]->arg
, "type", 4) == 0) {
3674 if (strncmp(argv
[idx
+ 5]->arg
, "ma", 2) == 0)
3675 type
= BGP_EVPN_MAC_IP_ROUTE
;
3676 else if (strncmp(argv
[idx
+ 5]->arg
, "mu", 2) == 0)
3677 type
= BGP_EVPN_IMET_ROUTE
;
3680 } else if (strncmp(argv
[idx
+ 4]->arg
, "vtep", 4) == 0) {
3681 if (!inet_aton(argv
[idx
+ 5]->arg
, &vtep_ip
)) {
3682 vty_out(vty
, "%% Malformed VTEP IP address\n");
3689 evpn_show_routes_vni(vty
, bgp
, vni
, type
, vtep_ip
, json
);
3692 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
3693 json
, JSON_C_TO_STRING_PRETTY
));
3694 json_object_free(json
);
3701 * Display per-VNI EVPN routing table for specific MACIP.
3703 DEFUN(show_bgp_l2vpn_evpn_route_vni_macip
,
3704 show_bgp_l2vpn_evpn_route_vni_macip_cmd
,
3705 "show bgp l2vpn evpn route vni " CMD_VNI_RANGE
" mac WORD [ip WORD] [json]",
3710 "EVPN route information\n"
3711 "VXLAN Network Identifier\n"
3714 "MAC address (e.g., 00:e0:ec:20:12:62)\n"
3716 "IP address (IPv4 or IPv6)\n"
3725 json_object
*json
= NULL
;
3727 bgp
= bgp_get_default();
3731 /* check if we need json output */
3732 uj
= use_json(argc
, argv
);
3734 json
= json_object_new_object();
3736 if (!argv_find(argv
, argc
, "evpn", &idx
))
3740 vni
= strtoul(argv
[idx
+ 3]->arg
, NULL
, 10);
3743 if (!prefix_str2mac(argv
[idx
+ 5]->arg
, &mac
)) {
3744 vty_out(vty
, "%% Malformed MAC address\n");
3749 memset(&ip
, 0, sizeof(ip
));
3750 if ((!uj
&& ((argc
== (idx
+ 1 + 7)) && argv
[idx
+ 7]->arg
!= NULL
))
3752 && ((argc
== (idx
+ 1 + 8)) && argv
[idx
+ 7]->arg
!= NULL
))) {
3753 if (str2ipaddr(argv
[idx
+ 7]->arg
, &ip
) != 0) {
3754 vty_out(vty
, "%% Malformed IP address\n");
3759 evpn_show_route_vni_macip(vty
, bgp
, vni
, &mac
, &ip
, json
);
3762 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
3763 json
, JSON_C_TO_STRING_PRETTY
));
3764 json_object_free(json
);
3771 * Display per-VNI EVPN routing table for specific multicast IP (remote VTEP).
3773 DEFUN(show_bgp_l2vpn_evpn_route_vni_multicast
,
3774 show_bgp_l2vpn_evpn_route_vni_multicast_cmd
,
3775 "show bgp l2vpn evpn route vni " CMD_VNI_RANGE
" multicast A.B.C.D [json]",
3780 "EVPN route information\n"
3781 "VXLAN Network Identifier\n"
3783 "Multicast (Type-3) route\n"
3784 "Originating Router IP address\n"
3790 struct in_addr orig_ip
;
3793 json_object
*json
= NULL
;
3795 bgp
= bgp_get_default();
3799 /* check if we need json output */
3800 uj
= use_json(argc
, argv
);
3802 json
= json_object_new_object();
3804 if (!argv_find(argv
, argc
, "evpn", &idx
))
3808 vni
= strtoul(argv
[idx
+ 3]->arg
, NULL
, 10);
3811 ret
= inet_aton(argv
[idx
+ 5]->arg
, &orig_ip
);
3813 vty_out(vty
, "%% Malformed Originating Router IP address\n");
3817 evpn_show_route_vni_multicast(vty
, bgp
, vni
, orig_ip
, json
);
3820 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
3821 json
, JSON_C_TO_STRING_PRETTY
));
3822 json_object_free(json
);
3829 * Display per-VNI EVPN routing table - for all VNIs.
3831 DEFUN(show_bgp_l2vpn_evpn_route_vni_all
,
3832 show_bgp_l2vpn_evpn_route_vni_all_cmd
,
3833 "show bgp l2vpn evpn route vni all [vtep A.B.C.D] [json]",
3838 "EVPN route information\n"
3839 "VXLAN Network Identifier\n"
3842 "Remote VTEP IP address\n"
3846 struct in_addr vtep_ip
;
3849 json_object
*json
= NULL
;
3851 bgp
= bgp_get_default();
3855 /* check if we need json output */
3856 uj
= use_json(argc
, argv
);
3858 json
= json_object_new_object();
3860 if (!argv_find(argv
, argc
, "evpn", &idx
))
3864 if ((!uj
&& (argc
== (idx
+ 1 + 5) && argv
[idx
+ 5]->arg
))
3865 || (uj
&& (argc
== (idx
+ 1 + 6) && argv
[idx
+ 5]->arg
))) {
3866 if (!inet_aton(argv
[idx
+ 5]->arg
, &vtep_ip
)) {
3867 vty_out(vty
, "%% Malformed VTEP IP address\n");
3872 evpn_show_routes_vni_all(vty
, bgp
, vtep_ip
, json
);
3875 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
3876 json
, JSON_C_TO_STRING_PRETTY
));
3877 json_object_free(json
);
3884 * Display EVPN import route-target hash table
3886 DEFUN(show_bgp_l2vpn_evpn_vrf_import_rt
,
3887 show_bgp_l2vpn_evpn_vrf_import_rt_cmd
,
3888 "show bgp l2vpn evpn vrf-import-rt [json]",
3893 "Show vrf import route target\n"
3897 struct bgp
*bgp_def
= NULL
;
3898 json_object
*json
= NULL
;
3900 bgp_def
= bgp_get_default();
3904 uj
= use_json(argc
, argv
);
3906 json
= json_object_new_object();
3908 evpn_show_vrf_import_rts(vty
, bgp_def
, json
);
3911 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
3912 json
, JSON_C_TO_STRING_PRETTY
));
3913 json_object_free(json
);
3920 * Display EVPN import route-target hash table
3922 DEFUN(show_bgp_l2vpn_evpn_import_rt
,
3923 show_bgp_l2vpn_evpn_import_rt_cmd
,
3924 "show bgp l2vpn evpn import-rt [json]",
3929 "Show import route target\n"
3934 json_object
*json
= NULL
;
3936 bgp
= bgp_get_default();
3940 uj
= use_json(argc
, argv
);
3942 json
= json_object_new_object();
3944 evpn_show_import_rts(vty
, bgp
, json
);
3947 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
3948 json
, JSON_C_TO_STRING_PRETTY
));
3949 json_object_free(json
);
3955 DEFUN(test_adv_evpn_type4_route
,
3956 test_adv_evpn_type4_route_cmd
,
3958 "Advertise EVPN ES route\n"
3959 "Ethernet-segment\n"
3960 "Ethernet-Segment Identifier\n")
3965 struct ipaddr vtep_ip
;
3967 bgp
= bgp_get_default();
3969 vty_out(vty
, "%%Default BGP instance not yet created\n");
3973 if (!str_to_esi(argv
[2]->arg
, &esi
)) {
3974 vty_out(vty
, "%%Malformed ESI\n");
3978 vtep_ip
.ipa_type
= IPADDR_V4
;
3979 vtep_ip
.ipaddr_v4
= bgp
->router_id
;
3981 ret
= bgp_evpn_local_es_add(bgp
, &esi
, &vtep_ip
);
3983 vty_out(vty
, "%%Failed to EVPN advertise type-4 route\n");
3989 DEFUN(test_withdraw_evpn_type4_route
,
3990 test_withdraw_evpn_type4_route_cmd
,
3992 "Advertise EVPN ES route\n"
3993 "Ethernet-segment\n"
3994 "Ethernet-Segment Identifier\n")
3999 struct ipaddr vtep_ip
;
4001 bgp
= bgp_get_default();
4003 vty_out(vty
, "%%Default BGP instance not yet created\n");
4007 if (!bgp
->peer_self
) {
4008 vty_out(vty
, "%%BGP instance doesn't have self peer\n");
4012 if (!str_to_esi(argv
[2]->arg
, &esi
)) {
4013 vty_out(vty
, "%%Malformed ESI\n");
4017 vtep_ip
.ipa_type
= IPADDR_V4
;
4018 vtep_ip
.ipaddr_v4
= bgp
->router_id
;
4019 ret
= bgp_evpn_local_es_del(bgp
, &esi
, &vtep_ip
);
4021 vty_out(vty
, "%%Failed to withdraw EVPN type-4 route\n");
4027 ALIAS_HIDDEN(show_bgp_l2vpn_evpn_vni
, show_bgp_evpn_vni_cmd
,
4028 "show bgp evpn vni [" CMD_VNI_RANGE
"]", SHOW_STR BGP_STR EVPN_HELP_STR
4032 ALIAS_HIDDEN(show_bgp_l2vpn_evpn_summary
, show_bgp_evpn_summary_cmd
,
4033 "show bgp evpn summary [json]", SHOW_STR BGP_STR EVPN_HELP_STR
4034 "Summary of BGP neighbor status\n" JSON_STR
)
4036 ALIAS_HIDDEN(show_bgp_l2vpn_evpn_route
, show_bgp_evpn_route_cmd
,
4037 "show bgp evpn route [type <macip|multicast>]",
4038 SHOW_STR BGP_STR EVPN_HELP_STR
4039 "EVPN route information\n"
4040 "Specify Route type\n"
4041 "MAC-IP (Type-2) route\n"
4042 "Multicast (Type-3) route\n")
4045 show_bgp_l2vpn_evpn_route_rd
, show_bgp_evpn_route_rd_cmd
,
4046 "show bgp evpn route rd ASN:NN_OR_IP-ADDRESS:NN [type <macip|multicast>]",
4047 SHOW_STR BGP_STR EVPN_HELP_STR
4048 "EVPN route information\n"
4049 "Route Distinguisher\n"
4050 "ASN:XX or A.B.C.D:XX\n"
4051 "Specify Route type\n"
4052 "MAC-IP (Type-2) route\n"
4053 "Multicast (Type-3) route\n")
4056 show_bgp_l2vpn_evpn_route_rd_macip
, show_bgp_evpn_route_rd_macip_cmd
,
4057 "show bgp evpn route rd ASN:NN_OR_IP-ADDRESS:NN mac WORD [ip WORD]",
4058 SHOW_STR BGP_STR EVPN_HELP_STR
4059 "EVPN route information\n"
4060 "Route Distinguisher\n"
4061 "ASN:XX or A.B.C.D:XX\n"
4063 "MAC address (e.g., 00:e0:ec:20:12:62)\n"
4065 "IP address (IPv4 or IPv6)\n")
4068 show_bgp_l2vpn_evpn_route_vni
, show_bgp_evpn_route_vni_cmd
,
4069 "show bgp evpn route vni " CMD_VNI_RANGE
" [<type <macip|multicast> | vtep A.B.C.D>]",
4070 SHOW_STR BGP_STR EVPN_HELP_STR
4071 "EVPN route information\n"
4072 "VXLAN Network Identifier\n"
4074 "Specify Route type\n"
4075 "MAC-IP (Type-2) route\n"
4076 "Multicast (Type-3) route\n"
4078 "Remote VTEP IP address\n")
4080 ALIAS_HIDDEN(show_bgp_l2vpn_evpn_route_vni_macip
,
4081 show_bgp_evpn_route_vni_macip_cmd
,
4082 "show bgp evpn route vni " CMD_VNI_RANGE
" mac WORD [ip WORD]",
4083 SHOW_STR BGP_STR EVPN_HELP_STR
4084 "EVPN route information\n"
4085 "VXLAN Network Identifier\n"
4088 "MAC address (e.g., 00:e0:ec:20:12:62)\n"
4090 "IP address (IPv4 or IPv6)\n")
4092 ALIAS_HIDDEN(show_bgp_l2vpn_evpn_route_vni_multicast
,
4093 show_bgp_evpn_route_vni_multicast_cmd
,
4094 "show bgp evpn route vni " CMD_VNI_RANGE
" multicast A.B.C.D",
4095 SHOW_STR BGP_STR EVPN_HELP_STR
4096 "EVPN route information\n"
4097 "VXLAN Network Identifier\n"
4099 "Multicast (Type-3) route\n"
4100 "Originating Router IP address\n")
4102 ALIAS_HIDDEN(show_bgp_l2vpn_evpn_route_vni_all
, show_bgp_evpn_route_vni_all_cmd
,
4103 "show bgp evpn route vni all [vtep A.B.C.D]",
4104 SHOW_STR BGP_STR EVPN_HELP_STR
4105 "EVPN route information\n"
4106 "VXLAN Network Identifier\n"
4109 "Remote VTEP IP address\n")
4111 ALIAS_HIDDEN(show_bgp_l2vpn_evpn_import_rt
, show_bgp_evpn_import_rt_cmd
,
4112 "show bgp evpn import-rt",
4113 SHOW_STR BGP_STR EVPN_HELP_STR
"Show import route target\n")
4115 DEFUN_NOSH (bgp_evpn_vni
,
4117 "vni " CMD_VNI_RANGE
,
4118 "VXLAN Network Identifier\n"
4122 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
4123 struct bgpevpn
*vpn
;
4128 vni
= strtoul(argv
[1]->arg
, NULL
, 10);
4130 /* Create VNI, or mark as configured. */
4131 vpn
= evpn_create_update_vni(bgp
, vni
);
4133 vty_out(vty
, "%% Failed to create VNI \n");
4137 VTY_PUSH_CONTEXT_SUB(BGP_EVPN_VNI_NODE
, vpn
);
4141 DEFUN (no_bgp_evpn_vni
,
4142 no_bgp_evpn_vni_cmd
,
4143 "no vni " CMD_VNI_RANGE
,
4145 "VXLAN Network Identifier\n"
4149 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
4150 struct bgpevpn
*vpn
;
4155 vni
= strtoul(argv
[2]->arg
, NULL
, 10);
4157 /* Check if we should disallow. */
4158 vpn
= bgp_evpn_lookup_vni(bgp
, vni
);
4160 vty_out(vty
, "%% Specified VNI does not exist\n");
4163 if (!is_vni_configured(vpn
)) {
4164 vty_out(vty
, "%% Specified VNI is not configured\n");
4168 evpn_delete_vni(bgp
, vpn
);
4172 DEFUN_NOSH (exit_vni
,
4175 "Exit from VNI mode\n")
4177 if (vty
->node
== BGP_EVPN_VNI_NODE
)
4178 vty
->node
= BGP_EVPN_NODE
;
4182 DEFUN (bgp_evpn_vrf_rd
,
4183 bgp_evpn_vrf_rd_cmd
,
4184 "rd ASN:NN_OR_IP-ADDRESS:NN",
4185 "Route Distinguisher\n"
4186 "ASN:XX or A.B.C.D:XX\n")
4189 struct prefix_rd prd
;
4190 struct bgp
*bgp_vrf
= VTY_GET_CONTEXT(bgp
);
4195 ret
= str2prefix_rd(argv
[1]->arg
, &prd
);
4197 vty_out(vty
, "%% Malformed Route Distinguisher\n");
4201 /* If same as existing value, there is nothing more to do. */
4202 if (bgp_evpn_vrf_rd_matches_existing(bgp_vrf
, &prd
))
4205 /* Configure or update the RD. */
4206 evpn_configure_vrf_rd(bgp_vrf
, &prd
);
4210 DEFUN (no_bgp_evpn_vrf_rd
,
4211 no_bgp_evpn_vrf_rd_cmd
,
4212 "no rd ASN:NN_OR_IP-ADDRESS:NN",
4214 "Route Distinguisher\n"
4215 "ASN:XX or A.B.C.D:XX\n")
4218 struct prefix_rd prd
;
4219 struct bgp
*bgp_vrf
= VTY_GET_CONTEXT(bgp
);
4224 ret
= str2prefix_rd(argv
[2]->arg
, &prd
);
4226 vty_out(vty
, "%% Malformed Route Distinguisher\n");
4230 /* Check if we should disallow. */
4231 if (!is_vrf_rd_configured(bgp_vrf
)) {
4232 vty_out(vty
, "%% RD is not configured for this VRF\n");
4236 if (!bgp_evpn_vrf_rd_matches_existing(bgp_vrf
, &prd
)) {
4238 "%% RD specified does not match configuration for this VRF\n");
4242 evpn_unconfigure_vrf_rd(bgp_vrf
);
4246 DEFUN (no_bgp_evpn_vrf_rd_without_val
,
4247 no_bgp_evpn_vrf_rd_without_val_cmd
,
4250 "Route Distinguisher\n")
4252 struct bgp
*bgp_vrf
= VTY_GET_CONTEXT(bgp
);
4257 /* Check if we should disallow. */
4258 if (!is_vrf_rd_configured(bgp_vrf
)) {
4259 vty_out(vty
, "%% RD is not configured for this VRF\n");
4263 evpn_unconfigure_vrf_rd(bgp_vrf
);
4267 DEFUN (bgp_evpn_vni_rd
,
4268 bgp_evpn_vni_rd_cmd
,
4269 "rd ASN:NN_OR_IP-ADDRESS:NN",
4270 "Route Distinguisher\n"
4271 "ASN:XX or A.B.C.D:XX\n")
4273 struct prefix_rd prd
;
4274 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
4275 VTY_DECLVAR_CONTEXT_SUB(bgpevpn
, vpn
);
4281 if (bgp
->vrf_id
!= VRF_DEFAULT
) {
4283 "This command is only supported under Default VRF\n");
4287 ret
= str2prefix_rd(argv
[1]->arg
, &prd
);
4289 vty_out(vty
, "%% Malformed Route Distinguisher\n");
4293 /* If same as existing value, there is nothing more to do. */
4294 if (bgp_evpn_rd_matches_existing(vpn
, &prd
))
4297 /* Configure or update the RD. */
4298 evpn_configure_rd(bgp
, vpn
, &prd
);
4302 DEFUN (no_bgp_evpn_vni_rd
,
4303 no_bgp_evpn_vni_rd_cmd
,
4304 "no rd ASN:NN_OR_IP-ADDRESS:NN",
4306 "Route Distinguisher\n"
4307 "ASN:XX or A.B.C.D:XX\n")
4309 struct prefix_rd prd
;
4310 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
4311 VTY_DECLVAR_CONTEXT_SUB(bgpevpn
, vpn
);
4317 if (bgp
->vrf_id
!= VRF_DEFAULT
) {
4319 "This command is only supported under Default VRF\n");
4323 ret
= str2prefix_rd(argv
[2]->arg
, &prd
);
4325 vty_out(vty
, "%% Malformed Route Distinguisher\n");
4329 /* Check if we should disallow. */
4330 if (!is_rd_configured(vpn
)) {
4331 vty_out(vty
, "%% RD is not configured for this VNI\n");
4335 if (!bgp_evpn_rd_matches_existing(vpn
, &prd
)) {
4337 "%% RD specified does not match configuration for this VNI\n");
4341 evpn_unconfigure_rd(bgp
, vpn
);
4345 DEFUN (no_bgp_evpn_vni_rd_without_val
,
4346 no_bgp_evpn_vni_rd_without_val_cmd
,
4349 "Route Distinguisher\n")
4351 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
4352 VTY_DECLVAR_CONTEXT_SUB(bgpevpn
, vpn
);
4357 if (bgp
->vrf_id
!= VRF_DEFAULT
) {
4359 "This command is only supported under Default VRF\n");
4363 /* Check if we should disallow. */
4364 if (!is_rd_configured(vpn
)) {
4365 vty_out(vty
, "%% RD is not configured for this VNI\n");
4369 evpn_unconfigure_rd(bgp
, vpn
);
4374 * Loop over all extended-communities in the route-target list rtl and
4375 * return 1 if we find ecomtarget
4377 static int bgp_evpn_rt_matches_existing(struct list
*rtl
,
4378 struct ecommunity
*ecomtarget
)
4380 struct listnode
*node
, *nnode
;
4381 struct ecommunity
*ecom
;
4383 for (ALL_LIST_ELEMENTS(rtl
, node
, nnode
, ecom
)) {
4384 if (ecommunity_match(ecom
, ecomtarget
))
4391 /* display L3VNI related info for a VRF instance */
4392 DEFUN (show_bgp_vrf_l3vni_info
,
4393 show_bgp_vrf_l3vni_info_cmd
,
4394 "show bgp vrf VRFNAME vni [json]",
4402 char buf
[ETHER_ADDR_STRLEN
];
4403 char buf1
[INET6_ADDRSTRLEN
];
4405 const char *name
= NULL
;
4406 struct bgp
*bgp
= NULL
;
4407 struct listnode
*node
= NULL
;
4408 struct bgpevpn
*vpn
= NULL
;
4409 struct ecommunity
*ecom
= NULL
;
4410 json_object
*json
= NULL
;
4411 json_object
*json_vnis
= NULL
;
4412 json_object
*json_export_rts
= NULL
;
4413 json_object
*json_import_rts
= NULL
;
4414 bool uj
= use_json(argc
, argv
);
4417 json
= json_object_new_object();
4418 json_vnis
= json_object_new_array();
4419 json_export_rts
= json_object_new_array();
4420 json_import_rts
= json_object_new_array();
4423 name
= argv
[idx_vrf
]->arg
;
4424 bgp
= bgp_lookup_by_name(name
);
4427 vty_out(vty
, "BGP instance for VRF %s not found", name
);
4429 json_object_string_add(json
, "warning",
4430 "BGP instance not found");
4431 vty_out(vty
, "%s\n", json_object_to_json_string(json
));
4432 json_object_free(json
);
4438 vty_out(vty
, "BGP VRF: %s\n", name
);
4439 vty_out(vty
, " Local-Ip: %s\n", inet_ntoa(bgp
->originator_ip
));
4440 vty_out(vty
, " L3-VNI: %u\n", bgp
->l3vni
);
4441 vty_out(vty
, " Rmac: %s\n",
4442 prefix_mac2str(&bgp
->rmac
, buf
, sizeof(buf
)));
4443 vty_out(vty
, " VNI Filter: %s\n",
4444 CHECK_FLAG(bgp
->vrf_flags
,
4445 BGP_VRF_L3VNI_PREFIX_ROUTES_ONLY
)
4446 ? "prefix-routes-only"
4448 vty_out(vty
, " L2-VNI List:\n");
4450 for (ALL_LIST_ELEMENTS_RO(bgp
->l2vnis
, node
, vpn
))
4451 vty_out(vty
, "%u ", vpn
->vni
);
4453 vty_out(vty
, " Export-RTs:\n");
4455 for (ALL_LIST_ELEMENTS_RO(bgp
->vrf_export_rtl
, node
, ecom
))
4456 vty_out(vty
, "%s ", ecommunity_str(ecom
));
4458 vty_out(vty
, " Import-RTs:\n");
4460 for (ALL_LIST_ELEMENTS_RO(bgp
->vrf_import_rtl
, node
, ecom
))
4461 vty_out(vty
, "%s ", ecommunity_str(ecom
));
4463 vty_out(vty
, " RD: %s\n",
4464 prefix_rd2str(&bgp
->vrf_prd
, buf1
, RD_ADDRSTRLEN
));
4466 json_object_string_add(json
, "vrf", name
);
4467 json_object_string_add(json
, "local-ip",
4468 inet_ntoa(bgp
->originator_ip
));
4469 json_object_int_add(json
, "l3vni", bgp
->l3vni
);
4470 json_object_string_add(
4472 prefix_mac2str(&bgp
->rmac
, buf
, sizeof(buf
)));
4473 json_object_string_add(
4475 CHECK_FLAG(bgp
->vrf_flags
,
4476 BGP_VRF_L3VNI_PREFIX_ROUTES_ONLY
)
4477 ? "prefix-routes-only"
4479 /* list of l2vnis */
4480 for (ALL_LIST_ELEMENTS_RO(bgp
->l2vnis
, node
, vpn
))
4481 json_object_array_add(json_vnis
,
4482 json_object_new_int(vpn
->vni
));
4483 json_object_object_add(json
, "l2vnis", json_vnis
);
4486 for (ALL_LIST_ELEMENTS_RO(bgp
->vrf_export_rtl
, node
, ecom
))
4487 json_object_array_add(
4489 json_object_new_string(ecommunity_str(ecom
)));
4490 json_object_object_add(json
, "export-rts", json_export_rts
);
4493 for (ALL_LIST_ELEMENTS_RO(bgp
->vrf_import_rtl
, node
, ecom
))
4494 json_object_array_add(
4496 json_object_new_string(ecommunity_str(ecom
)));
4497 json_object_object_add(json
, "import-rts", json_import_rts
);
4498 json_object_string_add(
4500 prefix_rd2str(&bgp
->vrf_prd
, buf1
, RD_ADDRSTRLEN
));
4504 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4505 json
, JSON_C_TO_STRING_PRETTY
));
4506 json_object_free(json
);
4511 /* import/export rt for l3vni-vrf */
4512 DEFUN (bgp_evpn_vrf_rt
,
4513 bgp_evpn_vrf_rt_cmd
,
4514 "route-target <both|import|export> RT",
4516 "import and export\n"
4519 "Route target (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
4522 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
4523 struct ecommunity
*ecomadd
= NULL
;
4528 if (!strcmp(argv
[1]->arg
, "import"))
4529 rt_type
= RT_TYPE_IMPORT
;
4530 else if (!strcmp(argv
[1]->arg
, "export"))
4531 rt_type
= RT_TYPE_EXPORT
;
4532 else if (!strcmp(argv
[1]->arg
, "both"))
4533 rt_type
= RT_TYPE_BOTH
;
4535 vty_out(vty
, "%% Invalid Route Target type\n");
4539 /* Add/update the import route-target */
4540 if (rt_type
== RT_TYPE_BOTH
|| rt_type
== RT_TYPE_IMPORT
) {
4541 ecomadd
= ecommunity_str2com(argv
[2]->arg
,
4542 ECOMMUNITY_ROUTE_TARGET
, 0);
4544 vty_out(vty
, "%% Malformed Route Target list\n");
4547 ecommunity_str(ecomadd
);
4549 /* Do nothing if we already have this import route-target */
4550 if (!bgp_evpn_rt_matches_existing(bgp
->vrf_import_rtl
, ecomadd
))
4551 bgp_evpn_configure_import_rt_for_vrf(bgp
, ecomadd
);
4554 /* Add/update the export route-target */
4555 if (rt_type
== RT_TYPE_BOTH
|| rt_type
== RT_TYPE_EXPORT
) {
4556 ecomadd
= ecommunity_str2com(argv
[2]->arg
,
4557 ECOMMUNITY_ROUTE_TARGET
, 0);
4559 vty_out(vty
, "%% Malformed Route Target list\n");
4562 ecommunity_str(ecomadd
);
4564 /* Do nothing if we already have this export route-target */
4565 if (!bgp_evpn_rt_matches_existing(bgp
->vrf_export_rtl
, ecomadd
))
4566 bgp_evpn_configure_export_rt_for_vrf(bgp
, ecomadd
);
4572 DEFUN (no_bgp_evpn_vrf_rt
,
4573 no_bgp_evpn_vrf_rt_cmd
,
4574 "no route-target <both|import|export> RT",
4577 "import and export\n"
4580 "ASN:XX or A.B.C.D:XX\n")
4582 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
4583 int rt_type
, found_ecomdel
;
4584 struct ecommunity
*ecomdel
= NULL
;
4589 if (!strcmp(argv
[2]->arg
, "import"))
4590 rt_type
= RT_TYPE_IMPORT
;
4591 else if (!strcmp(argv
[2]->arg
, "export"))
4592 rt_type
= RT_TYPE_EXPORT
;
4593 else if (!strcmp(argv
[2]->arg
, "both"))
4594 rt_type
= RT_TYPE_BOTH
;
4596 vty_out(vty
, "%% Invalid Route Target type\n");
4600 if (rt_type
== RT_TYPE_IMPORT
) {
4601 if (!CHECK_FLAG(bgp
->vrf_flags
, BGP_VRF_IMPORT_RT_CFGD
)) {
4603 "%% Import RT is not configured for this VRF\n");
4606 } else if (rt_type
== RT_TYPE_EXPORT
) {
4607 if (!CHECK_FLAG(bgp
->vrf_flags
, BGP_VRF_EXPORT_RT_CFGD
)) {
4609 "%% Export RT is not configured for this VRF\n");
4612 } else if (rt_type
== RT_TYPE_BOTH
) {
4613 if (!CHECK_FLAG(bgp
->vrf_flags
, BGP_VRF_IMPORT_RT_CFGD
)
4614 && !CHECK_FLAG(bgp
->vrf_flags
, BGP_VRF_EXPORT_RT_CFGD
)) {
4616 "%% Import/Export RT is not configured for this VRF\n");
4621 ecomdel
= ecommunity_str2com(argv
[3]->arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
4623 vty_out(vty
, "%% Malformed Route Target list\n");
4626 ecommunity_str(ecomdel
);
4628 if (rt_type
== RT_TYPE_IMPORT
) {
4629 if (!bgp_evpn_rt_matches_existing(bgp
->vrf_import_rtl
,
4632 "%% RT specified does not match configuration for this VRF\n");
4635 bgp_evpn_unconfigure_import_rt_for_vrf(bgp
, ecomdel
);
4636 } else if (rt_type
== RT_TYPE_EXPORT
) {
4637 if (!bgp_evpn_rt_matches_existing(bgp
->vrf_export_rtl
,
4640 "%% RT specified does not match configuration for this VRF\n");
4643 bgp_evpn_unconfigure_export_rt_for_vrf(bgp
, ecomdel
);
4644 } else if (rt_type
== RT_TYPE_BOTH
) {
4647 if (bgp_evpn_rt_matches_existing(bgp
->vrf_import_rtl
,
4649 bgp_evpn_unconfigure_import_rt_for_vrf(bgp
, ecomdel
);
4653 if (bgp_evpn_rt_matches_existing(bgp
->vrf_export_rtl
,
4655 bgp_evpn_unconfigure_export_rt_for_vrf(bgp
, ecomdel
);
4659 if (!found_ecomdel
) {
4661 "%% RT specified does not match configuration for this VRF\n");
4669 DEFUN (bgp_evpn_vni_rt
,
4670 bgp_evpn_vni_rt_cmd
,
4671 "route-target <both|import|export> RT",
4673 "import and export\n"
4676 "Route target (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n")
4678 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
4679 VTY_DECLVAR_CONTEXT_SUB(bgpevpn
, vpn
);
4681 struct ecommunity
*ecomadd
= NULL
;
4686 if (bgp
->vrf_id
!= VRF_DEFAULT
) {
4688 "This command is only supported under Default VRF\n");
4692 if (!strcmp(argv
[1]->text
, "import"))
4693 rt_type
= RT_TYPE_IMPORT
;
4694 else if (!strcmp(argv
[1]->text
, "export"))
4695 rt_type
= RT_TYPE_EXPORT
;
4696 else if (!strcmp(argv
[1]->text
, "both"))
4697 rt_type
= RT_TYPE_BOTH
;
4699 vty_out(vty
, "%% Invalid Route Target type\n");
4703 /* Add/update the import route-target */
4704 if (rt_type
== RT_TYPE_BOTH
|| rt_type
== RT_TYPE_IMPORT
) {
4705 ecomadd
= ecommunity_str2com(argv
[2]->arg
,
4706 ECOMMUNITY_ROUTE_TARGET
, 0);
4708 vty_out(vty
, "%% Malformed Route Target list\n");
4711 ecommunity_str(ecomadd
);
4713 /* Do nothing if we already have this import route-target */
4714 if (!bgp_evpn_rt_matches_existing(vpn
->import_rtl
, ecomadd
))
4715 evpn_configure_import_rt(bgp
, vpn
, ecomadd
);
4718 /* Add/update the export route-target */
4719 if (rt_type
== RT_TYPE_BOTH
|| rt_type
== RT_TYPE_EXPORT
) {
4720 ecomadd
= ecommunity_str2com(argv
[2]->arg
,
4721 ECOMMUNITY_ROUTE_TARGET
, 0);
4723 vty_out(vty
, "%% Malformed Route Target list\n");
4726 ecommunity_str(ecomadd
);
4728 /* Do nothing if we already have this export route-target */
4729 if (!bgp_evpn_rt_matches_existing(vpn
->export_rtl
, ecomadd
))
4730 evpn_configure_export_rt(bgp
, vpn
, ecomadd
);
4736 DEFUN (no_bgp_evpn_vni_rt
,
4737 no_bgp_evpn_vni_rt_cmd
,
4738 "no route-target <both|import|export> RT",
4741 "import and export\n"
4744 "ASN:XX or A.B.C.D:XX\n")
4746 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
4747 VTY_DECLVAR_CONTEXT_SUB(bgpevpn
, vpn
);
4748 int rt_type
, found_ecomdel
;
4749 struct ecommunity
*ecomdel
= NULL
;
4754 if (bgp
->vrf_id
!= VRF_DEFAULT
) {
4756 "This command is only supported under Default VRF\n");
4760 if (!strcmp(argv
[2]->text
, "import"))
4761 rt_type
= RT_TYPE_IMPORT
;
4762 else if (!strcmp(argv
[2]->text
, "export"))
4763 rt_type
= RT_TYPE_EXPORT
;
4764 else if (!strcmp(argv
[2]->text
, "both"))
4765 rt_type
= RT_TYPE_BOTH
;
4767 vty_out(vty
, "%% Invalid Route Target type\n");
4771 /* The user did "no route-target import", check to see if there are any
4772 * import route-targets configured. */
4773 if (rt_type
== RT_TYPE_IMPORT
) {
4774 if (!is_import_rt_configured(vpn
)) {
4776 "%% Import RT is not configured for this VNI\n");
4779 } else if (rt_type
== RT_TYPE_EXPORT
) {
4780 if (!is_export_rt_configured(vpn
)) {
4782 "%% Export RT is not configured for this VNI\n");
4785 } else if (rt_type
== RT_TYPE_BOTH
) {
4786 if (!is_import_rt_configured(vpn
)
4787 && !is_export_rt_configured(vpn
)) {
4789 "%% Import/Export RT is not configured for this VNI\n");
4794 ecomdel
= ecommunity_str2com(argv
[3]->arg
, ECOMMUNITY_ROUTE_TARGET
, 0);
4796 vty_out(vty
, "%% Malformed Route Target list\n");
4799 ecommunity_str(ecomdel
);
4801 if (rt_type
== RT_TYPE_IMPORT
) {
4802 if (!bgp_evpn_rt_matches_existing(vpn
->import_rtl
, ecomdel
)) {
4804 "%% RT specified does not match configuration for this VNI\n");
4807 evpn_unconfigure_import_rt(bgp
, vpn
, ecomdel
);
4808 } else if (rt_type
== RT_TYPE_EXPORT
) {
4809 if (!bgp_evpn_rt_matches_existing(vpn
->export_rtl
, ecomdel
)) {
4811 "%% RT specified does not match configuration for this VNI\n");
4814 evpn_unconfigure_export_rt(bgp
, vpn
, ecomdel
);
4815 } else if (rt_type
== RT_TYPE_BOTH
) {
4818 if (bgp_evpn_rt_matches_existing(vpn
->import_rtl
, ecomdel
)) {
4819 evpn_unconfigure_import_rt(bgp
, vpn
, ecomdel
);
4823 if (bgp_evpn_rt_matches_existing(vpn
->export_rtl
, ecomdel
)) {
4824 evpn_unconfigure_export_rt(bgp
, vpn
, ecomdel
);
4828 if (!found_ecomdel
) {
4830 "%% RT specified does not match configuration for this VNI\n");
4838 DEFUN (no_bgp_evpn_vni_rt_without_val
,
4839 no_bgp_evpn_vni_rt_without_val_cmd
,
4840 "no route-target <import|export>",
4846 struct bgp
*bgp
= VTY_GET_CONTEXT(bgp
);
4847 VTY_DECLVAR_CONTEXT_SUB(bgpevpn
, vpn
);
4853 if (bgp
->vrf_id
!= VRF_DEFAULT
) {
4855 "This command is only supported under Default VRF\n");
4859 if (!strcmp(argv
[2]->text
, "import")) {
4860 rt_type
= RT_TYPE_IMPORT
;
4861 } else if (!strcmp(argv
[2]->text
, "export")) {
4862 rt_type
= RT_TYPE_EXPORT
;
4864 vty_out(vty
, "%% Invalid Route Target type\n");
4868 /* Check if we should disallow. */
4869 if (rt_type
== RT_TYPE_IMPORT
) {
4870 if (!is_import_rt_configured(vpn
)) {
4872 "%% Import RT is not configured for this VNI\n");
4876 if (!is_export_rt_configured(vpn
)) {
4878 "%% Export RT is not configured for this VNI\n");
4883 /* Unconfigure the RT. */
4884 if (rt_type
== RT_TYPE_IMPORT
)
4885 evpn_unconfigure_import_rt(bgp
, vpn
, NULL
);
4887 evpn_unconfigure_export_rt(bgp
, vpn
, NULL
);
4891 static int vni_cmp(const void **a
, const void **b
)
4893 const struct bgpevpn
*first
= *a
;
4894 const struct bgpevpn
*secnd
= *b
;
4896 return secnd
->vni
- first
->vni
;
4900 * Output EVPN configuration information.
4902 void bgp_config_write_evpn_info(struct vty
*vty
, struct bgp
*bgp
, afi_t afi
,
4905 char buf1
[RD_ADDRSTRLEN
];
4908 struct list
*vnilist
= hash_to_list(bgp
->vnihash
);
4909 struct listnode
*ln
;
4910 struct bgpevpn
*data
;
4912 list_sort(vnilist
, vni_cmp
);
4913 for (ALL_LIST_ELEMENTS_RO(vnilist
, ln
, data
))
4914 write_vni_config(vty
, data
);
4916 list_delete(&vnilist
);
4919 if (bgp
->advertise_all_vni
)
4920 vty_out(vty
, " advertise-all-vni\n");
4922 if (bgp
->advertise_autort_rfc8365
)
4923 vty_out(vty
, " autort rfc8365-compatible\n");
4925 if (bgp
->advertise_gw_macip
)
4926 vty_out(vty
, " advertise-default-gw\n");
4928 if (bgp
->vxlan_flood_ctrl
== VXLAN_FLOOD_DISABLED
)
4929 vty_out(vty
, " flooding disable\n");
4931 if (CHECK_FLAG(bgp
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
4932 BGP_L2VPN_EVPN_ADVERTISE_IPV4_UNICAST
)) {
4933 if (bgp
->adv_cmd_rmap
[AFI_IP
][SAFI_UNICAST
].name
)
4934 vty_out(vty
, " advertise ipv4 unicast route-map %s\n",
4935 bgp
->adv_cmd_rmap
[AFI_IP
][SAFI_UNICAST
].name
);
4937 vty_out(vty
, " advertise ipv4 unicast\n");
4940 if (CHECK_FLAG(bgp
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
4941 BGP_L2VPN_EVPN_ADVERTISE_IPV6_UNICAST
)) {
4942 if (bgp
->adv_cmd_rmap
[AFI_IP6
][SAFI_UNICAST
].name
)
4943 vty_out(vty
, " advertise ipv6 unicast route-map %s\n",
4944 bgp
->adv_cmd_rmap
[AFI_IP6
][SAFI_UNICAST
].name
);
4946 vty_out(vty
, " advertise ipv6 unicast\n");
4949 if (CHECK_FLAG(bgp
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
4950 BGP_L2VPN_EVPN_DEFAULT_ORIGINATE_IPV4
))
4951 vty_out(vty
, " default-originate ipv4\n");
4953 if (CHECK_FLAG(bgp
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
4954 BGP_L2VPN_EVPN_DEFAULT_ORIGINATE_IPV6
))
4955 vty_out(vty
, " default-originate ipv6\n");
4957 if (CHECK_FLAG(bgp
->vrf_flags
, BGP_VRF_RD_CFGD
))
4958 vty_out(vty
, " rd %s\n",
4959 prefix_rd2str(&bgp
->vrf_prd
, buf1
, sizeof(buf1
)));
4961 /* import route-target */
4962 if (CHECK_FLAG(bgp
->vrf_flags
, BGP_VRF_IMPORT_RT_CFGD
)) {
4964 struct listnode
*node
, *nnode
;
4965 struct ecommunity
*ecom
;
4967 for (ALL_LIST_ELEMENTS(bgp
->vrf_import_rtl
, node
, nnode
,
4969 ecom_str
= ecommunity_ecom2str(
4970 ecom
, ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
4971 vty_out(vty
, " route-target import %s\n", ecom_str
);
4972 XFREE(MTYPE_ECOMMUNITY_STR
, ecom_str
);
4976 /* export route-target */
4977 if (CHECK_FLAG(bgp
->vrf_flags
, BGP_VRF_EXPORT_RT_CFGD
)) {
4979 struct listnode
*node
, *nnode
;
4980 struct ecommunity
*ecom
;
4982 for (ALL_LIST_ELEMENTS(bgp
->vrf_export_rtl
, node
, nnode
,
4984 ecom_str
= ecommunity_ecom2str(
4985 ecom
, ECOMMUNITY_FORMAT_ROUTE_MAP
, 0);
4986 vty_out(vty
, " route-target export %s\n", ecom_str
);
4987 XFREE(MTYPE_ECOMMUNITY_STR
, ecom_str
);
4992 void bgp_ethernetvpn_init(void)
4994 install_element(VIEW_NODE
, &show_ip_bgp_l2vpn_evpn_cmd
);
4995 install_element(VIEW_NODE
, &show_ip_bgp_l2vpn_evpn_rd_cmd
);
4996 install_element(VIEW_NODE
, &show_ip_bgp_l2vpn_evpn_all_tags_cmd
);
4997 install_element(VIEW_NODE
, &show_ip_bgp_l2vpn_evpn_rd_tags_cmd
);
4998 install_element(VIEW_NODE
,
4999 &show_ip_bgp_l2vpn_evpn_all_neighbor_routes_cmd
);
5000 install_element(VIEW_NODE
,
5001 &show_ip_bgp_l2vpn_evpn_rd_neighbor_routes_cmd
);
5004 &show_ip_bgp_l2vpn_evpn_all_neighbor_advertised_routes_cmd
);
5007 &show_ip_bgp_l2vpn_evpn_rd_neighbor_advertised_routes_cmd
);
5008 install_element(VIEW_NODE
, &show_ip_bgp_evpn_rd_overlay_cmd
);
5009 install_element(VIEW_NODE
, &show_ip_bgp_l2vpn_evpn_all_overlay_cmd
);
5010 install_element(BGP_EVPN_NODE
, &no_evpnrt5_network_cmd
);
5011 install_element(BGP_EVPN_NODE
, &evpnrt5_network_cmd
);
5012 install_element(BGP_EVPN_NODE
, &bgp_evpn_advertise_all_vni_cmd
);
5013 install_element(BGP_EVPN_NODE
, &no_bgp_evpn_advertise_all_vni_cmd
);
5014 install_element(BGP_EVPN_NODE
, &bgp_evpn_advertise_autort_rfc8365_cmd
);
5015 install_element(BGP_EVPN_NODE
, &no_bgp_evpn_advertise_autort_rfc8365_cmd
);
5016 install_element(BGP_EVPN_NODE
, &bgp_evpn_advertise_default_gw_cmd
);
5017 install_element(BGP_EVPN_NODE
, &no_bgp_evpn_advertise_default_gw_cmd
);
5018 install_element(BGP_EVPN_NODE
, &bgp_evpn_advertise_type5_cmd
);
5019 install_element(BGP_EVPN_NODE
, &no_bgp_evpn_advertise_type5_cmd
);
5020 install_element(BGP_EVPN_NODE
, &bgp_evpn_default_originate_cmd
);
5021 install_element(BGP_EVPN_NODE
, &no_bgp_evpn_default_originate_cmd
);
5022 install_element(BGP_EVPN_NODE
, &bgp_evpn_flood_control_cmd
);
5025 install_element(BGP_EVPN_NODE
, &test_adv_evpn_type4_route_cmd
);
5026 install_element(BGP_EVPN_NODE
, &test_withdraw_evpn_type4_route_cmd
);
5028 /* "show bgp l2vpn evpn" commands. */
5029 install_element(VIEW_NODE
, &show_bgp_l2vpn_evpn_es_cmd
);
5030 install_element(VIEW_NODE
, &show_bgp_l2vpn_evpn_vni_cmd
);
5031 install_element(VIEW_NODE
, &show_bgp_l2vpn_evpn_summary_cmd
);
5032 install_element(VIEW_NODE
, &show_bgp_l2vpn_evpn_route_cmd
);
5033 install_element(VIEW_NODE
, &show_bgp_l2vpn_evpn_route_rd_cmd
);
5034 install_element(VIEW_NODE
, &show_bgp_l2vpn_evpn_route_rd_macip_cmd
);
5035 install_element(VIEW_NODE
, &show_bgp_l2vpn_evpn_route_esi_cmd
);
5036 install_element(VIEW_NODE
, &show_bgp_l2vpn_evpn_route_vni_cmd
);
5037 install_element(VIEW_NODE
,
5038 &show_bgp_l2vpn_evpn_route_vni_multicast_cmd
);
5039 install_element(VIEW_NODE
, &show_bgp_l2vpn_evpn_route_vni_macip_cmd
);
5040 install_element(VIEW_NODE
, &show_bgp_l2vpn_evpn_route_vni_all_cmd
);
5041 install_element(VIEW_NODE
, &show_bgp_l2vpn_evpn_import_rt_cmd
);
5042 install_element(VIEW_NODE
, &show_bgp_l2vpn_evpn_vrf_import_rt_cmd
);
5044 /* "show bgp evpn" commands. */
5045 install_element(VIEW_NODE
, &show_bgp_evpn_vni_cmd
);
5046 install_element(VIEW_NODE
, &show_bgp_evpn_summary_cmd
);
5047 install_element(VIEW_NODE
, &show_bgp_evpn_route_cmd
);
5048 install_element(VIEW_NODE
, &show_bgp_evpn_route_rd_cmd
);
5049 install_element(VIEW_NODE
, &show_bgp_evpn_route_rd_macip_cmd
);
5050 install_element(VIEW_NODE
, &show_bgp_evpn_route_vni_cmd
);
5051 install_element(VIEW_NODE
, &show_bgp_evpn_route_vni_multicast_cmd
);
5052 install_element(VIEW_NODE
, &show_bgp_evpn_route_vni_macip_cmd
);
5053 install_element(VIEW_NODE
, &show_bgp_evpn_route_vni_all_cmd
);
5054 install_element(VIEW_NODE
, &show_bgp_evpn_import_rt_cmd
);
5055 install_element(VIEW_NODE
, &show_bgp_vrf_l3vni_info_cmd
);
5057 install_element(BGP_EVPN_NODE
, &bgp_evpn_vni_cmd
);
5058 install_element(BGP_EVPN_NODE
, &no_bgp_evpn_vni_cmd
);
5059 install_element(BGP_EVPN_VNI_NODE
, &exit_vni_cmd
);
5060 install_element(BGP_EVPN_VNI_NODE
, &bgp_evpn_vni_rd_cmd
);
5061 install_element(BGP_EVPN_VNI_NODE
, &no_bgp_evpn_vni_rd_cmd
);
5062 install_element(BGP_EVPN_VNI_NODE
, &no_bgp_evpn_vni_rd_without_val_cmd
);
5063 install_element(BGP_EVPN_VNI_NODE
, &bgp_evpn_vni_rt_cmd
);
5064 install_element(BGP_EVPN_VNI_NODE
, &no_bgp_evpn_vni_rt_cmd
);
5065 install_element(BGP_EVPN_VNI_NODE
, &no_bgp_evpn_vni_rt_without_val_cmd
);
5066 install_element(BGP_EVPN_NODE
, &bgp_evpn_vrf_rd_cmd
);
5067 install_element(BGP_EVPN_NODE
, &no_bgp_evpn_vrf_rd_cmd
);
5068 install_element(BGP_NODE
, &no_bgp_evpn_vrf_rd_without_val_cmd
);
5069 install_element(BGP_EVPN_NODE
, &bgp_evpn_vrf_rt_cmd
);
5070 install_element(BGP_EVPN_NODE
, &no_bgp_evpn_vrf_rt_cmd
);
5071 install_element(BGP_EVPN_VNI_NODE
,
5072 &bgp_evpn_advertise_default_gw_vni_cmd
);
5073 install_element(BGP_EVPN_VNI_NODE
,
5074 &no_bgp_evpn_advertise_default_gw_vni_cmd
);
5075 install_element(BGP_EVPN_VNI_NODE
, &bgp_evpn_advertise_vni_subnet_cmd
);
5076 install_element(BGP_EVPN_VNI_NODE
,
5077 &no_bgp_evpn_advertise_vni_subnet_cmd
);