From: Ameya Dharkar Date: Fri, 5 Oct 2018 21:30:59 +0000 (-0700) Subject: bgpd: BGP JSON show commands enhancements X-Git-Tag: frr-7.1-dev~226^2~1 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=50e05855f06d29d3c7ba86ef74529c777e3af7c3;p=matthieu%2Ffrr.git bgpd: BGP JSON show commands enhancements 1. "show bgp ipv4 json" - Corresponding CLI has "network" field which displays a prefix in 'prefix/prefixlen' format. Added this "network" field to JSON as well. - Following fields have different names in JSON and CLI. CLI JSON metric med locPrf localPref path aspath Added fields "metric", "locPrf" and "path" in JSON for CLI/JSON consistency. Older JSON fields med, localPref, aspath will be deprecated in future. 2. "show bgp ipv6 json" - Similar changes as "show bgp ipv4 json" - JSON does not have "prefix", "prefixLen" fields which are present in IPv4 command. Added these fields as they are useful. 3. "show bgp ipv4/ipv6 neighbor advertised-routes json" - Added "network" field. - Added locPrf, path fields for CLI/JSON consistency. localPref, aspath will be deprecated in future. 4. "show bgp ipv4/ipv6 summary json" - Added "pfxRcd" for CLI/JSON consistency. "prefixReceivedCount" will be deprecated in future. - Added "pfxSnt" for peers. This count is obtalned from corresponding update_subgroup. This needed a fix in the code where we copy fields for a split update_subgroup from the parent update_subgrp. New subgrp should inherit subgrp->scount(Count of advertized prefixes) of the parent subgrp. 5. "show bgp neighbor json" - Added "sentPrefixCounter" 6. "show bgp ipv4/ipv6 json" - Added "metric" field for CLI/JSON consistency. "med" will be deprecated in future. Signed-off-by: Ameya Dharkar --- diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 715393b91d..815a40190b 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -6288,6 +6288,7 @@ static void route_vty_out_route(struct prefix *p, struct vty *vty, { int len = 0; char buf[BUFSIZ]; + char buf2[BUFSIZ]; if (p->family == AF_INET) { if (!json) { @@ -6301,6 +6302,10 @@ static void route_vty_out_route(struct prefix *p, struct vty *vty, &p->u.prefix, buf, BUFSIZ)); json_object_int_add(json, "prefixLen", p->prefixlen); + sprintf(buf2, "%s/%d", + inet_ntop(p->family, &p->u.prefix, buf, + BUFSIZ), p->prefixlen); + json_object_string_add(json, "network", buf2); } } else if (p->family == AF_ETHERNET) { prefix2str(p, buf, PREFIX_STRLEN); @@ -6324,6 +6329,16 @@ static void route_vty_out_route(struct prefix *p, struct vty *vty, vty, "%s/%d", inet_ntop(p->family, &p->u.prefix, buf, BUFSIZ), p->prefixlen); + else { + json_object_string_add(json, "prefix", + inet_ntop(p->family, + &p->u.prefix, buf, + BUFSIZ)); + json_object_int_add(json, "prefixLen", p->prefixlen); + sprintf(buf2, "%s/%d", + inet_ntop(p->family, &p->u.prefix, buf, + BUFSIZ), p->prefixlen); + json_object_string_add(json, "network", buf2); } } if (!json) { @@ -6559,7 +6574,8 @@ void route_vty_out(struct vty *vty, struct prefix *p, struct bgp_info *binfo, inet_ntoa(attr->nexthop)); json_object_string_add(json_nexthop_global, "afi", "ipv4"); - json_object_boolean_true_add(json_nexthop_global, + json_object_boolean_true_add( + json_nexthop_global, "used"); } else { vty_out(vty, "%-16s", inet_ntoa(attr->nexthop)); @@ -6686,19 +6702,32 @@ void route_vty_out(struct vty *vty, struct prefix *p, struct bgp_info *binfo, /* MED/Metric */ if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC)) - if (json_paths) + if (json_paths) { + + /* + * Adding "metric" field to match with corresponding + * CLI. "med" will be deprecated in future. + */ json_object_int_add(json_path, "med", attr->med); - else + json_object_int_add(json_path, "metric", attr->med); + } else vty_out(vty, "%10u", attr->med); else if (!json_paths) vty_out(vty, " "); /* Local Pref */ if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF)) - if (json_paths) + if (json_paths) { + + /* + * Adding "locPrf" field to match with corresponding + * CLI. "localPref" will be deprecated in future. + */ json_object_int_add(json_path, "localpref", attr->local_pref); - else + json_object_int_add(json_path, "locPrf", + attr->local_pref); + } else vty_out(vty, "%7u", attr->local_pref); else if (!json_paths) vty_out(vty, " "); @@ -6717,10 +6746,17 @@ void route_vty_out(struct vty *vty, struct prefix *p, struct bgp_info *binfo, /* Print aspath */ if (attr->aspath) { - if (json_paths) + if (json_paths) { + + /* + * Adding "path" field to match with corresponding + * CLI. "aspath" will be deprecated in future. + */ json_object_string_add(json_path, "aspath", attr->aspath->str); - else + json_object_string_add(json_path, "path", + attr->aspath->str); + } else aspath_print_vty(vty, "%s", attr->aspath, " "); } @@ -6781,6 +6817,7 @@ void route_vty_out_tmp(struct vty *vty, struct prefix *p, struct attr *attr, json_object *json_status = NULL; json_object *json_net = NULL; char buff[BUFSIZ]; + char buf2[BUFSIZ]; /* Route status display. */ if (use_json) { json_status = json_object_new_object(); @@ -6792,11 +6829,16 @@ void route_vty_out_tmp(struct vty *vty, struct prefix *p, struct attr *attr, } /* print prefix and mask */ - if (use_json) + if (use_json) { json_object_string_add( json_net, "addrPrefix", inet_ntop(p->family, &p->u.prefix, buff, BUFSIZ)); - else + json_object_int_add(json_net, "prefixLen", p->prefixlen); + sprintf(buf2, "%s/%d", + inet_ntop(p->family, &p->u.prefix, buff, + BUFSIZ), p->prefixlen); + json_object_string_add(json_net, "network", buf2); + } else route_vty_out_route(p, vty, NULL); /* Print attribute */ @@ -6832,16 +6874,34 @@ void route_vty_out_tmp(struct vty *vty, struct prefix *p, struct attr *attr, json_object_int_add(json_net, "metric", attr->med); - if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF)) + if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF)) { + + /* + * Adding "locPrf" field to match with + * corresponding CLI. "localPref" will be + * deprecated in future. + */ json_object_int_add(json_net, "localPref", attr->local_pref); + json_object_int_add(json_net, "locPrf", + attr->local_pref); + } json_object_int_add(json_net, "weight", attr->weight); /* Print aspath */ - if (attr->aspath) + if (attr->aspath) { + + /* + * Adding "path" field to match with + * corresponding CLI. "localPref" will be + * deprecated in future. + */ json_object_string_add(json_net, "asPath", attr->aspath->str); + json_object_string_add(json_net, "path", + attr->aspath->str); + } /* Print origin */ json_object_string_add(json_net, "bgpOriginCode", @@ -7745,10 +7805,18 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct prefix *p, bgp_origin_long_str[attr->origin]); if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC)) { - if (json_paths) + if (json_paths) { + + /* + * Adding "metric" field to match with + * corresponding CLI. "med" will be + * deprecated in future. + */ json_object_int_add(json_path, "med", attr->med); - else + json_object_int_add(json_path, "metric", + attr->med); + } else vty_out(vty, ", metric %u", attr->med); } diff --git a/bgpd/bgp_updgrp.c b/bgpd/bgp_updgrp.c index 7f7b4a893f..2a4c3690c9 100644 --- a/bgpd/bgp_updgrp.c +++ b/bgpd/bgp_updgrp.c @@ -1182,6 +1182,8 @@ static void update_subgroup_copy_adj_out(struct update_subgroup *source, aout_copy->attr = aout->attr ? bgp_attr_intern(aout->attr) : NULL; } + + dest->scount = source->scount; } /* diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 58f23fd2f4..40c79e1da2 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -7681,6 +7681,7 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi, int pfx_rcd_safi; json_object *json_peer = NULL; json_object *json_peers = NULL; + struct peer_af *paf; /* labeled-unicast routes are installed in the unicast table so in order * to @@ -7973,8 +7974,22 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi, json_object_int_add(json_peer, "inq", 0); peer_uptime(peer->uptime, timebuf, BGP_UPTIME_LEN, use_json, json_peer); + + /* + * Adding "pfxRcd" field to match with the corresponding + * CLI. "prefixReceivedCount" will be deprecated in + * future. + */ json_object_int_add(json_peer, "prefixReceivedCount", peer->pcount[afi][pfx_rcd_safi]); + json_object_int_add(json_peer, "pfxRcd", + peer->pcount[afi][pfx_rcd_safi]); + + paf = peer_af_find(peer, afi, pfx_rcd_safi); + if (paf && PAF_SUBGRP(paf)) + json_object_int_add(json_peer, + "pfxSnt", + (PAF_SUBGRP(paf))->scount); if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN)) json_object_string_add(json_peer, "state", @@ -8688,6 +8703,9 @@ static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi, /* Receive prefix count */ json_object_int_add(json_addr, "acceptedPrefixCounter", p->pcount[afi][safi]); + if (paf && PAF_SUBGRP(paf)) + json_object_int_add(json_addr, "sentPrefixCounter", + (PAF_SUBGRP(paf))->scount); /* Maximum prefix */ if (CHECK_FLAG(p->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) {