45 std::vector<bool> sendMask;
57 BufArray(Packet **pkts, uint32_t numPkts,
bool fromLua =
false) {
59 this->fromLua = fromLua;
63 throw std::runtime_error(
64 "BufArray::BufArray() Please use an array with at least one slot");
71 sendMask.resize(numPkts);
72 for (uint32_t i = 0; i < numPkts; i++) {
88 assert(pktIdx < numBufs);
89 sendMask[pktIdx] =
false;
97 assert(pkt !=
nullptr);
98 for (uint32_t pktIdx = 0; pktIdx < numBufs; pktIdx++) {
99 if (pkt == pkts[pktIdx]) {
100 sendMask[pktIdx] =
false;
110 assert(pktIdx < numBufs);
111 sendMask[pktIdx] =
true;
122 if (numBufs == numSlots) {
125 reinterpret_cast<Packet **
>(malloc((
sizeof(Packet *) * numSlots * 2)));
126 for (uint32_t i = 0; i < numSlots; i++) {
127 newPkts[i] = pkts[i];
136 sendMask.resize(numSlots);
143 sendMask[numBufs] =
true;
144 pkts[numBufs++] = pkt;
153 for (
auto i : sendMask) {
168 return numBufs - sendCount;
176 uint32_t curSendBufs = 0;
177 uint32_t curPkts = 0;
180 while (curSendBufs < sendCount) {
181 if (sendMask[curPkts]) {
182 sendBufs[curSendBufs++] = pkts[curPkts++];
194 uint32_t curFreeBufs = 0;
195 uint32_t curPkts = 0;
198 while (curFreeBufs < freeCount) {
199 if (!sendMask[curPkts]) {
200 freeBufs[curFreeBufs++] = pkts[curPkts++];
213 Packet *
operator[](
unsigned int idx)
const {
return pkts[idx]; }
228 if (this->idx == it.idx) {
void markDropPkt(uint32_t pktIdx)
Mark one packet as drop.
void markSendPkt(uint32_t pktIdx)
Mark one packet as send.
uint32_t getFreeCount() const
Get the number of packets currently marked as free.
iterator(const iterator &it)
BufArray(Packet **pkts, uint32_t numPkts, bool fromLua=false)
Constructor.
uint32_t getTotalCount() const
Get the number of all packets in the BufArray.
void markDropPkt(Packet *pkt)
Mark one packet as drop.
Packet * operator[](unsigned int idx) const
uint32_t getSendCount() const
Get the number of packets currently marked as send.
void addPkt(Packet *pkt)
Add one packet to the BufArray.
void getSendBufs(Packet **sendBufs) const
Get all the packets which are to be sent.
void getFreeBufs(Packet **freeBufs) const
Get all the packets which are to be freed.
Wrapper around MoonGen bufarrays.
bool operator==(const iterator &it) const
bool operator!=(const iterator &it) const