Skip to content

Commit 74322eb

Browse files
authored
Few fixes to support DPDK 23.11 and 24.11 (#1774)
1 parent 8f12193 commit 74322eb

File tree

4 files changed

+52
-14
lines changed

4 files changed

+52
-14
lines changed

Pcap++/header/DpdkDevice.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,8 @@ namespace pcpp
405405

406406
/// Get the link status (link up/down, link speed and link duplex)
407407
/// @param[out] linkStatus A reference to object the result shall be written to
408-
void getLinkStatus(LinkStatus& linkStatus) const;
408+
/// @return True if managed to fetch the link status and `linkStatus` was updated, false otherwise
409+
bool getLinkStatus(LinkStatus& linkStatus) const;
409410

410411
/// @return The core ID used in this context
411412
uint32_t getCurrentCoreId() const;

Pcap++/src/DpdkDevice.cpp

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,18 @@ namespace pcpp
105105
0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A,
106106
};
107107

108+
static bool getDeviceInfo(uint16_t devId, rte_eth_dev_info& devInfo)
109+
{
110+
auto ret = rte_eth_dev_info_get(devId, &devInfo);
111+
if (ret < 0)
112+
{
113+
PCPP_LOG_ERROR("Couldn't get device info, error was: " << rte_strerror(ret) << " (" << ret << ")");
114+
return false;
115+
}
116+
117+
return true;
118+
}
119+
108120
DpdkDevice::DpdkDevice(int port, uint32_t mBufPoolSize, uint16_t mBufDataSize)
109121
: m_Id(port), m_MacAddress(MacAddress::Zero),
110122
m_MBufDataSize(mBufDataSize < 1 ? RTE_MBUF_DEFAULT_BUF_SIZE : mBufDataSize)
@@ -273,6 +285,8 @@ namespace pcpp
273285
{
274286
PCPP_LOG_DEBUG("PMD '" << m_PMDName << "' doesn't support RSS, setting RSS hash functions to 0");
275287
m_Config.rssHashFunction = RSS_NONE;
288+
m_Config.rssKey = nullptr;
289+
m_Config.rssKeyLength = 0;
276290
}
277291

278292
if (!isDeviceSupportRssHashFunction(getConfiguredRssHashFunction()))
@@ -346,7 +360,11 @@ namespace pcpp
346360
bool DpdkDevice::initQueues(uint8_t numOfRxQueuesToInit, uint8_t numOfTxQueuesToInit)
347361
{
348362
rte_eth_dev_info devInfo;
349-
rte_eth_dev_info_get(m_Id, &devInfo);
363+
if (!getDeviceInfo(m_Id, devInfo))
364+
{
365+
return false;
366+
}
367+
350368
if (numOfRxQueuesToInit > devInfo.max_rx_queues)
351369
{
352370
PCPP_LOG_ERROR("Num of RX queues requested for open [" << numOfRxQueuesToInit
@@ -500,7 +518,11 @@ namespace pcpp
500518
void DpdkDevice::setDeviceInfo()
501519
{
502520
rte_eth_dev_info portInfo;
503-
rte_eth_dev_info_get(m_Id, &portInfo);
521+
if (!getDeviceInfo(m_Id, portInfo))
522+
{
523+
return;
524+
}
525+
504526
m_PMDName = std::string(portInfo.driver_name);
505527

506528
if (m_PMDName == "eth_bond")
@@ -579,14 +601,22 @@ namespace pcpp
579601
}
580602
}
581603

582-
void DpdkDevice::getLinkStatus(LinkStatus& linkStatus) const
604+
bool DpdkDevice::getLinkStatus(LinkStatus& linkStatus) const
583605
{
584606
struct rte_eth_link link;
585-
rte_eth_link_get((uint8_t)m_Id, &link);
607+
auto ret = rte_eth_link_get((uint8_t)m_Id, &link);
608+
if (ret < 0)
609+
{
610+
PCPP_LOG_ERROR("Couldn't get link info, error was: " << rte_strerror(ret) << " (" << ret << ")");
611+
return false;
612+
}
613+
586614
linkStatus.linkUp = link.link_status;
587615
linkStatus.linkSpeedMbps = (unsigned)link.link_speed;
588616
linkStatus.linkDuplex =
589617
(link.link_duplex == DPDK_CONFIG_ETH_LINK_FULL_DUPLEX) ? LinkStatus::FULL_DUPLEX : LinkStatus::HALF_DUPLEX;
618+
619+
return true;
590620
}
591621

592622
bool DpdkDevice::initCoreConfigurationByCoreMask(CoreMask coreMask)
@@ -1054,7 +1084,7 @@ namespace pcpp
10541084
return 0;
10551085
}
10561086

1057-
rte_mbuf* mBufArr[MAX_BURST_SIZE];
1087+
rte_mbuf* mBufArr[MAX_BURST_SIZE] = {};
10581088

10591089
int packetIndex = 0;
10601090
int mBufArrIndex = 0;
@@ -1278,7 +1308,11 @@ namespace pcpp
12781308
if (rssHF == (uint64_t)-1)
12791309
{
12801310
rte_eth_dev_info devInfo;
1281-
rte_eth_dev_info_get(m_Id, &devInfo);
1311+
if (!getDeviceInfo(m_Id, devInfo))
1312+
{
1313+
return 0;
1314+
}
1315+
12821316
return devInfo.flow_type_rss_offloads;
12831317
}
12841318

@@ -1424,15 +1458,21 @@ namespace pcpp
14241458
uint64_t dpdkRssHF = convertRssHfToDpdkRssHf(rssHFMask);
14251459

14261460
rte_eth_dev_info devInfo;
1427-
rte_eth_dev_info_get(m_Id, &devInfo);
1461+
if (!getDeviceInfo(m_Id, devInfo))
1462+
{
1463+
return false;
1464+
}
14281465

14291466
return ((devInfo.flow_type_rss_offloads & dpdkRssHF) == dpdkRssHF);
14301467
}
14311468

