]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: BGP JSON show commands enhancements
authorAmeya Dharkar <adharkar@vmware.com>
Fri, 5 Oct 2018 21:30:59 +0000 (14:30 -0700)
committerAmeya Dharkar <adharkar@vmware.com>
Fri, 5 Oct 2018 22:06:17 +0000 (15:06 -0700)
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 <neighbor_addr> 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 <prefix> json"
  - Added "metric" field for CLI/JSON consistency.
    "med" will be deprecated in future.

Signed-off-by: Ameya Dharkar <adharkar@vmware.org>
bgpd/bgp_route.c
bgpd/bgp_updgrp.c
bgpd/bgp_vty.c

index 715393b91db62ffdc6cc2fb265a78e5606aaecd5..815a40190bfb045d9019412277efa9f386b0e96f 100644 (file)
@@ -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);
                }
 
index 7f7b4a893fc83c167866057739578f73918c0c1e..2a4c3690c95a0ed00da31bbfba3eeec0cb0d8eae 100644 (file)
@@ -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;
 }
 
 /*
index 58f23fd2f4338d16f1c12f07def034bfa32464d9..40c79e1da266908949698de9d05e700082c80dc0 100644 (file)
@@ -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)) {