Add the capability to iterate through the packets in a pktfifo,
and to remove elements in the middle of the fifo. These elements do not free space, they are just marked removed. Space is only freed from the front of the fifo. dev/etherpkt.cc: serialize the current slack dev/etherpkt.hh: add "slack" to the ethernet packet. It is to be used by any fifo that the packet is currently in to account for extra space that the packet may be occupying due to the fifo organization. --HG-- extra : convert_revision : 8e7c541ba316a9a76495c54cc5f707f8fc65b6d5
This commit is contained in:
parent
c0a4836077
commit
60e92986f7
3 changed files with 56 additions and 8 deletions
|
@ -38,6 +38,7 @@ void
|
||||||
PacketData::serialize(const string &base, ostream &os)
|
PacketData::serialize(const string &base, ostream &os)
|
||||||
{
|
{
|
||||||
paramOut(os, base + ".length", length);
|
paramOut(os, base + ".length", length);
|
||||||
|
paramOut(os, base + ".slack", slack);
|
||||||
arrayParamOut(os, base + ".data", data, length);
|
arrayParamOut(os, base + ".data", data, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,6 +47,7 @@ PacketData::unserialize(const string &base, Checkpoint *cp,
|
||||||
const string §ion)
|
const string §ion)
|
||||||
{
|
{
|
||||||
paramIn(cp, section, base + ".length", length);
|
paramIn(cp, section, base + ".length", length);
|
||||||
|
paramIn(cp, section, base + ".slack", slack);
|
||||||
if (length)
|
if (length)
|
||||||
arrayParamIn(cp, section, base + ".data", data, length);
|
arrayParamIn(cp, section, base + ".data", data, length);
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,14 +47,30 @@ class Checkpoint;
|
||||||
class PacketData : public RefCounted
|
class PacketData : public RefCounted
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
/*
|
||||||
|
* Pointer to packet data will be deleted
|
||||||
|
*/
|
||||||
uint8_t *data;
|
uint8_t *data;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Length of the current packet
|
||||||
|
*/
|
||||||
int length;
|
int length;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Extra space taken up by the packet in whatever data structure
|
||||||
|
* it is in.
|
||||||
|
*
|
||||||
|
* NOTE: This can only be use by *one* data structure at a time!
|
||||||
|
*/
|
||||||
|
int slack;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PacketData() : data(NULL), length(0) { }
|
PacketData() : data(NULL), length(0), slack(0) { }
|
||||||
explicit PacketData(size_t size) : data(new uint8_t[size]), length(0) { }
|
explicit PacketData(size_t size)
|
||||||
PacketData(std::auto_ptr<uint8_t> d, int l)
|
: data(new uint8_t[size]), length(0), slack(0) { }
|
||||||
: data(d.release()), length(l) { }
|
PacketData(std::auto_ptr<uint8_t> d, int l, int s = 0)
|
||||||
|
: data(d.release()), length(l), slack(s) { }
|
||||||
~PacketData() { if (data) delete [] data; }
|
~PacketData() { if (data) delete [] data; }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -39,6 +39,10 @@
|
||||||
class Checkpoint;
|
class Checkpoint;
|
||||||
class PacketFifo
|
class PacketFifo
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
typedef std::list<PacketPtr> fifo_list;
|
||||||
|
typedef fifo_list::iterator iterator;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::list<PacketPtr> fifo;
|
std::list<PacketPtr> fifo;
|
||||||
int _maxsize;
|
int _maxsize;
|
||||||
|
@ -64,9 +68,16 @@ class PacketFifo
|
||||||
return _reserved;
|
return _reserved;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
iterator begin() { return fifo.begin(); }
|
||||||
|
iterator end() { return fifo.end(); }
|
||||||
|
|
||||||
|
PacketPtr front() { return fifo.front(); }
|
||||||
|
|
||||||
bool push(PacketPtr ptr)
|
bool push(PacketPtr ptr)
|
||||||
{
|
{
|
||||||
|
assert(ptr->length);
|
||||||
assert(_reserved <= ptr->length);
|
assert(_reserved <= ptr->length);
|
||||||
|
assert(ptr->slack == 0);
|
||||||
if (avail() < ptr->length - _reserved)
|
if (avail() < ptr->length - _reserved)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -76,25 +87,44 @@ class PacketFifo
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
PacketPtr front() { return fifo.front(); }
|
|
||||||
|
|
||||||
void pop()
|
void pop()
|
||||||
{
|
{
|
||||||
if (empty())
|
if (empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_size -= fifo.front()->length;
|
PacketPtr &packet = fifo.front();
|
||||||
fifo.front() = NULL;
|
_size -= packet->length;
|
||||||
|
_size -= packet->slack;
|
||||||
|
packet->slack = 0;
|
||||||
|
packet = NULL;
|
||||||
fifo.pop_front();
|
fifo.pop_front();
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear()
|
void clear()
|
||||||
{
|
{
|
||||||
|
for (iterator i = begin(); i != end(); ++i)
|
||||||
|
(*i)->slack = 0;
|
||||||
fifo.clear();
|
fifo.clear();
|
||||||
_size = 0;
|
_size = 0;
|
||||||
_reserved = 0;
|
_reserved = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void remove(iterator i)
|
||||||
|
{
|
||||||
|
PacketPtr &packet = *i;
|
||||||
|
if (i != fifo.begin()) {
|
||||||
|
--i;
|
||||||
|
(*i)->slack += packet->length;
|
||||||
|
} else {
|
||||||
|
_size -= packet->length;
|
||||||
|
_size -= packet->slack;
|
||||||
|
}
|
||||||
|
|
||||||
|
packet->slack = 0;
|
||||||
|
packet = NULL;
|
||||||
|
fifo.erase(i);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serialization stuff
|
* Serialization stuff
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue