List of the packet tags stored in a packet. More...
#include <packet-tag-list.h>
Classes | |
struct | TagData |
Tree node for sharing serialized tags. More... | |
Public Member Functions | |
PacketTagList () | |
Create a new PacketTagList. More... | |
PacketTagList (PacketTagList const &o) | |
Copy constructor. More... | |
~PacketTagList () | |
Destructor. More... | |
void | Add (Tag const &tag) const |
Add a tag to the head of this branch. More... | |
const struct PacketTagList::TagData * | Head (void) const |
PacketTagList & | operator= (PacketTagList const &o) |
Assignment. More... | |
bool | Peek (Tag &tag) const |
Find a tag and return its value. More... | |
bool | Remove (Tag &tag) |
Remove (the first instance of) tag from the list. More... | |
void | RemoveAll (void) |
Remove all tags from this list (up to the first merge). More... | |
bool | Replace (Tag &tag) |
Replace the value of a tag. More... | |
Private Types | |
typedef bool(PacketTagList::* | COWWriter )(Tag &tag, bool preMerge, struct TagData *cur, struct TagData **prevNext) |
Typedef of method function pointer for copy-on-write operations. More... | |
Private Member Functions | |
bool | COWTraverse (Tag &tag, PacketTagList::COWWriter Writer) |
Traverse the list implementing copy-on-write, using Writer. More... | |
bool | RemoveWriter (Tag &tag, bool preMerge, struct TagData *cur, struct TagData **prevNext) |
Copy-on-write implementing Remove. More... | |
bool | ReplaceWriter (Tag &tag, bool preMerge, struct TagData *cur, struct TagData **prevNext) |
Copy-on-write implementing Replace. More... | |
Private Attributes | |
struct TagData * | m_next |
Pointer to first TagData on the list. More... | |
List of the packet tags stored in a packet.
This class is mostly private to the Packet implementation and users should never have to access it directly.
The implementation of this class is a bit tricky. Refer to this diagram in the discussion that follows.
T1-T7
in the diagram)next
pointers in the diagram) toward the root of the tree, which is a null pointer.count
is the number of incoming pointers to this TagData. Branch points, where branches merge or join, have count > 1
(T3
, T5
); successive links along a branch have count = 1
(T1
, T2
, T4
, T6
, T7
).T5-T7
)T6
). This is a constant time operation, and does not affect any other PacketTagList's, hence this is a const
function.o
, incrementing the count
. For assignment, the old branch is deleted, up to the first branch point, which has its count
decremented. (PacketTagList B
started as a copy of PacketTagList A
, before T6
was added to B
).This documentation entitles the original author to a free beer.
Definition at line 129 of file packet-tag-list.h.
|
private |
Typedef of method function pointer for copy-on-write operations.
[in] | tag | The tag type to operate on. |
[in] | preMerge | True if tag was found before the first merge, false otherwise. |
[in] | cur | Pointer to the tag. |
[in] | prevNext | Pointer to the struct TagData.next pointer pointing to cur. |
Definition at line 253 of file packet-tag-list.h.
|
inline |
Create a new PacketTagList.
Definition at line 303 of file packet-tag-list.h.
|
inline |
Copy constructor.
[in] | o | The PacketTagList to copy. |
This makes a light-weight copy by RemoveAll, then pointing to the same TagData as o.
Definition at line 308 of file packet-tag-list.h.
References ns3::PacketTagList::TagData::count, and m_next.
|
inline |
Destructor.
RemoveAll's the tags up to the first merge.
Definition at line 334 of file packet-tag-list.h.
References RemoveAll().
void ns3::PacketTagList::Add | ( | Tag const & | tag | ) | const |
Add a tag to the head of this branch.
[in] | tag | The tag to add |
Definition at line 245 of file packet-tag-list.cc.
References ns3::PacketTagList::TagData::count, ns3::PacketTagList::TagData::data, ns3::ObjectBase::GetInstanceTypeId(), ns3::Tag::GetSerializedSize(), m_next, ns3::PacketTagList::TagData::MAX_SIZE, ns3::PacketTagList::TagData::next, NS_ASSERT, NS_LOG_FUNCTION, ns3::Tag::Serialize(), and ns3::PacketTagList::TagData::tid.
Referenced by ns3::Packet::AddPacketTag(), PacketTagListTest::AddRemoveTime(), PacketTagListTest::DoRun(), and Replace().
|
private |
Traverse the list implementing copy-on-write, using Writer.
[in] | tag | The tag type to operate on. |
[in] | Writer | The copy-on-write function to use. |
Definition at line 39 of file packet-tag-list.cc.
References ns3::PacketTagList::TagData::count, ns3::PacketTagList::TagData::data, ns3::ObjectBase::GetInstanceTypeId(), m_next, ns3::PacketTagList::TagData::MAX_SIZE, ns3::PacketTagList::TagData::next, NS_ASSERT, NS_LOG_FUNCTION, NS_LOG_INFO, and ns3::PacketTagList::TagData::tid.
Referenced by Remove(), and Replace().
const struct PacketTagList::TagData * ns3::PacketTagList::Head | ( | void | ) | const |
Definition at line 283 of file packet-tag-list.cc.
References m_next.
Referenced by ns3::Packet::GetPacketTagIterator().
|
inline |
Assignment.
[in] | o | The PacketTagList to copy. |
This makes a light-weight copy by RemoveAll, then pointing to the same TagData as o.
Definition at line 318 of file packet-tag-list.h.
References ns3::PacketTagList::TagData::count, m_next, and RemoveAll().
bool ns3::PacketTagList::Peek | ( | Tag & | tag | ) | const |
Find a tag and return its value.
[in,out] | tag | The tag type to find. If found, tag is set to the value of the tag found. |
Definition at line 265 of file packet-tag-list.cc.
References ns3::Tag::Deserialize(), ns3::ObjectBase::GetInstanceTypeId(), m_next, ns3::PacketTagList::TagData::MAX_SIZE, ns3::PacketTagList::TagData::next, and NS_LOG_FUNCTION.
Referenced by PacketTagListTest::CheckRef(), PacketTagListTest::DoRun(), and ns3::Packet::PeekPacketTag().
bool ns3::PacketTagList::Remove | ( | Tag & | tag | ) |
Remove (the first instance of) tag from the list.
[in,out] | tag | The tag type to remove. If found, tag is set to the value of the tag found. |
Definition at line 159 of file packet-tag-list.cc.
References COWTraverse(), and RemoveWriter().
Referenced by PacketTagListTest::AddRemoveTime(), PacketTagListTest::DoRun(), and ns3::Packet::RemovePacketTag().
|
inline |
Remove all tags from this list (up to the first merge).
Definition at line 340 of file packet-tag-list.h.
References ns3::PacketTagList::TagData::count, m_next, and ns3::PacketTagList::TagData::next.
Referenced by operator=(), ns3::Packet::RemoveAllPacketTags(), and ~PacketTagList().
|
private |
Copy-on-write implementing Remove.
[in] | tag | The target tag type to remove. |
[in] | preMerge | True if tag was found before the first merge, false otherwise. |
[in] | cur | Pointer to the tag. |
[in] | prevNext | Pointer to the struct TagData.next pointer pointing to cur. |
Definition at line 166 of file packet-tag-list.cc.
References ns3::PacketTagList::TagData::count, ns3::PacketTagList::TagData::data, ns3::Tag::Deserialize(), ns3::PacketTagList::TagData::MAX_SIZE, ns3::PacketTagList::TagData::next, and NS_LOG_FUNCTION_NOARGS.
Referenced by Remove().
bool ns3::PacketTagList::Replace | ( | Tag & | tag | ) |
Replace the value of a tag.
[in] | tag | The tag type to replace. To get the old value of the tag, use Peek first. |
Definition at line 198 of file packet-tag-list.cc.
References Add(), COWTraverse(), and ReplaceWriter().
Referenced by ns3::Packet::ReplacePacketTag().
|
private |
Copy-on-write implementing Replace.
[in] | tag | The target tag type to replace |
[in] | preMerge | True if tag was found before the first merge, false otherwise. |
[in] | cur | Pointer to the tag |
[in] | prevNext | Pointer to the struct TagData.next pointer pointing to cur. |
Definition at line 210 of file packet-tag-list.cc.
References ns3::PacketTagList::TagData::count, ns3::PacketTagList::TagData::data, ns3::ObjectBase::GetInstanceTypeId(), ns3::Tag::GetSerializedSize(), ns3::PacketTagList::TagData::next, NS_LOG_FUNCTION_NOARGS, ns3::Tag::Serialize(), and ns3::PacketTagList::TagData::tid.
Referenced by Replace().
|
private |
Pointer to first TagData on the list.
Definition at line 292 of file packet-tag-list.h.
Referenced by Add(), COWTraverse(), Head(), operator=(), PacketTagList(), Peek(), and RemoveAll().