# HG changeset patch # User Mathieu Lacage # Date 1209078393 25200 # Node ID a624276a897bec22f2f8ba78b5e16c89822aef0d # Parent e11e106c7c1995c5c6734cd1e79687092a317140 mtag -> tag diff -r e11e106c7c19 -r a624276a897b samples/main-packet-tag.cc --- a/samples/main-packet-tag.cc Thu Apr 24 16:03:13 2008 -0700 +++ b/samples/main-packet-tag.cc Thu Apr 24 16:06:33 2008 -0700 @@ -17,7 +17,7 @@ * * Author: Mathieu Lacage */ -#include "ns3/mtag.h" +#include "ns3/tag.h" #include "ns3/packet.h" #include "ns3/uinteger.h" #include diff -r e11e106c7c19 -r a624276a897b src/common/mtag-buffer.cc --- a/src/common/mtag-buffer.cc Thu Apr 24 16:03:13 2008 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,160 +0,0 @@ -#include "mtag-buffer.h" -#include "ns3/assert.h" - -namespace ns3 { - -void -TagBuffer::WriteU8 (uint8_t v) -{ - NS_ASSERT (m_current + 1 <= m_end); - *m_current = v; - m_current++; -} -void -TagBuffer::WriteU16 (uint16_t data) -{ - WriteU8 ((data >> 0) & 0xff); - WriteU8 ((data >> 8) & 0xff); -} -void -TagBuffer::WriteU32 (uint32_t data) -{ - WriteU8 ((data >> 0) & 0xff); - WriteU8 ((data >> 8) & 0xff); - WriteU8 ((data >> 16) & 0xff); - WriteU8 ((data >> 24) & 0xff); -} -void -TagBuffer::WriteU64 (uint64_t data) -{ - WriteU8 ((data >> 0) & 0xff); - WriteU8 ((data >> 8) & 0xff); - WriteU8 ((data >> 16) & 0xff); - WriteU8 ((data >> 24) & 0xff); - WriteU8 ((data >> 32) & 0xff); - WriteU8 ((data >> 40) & 0xff); - WriteU8 ((data >> 48) & 0xff); - WriteU8 ((data >> 54) & 0xff); -} -void -TagBuffer::WriteDouble (double v) -{ - uint8_t *buf = (uint8_t *)&v; - for (uint32_t i = 0; i < sizeof (double); ++i, ++buf) - { - WriteU8 (*buf); - } -} -void -TagBuffer::Write (const uint8_t *buffer, uint32_t size) -{ - for (uint32_t i = 0; i < size; ++i, ++buffer) - { - WriteU8 (*buffer); - } -} -uint8_t -TagBuffer::ReadU8 (void) -{ - NS_ASSERT (m_current + 1 <= m_end); - uint8_t v; - v = *m_current; - m_current++; - return v; -} -uint16_t -TagBuffer::ReadU16 (void) -{ - uint8_t byte0 = ReadU8 (); - uint8_t byte1 = ReadU8 (); - uint16_t data = byte1; - data <<= 8; - data |= byte0; - return data; -} -uint32_t -TagBuffer::ReadU32 (void) -{ - uint8_t byte0 = ReadU8 (); - uint8_t byte1 = ReadU8 (); - uint8_t byte2 = ReadU8 (); - uint8_t byte3 = ReadU8 (); - uint32_t data = byte3; - data <<= 8; - data |= byte2; - data <<= 8; - data |= byte1; - data <<= 8; - data |= byte0; - return data; -} -uint64_t -TagBuffer::ReadU64 (void) -{ - uint8_t byte0 = ReadU8 (); - uint8_t byte1 = ReadU8 (); - uint8_t byte2 = ReadU8 (); - uint8_t byte3 = ReadU8 (); - uint8_t byte4 = ReadU8 (); - uint8_t byte5 = ReadU8 (); - uint8_t byte6 = ReadU8 (); - uint8_t byte7 = ReadU8 (); - uint32_t data = byte7; - data <<= 8; - data |= byte6; - data <<= 8; - data |= byte5; - data <<= 8; - data |= byte4; - data <<= 8; - data |= byte3; - data <<= 8; - data |= byte2; - data <<= 8; - data |= byte1; - data <<= 8; - data |= byte0; - - return data; -} -double -TagBuffer::ReadDouble (void) -{ - double v; - uint8_t *buf = (uint8_t *)&v; - for (uint32_t i = 0; i < sizeof (double); ++i, ++buf) - { - *buf = ReadU8 (); - } - return v; -} -void -TagBuffer::Read (uint8_t *buffer, uint32_t size) -{ - for (uint32_t i = 0; i < size; ++i, ++buffer) - { - *buffer = ReadU8 (); - } -} -TagBuffer::TagBuffer (uint8_t *start, uint8_t *end) - : m_current (start), - m_end (end) -{} - -void -TagBuffer::TrimAtEnd (uint32_t trim) -{ - NS_ASSERT (m_current <= (m_end - trim)); - m_end -= trim; -} - -void -TagBuffer::CopyFrom (TagBuffer o) -{ - uint32_t size = o.m_end - o.m_current; - NS_ASSERT (size <= m_end - m_current); - memcpy (m_current, o.m_current, size); - m_current += size; -} - -} // namespace ns3 diff -r e11e106c7c19 -r a624276a897b src/common/mtag-buffer.h --- a/src/common/mtag-buffer.h Thu Apr 24 16:03:13 2008 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -#ifndef MTAG_BUFFER_H -#define MTAG_BUFFER_H - -#include - -namespace ns3 { - -class TagBuffer -{ -public: - TagBuffer (uint8_t *start, uint8_t *end); - void TrimAtEnd (uint32_t trim); - - void WriteU8 (uint8_t v); - void WriteU16 (uint16_t v); - void WriteU32 (uint32_t v); - void WriteU64 (uint64_t v); - void WriteDouble (double v); - void Write (const uint8_t *buffer, uint32_t size); - uint8_t ReadU8 (void); - uint16_t ReadU16 (void); - uint32_t ReadU32 (void); - uint64_t ReadU64 (void); - double ReadDouble (void); - void Read (uint8_t *buffer, uint32_t size); - - void CopyFrom (TagBuffer o); -private: - - uint8_t *m_current; - uint8_t *m_end; -}; - -} // namespace ns3 - -#endif /* MTAG_BUFFER_H */ diff -r e11e106c7c19 -r a624276a897b src/common/mtag-list.cc --- a/src/common/mtag-list.cc Thu Apr 24 16:03:13 2008 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,237 +0,0 @@ -#include "mtag-list.h" - -namespace ns3 { - -TagList::Iterator::Item::Item (TagBuffer buf_) - : buf (buf_) -{} - -bool -TagList::Iterator::HasNext (void) const -{ - return m_current < m_end; -} -struct TagList::Iterator::Item -TagList::Iterator::Next (void) -{ - NS_ASSERT (HasNext ()); - struct Item item = Item (TagBuffer (m_current, m_end)); - item.tid.SetUid (item.buf.ReadU32 ()); - item.size = item.buf.ReadU32 (); - item.start = item.buf.ReadU32 (); - item.end = item.buf.ReadU32 (); - item.start = std::max (item.start, m_offsetStart); - item.end = std::min (item.end, m_offsetEnd); - m_current += 4 + 4 + 4 + 4 + item.size; - item.buf.TrimAtEnd (m_end - m_current); - PrepareForNext (); - return item; -} -void -TagList::Iterator::PrepareForNext (void) -{ - while (m_current < m_end) - { - struct Item item = Item (TagBuffer (m_current, m_end)); - item.tid.SetUid (item.buf.ReadU32 ()); - item.size = item.buf.ReadU32 (); - item.start = item.buf.ReadU32 (); - item.end = item.buf.ReadU32 (); - if (item.start > m_offsetEnd || item.end < m_offsetStart) - { - m_current += 4 + 4 + 4 + 4 + item.size; - } - else - { - break; - } - } -} -TagList::Iterator::Iterator (uint8_t *start, uint8_t *end, uint32_t offsetStart, uint32_t offsetEnd) - : m_current (start), - m_end (end), - m_offsetStart (offsetStart), - m_offsetEnd (offsetEnd) -{ - PrepareForNext (); -} - -uint32_t -TagList::Iterator::GetOffsetStart (void) const -{ - return m_offsetStart; -} - - -TagList::TagList () - : m_buffer (0), - m_size (0) -{} -TagList::TagList (const TagList &o) - : m_size (o.m_size) -{ - m_buffer = new uint8_t [o.m_size] (); - memcpy (m_buffer, o.m_buffer, o.m_size); -} -TagList & -TagList::operator = (const TagList &o) -{ - delete [] m_buffer; - m_buffer = new uint8_t [o.m_size] (); - memcpy (m_buffer, o.m_buffer, m_size); - m_size = o.m_size; - return *this; -} -TagList::~TagList () -{ - delete [] m_buffer; - m_buffer = 0; - m_size = 0; -} - -TagBuffer -TagList::Add (TypeId tid, uint32_t bufferSize, uint32_t start, uint32_t end) -{ - uint32_t newSize = m_size + bufferSize + 4 + 4 + 4 + 4; - uint8_t *newBuffer = new uint8_t [newSize] (); - memcpy (newBuffer, m_buffer, m_size); - TagBuffer tag = TagBuffer (newBuffer + m_size, newBuffer + newSize); - tag.WriteU32 (tid.GetUid ()); - tag.WriteU32 (bufferSize); - tag.WriteU32 (start); - tag.WriteU32 (end); - delete [] m_buffer; - m_buffer = newBuffer; - m_size = newSize; - return tag; -} - -void -TagList::Add (const TagList &o) -{ - TagList::Iterator i = o.Begin (0, 0xffffffff); - while (i.HasNext ()) - { - TagList::Iterator::Item item = i.Next (); - TagBuffer buf = Add (item.tid, item.size, item.start, item.end); - buf.CopyFrom (item.buf); - } -} - -void -TagList::Remove (const Iterator &i) -{ - // XXX: more complex to implement. -} - -void -TagList::RemoveAll (void) -{ - delete [] m_buffer; - m_buffer = 0; - m_size = 0; -} - -TagList::Iterator -TagList::Begin (uint32_t offsetStart, uint32_t offsetEnd) const -{ - return Iterator (m_buffer, m_buffer + m_size, offsetStart, offsetEnd); -} - -bool -TagList::IsDirtyAtEnd (uint32_t appendOffset) -{ - TagList::Iterator i = Begin (0, 0xffffffff); - while (i.HasNext ()) - { - TagList::Iterator::Item item = i.Next (); - if (item.end > appendOffset) - { - return true; - } - } - return false; -} - -bool -TagList::IsDirtyAtStart (uint32_t prependOffset) -{ - TagList::Iterator i = Begin (0, 0xffffffff); - while (i.HasNext ()) - { - TagList::Iterator::Item item = i.Next (); - if (item.start < prependOffset) - { - return true; - } - } - return false; -} - -void -TagList::AddAtEnd (int32_t adjustment, uint32_t appendOffset) -{ - if (adjustment == 0 && !IsDirtyAtEnd (appendOffset)) - { - return; - } - TagList list; - TagList::Iterator i = Begin (0, 0xffffffff); - while (i.HasNext ()) - { - TagList::Iterator::Item item = i.Next (); - item.start += adjustment; - item.end += adjustment; - - if (item.start > appendOffset) - { - continue; - } - else if (item.start < appendOffset && item.end > appendOffset) - { - item.end = appendOffset; - } - else - { - // nothing to do. - } - TagBuffer buf = list.Add (item.tid, item.size, item.start, item.end); - buf.CopyFrom (item.buf); - } - *this = list; -} - -void -TagList::AddAtStart (int32_t adjustment, uint32_t prependOffset) -{ - if (adjustment == 0 && !IsDirtyAtStart (prependOffset)) - { - return; - } - TagList list; - TagList::Iterator i = Begin (0, 0xffffffff); - while (i.HasNext ()) - { - TagList::Iterator::Item item = i.Next (); - item.start += adjustment; - item.end += adjustment; - - if (item.end < prependOffset) - { - continue; - } - else if (item.end > prependOffset && item.start < prependOffset) - { - item.start = prependOffset; - } - else - { - // nothing to do. - } - TagBuffer buf = list.Add (item.tid, item.size, item.start, item.end); - buf.CopyFrom (item.buf); - } - *this = list; -} - -} // namespace ns3 diff -r e11e106c7c19 -r a624276a897b src/common/mtag-list.h --- a/src/common/mtag-list.h Thu Apr 24 16:03:13 2008 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ -#ifndef MTAG_LIST_H -#define MTAG_LIST_H - -#include -#include "ns3/type-id.h" -#include "mtag-buffer.h" - -namespace ns3 { - -class TagList -{ -public: - - class Iterator - { - public: - struct Item - { - TypeId tid; - uint32_t size; - uint32_t start; - uint32_t end; - TagBuffer buf; - private: - friend class TagList; - Item (TagBuffer buf); - }; - bool HasNext (void) const; - struct TagList::Iterator::Item Next (void); - uint32_t GetOffsetStart (void) const; - private: - friend class TagList; - Iterator (uint8_t *start, uint8_t *end, uint32_t offsetStart, uint32_t offsetEnd); - void PrepareForNext (void); - uint8_t *m_current; - uint8_t *m_end; - uint32_t m_offsetStart; - uint32_t m_offsetEnd; - }; - - TagList (); - TagList (const TagList &o); - TagList &operator = (const TagList &o); - ~TagList (); - - TagBuffer Add (TypeId tid, uint32_t bufferSize, uint32_t start, uint32_t end); - - void Add (const TagList &o); - - void Remove (const Iterator &i); - void RemoveAll (void); - - TagList::Iterator Begin (uint32_t offsetStart, uint32_t offsetEnd) const; - - void AddAtEnd (int32_t adjustment, uint32_t appendOffset); - void AddAtStart (int32_t adjustment, uint32_t prependOffset); - -private: - bool IsDirtyAtEnd (uint32_t appendOffset); - bool IsDirtyAtStart (uint32_t prependOffset); - uint8_t *m_buffer; - uint32_t m_size; -}; - -} // namespace ns3 - -#endif /* MTAG_LIST_H */ diff -r e11e106c7c19 -r a624276a897b src/common/mtag.cc --- a/src/common/mtag.cc Thu Apr 24 16:03:13 2008 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ -#include "mtag.h" - -namespace ns3 { - -TypeId -Tag::GetTypeId (void) -{ - static TypeId tid = TypeId ("ns3::Tag") - .SetParent () - ; - return tid; -} - - -} // namespace ns3 diff -r e11e106c7c19 -r a624276a897b src/common/mtag.h --- a/src/common/mtag.h Thu Apr 24 16:03:13 2008 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -#ifndef MTAG_H -#define MTAG_H - -#include "ns3/object-base.h" -#include "mtag-buffer.h" -#include - -namespace ns3 { - -class Tag : public ObjectBase -{ -public: - static TypeId GetTypeId (void); - - virtual uint32_t GetSerializedSize (void) const = 0; - virtual void Serialize (TagBuffer i) const = 0; - virtual void Deserialize (TagBuffer i) = 0; -}; - -} // namespace ns3 - -#endif /* MTAG_H */ diff -r e11e106c7c19 -r a624276a897b src/common/packet.h --- a/src/common/packet.h Thu Apr 24 16:03:13 2008 -0700 +++ b/src/common/packet.h Thu Apr 24 16:06:33 2008 -0700 @@ -25,8 +25,8 @@ #include "header.h" #include "trailer.h" #include "packet-metadata.h" -#include "mtag.h" -#include "mtag-list.h" +#include "tag.h" +#include "tag-list.h" #include "ns3/callback.h" #include "ns3/assert.h" #include "ns3/ptr.h" diff -r e11e106c7c19 -r a624276a897b src/common/tag-buffer.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/common/tag-buffer.cc Thu Apr 24 16:06:33 2008 -0700 @@ -0,0 +1,160 @@ +#include "tag-buffer.h" +#include "ns3/assert.h" + +namespace ns3 { + +void +TagBuffer::WriteU8 (uint8_t v) +{ + NS_ASSERT (m_current + 1 <= m_end); + *m_current = v; + m_current++; +} +void +TagBuffer::WriteU16 (uint16_t data) +{ + WriteU8 ((data >> 0) & 0xff); + WriteU8 ((data >> 8) & 0xff); +} +void +TagBuffer::WriteU32 (uint32_t data) +{ + WriteU8 ((data >> 0) & 0xff); + WriteU8 ((data >> 8) & 0xff); + WriteU8 ((data >> 16) & 0xff); + WriteU8 ((data >> 24) & 0xff); +} +void +TagBuffer::WriteU64 (uint64_t data) +{ + WriteU8 ((data >> 0) & 0xff); + WriteU8 ((data >> 8) & 0xff); + WriteU8 ((data >> 16) & 0xff); + WriteU8 ((data >> 24) & 0xff); + WriteU8 ((data >> 32) & 0xff); + WriteU8 ((data >> 40) & 0xff); + WriteU8 ((data >> 48) & 0xff); + WriteU8 ((data >> 54) & 0xff); +} +void +TagBuffer::WriteDouble (double v) +{ + uint8_t *buf = (uint8_t *)&v; + for (uint32_t i = 0; i < sizeof (double); ++i, ++buf) + { + WriteU8 (*buf); + } +} +void +TagBuffer::Write (const uint8_t *buffer, uint32_t size) +{ + for (uint32_t i = 0; i < size; ++i, ++buffer) + { + WriteU8 (*buffer); + } +} +uint8_t +TagBuffer::ReadU8 (void) +{ + NS_ASSERT (m_current + 1 <= m_end); + uint8_t v; + v = *m_current; + m_current++; + return v; +} +uint16_t +TagBuffer::ReadU16 (void) +{ + uint8_t byte0 = ReadU8 (); + uint8_t byte1 = ReadU8 (); + uint16_t data = byte1; + data <<= 8; + data |= byte0; + return data; +} +uint32_t +TagBuffer::ReadU32 (void) +{ + uint8_t byte0 = ReadU8 (); + uint8_t byte1 = ReadU8 (); + uint8_t byte2 = ReadU8 (); + uint8_t byte3 = ReadU8 (); + uint32_t data = byte3; + data <<= 8; + data |= byte2; + data <<= 8; + data |= byte1; + data <<= 8; + data |= byte0; + return data; +} +uint64_t +TagBuffer::ReadU64 (void) +{ + uint8_t byte0 = ReadU8 (); + uint8_t byte1 = ReadU8 (); + uint8_t byte2 = ReadU8 (); + uint8_t byte3 = ReadU8 (); + uint8_t byte4 = ReadU8 (); + uint8_t byte5 = ReadU8 (); + uint8_t byte6 = ReadU8 (); + uint8_t byte7 = ReadU8 (); + uint32_t data = byte7; + data <<= 8; + data |= byte6; + data <<= 8; + data |= byte5; + data <<= 8; + data |= byte4; + data <<= 8; + data |= byte3; + data <<= 8; + data |= byte2; + data <<= 8; + data |= byte1; + data <<= 8; + data |= byte0; + + return data; +} +double +TagBuffer::ReadDouble (void) +{ + double v; + uint8_t *buf = (uint8_t *)&v; + for (uint32_t i = 0; i < sizeof (double); ++i, ++buf) + { + *buf = ReadU8 (); + } + return v; +} +void +TagBuffer::Read (uint8_t *buffer, uint32_t size) +{ + for (uint32_t i = 0; i < size; ++i, ++buffer) + { + *buffer = ReadU8 (); + } +} +TagBuffer::TagBuffer (uint8_t *start, uint8_t *end) + : m_current (start), + m_end (end) +{} + +void +TagBuffer::TrimAtEnd (uint32_t trim) +{ + NS_ASSERT (m_current <= (m_end - trim)); + m_end -= trim; +} + +void +TagBuffer::CopyFrom (TagBuffer o) +{ + uint32_t size = o.m_end - o.m_current; + NS_ASSERT (size <= m_end - m_current); + memcpy (m_current, o.m_current, size); + m_current += size; +} + +} // namespace ns3 diff -r e11e106c7c19 -r a624276a897b src/common/tag-buffer.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/common/tag-buffer.h Thu Apr 24 16:06:33 2008 -0700 @@ -0,0 +1,36 @@ +#ifndef MTAG_BUFFER_H +#define MTAG_BUFFER_H + +#include + +namespace ns3 { + +class TagBuffer +{ +public: + TagBuffer (uint8_t *start, uint8_t *end); + void TrimAtEnd (uint32_t trim); + + void WriteU8 (uint8_t v); + void WriteU16 (uint16_t v); + void WriteU32 (uint32_t v); + void WriteU64 (uint64_t v); + void WriteDouble (double v); + void Write (const uint8_t *buffer, uint32_t size); + uint8_t ReadU8 (void); + uint16_t ReadU16 (void); + uint32_t ReadU32 (void); + uint64_t ReadU64 (void); + double ReadDouble (void); + void Read (uint8_t *buffer, uint32_t size); + + void CopyFrom (TagBuffer o); +private: + + uint8_t *m_current; + uint8_t *m_end; +}; + +} // namespace ns3 + +#endif /* MTAG_BUFFER_H */ diff -r e11e106c7c19 -r a624276a897b src/common/tag-list.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/common/tag-list.cc Thu Apr 24 16:06:33 2008 -0700 @@ -0,0 +1,237 @@ +#include "tag-list.h" + +namespace ns3 { + +TagList::Iterator::Item::Item (TagBuffer buf_) + : buf (buf_) +{} + +bool +TagList::Iterator::HasNext (void) const +{ + return m_current < m_end; +} +struct TagList::Iterator::Item +TagList::Iterator::Next (void) +{ + NS_ASSERT (HasNext ()); + struct Item item = Item (TagBuffer (m_current, m_end)); + item.tid.SetUid (item.buf.ReadU32 ()); + item.size = item.buf.ReadU32 (); + item.start = item.buf.ReadU32 (); + item.end = item.buf.ReadU32 (); + item.start = std::max (item.start, m_offsetStart); + item.end = std::min (item.end, m_offsetEnd); + m_current += 4 + 4 + 4 + 4 + item.size; + item.buf.TrimAtEnd (m_end - m_current); + PrepareForNext (); + return item; +} +void +TagList::Iterator::PrepareForNext (void) +{ + while (m_current < m_end) + { + struct Item item = Item (TagBuffer (m_current, m_end)); + item.tid.SetUid (item.buf.ReadU32 ()); + item.size = item.buf.ReadU32 (); + item.start = item.buf.ReadU32 (); + item.end = item.buf.ReadU32 (); + if (item.start > m_offsetEnd || item.end < m_offsetStart) + { + m_current += 4 + 4 + 4 + 4 + item.size; + } + else + { + break; + } + } +} +TagList::Iterator::Iterator (uint8_t *start, uint8_t *end, uint32_t offsetStart, uint32_t offsetEnd) + : m_current (start), + m_end (end), + m_offsetStart (offsetStart), + m_offsetEnd (offsetEnd) +{ + PrepareForNext (); +} + +uint32_t +TagList::Iterator::GetOffsetStart (void) const +{ + return m_offsetStart; +} + + +TagList::TagList () + : m_buffer (0), + m_size (0) +{} +TagList::TagList (const TagList &o) + : m_size (o.m_size) +{ + m_buffer = new uint8_t [o.m_size] (); + memcpy (m_buffer, o.m_buffer, o.m_size); +} +TagList & +TagList::operator = (const TagList &o) +{ + delete [] m_buffer; + m_buffer = new uint8_t [o.m_size] (); + memcpy (m_buffer, o.m_buffer, m_size); + m_size = o.m_size; + return *this; +} +TagList::~TagList () +{ + delete [] m_buffer; + m_buffer = 0; + m_size = 0; +} + +TagBuffer +TagList::Add (TypeId tid, uint32_t bufferSize, uint32_t start, uint32_t end) +{ + uint32_t newSize = m_size + bufferSize + 4 + 4 + 4 + 4; + uint8_t *newBuffer = new uint8_t [newSize] (); + memcpy (newBuffer, m_buffer, m_size); + TagBuffer tag = TagBuffer (newBuffer + m_size, newBuffer + newSize); + tag.WriteU32 (tid.GetUid ()); + tag.WriteU32 (bufferSize); + tag.WriteU32 (start); + tag.WriteU32 (end); + delete [] m_buffer; + m_buffer = newBuffer; + m_size = newSize; + return tag; +} + +void +TagList::Add (const TagList &o) +{ + TagList::Iterator i = o.Begin (0, 0xffffffff); + while (i.HasNext ()) + { + TagList::Iterator::Item item = i.Next (); + TagBuffer buf = Add (item.tid, item.size, item.start, item.end); + buf.CopyFrom (item.buf); + } +} + +void +TagList::Remove (const Iterator &i) +{ + // XXX: more complex to implement. +} + +void +TagList::RemoveAll (void) +{ + delete [] m_buffer; + m_buffer = 0; + m_size = 0; +} + +TagList::Iterator +TagList::Begin (uint32_t offsetStart, uint32_t offsetEnd) const +{ + return Iterator (m_buffer, m_buffer + m_size, offsetStart, offsetEnd); +} + +bool +TagList::IsDirtyAtEnd (uint32_t appendOffset) +{ + TagList::Iterator i = Begin (0, 0xffffffff); + while (i.HasNext ()) + { + TagList::Iterator::Item item = i.Next (); + if (item.end > appendOffset) + { + return true; + } + } + return false; +} + +bool +TagList::IsDirtyAtStart (uint32_t prependOffset) +{ + TagList::Iterator i = Begin (0, 0xffffffff); + while (i.HasNext ()) + { + TagList::Iterator::Item item = i.Next (); + if (item.start < prependOffset) + { + return true; + } + } + return false; +} + +void +TagList::AddAtEnd (int32_t adjustment, uint32_t appendOffset) +{ + if (adjustment == 0 && !IsDirtyAtEnd (appendOffset)) + { + return; + } + TagList list; + TagList::Iterator i = Begin (0, 0xffffffff); + while (i.HasNext ()) + { + TagList::Iterator::Item item = i.Next (); + item.start += adjustment; + item.end += adjustment; + + if (item.start > appendOffset) + { + continue; + } + else if (item.start < appendOffset && item.end > appendOffset) + { + item.end = appendOffset; + } + else + { + // nothing to do. + } + TagBuffer buf = list.Add (item.tid, item.size, item.start, item.end); + buf.CopyFrom (item.buf); + } + *this = list; +} + +void +TagList::AddAtStart (int32_t adjustment, uint32_t prependOffset) +{ + if (adjustment == 0 && !IsDirtyAtStart (prependOffset)) + { + return; + } + TagList list; + TagList::Iterator i = Begin (0, 0xffffffff); + while (i.HasNext ()) + { + TagList::Iterator::Item item = i.Next (); + item.start += adjustment; + item.end += adjustment; + + if (item.end < prependOffset) + { + continue; + } + else if (item.end > prependOffset && item.start < prependOffset) + { + item.start = prependOffset; + } + else + { + // nothing to do. + } + TagBuffer buf = list.Add (item.tid, item.size, item.start, item.end); + buf.CopyFrom (item.buf); + } + *this = list; +} + +} // namespace ns3 diff -r e11e106c7c19 -r a624276a897b src/common/tag-list.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/common/tag-list.h Thu Apr 24 16:06:33 2008 -0700 @@ -0,0 +1,67 @@ +#ifndef MTAG_LIST_H +#define MTAG_LIST_H + +#include +#include "ns3/type-id.h" +#include "tag-buffer.h" + +namespace ns3 { + +class TagList +{ +public: + + class Iterator + { + public: + struct Item + { + TypeId tid; + uint32_t size; + uint32_t start; + uint32_t end; + TagBuffer buf; + private: + friend class TagList; + Item (TagBuffer buf); + }; + bool HasNext (void) const; + struct TagList::Iterator::Item Next (void); + uint32_t GetOffsetStart (void) const; + private: + friend class TagList; + Iterator (uint8_t *start, uint8_t *end, uint32_t offsetStart, uint32_t offsetEnd); + void PrepareForNext (void); + uint8_t *m_current; + uint8_t *m_end; + uint32_t m_offsetStart; + uint32_t m_offsetEnd; + }; + + TagList (); + TagList (const TagList &o); + TagList &operator = (const TagList &o); + ~TagList (); + + TagBuffer Add (TypeId tid, uint32_t bufferSize, uint32_t start, uint32_t end); + + void Add (const TagList &o); + + void Remove (const Iterator &i); + void RemoveAll (void); + + TagList::Iterator Begin (uint32_t offsetStart, uint32_t offsetEnd) const; + + void AddAtEnd (int32_t adjustment, uint32_t appendOffset); + void AddAtStart (int32_t adjustment, uint32_t prependOffset); + +private: + bool IsDirtyAtEnd (uint32_t appendOffset); + bool IsDirtyAtStart (uint32_t prependOffset); + uint8_t *m_buffer; + uint32_t m_size; +}; + +} // namespace ns3 + +#endif /* MTAG_LIST_H */ diff -r e11e106c7c19 -r a624276a897b src/common/tag.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/common/tag.cc Thu Apr 24 16:06:33 2008 -0700 @@ -0,0 +1,15 @@ +#include "tag.h" + +namespace ns3 { + +TypeId +Tag::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::Tag") + .SetParent () + ; + return tid; +} + + +} // namespace ns3 diff -r e11e106c7c19 -r a624276a897b src/common/tag.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/common/tag.h Thu Apr 24 16:06:33 2008 -0700 @@ -0,0 +1,22 @@ +#ifndef MTAG_H +#define MTAG_H + +#include "ns3/object-base.h" +#include "tag-buffer.h" +#include + +namespace ns3 { + +class Tag : public ObjectBase +{ +public: + static TypeId GetTypeId (void); + + virtual uint32_t GetSerializedSize (void) const = 0; + virtual void Serialize (TagBuffer i) const = 0; + virtual void Deserialize (TagBuffer i) = 0; +}; + +} // namespace ns3 + +#endif /* MTAG_H */ diff -r e11e106c7c19 -r a624276a897b src/common/wscript --- a/src/common/wscript Thu Apr 24 16:03:13 2008 -0700 +++ b/src/common/wscript Thu Apr 24 16:06:33 2008 -0700 @@ -13,9 +13,9 @@ 'pcap-writer.cc', 'data-rate.cc', 'error-model.cc', - 'mtag.cc', - 'mtag-list.cc', - 'mtag-buffer.cc', + 'tag.cc', + 'tag-list.cc', + 'tag-buffer.cc', ] headers = bld.create_obj('ns3header') @@ -30,7 +30,7 @@ 'pcap-writer.h', 'data-rate.h', 'error-model.h', - 'mtag.h', - 'mtag-list.h', - 'mtag-buffer.h', + 'tag.h', + 'tag-list.h', + 'tag-buffer.h', ] diff -r e11e106c7c19 -r a624276a897b src/contrib/delay-jitter-estimation.cc --- a/src/contrib/delay-jitter-estimation.cc Thu Apr 24 16:03:13 2008 -0700 +++ b/src/contrib/delay-jitter-estimation.cc Thu Apr 24 16:06:33 2008 -0700 @@ -1,6 +1,6 @@ #include "delay-jitter-estimation.h" -#include "ns3/mtag.h" +#include "ns3/tag.h" #include "ns3/simulator.h" #include "ns3/string.h" diff -r e11e106c7c19 -r a624276a897b src/devices/wifi/mac-low.cc --- a/src/devices/wifi/mac-low.cc Thu Apr 24 16:03:13 2008 -0700 +++ b/src/devices/wifi/mac-low.cc Thu Apr 24 16:06:33 2008 -0700 @@ -21,7 +21,7 @@ #include "ns3/assert.h" #include "ns3/packet.h" #include "ns3/simulator.h" -#include "ns3/mtag.h" +#include "ns3/tag.h" #include "ns3/log.h" #include "ns3/node.h" diff -r e11e106c7c19 -r a624276a897b src/devices/wifi/wifi-remote-station-manager.cc --- a/src/devices/wifi/wifi-remote-station-manager.cc Thu Apr 24 16:03:13 2008 -0700 +++ b/src/devices/wifi/wifi-remote-station-manager.cc Thu Apr 24 16:06:33 2008 -0700 @@ -21,7 +21,7 @@ #include "wifi-remote-station-manager.h" #include "ns3/assert.h" #include "ns3/log.h" -#include "ns3/mtag.h" +#include "ns3/tag.h" #include "ns3/boolean.h" #include "ns3/uinteger.h" #include "ns3/wifi-phy.h"