--- a/CHANGES.html Fri Jun 05 09:46:08 2009 -0700
+++ b/CHANGES.html Mon Jun 08 09:19:00 2009 +0200
@@ -65,12 +65,31 @@
<p> class Ipv4 now contains attributes in ipv4.cc; the first one
is called "IpForward" that will enable/disable Ipv4 forwarding.
</li>
+
+<li> <b>packet tags</b>
+<p>class Packet now contains AddPacketTag, RemovePacketTag and PeekPacketTag
+which can be used to attach a tag to a packet, as opposed to the old
+AddTag method which attached a tag to a set of bytes. The main
+semantic difference is in how these tags behave in the presence of
+fragmentation and reassembly.
+</li>
+
</ul>
<h2>Changes to existing API:</h2>
<ul>
-<p><b>YansWifiPhyHelper::EnablePcap* methods not static any more</b>
+<li> <b>packet byte tags renaming</b>
+ <ul>
+ <li>Packet::AddTag to Packet::AddByteTag</li>
+ <li>Packet::FindFirstMatchingTag to Packet::FindFirstMatchingByteTag</li>
+ <li>Packet::RemoveAllTags to Packet::RemoveAllByteTags</li>
+ <li>Packet::PrintTags to Packet::PrintByteTags</li>
+ <li>Packet::GetTagIterator to Packet::GetByteTagIterator</li>
+ </ul>
+</li>
+
+<li><b>YansWifiPhyHelper::EnablePcap* methods not static any more</b>
<p>To accommodate the possibility of configuring the PCAP format used for wifi promiscuous mode traces, several methods of YansWifiPhyHelper had to be made non-static:
<pre>
- static void EnablePcap (std::string filename, uint32_t nodeid, uint32_t deviceid);
--- a/bindings/python/ns3_module_common.py Fri Jun 05 09:46:08 2009 -0700
+++ b/bindings/python/ns3_module_common.py Mon Jun 08 09:19:00 2009 +0200
@@ -9,6 +9,16 @@
module.add_class('Buffer')
## buffer.h: ns3::Buffer::Iterator [class]
module.add_class('Iterator', outer_class=root_module['ns3::Buffer'])
+ ## packet.h: ns3::ByteTagIterator [class]
+ module.add_class('ByteTagIterator')
+ ## packet.h: ns3::ByteTagIterator::Item [class]
+ module.add_class('Item', outer_class=root_module['ns3::ByteTagIterator'])
+ ## byte-tag-list.h: ns3::ByteTagList [class]
+ module.add_class('ByteTagList')
+ ## byte-tag-list.h: ns3::ByteTagList::Iterator [class]
+ module.add_class('Iterator', outer_class=root_module['ns3::ByteTagList'])
+ ## byte-tag-list.h: ns3::ByteTagList::Iterator::Item [struct]
+ module.add_class('Item', outer_class=root_module['ns3::ByteTagList::Iterator'])
## data-rate.h: ns3::DataRate [class]
module.add_class('DataRate')
## packet.h: ns3::Packet [class]
@@ -21,20 +31,18 @@
module.add_enum('', ['PAYLOAD', 'HEADER', 'TRAILER'], outer_class=root_module['ns3::PacketMetadata::Item'])
## packet-metadata.h: ns3::PacketMetadata::ItemIterator [class]
module.add_class('ItemIterator', outer_class=root_module['ns3::PacketMetadata'])
+ ## packet.h: ns3::PacketTagIterator [class]
+ module.add_class('PacketTagIterator')
+ ## packet.h: ns3::PacketTagIterator::Item [class]
+ module.add_class('Item', outer_class=root_module['ns3::PacketTagIterator'])
+ ## packet-tag-list.h: ns3::PacketTagList [class]
+ module.add_class('PacketTagList')
+ ## packet-tag-list.h: ns3::PacketTagList::TagData [struct]
+ module.add_class('TagData', outer_class=root_module['ns3::PacketTagList'])
## tag.h: ns3::Tag [class]
module.add_class('Tag', parent=root_module['ns3::ObjectBase'])
## tag-buffer.h: ns3::TagBuffer [class]
module.add_class('TagBuffer')
- ## packet.h: ns3::TagIterator [class]
- module.add_class('TagIterator')
- ## packet.h: ns3::TagIterator::Item [class]
- module.add_class('Item', outer_class=root_module['ns3::TagIterator'])
- ## tag-list.h: ns3::TagList [class]
- module.add_class('TagList')
- ## tag-list.h: ns3::TagList::Iterator [class]
- module.add_class('Iterator', outer_class=root_module['ns3::TagList'])
- ## tag-list.h: ns3::TagList::Iterator::Item [struct]
- module.add_class('Item', outer_class=root_module['ns3::TagList::Iterator'])
## chunk.h: ns3::Chunk [class]
module.add_class('Chunk', parent=root_module['ns3::ObjectBase'])
## data-rate.h: ns3::DataRateChecker [class]
@@ -107,18 +115,22 @@
def register_methods(root_module):
register_Ns3Buffer_methods(root_module, root_module['ns3::Buffer'])
register_Ns3BufferIterator_methods(root_module, root_module['ns3::Buffer::Iterator'])
+ register_Ns3ByteTagIterator_methods(root_module, root_module['ns3::ByteTagIterator'])
+ register_Ns3ByteTagIteratorItem_methods(root_module, root_module['ns3::ByteTagIterator::Item'])
+ register_Ns3ByteTagList_methods(root_module, root_module['ns3::ByteTagList'])
+ register_Ns3ByteTagListIterator_methods(root_module, root_module['ns3::ByteTagList::Iterator'])
+ register_Ns3ByteTagListIteratorItem_methods(root_module, root_module['ns3::ByteTagList::Iterator::Item'])
register_Ns3DataRate_methods(root_module, root_module['ns3::DataRate'])
register_Ns3Packet_methods(root_module, root_module['ns3::Packet'])
register_Ns3PacketMetadata_methods(root_module, root_module['ns3::PacketMetadata'])
register_Ns3PacketMetadataItem_methods(root_module, root_module['ns3::PacketMetadata::Item'])
register_Ns3PacketMetadataItemIterator_methods(root_module, root_module['ns3::PacketMetadata::ItemIterator'])
+ register_Ns3PacketTagIterator_methods(root_module, root_module['ns3::PacketTagIterator'])
+ register_Ns3PacketTagIteratorItem_methods(root_module, root_module['ns3::PacketTagIterator::Item'])
+ register_Ns3PacketTagList_methods(root_module, root_module['ns3::PacketTagList'])
+ register_Ns3PacketTagListTagData_methods(root_module, root_module['ns3::PacketTagList::TagData'])
register_Ns3Tag_methods(root_module, root_module['ns3::Tag'])
register_Ns3TagBuffer_methods(root_module, root_module['ns3::TagBuffer'])
- register_Ns3TagIterator_methods(root_module, root_module['ns3::TagIterator'])
- register_Ns3TagIteratorItem_methods(root_module, root_module['ns3::TagIterator::Item'])
- register_Ns3TagList_methods(root_module, root_module['ns3::TagList'])
- register_Ns3TagListIterator_methods(root_module, root_module['ns3::TagList::Iterator'])
- register_Ns3TagListIteratorItem_methods(root_module, root_module['ns3::TagList::Iterator::Item'])
register_Ns3Chunk_methods(root_module, root_module['ns3::Chunk'])
register_Ns3DataRateChecker_methods(root_module, root_module['ns3::DataRateChecker'])
register_Ns3DataRateValue_methods(root_module, root_module['ns3::DataRateValue'])
@@ -346,6 +358,113 @@
is_const=True)
return
+def register_Ns3ByteTagIterator_methods(root_module, cls):
+ ## packet.h: ns3::ByteTagIterator::ByteTagIterator(ns3::ByteTagIterator const & arg0) [copy constructor]
+ cls.add_constructor([param('ns3::ByteTagIterator const &', 'arg0')])
+ ## packet.h: bool ns3::ByteTagIterator::HasNext() const [member function]
+ cls.add_method('HasNext',
+ 'bool',
+ [],
+ is_const=True)
+ ## packet.h: ns3::ByteTagIterator::Item ns3::ByteTagIterator::Next() [member function]
+ cls.add_method('Next',
+ 'ns3::ByteTagIterator::Item',
+ [])
+ return
+
+def register_Ns3ByteTagIteratorItem_methods(root_module, cls):
+ ## packet.h: ns3::ByteTagIterator::Item::Item(ns3::ByteTagIterator::Item const & arg0) [copy constructor]
+ cls.add_constructor([param('ns3::ByteTagIterator::Item const &', 'arg0')])
+ ## packet.h: ns3::TypeId ns3::ByteTagIterator::Item::GetTypeId() const [member function]
+ cls.add_method('GetTypeId',
+ 'ns3::TypeId',
+ [],
+ is_const=True)
+ ## packet.h: uint32_t ns3::ByteTagIterator::Item::GetStart() const [member function]
+ cls.add_method('GetStart',
+ 'uint32_t',
+ [],
+ is_const=True)
+ ## packet.h: uint32_t ns3::ByteTagIterator::Item::GetEnd() const [member function]
+ cls.add_method('GetEnd',
+ 'uint32_t',
+ [],
+ is_const=True)
+ ## packet.h: void ns3::ByteTagIterator::Item::GetTag(ns3::Tag & tag) const [member function]
+ cls.add_method('GetTag',
+ 'void',
+ [param('ns3::Tag &', 'tag')],
+ is_const=True)
+ return
+
+def register_Ns3ByteTagList_methods(root_module, cls):
+ ## byte-tag-list.h: ns3::ByteTagList::ByteTagList() [constructor]
+ cls.add_constructor([])
+ ## byte-tag-list.h: ns3::ByteTagList::ByteTagList(ns3::ByteTagList const & o) [copy constructor]
+ cls.add_constructor([param('ns3::ByteTagList const &', 'o')])
+ ## byte-tag-list.h: ns3::TagBuffer ns3::ByteTagList::Add(ns3::TypeId tid, uint32_t bufferSize, int32_t start, int32_t end) [member function]
+ cls.add_method('Add',
+ 'ns3::TagBuffer',
+ [param('ns3::TypeId', 'tid'), param('uint32_t', 'bufferSize'), param('int32_t', 'start'), param('int32_t', 'end')])
+ ## byte-tag-list.h: void ns3::ByteTagList::Add(ns3::ByteTagList const & o) [member function]
+ cls.add_method('Add',
+ 'void',
+ [param('ns3::ByteTagList const &', 'o')])
+ ## byte-tag-list.h: void ns3::ByteTagList::RemoveAll() [member function]
+ cls.add_method('RemoveAll',
+ 'void',
+ [])
+ ## byte-tag-list.h: ns3::ByteTagList::Iterator ns3::ByteTagList::Begin(int32_t offsetStart, int32_t offsetEnd) const [member function]
+ cls.add_method('Begin',
+ 'ns3::ByteTagList::Iterator',
+ [param('int32_t', 'offsetStart'), param('int32_t', 'offsetEnd')],
+ is_const=True)
+ ## byte-tag-list.h: void ns3::ByteTagList::AddAtEnd(int32_t adjustment, int32_t appendOffset) [member function]
+ cls.add_method('AddAtEnd',
+ 'void',
+ [param('int32_t', 'adjustment'), param('int32_t', 'appendOffset')])
+ ## byte-tag-list.h: void ns3::ByteTagList::AddAtStart(int32_t adjustment, int32_t prependOffset) [member function]
+ cls.add_method('AddAtStart',
+ 'void',
+ [param('int32_t', 'adjustment'), param('int32_t', 'prependOffset')])
+ return
+
+def register_Ns3ByteTagListIterator_methods(root_module, cls):
+ ## byte-tag-list.h: ns3::ByteTagList::Iterator::Iterator(ns3::ByteTagList::Iterator const & arg0) [copy constructor]
+ cls.add_constructor([param('ns3::ByteTagList::Iterator const &', 'arg0')])
+ ## byte-tag-list.h: bool ns3::ByteTagList::Iterator::HasNext() const [member function]
+ cls.add_method('HasNext',
+ 'bool',
+ [],
+ is_const=True)
+ ## byte-tag-list.h: ns3::ByteTagList::Iterator::Item ns3::ByteTagList::Iterator::Next() [member function]
+ cls.add_method('Next',
+ 'ns3::ByteTagList::Iterator::Item',
+ [])
+ ## byte-tag-list.h: uint32_t ns3::ByteTagList::Iterator::GetOffsetStart() const [member function]
+ cls.add_method('GetOffsetStart',
+ 'uint32_t',
+ [],
+ is_const=True)
+ return
+
+def register_Ns3ByteTagListIteratorItem_methods(root_module, cls):
+ ## byte-tag-list.h: ns3::ByteTagList::Iterator::Item::tid [variable]
+ cls.add_instance_attribute('tid', 'ns3::TypeId', is_const=False)
+ ## byte-tag-list.h: ns3::ByteTagList::Iterator::Item::size [variable]
+ cls.add_instance_attribute('size', 'uint32_t', is_const=False)
+ ## byte-tag-list.h: ns3::ByteTagList::Iterator::Item::start [variable]
+ cls.add_instance_attribute('start', 'int32_t', is_const=False)
+ ## byte-tag-list.h: ns3::ByteTagList::Iterator::Item::end [variable]
+ cls.add_instance_attribute('end', 'int32_t', is_const=False)
+ ## byte-tag-list.h: ns3::ByteTagList::Iterator::Item::buf [variable]
+ cls.add_instance_attribute('buf', 'ns3::TagBuffer', is_const=False)
+ ## byte-tag-list.h: ns3::ByteTagList::Iterator::Item::Item(ns3::ByteTagList::Iterator::Item const & arg0) [copy constructor]
+ cls.add_constructor([param('ns3::ByteTagList::Iterator::Item const &', 'arg0')])
+ ## byte-tag-list.h: ns3::ByteTagList::Iterator::Item::Item(ns3::TagBuffer buf) [constructor]
+ cls.add_constructor([param('ns3::TagBuffer', 'buf')])
+ return
+
def register_Ns3DataRate_methods(root_module, cls):
cls.add_output_stream_operator()
cls.add_binary_comparison_operator('!=')
@@ -388,19 +507,24 @@
cls.add_method('AddAtEnd',
'void',
[param('ns3::Ptr< ns3::Packet const >', 'packet')])
+ ## packet.h: void ns3::Packet::AddByteTag(ns3::Tag const & tag) const [member function]
+ cls.add_method('AddByteTag',
+ 'void',
+ [param('ns3::Tag const &', 'tag')],
+ is_const=True)
## packet.h: void ns3::Packet::AddHeader(ns3::Header const & header) [member function]
cls.add_method('AddHeader',
'void',
[param('ns3::Header const &', 'header')])
+ ## packet.h: void ns3::Packet::AddPacketTag(ns3::Tag const & tag) const [member function]
+ cls.add_method('AddPacketTag',
+ 'void',
+ [param('ns3::Tag const &', 'tag')],
+ is_const=True)
## packet.h: void ns3::Packet::AddPaddingAtEnd(uint32_t size) [member function]
cls.add_method('AddPaddingAtEnd',
'void',
[param('uint32_t', 'size')])
- ## packet.h: void ns3::Packet::AddTag(ns3::Tag const & tag) const [member function]
- cls.add_method('AddTag',
- 'void',
- [param('ns3::Tag const &', 'tag')],
- is_const=True)
## packet.h: void ns3::Packet::AddTrailer(ns3::Trailer const & trailer) [member function]
cls.add_method('AddTrailer',
'void',
@@ -439,21 +563,26 @@
'void',
[],
is_static=True)
- ## packet.h: bool ns3::Packet::FindFirstMatchingTag(ns3::Tag & tag) const [member function]
- cls.add_method('FindFirstMatchingTag',
+ ## packet.h: bool ns3::Packet::FindFirstMatchingByteTag(ns3::Tag & tag) const [member function]
+ cls.add_method('FindFirstMatchingByteTag',
'bool',
[param('ns3::Tag &', 'tag')],
is_const=True)
+ ## packet.h: ns3::ByteTagIterator ns3::Packet::GetByteTagIterator() const [member function]
+ cls.add_method('GetByteTagIterator',
+ 'ns3::ByteTagIterator',
+ [],
+ is_const=True)
+ ## packet.h: ns3::PacketTagIterator ns3::Packet::GetPacketTagIterator() const [member function]
+ cls.add_method('GetPacketTagIterator',
+ 'ns3::PacketTagIterator',
+ [],
+ is_const=True)
## packet.h: uint32_t ns3::Packet::GetSize() const [member function]
cls.add_method('GetSize',
'uint32_t',
[],
is_const=True)
- ## packet.h: ns3::TagIterator ns3::Packet::GetTagIterator() const [member function]
- cls.add_method('GetTagIterator',
- 'ns3::TagIterator',
- [],
- is_const=True)
## packet.h: uint32_t ns3::Packet::GetUid() const [member function]
cls.add_method('GetUid',
'uint32_t',
@@ -469,6 +598,11 @@
'uint32_t',
[param('ns3::Header &', 'header')],
is_const=True)
+ ## packet.h: bool ns3::Packet::PeekPacketTag(ns3::Tag & tag) const [member function]
+ cls.add_method('PeekPacketTag',
+ 'bool',
+ [param('ns3::Tag &', 'tag')],
+ is_const=True)
## packet.h: uint32_t ns3::Packet::PeekTrailer(ns3::Trailer & trailer) [member function]
cls.add_method('PeekTrailer',
'uint32_t',
@@ -478,13 +612,22 @@
'void',
[param('std::ostream &', 'os')],
is_const=True)
- ## packet.h: void ns3::Packet::PrintTags(std::ostream & os) const [member function]
- cls.add_method('PrintTags',
+ ## packet.h: void ns3::Packet::PrintByteTags(std::ostream & os) const [member function]
+ cls.add_method('PrintByteTags',
'void',
[param('std::ostream &', 'os')],
is_const=True)
- ## packet.h: void ns3::Packet::RemoveAllTags() [member function]
- cls.add_method('RemoveAllTags',
+ ## packet.h: void ns3::Packet::PrintPacketTags(std::ostream & os) const [member function]
+ cls.add_method('PrintPacketTags',
+ 'void',
+ [param('std::ostream &', 'os')],
+ is_const=True)
+ ## packet.h: void ns3::Packet::RemoveAllByteTags() [member function]
+ cls.add_method('RemoveAllByteTags',
+ 'void',
+ [])
+ ## packet.h: void ns3::Packet::RemoveAllPacketTags() [member function]
+ cls.add_method('RemoveAllPacketTags',
'void',
[])
## packet.h: void ns3::Packet::RemoveAtEnd(uint32_t size) [member function]
@@ -499,6 +642,10 @@
cls.add_method('RemoveHeader',
'uint32_t',
[param('ns3::Header &', 'header')])
+ ## packet.h: bool ns3::Packet::RemovePacketTag(ns3::Tag & tag) [member function]
+ cls.add_method('RemovePacketTag',
+ 'bool',
+ [param('ns3::Tag &', 'tag')])
## packet.h: uint32_t ns3::Packet::RemoveTrailer(ns3::Trailer & trailer) [member function]
cls.add_method('RemoveTrailer',
'uint32_t',
@@ -623,6 +770,80 @@
[])
return
+def register_Ns3PacketTagIterator_methods(root_module, cls):
+ ## packet.h: ns3::PacketTagIterator::PacketTagIterator(ns3::PacketTagIterator const & arg0) [copy constructor]
+ cls.add_constructor([param('ns3::PacketTagIterator const &', 'arg0')])
+ ## packet.h: bool ns3::PacketTagIterator::HasNext() const [member function]
+ cls.add_method('HasNext',
+ 'bool',
+ [],
+ is_const=True)
+ ## packet.h: ns3::PacketTagIterator::Item ns3::PacketTagIterator::Next() [member function]
+ cls.add_method('Next',
+ 'ns3::PacketTagIterator::Item',
+ [])
+ return
+
+def register_Ns3PacketTagIteratorItem_methods(root_module, cls):
+ ## packet.h: ns3::PacketTagIterator::Item::Item(ns3::PacketTagIterator::Item const & arg0) [copy constructor]
+ cls.add_constructor([param('ns3::PacketTagIterator::Item const &', 'arg0')])
+ ## packet.h: ns3::TypeId ns3::PacketTagIterator::Item::GetTypeId() const [member function]
+ cls.add_method('GetTypeId',
+ 'ns3::TypeId',
+ [],
+ is_const=True)
+ ## packet.h: void ns3::PacketTagIterator::Item::GetTag(ns3::Tag & tag) const [member function]
+ cls.add_method('GetTag',
+ 'void',
+ [param('ns3::Tag &', 'tag')],
+ is_const=True)
+ return
+
+def register_Ns3PacketTagList_methods(root_module, cls):
+ ## packet-tag-list.h: ns3::PacketTagList::PacketTagList() [constructor]
+ cls.add_constructor([])
+ ## packet-tag-list.h: ns3::PacketTagList::PacketTagList(ns3::PacketTagList const & o) [copy constructor]
+ cls.add_constructor([param('ns3::PacketTagList const &', 'o')])
+ ## packet-tag-list.h: void ns3::PacketTagList::Add(ns3::Tag const & tag) const [member function]
+ cls.add_method('Add',
+ 'void',
+ [param('ns3::Tag const &', 'tag')],
+ is_const=True)
+ ## packet-tag-list.h: bool ns3::PacketTagList::Remove(ns3::Tag & tag) [member function]
+ cls.add_method('Remove',
+ 'bool',
+ [param('ns3::Tag &', 'tag')])
+ ## packet-tag-list.h: bool ns3::PacketTagList::Peek(ns3::Tag & tag) const [member function]
+ cls.add_method('Peek',
+ 'bool',
+ [param('ns3::Tag &', 'tag')],
+ is_const=True)
+ ## packet-tag-list.h: void ns3::PacketTagList::RemoveAll() [member function]
+ cls.add_method('RemoveAll',
+ 'void',
+ [])
+ ## packet-tag-list.h: ns3::PacketTagList::TagData const * ns3::PacketTagList::Head() const [member function]
+ cls.add_method('Head',
+ 'ns3::PacketTagList::TagData const *',
+ [],
+ is_const=True)
+ return
+
+def register_Ns3PacketTagListTagData_methods(root_module, cls):
+ ## packet-tag-list.h: ns3::PacketTagList::TagData::data [variable]
+ cls.add_instance_attribute('data', 'uint8_t [ 20 ]', is_const=False)
+ ## packet-tag-list.h: ns3::PacketTagList::TagData::next [variable]
+ cls.add_instance_attribute('next', 'ns3::PacketTagList::TagData *', is_const=False)
+ ## packet-tag-list.h: ns3::PacketTagList::TagData::tid [variable]
+ cls.add_instance_attribute('tid', 'ns3::TypeId', is_const=False)
+ ## packet-tag-list.h: ns3::PacketTagList::TagData::count [variable]
+ cls.add_instance_attribute('count', 'uint32_t', is_const=False)
+ ## packet-tag-list.h: ns3::PacketTagList::TagData::TagData(ns3::PacketTagList::TagData const & arg0) [copy constructor]
+ cls.add_constructor([param('ns3::PacketTagList::TagData const &', 'arg0')])
+ ## packet-tag-list.h: ns3::PacketTagList::TagData::TagData() [constructor]
+ cls.add_constructor([])
+ return
+
def register_Ns3Tag_methods(root_module, cls):
## tag.h: ns3::Tag::Tag(ns3::Tag const & arg0) [copy constructor]
cls.add_constructor([param('ns3::Tag const &', 'arg0')])
@@ -718,113 +939,6 @@
[param('uint8_t *', 'buffer'), param('uint32_t', 'size')])
return
-def register_Ns3TagIterator_methods(root_module, cls):
- ## packet.h: ns3::TagIterator::TagIterator(ns3::TagIterator const & arg0) [copy constructor]
- cls.add_constructor([param('ns3::TagIterator const &', 'arg0')])
- ## packet.h: bool ns3::TagIterator::HasNext() const [member function]
- cls.add_method('HasNext',
- 'bool',
- [],
- is_const=True)
- ## packet.h: ns3::TagIterator::Item ns3::TagIterator::Next() [member function]
- cls.add_method('Next',
- 'ns3::TagIterator::Item',
- [])
- return
-
-def register_Ns3TagIteratorItem_methods(root_module, cls):
- ## packet.h: ns3::TagIterator::Item::Item(ns3::TagIterator::Item const & arg0) [copy constructor]
- cls.add_constructor([param('ns3::TagIterator::Item const &', 'arg0')])
- ## packet.h: ns3::TypeId ns3::TagIterator::Item::GetTypeId() const [member function]
- cls.add_method('GetTypeId',
- 'ns3::TypeId',
- [],
- is_const=True)
- ## packet.h: uint32_t ns3::TagIterator::Item::GetStart() const [member function]
- cls.add_method('GetStart',
- 'uint32_t',
- [],
- is_const=True)
- ## packet.h: uint32_t ns3::TagIterator::Item::GetEnd() const [member function]
- cls.add_method('GetEnd',
- 'uint32_t',
- [],
- is_const=True)
- ## packet.h: void ns3::TagIterator::Item::GetTag(ns3::Tag & tag) const [member function]
- cls.add_method('GetTag',
- 'void',
- [param('ns3::Tag &', 'tag')],
- is_const=True)
- return
-
-def register_Ns3TagList_methods(root_module, cls):
- ## tag-list.h: ns3::TagList::TagList() [constructor]
- cls.add_constructor([])
- ## tag-list.h: ns3::TagList::TagList(ns3::TagList const & o) [copy constructor]
- cls.add_constructor([param('ns3::TagList const &', 'o')])
- ## tag-list.h: ns3::TagBuffer ns3::TagList::Add(ns3::TypeId tid, uint32_t bufferSize, int32_t start, int32_t end) [member function]
- cls.add_method('Add',
- 'ns3::TagBuffer',
- [param('ns3::TypeId', 'tid'), param('uint32_t', 'bufferSize'), param('int32_t', 'start'), param('int32_t', 'end')])
- ## tag-list.h: void ns3::TagList::Add(ns3::TagList const & o) [member function]
- cls.add_method('Add',
- 'void',
- [param('ns3::TagList const &', 'o')])
- ## tag-list.h: void ns3::TagList::RemoveAll() [member function]
- cls.add_method('RemoveAll',
- 'void',
- [])
- ## tag-list.h: ns3::TagList::Iterator ns3::TagList::Begin(int32_t offsetStart, int32_t offsetEnd) const [member function]
- cls.add_method('Begin',
- 'ns3::TagList::Iterator',
- [param('int32_t', 'offsetStart'), param('int32_t', 'offsetEnd')],
- is_const=True)
- ## tag-list.h: void ns3::TagList::AddAtEnd(int32_t adjustment, int32_t appendOffset) [member function]
- cls.add_method('AddAtEnd',
- 'void',
- [param('int32_t', 'adjustment'), param('int32_t', 'appendOffset')])
- ## tag-list.h: void ns3::TagList::AddAtStart(int32_t adjustment, int32_t prependOffset) [member function]
- cls.add_method('AddAtStart',
- 'void',
- [param('int32_t', 'adjustment'), param('int32_t', 'prependOffset')])
- return
-
-def register_Ns3TagListIterator_methods(root_module, cls):
- ## tag-list.h: ns3::TagList::Iterator::Iterator(ns3::TagList::Iterator const & arg0) [copy constructor]
- cls.add_constructor([param('ns3::TagList::Iterator const &', 'arg0')])
- ## tag-list.h: bool ns3::TagList::Iterator::HasNext() const [member function]
- cls.add_method('HasNext',
- 'bool',
- [],
- is_const=True)
- ## tag-list.h: ns3::TagList::Iterator::Item ns3::TagList::Iterator::Next() [member function]
- cls.add_method('Next',
- 'ns3::TagList::Iterator::Item',
- [])
- ## tag-list.h: uint32_t ns3::TagList::Iterator::GetOffsetStart() const [member function]
- cls.add_method('GetOffsetStart',
- 'uint32_t',
- [],
- is_const=True)
- return
-
-def register_Ns3TagListIteratorItem_methods(root_module, cls):
- ## tag-list.h: ns3::TagList::Iterator::Item::tid [variable]
- cls.add_instance_attribute('tid', 'ns3::TypeId', is_const=False)
- ## tag-list.h: ns3::TagList::Iterator::Item::size [variable]
- cls.add_instance_attribute('size', 'uint32_t', is_const=False)
- ## tag-list.h: ns3::TagList::Iterator::Item::start [variable]
- cls.add_instance_attribute('start', 'int32_t', is_const=False)
- ## tag-list.h: ns3::TagList::Iterator::Item::end [variable]
- cls.add_instance_attribute('end', 'int32_t', is_const=False)
- ## tag-list.h: ns3::TagList::Iterator::Item::buf [variable]
- cls.add_instance_attribute('buf', 'ns3::TagBuffer', is_const=False)
- ## tag-list.h: ns3::TagList::Iterator::Item::Item(ns3::TagList::Iterator::Item const & arg0) [copy constructor]
- cls.add_constructor([param('ns3::TagList::Iterator::Item const &', 'arg0')])
- ## tag-list.h: ns3::TagList::Iterator::Item::Item(ns3::TagBuffer buf) [constructor]
- cls.add_constructor([param('ns3::TagBuffer', 'buf')])
- return
-
def register_Ns3Chunk_methods(root_module, cls):
## chunk.h: ns3::Chunk::Chunk(ns3::Chunk const & arg0) [copy constructor]
cls.add_constructor([param('ns3::Chunk const &', 'arg0')])
--- a/examples/stats/wifi-example-apps.cc Fri Jun 05 09:46:08 2009 -0700
+++ b/examples/stats/wifi-example-apps.cc Mon Jun 08 09:19:00 2009 +0200
@@ -131,7 +131,7 @@
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 @@
}
TimestampTag timestamp;
- packet->FindFirstMatchingTag(timestamp);
+ packet->FindFirstMatchingByteTag(timestamp);
Time tx = timestamp.GetTimestamp();
if (m_delay != 0) {
--- a/samples/main-packet-tag.cc Fri Jun 05 09:46:08 2009 -0700
+++ b/samples/main-packet-tag.cc Mon Jun 08 09:19:00 2009 +0200
@@ -101,19 +101,19 @@
// store the tag in a packet.
Ptr<Packet> p = Create<Packet> (100);
- p->AddTag (tag);
+ p->AddPacketTag (tag);
// create a copy of the packet
Ptr<Packet> aCopy = p->Copy ();
// read the tag from the packet copy
MyTag tagCopy;
- p->FindFirstMatchingTag (tagCopy);
+ p->PeekPacketTag (tagCopy);
// the copy and the original are the same !
NS_ASSERT (tagCopy.GetSimpleValue () == tag.GetSimpleValue ());
- aCopy->PrintTags (std::cout);
+ aCopy->PrintPacketTags (std::cout);
std::cout << std::endl;
return 0;
--- a/src/applications/udp-echo/udp-echo-server.cc Fri Jun 05 09:46:08 2009 -0700
+++ b/src/applications/udp-echo/udp-echo-server.cc Mon Jun 08 09:19:00 2009 +0200
@@ -121,7 +121,8 @@
NS_LOG_INFO ("Received " << packet->GetSize() << " bytes from " <<
address.GetIpv4());
- packet->RemoveAllTags ();
+ packet->RemoveAllPacketTags ();
+ packet->RemoteAllByteTags ();
NS_LOG_LOGIC ("Echoing packet");
socket->SendTo (packet, 0, from);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/common/byte-tag-list.cc Mon Jun 08 09:19:00 2009 +0200
@@ -0,0 +1,421 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2008 INRIA
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+#include "byte-tag-list.h"
+#include "ns3/log.h"
+#include <vector>
+#include <string.h>
+
+NS_LOG_COMPONENT_DEFINE ("ByteTagList");
+
+#define USE_FREE_LIST 1
+#define FREE_LIST_SIZE 1000
+#define OFFSET_MAX (2147483647)
+
+namespace ns3 {
+
+struct ByteTagListData {
+ uint32_t size;
+ uint32_t count;
+ uint32_t dirty;
+ uint8_t data[4];
+};
+
+#ifdef USE_FREE_LIST
+static class ByteTagListDataFreeList : public std::vector<struct ByteTagListData *>
+{
+public:
+ ~ByteTagListDataFreeList ();
+} g_freeList;
+static uint32_t g_maxSize = 0;
+
+ByteTagListDataFreeList::~ByteTagListDataFreeList ()
+{
+ for (ByteTagListDataFreeList::iterator i = begin ();
+ i != end (); i++)
+ {
+ uint8_t *buffer = (uint8_t *)(*i);
+ delete [] buffer;
+ }
+}
+#endif /* USE_FREE_LIST */
+
+ByteTagList::Iterator::Item::Item (TagBuffer buf_)
+ : buf (buf_)
+{}
+
+bool
+ByteTagList::Iterator::HasNext (void) const
+{
+ return m_current < m_end;
+}
+struct ByteTagList::Iterator::Item
+ByteTagList::Iterator::Next (void)
+{
+ NS_ASSERT (HasNext ());
+ struct Item item = Item (TagBuffer (m_current+16, m_end));
+ item.tid.SetUid (m_nextTid);
+ item.size = m_nextSize;
+ item.start = std::max (m_nextStart, m_offsetStart);
+ item.end = std::min (m_nextEnd, m_offsetEnd);
+ m_current += 4 + 4 + 4 + 4 + item.size;
+ item.buf.TrimAtEnd (m_end - m_current);
+ PrepareForNext ();
+ return item;
+}
+void
+ByteTagList::Iterator::PrepareForNext (void)
+{
+ while (m_current < m_end)
+ {
+ TagBuffer buf = TagBuffer (m_current, m_end);
+ m_nextTid = buf.ReadU32 ();
+ m_nextSize = buf.ReadU32 ();
+ m_nextStart = buf.ReadU32 ();
+ m_nextEnd = buf.ReadU32 ();
+ if (m_nextStart >= m_offsetEnd || m_nextEnd <= m_offsetStart)
+ {
+ m_current += 4 + 4 + 4 + 4 + m_nextSize;
+ }
+ else
+ {
+ break;
+ }
+ }
+}
+ByteTagList::Iterator::Iterator (uint8_t *start, uint8_t *end, int32_t offsetStart, int32_t offsetEnd)
+ : m_current (start),
+ m_end (end),
+ m_offsetStart (offsetStart),
+ m_offsetEnd (offsetEnd)
+{
+ PrepareForNext ();
+}
+
+uint32_t
+ByteTagList::Iterator::GetOffsetStart (void) const
+{
+ return m_offsetStart;
+}
+
+
+ByteTagList::ByteTagList ()
+ : m_used (0),
+ m_data (0)
+{
+ NS_LOG_FUNCTION (this);
+}
+ByteTagList::ByteTagList (const ByteTagList &o)
+ : m_used (o.m_used),
+ m_data (o.m_data)
+{
+ NS_LOG_FUNCTION (this << &o);
+ if (m_data != 0)
+ {
+ m_data->count++;
+ }
+}
+ByteTagList &
+ByteTagList::operator = (const ByteTagList &o)
+{
+ NS_LOG_FUNCTION (this << &o);
+ if (this == &o)
+ {
+ return *this;
+ }
+
+ Deallocate (m_data);
+ m_data = o.m_data;
+ m_used = o.m_used;
+ if (m_data != 0)
+ {
+ m_data->count++;
+ }
+ return *this;
+}
+ByteTagList::~ByteTagList ()
+{
+ NS_LOG_FUNCTION (this);
+ Deallocate (m_data);
+ m_data = 0;
+ m_used = 0;
+}
+
+TagBuffer
+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;
+ NS_ASSERT (m_used <= spaceNeeded);
+ if (m_data == 0)
+ {
+ m_data = Allocate (spaceNeeded);
+ m_used = 0;
+ }
+ else if (m_data->size < spaceNeeded ||
+ (m_data->count != 1 && m_data->dirty != m_used))
+ {
+ struct ByteTagListData *newData = Allocate (spaceNeeded);
+ memcpy (&newData->data, &m_data->data, m_used);
+ Deallocate (m_data);
+ m_data = newData;
+ }
+ TagBuffer tag = TagBuffer (&m_data->data[m_used],
+ &m_data->data[spaceNeeded]);
+ tag.WriteU32 (tid.GetUid ());
+ tag.WriteU32 (bufferSize);
+ tag.WriteU32 (start);
+ tag.WriteU32 (end);
+ m_used = spaceNeeded;
+ m_data->dirty = m_used;
+ return tag;
+}
+
+void
+ByteTagList::Add (const ByteTagList &o)
+{
+ NS_LOG_FUNCTION (this << &o);
+ ByteTagList::Iterator i = o.BeginAll ();
+ while (i.HasNext ())
+ {
+ ByteTagList::Iterator::Item item = i.Next ();
+ TagBuffer buf = Add (item.tid, item.size, item.start, item.end);
+ buf.CopyFrom (item.buf);
+ }
+}
+
+void
+ByteTagList::RemoveAll (void)
+{
+ NS_LOG_FUNCTION (this);
+ Deallocate (m_data);
+ m_data = 0;
+ m_used = 0;
+}
+
+ByteTagList::Iterator
+ByteTagList::BeginAll (void) const
+{
+ NS_LOG_FUNCTION (this);
+ // I am not totally sure but I might need to use
+ // INT32_MIN instead of zero below.
+ return Begin (0, OFFSET_MAX);
+}
+
+ByteTagList::Iterator
+ByteTagList::Begin (int32_t offsetStart, int32_t offsetEnd) const
+{
+ NS_LOG_FUNCTION (this << offsetStart << offsetEnd);
+ if (m_data == 0)
+ {
+ return Iterator (0, 0, offsetStart, offsetEnd);
+ }
+ else
+ {
+ return Iterator (m_data->data, &m_data->data[m_used], offsetStart, offsetEnd);
+ }
+}
+
+bool
+ByteTagList::IsDirtyAtEnd (int32_t appendOffset)
+{
+ NS_LOG_FUNCTION (this << appendOffset);
+ ByteTagList::Iterator i = BeginAll ();
+ while (i.HasNext ())
+ {
+ ByteTagList::Iterator::Item item = i.Next ();
+ if (item.end > appendOffset)
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+bool
+ByteTagList::IsDirtyAtStart (int32_t prependOffset)
+{
+ NS_LOG_FUNCTION (this << prependOffset);
+ ByteTagList::Iterator i = BeginAll ();
+ while (i.HasNext ())
+ {
+ ByteTagList::Iterator::Item item = i.Next ();
+ if (item.start < prependOffset)
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+void
+ByteTagList::AddAtEnd (int32_t adjustment, int32_t appendOffset)
+{
+ NS_LOG_FUNCTION (this << adjustment << appendOffset);
+ if (adjustment == 0 && !IsDirtyAtEnd (appendOffset))
+ {
+ return;
+ }
+ ByteTagList list;
+ ByteTagList::Iterator i = BeginAll ();
+ while (i.HasNext ())
+ {
+ ByteTagList::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
+ByteTagList::AddAtStart (int32_t adjustment, int32_t prependOffset)
+{
+ NS_LOG_FUNCTION (this << adjustment << prependOffset);
+ if (adjustment == 0 && !IsDirtyAtStart (prependOffset))
+ {
+ return;
+ }
+ ByteTagList list;
+ ByteTagList::Iterator i = BeginAll ();
+ while (i.HasNext ())
+ {
+ ByteTagList::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;
+}
+
+#ifdef USE_FREE_LIST
+
+struct ByteTagListData *
+ByteTagList::Allocate (uint32_t size)
+{
+ NS_LOG_FUNCTION (this << size);
+ while (!g_freeList.empty ())
+ {
+ struct ByteTagListData *data = g_freeList.back ();
+ g_freeList.pop_back ();
+ NS_ASSERT (data != 0);
+ if (data->size >= size)
+ {
+ data->count = 1;
+ data->dirty = 0;
+ return data;
+ }
+ uint8_t *buffer = (uint8_t *)data;
+ delete [] 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;
+ return data;
+}
+
+void
+ByteTagList::Deallocate (struct ByteTagListData *data)
+{
+ NS_LOG_FUNCTION (this << data);
+ if (data == 0)
+ {
+ return;
+ }
+ g_maxSize = std::max (g_maxSize, data->size);
+ data->count--;
+ if (data->count == 0)
+ {
+ if (g_freeList.size () > FREE_LIST_SIZE ||
+ data->size < g_maxSize)
+ {
+ uint8_t *buffer = (uint8_t *)data;
+ delete [] buffer;
+ }
+ else
+ {
+ g_freeList.push_back (data);
+ }
+ }
+}
+
+#else /* USE_FREE_LIST */
+
+struct ByteTagListData *
+ByteTagList::Allocate (uint32_t size)
+{
+ NS_LOG_FUNCTION (this << size);
+ 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;
+ return data;
+}
+
+void
+ByteTagList::Deallocate (struct ByteTagListData *data)
+{
+ NS_LOG_FUNCTION (this << data);
+ if (data == 0)
+ {
+ return;
+ }
+ data->count--;
+ if (data->count == 0)
+ {
+ uint8_t *buffer = (uint8_t *)data;
+ delete [] buffer;
+ }
+}
+
+#endif /* USE_FREE_LIST */
+
+
+} // namespace ns3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/common/byte-tag-list.h Mon Jun 08 09:19:00 2009 +0200
@@ -0,0 +1,170 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2008 INRIA
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+#ifndef BYTE_TAG_LIST_H
+#define BYTE_TAG_LIST_H
+
+#include <stdint.h>
+#include "ns3/type-id.h"
+#include "tag-buffer.h"
+
+namespace ns3 {
+
+struct ByteTagListData;
+
+/**
+ * \ingroup packet
+ *
+ * \brief keep track of the tags stored in a packet.
+ *
+ * This class is mostly private to the Packet implementation and users
+ * should never have to access it directly.
+ *
+ * \internal
+ * The implementation of this class is a bit tricky so, there are a couple
+ * of things to keep in mind here:
+ *
+ * - it stores all tags in a single byte buffer: each tag is stored
+ * as 4 32bit integers (TypeId, tag data size, start, end) followed
+ * by the tag data as generated by Tag::Serialize.
+ *
+ * - 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.
+ *
+ * - each tag tags a unique set of bytes identified by the pair of offsets
+ * (start,end). These offsets are provided by Buffer::GetCurrentStartOffset
+ * 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 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 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 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 ByteTagList
+{
+public:
+
+ class Iterator
+ {
+ public:
+ struct Item
+ {
+ TypeId tid;
+ uint32_t size;
+ int32_t start;
+ int32_t end;
+ TagBuffer buf;
+ Item (TagBuffer buf);
+ private:
+ friend class ByteTagList;
+ friend class ByteTagList::Iterator;
+ };
+ bool HasNext (void) const;
+ struct ByteTagList::Iterator::Item Next (void);
+ uint32_t GetOffsetStart (void) const;
+ private:
+ friend class ByteTagList;
+ Iterator (uint8_t *start, uint8_t *end, int32_t offsetStart, int32_t offsetEnd);
+ void PrepareForNext (void);
+ uint8_t *m_current;
+ uint8_t *m_end;
+ int32_t m_offsetStart;
+ int32_t m_offsetEnd;
+ uint32_t m_nextTid;
+ uint32_t m_nextSize;
+ int32_t m_nextStart;
+ int32_t m_nextEnd;
+ };
+
+ ByteTagList ();
+ ByteTagList (const ByteTagList &o);
+ ByteTagList &operator = (const ByteTagList &o);
+ ~ByteTagList ();
+
+ /**
+ * \param tid the typeid of the tag added
+ * \param bufferSize the size of the tag when its serialization will
+ * be completed. Typically, the return value of Tag::GetSerializedSize
+ * \param start offset which uniquely identifies the first byte tagged by this tag.
+ * \param end offset which uniquely identifies the last byte tagged by this tag.
+ * \returns a buffer which can be used to write the tag data.
+ *
+ *
+ */
+ TagBuffer Add (TypeId tid, uint32_t bufferSize, int32_t start, int32_t end);
+
+ /**
+ * \param o the other list of tags to aggregate.
+ *
+ * Aggregate the two lists of tags.
+ */
+ 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 ByteTagList.
+ * \param offsetEnd the offset which uniquely identifies the last data byte
+ * 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.
+ */
+ ByteTagList::Iterator Begin (int32_t offsetStart, int32_t offsetEnd) const;
+
+ /**
+ * Adjust the offsets stored internally by the adjustment delta and
+ * make sure that all offsets are smaller than appendOffset which represents
+ * the location where new bytes have been added to the byte buffer.
+ */
+ void AddAtEnd (int32_t adjustment, int32_t appendOffset);
+ /**
+ * Adjust the offsets stored internally by the adjustment delta and
+ * make sure that all offsets are bigger than prependOffset which represents
+ * the location where new bytes have been added to the byte buffer.
+ */
+ void AddAtStart (int32_t adjustment, int32_t prependOffset);
+
+private:
+ bool IsDirtyAtEnd (int32_t appendOffset);
+ bool IsDirtyAtStart (int32_t prependOffset);
+ ByteTagList::Iterator BeginAll (void) const;
+
+ struct ByteTagListData *Allocate (uint32_t size);
+ void Deallocate (struct ByteTagListData *data);
+
+ uint16_t m_used;
+ struct ByteTagListData *m_data;
+};
+
+} // namespace ns3
+
+#endif /* BYTE_TAG_LIST_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/common/packet-tag-list.cc Mon Jun 08 09:19:00 2009 +0200
@@ -0,0 +1,177 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2006 INRIA
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+#include "packet-tag-list.h"
+#include "tag-buffer.h"
+#include "tag.h"
+#include "ns3/fatal-error.h"
+#include "ns3/log.h"
+#include <string.h>
+
+NS_LOG_COMPONENT_DEFINE ("PacketTagList");
+
+namespace ns3 {
+
+#ifdef USE_FREE_LIST
+
+struct PacketTagList::TagData *PacketTagList::g_free = 0;
+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)
+ {
+ retval = g_free;
+ g_free = g_free->m_next;
+ g_nfree--;
+ }
+ else
+ {
+ retval = new struct PacketTagList::TagData ();
+ }
+ return retval;
+}
+
+void
+PacketTagList::FreeData (struct TagData *data) const
+{
+ NS_LOG_FUNCTION (g_nfree << data);
+ if (g_nfree > 1000)
+ {
+ delete data;
+ return;
+ }
+ g_nfree++;
+ data->next = g_free;
+ data->tid = TypeId ();
+ g_free = data;
+}
+#else
+struct PacketTagList::TagData *
+PacketTagList::AllocData (void) const
+{
+ NS_LOG_FUNCTION_NOARGS ();
+ struct PacketTagList::TagData *retval;
+ retval = new struct PacketTagList::TagData ();
+ return retval;
+}
+
+void
+PacketTagList::FreeData (struct TagData *data) const
+{
+ NS_LOG_FUNCTION (data);
+ delete data;
+}
+#endif
+
+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)
+ {
+ if (cur->tid == tid)
+ {
+ found = true;
+ tag.Deserialize (TagBuffer (cur->data, cur->data+PACKET_TAG_MAX_SIZE));
+ }
+ }
+ if (!found)
+ {
+ return false;
+ }
+ struct TagData *start = 0;
+ struct TagData **prevNext = &start;
+ for (struct TagData *cur = m_next; cur != 0; cur = cur->next)
+ {
+ if (cur->tid == tid)
+ {
+ /**
+ * XXX
+ * Note: I believe that we could optimize this to
+ * avoid copying each TagData located after the target id
+ * and just link the already-copied list to the next tag.
+ */
+ continue;
+ }
+ struct TagData *copy = AllocData ();
+ copy->tid = cur->tid;
+ copy->count = 1;
+ copy->next = 0;
+ memcpy (copy->data, cur->data, PACKET_TAG_MAX_SIZE);
+ *prevNext = copy;
+ prevNext = ©->next;
+ }
+ *prevNext = 0;
+ RemoveAll ();
+ m_next = start;
+ return true;
+}
+
+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)
+ {
+ NS_ASSERT (cur->tid != tag.GetInstanceTypeId ());
+ }
+ struct TagData *head = AllocData ();
+ head->count = 1;
+ head->next = 0;
+ head->tid = tag.GetInstanceTypeId ();
+ head->next = m_next;
+ NS_ASSERT (tag.GetSerializedSize () < PACKET_TAG_MAX_SIZE);
+ tag.Serialize (TagBuffer (head->data, head->data+tag.GetSerializedSize ()));
+
+ const_cast<PacketTagList *> (this)->m_next = head;
+}
+
+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)
+ {
+ if (cur->tid == tid)
+ {
+ /* found tag */
+ tag.Deserialize (TagBuffer (cur->data, cur->data+PACKET_TAG_MAX_SIZE));
+ return true;
+ }
+ }
+ /* no tag found */
+ return false;
+}
+
+const struct PacketTagList::TagData *
+PacketTagList::Head (void) const
+{
+ return m_next;
+}
+
+} // namespace ns3
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/common/packet-tag-list.h Mon Jun 08 09:19:00 2009 +0200
@@ -0,0 +1,142 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2006 INRIA
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+#ifndef PACKET_TAG_LIST_H
+#define PACKET_TAG_LIST_H
+
+#include <stdint.h>
+#include <ostream>
+#include "ns3/type-id.h"
+
+namespace ns3 {
+
+class Tag;
+
+/**
+ * \ingroup constants
+ * \brief Tag maximum size
+ * The maximum size (in bytes) of a Tag is stored
+ * in this constant.
+ */
+#define PACKET_TAG_MAX_SIZE 20
+
+class PacketTagList
+{
+public:
+ struct TagData {
+ uint8_t data[PACKET_TAG_MAX_SIZE];
+ struct TagData *next;
+ TypeId tid;
+ uint32_t count;
+ };
+
+ inline PacketTagList ();
+ inline PacketTagList (PacketTagList const &o);
+ inline PacketTagList &operator = (PacketTagList const &o);
+ inline ~PacketTagList ();
+
+ void Add (Tag const&tag) const;
+ bool Remove (Tag &tag);
+ bool Peek (Tag &tag) const;
+ inline void RemoveAll (void);
+
+ const struct PacketTagList::TagData *Head (void) const;
+
+private:
+
+ bool Remove (TypeId tid);
+ struct PacketTagList::TagData *AllocData (void) const;
+ void FreeData (struct TagData *data) const;
+
+ static struct PacketTagList::TagData *g_free;
+ static uint32_t g_nfree;
+
+ struct TagData *m_next;
+};
+
+} // namespace ns3
+
+/****************************************************
+ * Implementation of inline methods for performance
+ ****************************************************/
+
+namespace ns3 {
+
+PacketTagList::PacketTagList ()
+ : m_next ()
+{}
+
+PacketTagList::PacketTagList (PacketTagList const &o)
+ : m_next (o.m_next)
+{
+ if (m_next != 0)
+ {
+ m_next->count++;
+ }
+}
+
+PacketTagList &
+PacketTagList::operator = (PacketTagList const &o)
+{
+ // self assignment
+ if (m_next == o.m_next)
+ {
+ return *this;
+ }
+ RemoveAll ();
+ m_next = o.m_next;
+ if (m_next != 0)
+ {
+ m_next->count++;
+ }
+ return *this;
+}
+
+PacketTagList::~PacketTagList ()
+{
+ RemoveAll ();
+}
+
+void
+PacketTagList::RemoveAll (void)
+{
+ struct TagData *prev = 0;
+ for (struct TagData *cur = m_next; cur != 0; cur = cur->next)
+ {
+ cur->count--;
+ if (cur->count > 0)
+ {
+ break;
+ }
+ if (prev != 0)
+ {
+ FreeData (prev);
+ }
+ prev = cur;
+ }
+ if (prev != 0)
+ {
+ FreeData (prev);
+ }
+ m_next = 0;
+}
+
+} // namespace ns3
+
+#endif /* PACKET_TAG_LIST_H */
--- a/src/common/packet.cc Fri Jun 05 09:46:08 2009 -0700
+++ b/src/common/packet.cc Mon Jun 08 09:19:00 2009 +0200
@@ -28,22 +28,22 @@
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,31 +51,64 @@
}
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)
{}
+PacketTagIterator::PacketTagIterator (const struct PacketTagList::TagData *head)
+ : m_current (head)
+{}
+bool
+PacketTagIterator::HasNext (void) const
+{
+ return m_current != 0;
+}
+PacketTagIterator::Item
+PacketTagIterator::Next (void)
+{
+ NS_ASSERT (HasNext ());
+ const struct PacketTagList::TagData *prev = m_current;
+ m_current = m_current->next;
+ return PacketTagIterator::Item (prev);
+}
+
+PacketTagIterator::Item::Item (const struct PacketTagList::TagData *data)
+ : m_data (data)
+{}
+TypeId
+PacketTagIterator::Item::GetTypeId (void) const
+{
+ return m_data->tid;
+}
+void
+PacketTagIterator::Item::GetTag (Tag &tag) const
+{
+ NS_ASSERT (tag.GetInstanceTypeId () == m_data->tid);
+ tag.Deserialize (TagBuffer ((uint8_t*)m_data->data, (uint8_t*)m_data->data+PACKET_TAG_MAX_SIZE));
+}
+
+
void
Packet::Ref (void) const
{
@@ -102,7 +135,8 @@
Packet::Packet ()
: m_buffer (),
- m_tagList (),
+ m_byteTagList (),
+ m_packetTagList (),
m_metadata (m_globalUid, 0),
m_refCount (1)
{
@@ -111,7 +145,8 @@
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)
{}
@@ -124,14 +159,16 @@
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;
}
Packet::Packet (uint32_t size)
: m_buffer (size),
- m_tagList (),
+ m_byteTagList (),
+ m_packetTagList (),
m_metadata (m_globalUid, size),
m_refCount (1)
{
@@ -139,7 +176,8 @@
}
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)
{
@@ -149,9 +187,11 @@
i.Write (buffer, size);
}
-Packet::Packet (const Buffer &buffer, const TagList &tagList, const PacketMetadata &metadata)
+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)
{}
@@ -166,7 +206,7 @@
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, metadata), false);
+ return Ptr<Packet> (new Packet (buffer, m_byteTagList, m_packetTagList, metadata), false);
}
uint32_t
@@ -184,8 +224,8 @@
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);
@@ -215,8 +255,8 @@
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);
@@ -247,12 +287,12 @@
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
@@ -263,8 +303,8 @@
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);
}
@@ -284,10 +324,10 @@
}
void
-Packet::RemoveAllTags (void)
+Packet::RemoveAllByteTags (void)
{
NS_LOG_FUNCTION (this);
- m_tagList.RemoveAll ();
+ m_byteTagList.RemoveAll ();
}
uint8_t const *
@@ -297,9 +337,9 @@
uint32_t oldStart = m_buffer.GetCurrentStartOffset ();
uint8_t const * data = m_buffer.PeekData ();
uint32_t newStart = m_buffer.GetCurrentStartOffset ();
-
+
// Update tag offsets if buffer offsets were changed
- const_cast<TagList &>(m_tagList).AddAtStart (newStart - oldStart, newStart);
+ const_cast<ByteTagList &>(m_byteTagList).AddAtStart (newStart - oldStart, newStart);
return data;
}
@@ -323,12 +363,12 @@
}
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 ())
@@ -544,29 +584,29 @@
}
void
-Packet::AddTag (const Tag &tag) const
+Packet::AddByteTag (const Tag &tag) const
{
NS_LOG_FUNCTION (this << tag.GetInstanceTypeId ().GetName () << tag.GetSerializedSize ());
- 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);
@@ -576,6 +616,62 @@
return false;
}
+void
+Packet::AddPacketTag (const Tag &tag) const
+{
+ NS_LOG_FUNCTION (this << tag.GetInstanceTypeId ().GetName () << tag.GetSerializedSize ());
+ m_packetTagList.Add (tag);
+}
+bool
+Packet::RemovePacketTag (Tag &tag)
+{
+ NS_LOG_FUNCTION (this << tag.GetInstanceTypeId ().GetName () << tag.GetSerializedSize ());
+ bool found = m_packetTagList.Remove (tag);
+ return found;
+}
+bool
+Packet::PeekPacketTag (Tag &tag) const
+{
+ bool found = m_packetTagList.Peek (tag);
+ return found;
+}
+void
+Packet::RemoveAllPacketTags (void)
+{
+ NS_LOG_FUNCTION (this);
+ m_packetTagList.RemoveAll ();
+}
+
+void
+Packet::PrintPacketTags (std::ostream &os) const
+{
+ PacketTagIterator i = GetPacketTagIterator ();
+ while (i.HasNext ())
+ {
+ PacketTagIterator::Item item = i.Next ();
+ NS_ASSERT (item.GetTypeId ().HasConstructor ());
+ Callback<ObjectBase *> constructor = item.GetTypeId ().GetConstructor ();
+ NS_ASSERT (!constructor.IsNull ());
+ ObjectBase *instance = constructor ();
+ Tag *tag = dynamic_cast<Tag *> (instance);
+ NS_ASSERT (tag != 0);
+ item.GetTag (*tag);
+ tag->Print (os);
+ delete tag;
+ if (i.HasNext ())
+ {
+ os << " ";
+ }
+ }
+}
+
+PacketTagIterator
+Packet::GetPacketTagIterator (void) const
+{
+ return PacketTagIterator (m_packetTagList.Head ());
+}
+
+
std::ostream& operator<< (std::ostream& os, const Packet &packet)
{
packet.Print (os);
@@ -585,8 +681,6 @@
} // namespace ns3
-
-
#ifdef RUN_SELF_TESTS
#include "ns3/test.h"
@@ -773,14 +867,14 @@
namespace ns3 {
-class PacketTest: public Test
+static class PacketTest: public Test
{
public:
PacketTest ();
virtual bool RunTests (void);
private:
bool DoCheck (Ptr<const Packet> p, const char *file, int line, uint32_t n, ...);
-};
+} g_packetTest;
PacketTest::PacketTest ()
@@ -802,11 +896,11 @@
}
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 << ">";
@@ -845,12 +939,12 @@
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));
@@ -861,7 +955,7 @@
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));
@@ -870,11 +964,11 @@
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);
@@ -894,7 +988,7 @@
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));
@@ -905,7 +999,7 @@
{
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));
@@ -916,7 +1010,7 @@
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));
@@ -931,7 +1025,7 @@
{
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));
@@ -942,26 +1036,57 @@
{
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));
}
-
+
+ {
+ Packet p;
+ ATestTag<10> a;
+ p.AddPacketTag (a);
+ NS_TEST_ASSERT (p.PeekPacketTag (a));
+ ATestTag<11> b;
+ p.AddPacketTag (b);
+ NS_TEST_ASSERT (p.PeekPacketTag (b));
+ NS_TEST_ASSERT (p.PeekPacketTag (a));
+ Packet copy = p;
+ NS_TEST_ASSERT (copy.PeekPacketTag (b));
+ NS_TEST_ASSERT (copy.PeekPacketTag (a));
+ ATestTag<12> c;
+ NS_TEST_ASSERT (!copy.PeekPacketTag (c));
+ copy.AddPacketTag (c);
+ NS_TEST_ASSERT (copy.PeekPacketTag (c));
+ NS_TEST_ASSERT (copy.PeekPacketTag (b));
+ NS_TEST_ASSERT (copy.PeekPacketTag (a));
+ NS_TEST_ASSERT (!p.PeekPacketTag (c));
+ copy.RemovePacketTag (b);
+ NS_TEST_ASSERT (!copy.PeekPacketTag (b));
+ NS_TEST_ASSERT (p.PeekPacketTag (b));
+ p.RemovePacketTag (a);
+ NS_TEST_ASSERT (!p.PeekPacketTag (a));
+ NS_TEST_ASSERT (copy.PeekPacketTag (a));
+ NS_TEST_ASSERT (!p.PeekPacketTag (c));
+ NS_TEST_ASSERT (copy.PeekPacketTag (c));
+ p.RemoveAllPacketTags ();
+ NS_TEST_ASSERT (!p.PeekPacketTag (b));
+ }
+
{
// bug 572
Ptr<Packet> tmp = Create<Packet> (1000);
- tmp->AddTag (ATestTag<20> ());
+ tmp->AddByteTag (ATestTag<20> ());
CHECK (tmp, 1, E (20, 0, 1000));
tmp->AddHeader (ATestHeader<2> ());
CHECK (tmp, 1, E (20, 2, 1002));
@@ -974,9 +1099,6 @@
return result;
}
-
-static PacketTest g_packetTest;
-
-}; // namespace ns3
+} // namespace ns3
#endif /* RUN_SELF_TESTS */
--- a/src/common/packet.h Fri Jun 05 09:46:08 2009 -0700
+++ b/src/common/packet.h Mon Jun 08 09:19:00 2009 +0200
@@ -26,7 +26,8 @@
#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"
#include "ns3/ptr.h"
@@ -45,7 +46,7 @@
*
* This is a java-style iterator.
*/
-class TagIterator
+class ByteTagIterator
{
public:
/**
@@ -81,7 +82,7 @@
*/
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;
@@ -98,16 +99,63 @@
Item Next (void);
private:
friend class Packet;
- TagIterator (TagList::Iterator i);
- TagList::Iterator m_current;
+ ByteTagIterator (ByteTagList::Iterator i);
+ ByteTagList::Iterator m_current;
+};
+
+/**
+ * \ingroup packet
+ * \brief Iterator over the set of 'packet' tags in a packet
+ *
+ * This is a java-style iterator.
+ */
+class PacketTagIterator
+{
+public:
+ /**
+ * Identifies a tag within a packet.
+ */
+ class Item
+ {
+ public:
+ /**
+ * \returns the ns3::TypeId associated to this tag.
+ */
+ TypeId GetTypeId (void) const;
+ /**
+ * \param tag the user tag to which the data should be copied.
+ *
+ * Read the requested tag and store it in the user-provided
+ * tag instance. This method will crash if the type of the
+ * tag provided by the user does not match the type of
+ * the underlying tag.
+ */
+ void GetTag (Tag &tag) const;
+ private:
+ friend class PacketTagIterator;
+ Item (const struct PacketTagList::TagData *data);
+ const struct PacketTagList::TagData *m_data;
+ };
+ /**
+ * \returns true if calling Next is safe, false otherwise.
+ */
+ bool HasNext (void) const;
+ /**
+ * \returns the next item found and prepare for the next one.
+ */
+ Item Next (void);
+private:
+ friend class Packet;
+ PacketTagIterator (const struct PacketTagList::TagData *head);
+ const struct PacketTagList::TagData *m_current;
};
/**
* \ingroup packet
* \brief network packets
*
- * Each network packet contains a byte buffer, a set of tags, and
- * metadata.
+ * Each network packet contains a byte buffer, a set of byte tags, a set of
+ * packet tags, and metadata.
*
* - The byte buffer stores the serialized content of the headers and trailers
* added to a packet. The serialized representation of these headers is expected
@@ -115,17 +163,28 @@
* forces you to do this) which means that the content of a packet buffer
* is expected to be that of a real packet.
*
- * - Each tag tags a subset of the bytes in the packet byte buffer with the
- * information stored in the tag. A classic example of a tag is a FlowIdTag
- * which contains a flow id: the set of bytes tagged by this tag implicitely
- * belong to the attached flow id.
- *
* - The metadata describes the type of the headers and trailers which
* were serialized in the byte buffer. The maintenance of metadata is
* optional and disabled by default. To enable it, you must call
* Packet::EnableMetadata and this will allow you to get non-empty
* output from Packet::Print and Packet::Print.
*
+ * - The set of tags contain simulation-specific information which cannot
+ * be stored in the packet byte buffer because the protocol headers or trailers
+ * have no standard-conformant field for this information. So-called
+ * 'byte' tags are used to tag a subset of the bytes in the packet byte buffer
+ * while 'packet' tags are used to tag the packet itself. The main difference
+ * between these two kinds of tags is what happens when packets are copied,
+ * fragmented, and reassembled: 'byte' tags follow bytes while 'packet' tags
+ * follow packets. Another important difference between these two kinds of tags
+ * is that byte tags cannot be removed and are expected to be written once,
+ * and read many times, while packet tags are expected to be written once,
+ * read many times, and removed exactly once. An example of a 'byte'
+ * tag is a FlowIdTag which contains a flow id and is set by the application
+ * generating traffic. An example of a 'packet' tag is a cross-layer
+ * qos class id set by an application and processed by a lower-level MAC
+ * layer.
+ *
* Implementing a new type of Header or Trailer for a new protocol is
* pretty easy and is a matter of creating a subclass of the ns3::Header
* or of the ns3::Trailer base class, and implementing the methods
@@ -236,13 +295,6 @@
* \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
@@ -388,11 +440,11 @@
* 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.
+ * \returns an iterator over the set of byte 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.
@@ -400,17 +452,76 @@
* 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
+ *
+ * Add a tag to this packet. This method calls the
+ * Tag::GetSerializedSize and, then, Tag::Serialize.
+ *
+ * Note that this method is const, that is, it does not
+ * modify the state of this packet, which is fairly
+ * un-intuitive.
+ */
+ void AddPacketTag (const Tag &tag) const;
+ /**
+ * \param tag the tag to remove from this packet
+ * \returns true if the requested tag is found, false
+ * otherwise.
+ *
+ * Remove a tag from this packet. This method calls
+ * Tag::Deserialize if the tag is found.
+ */
+ bool RemovePacketTag (Tag &tag);
+ /**
+ * \param tag the tag to search in this packet
+ * \returns true if the requested tag is found, false
+ * otherwise.
+ *
+ * Search a matching tag and call Tag::Deserialize if it is found.
+ */
+ bool PeekPacketTag (Tag &tag) const;
+ /**
+ * Remove all packet tags.
+ */
+ void RemoveAllPacketTags (void);
+
+ /**
+ * \param os the stream in which we want to print data.
+ *
+ * Print the list of 'packet' tags.
+ *
+ * \sa Packet::AddPacketTag, Packet::RemovePacketTag, Packet::PeekPacketTag,
+ * Packet::RemoveAllPacketTags
+ */
+ void PrintPacketTags (std::ostream &os) const;
+
+ /**
+ * \returns an object which can be used to iterate over the list of
+ * packet tags.
+ */
+ PacketTagIterator GetPacketTagIterator (void) const;
private:
- Packet (const Buffer &buffer, const TagList &tagList, const PacketMetadata &metadata);
+ 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;
static uint32_t m_globalUid;
@@ -435,11 +546,15 @@
* - ns3::Packet::AddHeader
* - ns3::Packet::AddTrailer
* - both versions of ns3::Packet::AddAtEnd
+ * - ns3::Packet::RemovePacketTag
*
* Non-dirty operations:
- * - ns3::Packet::AddTag
- * - ns3::Packet::RemoveAllTags
- * - ns3::Packet::PeekTag
+ * - ns3::Packet::AddPacketTag
+ * - ns3::Packet::PeekPacketTag
+ * - ns3::Packet::RemoveAllPacketTags
+ * - ns3::Packet::AddByteTag
+ * - ns3::Packet::FindFirstMatchingByteTag
+ * - ns3::Packet::RemoveAllByteTags
* - ns3::Packet::RemoveHeader
* - ns3::Packet::RemoveTrailer
* - ns3::Packet::CreateFragment
--- a/src/common/tag-list.cc Fri Jun 05 09:46:08 2009 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,421 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2008 INRIA
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-#include "tag-list.h"
-#include "ns3/log.h"
-#include <vector>
-#include <string.h>
-
-NS_LOG_COMPONENT_DEFINE ("TagList");
-
-#define USE_FREE_LIST 1
-#define FREE_LIST_SIZE 1000
-#define OFFSET_MAX (2147483647)
-
-namespace ns3 {
-
-struct TagListData {
- uint32_t size;
- uint32_t count;
- uint32_t dirty;
- uint8_t data[4];
-};
-
-#ifdef USE_FREE_LIST
-static class TagListDataFreeList : public std::vector<struct TagListData *>
-{
-public:
- ~TagListDataFreeList ();
-} g_freeList;
-static uint32_t g_maxSize = 0;
-
-TagListDataFreeList::~TagListDataFreeList ()
-{
- for (TagListDataFreeList::iterator i = begin ();
- i != end (); i++)
- {
- uint8_t *buffer = (uint8_t *)(*i);
- delete [] buffer;
- }
-}
-#endif /* USE_FREE_LIST */
-
-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+16, m_end));
- item.tid.SetUid (m_nextTid);
- item.size = m_nextSize;
- item.start = std::max (m_nextStart, m_offsetStart);
- item.end = std::min (m_nextEnd, 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)
- {
- TagBuffer buf = TagBuffer (m_current, m_end);
- m_nextTid = buf.ReadU32 ();
- m_nextSize = buf.ReadU32 ();
- m_nextStart = buf.ReadU32 ();
- m_nextEnd = buf.ReadU32 ();
- if (m_nextStart >= m_offsetEnd || m_nextEnd <= m_offsetStart)
- {
- m_current += 4 + 4 + 4 + 4 + m_nextSize;
- }
- else
- {
- break;
- }
- }
-}
-TagList::Iterator::Iterator (uint8_t *start, uint8_t *end, int32_t offsetStart, int32_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_used (0),
- m_data (0)
-{
- NS_LOG_FUNCTION (this);
-}
-TagList::TagList (const TagList &o)
- : m_used (o.m_used),
- m_data (o.m_data)
-{
- NS_LOG_FUNCTION (this << &o);
- if (m_data != 0)
- {
- m_data->count++;
- }
-}
-TagList &
-TagList::operator = (const TagList &o)
-{
- NS_LOG_FUNCTION (this << &o);
- if (this == &o)
- {
- return *this;
- }
-
- Deallocate (m_data);
- m_data = o.m_data;
- m_used = o.m_used;
- if (m_data != 0)
- {
- m_data->count++;
- }
- return *this;
-}
-TagList::~TagList ()
-{
- NS_LOG_FUNCTION (this);
- Deallocate (m_data);
- m_data = 0;
- m_used = 0;
-}
-
-TagBuffer
-TagList::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;
- NS_ASSERT (m_used <= spaceNeeded);
- if (m_data == 0)
- {
- m_data = Allocate (spaceNeeded);
- m_used = 0;
- }
- else if (m_data->size < spaceNeeded ||
- (m_data->count != 1 && m_data->dirty != m_used))
- {
- struct TagListData *newData = Allocate (spaceNeeded);
- memcpy (&newData->data, &m_data->data, m_used);
- Deallocate (m_data);
- m_data = newData;
- }
- TagBuffer tag = TagBuffer (&m_data->data[m_used],
- &m_data->data[spaceNeeded]);
- tag.WriteU32 (tid.GetUid ());
- tag.WriteU32 (bufferSize);
- tag.WriteU32 (start);
- tag.WriteU32 (end);
- m_used = spaceNeeded;
- m_data->dirty = m_used;
- return tag;
-}
-
-void
-TagList::Add (const TagList &o)
-{
- NS_LOG_FUNCTION (this << &o);
- TagList::Iterator i = o.BeginAll ();
- 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::RemoveAll (void)
-{
- NS_LOG_FUNCTION (this);
- Deallocate (m_data);
- m_data = 0;
- m_used = 0;
-}
-
-TagList::Iterator
-TagList::BeginAll (void) const
-{
- NS_LOG_FUNCTION (this);
- // I am not totally sure but I might need to use
- // INT32_MIN instead of zero below.
- return Begin (0, OFFSET_MAX);
-}
-
-TagList::Iterator
-TagList::Begin (int32_t offsetStart, int32_t offsetEnd) const
-{
- NS_LOG_FUNCTION (this << offsetStart << offsetEnd);
- if (m_data == 0)
- {
- return Iterator (0, 0, offsetStart, offsetEnd);
- }
- else
- {
- return Iterator (m_data->data, &m_data->data[m_used], offsetStart, offsetEnd);
- }
-}
-
-bool
-TagList::IsDirtyAtEnd (int32_t appendOffset)
-{
- NS_LOG_FUNCTION (this << appendOffset);
- TagList::Iterator i = BeginAll ();
- while (i.HasNext ())
- {
- TagList::Iterator::Item item = i.Next ();
- if (item.end > appendOffset)
- {
- return true;
- }
- }
- return false;
-}
-
-bool
-TagList::IsDirtyAtStart (int32_t prependOffset)
-{
- NS_LOG_FUNCTION (this << prependOffset);
- TagList::Iterator i = BeginAll ();
- while (i.HasNext ())
- {
- TagList::Iterator::Item item = i.Next ();
- if (item.start < prependOffset)
- {
- return true;
- }
- }
- return false;
-}
-
-void
-TagList::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 ();
- 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, int32_t prependOffset)
-{
- NS_LOG_FUNCTION (this << adjustment << prependOffset);
- if (adjustment == 0 && !IsDirtyAtStart (prependOffset))
- {
- return;
- }
- TagList list;
- TagList::Iterator i = BeginAll ();
- 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;
-}
-
-#ifdef USE_FREE_LIST
-
-struct TagListData *
-TagList::Allocate (uint32_t size)
-{
- NS_LOG_FUNCTION (this << size);
- while (!g_freeList.empty ())
- {
- struct TagListData *data = g_freeList.back ();
- g_freeList.pop_back ();
- NS_ASSERT (data != 0);
- if (data->size >= size)
- {
- data->count = 1;
- data->dirty = 0;
- return data;
- }
- 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;
- data->count = 1;
- data->size = size;
- data->dirty = 0;
- return data;
-}
-
-void
-TagList::Deallocate (struct TagListData *data)
-{
- NS_LOG_FUNCTION (this << data);
- if (data == 0)
- {
- return;
- }
- g_maxSize = std::max (g_maxSize, data->size);
- data->count--;
- if (data->count == 0)
- {
- if (g_freeList.size () > FREE_LIST_SIZE ||
- data->size < g_maxSize)
- {
- uint8_t *buffer = (uint8_t *)data;
- delete [] buffer;
- }
- else
- {
- g_freeList.push_back (data);
- }
- }
-}
-
-#else /* USE_FREE_LIST */
-
-struct TagListData *
-TagList::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;
- data->count = 1;
- data->size = size;
- data->dirty = 0;
- return data;
-}
-
-void
-TagList::Deallocate (struct TagListData *data)
-{
- NS_LOG_FUNCTION (this << data);
- if (data == 0)
- {
- return;
- }
- data->count--;
- if (data->count == 0)
- {
- uint8_t *buffer = (uint8_t *)data;
- delete [] buffer;
- }
-}
-
-#endif /* USE_FREE_LIST */
-
-
-} // namespace ns3
--- a/src/common/tag-list.h Fri Jun 05 09:46:08 2009 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,170 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2008 INRIA
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-#ifndef TAG_LIST_H
-#define TAG_LIST_H
-
-#include <stdint.h>
-#include "ns3/type-id.h"
-#include "tag-buffer.h"
-
-namespace ns3 {
-
-struct TagListData;
-
-/**
- * \ingroup packet
- *
- * \brief keep track of the tags stored in a packet.
- *
- * This class is mostly private to the Packet implementation and users
- * should never have to access it directly.
- *
- * \internal
- * The implementation of this class is a bit tricky so, there are a couple
- * of things to keep in mind here:
- *
- * - it stores all tags in a single byte buffer: each tag is stored
- * 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
- * is shared and, thus, reference-counted. This data structure is unshared
- * as-needed to emulate COW semantics.
- *
- * - each tag tags a unique set of bytes identified by the pair of offsets
- * (start,end). These offsets are provided by Buffer::GetCurrentStartOffset
- * 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
- * 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.
- *
- * - whenever bytes are removed from the packet byte buffer, the TagList 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
-{
-public:
-
- class Iterator
- {
- public:
- struct Item
- {
- TypeId tid;
- uint32_t size;
- int32_t start;
- int32_t end;
- TagBuffer buf;
- Item (TagBuffer buf);
- private:
- friend class TagList;
- friend class TagList::Iterator;
- };
- 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, int32_t offsetStart, int32_t offsetEnd);
- void PrepareForNext (void);
- uint8_t *m_current;
- uint8_t *m_end;
- int32_t m_offsetStart;
- int32_t m_offsetEnd;
- uint32_t m_nextTid;
- uint32_t m_nextSize;
- int32_t m_nextStart;
- int32_t m_nextEnd;
- };
-
- TagList ();
- TagList (const TagList &o);
- TagList &operator = (const TagList &o);
- ~TagList ();
-
- /**
- * \param tid the typeid of the tag added
- * \param bufferSize the size of the tag when its serialization will
- * be completed. Typically, the return value of Tag::GetSerializedSize
- * \param start offset which uniquely identifies the first byte tagged by this tag.
- * \param end offset which uniquely identifies the last byte tagged by this tag.
- * \returns a buffer which can be used to write the tag data.
- *
- *
- */
- TagBuffer Add (TypeId tid, uint32_t bufferSize, int32_t start, int32_t end);
-
- /**
- * \param o the other list of tags to aggregate.
- *
- * Aggregate the two lists of tags.
- */
- void Add (const TagList &o);
-
- void RemoveAll (void);
-
- /**
- * \param offsetStart the offset which uniquely identifies the first data byte
- * present in the byte buffer associated to this TagList.
- * \param offsetEnd the offset which uniquely identifies the last data byte
- * present in the byte buffer associated to this TagList.
- * \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;
-
- /**
- * Adjust the offsets stored internally by the adjustment delta and
- * make sure that all offsets are smaller than appendOffset which represents
- * the location where new bytes have been added to the byte buffer.
- */
- void AddAtEnd (int32_t adjustment, int32_t appendOffset);
- /**
- * Adjust the offsets stored internally by the adjustment delta and
- * make sure that all offsets are bigger than prependOffset which represents
- * the location where new bytes have been added to the byte buffer.
- */
- void AddAtStart (int32_t adjustment, int32_t prependOffset);
-
-private:
- bool IsDirtyAtEnd (int32_t appendOffset);
- bool IsDirtyAtStart (int32_t prependOffset);
- TagList::Iterator BeginAll (void) const;
-
- struct TagListData *Allocate (uint32_t size);
- void Deallocate (struct TagListData *data);
-
- uint16_t m_used;
- struct TagListData *m_data;
-};
-
-} // namespace ns3
-
-#endif /* TAG_LIST_H */
--- a/src/common/tag.h Fri Jun 05 09:46:08 2009 -0700
+++ b/src/common/tag.h Mon Jun 08 09:19:00 2009 +0200
@@ -41,8 +41,8 @@
/**
* \returns the number of bytes required to serialize the data of the tag.
*
- * This method is typically invoked by Packet::AddTag just prior to calling
- * Tag::Serialize.
+ * This method is typically invoked by Packet::AddPacketTag or Packet::AddByteTag
+ * just prior to calling Tag::Serialize.
*/
virtual uint32_t GetSerializedSize (void) const = 0;
/**
@@ -65,7 +65,8 @@
/**
* \param os the stream to print to
*
- * This method is typically invoked from the Packet::PrintTags method
+ * This method is typically invoked from the Packet::PrintByteTags
+ * or Packet::PrintPacketTags methods.
*/
virtual void Print (std::ostream &os) const = 0;
};
--- a/src/common/wscript Fri Jun 05 09:46:08 2009 -0700
+++ b/src/common/wscript Mon Jun 08 09:19:00 2009 +0200
@@ -14,8 +14,9 @@
'data-rate.cc',
'error-model.cc',
'tag.cc',
- 'tag-list.cc',
+ 'byte-tag-list.cc',
'tag-buffer.cc',
+ 'packet-tag-list.cc',
]
headers = bld.new_task_gen('ns3header')
@@ -31,6 +32,7 @@
'data-rate.h',
'error-model.h',
'tag.h',
- 'tag-list.h',
+ 'byte-tag-list.h',
'tag-buffer.h',
+ 'packet-tag-list.h',
]
--- a/src/contrib/delay-jitter-estimation.cc Fri Jun 05 09:46:08 2009 -0700
+++ b/src/contrib/delay-jitter-estimation.cc Mon Jun 08 09:19:00 2009 +0200
@@ -83,14 +83,14 @@
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;
--- a/src/devices/wifi/mac-low.cc Fri Jun 05 09:46:08 2009 -0700
+++ b/src/devices/wifi/mac-low.cc Mon Jun 08 09:19:00 2009 +0200
@@ -537,7 +537,7 @@
{
NS_LOG_DEBUG ("receive cts from="<<m_currentHdr.GetAddr1 ());
SnrTag tag;
- packet->FindFirstMatchingTag (tag);
+ packet->RemovePacketTag (tag);
WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ());
station->ReportRxOk (rxSnr, txMode);
station->ReportRtsOk (rxSnr, txMode, tag.Get ());
@@ -560,7 +560,7 @@
{
NS_LOG_DEBUG ("receive ack from="<<m_currentHdr.GetAddr1 ());
SnrTag tag;
- packet->FindFirstMatchingTag (tag);
+ packet->RemovePacketTag (tag);
WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ());
station->ReportRxOk (rxSnr, txMode);
station->ReportDataOk (rxSnr, txMode, tag.Get ());
@@ -1080,7 +1080,7 @@
struct SnrTag tag;
tag.Set (rtsSnr);
- packet->AddTag (tag);
+ packet->AddPacketTag (tag);
ForwardDown (packet, &cts, ctsTxMode);
}
@@ -1159,7 +1159,7 @@
struct SnrTag tag;
tag.Set (dataSnr);
- packet->AddTag (tag);
+ packet->AddPacketTag (tag);
ForwardDown (packet, &ack, ackTxMode);
}
--- a/src/devices/wifi/qos-utils.cc Fri Jun 05 09:46:08 2009 -0700
+++ b/src/devices/wifi/qos-utils.cc Mon Jun 08 09:19:00 2009 +0200
@@ -59,7 +59,7 @@
{
QosTag qos;
uint8_t tid = 8;
- if (packet->FindFirstMatchingTag (qos))
+ if (packet->PeekPacketTag (qos))
{
if (qos.Get () < 8)
{
--- a/src/devices/wifi/wifi-phy-test.cc Fri Jun 05 09:46:08 2009 -0700
+++ b/src/devices/wifi/wifi-phy-test.cc Mon Jun 08 09:19:00 2009 +0200
@@ -167,7 +167,7 @@
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);
}
@@ -176,7 +176,7 @@
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);
}
@@ -185,7 +185,7 @@
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++;
--- a/src/devices/wifi/wifi-remote-station-manager.cc Fri Jun 05 09:46:08 2009 -0700
+++ b/src/devices/wifi/wifi-remote-station-manager.cc Mon Jun 08 09:19:00 2009 +0200
@@ -577,7 +577,7 @@
return;
}
TxModeTag tag = TxModeTag (DoGetRtsMode (), DoGetDataMode (fullPacketSize));
- packet->AddTag (tag);
+ packet->AddPacketTag (tag);
}
WifiMode
WifiRemoteStation::GetDataMode (Ptr<const Packet> packet, uint32_t fullPacketSize)
@@ -588,7 +588,7 @@
}
TxModeTag tag;
bool found;
- found = packet->FindFirstMatchingTag (tag);
+ found = ConstCast<Packet> (packet)->RemovePacketTag (tag);
NS_ASSERT (found);
return tag.GetDataMode ();
}
@@ -601,7 +601,7 @@
}
TxModeTag tag;
bool found;
- found = packet->FindFirstMatchingTag (tag);
+ found = ConstCast<Packet> (packet)->RemovePacketTag (tag);
NS_ASSERT (found);
return tag.GetRtsMode ();
}
--- a/src/internet-stack/ipv4-l3-protocol.cc Fri Jun 05 09:46:08 2009 -0700
+++ b/src/internet-stack/ipv4-l3-protocol.cc Mon Jun 08 09:19:00 2009 +0200
@@ -482,7 +482,7 @@
bool mayFragment = true;
uint8_t ttl = m_defaultTtl;
SocketIpTtlTag tag;
- bool found = packet->FindFirstMatchingTag (tag);
+ bool found = packet->RemovePacketTag (tag);
if (found)
{
ttl = tag.GetTtl ();
--- a/src/internet-stack/tcp-socket-impl.cc Fri Jun 05 09:46:08 2009 -0700
+++ b/src/internet-stack/tcp-socket-impl.cc Mon Jun 08 09:19:00 2009 +0200
@@ -563,6 +563,9 @@
m_rxBufSize += i->second->GetSize()-avail;
}
}
+ SocketAddressTag tag;
+ tag.SetAddress (InetSocketAddress (m_remoteAddress, m_remotePort));
+ outPacket->AddPacketTag (tag);
return outPacket;
}
@@ -577,7 +580,7 @@
Ptr<Packet>
TcpSocketImpl::RecvFrom (uint32_t maxSize, uint32_t flags,
- Address &fromAddress)
+ Address &fromAddress)
{
NS_LOG_FUNCTION (this << maxSize << flags);
Ptr<Packet> packet = Recv (maxSize, flags);
@@ -586,7 +589,7 @@
{
SocketAddressTag tag;
bool found;
- found = packet->FindFirstMatchingTag (tag);
+ found = packet->PeekPacketTag (tag);
NS_ASSERT (found);
fromAddress = tag.GetAddress ();
}
@@ -1196,9 +1199,6 @@
p = p->CreateFragment (0,s);
m_nextRxSequence += s; // Advance next expected sequence
NS_LOG_LOGIC("Case 1, advanced nrxs to " << m_nextRxSequence );
- SocketAddressTag tag;
- tag.SetAddress (fromAddress);
- p->AddTag (tag);
//buffer this, it'll be read by call to Recv
UnAckData_t::iterator i =
m_bufferedData.find (tcpHeader.GetSequenceNumber () );
@@ -1266,9 +1266,6 @@
}
}
// Save for later delivery
- SocketAddressTag tag;
- tag.SetAddress (fromAddress);
- p->AddTag (tag);
m_bufferedData[startSeq] = p;
i = m_bufferedData.find (startSeq);
next = i;
@@ -1295,9 +1292,6 @@
p = p->CreateFragment (m_nextRxSequence - tcpHeader.GetSequenceNumber (),s);
SequenceNumber start = m_nextRxSequence;
m_nextRxSequence += s; // Advance next expected sequence
- SocketAddressTag tag;
- tag.SetAddress (fromAddress);
- p->AddTag (tag);
//buffer the new fragment, it'll be read by call to Recv
UnAckData_t::iterator i = m_bufferedData.find (start);
if (i != m_bufferedData.end () ) //we found it already in the buffer
--- a/src/internet-stack/udp-socket-impl.cc Fri Jun 05 09:46:08 2009 -0700
+++ b/src/internet-stack/udp-socket-impl.cc Mon Jun 08 09:19:00 2009 +0200
@@ -325,17 +325,17 @@
{
SocketIpTtlTag tag;
tag.SetTtl (m_ipMulticastTtl);
- p->AddTag (tag);
+ p->AddPacketTag (tag);
}
else if (m_ipTtl != 0 && !dest.IsMulticast () && !dest.IsBroadcast ())
{
SocketIpTtlTag tag;
tag.SetTtl (m_ipTtl);
- p->AddTag (tag);
+ p->AddPacketTag (tag);
}
{
SocketSetDontFragmentTag tag;
- bool found = p->FindFirstMatchingTag (tag);
+ bool found = p->RemovePacketTag (tag);
if (!found)
{
if (m_mtuDiscover)
@@ -346,7 +346,7 @@
{
tag.Disable ();
}
- p->AddTag (tag);
+ p->AddPacketTag (tag);
}
}
//
@@ -490,7 +490,7 @@
{
SocketAddressTag tag;
bool found;
- found = packet->FindFirstMatchingTag (tag);
+ found = packet->PeekPacketTag (tag);
NS_ASSERT (found);
fromAddress = tag.GetAddress ();
}
@@ -554,7 +554,7 @@
Address address = InetSocketAddress (ipv4, port);
SocketAddressTag tag;
tag.SetAddress (address);
- packet->AddTag (tag);
+ packet->AddPacketTag (tag);
m_deliveryQueue.push (packet);
m_rxAvailable += packet->GetSize ();
NotifyDataRecv ();
--- a/src/internet-stack/udp-test.cc Fri Jun 05 09:46:08 2009 -0700
+++ b/src/internet-stack/udp-test.cc Mon Jun 08 09:19:00 2009 +0200
@@ -216,8 +216,8 @@
NS_TEST_ASSERT_EQUAL (m_receivedPacket->GetSize (), 123);
NS_TEST_ASSERT_EQUAL (m_receivedPacket2->GetSize (), 0); // second interface should receive it
- m_receivedPacket->RemoveAllTags ();
- m_receivedPacket2->RemoveAllTags ();
+ m_receivedPacket->RemoveAllByteTags ();
+ m_receivedPacket2->RemoveAllByteTags ();
// Simple broadcast test
@@ -230,8 +230,8 @@
// second socket should not receive it (it is bound specifically to the second interface's address
NS_TEST_ASSERT_EQUAL (m_receivedPacket2->GetSize (), 0);
- m_receivedPacket->RemoveAllTags ();
- m_receivedPacket2->RemoveAllTags ();
+ m_receivedPacket->RemoveAllByteTags ();
+ m_receivedPacket2->RemoveAllByteTags ();
// Broadcast test with multiple receiving sockets
@@ -251,8 +251,8 @@
NS_TEST_ASSERT_EQUAL (m_receivedPacket->GetSize (), 123);
NS_TEST_ASSERT_EQUAL (m_receivedPacket2->GetSize (), 123);
- m_receivedPacket->RemoveAllTags ();
- m_receivedPacket2->RemoveAllTags ();
+ m_receivedPacket->RemoveAllByteTags ();
+ m_receivedPacket2->RemoveAllByteTags ();
Simulator::Destroy ();
--- a/src/node/address.h Fri Jun 05 09:46:08 2009 -0700
+++ b/src/node/address.h Mon Jun 08 09:19:00 2009 +0200
@@ -91,7 +91,7 @@
* can be stored in an Address instance.
*/
enum MaxSize_e {
- MAX_SIZE = 30
+ MAX_SIZE = 20
};
/**
--- a/src/node/packet-socket.cc Fri Jun 05 09:46:08 2009 -0700
+++ b/src/node/packet-socket.cc Mon Jun 08 09:19:00 2009 +0200
@@ -52,7 +52,7 @@
PacketSocket::PacketSocket () : m_rxAvailable (0)
{
- NS_LOG_FUNCTION_NOARGS ();
+ NS_LOG_FUNCTION (this);
m_state = STATE_OPEN;
m_shutdownSend = false;
m_shutdownRecv = false;
@@ -64,40 +64,40 @@
void
PacketSocket::SetNode (Ptr<Node> node)
{
- NS_LOG_FUNCTION_NOARGS ();
+ NS_LOG_FUNCTION (this << node);
m_node = node;
}
PacketSocket::~PacketSocket ()
{
- NS_LOG_FUNCTION_NOARGS ();
+ NS_LOG_FUNCTION (this);
}
void
PacketSocket::DoDispose (void)
{
- NS_LOG_FUNCTION_NOARGS ();
+ NS_LOG_FUNCTION (this);
m_device = 0;
}
enum Socket::SocketErrno
PacketSocket::GetErrno (void) const
{
- NS_LOG_FUNCTION_NOARGS ();
+ NS_LOG_FUNCTION (this);
return m_errno;
}
Ptr<Node>
PacketSocket::GetNode (void) const
{
- NS_LOG_FUNCTION_NOARGS ();
+ NS_LOG_FUNCTION (this);
return m_node;
}
int
PacketSocket::Bind (void)
{
- NS_LOG_FUNCTION_NOARGS ();
+ NS_LOG_FUNCTION (this);
PacketSocketAddress address;
address.SetProtocol (0);
address.SetAllDevices ();
@@ -107,7 +107,7 @@
int
PacketSocket::Bind (const Address &address)
{
- NS_LOG_FUNCTION_NOARGS ();
+ NS_LOG_FUNCTION (this << address);
if (!PacketSocketAddress::IsMatchingType (address))
{
m_errno = ERROR_INVAL;
@@ -120,7 +120,7 @@
int
PacketSocket::DoBind (const PacketSocketAddress &address)
{
- NS_LOG_FUNCTION_NOARGS ();
+ NS_LOG_FUNCTION (this << address);
if (m_state == STATE_BOUND ||
m_state == STATE_CONNECTED)
{
@@ -153,7 +153,7 @@
int
PacketSocket::ShutdownSend (void)
{
- NS_LOG_FUNCTION_NOARGS ();
+ NS_LOG_FUNCTION (this);
if (m_state == STATE_CLOSED)
{
m_errno = ERROR_BADF;
@@ -166,7 +166,7 @@
int
PacketSocket::ShutdownRecv (void)
{
- NS_LOG_FUNCTION_NOARGS ();
+ NS_LOG_FUNCTION (this);
if (m_state == STATE_CLOSED)
{
m_errno = ERROR_BADF;
@@ -179,7 +179,7 @@
int
PacketSocket::Close(void)
{
- NS_LOG_FUNCTION_NOARGS ();
+ NS_LOG_FUNCTION (this);
if (m_state == STATE_CLOSED)
{
m_errno = ERROR_BADF;
@@ -192,7 +192,7 @@
int
PacketSocket::Connect(const Address &ad)
{
- NS_LOG_FUNCTION_NOARGS ();
+ NS_LOG_FUNCTION (this << ad);
PacketSocketAddress address;
if (m_state == STATE_CLOSED)
{
@@ -233,7 +233,7 @@
int
PacketSocket::Send (Ptr<Packet> p, uint32_t flags)
{
- NS_LOG_FUNCTION_NOARGS ();
+ NS_LOG_FUNCTION (this << p << flags);
if (m_state == STATE_OPEN ||
m_state == STATE_BOUND)
{
@@ -278,7 +278,7 @@
int
PacketSocket::SendTo (Ptr<Packet> p, uint32_t flags, const Address &address)
{
- NS_LOG_FUNCTION_NOARGS ();
+ NS_LOG_FUNCTION (this << p << flags << address);
PacketSocketAddress ad;
if (m_state == STATE_CLOSED)
{
@@ -351,7 +351,7 @@
uint16_t protocol, const Address &from,
const Address &to, NetDevice::PacketType packetType)
{
- NS_LOG_FUNCTION_NOARGS ();
+ NS_LOG_FUNCTION (this << device << packet << protocol << from << to << packetType);
if (m_shutdownRecv)
{
return;
@@ -365,10 +365,11 @@
if ((m_rxAvailable + packet->GetSize ()) <= m_rcvBufSize)
{
+ Ptr<Packet> copy = packet->Copy ();
SocketAddressTag tag;
tag.SetAddress (address);
- packet->AddTag (tag);
- m_deliveryQueue.push (packet->Copy ());
+ copy->AddPacketTag (tag);
+ m_deliveryQueue.push (copy);
m_rxAvailable += packet->GetSize ();
NS_LOG_LOGIC ("UID is " << packet->GetUid() << " PacketSocket " << this);
NotifyDataRecv ();
@@ -388,7 +389,7 @@
uint32_t
PacketSocket::GetRxAvailable (void) const
{
- NS_LOG_FUNCTION_NOARGS ();
+ NS_LOG_FUNCTION (this);
// We separately maintain this state to avoid walking the queue
// every time this might be called
return m_rxAvailable;
@@ -397,7 +398,7 @@
Ptr<Packet>
PacketSocket::Recv (uint32_t maxSize, uint32_t flags)
{
- NS_LOG_FUNCTION_NOARGS ();
+ NS_LOG_FUNCTION (this << maxSize << flags);
if (m_deliveryQueue.empty() )
{
return 0;
@@ -418,13 +419,13 @@
Ptr<Packet>
PacketSocket::RecvFrom (uint32_t maxSize, uint32_t flags, Address &fromAddress)
{
- NS_LOG_FUNCTION_NOARGS ();
+ NS_LOG_FUNCTION (this << maxSize << flags << fromAddress);
Ptr<Packet> packet = Recv (maxSize, flags);
if (packet != 0)
{
SocketAddressTag tag;
bool found;
- found = packet->FindFirstMatchingTag (tag);
+ found = packet->PeekPacketTag (tag);
NS_ASSERT (found);
fromAddress = tag.GetAddress ();
}
@@ -434,7 +435,7 @@
int
PacketSocket::GetSockName (Address &address) const
{
- NS_LOG_FUNCTION_NOARGS ();
+ NS_LOG_FUNCTION (this << address);
PacketSocketAddress ad = PacketSocketAddress::ConvertFrom(address);
ad.SetProtocol (m_protocol);
--- a/utils/bench-packets.cc Fri Jun 05 09:46:08 2009 -0700
+++ b/utils/bench-packets.cc Mon Jun 08 09:19:00 2009 +0200
@@ -168,14 +168,14 @@
for (uint32_t i = 0; i < n; i++) {
Ptr<Packet> p = Create<Packet> (2000);
- p->AddTag (tag1);
+ p->AddPacketTag (tag1);
p->AddHeader (udp);
- p->FindFirstMatchingTag (tag1);
- p->AddTag (tag2);
+ p->RemovePacketTag (tag1);
+ p->AddPacketTag (tag2);
p->AddHeader (ipv4);
Ptr<Packet> o = p->Copy ();
o->RemoveHeader (ipv4);
- p->FindFirstMatchingTag (tag2);
+ p->RemovePacketTag (tag2);
o->RemoveHeader (udp);
}
}