]> git.puffer.fish Git - mirror/frr.git/commitdiff
pimd: Change to DEFPY and make the api common
authorMobashshera Rasool <mrasool@vmware.com>
Wed, 1 Jun 2022 15:58:33 +0000 (08:58 -0700)
committerMobashshera Rasool <mrasool@vmware.com>
Mon, 13 Jun 2022 04:24:01 +0000 (21:24 -0700)
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>
pimd/pim_cmd.c
pimd/pim_cmd_common.c
pimd/pim_cmd_common.h

index 2e4c98f7568fadeed03add10a9c23c24ffe94e1a..817ebcc256e0c06a06552f029ed58276e2f93b1a 100644 (file)
@@ -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,
index bfa0ddec6981adf796d4ab38cd6f1943a39b9219..2e03bac945846b434ef839d9d55d79165ec43ab9 100644 (file)
@@ -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;
+}
index ead6c9b488cb93837bb74742ecb1d39e6ff17e35..67e092e0794550af8f7d4a2ee46f978182f4e612 100644 (file)
@@ -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;
  */