]> git.puffer.fish Git - mirror/frr.git/commitdiff
zebra: add uptime to NHEs
authorStephen Worley <sworley@nvidia.com>
Thu, 22 Apr 2021 21:19:03 +0000 (17:19 -0400)
committerStephen Worley <sworley@nvidia.com>
Thu, 22 Apr 2021 21:25:15 +0000 (17:25 -0400)
Add uptime for use with NHEs to keep track of how
long we have had this NHE in our rib without an update.

This is treated exactly the same as the re->uptime for
routes. When we get an update for a route, we reset the
uptime.

Signed-off-by: Stephen Worley <sworley@nvidia.com>
zebra/zebra_nhg.c
zebra/zebra_nhg.h
zebra/zebra_vty.c

index 0f3c0a147e0da0d4cbd0dc5d6453f285768bc857..9640d05f05a1461c3de72697e9943eba9fc23e48 100644 (file)
@@ -845,6 +845,8 @@ static bool zebra_nhe_find(struct nhg_hash_entry **nhe, /* return value */
                SET_FLAG(backup_nhe->flags, NEXTHOP_GROUP_RECURSIVE);
 
 done:
+       /* Reset time since last update */
+       (*nhe)->uptime = monotime(NULL);
 
        return created;
 }
index 0489f059be20563c48edfbe6fd40e16a68512e19..afbf1f6793ddbc5510ee89b562e88e2d567a6c21 100644 (file)
@@ -51,6 +51,9 @@ struct nhg_hash_entry {
        afi_t afi;
        vrf_id_t vrf_id;
 
+       /* Time since last update */
+       time_t uptime;
+
        /* Source protocol - zebra or another daemon */
        int type;
 
index 283a3e52d664896afcfc95d2484b2cbc5e887045..8061f34d2ba99dde6b6fc834c308c4e116ecf683 100644 (file)
@@ -445,6 +445,16 @@ static void zebra_show_ip_route_opaque(struct vty *vty, struct route_entry *re,
        }
 }
 
+static void uptime2str(time_t uptime, char *buf, size_t bufsize)
+{
+       time_t cur;
+
+       cur = monotime(NULL);
+       cur -= uptime;
+
+       frrtime_to_interval(cur, buf, bufsize);
+}
+
 /* New RIB.  Detailed information for IPv4 route. */
 static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn,
                                     int mcast, bool use_fib, bool show_ng)
@@ -499,12 +509,7 @@ static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn,
                        vty_out(vty, ", best");
                vty_out(vty, "\n");
 
-               time_t uptime;
-
-               uptime = monotime(NULL);
-               uptime -= re->uptime;
-
-               frrtime_to_interval(uptime, buf, sizeof(buf));
+               uptime2str(re->uptime, buf, sizeof(buf));
 
                vty_out(vty, "  Last update %s ago\n", buf);
 
@@ -839,17 +844,13 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn,
        json_object *json_nexthops = NULL;
        json_object *json_nexthop = NULL;
        json_object *json_route = NULL;
-       time_t uptime;
        const rib_dest_t *dest = rib_dest_from_rnode(rn);
        const struct nexthop_group *nhg;
        char up_str[MONOTIME_STRLEN];
        bool first_p = true;
        bool nhg_from_backup = false;
 
-       uptime = monotime(NULL);
-       uptime -= re->uptime;
-
-       frrtime_to_interval(uptime, up_str, sizeof(up_str));
+       uptime2str(re->uptime, up_str, sizeof(up_str));
 
        /* If showing fib information, use the fib view of the
         * nexthops.
@@ -1339,9 +1340,13 @@ static void show_nexthop_group_out(struct vty *vty, struct nhg_hash_entry *nhe)
        struct nexthop *nexthop = NULL;
        struct nhg_connected *rb_node_dep = NULL;
        struct nexthop_group *backup_nhg;
+       char up_str[MONOTIME_STRLEN];
+
+       uptime2str(nhe->uptime, up_str, sizeof(up_str));
 
        vty_out(vty, "ID: %u (%s)\n", nhe->id, zebra_route_string(nhe->type));
-       vty_out(vty, "     RefCnt: %d\n", nhe->refcnt);
+       vty_out(vty, "     RefCnt: %u\n", nhe->refcnt);
+       vty_out(vty, "     Uptime: %s\n", up_str);
        vty_out(vty, "     VRF: %s\n", vrf_id_to_name(nhe->vrf_id));
 
        if (CHECK_FLAG(nhe->flags, NEXTHOP_GROUP_VALID)) {