diff options
author | Sai Gomathi N <nsaigomathi@vmware.com> | 2022-03-02 10:22:13 +0100 |
---|---|---|
committer | Sai Gomathi N <nsaigomathi@vmware.com> | 2022-04-04 09:52:03 +0200 |
commit | 1295dbebe8b581e5f4337495ca6d2c728e8826d9 (patch) | |
tree | a6f55c4b990a31edcb216dcc776c0cfcd9bee585 | |
parent | pim6d: Adding "show ipv6 pim local-membership" (diff) | |
download | frr-1295dbebe8b581e5f4337495ca6d2c728e8826d9.tar.xz frr-1295dbebe8b581e5f4337495ca6d2c728e8826d9.zip |
pim6d: Adding "show ipv6 [vrf|vrf ALL] pim neighbor" command
Adding new show CLI to display regarding pim neighbors.
Changing DEFUN to DEFPY for "show ip pim neighbor" command.
Signed-off-by: Sai Gomathi N <nsaigomathi@vmware.com>
-rw-r--r-- | pimd/pim6_cmd.c | 75 | ||||
-rw-r--r-- | pimd/pim_cmd.c | 71 | ||||
-rw-r--r-- | pimd/pim_cmd_common.c | 23 | ||||
-rw-r--r-- | pimd/pim_cmd_common.h | 5 |
4 files changed, 125 insertions, 49 deletions
diff --git a/pimd/pim6_cmd.c b/pimd/pim6_cmd.c index a1a6d9d3f..aa264c475 100644 --- a/pimd/pim6_cmd.c +++ b/pimd/pim6_cmd.c @@ -1306,6 +1306,79 @@ DEFPY (show_ipv6_pim_local_membership, return CMD_SUCCESS; } +DEFPY (show_ipv6_pim_neighbor, + show_ipv6_pim_neighbor_cmd, + "show ipv6 pim [vrf NAME] neighbor [detail|WORD]$interface [json$json]", + SHOW_STR + IPV6_STR + PIM_STR + VRF_CMD_HELP_STR + "PIM neighbor information\n" + "Detailed output\n" + "Name of interface or neighbor\n" + JSON_STR) +{ + struct vrf *v; + json_object *json_parent = NULL; + + v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); + + if (!v) + return CMD_WARNING; + + if (json) + json_parent = json_object_new_object(); + + if (interface) + pim_show_neighbors_single(v->info, vty, interface, json_parent); + else + pim_show_neighbors(v->info, vty, json_parent); + + if (json) + vty_json(vty, json_parent); + + return CMD_SUCCESS; +} + +DEFPY (show_ipv6_pim_neighbor_vrf_all, + show_ipv6_pim_neighbor_vrf_all_cmd, + "show ipv6 pim vrf all neighbor [detail|WORD]$interface [json$json]", + SHOW_STR + IPV6_STR + PIM_STR + VRF_CMD_HELP_STR + "PIM neighbor information\n" + "Detailed output\n" + "Name of interface or neighbor\n" + JSON_STR) +{ + struct vrf *v; + json_object *json_parent = NULL; + json_object *json_vrf = NULL; + + if (json) + json_parent = json_object_new_object(); + RB_FOREACH (v, vrf_name_head, &vrfs_by_name) { + if (!json) + vty_out(vty, "VRF: %s\n", v->name); + else + json_vrf = json_object_new_object(); + + if (interface) + pim_show_neighbors_single(v->info, vty, interface, + json_vrf); + else + pim_show_neighbors(v->info, vty, json_vrf); + + if (json) + json_object_object_add(json_parent, v->name, json_vrf); + } + if (json) + vty_json(vty, json_parent); + + return CMD_SUCCESS; +} + void pim_cmd_init(void) { if_cmd_init(pim_interface_config_write); @@ -1377,4 +1450,6 @@ void pim_cmd_init(void) install_element(VIEW_NODE, &show_ipv6_pim_join_vrf_all_cmd); install_element(VIEW_NODE, &show_ipv6_pim_jp_agg_cmd); install_element(VIEW_NODE, &show_ipv6_pim_local_membership_cmd); + install_element(VIEW_NODE, &show_ipv6_pim_neighbor_cmd); + install_element(VIEW_NODE, &show_ipv6_pim_neighbor_vrf_all_cmd); } diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index bd7e24bd0..3b6a62d65 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -2983,9 +2983,9 @@ DEFUN(show_ip_pim_mlag_up_vrf_all, show_ip_pim_mlag_up_vrf_all_cmd, return CMD_SUCCESS; } -DEFUN (show_ip_pim_neighbor, +DEFPY (show_ip_pim_neighbor, show_ip_pim_neighbor_cmd, - "show ip pim [vrf NAME] neighbor [detail|WORD] [json]", + "show ip pim [vrf NAME] neighbor [detail|WORD]$interface [json$json]", SHOW_STR IP_STR PIM_STR @@ -2995,25 +2995,31 @@ DEFUN (show_ip_pim_neighbor, "Name of interface or neighbor\n" JSON_STR) { - int idx = 2; - struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx); - bool uj = use_json(argc, argv); + struct vrf *v; + json_object *json_parent = NULL; - if (!vrf) + v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); + + if (!v) return CMD_WARNING; - if (argv_find(argv, argc, "detail", &idx) - || argv_find(argv, argc, "WORD", &idx)) - pim_show_neighbors_single(vrf->info, vty, argv[idx]->arg, uj); + if (json) + json_parent = json_object_new_object(); + + if (interface) + pim_show_neighbors_single(v->info, vty, interface, json_parent); else - pim_show_neighbors(vrf->info, vty, uj); + pim_show_neighbors(v->info, vty, json_parent); + + if (json) + vty_json(vty, json_parent); return CMD_SUCCESS; } -DEFUN (show_ip_pim_neighbor_vrf_all, +DEFPY (show_ip_pim_neighbor_vrf_all, show_ip_pim_neighbor_vrf_all_cmd, - "show ip pim vrf all neighbor [detail|WORD] [json]", + "show ip pim vrf all neighbor [detail|WORD]$interface [json$json]", SHOW_STR IP_STR PIM_STR @@ -3023,30 +3029,29 @@ DEFUN (show_ip_pim_neighbor_vrf_all, "Name of interface or neighbor\n" JSON_STR) { - int idx = 2; - bool uj = use_json(argc, argv); - struct vrf *vrf; - bool first = true; + struct vrf *v; + json_object *json_parent = NULL; + json_object *json_vrf = NULL; - if (uj) - vty_out(vty, "{ "); - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - if (uj) { - if (!first) - vty_out(vty, ", "); - vty_out(vty, " \"%s\": ", vrf->name); - first = false; - } else - vty_out(vty, "VRF: %s\n", vrf->name); - if (argv_find(argv, argc, "detail", &idx) - || argv_find(argv, argc, "WORD", &idx)) - pim_show_neighbors_single(vrf->info, vty, - argv[idx]->arg, uj); + if (json) + json_parent = json_object_new_object(); + RB_FOREACH (v, vrf_name_head, &vrfs_by_name) { + if (!json) + vty_out(vty, "VRF: %s\n", v->name); else - pim_show_neighbors(vrf->info, vty, uj); + json_vrf = json_object_new_object(); + + if (interface) + pim_show_neighbors_single(v->info, vty, interface, + json_vrf); + else + pim_show_neighbors(v->info, vty, json_vrf); + + if (json) + json_object_object_add(json_parent, v->name, json_vrf); } - if (uj) - vty_out(vty, "}\n"); + if (json) + vty_json(vty, json_parent); return CMD_SUCCESS; } diff --git a/pimd/pim_cmd_common.c b/pimd/pim_cmd_common.c index 441a00816..0d575a145 100644 --- a/pimd/pim_cmd_common.c +++ b/pimd/pim_cmd_common.c @@ -2677,7 +2677,8 @@ void pim_show_neighbors_single(struct pim_instance *pim, struct vty *vty, vty_out(vty, "%% No such interface or neighbor\n"); } -void pim_show_neighbors(struct pim_instance *pim, struct vty *vty, bool uj) +void pim_show_neighbors(struct pim_instance *pim, struct vty *vty, + json_object *json) { struct listnode *neighnode; struct interface *ifp; @@ -2686,16 +2687,13 @@ void pim_show_neighbors(struct pim_instance *pim, struct vty *vty, bool uj) time_t now; char uptime[10]; char expire[10]; - char neigh_src_str[INET_ADDRSTRLEN]; - json_object *json = NULL; + char neigh_src_str[PIM_ADDRSTRLEN]; json_object *json_ifp_rows = NULL; json_object *json_row = NULL; now = pim_time_monotonic_sec(); - if (uj) { - json = json_object_new_object(); - } else { + if (!json) { vty_out(vty, "Interface Neighbor Uptime Holdtime DR Pri\n"); } @@ -2709,19 +2707,19 @@ void pim_show_neighbors(struct pim_instance *pim, struct vty *vty, bool uj) if (pim_ifp->pim_sock_fd < 0) continue; - if (uj) + if (json) json_ifp_rows = json_object_new_object(); for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list, neighnode, neigh)) { - pim_inet4_dump("<src?>", neigh->source_addr, - neigh_src_str, sizeof(neigh_src_str)); + snprintfrr(neigh_src_str, sizeof(neigh_src_str), + "%pPAs", &neigh->source_addr); pim_time_uptime(uptime, sizeof(uptime), now - neigh->creation); pim_time_timer_to_hhmmss(expire, sizeof(expire), neigh->t_expire_timer); - if (uj) { + if (json) { json_row = json_object_new_object(); json_object_string_add(json_row, "interface", ifp->name); @@ -2745,12 +2743,9 @@ void pim_show_neighbors(struct pim_instance *pim, struct vty *vty, bool uj) } } - if (uj) { + if (json) { json_object_object_add(json, ifp->name, json_ifp_rows); json_ifp_rows = NULL; } } - - if (uj) - vty_json(vty, json); } diff --git a/pimd/pim_cmd_common.h b/pimd/pim_cmd_common.h index 13fd40b99..00a9a5673 100644 --- a/pimd/pim_cmd_common.h +++ b/pimd/pim_cmd_common.h @@ -90,8 +90,9 @@ void ip_pim_ssm_show_group_range(struct pim_instance *pim, struct vty *vty, bool uj); void pim_show_nexthop(struct pim_instance *pim, struct vty *vty); void pim_show_neighbors_single(struct pim_instance *pim, struct vty *vty, - const char *neighbor, bool uj); -void pim_show_neighbors(struct pim_instance *pim, struct vty *vty, bool uj); + const char *neighbor, json_object *json); +void pim_show_neighbors(struct pim_instance *pim, struct vty *vty, + json_object *json); /* * Special Macro to allow us to get the correct pim_instance */ |