Skip to content

Commit b1eaf0e

Browse files
authored
Merge pull request #205 from CESNET/dpdk-mtu
Setting MTU size in dpdk input plugin
2 parents d2b7d7d + e13ff4e commit b1eaf0e

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
lines changed

.github/workflows/c-cpp.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ jobs:
3535
run: ./configure --with-raw --with-pcap --with-nemea --with-gtest --enable-debug CXXFLAGS=-coverage CFLAGS=-coverage LDFLAGS=-lgcov
3636
- name: rebuild and check
3737
run: make clean; make check
38-
- uses: codecov/codecov-action@v3
38+
- uses: codecov/codecov-action@v4
3939
with:
4040
flags: tests # optional
4141
name: ipfixprobe # optional
4242
fail_ci_if_error: true # optional (default = false)
43+
token: ${{ secrets.CODECOV_TOKEN }}
4344
verbose: true
4445
gcov: true

input/dpdk.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,13 @@ void DpdkCore::configure(const char* params)
155155
uint16_t mempoolSize = parser.pkt_mempool_size();
156156
uint16_t rxQueueCount = parser.rx_queues();
157157
m_mBufsCount = parser.pkt_buffer_size();
158+
uint16_t mtuSize = parser.mtu_size();
158159

159160
configureEal(parser.eal_params());
160161

161162
m_dpdkDevices.reserve(parser.port_numbers().size());
162163
for (auto portID : parser.port_numbers()) {
163-
m_dpdkDevices.emplace_back(portID, rxQueueCount, mempoolSize, m_mBufsCount);
164+
m_dpdkDevices.emplace_back(portID, rxQueueCount, mempoolSize, m_mBufsCount, mtuSize);
164165
}
165166

166167
isConfigured = true;

input/dpdk.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class DpdkOptParser : public OptionsParser {
5050
std::vector<uint16_t> port_numbers_;
5151
uint16_t rx_queues_ = 1;
5252
std::string eal_;
53+
uint16_t mtu_;
5354

5455
std::vector<uint16_t> parsePortNumbers(std::string arg)
5556
{
@@ -80,6 +81,7 @@ class DpdkOptParser : public OptionsParser {
8081
: OptionsParser("dpdk", "Input plugin for reading packets using DPDK interface")
8182
, pkt_buffer_size_(DEFAULT_MBUF_BURST_SIZE)
8283
, pkt_mempool_size_(DEFAULT_MBUF_POOL_SIZE)
84+
, mtu_(RTE_ETHER_MAX_LEN)
8385
{
8486
register_option(
8587
"b",
@@ -116,6 +118,13 @@ class DpdkOptParser : public OptionsParser {
116118
"DPDK eal",
117119
[this](const char *arg){eal_ = arg; return true;},
118120
OptionFlags::RequiredArgument);
121+
register_option(
122+
"M",
123+
"mtu",
124+
"MTU",
125+
"Input interface MTU. Default: " + std::to_string(RTE_ETHER_MAX_LEN),
126+
[this](const char *arg) {try{mtu_ = str2num<decltype(mtu_)>(arg);} catch (std::invalid_argument&){return false;} return true; },
127+
RequiredArgument);
119128
}
120129

121130
size_t pkt_buffer_size() const { return pkt_buffer_size_; }
@@ -127,6 +136,8 @@ class DpdkOptParser : public OptionsParser {
127136
std::string eal_params() const { return eal_; }
128137

129138
uint16_t rx_queues() const { return rx_queues_; }
139+
140+
uint16_t mtu_size() const { return mtu_; }
130141
};
131142

132143
class DpdkCore {

input/dpdk/dpdkDevice.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,16 @@ DpdkDevice::DpdkDevice(
3939
uint16_t portID,
4040
uint16_t rxQueueCount,
4141
uint16_t memPoolSize,
42-
uint16_t mbufsCount)
42+
uint16_t mbufsCount,
43+
uint16_t mtuSize)
4344
: m_portID(portID)
4445
, m_rxQueueCount(rxQueueCount)
4546
, m_txQueueCount(0)
4647
, m_mBufsCount(mbufsCount)
4748
, m_isNfbDpdkDriver(false)
4849
, m_supportedRSS(false)
4950
, m_supportedHWTimestamp(false)
51+
, m_mtuSize(mtuSize)
5052
{
5153
validatePort();
5254
recognizeDriver();
@@ -137,9 +139,9 @@ rte_eth_conf DpdkDevice::createPortConfig()
137139
}
138140

139141
#if RTE_VERSION >= RTE_VERSION_NUM(21, 11, 0, 0)
140-
rte_eth_conf portConfig {.rxmode = {.mtu = RTE_ETHER_MAX_LEN}};
142+
rte_eth_conf portConfig {.rxmode = {.mtu = m_mtuSize}};
141143
#else
142-
rte_eth_conf portConfig {.rxmode = {.max_rx_pkt_len = RTE_ETHER_MAX_LEN}};
144+
rte_eth_conf portConfig {.rxmode = {.max_rx_pkt_len = m_mtuSize}};
143145
#endif
144146

145147
if (m_supportedRSS) {
@@ -172,7 +174,7 @@ void DpdkDevice::initMemPools(uint16_t memPoolSize)
172174
memPoolSize,
173175
MEMPOOL_CACHE_SIZE,
174176
0,
175-
RTE_MBUF_DEFAULT_BUF_SIZE,
177+
std::max(m_mtuSize, (uint16_t)RTE_MBUF_DEFAULT_DATAROOM) + RTE_PKTMBUF_HEADROOM,
176178
rte_eth_dev_socket_id(m_portID));
177179
if (!memPool) {
178180
throw PluginError(

input/dpdk/dpdkDevice.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ class DpdkDevice {
4545
* @param rxQueueCount The number of receive queues to be configured.
4646
* @param memPoolSize The size of the memory pool for packet buffers.
4747
* @param mbufsCount The number of mbufs (packet buffers) to be allocated.
48+
* @param mtuSize Maximum transmission unit of input interface.
4849
*/
49-
DpdkDevice(uint16_t portID, uint16_t rxQueueCount, uint16_t memPoolSize, uint16_t mbufsCount);
50+
DpdkDevice(uint16_t portID, uint16_t rxQueueCount, uint16_t memPoolSize, uint16_t mbufsCount, uint16_t mtuSize);
5051

5152
/**
5253
* @brief Receives packets from the specified receive queue of the DPDK device.
@@ -92,6 +93,7 @@ class DpdkDevice {
9293
bool m_supportedHWTimestamp;
9394
int m_rxTimestampOffset;
9495
int m_rxTimestampDynflag;
96+
uint16_t m_mtuSize;
9597

9698
};
9799

0 commit comments

Comments
 (0)