1717#include < cstdio>
1818#include < cstring>
1919#include < iostream>
20+ #include < memory>
21+ #include < algorithm>
22+ #include < span>
2023
2124#include < ipfixprobe/pluginFactory/pluginManifest.hpp>
2225#include < ipfixprobe/pluginFactory/pluginRegistrar.hpp>
@@ -47,7 +50,7 @@ static std::vector<std::string> parseDevices(const std::string& input)
4750{
4851 std::vector<std::string> result;
4952
50- size_t colon_pos = input.find (' :' );
53+ size_t colon_pos = input.find_last_of (' :' );
5154 std::string suffix;
5255 std::string devices;
5356
@@ -69,6 +72,7 @@ static std::vector<std::string> parseDevices(const std::string& input)
6972}
7073
7174NdpPacketReader::NdpPacketReader (const std::string& params)
75+ : ndp_packet_burst(new ndp_packet[64 ])
7276{
7377 init (params.c_str ());
7478}
@@ -121,54 +125,57 @@ InputPlugin::Result NdpPacketReader::get(PacketBlock& packets)
121125 parser_opt_t opt = {&packets, false , false , 0 };
122126 struct ndp_packet * ndp_packet;
123127 struct timeval timestamp;
124- size_t read_pkts = 0 ;
125128 int ret = -1 ;
126129
127130 packets.cnt = 0 ;
131+ constexpr size_t maxBurstSize = 64 ;
132+ size_t burstSize = std::min (packets.size , maxBurstSize);
133+ std::span<struct ndp_packet > packetSpan (ndp_packet_burst.get (), burstSize);
134+ std::span<timeval> timestampSpan (timestamps);
135+
136+ size_t reader_index = (m_reader_idx++) & (m_readers_count - 1 );
137+ NdpReader& reader = ndpReader[reader_index];
138+ int received = reader.get_packets (packetSpan, timestampSpan);
139+
140+ if (received < 32 ) {
141+ std::span<struct ndp_packet > packetSpan (ndp_packet_burst.get () + received, burstSize - received);
142+ std::span<timeval> timestampSpan (timestamps.data () + received, burstSize - received);
143+
144+ size_t reader_index = (m_reader_idx++) & (m_readers_count - 1 );
145+ NdpReader& reader = ndpReader[reader_index];
146+ received += reader.get_packets (packetSpan, timestampSpan);
147+ }
148+
149+ for (unsigned i = 0 ; i < received; ++i) {
150+ ndp_packet = &ndp_packet_burst[i];
151+ timestamp = timestamps[i];
128152
129- bool any_timeout = false ;
130-
131- for (unsigned r = 0 ; r < m_readers_count; ++r) {
132- NdpReader& reader = ndpReader[(m_reader_idx++) % m_readers_count];
133-
134- for (unsigned i = 0 ; i < packets.size ; ++i) {
135- ret = reader.get_pkt (&ndp_packet, ×tamp);
136- if (ret == 0 ) {
137- any_timeout = true ;
138- break ;
139- } else if (ret < 0 ) {
140- // Error occured.
141- throw PluginError (reader.error_msg );
142- }
143-
144- ++read_pkts;
145- parse_packet (
146- &opt,
147- m_parser_stats,
148- timestamp,
149- ndp_packet->data ,
150- ndp_packet->data_length ,
151- ndp_packet->data_length );
152-
153- if (opt.pblock ->cnt >= packets.size ) {
154- break ;
155- }
153+ if (ndp_packet->data_length == 0 ) {
154+ continue ; // Skip empty packets
156155 }
157156
158- if (opt.pblock ->cnt ) {
157+ parse_packet (
158+ &opt,
159+ m_parser_stats,
160+ timestamp,
161+ ndp_packet->data ,
162+ ndp_packet->data_length ,
163+ ndp_packet->data_length );
164+
165+ if (opt.pblock ->cnt >= packets.size ) {
159166 break ;
160167 }
161168 }
162169
163- m_seen += read_pkts ;
170+ m_seen += received ;
164171 m_parsed += opt.pblock ->cnt ;
165172
166- m_stats.receivedPackets += read_pkts ;
173+ m_stats.receivedPackets += received ;
167174 m_stats.receivedBytes += packets.bytes ;
168175
169176 if (opt.pblock ->cnt ) {
170177 return Result::PARSED;
171- } else if (any_timeout ) {
178+ } else if (received == 0 ) {
172179 return Result::TIMEOUT;
173180 } else {
174181 return Result::NOT_PARSED;
0 commit comments