mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-07-23 06:47:07 +00:00
bgpd: Json support for evpn commands
Ticket:CM-16241 Reviewed By:CCR-6451 Testing: Manual Signed-off-by: Mitesh Kanjariya <mitesh@cumulusnetworks.com>
This commit is contained in:
parent
acf716660f
commit
9c92b5f768
@ -2187,6 +2187,61 @@ char *bgp_evpn_label2str(mpls_label_t *label, char *buf, int len)
|
||||
return buf;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function to convert evpn route to json format.
|
||||
* NOTE: We don't use prefix2str as the output here is a bit different.
|
||||
*/
|
||||
void
|
||||
bgp_evpn_route2json (struct prefix_evpn *p, json_object *json)
|
||||
{
|
||||
char buf1[ETHER_ADDR_STRLEN];
|
||||
char buf2[PREFIX2STR_BUFFER];
|
||||
|
||||
if (!json)
|
||||
return;
|
||||
|
||||
if (p->prefix.route_type == BGP_EVPN_IMET_ROUTE)
|
||||
{
|
||||
json_object_int_add (json, "routeType", p->prefix.route_type);
|
||||
json_object_int_add (json, "ethTag", 0);
|
||||
json_object_int_add (json, "ipLen", IS_EVPN_PREFIX_IPADDR_V4 (p) ? IPV4_MAX_BITLEN : IPV6_MAX_BITLEN);
|
||||
json_object_string_add (json, "ip", inet_ntoa (p->prefix.ip.ipaddr_v4));
|
||||
}
|
||||
else if (p->prefix.route_type == BGP_EVPN_MAC_IP_ROUTE)
|
||||
{
|
||||
if (IS_EVPN_PREFIX_IPADDR_NONE(p))
|
||||
{
|
||||
json_object_int_add (json, "routeType", p->prefix.route_type);
|
||||
json_object_int_add (json, "esi", 0); /* TODO: we don't support esi yet */
|
||||
json_object_int_add (json, "ethTag", 0);
|
||||
json_object_int_add (json, "macLen", 8 * ETHER_ADDR_LEN);
|
||||
json_object_string_add (json, "mac", prefix_mac2str (&p->prefix.mac, buf1, sizeof (buf1)));
|
||||
}
|
||||
else
|
||||
{
|
||||
u_char family;
|
||||
|
||||
family = IS_EVPN_PREFIX_IPADDR_V4(p) ? \
|
||||
AF_INET : AF_INET6;
|
||||
|
||||
json_object_int_add (json, "routeType", p->prefix.route_type);
|
||||
json_object_int_add (json, "esi", 0); /* TODO: we don't support esi yet */
|
||||
json_object_int_add (json, "ethTag", 0);
|
||||
json_object_int_add (json, "macLen", 8 * ETHER_ADDR_LEN);
|
||||
json_object_string_add (json, "mac", prefix_mac2str (&p->prefix.mac, buf1, sizeof (buf1)));
|
||||
json_object_int_add (json, "ipLen", IS_EVPN_PREFIX_IPADDR_V4 (p) ? IPV4_MAX_BITLEN : IPV6_MAX_BITLEN);
|
||||
json_object_string_add (json, "ip", inet_ntop (family, &p->prefix.ip.ip.addr, buf2, PREFIX2STR_BUFFER));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Currently, this is to cater to other AF_ETHERNET code. */
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Function to convert evpn route to string.
|
||||
* NOTE: We don't use prefix2str as the output here is a bit different.
|
||||
|
@ -28,6 +28,8 @@
|
||||
extern void bgp_evpn_handle_router_id_update(struct bgp *bgp, int withdraw);
|
||||
extern char *bgp_evpn_label2str(mpls_label_t *label, char *buf, int len);
|
||||
extern char *bgp_evpn_route2str(struct prefix_evpn *p, char *buf, int len);
|
||||
extern void
|
||||
bgp_evpn_route2json (struct prefix_evpn *p, json_object *json);
|
||||
extern void bgp_evpn_encode_prefix(struct stream *s, struct prefix *p,
|
||||
struct prefix_rd *prd, mpls_label_t *label,
|
||||
struct attr *attr, int addpath_encode,
|
||||
|
@ -28,6 +28,8 @@
|
||||
#include "bgpd/bgpd.h"
|
||||
#include "bgpd/bgp_ecommunity.h"
|
||||
|
||||
#define RT_ADDRSTRLEN 28
|
||||
|
||||
/* EVPN prefix lengths. */
|
||||
#define EVPN_TYPE_2_ROUTE_PREFIXLEN 224
|
||||
#define EVPN_TYPE_3_ROUTE_PREFIXLEN 224
|
||||
|
1156
bgpd/bgp_evpn_vty.c
1156
bgpd/bgp_evpn_vty.c
File diff suppressed because it is too large
Load Diff
@ -6227,7 +6227,8 @@ void bgp_redistribute_withdraw(struct bgp *bgp, afi_t afi, int type,
|
||||
}
|
||||
|
||||
/* Static function to display route. */
|
||||
static void route_vty_out_route(struct prefix *p, struct vty *vty)
|
||||
static void route_vty_out_route(struct prefix *p, struct vty *vty,
|
||||
json_object *json)
|
||||
{
|
||||
int len;
|
||||
u_int32_t destination;
|
||||
@ -6250,23 +6251,29 @@ static void route_vty_out_route(struct prefix *p, struct vty *vty)
|
||||
len = vty_out(vty, "%s", buf);
|
||||
} else if (p->family == AF_EVPN) {
|
||||
#if defined(HAVE_CUMULUS)
|
||||
len = vty_out(vty, "%s",
|
||||
bgp_evpn_route2str((struct prefix_evpn *)p, buf,
|
||||
BUFSIZ));
|
||||
if (!json)
|
||||
len = vty_out (vty, "%s",
|
||||
bgp_evpn_route2str((struct prefix_evpn *)p,
|
||||
buf, BUFSIZ));
|
||||
else
|
||||
bgp_evpn_route2json ( (struct prefix_evpn *) p, json);
|
||||
#else
|
||||
prefix2str(p, buf, PREFIX_STRLEN);
|
||||
len = vty_out(vty, "%s", buf);
|
||||
#endif
|
||||
} else
|
||||
} else {
|
||||
len = vty_out(vty, "%s/%d",
|
||||
inet_ntop(p->family, &p->u.prefix, buf, BUFSIZ),
|
||||
p->prefixlen);
|
||||
}
|
||||
|
||||
len = 17 - len;
|
||||
if (len < 1)
|
||||
vty_out(vty, "\n%*s", 20, " ");
|
||||
else
|
||||
vty_out(vty, "%*s", len, " ");
|
||||
if (!json) {
|
||||
len = 17 - len;
|
||||
if (len < 1)
|
||||
vty_out(vty, "\n%*s", 20, " ");
|
||||
else
|
||||
vty_out(vty, "%*s", len, " ");
|
||||
}
|
||||
}
|
||||
|
||||
enum bgp_display_type {
|
||||
@ -6370,9 +6377,11 @@ void route_vty_out(struct vty *vty, struct prefix *p, struct bgp_info *binfo,
|
||||
if (!json_paths) {
|
||||
/* print prefix and mask */
|
||||
if (!display)
|
||||
route_vty_out_route(p, vty);
|
||||
route_vty_out_route(p, vty, json_path);
|
||||
else
|
||||
vty_out(vty, "%*s", 17, " ");
|
||||
} else {
|
||||
route_vty_out_route (p, vty, json_path);
|
||||
}
|
||||
|
||||
/* Print attribute */
|
||||
@ -6668,7 +6677,7 @@ void route_vty_out_tmp(struct vty *vty, struct prefix *p, struct attr *attr,
|
||||
json_net, "addrPrefix",
|
||||
inet_ntop(p->family, &p->u.prefix, buff, BUFSIZ));
|
||||
else
|
||||
route_vty_out_route(p, vty);
|
||||
route_vty_out_route(p, vty, NULL);
|
||||
|
||||
/* Print attribute */
|
||||
if (attr) {
|
||||
@ -6801,7 +6810,7 @@ void route_vty_out_tag(struct vty *vty, struct prefix *p,
|
||||
/* print prefix and mask */
|
||||
if (json == NULL) {
|
||||
if (!display)
|
||||
route_vty_out_route(p, vty);
|
||||
route_vty_out_route(p, vty, NULL);
|
||||
else
|
||||
vty_out(vty, "%*s", 17, " ");
|
||||
}
|
||||
@ -6916,7 +6925,7 @@ void route_vty_out_overlay(struct vty *vty, struct prefix *p,
|
||||
|
||||
/* print prefix and mask */
|
||||
if (!display)
|
||||
route_vty_out_route(p, vty);
|
||||
route_vty_out_route(p, vty, NULL);
|
||||
else
|
||||
vty_out(vty, "%*s", 17, " ");
|
||||
|
||||
@ -6985,7 +6994,7 @@ static void damp_route_vty_out(struct vty *vty, struct prefix *p,
|
||||
/* print prefix and mask */
|
||||
if (!use_json) {
|
||||
if (!display)
|
||||
route_vty_out_route(p, vty);
|
||||
route_vty_out_route(p, vty, NULL);
|
||||
else
|
||||
vty_out(vty, "%*s", 17, " ");
|
||||
}
|
||||
@ -7054,7 +7063,7 @@ static void flap_route_vty_out(struct vty *vty, struct prefix *p,
|
||||
/* print prefix and mask */
|
||||
if (!use_json) {
|
||||
if (!display)
|
||||
route_vty_out_route(p, vty);
|
||||
route_vty_out_route(p, vty, NULL);
|
||||
else
|
||||
vty_out(vty, "%*s", 17, " ");
|
||||
}
|
||||
@ -8336,6 +8345,7 @@ void route_vty_out_detail_header(struct vty *vty, struct bgp *bgp,
|
||||
#if defined(HAVE_CUMULUS)
|
||||
char buf3[EVPN_ROUTE_STRLEN];
|
||||
#endif
|
||||
char prefix_str[BUFSIZ];
|
||||
int count = 0;
|
||||
int best = 0;
|
||||
int suppress = 0;
|
||||
@ -8357,10 +8367,9 @@ void route_vty_out_detail_header(struct vty *vty, struct bgp *bgp,
|
||||
if (has_valid_label)
|
||||
json_object_int_add(json, "localLabel", label);
|
||||
|
||||
json_object_string_add(json, "prefix",
|
||||
inet_ntop(p->family, &p->u.prefix, buf2,
|
||||
INET6_ADDRSTRLEN));
|
||||
json_object_int_add(json, "prefixlen", p->prefixlen);
|
||||
json_object_string_add (json, "prefix",
|
||||
prefix2str (p, prefix_str,
|
||||
sizeof (prefix_str)));
|
||||
} else {
|
||||
#if defined(HAVE_CUMULUS)
|
||||
if (safi == SAFI_EVPN)
|
||||
|
Loading…
Reference in New Issue
Block a user