Skip to content

Commit

Permalink
pimd: convert uptime to epoch for igmp vrf groups
Browse files Browse the repository at this point in the history
Currently, json output of show ip igmp vrf <vrf-id> groups
commands are having "uptime" in "00:14:16" format.

uptime is converted into epoch format and added json attributes
accordingly.

Supported commands:

```
show ip igmp vrf <vrf-id> groups json
show ip igmp vrf <vrf-id> groups detail json
```

Sample ip igmp vrf <vrf-id> groups... json output:

Before Fix:

```
tor-12# show ip igmp vrf red groups swp3 detail json
{"totalGroups":5,"watermarkLimit":0,"swp3":{"name":"swp3","state":"up","address":"20.20.20.2","index":5,"flagMulticast":true,"flagBroadcast":true,"flagAllMulticast":true,"lanDelayEnabled":true,"groups":[{"group":"225.1.101.5","mode":"EXCLUDE","timer":"00:05:03","sourcesCount":1,"version":3,"uptime":"00:16:03","sources":[{"source":"*","timer":"05:03","forwarded":true,"uptime":"00:16:03"}]},{"group":"225.1.101.4","mode":"EXCLUDE","timer":"00:05:03","sourcesCount":1,"version":3,"uptime":"00:16:03","sources":[{"source":"*","timer":"05:03","forwarded":true,"uptime":"00:16:03"}]},{"group":"225.1.101.3","mode":"EXCLUDE","timer":"00:05:03","sourcesCount":1,"version":3,"uptime":"00:16:03","sources":[{"source":"*","timer":"05:03","forwarded":true,"uptime":"00:16:03"}]},{"group":"225.1.101.2","mode":"EXCLUDE","timer":"00:05:03","sourcesCount":1,"version":3,"uptime":"00:16:03","sources":[{"source":"*","timer":"05:03","forwarded":true,"uptime":"00:16:03"}]},{"group":"225.1.101.1","mode":"EXCLUDE","timer":"00:05:03","sourcesCount":1,"version":3,"uptime":"00:16:03","sources":[{"source":"*","timer":"05:03","forwarded":true,"uptime":"00:16:03"}]}]}}
tor-12#
```

```
tor-12# show ip igmp vrf red groups json
{
  "totalGroups":5,
  "watermarkLimit":0,
  "swp3":{
    "name":"swp3",
    "state":"up",
    "address":"20.20.20.2",
    "index":5,
    "flagMulticast":true,
    "flagBroadcast":true,
    "flagAllMulticast":true,
    "lanDelayEnabled":true,
    "groups":[
      {
        "group":"225.1.101.5",
        "mode":"EXCLUDE",
        "timer":"00:05:25",
        "sourcesCount":1,
        "version":3,
        "uptime":"00:14:16"
      },
      {
        "group":"225.1.101.4",
        "mode":"EXCLUDE",
        "timer":"00:05:25",
        "sourcesCount":1,
        "version":3,
        "uptime":"00:14:16"
      },
      {
        "group":"225.1.101.3",
        "mode":"EXCLUDE",
        "timer":"00:05:25",
        "sourcesCount":1,
        "version":3,
        "uptime":"00:14:16"
      },
      {
        "group":"225.1.101.2",
        "mode":"EXCLUDE",
        "timer":"00:05:25",
        "sourcesCount":1,
        "version":3,
        "uptime":"00:14:16"
      },
      {
        "group":"225.1.101.1",
        "mode":"EXCLUDE",
        "timer":"00:05:25",
        "sourcesCount":1,
        "version":3,
        "uptime":"00:14:16"
      }
    ]
  }
}
tor-12#
```

After Fix:

```
tor-12# show ip igmp vrf red groups detail json
{"totalGroups":5,"watermarkLimit":0,"swp3":
{"name":"swp3","state":"up","address":"20.20.20.2","index":5,"flagMulticast":true,"flagBroadcast":true,"flagAllMulticast":true,"lanDelayEnabled":true,"groups":[{"group":"225.1.101.5","mode":"EXCLUDE","timer":"00:05:34","sourcesCount":1,"version":3,"uptime":"00:00:55","sources":[{"source":"*","timer":"05:34","forwarded":true,"uptime":"00:00:55","grpUptimeEpoch":1691123525,"grpUptimeEpochStr":"Fri
Aug  4 04:32:05
2023\n"}]},{"group":"225.1.101.4","mode":"EXCLUDE","timer":"00:05:34","sourcesCount":1,"version":3,"uptime":"00:00:55","sources":[{"source":"*","timer":"05:34","forwarded":true,"uptime":"00:00:55","grpUptimeEpoch":1691123525,"grpUptimeEpochStr":"Fri
Aug  4 04:32:05
2023\n"}]},{"group":"225.1.101.3","mode":"EXCLUDE","timer":"00:05:34","sourcesCount":1,"version":3,"uptime":"00:00:55","sources":[{"source":"*","timer":"05:34","forwarded":true,"uptime":"00:00:55","grpUptimeEpoch":1691123525,"grpUptimeEpochStr":"Fri
Aug  4 04:32:05
2023\n"}]},{"group":"225.1.101.2","mode":"EXCLUDE","timer":"00:05:34","sourcesCount":1,"version":3,"uptime":"00:00:55","sources":[{"source":"*","timer":"05:34","forwarded":true,"uptime":"00:00:55","grpUptimeEpoch":1691123525,"grpUptimeEpochStr":"Fri
Aug  4 04:32:05
2023\n"}]},{"group":"225.1.101.1","mode":"EXCLUDE","timer":"00:05:34","sourcesCount":1,"version":3,"uptime":"00:00:55","sources":[{"source":"*","timer":"05:34","forwarded":true,"uptime":"00:00:55","grpUptimeEpoch":1691123525,"grpUptimeEpochStr":"Fri
Aug  4 04:32:05 2023\n"}]}]}}
tor-12#
tor-12#
```

