A Discrete-Event Network Simulator
API
Classes | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
ns3::PacketTagList Class Reference

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::TagDataHead (void) const
 
PacketTagListoperator= (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...
 

Static Private Member Functions

static TagDataCreateTagData (size_t dataSize)
 Allocate and construct a TagData struct, sizing the data area large enough to serialize dataSize bytes from a Tag. More...
 

Private Attributes

struct TagDatam_next
 Pointer to first TagData on the list. More...
 

Detailed Description

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.

Internal:

The implementation of this class is a bit tricky. Refer to this diagram in the discussion that follows.

dot_inline_dotgraph_1.png
Copy-on-write is implemented as follows:

Definition at line 123 of file packet-tag-list.h.

Member Typedef Documentation

◆ COWWriter

typedef bool(PacketTagList::* ns3::PacketTagList::COWWriter) (Tag &tag, bool preMerge, struct TagData *cur, struct TagData **prevNext)
private

Typedef of method function pointer for copy-on-write operations.

Parameters
[in]tagThe tag type to operate on.
[in]preMergeTrue if tag was found before the first merge, false otherwise.
[in]curPointer to the tag.
[in]prevNextPointer to the struct TagData.next pointer pointing to cur.
Returns
True if operation successful, false otherwise

Definition at line 244 of file packet-tag-list.h.

Constructor & Destructor Documentation

◆ PacketTagList() [1/2]

ns3::PacketTagList::PacketTagList ( )
inline

Create a new PacketTagList.

Definition at line 295 of file packet-tag-list.h.

◆ PacketTagList() [2/2]

ns3::PacketTagList::PacketTagList ( PacketTagList const &  o)
inline

Copy constructor.

Parameters
[in]oThe PacketTagList to copy.

This makes a light-weight copy by RemoveAll, then pointing to the same TagData as o.

Definition at line 300 of file packet-tag-list.h.

References ns3::PacketTagList::TagData::count, and m_next.

◆ ~PacketTagList()

ns3::PacketTagList::~PacketTagList ( )
inline

Destructor.

RemoveAll's the tags up to the first merge.

Definition at line 326 of file packet-tag-list.h.

References RemoveAll().

Member Function Documentation

◆ Add()

void ns3::PacketTagList::Add ( Tag const &  tag) const

◆ COWTraverse()

bool ns3::PacketTagList::COWTraverse ( Tag tag,
PacketTagList::COWWriter  Writer 
)
private

Traverse the list implementing copy-on-write, using Writer.

Parameters
[in]tagThe tag type to operate on.
[in]WriterThe copy-on-write function to use.
Returns
True if tag found, false otherwise.

Definition at line 55 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().

◆ CreateTagData()

PacketTagList::TagData * ns3::PacketTagList::CreateTagData ( size_t  dataSize)
staticprivate

Allocate and construct a TagData struct, sizing the data area large enough to serialize dataSize bytes from a Tag.

Parameters
[in]dataSizeThe serialized size of the Tag.
Returns
The newly constructed TagData object.

Definition at line 38 of file packet-tag-list.cc.

References max, NS_ASSERT_MSG(), and ns3::PacketTagList::TagData::size.

Referenced by Add(), COWTraverse(), and ReplaceWriter().

◆ Head()

const struct PacketTagList::TagData * ns3::PacketTagList::Head ( void  ) const
Returns
pointer to head of tag list

Definition at line 298 of file packet-tag-list.cc.

References m_next.

Referenced by ns3::Packet::GetPacketTagIterator().

◆ operator=()

PacketTagList & ns3::PacketTagList::operator= ( PacketTagList const &  o)
inline

Assignment.

Parameters
[in]oThe PacketTagList to copy.
Returns
the copied object

This makes a light-weight copy by RemoveAll, then pointing to the same TagData as o.

Definition at line 310 of file packet-tag-list.h.

References ns3::PacketTagList::TagData::count, m_next, and RemoveAll().

◆ Peek()

bool ns3::PacketTagList::Peek ( Tag tag) const

Find a tag and return its value.

Parameters
[in,out]tagThe tag type to find. If found, tag is set to the value of the tag found.
Returns
True if tag is found, false otherwise.

Definition at line 280 of file packet-tag-list.cc.

References ns3::Tag::Deserialize(), ns3::ObjectBase::GetInstanceTypeId(), m_next, ns3::PacketTagList::TagData::next, and NS_LOG_FUNCTION.

Referenced by PacketTagListTest::CheckRef(), PacketTagListTest::DoRun(), and ns3::Packet::PeekPacketTag().

◆ Remove()

bool ns3::PacketTagList::Remove ( Tag tag)

Remove (the first instance of) tag from the list.

Parameters
[in,out]tagThe tag type to remove. If found, tag is set to the value of the tag found.
Returns
True if tag is found, false otherwise.

Definition at line 176 of file packet-tag-list.cc.

References COWTraverse(), and RemoveWriter().

Referenced by PacketTagListTest::AddRemoveTime(), PacketTagListTest::DoRun(), and ns3::Packet::RemovePacketTag().

◆ RemoveAll()

void ns3::PacketTagList::RemoveAll ( void  )
inline

Remove all tags from this list (up to the first merge).

Definition at line 332 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().

◆ RemoveWriter()

bool ns3::PacketTagList::RemoveWriter ( Tag tag,
bool  preMerge,
struct TagData cur,
struct TagData **  prevNext 
)
private

Copy-on-write implementing Remove.

Parameters
[in]tagThe target tag type to remove.
[in]preMergeTrue if tag was found before the first merge, false otherwise.
[in]curPointer to the tag.
[in]prevNextPointer to the struct TagData.next pointer pointing to cur.
Returns
True, since tag will definitely be removed.

Definition at line 183 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().

◆ Replace()

bool ns3::PacketTagList::Replace ( Tag tag)

Replace the value of a tag.

Parameters
[in]tagThe tag type to replace. To get the old value of the tag, use Peek first.
Returns
True if tag is found, false otherwise. If tag wasn't found, Add is performed instead (so the list is guaranteed to have the new tag value either way).

Definition at line 215 of file packet-tag-list.cc.

References Add(), COWTraverse(), and ReplaceWriter().

Referenced by ns3::Packet::ReplacePacketTag().

◆ ReplaceWriter()

bool ns3::PacketTagList::ReplaceWriter ( Tag tag,
bool  preMerge,
struct TagData cur,
struct TagData **  prevNext 
)
private

Copy-on-write implementing Replace.

Parameters
[in]tagThe target tag type to replace
[in]preMergeTrue if tag was found before the first merge, false otherwise.
[in]curPointer to the tag
[in]prevNextPointer to the struct TagData.next pointer pointing to cur.
Returns
True, since tag value will definitely be replaced.

Definition at line 227 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().

Member Data Documentation

◆ m_next

struct TagData* ns3::PacketTagList::m_next
private

Pointer to first TagData on the list.

Definition at line 284 of file packet-tag-list.h.

Referenced by Add(), COWTraverse(), Head(), operator=(), PacketTagList(), Peek(), and RemoveAll().


The documentation for this class was generated from the following files: