app/testpmd: support unidirectional configuration
[dpdk.git] / app / test-pmd / testpmd.c
index 1ee935b..38b9051 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -354,17 +354,17 @@ set_default_fwd_lcores_config(void)
 
        nb_lc = 0;
        for (i = 0; i < RTE_MAX_LCORE; i++) {
-               if (! rte_lcore_is_enabled(i))
-                       continue;
-               if (i == rte_get_master_lcore())
-                       continue;
-               fwd_lcores_cpuids[nb_lc++] = i;
                sock_num = rte_lcore_to_socket_id(i) + 1;
                if (sock_num > max_socket) {
                        if (sock_num > RTE_MAX_NUMA_NODES)
                                rte_exit(EXIT_FAILURE, "Total sockets greater than %u\n", RTE_MAX_NUMA_NODES);
                        max_socket = sock_num;
                }
+               if (!rte_lcore_is_enabled(i))
+                       continue;
+               if (i == rte_get_master_lcore())
+                       continue;
+               fwd_lcores_cpuids[nb_lc++] = i;
        }
        nb_lcores = (lcoreid_t) nb_lc;
        nb_cfg_lcores = nb_lcores;
@@ -608,6 +608,7 @@ init_fwd_streams(void)
        portid_t pid;
        struct rte_port *port;
        streamid_t sm_id, nb_fwd_streams_new;
+       queueid_t q;
 
        /* set socket id according to numa or not */
        FOREACH_PORT(pid, ports) {
@@ -643,7 +644,12 @@ init_fwd_streams(void)
                }
        }
 
-       nb_fwd_streams_new = (streamid_t)(nb_ports * nb_rxq);
+       q = RTE_MAX(nb_rxq, nb_txq);
+       if (q == 0) {
+               printf("Fail: Cannot allocate fwd streams as number of queues is 0\n");
+               return -1;
+       }
+       nb_fwd_streams_new = (streamid_t)(nb_ports * q);
        if (nb_fwd_streams_new == nb_fwd_streams)
                return 0;
        /* clear the old */
@@ -754,9 +760,7 @@ fwd_port_stats_display(portid_t port_id, struct rte_eth_stats *stats)
                        printf("  Bad-ipcsum: %-14"PRIu64" Bad-l4csum: %-14"PRIu64" \n",
                               port->rx_bad_ip_csum, port->rx_bad_l4_csum);
                if (((stats->ierrors - stats->imissed) + stats->rx_nombuf) > 0) {
-                       printf("  RX-badcrc:  %-14"PRIu64" RX-badlen:  %-14"PRIu64
-                              "RX-error: %-"PRIu64"\n",
-                              stats->ibadcrc, stats->ibadlen, stats->ierrors);
+                       printf("  RX-error: %-"PRIu64"\n",  stats->ierrors);
                        printf("  RX-nombufs: %-14"PRIu64"\n", stats->rx_nombuf);
                }
 
@@ -775,9 +779,7 @@ fwd_port_stats_display(portid_t port_id, struct rte_eth_stats *stats)
                        printf("  Bad-ipcsum:%14"PRIu64"    Bad-l4csum:%14"PRIu64"\n",
                               port->rx_bad_ip_csum, port->rx_bad_l4_csum);
                if (((stats->ierrors - stats->imissed) + stats->rx_nombuf) > 0) {
-                       printf("  RX-badcrc:              %14"PRIu64"    RX-badlen: %14"PRIu64
-                              "    RX-error:%"PRIu64"\n",
-                              stats->ibadcrc, stats->ibadlen, stats->ierrors);
+                       printf("  RX-error:%"PRIu64"\n", stats->ierrors);
                        printf("  RX-nombufs:             %14"PRIu64"\n",
                               stats->rx_nombuf);
                }
@@ -788,15 +790,6 @@ fwd_port_stats_display(portid_t port_id, struct rte_eth_stats *stats)
                       (uint64_t) (stats->opackets + port->tx_dropped));
        }
 
