Skip to content

Commit

Permalink
dpdk: Upgrade to DPDK 19.11 API
Browse files Browse the repository at this point in the history
Support DPDK versions 19.11 and 20.11
  • Loading branch information
alynch-ni authored and atrnati committed Dec 6, 2021
1 parent 8ce91bc commit b17d2df
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 129 deletions.
2 changes: 1 addition & 1 deletion host/cmake/Modules/FindDPDK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ else()
endif()

find_package(PkgConfig)
PKG_CHECK_MODULES(PC_DPDK QUIET libdpdk>=18.11)
PKG_CHECK_MODULES(PC_DPDK QUIET libdpdk>=19.11)

find_path (DPDK_VERSION_INCLUDE_DIR rte_version.h
HINTS ${PC_DPDK_INCLUDE_DIRS}
Expand Down
2 changes: 1 addition & 1 deletion host/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ endmacro(INCLUDE_SUBDIRECTORY)
message(STATUS "")
# Dependencies
find_package(LIBUSB)
find_package(DPDK 18.11 EXACT)
find_package(DPDK 19.11...20.11)
LIBUHD_REGISTER_COMPONENT("USB" ENABLE_USB ON "ENABLE_LIBUHD;LIBUSB_FOUND" OFF OFF)
# Devices
LIBUHD_REGISTER_COMPONENT("B100" ENABLE_B100 ON "ENABLE_LIBUHD;ENABLE_USB" OFF OFF)
Expand Down
6 changes: 3 additions & 3 deletions host/lib/include/uhdlib/transport/dpdk/arp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ namespace uhd { namespace transport { namespace dpdk {

struct arp_request
{
struct ether_addr tha;
struct rte_ether_addr tha;
port_id_t port;
ipv4_addr tpa;
rte_ipv4_addr tpa;
};

struct arp_entry
{
struct ether_addr mac_addr;
struct rte_ether_addr mac_addr;
std::vector<wait_req*> reqs;
};

Expand Down
32 changes: 16 additions & 16 deletions host/lib/include/uhdlib/transport/dpdk/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct arp_entry;

using queue_id_t = uint16_t;
using port_id_t = uint16_t;
using ipv4_addr = uint32_t;
using rte_ipv4_addr = uint32_t;

class dpdk_adapter_info : public adapter_info
{
Expand Down Expand Up @@ -143,7 +143,7 @@ class dpdk_port
* \param num_desc The number of descriptors per DMA queue
* \param rx_pktbuf_pool A pointer to the port's RX packet buffer pool
* \param tx_pktbuf_pool A pointer to the port's TX packet buffer pool
* \param ipv4_address The IPv4 network address (w/ netmask)
* \param rte_ipv4_address The IPv4 network address (w/ netmask)
* \return A unique_ptr to a dpdk_port object
*/
static dpdk_port::uptr make(port_id_t port,
Expand All @@ -152,15 +152,15 @@ class dpdk_port
uint16_t num_desc,
struct rte_mempool* rx_pktbuf_pool,
struct rte_mempool* tx_pktbuf_pool,
std::string ipv4_address);
std::string rte_ipv4_address);

dpdk_port(port_id_t port,
size_t mtu,
uint16_t num_queues,
uint16_t num_desc,
struct rte_mempool* rx_pktbuf_pool,
struct rte_mempool* tx_pktbuf_pool,
std::string ipv4_address);
std::string rte_ipv4_address);

~dpdk_port();

Expand All @@ -180,7 +180,7 @@ class dpdk_port
/*! Getter for this port's MAC address
* \return this port's MAC address
*/
inline ether_addr get_mac_addr() const
inline rte_ether_addr get_mac_addr() const
{
return _mac_addr;
}
Expand All @@ -196,15 +196,15 @@ class dpdk_port
/*! Getter for this port's IPv4 address
* \return this port's IPv4 address (in network order)
*/
inline ipv4_addr get_ipv4() const
inline rte_ipv4_addr get_ipv4() const
{
return _ipv4;
}

/*! Getter for this port's subnet mask
* \return this port's subnet mask (in network order)
*/
inline ipv4_addr get_netmask() const
inline rte_ipv4_addr get_netmask() const
{
return _netmask;
}
Expand Down Expand Up @@ -238,12 +238,12 @@ class dpdk_port
}

/*! Determine if the destination address is a broadcast address for this port
* \param dst_ipv4_addr The destination IPv4 address (in network order)
* \param dst_rte_ipv4_addr The destination IPv4 address (in network order)
* \return whether the destination address matches this port's broadcast address
*/
inline bool dst_is_broadcast(const ipv4_addr dst_ipv4_addr) const
inline bool dst_is_broadcast(const rte_ipv4_addr dst_rte_ipv4_addr) const
{
uint32_t network = _netmask | ((~_netmask) & dst_ipv4_addr);
uint32_t network = _netmask | ((~_netmask) & dst_rte_ipv4_addr);
return (network == 0xffffffff);
}

Expand All @@ -261,16 +261,16 @@ class dpdk_port
/*!
* Construct and transmit an ARP reply (for the given ARP request)
*/
int _arp_reply(queue_id_t queue_id, struct arp_hdr* arp_req);
int _arp_reply(queue_id_t queue_id, struct rte_arp_hdr* arp_req);

port_id_t _port;
size_t _mtu;
size_t _num_queues;
struct rte_mempool* _rx_pktbuf_pool;
struct rte_mempool* _tx_pktbuf_pool;
struct ether_addr _mac_addr;
ipv4_addr _ipv4;
ipv4_addr _netmask;
struct rte_ether_addr _mac_addr;
rte_ipv4_addr _ipv4;
rte_ipv4_addr _netmask;

// Structures protected by mutex
std::mutex _mutex;
Expand All @@ -279,7 +279,7 @@ class dpdk_port

// Structures protected by spin lock
rte_spinlock_t _spinlock = RTE_SPINLOCK_INITIALIZER;
std::unordered_map<ipv4_addr, struct arp_entry*> _arp_table;
std::unordered_map<rte_ipv4_addr, struct arp_entry*> _arp_table;
};


Expand Down Expand Up @@ -317,7 +317,7 @@ class dpdk_ctx : uhd::noncopyable, public std::enable_shared_from_this<dpdk_ctx>
* \param mac_addr MAC address
* \return pointer to port if match found, else nullptr
*/
dpdk_port* get_port(struct ether_addr mac_addr) const;
dpdk_port* get_port(struct rte_ether_addr mac_addr) const;

/*!
* Get port structure from provided port ID
Expand Down
56 changes: 28 additions & 28 deletions host/lib/include/uhdlib/transport/dpdk/udp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
namespace uhd { namespace transport { namespace dpdk {

constexpr size_t HDR_SIZE_UDP_IPV4 =
(sizeof(struct ether_hdr) + sizeof(struct ipv4_hdr) + sizeof(struct udp_hdr));
(sizeof(struct rte_ether_hdr) + sizeof(struct rte_ipv4_hdr) + sizeof(struct rte_udp_hdr));

/*!
* An enumerated type representing the type of flow for an IPv4 client
Expand All @@ -32,76 +32,76 @@ enum flow_type {
struct ipv4_5tuple
{
enum flow_type flow_type;
ipv4_addr src_ip;
ipv4_addr dst_ip;
rte_ipv4_addr src_ip;
rte_ipv4_addr dst_ip;
uint16_t src_port;
uint16_t dst_port;
};

inline void fill_ipv4_hdr(struct rte_mbuf* mbuf,
inline void fill_rte_ipv4_hdr(struct rte_mbuf* mbuf,
const dpdk_port* port,
uint32_t dst_ipv4_addr,
uint32_t dst_rte_ipv4_addr,
uint8_t proto_id,
uint32_t payload_len)
{
struct ether_hdr* eth_hdr = rte_pktmbuf_mtod(mbuf, struct ether_hdr*);
struct ipv4_hdr* ip_hdr = (struct ipv4_hdr*)&eth_hdr[1];
struct rte_ether_hdr* eth_hdr = rte_pktmbuf_mtod(mbuf, struct rte_ether_hdr*);
struct rte_ipv4_hdr* ip_hdr = (struct rte_ipv4_hdr*)&eth_hdr[1];

ip_hdr->version_ihl = 0x40 | 5;
ip_hdr->type_of_service = 0;
ip_hdr->total_length = rte_cpu_to_be_16(20 + payload_len);
ip_hdr->packet_id = 0;
ip_hdr->fragment_offset = rte_cpu_to_be_16(IPV4_HDR_DF_FLAG);
ip_hdr->fragment_offset = rte_cpu_to_be_16(RTE_IPV4_HDR_DF_FLAG);
ip_hdr->time_to_live = 64;
ip_hdr->next_proto_id = proto_id;
ip_hdr->hdr_checksum = 0; // Require HW offload
ip_hdr->src_addr = port->get_ipv4();
ip_hdr->dst_addr = dst_ipv4_addr;
ip_hdr->dst_addr = dst_rte_ipv4_addr;

mbuf->ol_flags = PKT_TX_IP_CKSUM | PKT_TX_IPV4;
mbuf->l2_len = sizeof(struct ether_hdr);
mbuf->l3_len = sizeof(struct ipv4_hdr);
mbuf->pkt_len = sizeof(struct ether_hdr) + sizeof(struct ipv4_hdr) + payload_len;
mbuf->data_len = sizeof(struct ether_hdr) + sizeof(struct ipv4_hdr) + payload_len;
mbuf->l2_len = sizeof(struct rte_ether_hdr);
mbuf->l3_len = sizeof(struct rte_ipv4_hdr);
mbuf->pkt_len = sizeof(struct rte_ether_hdr) + sizeof(struct rte_ipv4_hdr) + payload_len;
mbuf->data_len = sizeof(struct rte_ether_hdr) + sizeof(struct rte_ipv4_hdr) + payload_len;
}

/* All values except payload length must be in network order */
inline void fill_udp_hdr(struct rte_mbuf* mbuf,
inline void fill_rte_udp_hdr(struct rte_mbuf* mbuf,
const dpdk_port* port,
uint32_t dst_ipv4_addr,
uint32_t dst_rte_ipv4_addr,
uint16_t src_port,
uint16_t dst_port,
uint32_t payload_len)
{
struct ether_hdr* eth_hdr;
struct ipv4_hdr* ip_hdr;
struct udp_hdr* tx_hdr;
struct rte_ether_hdr* eth_hdr;
struct rte_ipv4_hdr* ip_hdr;
struct rte_udp_hdr* tx_hdr;

fill_ipv4_hdr(
mbuf, port, dst_ipv4_addr, IPPROTO_UDP, sizeof(struct udp_hdr) + payload_len);
fill_rte_ipv4_hdr(
mbuf, port, dst_rte_ipv4_addr, IPPROTO_UDP, sizeof(struct rte_udp_hdr) + payload_len);

eth_hdr = rte_pktmbuf_mtod(mbuf, struct ether_hdr*);
ip_hdr = (struct ipv4_hdr*)&eth_hdr[1];
tx_hdr = (struct udp_hdr*)&ip_hdr[1];
eth_hdr = rte_pktmbuf_mtod(mbuf, struct rte_ether_hdr*);
ip_hdr = (struct rte_ipv4_hdr*)&eth_hdr[1];
tx_hdr = (struct rte_udp_hdr*)&ip_hdr[1];

tx_hdr->src_port = src_port;
tx_hdr->dst_port = dst_port;
tx_hdr->dgram_len = rte_cpu_to_be_16(8 + payload_len);
tx_hdr->dgram_cksum = 0;
mbuf->l4_len = sizeof(struct udp_hdr);
mbuf->l4_len = sizeof(struct rte_udp_hdr);
}

//! Return an IPv4 address (numeric, in network order) into a string
inline std::string ipv4_num_to_str(const uint32_t ip_addr)
{
char addr_str[INET_ADDRSTRLEN];
struct in_addr ipv4_addr;
ipv4_addr.s_addr = ip_addr;
inet_ntop(AF_INET, &ipv4_addr, addr_str, sizeof(addr_str));
struct in_addr rte_ipv4_addr;
rte_ipv4_addr.s_addr = ip_addr;
inet_ntop(AF_INET, &rte_ipv4_addr, addr_str, sizeof(addr_str));
return std::string(addr_str);
}

inline std::string eth_addr_to_string(const struct ether_addr mac_addr)
inline std::string eth_addr_to_string(const struct rte_ether_addr mac_addr)
{
auto mac_stream = boost::format("%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx");
mac_stream % (uint32_t)mac_addr.addr_bytes[0] % (uint32_t)mac_addr.addr_bytes[1]
Expand Down
8 changes: 4 additions & 4 deletions host/lib/include/uhdlib/transport/dpdk_io_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class dpdk_io_service : public virtual io_service,
* \param ip the IPv4 address for which the caller is seeking a MAC address
*/
int _send_arp_request(
dpdk::dpdk_port* port, dpdk::queue_id_t queue, dpdk::ipv4_addr ip);
dpdk::dpdk_port* port, dpdk::queue_id_t queue, dpdk::rte_ipv4_addr ip);

/*!
* Helper function for I/O thread to process an ARP request/reply
Expand All @@ -170,7 +170,7 @@ class dpdk_io_service : public virtual io_service,
* \param arp_frame a pointer to the ARP frame
*/
int _process_arp(
dpdk::dpdk_port* port, dpdk::queue_id_t queue_id, struct arp_hdr* arp_frame);
dpdk::dpdk_port* port, dpdk::queue_id_t queue_id, struct rte_arp_hdr* arp_frame);

/*!
* Helper function for I/O thread to process an IPv4 packet
Expand All @@ -179,7 +179,7 @@ class dpdk_io_service : public virtual io_service,
* \param mbuf a pointer to the packet buffer container
* \param pkt a pointer to the IPv4 header of the packet
*/
int _process_ipv4(dpdk::dpdk_port* port, struct rte_mbuf* mbuf, struct ipv4_hdr* pkt);
int _process_ipv4(dpdk::dpdk_port* port, struct rte_mbuf* mbuf, struct rte_ipv4_hdr* pkt);

/*!
* Helper function for I/O thread to process an IPv4 packet
Expand All @@ -191,7 +191,7 @@ class dpdk_io_service : public virtual io_service,
* IPv4 address
*/
int _process_udp(
dpdk::dpdk_port* port, struct rte_mbuf* mbuf, struct udp_hdr* pkt, bool bcast);
dpdk::dpdk_port* port, struct rte_mbuf* mbuf, struct rte_udp_hdr* pkt, bool bcast);