```
tor-12# show ip igmp vrf red groups json
{
  "totalGroups":5,
  "watermarkLimit":0,
  "swp3":{
    "name":"swp3",
    "state":"up",
    "address":"20.20.20.2",
    "index":5,
    "flagMulticast":true,
    "flagBroadcast":true,
    "flagAllMulticast":true,
    "lanDelayEnabled":true,
    "groups":[
      {
        "group":"225.1.101.5",
        "mode":"EXCLUDE",
        "timer":"00:05:06",
        "sourcesCount":1,
        "version":3,
        "uptime":"00:00:58",
        "igmpGrpUptimeEpoch":1691123524,
        "igmpGrpUptimeEpochStr":"Fri Aug  4 04:32:04 2023\n"
      },
      {
        "group":"225.1.101.3",
        "mode":"EXCLUDE",
        "timer":"00:05:06",
        "sourcesCount":1,
        "version":3,
        "uptime":"00:00:58",
        "igmpGrpUptimeEpoch":1691123524,
        "igmpGrpUptimeEpochStr":"Fri Aug  4 04:32:04 2023\n"
      },
      {
        "group":"225.1.101.2",
        "mode":"EXCLUDE",
        "timer":"00:05:06",
        "sourcesCount":1,
        "version":3,
        "uptime":"00:00:58",
        "igmpGrpUptimeEpoch":1691123524,
        "igmpGrpUptimeEpochStr":"Fri Aug  4 04:32:04 2023\n"
      },
      {
        "group":"225.1.101.1",
        "mode":"EXCLUDE",
        "timer":"00:05:06",
        "sourcesCount":1,
        "version":3,
        "uptime":"00:00:58",
        "igmpGrpUptimeEpoch":1691123524,
        "igmpGrpUptimeEpochStr":"Fri Aug  4 04:32:04 2023\n"
      }
    ]
  }
}
tor-12#

```

Ticket:#3541629

Issue:3541629

Testing: UT done

Signed-off-by: Sindhu Parvathi Gopinathan's <sgopinathan@nvidia.com>
  • Loading branch information
Sindhu Parvathi Gopinathan authored and chiragshah6 committed Aug 15, 2023
1 parent 43b23fb commit a3a8eec
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions pimd/pim_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -828,19 +828,26 @@ static void igmp_show_statistics(struct pim_instance *pim, struct vty *vty,

static void igmp_source_json_helper(struct gm_source *src,
json_object *json_sources, char *source_str,
char *mmss, char *uptime)
char *mmss, char *uptime,
time_t source_creation)
{
json_object *json_source = NULL;
time_t epoch_tbuf;

json_source = json_object_new_object();
if (!json_source)
return;

epoch_tbuf =
time(NULL) - (monotime(NULL) - (UPTIMESECS(source_creation)));
json_object_string_add(json_source, "source", source_str);
json_object_string_add(json_source, "timer", mmss);
json_object_boolean_add(json_source, "forwarded",
IGMP_SOURCE_TEST_FORWARDING(src->source_flags));
json_object_string_add(json_source, "uptime", uptime);
json_object_int_add(json_source, "grpUptimeEpoch", epoch_tbuf);
json_object_string_add(json_source, "grpUptimeEpochStr",
ctime(&epoch_tbuf));
json_object_array_add(json_sources, json_source);
}

Expand All @@ -854,11 +861,14 @@ 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 @@ -898,6 +908,11 @@ static void igmp_group_print(struct interface *ifp, struct vty *vty, bool uj,
json_object_int_add(json_group, "version",
grp->igmp_version);
json_object_string_add(json_group, "uptime", uptime);
json_object_int_add(json_group, "igmpGrpUptimeEpoch",
epoch_tbuf);
json_object_string_add(json_group,
"igmpGrpUptimeEpochStr",
ctime(&epoch_tbuf));
json_object_array_add(json_groups, json_group);

if (detail) {
Expand Down Expand Up @@ -931,7 +946,8 @@ static void igmp_group_print(struct interface *ifp, struct vty *vty, bool uj,

igmp_source_json_helper(
src, json_sources, source_str,
mmss, src_uptime);
mmss, src_uptime,
src->source_creation);
}
}
}
Expand Down Expand Up @@ -1221,7 +1237,8 @@ static void igmp_sources_print(struct interface *ifp, char *group_str,
json_object_object_get_ex(json_group, "sources", &json_sources);
if (json_sources)
igmp_source_json_helper(src, json_sources, source_str,
mmss, uptime);
mmss, uptime,
src->source_creation);
} else {
vty_out(vty, "%-16s %-15s %-15s %5s %3s %8s\n", ifp->name,
group_str, source_str, mmss,
Expand Down

0 comments on commit a3a8eec

Please sign in to comment.