14321469
uint64_t DpdkDevice::getSupportedRssHashFunctions() const
14331470
{
14341471
rte_eth_dev_info devInfo;
1435-
rte_eth_dev_info_get(m_Id, &devInfo);
1472+
if (!getDeviceInfo(m_Id, devInfo))
1473+
{
1474+
return 0;
1475+
}
14361476

14371477
return convertDpdkRssHfToRssHf(devInfo.flow_type_rss_offloads);
14381478
}

Pcap++/src/MBufRawPacket.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,9 @@ namespace pcpp
333333
return;
334334
}
335335

336-
m_MBuf = mBuf;
337336
RawPacket::setRawData(rte_pktmbuf_mtod(mBuf, const uint8_t*), rte_pktmbuf_pkt_len(mBuf), timestamp,
338337
LINKTYPE_ETHERNET);
338+
m_MBuf = mBuf;
339339
}
340340

341341
} // namespace pcpp

Tests/Pcap++Test/Tests/DpdkTests.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,13 @@ class DpdkTestWorkerThread : public pcpp::DpdkWorkerThread
200200
{
201201
if (!m_Initialized)
202202
{
203-
std::cout << "Error: Thread " << coreId << " was not initialized" << std::endl;
204203
return false;
205204
}
206205

207206
m_CoreId = coreId;
208207

209208
if (m_DpdkDevice == NULL)
210209
{
211-
std::cout << "Error: DpdkDevice is NULL";
212210
return false;
213211
}
214212

@@ -225,7 +223,6 @@ class DpdkTestWorkerThread : public pcpp::DpdkWorkerThread
225223
uint16_t packetsSent = m_DpdkDevice->sendPackets(mBufArr, packetReceived, m_QueueId);
226224
if (packetsSent != packetReceived)
227225
{
228-
std::cout << "Error: Couldn't send all received packets on thread " << m_CoreId;
229226
return false;
230227
}
231228
}
@@ -332,7 +329,7 @@ PTF_TEST_CASE(TestDpdkDevice)
332329
PTF_ASSERT_EQUAL(dev->getNumOfOpenedRxQueues(), 1);
333330
PTF_ASSERT_EQUAL(dev->getNumOfOpenedTxQueues(), 1);
334331
pcpp::DpdkDevice::LinkStatus linkStatus;
335-
dev->getLinkStatus(linkStatus);
332+
PTF_ASSERT_TRUE(dev->getLinkStatus(linkStatus));
336333
PTF_ASSERT_TRUE(linkStatus.linkUp);
337334
PTF_ASSERT_GREATER_THAN(linkStatus.linkSpeedMbps, 0);
338335

0 commit comments

Comments
 (0)