1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
3 * Copyright(c) 2018 Mellanox Technology
10 #include <rte_ether.h>
11 #include <rte_vxlan.h>
12 #include <rte_ethdev.h>
18 print_ether_addr(const char *what, const struct rte_ether_addr *eth_addr)
20 char buf[RTE_ETHER_ADDR_FMT_SIZE];
21 rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr);
22 printf("%s%s", what, buf);
26 dump_pkt_burst(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
27 uint16_t nb_pkts, int is_rx)
30 const struct rte_ether_hdr *eth_hdr;
31 struct rte_ether_hdr _eth_hdr;
34 uint16_t i, packet_type;
35 uint16_t is_encapsulation;
37 struct rte_net_hdr_lens hdr_lens;
38 uint32_t sw_packet_type;
45 printf("port %u/queue %u: %s %u packets\n",
47 is_rx ? "received" : "sent",
48 (unsigned int) nb_pkts);
49 for (i = 0; i < nb_pkts; i++) {
51 eth_hdr = rte_pktmbuf_read(mb, 0, sizeof(_eth_hdr), &_eth_hdr);
52 eth_type = RTE_BE_TO_CPU_16(eth_hdr->ether_type);
53 ol_flags = mb->ol_flags;
54 packet_type = mb->packet_type;
55 is_encapsulation = RTE_ETH_IS_TUNNEL_PKT(packet_type);
57 print_ether_addr(" src=", ð_hdr->s_addr);
58 print_ether_addr(" - dst=", ð_hdr->d_addr);
59 printf(" - type=0x%04x - length=%u - nb_segs=%d",
60 eth_type, (unsigned int) mb->pkt_len,
62 if (ol_flags & PKT_RX_RSS_HASH) {
63 printf(" - RSS hash=0x%x", (unsigned int) mb->hash.rss);
64 printf(" - RSS queue=0x%x", (unsigned int) queue);
66 if (ol_flags & PKT_RX_FDIR) {
67 printf(" - FDIR matched ");
68 if (ol_flags & PKT_RX_FDIR_ID)
71 else if (ol_flags & PKT_RX_FDIR_FLX)
72 printf("flex bytes=0x%08x %08x",
73 mb->hash.fdir.hi, mb->hash.fdir.lo);
75 printf("hash=0x%x ID=0x%x ",
76 mb->hash.fdir.hash, mb->hash.fdir.id);
78 if (ol_flags & PKT_RX_TIMESTAMP)
79 printf(" - timestamp %"PRIu64" ", mb->timestamp);
80 if (ol_flags & PKT_RX_QINQ)
81 printf(" - QinQ VLAN tci=0x%x, VLAN tci outer=0x%x",
82 mb->vlan_tci, mb->vlan_tci_outer);
83 else if (ol_flags & PKT_RX_VLAN)
84 printf(" - VLAN tci=0x%x", mb->vlan_tci);
85 if (mb->packet_type) {
86 rte_get_ptype_name(mb->packet_type, buf, sizeof(buf));
87 printf(" - hw ptype: %s", buf);
89 sw_packet_type = rte_net_get_ptype(mb, &hdr_lens,
91 rte_get_ptype_name(sw_packet_type, buf, sizeof(buf));
92 printf(" - sw ptype: %s", buf);
93 if (sw_packet_type & RTE_PTYPE_L2_MASK)
94 printf(" - l2_len=%d", hdr_lens.l2_len);
95 if (sw_packet_type & RTE_PTYPE_L3_MASK)
96 printf(" - l3_len=%d", hdr_lens.l3_len);
97 if (sw_packet_type & RTE_PTYPE_L4_MASK)
98 printf(" - l4_len=%d", hdr_lens.l4_len);
99 if (sw_packet_type & RTE_PTYPE_TUNNEL_MASK)
100 printf(" - tunnel_len=%d", hdr_lens.tunnel_len);
101 if (sw_packet_type & RTE_PTYPE_INNER_L2_MASK)
102 printf(" - inner_l2_len=%d", hdr_lens.inner_l2_len);
103 if (sw_packet_type & RTE_PTYPE_INNER_L3_MASK)
104 printf(" - inner_l3_len=%d", hdr_lens.inner_l3_len);
105 if (sw_packet_type & RTE_PTYPE_INNER_L4_MASK)
106 printf(" - inner_l4_len=%d", hdr_lens.inner_l4_len);
107 if (is_encapsulation) {
108 struct rte_ipv4_hdr *ipv4_hdr;
109 struct rte_ipv6_hdr *ipv6_hdr;
110 struct rte_udp_hdr *udp_hdr;
115 struct rte_vxlan_hdr *vxlan_hdr;
117 l2_len = sizeof(struct rte_ether_hdr);
119 /* Do not support ipv4 option field */
120 if (RTE_ETH_IS_IPV4_HDR(packet_type)) {
121 l3_len = sizeof(struct rte_ipv4_hdr);
122 ipv4_hdr = rte_pktmbuf_mtod_offset(mb,
123 struct rte_ipv4_hdr *,
125 l4_proto = ipv4_hdr->next_proto_id;
127 l3_len = sizeof(struct rte_ipv6_hdr);
128 ipv6_hdr = rte_pktmbuf_mtod_offset(mb,
129 struct rte_ipv6_hdr *,
131 l4_proto = ipv6_hdr->proto;
133 if (l4_proto == IPPROTO_UDP) {
134 udp_hdr = rte_pktmbuf_mtod_offset(mb,
135 struct rte_udp_hdr *,
137 l4_len = sizeof(struct rte_udp_hdr);
138 vxlan_hdr = rte_pktmbuf_mtod_offset(mb,
139 struct rte_vxlan_hdr *,
140 l2_len + l3_len + l4_len);
141 udp_port = RTE_BE_TO_CPU_16(udp_hdr->dst_port);
142 vx_vni = rte_be_to_cpu_32(vxlan_hdr->vx_vni);
143 printf(" - VXLAN packet: packet type =%d, "
144 "Destination UDP port =%d, VNI = %d",
145 packet_type, udp_port, vx_vni >> 8);
148 printf(" - %s queue=0x%x", is_rx ? "Receive" : "Send",
149 (unsigned int) queue);
151 rte_get_rx_ol_flag_list(mb->ol_flags, buf, sizeof(buf));
152 printf(" ol_flags: %s\n", buf);
153 if (rte_mbuf_check(mb, 1, &reason) < 0)
154 printf("INVALID mbuf: %s\n", reason);
159 dump_rx_pkts(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
160 uint16_t nb_pkts, __rte_unused uint16_t max_pkts,
161 __rte_unused void *user_param)
163 dump_pkt_burst(port_id, queue, pkts, nb_pkts, 1);
168 dump_tx_pkts(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
169 uint16_t nb_pkts, __rte_unused void *user_param)
171 dump_pkt_burst(port_id, queue, pkts, nb_pkts, 0);
176 tx_pkt_set_md(uint16_t port_id, __rte_unused uint16_t queue,
177 struct rte_mbuf *pkts[], uint16_t nb_pkts,
178 __rte_unused void *user_param)
183 * Add metadata value to every Tx packet,
184 * and set ol_flags accordingly.
186 for (i = 0; i < nb_pkts; i++) {
187 pkts[i]->tx_metadata = ports[port_id].tx_metadata;
188 pkts[i]->ol_flags |= PKT_TX_METADATA;
194 add_tx_md_callback(portid_t portid)
196 struct rte_eth_dev_info dev_info;
200 if (port_id_is_invalid(portid, ENABLED_WARN))
203 ret = eth_dev_info_get_print_err(portid, &dev_info);
207 for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
208 if (!ports[portid].tx_set_md_cb[queue])
209 ports[portid].tx_set_md_cb[queue] =
210 rte_eth_add_tx_callback(portid, queue,
211 tx_pkt_set_md, NULL);
215 remove_tx_md_callback(portid_t portid)
217 struct rte_eth_dev_info dev_info;
221 if (port_id_is_invalid(portid, ENABLED_WARN))
224 ret = eth_dev_info_get_print_err(portid, &dev_info);
228 for (queue = 0; queue < dev_info.nb_tx_queues; queue++)
229 if (ports[portid].tx_set_md_cb[queue]) {
230 rte_eth_remove_tx_callback(portid, queue,
231 ports[portid].tx_set_md_cb[queue]);
232 ports[portid].tx_set_md_cb[queue] = NULL;
237 eth_dev_info_get_print_err(uint16_t port_id,
238 struct rte_eth_dev_info *dev_info)
242 ret = rte_eth_dev_info_get(port_id, dev_info);
244 printf("Error during getting device (port %u) info: %s\n",
245 port_id, strerror(-ret));
251 eth_set_promisc_mode(uint16_t port, int enable)
256 ret = rte_eth_promiscuous_enable(port);
258 ret = rte_eth_promiscuous_disable(port);
261 printf("Error during %s promiscuous mode for port %u: %s\n",
262 enable ? "enabling" : "disabling",
263 port, rte_strerror(-ret));
267 eth_set_allmulticast_mode(uint16_t port, int enable)
272 ret = rte_eth_allmulticast_enable(port);
274 ret = rte_eth_allmulticast_disable(port);
277 printf("Error during %s all-multicast mode for port %u: %s\n",
278 enable ? "enabling" : "disabling",
279 port, rte_strerror(-ret));
283 eth_link_get_nowait_print_err(uint16_t port_id, struct rte_eth_link *link)
287 ret = rte_eth_link_get_nowait(port_id, link);
289 printf("Device (port %u) link get (without wait) failed: %s\n",
290 port_id, rte_strerror(-ret));
296 eth_macaddr_get_print_err(uint16_t port_id, struct rte_ether_addr *mac_addr)
300 ret = rte_eth_macaddr_get(port_id, mac_addr);
302 printf("Error getting device (port %u) mac address: %s\n",
303 port_id, rte_strerror(-ret));