-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAppReceiverThread.h
89 lines (71 loc) · 1.96 KB
/
AppReceiverThread.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#pragma once
#include "Common.h"
#include "PacketUtils.h"
#include "DpdkDevice.h"
#include "DpdkDeviceList.h"
#include "PcapFileDevice.h"
using namespace pcpp;
/**
* The worker thread class which does all the work. It's initialized with pointers to the RX and TX devices, then it runs in
* an endless loop which reads packets from the RX device and sends them to the TX device.
* The endless loop is interrupted only when the thread is asked to stop (calling its stop() method)
*/
class AppReceiverThread : public DpdkWorkerThread
{
private:
AppWorkerConfig& m_WorkerConfig;
bool m_Stop;
uint32_t m_CoreId;
public:
AppReceiverThread(AppWorkerConfig& workerConfig) :
m_WorkerConfig(workerConfig), m_Stop(true), m_CoreId(MAX_NUM_OF_CORES+1)
{
}
virtual ~AppReceiverThread()
{
// do nothing
}
// implement abstract methods
bool run(uint32_t coreId)
{
m_CoreId = coreId;
m_Stop = false;
DpdkDevice* rxDevice = m_WorkerConfig.RxDevice;
DpdkDevice* txDevice = m_WorkerConfig.TxDevice;
// if no DPDK devices were assigned to this worker/core don't enter the main loop and exit
if (!rxDevice || !txDevice)
{
return true;
}
#define MAX_RECEIVE_BURST 1064
MBufRawPacket* packetArr[MAX_RECEIVE_BURST] = {};
// main loop, runs until be told to stop
while (!m_Stop)
{
for(uint16_t i = 0; i < m_WorkerConfig.RxQueues; i++)
{
// receive packets from network on the specified DPDK device
uint16_t packetsReceived = rxDevice->receivePackets(packetArr, MAX_RECEIVE_BURST, i);
if (packetsReceived > 0)
{
}
}
}
// free packet array (frees all mbufs as well)
for (int i = 0; i < MAX_RECEIVE_BURST; i++)
{
if (packetArr[i] != NULL)
delete packetArr[i];
}
return true;
}
void stop()
{
// assign the stop flag which will cause the main loop to end
m_Stop = true;
}
uint32_t getCoreId()
{
return m_CoreId;
}
};