} /* scan interfaces */
}
-static void igmp_show_sources(struct pim_instance *pim, struct vty *vty)
+static void igmp_show_sources(struct pim_instance *pim, struct vty *vty,
+ bool uj)
{
struct interface *ifp;
time_t now;
+ json_object *json = NULL;
+ json_object *json_iface = NULL;
+ json_object *json_group = NULL;
+ json_object *json_source = NULL;
+ json_object *json_sources = NULL;
now = pim_time_monotonic_sec();
- vty_out(vty,
- "Interface Group Source Timer Fwd Uptime \n");
+ if (uj)
+ json = json_object_new_object();
+ else
+ vty_out(vty,
+ "Interface Address Group Source Timer Fwd Uptime \n");
/* scan interfaces */
FOR_ALL_INTERFACES (pim->vrf, ifp) {
pim_time_uptime(uptime, sizeof(uptime),
now - src->source_creation);
- vty_out(vty, "%-16s %-15s %-15s %5s %3s %8s\n",
- ifp->name, group_str, source_str, mmss,
- IGMP_SOURCE_TEST_FORWARDING(
- src->source_flags)
- ? "Y"
- : "N",
- uptime);
+ if (uj) {
+ json_object_object_get_ex(
+ json, ifp->name, &json_iface);
+ if (!json_iface) {
+ json_iface =
+ json_object_new_object();
+ json_object_string_add(
+ json_iface, "name",
+ ifp->name);
+ json_object_object_add(
+ json, ifp->name,
+ json_iface);
+ }
+ json_object_object_get_ex(json_iface,
+ group_str,
+ &json_group);
+
+ if (!json_group) {
+ json_group =
+ json_object_new_object();
+ json_object_string_add(
+ json_group, "group",
+ group_str);
+ json_object_object_add(
+ json_iface, group_str,
+ json_group);
+ json_sources =
+ json_object_new_array();
+ json_object_object_add(
+ json_group, "sources",
+ json_sources);
+ }
+ json_source = json_object_new_object();
+ 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_array_add(json_sources,
+ json_source);
+
+ } else {
+ vty_out(vty,
+ "%-16s %-15s %-15s %5s %3s %8s\n",
+ ifp->name, group_str,
+ source_str, mmss,
+ IGMP_SOURCE_TEST_FORWARDING(
+ src->source_flags)
+ ? "Y"
+ : "N",
+ uptime);
+ }
} /* scan group sources */
} /* scan igmp groups */
} /* scan interfaces */
+ if (uj)
+ vty_json(vty, json);
}
static void igmp_show_source_retransmission(struct pim_instance *pim,
DEFUN (show_ip_igmp_sources,
show_ip_igmp_sources_cmd,
- "show ip igmp [vrf NAME] sources",
+ "show ip igmp [vrf NAME] sources [json]",
SHOW_STR
IP_STR
IGMP_STR
VRF_CMD_HELP_STR
- IGMP_SOURCE_STR)
+ IGMP_SOURCE_STR
+ JSON_STR)
{
int idx = 2;
struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx);
if (!vrf)
return CMD_WARNING;
- igmp_show_sources(vrf->info, vty);
+ igmp_show_sources(vrf->info, vty, use_json(argc, argv));
return CMD_SUCCESS;
}