test/hash: use existing lcore API
[dpdk.git] / app / test-pmd / util.c
index f4125df..a1164b7 100644 (file)
 #include "testpmd.h"
 
 static inline void
-print_ether_addr(const char *what, struct ether_addr *eth_addr)
+print_ether_addr(const char *what, struct rte_ether_addr *eth_addr)
 {
-       char buf[ETHER_ADDR_FMT_SIZE];
-       ether_format_addr(buf, ETHER_ADDR_FMT_SIZE, eth_addr);
+       char buf[RTE_ETHER_ADDR_FMT_SIZE];
+       rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr);
        printf("%s%s", what, buf);
 }
 
@@ -26,7 +26,7 @@ dump_pkt_burst(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
              uint16_t nb_pkts, int is_rx)
 {
        struct rte_mbuf  *mb;
-       struct ether_hdr *eth_hdr;
+       struct rte_ether_hdr *eth_hdr;
        uint16_t eth_type;
        uint64_t ol_flags;
        uint16_t i, packet_type;
@@ -36,6 +36,7 @@ dump_pkt_burst(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
        uint32_t sw_packet_type;
        uint16_t udp_port;
        uint32_t vx_vni;
+       const char *reason;
 
        if (!nb_pkts)
                return;
@@ -45,7 +46,7 @@ dump_pkt_burst(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
               (unsigned int) nb_pkts);
        for (i = 0; i < nb_pkts; i++) {
                mb = pkts[i];
-               eth_hdr = rte_pktmbuf_mtod(mb, struct ether_hdr *);
+               eth_hdr = rte_pktmbuf_mtod(mb, struct rte_ether_hdr *);
                eth_type = RTE_BE_TO_CPU_16(eth_hdr->ether_type);
                ol_flags = mb->ol_flags;
                packet_type = mb->packet_type;
@@ -102,38 +103,38 @@ dump_pkt_burst(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
                if (sw_packet_type & RTE_PTYPE_INNER_L4_MASK)
                        printf(" - inner_l4_len=%d", hdr_lens.inner_l4_len);
                if (is_encapsulation) {
-                       struct ipv4_hdr *ipv4_hdr;
-                       struct ipv6_hdr *ipv6_hdr;
-                       struct udp_hdr *udp_hdr;
+                       struct rte_ipv4_hdr *ipv4_hdr;
+                       struct rte_ipv6_hdr *ipv6_hdr;
+                       struct rte_udp_hdr *udp_hdr;
                        uint8_t l2_len;
                        uint8_t l3_len;
                        uint8_t l4_len;
                        uint8_t l4_proto;
-                       struct  vxlan_hdr *vxlan_hdr;
+                       struct  rte_vxlan_hdr *vxlan_hdr;
 
-                       l2_len  = sizeof(struct ether_hdr);
+                       l2_len  = sizeof(struct rte_ether_hdr);
 
                        /* Do not support ipv4 option field */
                        if (RTE_ETH_IS_IPV4_HDR(packet_type)) {
-                               l3_len = sizeof(struct ipv4_hdr);
+                               l3_len = sizeof(struct rte_ipv4_hdr);
                                ipv4_hdr = rte_pktmbuf_mtod_offset(mb,
-                               struct ipv4_hdr *,
+                               struct rte_ipv4_hdr *,
                                l2_len);
                                l4_proto = ipv4_hdr->next_proto_id;
                        } else {
-                               l3_len = sizeof(struct ipv6_hdr);
+                               l3_len = sizeof(struct rte_ipv6_hdr);
                                ipv6_hdr = rte_pktmbuf_mtod_offset(mb,
-                               struct ipv6_hdr *,
+                               struct rte_ipv6_hdr *,
                                l2_len);
                                l4_proto = ipv6_hdr->proto;
                        }
                        if (l4_proto == IPPROTO_UDP) {
                                udp_hdr = rte_pktmbuf_mtod_offset(mb,
-                               struct udp_hdr *,
+                               struct rte_udp_hdr *,
                                l2_len + l3_len);
-                               l4_len = sizeof(struct udp_hdr);
+                               l4_len = sizeof(struct rte_udp_hdr);
                                vxlan_hdr = rte_pktmbuf_mtod_offset(mb,
-                               struct vxlan_hdr *,
+                               struct rte_vxlan_hdr *,
                                l2_len + l3_len + l4_len);
                                udp_port = RTE_BE_TO_CPU_16(udp_hdr->dst_port);
                                vx_vni = rte_be_to_cpu_32(vxlan_hdr->vx_vni);
@@ -147,6 +148,8 @@ dump_pkt_burst(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
                printf("\n");
                rte_get_rx_ol_flag_list(mb->ol_flags, buf, sizeof(buf));
                printf("  ol_flags: %s\n", buf);
+               if (rte_mbuf_check(mb, 1, &reason) < 0)
+                       printf("INVALID mbuf: %s\n", reason);
        }
 }
 
@@ -166,3 +169,54 @@ dump_tx_pkts(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
        dump_pkt_burst(port_id, queue, pkts, nb_pkts, 0);
        return nb_pkts;
 }
+
+uint16_t
+tx_pkt_set_md(uint16_t port_id, __rte_unused uint16_t queue,
+             struct rte_mbuf *pkts[], uint16_t nb_pkts,
+             __rte_unused void *user_param)
+{
+       uint16_t i = 0;
+
+       /*
+        * Add metadata value to every Tx packet,
+        * and set ol_flags accordingly.
+        */
+       for (i = 0; i < nb_pkts; i++) {
+               pkts[i]->tx_metadata = ports[port_id].tx_metadata;
+               pkts[i]->ol_flags |= PKT_TX_METADATA;
+       }
+       return nb_pkts;
+}
+
+void
+add_tx_md_callback(portid_t portid)
+{
+       struct rte_eth_dev_info dev_info;
+       uint16_t queue;
+
+       if (port_id_is_invalid(portid, ENABLED_WARN))
+               return;
+       rte_eth_dev_info_get(portid, &dev_info);
+       for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
+               if (!ports[portid].tx_set_md_cb[queue])
+                       ports[portid].tx_set_md_cb[queue] =
+                               rte_eth_add_tx_callback(portid, queue,
+                                                       tx_pkt_set_md, NULL);
+}
+
+void
+remove_tx_md_callback(portid_t portid)
+{
+       struct rte_eth_dev_info dev_info;
+       uint16_t queue;
+
+       if (port_id_is_invalid(portid, ENABLED_WARN))
+               return;
+       rte_eth_dev_info_get(portid, &dev_info);
+       for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
+               if (ports[portid].tx_set_md_cb[queue]) {
+                       rte_eth_remove_tx_callback(portid, queue,
+                               ports[portid].tx_set_md_cb[queue]);
+                       ports[portid].tx_set_md_cb[queue] = NULL;
+               }
+}