Skip to content

Commit

Permalink
ospfd: convert uptime to epoch for ip ospf neigh
Browse files Browse the repository at this point in the history
Currently, json output of show ip ospf neighbor commands are
having "uptime" in "17.515s" format.

uptime is converted into epoch format and added json attributes.

Supported commands:

```
show ip ospf vrf <vrf-id> neighbor json
show ip ospf vrf <VRFNAME> neighbor <neighbor-id> json
```

Sample ip ospf neighbor json output:

```
tor-21# show ip ospf vrf default neighbor swp1 json
{
  "6.0.0.9":[
    {
      "nbrState":"Full\/-",
      "nbrPriority":1,
      "converged":"Full",
      "role":"DROther",
      "upTimeInMsec":17515,
      "routerDeadIntervalTimerDueMsec":32482,
      "upTime":"17.515s",
      "deadTime":"32.482s",
      "ospfNeighUptimeEpoch":1691046764,
      "ospfNeighUptimeEpochStr":"Thu Aug  3 07:12:44 2023\n",
      "ifaceAddress":"6.0.0.9",
      "ifaceName":"swp1:6.0.0.17",
      "linkStateRetransmissionListCounter":0,
      "linkStateRequestListCounter":0,
      "databaseSummaryListCounter":0
    }
  ]
}
tor-21#
```

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 f8d9764 commit 6d07b95
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ospfd/ospf_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -4622,11 +4622,16 @@ static void show_ip_ospf_neighbour_brief(struct vty *vty,
struct timeval res = {.tv_sec = 0, .tv_usec = 0};
long time_val = 0;
char uptime[OSPF_TIME_DUMP_SIZE];
time_t epoch_tbuf = 0;

if (nbr->ts_last_progress.tv_sec || nbr->ts_last_progress.tv_usec)
time_val =
monotime_since(&nbr->ts_last_progress, &res) / 1000LL;

if (nbr->ts_last_progress.tv_sec)
epoch_tbuf = time(NULL) -
(monotime(NULL) - (nbr->ts_last_progress.tv_sec));

if (use_json) {
char neigh_str[INET_ADDRSTRLEN];

Expand Down Expand Up @@ -4684,6 +4689,11 @@ static void show_ip_ospf_neighbour_brief(struct vty *vty,
json_neighbor, "deadTime",
ospf_timer_dump(nbr->t_inactivity, timebuf,
sizeof(timebuf)));
json_object_int_add(json_neighbor,
"ospfNeighUptimeEpoch", epoch_tbuf);
json_object_string_add(json_neighbor,
"ospfNeighUptimeEpochStr",
ctime(&epoch_tbuf));
} else {
json_object_string_add(json_neighbor, "deadTimeMsecs",
"inactive");
Expand Down

0 comments on commit 6d07b95

Please sign in to comment.