rename normal tags to byte tags

This commit is contained in:
Mathieu Lacage
2009-03-23 20:41:26 +01:00
parent efec0cd2d0
commit fd76798519
10 changed files with 175 additions and 167 deletions

View File

@@ -131,7 +131,7 @@ void Sender::SendPacket()
TimestampTag timestamp;
timestamp.SetTimestamp(Simulator::Now());
packet->AddTag(timestamp);
packet->AddByteTag (timestamp);
// Could connect the socket since the address never changes; using SendTo
// here simply because all of the standard apps do not.
@@ -250,7 +250,7 @@ Receiver::Receive(Ptr<Socket> socket)
}
TimestampTag timestamp;
packet->FindFirstMatchingTag(timestamp);
packet->FindFirstMatchingByteTag(timestamp);
Time tx = timestamp.GetTimestamp();
if (m_delay != 0) {

View File

@@ -104,7 +104,7 @@ UdpEchoServer::HandleRead (Ptr<Socket> socket)
NS_LOG_INFO ("Received " << packet->GetSize() << " bytes from " <<
address.GetIpv4());
packet->RemoveAllTags ();
packet->RemoveAllPacketTags ();
NS_LOG_LOGIC ("Echoing packet");
socket->SendTo (packet, 0, from);

View File

@@ -17,12 +17,12 @@
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#include "tag-list.h"
#include "byte-tag-list.h"
#include "ns3/log.h"
#include <vector>
#include <string.h>
NS_LOG_COMPONENT_DEFINE ("TagList");
NS_LOG_COMPONENT_DEFINE ("ByteTagList");
#define USE_FREE_LIST 1
#define FREE_LIST_SIZE 1000
@@ -30,7 +30,7 @@ NS_LOG_COMPONENT_DEFINE ("TagList");
namespace ns3 {
struct TagListData {
struct ByteTagListData {
uint32_t size;
uint32_t count;
uint32_t dirty;
@@ -38,16 +38,16 @@ struct TagListData {
};
#ifdef USE_FREE_LIST
static class TagListDataFreeList : public std::vector<struct TagListData *>
static class ByteTagListDataFreeList : public std::vector<struct ByteTagListData *>
{
public:
~TagListDataFreeList ();
~ByteTagListDataFreeList ();
} g_freeList;
static uint32_t g_maxSize = 0;
TagListDataFreeList::~TagListDataFreeList ()
ByteTagListDataFreeList::~ByteTagListDataFreeList ()
{
for (TagListDataFreeList::iterator i = begin ();
for (ByteTagListDataFreeList::iterator i = begin ();
i != end (); i++)
{
uint8_t *buffer = (uint8_t *)(*i);
@@ -56,17 +56,17 @@ TagListDataFreeList::~TagListDataFreeList ()
}
#endif /* USE_FREE_LIST */
TagList::Iterator::Item::Item (TagBuffer buf_)
ByteTagList::Iterator::Item::Item (TagBuffer buf_)
: buf (buf_)
{}
bool
TagList::Iterator::HasNext (void) const
ByteTagList::Iterator::HasNext (void) const
{
return m_current < m_end;
}
struct TagList::Iterator::Item
TagList::Iterator::Next (void)
struct ByteTagList::Iterator::Item
ByteTagList::Iterator::Next (void)
{
NS_ASSERT (HasNext ());
struct Item item = Item (TagBuffer (m_current+16, m_end));
@@ -80,7 +80,7 @@ TagList::Iterator::Next (void)
return item;
}
void
TagList::Iterator::PrepareForNext (void)
ByteTagList::Iterator::PrepareForNext (void)
{
while (m_current < m_end)
{
@@ -99,7 +99,7 @@ TagList::Iterator::PrepareForNext (void)
}
}
}
TagList::Iterator::Iterator (uint8_t *start, uint8_t *end, int32_t offsetStart, int32_t offsetEnd)
ByteTagList::Iterator::Iterator (uint8_t *start, uint8_t *end, int32_t offsetStart, int32_t offsetEnd)
: m_current (start),
m_end (end),
m_offsetStart (offsetStart),
@@ -109,19 +109,19 @@ TagList::Iterator::Iterator (uint8_t *start, uint8_t *end, int32_t offsetStart,
}
uint32_t
TagList::Iterator::GetOffsetStart (void) const
ByteTagList::Iterator::GetOffsetStart (void) const
{
return m_offsetStart;
}
TagList::TagList ()
ByteTagList::ByteTagList ()
: m_used (0),
m_data (0)
{
NS_LOG_FUNCTION (this);
}
TagList::TagList (const TagList &o)
ByteTagList::ByteTagList (const ByteTagList &o)
: m_used (o.m_used),
m_data (o.m_data)
{
@@ -131,8 +131,8 @@ TagList::TagList (const TagList &o)
m_data->count++;
}
}
TagList &
TagList::operator = (const TagList &o)
ByteTagList &
ByteTagList::operator = (const ByteTagList &o)
{
NS_LOG_FUNCTION (this << &o);
if (this == &o)
@@ -149,7 +149,7 @@ TagList::operator = (const TagList &o)
}
return *this;
}
TagList::~TagList ()
ByteTagList::~ByteTagList ()
{
NS_LOG_FUNCTION (this);
Deallocate (m_data);
@@ -158,7 +158,7 @@ TagList::~TagList ()
}
TagBuffer
TagList::Add (TypeId tid, uint32_t bufferSize, int32_t start, int32_t end)
ByteTagList::Add (TypeId tid, uint32_t bufferSize, int32_t start, int32_t end)
{
NS_LOG_FUNCTION (this << tid << bufferSize << start << end);
uint32_t spaceNeeded = m_used + bufferSize + 4 + 4 + 4 + 4;
@@ -171,7 +171,7 @@ TagList::Add (TypeId tid, uint32_t bufferSize, int32_t start, int32_t end)
else if (m_data->size < spaceNeeded ||
(m_data->count != 1 && m_data->dirty != m_used))
{
struct TagListData *newData = Allocate (spaceNeeded);
struct ByteTagListData *newData = Allocate (spaceNeeded);
memcpy (&newData->data, &m_data->data, m_used);
Deallocate (m_data);
m_data = newData;
@@ -188,20 +188,20 @@ TagList::Add (TypeId tid, uint32_t bufferSize, int32_t start, int32_t end)
}
void
TagList::Add (const TagList &o)
ByteTagList::Add (const ByteTagList &o)
{
NS_LOG_FUNCTION (this << &o);
TagList::Iterator i = o.BeginAll ();
ByteTagList::Iterator i = o.BeginAll ();
while (i.HasNext ())
{
TagList::Iterator::Item item = i.Next ();
ByteTagList::Iterator::Item item = i.Next ();
TagBuffer buf = Add (item.tid, item.size, item.start, item.end);
buf.CopyFrom (item.buf);
}
}
void
TagList::RemoveAll (void)
ByteTagList::RemoveAll (void)
{
NS_LOG_FUNCTION (this);
Deallocate (m_data);
@@ -209,8 +209,8 @@ TagList::RemoveAll (void)
m_used = 0;
}
TagList::Iterator
TagList::BeginAll (void) const
ByteTagList::Iterator
ByteTagList::BeginAll (void) const
{
NS_LOG_FUNCTION (this);
// I am not totally sure but I might need to use
@@ -218,8 +218,8 @@ TagList::BeginAll (void) const
return Begin (0, OFFSET_MAX);
}
TagList::Iterator
TagList::Begin (int32_t offsetStart, int32_t offsetEnd) const
ByteTagList::Iterator
ByteTagList::Begin (int32_t offsetStart, int32_t offsetEnd) const
{
NS_LOG_FUNCTION (this << offsetStart << offsetEnd);
if (m_data == 0)
@@ -233,13 +233,13 @@ TagList::Begin (int32_t offsetStart, int32_t offsetEnd) const
}
bool
TagList::IsDirtyAtEnd (int32_t appendOffset)
ByteTagList::IsDirtyAtEnd (int32_t appendOffset)
{
NS_LOG_FUNCTION (this << appendOffset);
TagList::Iterator i = BeginAll ();
ByteTagList::Iterator i = BeginAll ();
while (i.HasNext ())
{
TagList::Iterator::Item item = i.Next ();
ByteTagList::Iterator::Item item = i.Next ();
if (item.end > appendOffset)
{
return true;
@@ -249,13 +249,13 @@ TagList::IsDirtyAtEnd (int32_t appendOffset)
}
bool
TagList::IsDirtyAtStart (int32_t prependOffset)
ByteTagList::IsDirtyAtStart (int32_t prependOffset)
{
NS_LOG_FUNCTION (this << prependOffset);
TagList::Iterator i = BeginAll ();
ByteTagList::Iterator i = BeginAll ();
while (i.HasNext ())
{
TagList::Iterator::Item item = i.Next ();
ByteTagList::Iterator::Item item = i.Next ();
if (item.start < prependOffset)
{
return true;
@@ -265,18 +265,18 @@ TagList::IsDirtyAtStart (int32_t prependOffset)
}
void
TagList::AddAtEnd (int32_t adjustment, int32_t appendOffset)
ByteTagList::AddAtEnd (int32_t adjustment, int32_t appendOffset)
{
NS_LOG_FUNCTION (this << adjustment << appendOffset);
if (adjustment == 0 && !IsDirtyAtEnd (appendOffset))
{
return;
}
TagList list;
TagList::Iterator i = BeginAll ();
ByteTagList list;
ByteTagList::Iterator i = BeginAll ();
while (i.HasNext ())
{
TagList::Iterator::Item item = i.Next ();
ByteTagList::Iterator::Item item = i.Next ();
item.start += adjustment;
item.end += adjustment;
@@ -299,18 +299,18 @@ TagList::AddAtEnd (int32_t adjustment, int32_t appendOffset)
}
void
TagList::AddAtStart (int32_t adjustment, int32_t prependOffset)
ByteTagList::AddAtStart (int32_t adjustment, int32_t prependOffset)
{
NS_LOG_FUNCTION (this << adjustment << prependOffset);
if (adjustment == 0 && !IsDirtyAtStart (prependOffset))
{
return;
}
TagList list;
TagList::Iterator i = BeginAll ();
ByteTagList list;
ByteTagList::Iterator i = BeginAll ();
while (i.HasNext ())
{
TagList::Iterator::Item item = i.Next ();
ByteTagList::Iterator::Item item = i.Next ();
item.start += adjustment;
item.end += adjustment;
@@ -334,13 +334,13 @@ TagList::AddAtStart (int32_t adjustment, int32_t prependOffset)
#ifdef USE_FREE_LIST
struct TagListData *
TagList::Allocate (uint32_t size)
struct ByteTagListData *
ByteTagList::Allocate (uint32_t size)
{
NS_LOG_FUNCTION (this << size);
while (!g_freeList.empty ())
{
struct TagListData *data = g_freeList.back ();
struct ByteTagListData *data = g_freeList.back ();
g_freeList.pop_back ();
NS_ASSERT (data != 0);
if (data->size >= size)
@@ -352,8 +352,8 @@ TagList::Allocate (uint32_t size)
uint8_t *buffer = (uint8_t *)data;
delete [] buffer;
}
uint8_t *buffer = new uint8_t [std::max (size, g_maxSize) + sizeof (struct TagListData) - 4];
struct TagListData *data = (struct TagListData *)buffer;
uint8_t *buffer = new uint8_t [std::max (size, g_maxSize) + sizeof (struct ByteTagListData) - 4];
struct ByteTagListData *data = (struct ByteTagListData *)buffer;
data->count = 1;
data->size = size;
data->dirty = 0;
@@ -361,7 +361,7 @@ TagList::Allocate (uint32_t size)
}
void
TagList::Deallocate (struct TagListData *data)
ByteTagList::Deallocate (struct ByteTagListData *data)
{
NS_LOG_FUNCTION (this << data);
if (data == 0)
@@ -387,12 +387,12 @@ TagList::Deallocate (struct TagListData *data)
#else /* USE_FREE_LIST */
struct TagListData *
TagList::Allocate (uint32_t size)
struct ByteTagListData *
ByteTagList::Allocate (uint32_t size)
{
NS_LOG_FUNCTION (this << size);
uint8_t *buffer = new uint8_t [size + sizeof (struct TagListData) - 4];
struct TagListData *data = (struct TagListData *)buffer;
uint8_t *buffer = new uint8_t [size + sizeof (struct ByteTagListData) - 4];
struct ByteTagListData *data = (struct ByteTagListData *)buffer;
data->count = 1;
data->size = size;
data->dirty = 0;
@@ -400,7 +400,7 @@ TagList::Allocate (uint32_t size)
}
void
TagList::Deallocate (struct TagListData *data)
ByteTagList::Deallocate (struct ByteTagListData *data)
{
NS_LOG_FUNCTION (this << data);
if (data == 0)

View File

@@ -26,7 +26,7 @@
namespace ns3 {
struct TagListData;
struct ByteTagListData;
/**
* \ingroup packet
@@ -44,7 +44,7 @@ struct TagListData;
* as 4 32bit integers (TypeId, tag data size, start, end) followed
* by the tag data as generated by Tag::Serialize.
*
* - the struct TagListData structure which contains the tag byte buffer
* - the struct ByteTagListData structure which contains the tag byte buffer
* is shared and, thus, reference-counted. This data structure is unshared
* as-needed to emulate COW semantics.
*
@@ -53,19 +53,19 @@ struct TagListData;
* and Buffer::GetCurrentEndOffset which means that they are relative to
* the start of the 'virtual byte buffer' as explained in the documentation
* for the ns3::Buffer class. Whenever the origin of the offset of the Buffer
* instance associated to this TagList instance changes, the Buffer class
* instance associated to this ByteTagList instance changes, the Buffer class
* reports this to its container Packet class as a bool return value
* in Buffer::AddAtStart and Buffer::AddAtEnd. In both cases, when this happens
* the Packet class calls TagList::AddAtEnd and TagList::AddAtStart to update
* the byte offsets of each tag in the TagList.
* the Packet class calls ByteTagList::AddAtEnd and ByteTagList::AddAtStart to update
* the byte offsets of each tag in the ByteTagList.
*
* - whenever bytes are removed from the packet byte buffer, the TagList offsets
* - whenever bytes are removed from the packet byte buffer, the ByteTagList offsets
* are never updated because we rely on the fact that they will be updated in
* either the next call to Packet::AddHeader or Packet::AddTrailer or when
* the user iterates the tag list with Packet::GetTagIterator and
* TagIterator::Next.
*/
class TagList
class ByteTagList
{
public:
@@ -81,14 +81,14 @@ public:
TagBuffer buf;
Item (TagBuffer buf);
private:
friend class TagList;
friend class TagList::Iterator;
friend class ByteTagList;
friend class ByteTagList::Iterator;
};
bool HasNext (void) const;
struct TagList::Iterator::Item Next (void);
struct ByteTagList::Iterator::Item Next (void);
uint32_t GetOffsetStart (void) const;
private:
friend class TagList;
friend class ByteTagList;
Iterator (uint8_t *start, uint8_t *end, int32_t offsetStart, int32_t offsetEnd);
void PrepareForNext (void);
uint8_t *m_current;
@@ -101,10 +101,10 @@ public:
int32_t m_nextEnd;
};
TagList ();
TagList (const TagList &o);
TagList &operator = (const TagList &o);
~TagList ();
ByteTagList ();
ByteTagList (const ByteTagList &o);
ByteTagList &operator = (const ByteTagList &o);
~ByteTagList ();
/**
* \param tid the typeid of the tag added
@@ -123,22 +123,22 @@ public:
*
* Aggregate the two lists of tags.
*/
void Add (const TagList &o);
void Add (const ByteTagList &o);
void RemoveAll (void);
/**
* \param offsetStart the offset which uniquely identifies the first data byte
* present in the byte buffer associated to this TagList.
* present in the byte buffer associated to this ByteTagList.
* \param offsetEnd the offset which uniquely identifies the last data byte
* present in the byte buffer associated to this TagList.
* present in the byte buffer associated to this ByteTagList.
* \returns an iterator
*
* The returned iterator will allow you to loop through the set of tags present
* in this list: the boundaries of each tag as reported by their start and
* end offsets will be included within the input offsetStart and offsetEnd.
*/
TagList::Iterator Begin (int32_t offsetStart, int32_t offsetEnd) const;
ByteTagList::Iterator Begin (int32_t offsetStart, int32_t offsetEnd) const;
/**
* Adjust the offsets stored internally by the adjustment delta and
@@ -156,13 +156,13 @@ public:
private:
bool IsDirtyAtEnd (int32_t appendOffset);
bool IsDirtyAtStart (int32_t prependOffset);
TagList::Iterator BeginAll (void) const;
ByteTagList::Iterator BeginAll (void) const;
struct TagListData *Allocate (uint32_t size);
void Deallocate (struct TagListData *data);
struct ByteTagListData *Allocate (uint32_t size);
void Deallocate (struct ByteTagListData *data);
uint16_t m_used;
struct TagListData *m_data;
struct ByteTagListData *m_data;
};
} // namespace ns3

View File

@@ -36,6 +36,7 @@ uint32_t PacketTagList::g_nfree = 0;
struct PacketTagList::TagData *
PacketTagList::AllocData (void) const
{
NS_LOG_FUNCTION (g_nfree);
struct PacketTagList::TagData *retval;
if (g_free != 0)
{
@@ -53,6 +54,7 @@ PacketTagList::AllocData (void) const
void
PacketTagList::FreeData (struct TagData *data) const
{
NS_LOG_FUNCTION (g_nfree << data);
if (g_nfree > 1000)
{
delete data;
@@ -67,6 +69,7 @@ PacketTagList::FreeData (struct TagData *data) const
struct PacketTagList::TagData *
PacketTagList::AllocData (void) const
{
NS_LOG_FUNCTION_NOARGS ();
struct PacketTagList::TagData *retval;
retval = new struct PacketTagList::TagData ();
return retval;
@@ -75,6 +78,7 @@ PacketTagList::AllocData (void) const
void
PacketTagList::FreeData (struct TagData *data) const
{
NS_LOG_FUNCTION (data);
delete data;
}
#endif
@@ -82,6 +86,7 @@ PacketTagList::FreeData (struct TagData *data) const
bool
PacketTagList::Remove (Tag &tag)
{
NS_LOG_FUNCTION (this << tag.GetInstanceTypeId ());
TypeId tid = tag.GetInstanceTypeId ();
bool found = false;
for (struct TagData *cur = m_next; cur != 0; cur = cur->next)
@@ -127,6 +132,7 @@ PacketTagList::Remove (Tag &tag)
void
PacketTagList::Add (const Tag &tag) const
{
NS_LOG_FUNCTION (this << tag.GetInstanceTypeId ());
// ensure this id was not yet added
for (struct TagData *cur = m_next; cur != 0; cur = cur->next)
{
@@ -146,6 +152,7 @@ PacketTagList::Add (const Tag &tag) const
bool
PacketTagList::Peek (Tag &tag) const
{
NS_LOG_FUNCTION (this << tag.GetInstanceTypeId ());
TypeId tid = tag.GetInstanceTypeId ();
for (struct TagData *cur = m_next; cur != 0; cur = cur->next)
{

View File

@@ -28,22 +28,22 @@ namespace ns3 {
uint32_t Packet::m_globalUid = 0;
TypeId
TagIterator::Item::GetTypeId (void) const
ByteTagIterator::Item::GetTypeId (void) const
{
return m_tid;
}
uint32_t
TagIterator::Item::GetStart (void) const
ByteTagIterator::Item::GetStart (void) const
{
return m_start;
}
uint32_t
TagIterator::Item::GetEnd (void) const
ByteTagIterator::Item::GetEnd (void) const
{
return m_end;
}
void
TagIterator::Item::GetTag (Tag &tag) const
ByteTagIterator::Item::GetTag (Tag &tag) const
{
if (tag.GetInstanceTypeId () != GetTypeId ())
{
@@ -51,27 +51,27 @@ TagIterator::Item::GetTag (Tag &tag) const
}
tag.Deserialize (m_buffer);
}
TagIterator::Item::Item (TypeId tid, uint32_t start, uint32_t end, TagBuffer buffer)
ByteTagIterator::Item::Item (TypeId tid, uint32_t start, uint32_t end, TagBuffer buffer)
: m_tid (tid),
m_start (start),
m_end (end),
m_buffer (buffer)
{}
bool
TagIterator::HasNext (void) const
ByteTagIterator::HasNext (void) const
{
return m_current.HasNext ();
}
TagIterator::Item
TagIterator::Next (void)
ByteTagIterator::Item
ByteTagIterator::Next (void)
{
TagList::Iterator::Item i = m_current.Next ();
return TagIterator::Item (i.tid,
i.start-m_current.GetOffsetStart (),
i.end-m_current.GetOffsetStart (),
i.buf);
ByteTagList::Iterator::Item i = m_current.Next ();
return ByteTagIterator::Item (i.tid,
i.start-m_current.GetOffsetStart (),
i.end-m_current.GetOffsetStart (),
i.buf);
}
TagIterator::TagIterator (TagList::Iterator i)
ByteTagIterator::ByteTagIterator (ByteTagList::Iterator i)
: m_current (i)
{}
@@ -135,7 +135,7 @@ Packet::Copy (void) const
Packet::Packet ()
: m_buffer (),
m_tagList (),
m_byteTagList (),
m_packetTagList (),
m_metadata (m_globalUid, 0),
m_refCount (1)
@@ -145,7 +145,7 @@ Packet::Packet ()
Packet::Packet (const Packet &o)
: m_buffer (o.m_buffer),
m_tagList (o.m_tagList),
m_byteTagList (o.m_byteTagList),
m_packetTagList (o.m_packetTagList),
m_metadata (o.m_metadata),
m_refCount (1)
@@ -159,7 +159,7 @@ Packet::operator = (const Packet &o)
return *this;
}
m_buffer = o.m_buffer;
m_tagList = o.m_tagList;
m_byteTagList = o.m_byteTagList;
m_packetTagList = o.m_packetTagList;
m_metadata = o.m_metadata;
return *this;
@@ -167,7 +167,7 @@ Packet::operator = (const Packet &o)
Packet::Packet (uint32_t size)
: m_buffer (size),
m_tagList (),
m_byteTagList (),
m_packetTagList (),
m_metadata (m_globalUid, size),
m_refCount (1)
@@ -176,7 +176,7 @@ Packet::Packet (uint32_t size)
}
Packet::Packet (uint8_t const*buffer, uint32_t size)
: m_buffer (),
m_tagList (),
m_byteTagList (),
m_packetTagList (),
m_metadata (m_globalUid, size),
m_refCount (1)
@@ -187,10 +187,10 @@ Packet::Packet (uint8_t const*buffer, uint32_t size)
i.Write (buffer, size);
}
Packet::Packet (const Buffer &buffer, const TagList &tagList,
Packet::Packet (const Buffer &buffer, const ByteTagList &byteTagList,
const PacketTagList &packetTagList, const PacketMetadata &metadata)
: m_buffer (buffer),
m_tagList (tagList),
m_byteTagList (byteTagList),
m_packetTagList (packetTagList),
m_metadata (metadata),
m_refCount (1)
@@ -206,7 +206,7 @@ Packet::CreateFragment (uint32_t start, uint32_t length) const
PacketMetadata metadata = m_metadata.CreateFragment (start, end);
// again, call the constructor directly rather than
// through Create because it is private.
return Ptr<Packet> (new Packet (buffer, m_tagList, m_packetTagList, metadata), false);
return Ptr<Packet> (new Packet (buffer, m_byteTagList, m_packetTagList, metadata), false);
}
uint32_t
@@ -224,8 +224,8 @@ Packet::AddHeader (const Header &header)
bool resized = m_buffer.AddAtStart (size);
if (resized)
{
m_tagList.AddAtStart (m_buffer.GetCurrentStartOffset () + size - orgStart,
m_buffer.GetCurrentStartOffset () + size);
m_byteTagList.AddAtStart (m_buffer.GetCurrentStartOffset () + size - orgStart,
m_buffer.GetCurrentStartOffset () + size);
}
header.Serialize (m_buffer.Begin ());
m_metadata.AddHeader (header, size);
@@ -255,8 +255,8 @@ Packet::AddTrailer (const Trailer &trailer)
bool resized = m_buffer.AddAtEnd (size);
if (resized)
{
m_tagList.AddAtEnd (m_buffer.GetCurrentStartOffset () - orgStart,
m_buffer.GetCurrentEndOffset () - size);
m_byteTagList.AddAtEnd (m_buffer.GetCurrentStartOffset () - orgStart,
m_buffer.GetCurrentEndOffset () - size);
}
Buffer::Iterator end = m_buffer.End ();
trailer.Serialize (end);
@@ -287,12 +287,12 @@ Packet::AddAtEnd (Ptr<const Packet> packet)
uint32_t bEnd = packet->m_buffer.GetCurrentEndOffset ();
m_buffer.AddAtEnd (packet->m_buffer);
uint32_t appendPrependOffset = m_buffer.GetCurrentEndOffset () - packet->m_buffer.GetSize ();
m_tagList.AddAtEnd (m_buffer.GetCurrentStartOffset () - aStart,
appendPrependOffset);
TagList copy = packet->m_tagList;
m_byteTagList.AddAtEnd (m_buffer.GetCurrentStartOffset () - aStart,
appendPrependOffset);
ByteTagList copy = packet->m_byteTagList;
copy.AddAtStart (m_buffer.GetCurrentEndOffset () - bEnd,
appendPrependOffset);
m_tagList.Add (copy);
m_byteTagList.Add (copy);
m_metadata.AddAtEnd (packet->m_metadata);
}
void
@@ -303,8 +303,8 @@ Packet::AddPaddingAtEnd (uint32_t size)
bool resized = m_buffer.AddAtEnd (size);
if (resized)
{
m_tagList.AddAtEnd (m_buffer.GetCurrentEndOffset () - orgEnd,
m_buffer.GetCurrentEndOffset () - size);
m_byteTagList.AddAtEnd (m_buffer.GetCurrentEndOffset () - orgEnd,
m_buffer.GetCurrentEndOffset () - size);
}
m_metadata.AddPaddingAtEnd (size);
}
@@ -324,10 +324,10 @@ Packet::RemoveAtStart (uint32_t size)
}
void
Packet::RemoveAllTags (void)
Packet::RemoveAllByteTags (void)
{
NS_LOG_FUNCTION (this);
m_tagList.RemoveAll ();
m_byteTagList.RemoveAll ();
}
uint8_t const *
@@ -356,12 +356,12 @@ Packet::GetUid (void) const
}
void
Packet::PrintTags (std::ostream &os) const
Packet::PrintByteTags (std::ostream &os) const
{
TagIterator i = GetTagIterator ();
ByteTagIterator i = GetByteTagIterator ();
while (i.HasNext ())
{
TagIterator::Item item = i.Next ();
ByteTagIterator::Item item = i.Next ();
os << item.GetTypeId ().GetName () << " [" << item.GetStart () << "-" << item.GetEnd () << "]";
Callback<ObjectBase *> constructor = item.GetTypeId ().GetConstructor ();
if (constructor.IsNull ())
@@ -584,29 +584,29 @@ Packet::Deserialize (Buffer buffer)
}
void
Packet::AddTag (const Tag &tag) const
Packet::AddByteTag (const Tag &tag) const
{
NS_LOG_FUNCTION (this << &tag);
TagList *list = const_cast<TagList *> (&m_tagList);
ByteTagList *list = const_cast<ByteTagList *> (&m_byteTagList);
TagBuffer buffer = list->Add (tag.GetInstanceTypeId (), tag.GetSerializedSize (),
m_buffer.GetCurrentStartOffset (),
m_buffer.GetCurrentEndOffset ());
m_buffer.GetCurrentStartOffset (),
m_buffer.GetCurrentEndOffset ());
tag.Serialize (buffer);
}
TagIterator
Packet::GetTagIterator (void) const
ByteTagIterator
Packet::GetByteTagIterator (void) const
{
return TagIterator (m_tagList.Begin (m_buffer.GetCurrentStartOffset (), m_buffer.GetCurrentEndOffset ()));
return ByteTagIterator (m_byteTagList.Begin (m_buffer.GetCurrentStartOffset (), m_buffer.GetCurrentEndOffset ()));
}
bool
Packet::FindFirstMatchingTag (Tag &tag) const
Packet::FindFirstMatchingByteTag (Tag &tag) const
{
TypeId tid = tag.GetInstanceTypeId ();
TagIterator i = GetTagIterator ();
ByteTagIterator i = GetByteTagIterator ();
while (i.HasNext ())
{
TagIterator::Item item = i.Next ();
ByteTagIterator::Item item = i.Next ();
if (tid == item.GetTypeId ())
{
item.GetTag (tag);
@@ -893,11 +893,11 @@ PacketTest::DoCheck (Ptr<const Packet> p, const char *file, int line, uint32_t n
}
va_end (ap);
TagIterator i = p->GetTagIterator ();
ByteTagIterator i = p->GetByteTagIterator ();
uint32_t j = 0;
while (i.HasNext () && j < expected.size ())
{
TagIterator::Item item = i.Next ();
ByteTagIterator::Item item = i.Next ();
struct Expected e = expected[j];
std::ostringstream oss;
oss << "anon::ATestTag<" << e.n << ">";
@@ -936,12 +936,12 @@ PacketTest::RunTests (void)
Ptr<const Packet> p = Create<Packet> (1000);
p->AddTag (ATestTag<1> ());
p->AddByteTag (ATestTag<1> ());
CHECK (p, 1, E (1, 0, 1000));
Ptr<const Packet> copy = p->Copy ();
CHECK (copy, 1, E (1, 0, 1000));
p->AddTag (ATestTag<2> ());
p->AddByteTag (ATestTag<2> ());
CHECK (p, 2, E (1, 0, 1000), E(2, 0, 1000));
CHECK (copy, 1, E (1, 0, 1000));
@@ -952,7 +952,7 @@ PacketTest::RunTests (void)
CHECK (&c0, 1, E (1, 0, 1000));
CHECK (&c1, 1, E (1, 0, 1000));
CHECK (copy, 1, E (1, 0, 1000));
c0.AddTag (ATestTag<10> ());
c0.AddByteTag (ATestTag<10> ());
CHECK (&c0, 2, E (1, 0, 1000), E (10, 0, 1000));
CHECK (&c1, 1, E (1, 0, 1000));
CHECK (copy, 1, E (1, 0, 1000));
@@ -961,11 +961,11 @@ PacketTest::RunTests (void)
Ptr<Packet> frag0 = p->CreateFragment (0, 10);
Ptr<Packet> frag1 = p->CreateFragment (10, 90);
Ptr<const Packet> frag2 = p->CreateFragment (100, 900);
frag0->AddTag (ATestTag<3> ());
frag0->AddByteTag (ATestTag<3> ());
CHECK (frag0, 3, E (1, 0, 10), E(2, 0, 10), E (3, 0, 10));
frag1->AddTag (ATestTag<4> ());
frag1->AddByteTag (ATestTag<4> ());
CHECK (frag1, 3, E (1, 0, 90), E(2, 0, 90), E (4, 0, 90));
frag2->AddTag (ATestTag<5> ());
frag2->AddByteTag (ATestTag<5> ());
CHECK (frag2, 3, E (1, 0, 900), E(2, 0, 900), E (5, 0, 900));
frag1->AddAtEnd (frag2);
@@ -985,7 +985,7 @@ PacketTest::RunTests (void)
frag0 = 0;
p = Create<Packet> (1000);
p->AddTag (ATestTag<20> ());
p->AddByteTag (ATestTag<20> ());
CHECK (p, 1, E (20, 0, 1000));
frag0 = p->CreateFragment (10, 90);
CHECK (p, 1, E (20, 0, 1000));
@@ -996,7 +996,7 @@ PacketTest::RunTests (void)
{
Ptr<Packet> tmp = Create<Packet> (100);
tmp->AddTag (ATestTag<20> ());
tmp->AddByteTag (ATestTag<20> ());
CHECK (tmp, 1, E (20, 0, 100));
tmp->AddHeader (ATestHeader<10> ());
CHECK (tmp, 1, E (20, 10, 110));
@@ -1007,7 +1007,7 @@ PacketTest::RunTests (void)
CHECK (tmp, 1, E (20, 10, 110));
tmp = Create<Packet> (100);
tmp->AddTag (ATestTag<20> ());
tmp->AddByteTag (ATestTag<20> ());
CHECK (tmp, 1, E (20, 0, 100));
tmp->AddTrailer (ATestTrailer<10> ());
CHECK (tmp, 1, E (20, 0, 100));
@@ -1022,7 +1022,7 @@ PacketTest::RunTests (void)
{
Ptr<Packet> tmp = Create<Packet> (0);
tmp->AddHeader (ATestHeader<156> ());
tmp->AddTag (ATestTag<20> ());
tmp->AddByteTag (ATestTag<20> ());
CHECK (tmp, 1, E (20, 0, 156));
tmp->RemoveAtStart (120);
CHECK (tmp, 1, E (20, 0, 36));
@@ -1033,17 +1033,17 @@ PacketTest::RunTests (void)
{
Ptr<Packet> tmp = Create<Packet> (0);
tmp->AddTag (ATestTag<20> ());
tmp->AddByteTag (ATestTag<20> ());
CHECK (tmp, 0, E (20, 0, 0));
}
{
Ptr<Packet> tmp = Create<Packet> (1000);
tmp->AddTag (ATestTag<20> ());
tmp->AddByteTag (ATestTag<20> ());
CHECK (tmp, 1, E (20, 0, 1000));
tmp->RemoveAtStart (1000);
CHECK (tmp, 0, E (0,0,0));
Ptr<Packet> a = Create<Packet> (10);
a->AddTag (ATestTag<10> ());
a->AddByteTag (ATestTag<10> ());
CHECK (a, 1, E (10, 0, 10));
tmp->AddAtEnd (a);
CHECK (tmp, 1, E (10, 0, 10));

View File

@@ -26,7 +26,7 @@
#include "trailer.h"
#include "packet-metadata.h"
#include "tag.h"
#include "tag-list.h"
#include "byte-tag-list.h"
#include "packet-tag-list.h"
#include "ns3/callback.h"
#include "ns3/assert.h"
@@ -46,7 +46,7 @@ namespace ns3 {
*
* This is a java-style iterator.
*/
class TagIterator
class ByteTagIterator
{
public:
/**
@@ -82,7 +82,7 @@ public:
*/
void GetTag (Tag &tag) const;
private:
friend class TagIterator;
friend class ByteTagIterator;
Item (TypeId tid, uint32_t start, uint32_t end, TagBuffer buffer);
TypeId m_tid;
uint32_t m_start;
@@ -99,8 +99,8 @@ public:
Item Next (void);
private:
friend class Packet;
TagIterator (TagList::Iterator i);
TagList::Iterator m_current;
ByteTagIterator (ByteTagList::Iterator i);
ByteTagList::Iterator m_current;
};
/**
@@ -284,13 +284,6 @@ public:
* \returns the number of bytes read from the end of the packet.
*/
uint32_t PeekTrailer (Trailer &trailer);
/**
* \param os output stream in which the data should be printed.
*
* Iterate over the tags present in this packet, and
* invoke the Print method of each tag stored in the packet.
*/
void PrintTags (std::ostream &os) const;
/**
* Concatenate the input packet at the end of the current
@@ -438,11 +431,11 @@ public:
* totally evil to allow a trace sink to modify the content of a
* packet).
*/
void AddTag (const Tag &tag) const;
void AddByteTag (const Tag &tag) const;
/**
* \returns an iterator over the set of tags included in this packet.
*/
TagIterator GetTagIterator (void) const;
ByteTagIterator GetByteTagIterator (void) const;
/**
* \param tag the tag to search in this packet
* \returns true if the requested tag type was found, false otherwise.
@@ -450,12 +443,20 @@ public:
* If the requested tag type is found, it is copied in the user's
* provided tag instance.
*/
bool FindFirstMatchingTag (Tag &tag) const;
bool FindFirstMatchingByteTag (Tag &tag) const;
/**
* Remove all the tags stored in this packet.
*/
void RemoveAllTags (void);
void RemoveAllByteTags (void);
/**
* \param os output stream in which the data should be printed.
*
* Iterate over the tags present in this packet, and
* invoke the Print method of each tag stored in the packet.
*/
void PrintByteTags (std::ostream &os) const;
/**
* \param tag the tag to store in this packet
@@ -497,10 +498,10 @@ public:
PacketTagIterator GetPacketTagIterator (void) const;
private:
Packet (const Buffer &buffer, const TagList &tagList,
Packet (const Buffer &buffer, const ByteTagList &byteTagList,
const PacketTagList &packetTagList, const PacketMetadata &metadata);
Buffer m_buffer;
TagList m_tagList;
ByteTagList m_byteTagList;
PacketTagList m_packetTagList;
PacketMetadata m_metadata;
mutable uint32_t m_refCount;

View File

@@ -14,7 +14,7 @@ def build(bld):
'data-rate.cc',
'error-model.cc',
'tag.cc',
'tag-list.cc',
'byte-tag-list.cc',
'tag-buffer.cc',
'packet-tag-list.cc',
]
@@ -32,7 +32,7 @@ def build(bld):
'data-rate.h',
'error-model.h',
'tag.h',
'tag-list.h',
'byte-tag-list.h',
'tag-buffer.h',
'packet-tag-list.h',
]

View File

@@ -83,14 +83,14 @@ void
DelayJitterEstimation::PrepareTx (Ptr<const Packet> packet)
{
DelayJitterEstimationTimestampTag tag;
packet->AddTag (tag);
packet->AddByteTag (tag);
}
void
DelayJitterEstimation::RecordRx (Ptr<const Packet> packet)
{
DelayJitterEstimationTimestampTag tag;
bool found;
found = packet->FindFirstMatchingTag (tag);
found = packet->FindFirstMatchingByteTag (tag);
if (!found)
{
return;

View File

@@ -148,7 +148,7 @@ void
CollisionExperiment::SendA (void) const
{
Ptr<Packet> p = Create<Packet> (m_input.packetSizeA);
p->AddTag (FlowIdTag (m_flowIdA));
p->AddByteTag (FlowIdTag (m_flowIdA));
m_txA->SendPacket (p, WifiMode (m_input.txModeA),
WIFI_PREAMBLE_SHORT, m_input.txPowerLevelA);
}
@@ -157,7 +157,7 @@ void
CollisionExperiment::SendB (void) const
{
Ptr<Packet> p = Create<Packet> (m_input.packetSizeB);
p->AddTag (FlowIdTag (m_flowIdB));
p->AddByteTag (FlowIdTag (m_flowIdB));
m_txB->SendPacket (p, WifiMode (m_input.txModeB),
WIFI_PREAMBLE_SHORT, m_input.txPowerLevelB);
}
@@ -166,7 +166,7 @@ void
CollisionExperiment::Receive (Ptr<Packet> p, double snr, WifiMode mode, enum WifiPreamble preamble)
{
FlowIdTag tag;
p->FindFirstMatchingTag (tag);
p->FindFirstMatchingByteTag (tag);
if (tag.GetFlowId () == m_flowIdA)
{
m_output.receivedA++;