app/testpmd: fix metering and policing command for RFC4115
[dpdk.git] / app / test-pmd / icmpecho.c
index 65aece1..99c94cb 100644 (file)
@@ -20,7 +20,6 @@
 #include <rte_cycles.h>
 #include <rte_per_lcore.h>
 #include <rte_lcore.h>
-#include <rte_atomic.h>
 #include <rte_branch_prediction.h>
 #include <rte_memory.h>
 #include <rte_mempool.h>
@@ -54,7 +53,7 @@ arp_op_name(uint16_t arp_op)
        default:
                break;
        }
-       return "Unkwown ARP op";
+       return "Unknown ARP op";
 }
 
 static const char *
@@ -293,27 +292,19 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
        uint32_t cksum;
        uint8_t  i;
        int l2_len;
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
-       uint64_t start_tsc;
-       uint64_t end_tsc;
-       uint64_t core_cycles;
-#endif
+       uint64_t start_tsc = 0;
 
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
-       start_tsc = rte_rdtsc();
-#endif
+       get_start_cycles(&start_tsc);
 
        /*
         * First, receive a burst of packets.
         */
        nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
                                 nb_pkt_per_burst);
+       inc_rx_burst_stats(fs, nb_rx);
        if (unlikely(nb_rx == 0))
                return;
 
-#ifdef RTE_TEST_PMD_RECORD_BURST_STATS
-       fs->rx_burst_stats.pkt_burst_spread[nb_rx]++;
-#endif
        fs->rx_packets += nb_rx;
        nb_replies = 0;
        for (i = 0; i < nb_rx; i++) {
@@ -327,8 +318,8 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
                if (verbose_level > 0) {
                        printf("\nPort %d pkt-len=%u nb-segs=%u\n",
                               fs->rx_port, pkt->pkt_len, pkt->nb_segs);
-                       ether_addr_dump("  ETH:  src=", &eth_h->s_addr);
-                       ether_addr_dump(" dst=", &eth_h->d_addr);
+                       ether_addr_dump("  ETH:  src=", &eth_h->src_addr);
+                       ether_addr_dump(" dst=", &eth_h->dst_addr);
                }
                if (eth_type == RTE_ETHER_TYPE_VLAN) {
                        vlan_h = (struct rte_vlan_hdr *)
@@ -393,17 +384,17 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
                         */
 
                        /* Use source MAC address as destination MAC address. */
-                       rte_ether_addr_copy(&eth_h->s_addr, &eth_h->d_addr);
+                       rte_ether_addr_copy(&eth_h->src_addr, &eth_h->dst_addr);
                        /* Set source MAC address with MAC address of TX port */
                        rte_ether_addr_copy(&ports[fs->tx_port].eth_addr,
-                                       &eth_h->s_addr);
+                                       &eth_h->src_addr);
 
                        arp_h->arp_opcode = rte_cpu_to_be_16(RTE_ARP_OP_REPLY);
                        rte_ether_addr_copy(&arp_h->arp_data.arp_tha,
                                        &eth_addr);
                        rte_ether_addr_copy(&arp_h->arp_data.arp_sha,
                                        &arp_h->arp_data.arp_tha);
-                       rte_ether_addr_copy(&eth_h->s_addr,
+                       rte_ether_addr_copy(&eth_h->src_addr,
                                        &arp_h->arp_data.arp_sha);
 
                        /* Swap IP addresses in ARP payload */
@@ -461,9 +452,9 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
                 * ICMP checksum is computed by assuming it is valid in the
                 * echo request and not verified.
                 */
-               rte_ether_addr_copy(&eth_h->s_addr, &eth_addr);
-               rte_ether_addr_copy(&eth_h->d_addr, &eth_h->s_addr);
-               rte_ether_addr_copy(&eth_addr, &eth_h->d_addr);
+               rte_ether_addr_copy(&eth_h->src_addr, &eth_addr);
+               rte_ether_addr_copy(&eth_h->dst_addr, &eth_h->src_addr);
+               rte_ether_addr_copy(&eth_addr, &eth_h->dst_addr);
                ip_addr = ip_h->src_addr;
                if (is_multicast_ipv4_addr(ip_h->dst_addr)) {
                        uint32_t ip_src;
@@ -482,8 +473,8 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
                }
                icmp_h->icmp_type = RTE_IP_ICMP_ECHO_REPLY;
                cksum = ~icmp_h->icmp_cksum & 0xffff;
-               cksum += ~htons(RTE_IP_ICMP_ECHO_REQUEST << 8) & 0xffff;
-               cksum += htons(RTE_IP_ICMP_ECHO_REPLY << 8);
+               cksum += ~RTE_BE16(RTE_IP_ICMP_ECHO_REQUEST << 8) & 0xffff;
+               cksum += RTE_BE16(RTE_IP_ICMP_ECHO_REPLY << 8);
                cksum = (cksum & 0xffff) + (cksum >> 16);
                cksum = (cksum & 0xffff) + (cksum >> 16);
                icmp_h->icmp_cksum = ~cksum;
@@ -509,9 +500,7 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
                        }
                }
                fs->tx_packets += nb_tx;
-#ifdef RTE_TEST_PMD_RECORD_BURST_STATS
-               fs->tx_burst_stats.pkt_burst_spread[nb_tx]++;
-#endif
+               inc_tx_burst_stats(fs, nb_tx);
                if (unlikely(nb_tx < nb_replies)) {
                        fs->fwd_dropped += (nb_replies - nb_tx);
                        do {
@@ -520,11 +509,7 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
                }
        }
 
-#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
-       end_tsc = rte_rdtsc();
-       core_cycles = (end_tsc - start_tsc);
-       fs->core_cycles = (uint64_t) (fs->core_cycles + core_cycles);
-#endif
+       get_end_cycles(fs, start_tsc);
 }
 
 struct fwd_engine icmp_echo_engine = {