A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ns3::ByteTagList Class Reference

keep track of the byte tags stored in a packet. More...

#include "byte-tag-list.h"

+ Collaboration diagram for ns3::ByteTagList:

Classes

class  Iterator
 An iterator for iterating through a byte tag list. More...
 

Public Member Functions

 ByteTagList ()
 
 ByteTagList (const ByteTagList &o)
 Copy constructor, copies the data and increases reference count.
 
 ~ByteTagList ()
 
void Add (const ByteTagList &o)
 
TagBuffer Add (TypeId tid, uint32_t bufferSize, int32_t start, int32_t end)
 
void AddAtEnd (int32_t appendOffset)
 Make sure that all offsets are smaller than appendOffset which represents the location where new bytes have been added to the byte buffer.
 
void AddAtStart (int32_t prependOffset)
 Make sure that all offsets are bigger than prependOffset which represents the location where new bytes have been added to the byte buffer.
 
void Adjust (int32_t adjustment)
 Adjust the offsets stored internally by the adjustment delta.
 
ByteTagList::Iterator Begin (int32_t offsetStart, int32_t offsetEnd) const
 
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.
 
ByteTagListoperator= (const ByteTagList &o)
 Assignment operator, deallocates current data and assigns value of passed in ByteTagList.
 
void RemoveAll ()
 Removes all of the tags from the ByteTagList.
 
uint32_t Serialize (uint32_t *buffer, uint32_t maxSize) const
 Serialize the tag list into a byte buffer.
 

Private Member Functions

ByteTagListDataAllocate (uint32_t size)
 Allocate the memory for the ByteTagListData.
 
ByteTagList::Iterator BeginAll () const
 Returns an iterator pointing to the very first tag in this list.
 
void Deallocate (ByteTagListData *data)
 Deallocates a ByteTagListData.
 

Private Attributes

int32_t m_adjustment
 adjustment to byte tag offsets
 
ByteTagListDatam_data
 the ByteTagListData structure
 
int32_t m_maxEnd
 maximal end offset
 
int32_t m_minStart
 minimal start offset
 
uint32_t m_used
 the number of used bytes in the buffer
 

Detailed Description

keep track of the byte 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 relative to the start of the packet Whenever the origin of the offset changes, the Packet adjusts all byte tags using ByteTagList::Adjust method.
  • When packet is reduced in size, byte tags that span outside the packet boundaries remain in ByteTagList. It is not a problem as iterator fixes the boundaries before returning item. However, when packet is extending, it calls ByteTagList::AddAtStart or ByteTagList::AddAtEnd to cut byte tags that will otherwise cover new bytes.

Definition at line 54 of file byte-tag-list.h.

Constructor & Destructor Documentation

◆ ByteTagList() [1/2]

ns3::ByteTagList::ByteTagList ( )

Definition at line 139 of file byte-tag-list.cc.

References NS_LOG_FUNCTION.

◆ ByteTagList() [2/2]

ns3::ByteTagList::ByteTagList ( const ByteTagList & o)

Copy constructor, copies the data and increases reference count.

Parameters
oThe ByteTagList to copy

Definition at line 149 of file byte-tag-list.cc.

References ns3::ByteTagListData::count, m_data, and NS_LOG_FUNCTION.

◆ ~ByteTagList()

ns3::ByteTagList::~ByteTagList ( )

Definition at line 184 of file byte-tag-list.cc.

References Deallocate(), m_data, m_used, and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

Member Function Documentation

◆ Add() [1/2]

void ns3::ByteTagList::Add ( const ByteTagList & o)
Parameters
othe other list of tags to aggregate.

Aggregate the two lists of tags.

Definition at line 229 of file byte-tag-list.cc.

References Add(), BeginAll(), ns3::ByteTagList::Iterator::Item::buf, ns3::TagBuffer::CopyFrom(), ns3::ByteTagList::Iterator::Item::end, ns3::ByteTagList::Iterator::HasNext(), ns3::ByteTagList::Iterator::Next(), NS_LOG_FUNCTION, ns3::ByteTagList::Iterator::Item::size, ns3::ByteTagList::Iterator::Item::start, and ns3::ByteTagList::Iterator::Item::tid.

+ Here is the call graph for this function:

◆ Add() [2/2]

TagBuffer ns3::ByteTagList::Add ( TypeId tid,
uint32_t bufferSize,
int32_t start,
int32_t end )
Parameters
tidthe typeid of the tag added
bufferSizethe size of the tag when its serialization will be completed. Typically, the return value of Tag::GetSerializedSize
startoffset which uniquely identifies the first byte tagged by this tag.
endoffset which uniquely identifies the last byte tagged by this tag.
Returns
a buffer which can be used to write the tag data.

