net: add rte prefix to ether functions
[dpdk.git] / app / test-pmd / util.c
index 3ba3b58..55f3844 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);
+       rte_ether_format_addr(buf, ETHER_ADDR_FMT_SIZE, eth_addr);
        printf("%s%s", what, buf);
 }
 
-void
+static inline void
 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;
@@ -109,9 +110,9 @@ dump_pkt_burst(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
                        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)) {
@@ -133,7 +134,7 @@ dump_pkt_burst(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
                                l2_len + l3_len);
                                l4_len = sizeof(struct 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,5 +148,75 @@ 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);
+       }
+}
+
+uint16_t
+dump_rx_pkts(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
+            uint16_t nb_pkts, __rte_unused uint16_t max_pkts,
+            __rte_unused void *user_param)
+{
+       dump_pkt_burst(port_id, queue, pkts, nb_pkts, 1);
+       return nb_pkts;
+}
+
+uint16_t
+dump_tx_pkts(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
+            uint16_t nb_pkts, __rte_unused void *user_param)
+{
+       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;
+               }
 }