Skip to content

Commit

Permalink
Merge branch 'dev' into increase-protocol-types
Browse files Browse the repository at this point in the history
  • Loading branch information
seladb authored Dec 27, 2023
2 parents a86ea9d + 96987d2 commit f5f6d41
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 150 deletions.
20 changes: 10 additions & 10 deletions Examples/DpdkExample-FilterTraffic/AppWorkerThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,22 @@ class AppWorkerThread : public pcpp::DpdkWorkerThread
{
m_CoreId = coreId;
m_Stop = false;
m_Stats.WorkerId = coreId;
pcpp::DpdkDevice* sendPacketsTo = m_WorkerConfig.SendPacketsTo;
m_Stats.workerId = coreId;
pcpp::DpdkDevice* sendPacketsTo = m_WorkerConfig.sendPacketsTo;
pcpp::PcapFileWriterDevice* pcapWriter = NULL;

// if needed, create the pcap file writer which all matched packets will be written into
if (m_WorkerConfig.WriteMatchedPacketsToFile)
if (m_WorkerConfig.writeMatchedPacketsToFile)
{
pcapWriter = new pcpp::PcapFileWriterDevice(m_WorkerConfig.PathToWritePackets.c_str());
pcapWriter = new pcpp::PcapFileWriterDevice(m_WorkerConfig.pathToWritePackets.c_str());
if (!pcapWriter->open())
{
EXIT_WITH_ERROR("Couldn't open pcap writer device");
}
}

// if no DPDK devices were assigned to this worker/core don't enter the main loop and exit
if (m_WorkerConfig.InDataCfg.size() == 0)
if (m_WorkerConfig.inDataCfg.size() == 0)
{
return true;
}
Expand All @@ -74,7 +74,7 @@ class AppWorkerThread : public pcpp::DpdkWorkerThread
while (!m_Stop)
{
// go over all DPDK devices configured for this worker/core
for (const auto &iter : m_WorkerConfig.InDataCfg)
for (const auto &iter : m_WorkerConfig.inDataCfg)
{
// for each DPDK device go over all RX queues configured for this worker/core
for (const auto &iter2 : iter.second)
Expand All @@ -92,7 +92,7 @@ class AppWorkerThread : public pcpp::DpdkWorkerThread
// collect packet statistics
m_Stats.collectStats(parsedPacket);

bool packetMatched = false;
bool packetMatched;

// hash the packet by 5-tuple and look in the flow table to see whether this packet belongs to an existing or new flow
uint32_t hash = pcpp::hash5Tuple(&parsedPacket);
Expand All @@ -114,11 +114,11 @@ class AppWorkerThread : public pcpp::DpdkWorkerThread
//collect stats
if (parsedPacket.isPacketOfType(pcpp::TCP))
{
m_Stats.MatchedTcpFlows++;
m_Stats.matchedTcpFlows++;
}
else if (parsedPacket.isPacketOfType(pcpp::UDP))
{
m_Stats.MatchedUdpFlows++;
m_Stats.matchedUdpFlows++;
}

}
Expand All @@ -138,7 +138,7 @@ class AppWorkerThread : public pcpp::DpdkWorkerThread
pcapWriter->writePacket(*packetArr[i]);
}

m_Stats.MatchedPackets++;
m_Stats.matchedPackets++;
}
}
}
Expand Down
172 changes: 70 additions & 102 deletions Examples/DpdkExample-FilterTraffic/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,14 @@ typedef std::map<pcpp::DpdkDevice*, std::vector<int> > InputDataConfig;
*/
struct AppWorkerConfig
{
uint32_t CoreId;
InputDataConfig InDataCfg;
pcpp::DpdkDevice* SendPacketsTo;
bool WriteMatchedPacketsToFile;
std::string PathToWritePackets;

AppWorkerConfig() : CoreId(MAX_NUM_OF_CORES+1), SendPacketsTo(NULL), WriteMatchedPacketsToFile(false), PathToWritePackets("")
{
}
uint32_t coreId;
InputDataConfig inDataCfg;
pcpp::DpdkDevice* sendPacketsTo;
bool writeMatchedPacketsToFile;
std::string pathToWritePackets;

AppWorkerConfig() : coreId(MAX_NUM_OF_CORES+1), sendPacketsTo(nullptr),
writeMatchedPacketsToFile(false), pathToWritePackets("") {}
};


