Skip to content

Commit

Permalink
zebra: Add uptime string format for non-json cli output
Browse files Browse the repository at this point in the history
time in string format is added for non-json cli show output for below
commands,

show ip[v6] route , nexthop-group, ospfv2 neighbor, ospfv2 neighbor bfd
and igmp groups.

Sample non-json output,

```
tor-22# show nexthop-group rib 28
ID: 28 (zebra)
     RefCnt: 11
     Uptime: 00:04:07, Wed Aug 16 12:12:50 2023

     VRF: default
     Valid, Installed
     Interface Index: 4
           via fe80::202:ff:fe00:18, swp2 (vrf default), weight 1
     Dependents: (26)
tor-22#
```

Ticket:#3541629

Issue:3541629

Testing: UT done

Signed-off-by: Sindhu Parvathi Gopinathan's <[email protected]>
  • Loading branch information
Sindhu Parvathi Gopinathan authored and donaldsharp committed Dec 17, 2024
1 parent 6d07b95 commit 5b8b454
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 26 deletions.
8 changes: 6 additions & 2 deletions lib/bfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,8 @@ void bfd_sess_show(struct vty *vty, struct json_object *json,
{
json_object *json_bfd = NULL;
char time_buf[64];
time_t epoch_tbuf;
char epoch_str_buf[MONOTIME_STRLEN];

if (!bsp)
return;
Expand Down Expand Up @@ -840,13 +842,15 @@ void bfd_sess_show(struct vty *vty, struct json_object *json,
}

bfd_last_update(bsp->bss.last_event, time_buf, sizeof(time_buf));
epoch_tbuf = time(NULL) - (monotime(NULL) - bsp->bss.last_event);
if (json) {
json_object_string_add(json_bfd, "status",
bfd_get_status_str(bsp->bss.state));
json_object_string_add(json_bfd, "lastUpdate", time_buf);
} else
vty_out(vty, " Status: %s, Last update: %s\n",
bfd_get_status_str(bsp->bss.state), time_buf);
vty_out(vty, " Status: %s, Last update: %s, %s\n",
bfd_get_status_str(bsp->bss.state), time_buf,
ctime_r(&epoch_tbuf, epoch_str_buf));

if (json)
json_object_object_add(json, "peerBfdInfo", json_bfd);
Expand Down
5 changes: 3 additions & 2 deletions ospfd/ospf_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -4623,6 +4623,7 @@ static void show_ip_ospf_neighbour_brief(struct vty *vty,
long time_val = 0;
char uptime[OSPF_TIME_DUMP_SIZE];
time_t epoch_tbuf = 0;
char epoch_str_buf[MONOTIME_STRLEN];

if (nbr->ts_last_progress.tv_sec || nbr->ts_last_progress.tv_usec)
time_val =
Expand Down Expand Up @@ -4726,8 +4727,8 @@ static void show_ip_ospf_neighbour_brief(struct vty *vty,
vty_out(vty, "%-15pI4 %3d %-15s ", &nbr->router_id,
nbr->priority, msgbuf);

vty_out(vty, "%-15s ",
ospf_timeval_dump(&res, uptime, sizeof(uptime)));
vty_out(vty, "%-15s %-25s ", ospf_timeval_dump(&res, uptime, sizeof(uptime)),
ctime_r(&epoch_tbuf, epoch_str_buf));

vty_out(vty, "%9s ",
ospf_timer_dump(nbr->t_inactivity, timebuf,
Expand Down
32 changes: 13 additions & 19 deletions pimd/pim_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -854,11 +854,13 @@ static void igmp_group_print(struct interface *ifp, struct vty *vty, bool uj,
char group_str[INET_ADDRSTRLEN];
char hhmmss[PIM_TIME_STRLEN];
char uptime[PIM_TIME_STRLEN];
time_t epoch_tbuf;

pim_inet4_dump("<group?>", grp->group_addr, group_str,
sizeof(group_str));
pim_time_timer_to_hhmmss(hhmmss, sizeof(hhmmss), grp->t_group_timer);
pim_time_uptime(uptime, sizeof(uptime), now - grp->group_creation);
epoch_tbuf = time(NULL) - (monotime(NULL) - (UPTIMESECS(grp->group_creation)));

if (uj) {
json_object_object_get_ex(json, ifp->name, &json_iface);
Expand Down Expand Up @@ -936,6 +938,7 @@ static void igmp_group_print(struct interface *ifp, struct vty *vty, bool uj,
}
}
} else {
char epoch_str_buf[MONOTIME_STRLEN];
if (detail) {
struct listnode *srcnode;
struct gm_source *src;
Expand All @@ -947,31 +950,22 @@ static void igmp_group_print(struct interface *ifp, struct vty *vty, bool uj,
pim_inet4_dump("<source?>", src->source_addr,
source_str, sizeof(source_str));

vty_out(vty,
"%-16s %-15s %4s %8s %-15s %d %8s\n",
ifp->name, group_str,
vty_out(vty, "%-16s %-15s %4s %8s %-15s %d %8s %-25s\n", ifp->name,
group_str,
grp->igmp_version == 3
? (grp->group_filtermode_isexcl
? "EXCL"
: "INCL")
? (grp->group_filtermode_isexcl ? "EXCL" : "INCL")
: "----",
hhmmss, source_str, grp->igmp_version,
uptime);
hhmmss, source_str, grp->igmp_version, uptime,
ctime_r(&epoch_tbuf, epoch_str_buf));
}
return;
}

vty_out(vty, "%-16s %-15s %4s %8s %4d %d %8s\n", ifp->name,
group_str,
grp->igmp_version == 3
? (grp->group_filtermode_isexcl ? "EXCL"
: "INCL")
: "----",
hhmmss,
grp->group_source_list
? listcount(grp->group_source_list)
: 0,
grp->igmp_version, uptime);
vty_out(vty, "%-16s %-15s %4s %8s %4d %d %8s %-25s\n", ifp->name, group_str,
grp->igmp_version == 3 ? (grp->group_filtermode_isexcl ? "EXCL" : "INCL")
: "----",
hhmmss, grp->group_source_list ? listcount(grp->group_source_list) : 0,
grp->igmp_version, uptime, ctime_r(&epoch_tbuf, epoch_str_buf));
}
}

Expand Down
12 changes: 9 additions & 3 deletions zebra/zebra_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,11 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn,
char up_str[MONOTIME_STRLEN];
bool first_p = true;
bool nhg_from_backup = false;
time_t epoch_tbuf;
char epoch_str_buf[MONOTIME_STRLEN];

uptime2str(re->uptime, up_str, sizeof(up_str));
epoch_tbuf = time(NULL) - (monotime(NULL) - (UPTIMESECS(re->uptime)));

/* If showing fib information, use the fib view of the
* nexthops.
Expand Down Expand Up @@ -804,7 +807,7 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn,
}

show_route_nexthop_helper(vty, re, nexthop);
vty_out(vty, ", %s\n", up_str);
vty_out(vty, ", %s, %s\n", up_str, ctime_r(&epoch_tbuf, epoch_str_buf));
}

/* If we only had backup nexthops, we're done */
Expand Down Expand Up @@ -1197,9 +1200,10 @@ static void show_nexthop_group_out(struct vty *vty, struct nhg_hash_entry *nhe,
json_object *json = NULL;
json_object *json_backup_nexthop_array = NULL;
json_object *json_backup_nexthops = NULL;

time_t epoch_tbuf;

uptime2str(nhe->uptime, up_str, sizeof(up_str));
epoch_tbuf = time(NULL) - (monotime(NULL) - (UPTIMESECS(nhe->uptime)));

if (json_nhe_hdr)
json = json_object_new_object();
Expand All @@ -1219,6 +1223,8 @@ static void show_nexthop_group_out(struct vty *vty, struct nhg_hash_entry *nhe,
vrf_id_to_name(nhe->vrf_id));

} else {
char epoch_str_buf[MONOTIME_STRLEN];

vty_out(vty, "ID: %u (%s)\n", nhe->id,
zebra_route_string(nhe->type));
vty_out(vty, " RefCnt: %u", nhe->refcnt);
Expand All @@ -1229,7 +1235,7 @@ static void show_nexthop_group_out(struct vty *vty, struct nhg_hash_entry *nhe,
nhe->timer));
vty_out(vty, "\n");

vty_out(vty, " Uptime: %s\n", up_str);
vty_out(vty, " Uptime: %s, %s\n", up_str, ctime_r(&epoch_tbuf, epoch_str_buf));
vty_out(vty, " VRF: %s\n", vrf_id_to_name(nhe->vrf_id));
}

Expand Down

0 comments on commit 5b8b454

Please sign in to comment.