/*!
* Helper function to get a unique client ID
Expand Down
10 changes: 5 additions & 5 deletions host/lib/include/uhdlib/transport/udp_dpdk_link.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,19 @@ class udp_dpdk_link : public virtual recv_link_if, public virtual send_link_if
*
* \param mac the remote host's MAC address
*/
inline void set_remote_mac(struct ether_addr& mac)
inline void set_remote_mac(struct rte_ether_addr& mac)
{
ether_addr_copy(&mac, &_remote_mac);
rte_ether_addr_copy(&mac, &_remote_mac);
}

/*!
* Get the remote host's MAC address
*
* \param mac Where to write the MAC address
*/
inline void get_remote_mac(struct ether_addr& dst)
inline void get_remote_mac(struct rte_ether_addr& dst)
{
ether_addr_copy(&_remote_mac, &dst);
rte_ether_addr_copy(&_remote_mac, &dst);
}

/*!
Expand Down Expand Up @@ -244,7 +244,7 @@ class udp_dpdk_link : public virtual recv_link_if, public virtual send_link_if
//! Remote IPv4 address, in network order
uint32_t _remote_ipv4;
//! Remote host's MAC address
struct ether_addr _remote_mac;
struct rte_ether_addr _remote_mac;
//! Number of recv frames is not validated
size_t _num_recv_frames;
//! Maximum bytes of UDP payload data in recv frame
Expand Down
6 changes: 3 additions & 3 deletions host/lib/transport/dpdk_simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ class dpdk_simple_impl : public dpdk_simple

// Extract the sender's address. This is only possible because we know
// the memory layout of the buff
struct udp_hdr* udp_hdr_end = (struct udp_hdr*)buff->data();
struct ipv4_hdr* ip_hdr_end = (struct ipv4_hdr*)(&udp_hdr_end[-1]);
struct ipv4_hdr* ip_hdr = (struct ipv4_hdr*)(&ip_hdr_end[-1]);
struct rte_udp_hdr* rte_udp_hdr_end = (struct rte_udp_hdr*)buff->data();
struct rte_ipv4_hdr* ip_hdr_end = (struct rte_ipv4_hdr*)(&rte_udp_hdr_end[-1]);
struct rte_ipv4_hdr* ip_hdr = (struct rte_ipv4_hdr*)(&ip_hdr_end[-1]);
_last_recv_addr = ip_hdr->src_addr;

// Extract the buffer data
Expand Down
20 changes: 10 additions & 10 deletions host/lib/transport/udp_dpdk_link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ udp_dpdk_link::sptr udp_dpdk_link::make(const dpdk::port_id_t port_id,
void udp_dpdk_link::enqueue_recv_mbuf(struct rte_mbuf* mbuf)
{
// Get packet size
struct udp_hdr* hdr = rte_pktmbuf_mtod_offset(
mbuf, struct udp_hdr*, sizeof(struct ether_hdr) + sizeof(struct ipv4_hdr));
size_t packet_size = rte_be_to_cpu_16(hdr->dgram_len) - sizeof(struct udp_hdr);
struct rte_udp_hdr* hdr = rte_pktmbuf_mtod_offset(
mbuf, struct rte_udp_hdr*, sizeof(struct rte_ether_hdr) + sizeof(struct rte_ipv4_hdr));
size_t packet_size = rte_be_to_cpu_16(hdr->dgram_len) - sizeof(struct rte_udp_hdr);
// Prepare the dpdk_frame_buff
auto buff = new (rte_mbuf_to_priv(mbuf)) dpdk_frame_buff(mbuf);
buff->header_jump(
sizeof(struct ether_hdr) + sizeof(struct ipv4_hdr) + sizeof(struct udp_hdr));
sizeof(struct rte_ether_hdr) + sizeof(struct rte_ipv4_hdr) + sizeof(struct rte_udp_hdr));
buff->set_packet_size(packet_size);
// Add the dpdk_frame_buff to the list
if (_recv_buff_head) {
Expand Down Expand Up @@ -155,7 +155,7 @@ frame_buff::uptr udp_dpdk_link::get_send_buff(int32_t /*timeout_ms*/)
if (mbuf) {
auto buff = new (rte_mbuf_to_priv(mbuf)) dpdk_frame_buff(mbuf);
buff->header_jump(
sizeof(struct ether_hdr) + sizeof(struct ipv4_hdr) + sizeof(struct udp_hdr));
sizeof(struct rte_ether_hdr) + sizeof(struct rte_ipv4_hdr) + sizeof(struct rte_udp_hdr));
return frame_buff::uptr(buff);
}
return frame_buff::uptr();
Expand All @@ -169,12 +169,12 @@ void udp_dpdk_link::release_send_buff(frame_buff::uptr buff)
if (buff_ptr->packet_size()) {
// Fill in L2 header
auto local_mac = _port->get_mac_addr();
struct ether_hdr* l2_hdr = rte_pktmbuf_mtod(mbuf, struct ether_hdr*);
ether_addr_copy(&_remote_mac, &l2_hdr->d_addr);
ether_addr_copy(&local_mac, &l2_hdr->s_addr);
l2_hdr->ether_type = rte_cpu_to_be_16(ETHER_TYPE_IPv4);
struct rte_ether_hdr* l2_hdr = rte_pktmbuf_mtod(mbuf, struct rte_ether_hdr*);
rte_ether_addr_copy(&_remote_mac, &l2_hdr->d_addr);
rte_ether_addr_copy(&local_mac, &l2_hdr->s_addr);
l2_hdr->ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4);
// Fill in L3 and L4 headers
dpdk::fill_udp_hdr(mbuf,
dpdk::fill_rte_udp_hdr(mbuf,
_port,
_remote_ipv4,
_local_port,
Expand Down

0 comments on commit b17d2df

Please sign in to comment.