Definition at line 193 of file byte-tag-list.cc.

References Allocate(), ns3::ByteTagListData::count, ns3::ByteTagListData::data, Deallocate(), ns3::ByteTagListData::dirty, ns3::TypeId::GetUid(), m_adjustment, m_data, m_maxEnd, m_minStart, m_used, NS_ASSERT, NS_LOG_FUNCTION, ns3::ByteTagListData::size, and ns3::TagBuffer::WriteU32().

Referenced by Add(), ns3::Packet::AddAtEnd(), and Deserialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AddAtEnd()

void ns3::ByteTagList::AddAtEnd ( int32_t appendOffset)

Make sure that all offsets are smaller than appendOffset which represents the location where new bytes have been added to the byte buffer.

Parameters
appendOffsetmaximum offset value

Definition at line 277 of file byte-tag-list.cc.

References BeginAll(), ns3::ByteTagList::Iterator::Item::buf, ns3::TagBuffer::CopyFrom(), ns3::ByteTagList::Iterator::Item::end, ns3::ByteTagList::Iterator::HasNext(), list, m_adjustment, m_maxEnd, ns3::ByteTagList::Iterator::Next(), NS_LOG_FUNCTION, ns3::ByteTagList::Iterator::Item::size, ns3::ByteTagList::Iterator::Item::start, and ns3::ByteTagList::Iterator::Item::tid.

Referenced by ns3::Packet::AddAtEnd(), ns3::Packet::AddPaddingAtEnd(), and ns3::Packet::AddTrailer().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AddAtStart()

void ns3::ByteTagList::AddAtStart ( int32_t prependOffset)

Make sure that all offsets are bigger than prependOffset which represents the location where new bytes have been added to the byte buffer.

Parameters
prependOffsetminimum offset value

Definition at line 309 of file byte-tag-list.cc.

References BeginAll(), ns3::ByteTagList::Iterator::Item::buf, ns3::TagBuffer::CopyFrom(), ns3::ByteTagList::Iterator::Item::end, ns3::ByteTagList::Iterator::HasNext(), list, m_adjustment, m_minStart, ns3::ByteTagList::Iterator::Next(), NS_LOG_FUNCTION, ns3::ByteTagList::Iterator::Item::size, ns3::ByteTagList::Iterator::Item::start, and ns3::ByteTagList::Iterator::Item::tid.

Referenced by ns3::Packet::AddAtEnd(), and ns3::Packet::AddHeader().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Adjust()

void ns3::ByteTagList::Adjust ( int32_t adjustment)
inline

Adjust the offsets stored internally by the adjustment delta.

Parameters
adjustmentvalue to change stored offsets by

Definition at line 283 of file byte-tag-list.h.

References m_adjustment.

Referenced by ns3::Packet::AddAtEnd(), ns3::Packet::AddHeader(), ns3::Packet::CreateFragment(), ns3::Packet::RemoveAtStart(), ns3::Packet::RemoveHeader(), and ns3::Packet::RemoveHeader().

+ Here is the caller graph for this function:

◆ Allocate()

ByteTagListData * ns3::ByteTagList::Allocate ( uint32_t size)
private

Allocate the memory for the ByteTagListData.

Parameters
sizethe memory to allocate
Returns
the ByteTagListData structure

Definition at line 344 of file byte-tag-list.cc.

References data, ns3::g_freeList, ns3::g_maxSize, NS_ASSERT, and NS_LOG_FUNCTION.

Referenced by Add().

+ Here is the caller graph for this function:

◆ Begin()

ByteTagList::Iterator ns3::ByteTagList::Begin ( int32_t offsetStart,
int32_t offsetEnd ) const
Parameters
offsetStartthe offset which uniquely identifies the first data byte present in the byte buffer associated to this ByteTagList.
offsetEndthe 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.

Definition at line 263 of file byte-tag-list.cc.

References ns3::ByteTagListData::data, m_adjustment, m_data, m_used, and NS_LOG_FUNCTION.

Referenced by BeginAll(), and ns3::Packet::GetByteTagIterator().

+ Here is the caller graph for this function:

◆ BeginAll()

ByteTagList::Iterator ns3::ByteTagList::BeginAll ( ) const
private

Returns an iterator pointing to the very first tag in this list.

Returns
an iterator

Definition at line 254 of file byte-tag-list.cc.

References Begin(), NS_LOG_FUNCTION, and OFFSET_MAX.

Referenced by Add(), AddAtEnd(), AddAtStart(), GetSerializedSize(), and Serialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Deallocate()

