diff options
author | Mobashshera Rasool <mrasool@vmware.com> | 2022-06-01 17:58:33 +0200 |
---|---|---|
committer | Mobashshera Rasool <mrasool@vmware.com> | 2022-06-13 06:24:01 +0200 |
commit | 52770b79a801533c9d3b0409bc873bfe9a359f72 (patch) | |
tree | 66d61feac794e8db3b7a801e43a5715c2d8b9fa8 /pimd | |
parent | pim6d: Moving show apis to common file (diff) | |
download | frr-52770b79a801533c9d3b0409bc873bfe9a359f72.tar.xz frr-52770b79a801533c9d3b0409bc873bfe9a359f72.zip |
pimd: Change to DEFPY and make the api common
For show ip pim interface traffic cli, doing the below changes
1. Changing DEFUN to DEFPY
2. Move the whole code to a common api and modify it so that can
be reused for pimv6.
Signed-off-by: Mobashshera Rasool <mrasool@vmware.com>
Diffstat (limited to 'pimd')
-rw-r--r-- | pimd/pim_cmd.c | 19 | ||||
-rw-r--r-- | pimd/pim_cmd_common.c | 26 | ||||
-rw-r--r-- | pimd/pim_cmd_common.h | 2 |
3 files changed, 31 insertions, 16 deletions
diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index 2e4c98f75..817ebcc25 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -2806,9 +2806,9 @@ DEFPY (show_ip_pim_nexthop_lookup, return pim_show_nexthop_lookup_cmd_helper(vrf, vty, source, group); } -DEFUN (show_ip_pim_interface_traffic, +DEFPY (show_ip_pim_interface_traffic, show_ip_pim_interface_traffic_cmd, - "show ip pim [vrf NAME] interface traffic [WORD] [json]", + "show ip pim [vrf NAME] interface traffic [WORD$if_name] [json$json]", SHOW_STR IP_STR PIM_STR @@ -2818,20 +2818,7 @@ DEFUN (show_ip_pim_interface_traffic, "Interface name\n" JSON_STR) { - int idx = 2; - struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx); - bool uj = use_json(argc, argv); - - if (!vrf) - return CMD_WARNING; - - if (argv_find(argv, argc, "WORD", &idx)) - pim_show_interface_traffic_single(vrf->info, vty, - argv[idx]->arg, uj); - else - pim_show_interface_traffic(vrf->info, vty, uj); - - return CMD_SUCCESS; + return pim_show_interface_traffic_helper(vrf, if_name, vty, !!json); } DEFUN (show_ip_pim_bsm_db, diff --git a/pimd/pim_cmd_common.c b/pimd/pim_cmd_common.c index bfa0ddec6..2e03bac94 100644 --- a/pimd/pim_cmd_common.c +++ b/pimd/pim_cmd_common.c @@ -4825,3 +4825,29 @@ void pim_show_interface_traffic_single(struct pim_instance *pim, else if (!found_ifname) vty_out(vty, "%% No such interface\n"); } + +int pim_show_interface_traffic_helper(const char *vrf, const char *if_name, + struct vty *vty, bool uj) +{ + struct pim_instance *pim; + struct vrf *v; + + v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); + + if (!v) + return CMD_WARNING; + + pim = pim_get_pim_instance(v->vrf_id); + + if (!pim) { + vty_out(vty, "%% Unable to find pim instance\n"); + return CMD_WARNING; + } + + if (if_name) + pim_show_interface_traffic_single(v->info, vty, if_name, uj); + else + pim_show_interface_traffic(v->info, vty, uj); + + return CMD_SUCCESS; +} diff --git a/pimd/pim_cmd_common.h b/pimd/pim_cmd_common.h index ead6c9b48..67e092e07 100644 --- a/pimd/pim_cmd_common.h +++ b/pimd/pim_cmd_common.h @@ -185,6 +185,8 @@ void pim_show_interface_traffic_single(struct pim_instance *pim, bool uj); void pim_show_interface_traffic(struct pim_instance *pim, struct vty *vty, bool uj); +int pim_show_interface_traffic_helper(const char *vrf, const char *if_name, + struct vty *vty, bool uj); /* * Special Macro to allow us to get the correct pim_instance; */ |