From: Lakshman Krishnamoorthy Date: Sat, 11 May 2019 16:47:10 +0000 (-0700) Subject: bgpd: json cli output for bgp evpn overlay X-Git-Tag: base_7.2~339^2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=14f51ebaacf468c847e9ae90bddf020a2684fa23;p=mirror%2Ffrr.git bgpd: json cli output for bgp evpn overlay This diff provides implementation for the cli: "show bgp l2vpn evpn all overlay json" Sample output after this change: leaf-1# sh bgp l2vpn evpn all overlay json { "bgpTableVersion":1, "bgpLocalRouterId":"10.100.0.1", "defaultLocPrf":100, "localAS":65000, "10.101.1.4:5":{ "rd":"10.101.1.4:5", "[5]:[0]:[32]:[101.101.101.101]":{ "prefix":"[5]:[0]:[32]:[101.101.101.101]", "prefixLen":288, "paths":[ { "valid":true, "bestpath":true, "pathFrom":"external", "nexthop":{ "ip":"10.100.0.2", "afi":"ipv4" }, "overlay":{ "esi":"00:00:00:00:00:00:00:00:00:00", "gw":"0.0.0.0", "rmac":"ea:47:79:75:22:1b" } }, { "valid":true, "pathFrom":"external", "nexthop":{ "ip":"10.100.0.2", "afi":"ipv4" }, "overlay":{ "esi":"00:00:00:00:00:00:00:00:00:00", "gw":"0.0.0.0", "rmac":"ea:47:79:75:22:1b" } } ] } }, ... ... } Signed-off-by: Lakshman Krishnamoorthy --- diff --git a/bgpd/bgp_evpn_vty.c b/bgpd/bgp_evpn_vty.c index 1bd153639b..64e6fe2584 100644 --- a/bgpd/bgp_evpn_vty.c +++ b/bgpd/bgp_evpn_vty.c @@ -1554,14 +1554,15 @@ DEFUN(show_ip_bgp_l2vpn_evpn_rd_neighbor_advertised_routes, DEFUN(show_ip_bgp_l2vpn_evpn_all_overlay, show_ip_bgp_l2vpn_evpn_all_overlay_cmd, - "show [ip] bgp l2vpn evpn all overlay", + "show [ip] bgp l2vpn evpn all overlay [json]", SHOW_STR IP_STR BGP_STR L2VPN_HELP_STR EVPN_HELP_STR "Display information about all EVPN NLRIs\n" - "Display BGP Overlay Information for prefixes\n") + "Display BGP Overlay Information for prefixes\n" + JSON_STR) { return bgp_show_ethernet_vpn(vty, NULL, bgp_show_type_normal, NULL, SHOW_DISPLAY_OVERLAY, diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 82a395d8e6..d5e12488d7 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -7525,21 +7525,26 @@ void route_vty_out_overlay(struct vty *vty, struct prefix *p, json_object *json_paths) { struct attr *attr; - char buf[BUFSIZ]; + char buf[BUFSIZ] = {0}; json_object *json_path = NULL; - - if (json_paths) - json_path = json_object_new_object(); + json_object *json_nexthop = NULL; + json_object *json_overlay = NULL; if (!path->extra) return; + if (json_paths) { + json_path = json_object_new_object(); + json_overlay = json_object_new_object(); + json_nexthop = json_object_new_object(); + } + /* short status lead text */ route_vty_short_status_out(vty, path, json_path); /* print prefix and mask */ if (!display) - route_vty_out_route(p, vty, NULL); + route_vty_out_route(p, vty, json_path); else vty_out(vty, "%*s", 17, " "); @@ -7551,35 +7556,69 @@ void route_vty_out_overlay(struct vty *vty, struct prefix *p, switch (af) { case AF_INET: - vty_out(vty, "%-16s", - inet_ntop(af, &attr->mp_nexthop_global_in, buf, - BUFSIZ)); + inet_ntop(af, &attr->mp_nexthop_global_in, buf, BUFSIZ); + if (!json_path) { + vty_out(vty, "%-16s", buf); + } else { + json_object_string_add(json_nexthop, "ip", buf); + + json_object_string_add(json_nexthop, "afi", + "ipv4"); + + json_object_object_add(json_path, "nexthop", + json_nexthop); + } break; case AF_INET6: - vty_out(vty, "%s(%s)", - inet_ntop(af, &attr->mp_nexthop_global, buf, - BUFSIZ), - inet_ntop(af, &attr->mp_nexthop_local, buf1, - BUFSIZ)); + inet_ntop(af, &attr->mp_nexthop_global, buf, BUFSIZ); + inet_ntop(af, &attr->mp_nexthop_local, buf1, BUFSIZ); + if (!json_path) { + vty_out(vty, "%s(%s)", buf, buf1); + } else { + json_object_string_add(json_nexthop, + "ipv6Global", buf); + + json_object_string_add(json_nexthop, + "ipv6LinkLocal", buf1); + + json_object_string_add(json_nexthop, "afi", + "ipv6"); + + json_object_object_add(json_path, "nexthop", + json_nexthop); + } break; default: - vty_out(vty, "?"); + if (!json_path) { + vty_out(vty, "?"); + } else { + json_object_string_add(json_nexthop, "Error", + "Unsupported address-family"); + } } char *str = esi2str(&(attr->evpn_overlay.eth_s_id)); - vty_out(vty, "%s", str); + if (!json_path) + vty_out(vty, "%s", str); + else + json_object_string_add(json_overlay, "esi", str); + XFREE(MTYPE_TMP, str); if (is_evpn_prefix_ipaddr_v4((struct prefix_evpn *)p)) { - vty_out(vty, "/%s", - inet_ntoa(attr->evpn_overlay.gw_ip.ipv4)); + inet_ntop(AF_INET, &(attr->evpn_overlay.gw_ip.ipv4), + buf, BUFSIZ); } else if (is_evpn_prefix_ipaddr_v6((struct prefix_evpn *)p)) { - vty_out(vty, "/%s", - inet_ntop(AF_INET6, - &(attr->evpn_overlay.gw_ip.ipv6), buf, - BUFSIZ)); + inet_ntop(AF_INET6, &(attr->evpn_overlay.gw_ip.ipv6), + buf, BUFSIZ); } + + if (!json_path) + vty_out(vty, "/%s", buf); + else + json_object_string_add(json_overlay, "gw", buf); + if (attr->ecommunity) { char *mac = NULL; struct ecommunity_val *routermac = ecommunity_lookup( @@ -7588,13 +7627,25 @@ void route_vty_out_overlay(struct vty *vty, struct prefix *p, if (routermac) mac = ecom_mac2str((char *)routermac->val); if (mac) { - vty_out(vty, "/%s", (char *)mac); + if (!json_path) { + vty_out(vty, "/%s", (char *)mac); + } else { + json_object_string_add(json_overlay, + "rmac", mac); + } XFREE(MTYPE_TMP, mac); } } - vty_out(vty, "\n"); - } + if (!json_path) { + vty_out(vty, "\n"); + } else { + json_object_object_add(json_path, "overlay", + json_overlay); + + json_object_array_add(json_paths, json_path); + } + } } /* dampening route */