test/bonding: fix RSS test when disable RSS
[dpdk.git] / app / test-pmd / flowgen.c
index 9348618..1e01120 100644 (file)
@@ -24,7 +24,6 @@
 #include <rte_eal.h>
 #include <rte_per_lcore.h>
 #include <rte_lcore.h>
-#include <rte_atomic.h>
 #include <rte_branch_prediction.h>
 #include <rte_mempool.h>
 #include <rte_mbuf.h>
@@ -40,8 +39,6 @@
 
 #include "testpmd.h"
 
-/* hardcoded configuration (for now) */
-static unsigned cfg_n_flows    = 1024;
 static uint32_t cfg_ip_src     = RTE_IPV4(10, 254, 0, 0);
 static uint32_t cfg_ip_dst     = RTE_IPV4(10, 253, 0, 0);
 static uint16_t cfg_udp_src    = 1000;
@@ -76,6 +73,7 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
        uint64_t ol_flags = 0;
        uint16_t nb_rx;
        uint16_t nb_tx;
+       uint16_t nb_dropped;
        uint16_t nb_pkt;
        uint16_t nb_clones = nb_pkt_flowgen_clones;
        uint16_t i;
@@ -100,12 +98,12 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
        vlan_tci_outer = ports[fs->tx_port].tx_vlan_id_outer;
 
        tx_offloads = ports[fs->tx_port].dev_conf.txmode.offloads;
-       if (tx_offloads & DEV_TX_OFFLOAD_VLAN_INSERT)
-               ol_flags |= PKT_TX_VLAN_PKT;
-       if (tx_offloads & DEV_TX_OFFLOAD_QINQ_INSERT)
-               ol_flags |= PKT_TX_QINQ_PKT;
-       if (tx_offloads & DEV_TX_OFFLOAD_MACSEC_INSERT)
-               ol_flags |= PKT_TX_MACSEC;
+       if (tx_offloads & RTE_ETH_TX_OFFLOAD_VLAN_INSERT)
+               ol_flags |= RTE_MBUF_F_TX_VLAN;
+       if (tx_offloads & RTE_ETH_TX_OFFLOAD_QINQ_INSERT)
+               ol_flags |= RTE_MBUF_F_TX_QINQ;
+       if (tx_offloads & RTE_ETH_TX_OFFLOAD_MACSEC_INSERT)
+               ol_flags |= RTE_MBUF_F_TX_MACSEC;
 
        for (nb_pkt = 0; nb_pkt < nb_pkt_per_burst; nb_pkt++) {
                if (!nb_pkt || !nb_clones) {
@@ -123,8 +121,8 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
 
                        /* Initialize Ethernet header. */
                        eth_hdr = rte_pktmbuf_mtod(pkt, struct rte_ether_hdr *);
-                       rte_ether_addr_copy(&cfg_ether_dst, &eth_hdr->d_addr);
-                       rte_ether_addr_copy(&cfg_ether_src, &eth_hdr->s_addr);
+                       rte_ether_addr_copy(&cfg_ether_dst, &eth_hdr->dst_addr);
+                       rte_ether_addr_copy(&cfg_ether_src, &eth_hdr->src_addr);
                        eth_hdr->ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
 
                        /* Initialize IP header. */
@@ -153,7 +151,7 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
                                                                   sizeof(*ip_hdr));
                        pkt->nb_segs            = 1;
                        pkt->pkt_len            = pkt_size;
-                       pkt->ol_flags           &= EXT_ATTACHED_MBUF;
+                       pkt->ol_flags           &= RTE_MBUF_F_EXTERNAL;
                        pkt->ol_flags           |= ol_flags;
                        pkt->vlan_tci           = vlan_tci;
                        pkt->vlan_tci_outer     = vlan_tci_outer;
@@ -165,7 +163,7 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
                }
                pkts_burst[nb_pkt] = pkt;
 
-               if (++next_flow >= (int)cfg_n_flows)
+               if (++next_flow >= nb_flows_flowgen)
                        next_flow = 0;
        }
 
@@ -184,13 +182,14 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
        fs->tx_packets += nb_tx;
 
        inc_tx_burst_stats(fs, nb_tx);
-       if (unlikely(nb_tx < nb_pkt)) {
+       nb_dropped = nb_pkt - nb_tx;
+       if (unlikely(nb_dropped > 0)) {
                /* Back out the flow counter. */
-               next_flow -= (nb_pkt - nb_tx);
+               next_flow -= nb_dropped;
                while (next_flow < 0)
-                       next_flow += cfg_n_flows;
+                       next_flow += nb_flows_flowgen;
 
-               fs->fwd_dropped += nb_pkt - nb_tx;
+               fs->fwd_dropped += nb_dropped;
                do {
                        rte_pktmbuf_free(pkts_burst[nb_tx]);
                } while (++nb_tx < nb_pkt);
@@ -201,9 +200,29 @@ pkt_burst_flow_gen(struct fwd_stream *fs)
        get_end_cycles(fs, start_tsc);
 }
 
+static int
+flowgen_begin(portid_t pi)
+{
+       printf("  number of flows for port %u: %d\n", pi, nb_flows_flowgen);
+       return 0;
+}
+
+static void
+flowgen_stream_init(struct fwd_stream *fs)
+{
+       bool rx_stopped, tx_stopped;
+
+       rx_stopped = ports[fs->rx_port].rxq[fs->rx_queue].state ==
+                                               RTE_ETH_QUEUE_STATE_STOPPED;
+       tx_stopped = ports[fs->tx_port].txq[fs->tx_queue].state ==
+                                               RTE_ETH_QUEUE_STATE_STOPPED;
+       fs->disabled = rx_stopped || tx_stopped;
+}
+
 struct fwd_engine flow_gen_engine = {
        .fwd_mode_name  = "flowgen",
-       .port_fwd_begin = NULL,
+       .port_fwd_begin = flowgen_begin,
        .port_fwd_end   = NULL,
+       .stream_init    = flowgen_stream_init,
        .packet_fwd     = pkt_burst_flow_gen,
 };