void ns3::ByteTagList::Deallocate ( ByteTagListData * data)
private

Deallocates a ByteTagListData.

Parameters
datathe ByteTagListData to deallocate

Definition at line 370 of file byte-tag-list.cc.

References data, FREE_LIST_SIZE, ns3::g_freeList, ns3::g_maxSize, and NS_LOG_FUNCTION.

Referenced by ~ByteTagList(), Add(), operator=(), and RemoveAll().

+ Here is the caller graph for this function:

◆ Deserialize()

uint32_t ns3::ByteTagList::Deserialize ( const uint32_t * buffer,
uint32_t size )

Deserialize tag list from the provided buffer.

Parameters
[in]bufferThe buffer to read from.
[in]sizeThe number of bytes to deserialize.
Returns
zero if complete tag list is not deserialized

Definition at line 539 of file byte-tag-list.cc.

References Add(), ns3::TypeId::LookupByHash(), NS_ASSERT, NS_LOG_FUNCTION, NS_LOG_INFO, and ns3::TagBuffer::Write().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetSerializedSize()

uint32_t ns3::ByteTagList::GetSerializedSize ( ) const

Returns number of bytes required for packet serialization.

Returns
number of bytes required for packet serialization

Definition at line 426 of file byte-tag-list.cc.

References BeginAll(), ns3::ByteTagList::Iterator::HasNext(), ns3::ByteTagList::Iterator::Next(), NS_LOG_FUNCTION_NOARGS, and ns3::ByteTagList::Iterator::Item::size.

Referenced by ns3::Packet::GetSerializedSize(), and ns3::Packet::Serialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator=()

ByteTagList & ns3::ByteTagList::operator= ( const ByteTagList & o)

Assignment operator, deallocates current data and assigns value of passed in ByteTagList.

Also increases reference count

Parameters
oreference to the ByteTagList to copy
Returns
reference to the assignee

Definition at line 164 of file byte-tag-list.cc.

References ns3::ByteTagListData::count, Deallocate(), m_adjustment, m_data, m_maxEnd, m_minStart, and m_used.

+ Here is the call graph for this function:

◆ RemoveAll()

void ns3::ByteTagList::RemoveAll ( )

Removes all of the tags from the ByteTagList.

Definition at line 242 of file byte-tag-list.cc.

References Deallocate(), m_adjustment, m_data, m_maxEnd, m_minStart, m_used, and NS_LOG_FUNCTION.

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Serialize()

uint32_t ns3::ByteTagList::Serialize ( uint32_t * buffer,
uint32_t maxSize ) const

Serialize the tag list into a byte buffer.

Parameters
[in,out]bufferThe byte buffer to which the tag list will be serialized
[in]maxSizeMax The max size of the buffer for bounds checking
Returns
zero if complete tag list is not serialized

Definition at line 455 of file byte-tag-list.cc.

References BeginAll(), ns3::ByteTagList::Iterator::Item::buf, ns3::ByteTagList::Iterator::Item::end, ns3::TypeId::GetHash(), ns3::ByteTagList::Iterator::HasNext(), ns3::ByteTagList::Iterator::Next(), NS_LOG_FUNCTION, NS_LOG_INFO, ns3::TagBuffer::Read(), ns3::ByteTagList::Iterator::Item::size, ns3::ByteTagList::Iterator::Item::start, and ns3::ByteTagList::Iterator::Item::tid.

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_adjustment

int32_t ns3::ByteTagList::m_adjustment
private

adjustment to byte tag offsets

Definition at line 277 of file byte-tag-list.h.

Referenced by Add(), AddAtEnd(), AddAtStart(), Adjust(), Begin(), operator=(), and RemoveAll().

◆ m_data

ByteTagListData* ns3::ByteTagList::m_data
private

the ByteTagListData structure

Definition at line 279 of file byte-tag-list.h.

Referenced by ByteTagList(), ~ByteTagList(), Add(), Begin(), operator=(), and RemoveAll().

◆ m_maxEnd

int32_t ns3::ByteTagList::m_maxEnd
private

maximal end offset

Definition at line 276 of file byte-tag-list.h.

Referenced by Add(), AddAtEnd(), operator=(), and RemoveAll().

◆ m_minStart

int32_t ns3::ByteTagList::m_minStart
private

minimal start offset

Definition at line 275 of file byte-tag-list.h.

Referenced by Add(), AddAtStart(), operator=(), and RemoveAll().

◆ m_used

uint32_t ns3::ByteTagList::m_used
private

the number of used bytes in the buffer

Definition at line 278 of file byte-tag-list.h.

Referenced by ~ByteTagList(), Add(), Begin(), operator=(), and RemoveAll().


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