Simplify cores_task_are_valid()
[samplevnf.git] / VNFs / DPPD-PROX / cmd_parser.c
index f88ee94..927abc2 100644 (file)
@@ -76,19 +76,8 @@ static int cores_task_are_valid(unsigned int *lcores, int task_id, unsigned int
        unsigned int lcore_id;
        for (unsigned int i = 0; i < nb_cores; i++) {
                lcore_id = lcores[i];
-               if (lcore_id >= RTE_MAX_LCORE) {
-                       plog_err("Invalid core id %u (lcore ID above %d)\n", lcore_id, RTE_MAX_LCORE);
+               if (core_task_is_valid(lcore_id, task_id) == 0)
                        return 0;
-               }
-               else if (!prox_core_active(lcore_id, 0)) {
-                       plog_err("Invalid core id %u (lcore is not active)\n", lcore_id);
-                       return 0;
-               }
-               else if (task_id >= lcore_cfg[lcore_id].n_tasks_all) {
-                       plog_err("Invalid task id (valid task IDs for core %u are below %u)\n",
-                               lcore_id, lcore_cfg[lcore_id].n_tasks_all);
-                       return 0;
-               }
        }
        return 1;
 }
@@ -1582,6 +1571,49 @@ static int parse_cmd_port_stats(const char *str, struct input *input)
        return 0;
 }
 
+static int parse_cmd_multi_port_stats(const char *str, struct input *input)
+{
+       uint32_t ports[PROX_MAX_PORTS];
+       int nb_ports = parse_list_set(ports, str, PROX_MAX_PORTS);
+       if (nb_ports <= 0) {
+               return -1;
+       }
+
+       char buf[PROX_MAX_PORTS * (11+5*21) + 1], *pbuf = buf;
+       int left = sizeof(buf);
+       for (int i = 0; i < nb_ports; ++i) {
+               struct get_port_stats s;
+               if (stats_port(ports[i], &s)) {
+                       plog_err("Invalid port %u\n", ports[i]);
+                       return 0;
+               }
+
+               int len = snprintf(pbuf, left,
+                               "%u,"
+                               "%"PRIu64",%"PRIu64","
+                               "%"PRIu64",%"PRIu64","
+                               "%"PRIu64";",
+                               //TODO: adjust buf size above when adding fields
+                               ports[i],
+                               s.rx_tot, s.tx_tot,
+                               s.no_mbufs_tot, s.ierrors_tot + s.imissed_tot,
+                               s.last_tsc);
+               if ((len < 0) || (len >= left)) {
+                       plog_err("Cannot print stats for port %u\n", ports[i]);
+                       return 0;
+               }
+               pbuf += len;
+               left -= len;
+       }
+       pbuf--;
+       *pbuf = '\n';
+
+       plog_info("%s", buf);
+       if (input->reply)
+               input->reply(input, buf, sizeof(buf) - left);
+       return 0;
+}
+
 static int parse_cmd_core_stats(const char *str, struct input *input)
 {
        unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
@@ -1613,6 +1645,39 @@ static int parse_cmd_core_stats(const char *str, struct input *input)
        return 0;
 }
 
+static int parse_cmd_dp_core_stats(const char *str, struct input *input)
+{
+       unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
+
+       if (parse_core_task(str, lcores, &task_id, &nb_cores))
+               return -1;
+
+       if (cores_task_are_valid(lcores, task_id, nb_cores)) {
+               for (unsigned int i = 0; i < nb_cores; i++) {
+                       lcore_id = lcores[i];
+                       uint64_t tot_rx = stats_core_task_tot_rx(lcore_id, task_id);
+                       uint64_t tot_tx = stats_core_task_tot_tx(lcore_id, task_id);
+                       uint64_t tot_rx_non_dp = stats_core_task_tot_rx_non_dp(lcore_id, task_id);
+                       uint64_t tot_tx_non_dp = stats_core_task_tot_tx_non_dp(lcore_id, task_id);
+                       uint64_t tot_drop = stats_core_task_tot_drop(lcore_id, task_id);
+                       uint64_t last_tsc = stats_core_task_last_tsc(lcore_id, task_id);
+
+                       if (input->reply) {
+                               char buf[128];
+                               snprintf(buf, sizeof(buf),
+                                       "%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64"\n",
+                                       tot_rx, tot_tx, tot_rx_non_dp, tot_tx_non_dp, tot_drop, last_tsc, rte_get_tsc_hz());
+                               input->reply(input, buf, strlen(buf));
+                       }
+                       else {
+                               plog_info("RX: %"PRIu64", TX: %"PRIu64", RX_NON_DP:  %"PRIu64", TX_NON_DP: %"PRIu64", DROP: %"PRIu64"\n",
+                                       tot_rx, tot_tx, tot_rx_non_dp, tot_tx_non_dp, tot_drop);
+                       }
+               }
+       }
+       return 0;
+}
+
 static int parse_cmd_lat_stats(const char *str, struct input *input)
 {
        unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
@@ -1932,7 +1997,9 @@ static struct cmd_str cmd_strings[] = {
        {"lat packets", "<core id> <task id>", "Print the latency for each of the last set of packets", parse_cmd_lat_packets},
        {"accuracy limit", "<core id> <task id> <nsec>", "Only consider latency of packets that were measured with an error no more than <nsec>", parse_cmd_accuracy},
        {"core stats", "<core id> <task id>", "Print rx/tx/drop for task <task id> running on core <core id>", parse_cmd_core_stats},
+       {"dp core stats", "<core id> <task id>", "Print rx/tx/non_dp_rx/non_dp_tx/drop for task <task id> running on core <core id>", parse_cmd_dp_core_stats},
        {"port_stats", "<port id>", "Print rate for no_mbufs, ierrors + imissed, rx_bytes, tx_bytes, rx_pkts, tx_pkts; totals for RX, TX, no_mbufs, ierrors + imissed for port <port id>", parse_cmd_port_stats},
+       {"multi port stats", "<port list>", "Get stats for multiple ports, semi-colon separated: port id, total for rx_pkts, tx_pkts, no_mbufs, ierrors + imissed, last_tsc", parse_cmd_multi_port_stats},
        {"read reg", "", "Read register", parse_cmd_read_reg},
        {"write reg", "", "Read register", parse_cmd_write_reg},
        {"set vlan offload", "", "Set Vlan offload", parse_cmd_set_vlan_offload},