-       /* Display statistics of XON/XOFF pause frames, if any. */
-       if ((stats->tx_pause_xon  | stats->rx_pause_xon |
-            stats->tx_pause_xoff | stats->rx_pause_xoff) > 0) {
-               printf("  RX-XOFF:    %-14"PRIu64" RX-XON:     %-14"PRIu64"\n",
-                      stats->rx_pause_xoff, stats->rx_pause_xon);
-               printf("  TX-XOFF:    %-14"PRIu64" TX-XON:     %-14"PRIu64"\n",
-                      stats->tx_pause_xoff, stats->tx_pause_xon);
-       }
-
 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
        if (port->rx_stream)
                pkt_burst_stats_display("RX",
@@ -805,11 +798,6 @@ fwd_port_stats_display(portid_t port_id, struct rte_eth_stats *stats)
                pkt_burst_stats_display("TX",
                        &port->tx_stream->tx_burst_stats);
 #endif
-       /* stats fdir */
-       if (fdir_conf.mode != RTE_FDIR_MODE_NONE)
-               printf("  Fdirmiss:%14"PRIu64"    Fdirmatch:%14"PRIu64"\n",
-                      stats->fdirmiss,
-                      stats->fdirmatch);
 
        if (port->rx_queue_stats_mapping_enabled) {
                printf("\n");
@@ -973,6 +961,19 @@ start_packet_forwarding(int with_tx_first)
        portid_t   pt_id;
        streamid_t sm_id;
 
+       if (strcmp(cur_fwd_eng->fwd_mode_name, "rxonly") == 0 && !nb_rxq)
+               rte_exit(EXIT_FAILURE, "rxq are 0, cannot use rxonly fwd mode\n");
+
+       if (strcmp(cur_fwd_eng->fwd_mode_name, "txonly") == 0 && !nb_txq)
+               rte_exit(EXIT_FAILURE, "txq are 0, cannot use txonly fwd mode\n");
+
+       if ((strcmp(cur_fwd_eng->fwd_mode_name, "rxonly") != 0 &&
+               strcmp(cur_fwd_eng->fwd_mode_name, "txonly") != 0) &&
+               (!nb_rxq || !nb_txq))
+               rte_exit(EXIT_FAILURE,
+                       "Either rxq or txq are 0, cannot use %s fwd mode\n",
+                       cur_fwd_eng->fwd_mode_name);
+
        if (all_ports_started() == 0) {
                printf("Not all ports were started\n");
                return;
@@ -1153,10 +1154,6 @@ stop_packet_forwarding(void)
                port->stats.oerrors = 0;
                stats.rx_nombuf -= port->stats.rx_nombuf;
                port->stats.rx_nombuf = 0;
-               stats.fdirmatch -= port->stats.fdirmatch;
-               port->stats.rx_nombuf = 0;
-               stats.fdirmiss -= port->stats.fdirmiss;
-               port->stats.rx_nombuf = 0;
 
                total_recv += stats.ipackets;
                total_xmit += stats.opackets;
@@ -1534,7 +1531,7 @@ attach_port(char *identifier)
        nb_ports = rte_eth_dev_count();
 
        /* set_default_fwd_ports_config(); */
-       bzero(fwd_ports_ids, sizeof(fwd_ports_ids));
+       memset(fwd_ports_ids, 0, sizeof(fwd_ports_ids));
        i = 0;
        FOREACH_PORT(j, ports) {
                fwd_ports_ids[i] = j;
@@ -1569,7 +1566,7 @@ detach_port(uint8_t port_id)
        nb_ports = rte_eth_dev_count();
 
        /* set_default_fwd_ports_config(); */
-       bzero(fwd_ports_ids, sizeof(fwd_ports_ids));
+       memset(fwd_ports_ids, 0, sizeof(fwd_ports_ids));
        i = 0;
        FOREACH_PORT(pi, ports) {
                fwd_ports_ids[i] = pi;
@@ -1592,13 +1589,16 @@ pmd_test_exit(void)
        if (test_done == 0)
                stop_packet_forwarding();
 
-       FOREACH_PORT(pt_id, ports) {
-               printf("Stopping port %d...", pt_id);
-               fflush(stdout);
-               rte_eth_dev_close(pt_id);
-               printf("done\n");
+       if (ports != NULL) {
+               no_link_check = 1;
+               FOREACH_PORT(pt_id, ports) {
+                       printf("\nShutting down port %d...\n", pt_id);
+                       fflush(stdout);
+                       stop_port(pt_id);
+                       close_port(pt_id);
+               }
        }
-       printf("bye...\n");
+       printf("\nBye...\n");
 }
 
 typedef void (*cmd_func_t)(void);
@@ -2006,12 +2006,35 @@ init_port(void)
                ports[pid].enabled = 1;
 }
 
+static void
+force_quit(void)
+{
+       pmd_test_exit();
+       prompt_exit();
+}
+
+static void
+signal_handler(int signum)
+{
+       if (signum == SIGINT || signum == SIGTERM) {
+               printf("\nSignal %d received, preparing to exit...\n",
+                               signum);
+               force_quit();
+               /* exit with the expected status */
+               signal(signum, SIG_DFL);
+               kill(getpid(), signum);
+       }
+}
+
 int
 main(int argc, char** argv)
 {
        int  diag;
        uint8_t port_id;
 
+       signal(SIGINT, signal_handler);
+       signal(SIGTERM, signal_handler);
+
        diag = rte_eal_init(argc, argv);
        if (diag < 0)
                rte_panic("Cannot init EAL\n");
@@ -2033,7 +2056,10 @@ main(int argc, char** argv)
        if (argc > 1)
                launch_args_parse(argc, argv);
 
-       if (nb_rxq > nb_txq)
+       if (!nb_rxq && !nb_txq)
+               printf("Warning: Either rx or tx queues should be non-zero\n");
+
+       if (nb_rxq > 1 && nb_rxq > nb_txq)
                printf("Warning: nb_rxq=%d enables RSS configuration, "
                       "but nb_txq=%d will prevent to fully test it.\n",
                       nb_rxq, nb_txq);
@@ -2063,6 +2089,7 @@ main(int argc, char** argv)
                start_packet_forwarding(0);
                printf("Press enter to exit\n");
                rc = read(0, &c, 1);
+               pmd_test_exit();
                if (rc < 0)
                        return 1;
        }