Expand All @@ -58,115 +57,84 @@ struct AppWorkerConfig
struct PacketStats
{
public:
uint8_t WorkerId;

int PacketCount;
int EthCount;
int ArpCount;
int Ip4Count;
int Ip6Count;
int TcpCount;
int UdpCount;
int HttpCount;

int MatchedTcpFlows;
int MatchedUdpFlows;
int MatchedPackets;

PacketStats() : WorkerId(MAX_NUM_OF_CORES+1), PacketCount(0), EthCount(0), ArpCount(0), Ip4Count(0), Ip6Count(0), TcpCount(0), UdpCount(0), HttpCount(0), MatchedTcpFlows(0), MatchedUdpFlows(0), MatchedPackets(0) {}
uint8_t workerId;

int packetCount;
int ethCount;
int arpCount;
int ipv4Count;
int ipv6Count;
int tcpCount;
int udpCount;
int httpCount;
int dnsCount;
int tlsCount;

int matchedTcpFlows;
int matchedUdpFlows;
int matchedPackets;

PacketStats() : workerId(MAX_NUM_OF_CORES+1), packetCount(0), ethCount(0), arpCount(0), ipv4Count(0), ipv6Count(0),
tcpCount(0), udpCount(0), httpCount(0), dnsCount(0), tlsCount(0),
matchedTcpFlows(0), matchedUdpFlows(0), matchedPackets(0) {}

void collectStats(pcpp::Packet& packet)
{
PacketCount++;
packetCount++;
if (packet.isPacketOfType(pcpp::Ethernet))
EthCount++;
ethCount++;
if (packet.isPacketOfType(pcpp::ARP))
ArpCount++;
arpCount++;
if (packet.isPacketOfType(pcpp::IPv4))
Ip4Count++;
ipv4Count++;
if (packet.isPacketOfType(pcpp::IPv6))
Ip6Count++;
ipv6Count++;
if (packet.isPacketOfType(pcpp::TCP))
TcpCount++;
tcpCount++;
if (packet.isPacketOfType(pcpp::UDP))
UdpCount++;
udpCount++;
if (packet.isPacketOfType(pcpp::HTTP))
HttpCount++;
httpCount++;
if (packet.isPacketOfType(pcpp::DNS))
dnsCount++;
if (packet.isPacketOfType(pcpp::SSL))
tlsCount++;
}

void collectStats(const PacketStats& stats)
{
PacketCount += stats.PacketCount;
EthCount += stats.EthCount;
ArpCount += stats.ArpCount;
Ip4Count += stats.Ip4Count;
Ip6Count += stats.Ip6Count;
TcpCount += stats.TcpCount;
UdpCount += stats.UdpCount;
HttpCount += stats.HttpCount;

MatchedTcpFlows += stats.MatchedTcpFlows;
MatchedUdpFlows += stats.MatchedUdpFlows;
MatchedPackets += stats.MatchedPackets;
packetCount += stats.packetCount;
ethCount += stats.ethCount;
arpCount += stats.arpCount;
ipv4Count += stats.ipv4Count;
ipv6Count += stats.ipv6Count;
tcpCount += stats.tcpCount;
udpCount += stats.udpCount;
httpCount += stats.httpCount;
dnsCount += stats.dnsCount;
tlsCount += stats.tlsCount;

matchedTcpFlows += stats.matchedTcpFlows;
matchedUdpFlows += stats.matchedUdpFlows;
matchedPackets += stats.matchedPackets;
}

void clear() { WorkerId = MAX_NUM_OF_CORES+1; PacketCount = 0; EthCount = 0; ArpCount = 0; Ip4Count = 0; Ip6Count = 0; TcpCount = 0; UdpCount = 0; HttpCount = 0; MatchedTcpFlows = 0; MatchedUdpFlows = 0; MatchedPackets = 0; }

std::string getStatValuesAsString(const std::string &delimiter)
void clear()
{
std::stringstream values;
if (WorkerId == MAX_NUM_OF_CORES+1)
values << "Total" << delimiter;
else
values << (int)WorkerId << delimiter;
values << PacketCount << delimiter;
values << EthCount << delimiter;
values << ArpCount << delimiter;
values << Ip4Count << delimiter;
values << Ip6Count << delimiter;
values << TcpCount << delimiter;
values << UdpCount << delimiter;
values << HttpCount << delimiter;
values << MatchedTcpFlows << delimiter;
values << MatchedUdpFlows << delimiter;
values << MatchedPackets;

return values.str();
}

static void getStatsColumns(std::vector<std::string>& columnNames, std::vector<int>& columnWidths)
{
columnNames.clear();
columnWidths.clear();

static const int narrowColumnWidth = 11;
static const int wideColumnWidth = 18;

columnNames.push_back("Core ID");
columnNames.push_back("Packet Cnt");
columnNames.push_back("Eth Cnt");
columnNames.push_back("ARP Cnt");
columnNames.push_back("IPv4 Cnt");
columnNames.push_back("IPv6 Cnt");
columnNames.push_back("TCP Cnt");
columnNames.push_back("UDP Cnt");
columnNames.push_back("HTTP Cnt");
columnNames.push_back("Matched TCP Flows");
columnNames.push_back("Matched UDP Flows");
columnNames.push_back("Matched Packets");

columnWidths.push_back(7);
columnWidths.push_back(narrowColumnWidth);
columnWidths.push_back(narrowColumnWidth);
columnWidths.push_back(narrowColumnWidth);
columnWidths.push_back(narrowColumnWidth);
columnWidths.push_back(narrowColumnWidth);
columnWidths.push_back(narrowColumnWidth);
columnWidths.push_back(narrowColumnWidth);
columnWidths.push_back(narrowColumnWidth);
columnWidths.push_back(wideColumnWidth);
columnWidths.push_back(wideColumnWidth);
columnWidths.push_back(wideColumnWidth);

workerId = MAX_NUM_OF_CORES+1;
packetCount = 0;
ethCount = 0;
arpCount = 0;
ipv4Count = 0;
ipv6Count = 0;
tcpCount = 0;
udpCount = 0;
httpCount = 0;
dnsCount = 0;
tlsCount = 0;

matchedTcpFlows = 0;
matchedUdpFlows = 0;
matchedPackets = 0;
}
};
Loading

0 comments on commit f5f6d41

Please sign in to comment.