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. | |
| PacketTagList (const PacketTagList &o) | |
| Copy constructor. | |
| ~PacketTagList () | |
| Destructor. | |
| void | Add (const Tag &tag) const |
| Add a tag to the head of this branch. | |
| uint32_t | Deserialize (const uint32_t *buffer, uint32_t size) |
| Deserialize tag list from the provided buffer. | |
| uint32_t | GetSerializedSize () const |
| Returns number of bytes required for packet serialization. | |
| const PacketTagList::TagData * | Head () const |
| PacketTagList & | operator= (const PacketTagList &o) |
| Assignment. | |
| bool | Peek (Tag &tag) const |
| Find a tag and return its value. | |
| bool | Remove (Tag &tag) |
| Remove (the first instance of) tag from the list. | |
| void | RemoveAll () |
| Remove all tags from this list (up to the first merge). | |
| bool | Replace (Tag &tag) |
| Replace the value of a tag. | |
| uint32_t | Serialize (uint32_t *buffer, uint32_t maxSize) const |
| Serialize the tag list into a byte buffer. | |
Private Types | |
| typedef bool(PacketTagList::* | COWWriter) (Tag &tag, bool preMerge, TagData *cur, TagData **prevNext) |
| Typedef of method function pointer for copy-on-write operations. | |
Private Member Functions | |
| bool | COWTraverse (Tag &tag, PacketTagList::COWWriter Writer) |
| Traverse the list implementing copy-on-write, using Writer. | |
| bool | RemoveWriter (Tag &tag, bool preMerge, TagData *cur, TagData **prevNext) |
| Copy-on-write implementing Remove. | |
| bool | ReplaceWriter (Tag &tag, bool preMerge, TagData *cur, TagData **prevNext) |
| Copy-on-write implementing Replace. | |
Static Private Member Functions | |
| static TagData * | CreateTagData (size_t dataSize) |
| Allocate and construct a TagData struct, sizing the data area large enough to serialize dataSize bytes from a Tag. | |
Private Attributes | |
| TagData * | m_next |
| Pointer to first TagData on the list. | |
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.
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).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).Definition at line 113 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 256 of file packet-tag-list.h.
|
inline |
Create a new PacketTagList.
Definition at line 308 of file packet-tag-list.h.
References m_next.
Referenced by PacketTagList(), Add(), and operator=().
|
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 313 of file packet-tag-list.h.
References PacketTagList(), and m_next.
|
inline |
Destructor.
RemoveAll's the tags up to the first merge.
Definition at line 339 of file packet-tag-list.h.
References RemoveAll().
| void ns3::PacketTagList::Add | ( | const Tag & | tag | ) | const |
Add a tag to the head of this branch.
| [in] | tag | The tag to add |
Definition at line 251 of file packet-tag-list.cc.
References PacketTagList(), ns3::PacketTagList::TagData::count, CreateTagData(), ns3::PacketTagList::TagData::data, ns3::ObjectBase::GetInstanceTypeId(), ns3::TypeId::GetName(), ns3::Tag::GetSerializedSize(), m_next, ns3::PacketTagList::TagData::next, NS_ASSERT_MSG, NS_LOG_FUNCTION, ns3::Tag::Serialize(), ns3::PacketTagList::TagData::size, and ns3::PacketTagList::TagData::tid.
Referenced by 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 45 of file packet-tag-list.cc.
References ns3::PacketTagList::TagData::count, CreateTagData(), ns3::PacketTagList::TagData::data, ns3::ObjectBase::GetInstanceTypeId(), m_next, ns3::PacketTagList::TagData::next, NS_ASSERT, NS_LOG_FUNCTION, NS_LOG_INFO, ns3::PacketTagList::TagData::size, and ns3::PacketTagList::TagData::tid.
Referenced by Remove(), and Replace().
|
staticprivate |
Allocate and construct a TagData struct, sizing the data area large enough to serialize dataSize bytes from a Tag.
| [in] | dataSize | The serialized size of the Tag. |
Definition at line 30 of file packet-tag-list.cc.
References NS_ASSERT_MSG, and ns3::PacketTagList::TagData::size.
Referenced by Add(), COWTraverse(), Deserialize(), and ReplaceWriter().
Deserialize tag list from the provided buffer.
| [in] | buffer | The buffer to read from. |
| [in] | size | The number of bytes to deserialize. |
Definition at line 384 of file packet-tag-list.cc.
References ns3::PacketTagList::TagData::count, CreateTagData(), ns3::PacketTagList::TagData::data, ns3::TypeId::LookupByHash(), m_next, ns3::PacketTagList::TagData::next, NS_ASSERT, NS_LOG_FUNCTION, NS_LOG_INFO, and ns3::PacketTagList::TagData::tid.
| uint32_t ns3::PacketTagList::GetSerializedSize | ( | ) | const |
Returns number of bytes required for packet serialization.
Definition at line 296 of file packet-tag-list.cc.
References m_next, and NS_LOG_FUNCTION_NOARGS.
| const PacketTagList::TagData * ns3::PacketTagList::Head | ( | ) | const |
Definition at line 290 of file packet-tag-list.cc.
References m_next.
|
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 323 of file packet-tag-list.h.
References PacketTagList(), 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 272 of file packet-tag-list.cc.
References ns3::Tag::Deserialize(), ns3::ObjectBase::GetInstanceTypeId(), m_next, and NS_LOG_FUNCTION.
Referenced by PacketTagListTest::CheckRef(), and PacketTagListTest::DoRun().
| 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 165 of file packet-tag-list.cc.
References COWTraverse(), and RemoveWriter().
Referenced by PacketTagListTest::AddRemoveTime(), and PacketTagListTest::DoRun().
|
inline |
Remove all tags from this list (up to the first merge).
Definition at line 345 of file packet-tag-list.h.
Referenced by ~PacketTagList(), and operator=().
|
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 172 of file packet-tag-list.cc.
References ns3::PacketTagList::TagData::count, ns3::PacketTagList::TagData::data, ns3::Tag::Deserialize(), ns3::PacketTagList::TagData::next, NS_LOG_FUNCTION_NOARGS, and ns3::PacketTagList::TagData::size.
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 205 of file packet-tag-list.cc.
References Add(), COWTraverse(), and ReplaceWriter().
|
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 217 of file packet-tag-list.cc.
References ns3::PacketTagList::TagData::count, CreateTagData(), ns3::PacketTagList::TagData::data, ns3::ObjectBase::GetInstanceTypeId(), ns3::Tag::GetSerializedSize(), ns3::PacketTagList::TagData::next, NS_LOG_FUNCTION_NOARGS, ns3::Tag::Serialize(), ns3::PacketTagList::TagData::size, and ns3::PacketTagList::TagData::tid.
Referenced by Replace().
Serialize the tag list into a byte buffer.
| [in,out] | buffer | The byte buffer to which the tag list will be serialized |
| [in] | maxSize | Max The max size of the buffer for bounds checking |
Definition at line 321 of file packet-tag-list.cc.
References m_next, NS_LOG_FUNCTION, and NS_LOG_INFO.
|
private |
Pointer to first TagData on the list.
Definition at line 296 of file packet-tag-list.h.
Referenced by PacketTagList(), PacketTagList(), Add(), COWTraverse(), Deserialize(), GetSerializedSize(), Head(), operator=(), Peek(), RemoveAll(), and Serialize().