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

automatically resized byte buffer More...

#include "buffer.h"

+ Collaboration diagram for ns3::Buffer:

Classes

struct  Data
 This data structure is variable-sized through its last member whose size is determined at allocation time and stored in the m_size field. More...
 
class  Iterator
 iterator in a Buffer instance More...
 
struct  LocalStaticDestructor
 Local static destructor structure. More...
 

Public Member Functions

 Buffer ()
 
 Buffer (const Buffer &o)
 Copy constructor.
 
 Buffer (uint32_t dataSize)
 Constructor.
 
 Buffer (uint32_t dataSize, bool initialize)
 Constructor.
 
 ~Buffer ()
 
void AddAtEnd (const Buffer &o)
 
void AddAtEnd (uint32_t end)
 
void AddAtStart (uint32_t start)
 
Buffer::Iterator Begin () const
 
void CopyData (std::ostream *os, uint32_t size) const
 Copy the specified amount of data from the buffer to the given output stream.
 
uint32_t CopyData (uint8_t *buffer, uint32_t size) const
 Copy the specified amount of data from the buffer to the given buffer.
 
Buffer CreateFragment (uint32_t start, uint32_t length) const
 
uint32_t Deserialize (const uint8_t *buffer, uint32_t size)
 
Buffer::Iterator End () const
 
uint32_t GetSerializedSize () const
 Return the number of bytes required for serialization.
 
uint32_t GetSize () const
 
Bufferoperator= (const Buffer &o)
 Assignment operator.
 
const uint8_t * PeekData () const
 
void RemoveAtEnd (uint32_t end)
 
void RemoveAtStart (uint32_t start)
 
uint32_t Serialize (uint8_t *buffer, uint32_t maxSize) const
 

Private Types

typedef std::vector< Buffer::Data * > FreeList
 Container for buffer data.
 

Private Member Functions

bool CheckInternalState () const
 Checks the internal buffer structures consistency.
 
Buffer CreateFullCopy () const
 Create a full copy of the buffer, including all the internal structures.
 
uint32_t GetInternalEnd () const
 Get the buffer end position.
 
uint32_t GetInternalSize () const
 Get the buffer real size.
 
void Initialize (uint32_t zeroSize)
 Initializes the buffer with a number of zeroes.
 
void TransformIntoRealBuffer () const
 Transform a "Virtual byte buffer" into a "Real byte buffer".
 

Static Private Member Functions

static Buffer::DataAllocate (uint32_t reqSize)
 Allocate a buffer data storage.
 
static Buffer::DataCreate (uint32_t size)
 Create a buffer data storage.
 
static void Deallocate (Buffer::Data *data)
 Deallocate the buffer memory.
 
static void Recycle (Buffer::Data *data)
 Recycle the buffer memory.
 

Private Attributes

Datam_data
 the buffer data storage
 
uint32_t m_end
 offset to the end of the data referenced by this Buffer instance from the start of m_data->m_data
 
uint32_t m_maxZeroAreaStart
 keep track of the maximum value of m_zeroAreaStart across the lifetime of a Buffer instance.
 
uint32_t m_start
 offset to the start of the data referenced by this Buffer instance from the start of m_data->m_data
 
uint32_t m_zeroAreaEnd
 offset to the end of the virtual zero area from the start of m_data->m_data
 
uint32_t m_zeroAreaStart
 offset to the start of the virtual zero area from the start of m_data->m_data
 

Static Private Attributes

static FreeListg_freeList = nullptr
 Buffer data container.
 
static LocalStaticDestructor g_localStaticDestructor
 Local static destructor.
 
static uint32_t g_maxSize = 0
 Max observed data size.
 
static uint32_t g_recommendedStart = 0
 location in a newly-allocated buffer where you should start writing data.
 

Detailed Description

automatically resized byte buffer

This represents a buffer of bytes. Its size is automatically adjusted to hold any data prepended or appended by the user. Its implementation is optimized to ensure that the number of buffer resizes is minimized, by creating new Buffers of the maximum size ever used. The correct maximum size is learned at runtime during use by recording the maximum size of each packet.

Internal:
The implementation of the Buffer class uses a COW (Copy On Write) technique to ensure that the underlying data buffer which holds the data bytes is shared among a lot of Buffer instances despite data being added or removed from them.

When multiple Buffer instances hold a reference to the same underlying BufferData object, they must be able to detect when the operation they want to perform should trigger a copy of the BufferData. If the BufferData::m_count field is one, it means that there exist only one instance of Buffer which references the BufferData instance so, it is safe to modify it. It is also safe to modify the content of a BufferData if the modification falls outside of the "dirty area" defined by the BufferData. In every other case, the BufferData must be copied before being modified.

To understand the way the Buffer::Add and Buffer::Remove methods work, you first need to understand the "virtual offsets" used to keep track of the content of buffers. Each Buffer instance contains real data bytes in its BufferData instance but it also contains "virtual zero data" which typically is used to represent application-level payload. No memory is allocated to store the zero bytes of application-level payload unless the user fragments a Buffer: this application-level payload is kept track of with a pair of integers which describe where in the buffer content the "virtual zero area" starts and ends.

* ***: unused bytes
* xxx: bytes "added" at the front of the zero area
* ...: bytes "added" at the back of the zero area
* 000: virtual zero bytes
*
* Real byte buffer:      |********xxxxxxxxxxxx.........*****|
*                        |--------^ m_start
*                        |-------------------^ m_zeroAreaStart
*                        |-----------------------------^ m_end - (m_zeroAreaEnd - m_zeroAreaStart)
* Virtual byte buffer:           |xxxxxxxxxxxx0000000000000.........|
*                        |--------^ m_start
*                        |--------------------^ m_zeroAreaStart
*                        |---------------------------------^ m_zeroAreaEnd
*                        |------------------------------------------^ m_end
* 

A simple state invariant is that m_start <= m_zeroStart <= m_zeroEnd <= m_end

Definition at line 82 of file buffer.h.

Member Typedef Documentation

◆ FreeList

typedef std::vector<Buffer::Data*> ns3::Buffer::FreeList
private

Container for buffer data.

Definition at line 786 of file buffer.h.

Constructor & Destructor Documentation

◆ Buffer() [1/4]

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

Copy constructor.

Parameters
othe buffer to copy

Definition at line 1044 of file buffer.h.

References CheckInternalState(), ns3::Buffer::Data::m_count, m_data, and NS_ASSERT.

+ Here is the call graph for this function:

◆ Buffer() [2/4]

ns3::Buffer::Buffer ( )

Definition at line 181 of file buffer.cc.

References Initialize(), and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ Buffer() [3/4]

ns3::Buffer::Buffer ( uint32_t dataSize)

Constructor.

The buffer will be initialized with zeroes up to its size.

Parameters
dataSizethe buffer size

Definition at line 187 of file buffer.cc.

References Initialize(), and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ Buffer() [4/4]

ns3::Buffer::Buffer ( uint32_t dataSize,
bool initialize )

Constructor.

If initialize is set to true, the buffer will be initialized with zeroes up to its size.

Parameters
dataSizethe buffer size.
initializeinitialize the buffer with zeroes.

Definition at line 193 of file buffer.cc.

References Initialize(), and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ ~Buffer()

ns3::Buffer::~Buffer ( )

Definition at line 276 of file buffer.cc.

References CheckInternalState(), g_recommendedStart, ns3::Buffer::Data::m_count, m_data, m_maxZeroAreaStart, NS_ASSERT, NS_LOG_FUNCTION, and Recycle().

+ Here is the call graph for this function:

Member Function Documentation

◆ AddAtEnd() [1/2]

void ns3::Buffer::AddAtEnd ( const Buffer & o)
Parameters
othe buffer to append to the end of this buffer.

Add bytes at the end of the Buffer. Any call to this method invalidates any Iterator pointing to this Buffer.

This is an optimization which kicks in when we attempt to aggregate two buffers which contain adjacent zero areas.

Definition at line 395 of file buffer.cc.

References AddAtEnd(), Begin(), CheckInternalState(), CreateFullCopy(), End(), GetSize(), ns3::Buffer::Data::m_count, m_data, ns3::Buffer::Data::m_dirtyEnd, m_end, m_start, m_zeroAreaEnd, m_zeroAreaStart, NS_ASSERT, NS_LOG_FUNCTION, ns3::Buffer::Iterator::Prev(), and ns3::Buffer::Iterator::Write().

+ Here is the call graph for this function:

◆ AddAtEnd() [2/2]

void ns3::Buffer::AddAtEnd ( uint32_t end)
Parameters
endsize to reserve

Add bytes at the end of the Buffer. The content of these bytes is undefined but debugging builds initialize them to 0x33. Any call to this method invalidates any Iterator pointing to this Buffer.

Definition at line 349 of file buffer.cc.

References CheckInternalState(), Create(), GetInternalEnd(), GetInternalSize(), LOG_INTERNAL_STATE, ns3::Buffer::Data::m_count, ns3::Buffer::Data::m_data, m_data, ns3::Buffer::Data::m_dirtyEnd, ns3::Buffer::Data::m_dirtyStart, m_end, m_maxZeroAreaStart, m_start, m_zeroAreaEnd, m_zeroAreaStart, NS_ASSERT, NS_LOG_FUNCTION, and Recycle().

Referenced by AddAtEnd(), ns3::Packet::AddAtEnd(), ns3::dsr::DsrOptionField::AddDsrOption(), ns3::OptionField::AddOption(), ns3::Packet::AddPaddingAtEnd(), ns3::Packet::AddTrailer(), CreateFullCopy(), Deserialize(), ns3::dsr::DsrFsHeader::Deserialize(), ns3::dsr::DsrOptionField::Deserialize(), ns3::dsr::DsrOptionHeader::Deserialize(), ns3::dsr::DsrOptionRerrHeader::Deserialize(), ns3::Ipv6ExtensionHeader::Deserialize(), ns3::Ipv6OptionHeader::Deserialize(), ns3::OptionField::Deserialize(), ns3::WifiInformationElement::DoDeserialize(), BufferTest::DoRun(), ns3::WifiInformationElement::operator==(), and ns3::Asn1Header::WriteOctet().

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

◆ AddAtStart()

void ns3::Buffer::AddAtStart ( uint32_t start)
Parameters
startsize to reserve

Add bytes at the start of the Buffer. The content of these bytes is undefined but debugging builds initialize them to 0x33. Any call to this method invalidates any Iterator pointing to this Buffer.

Definition at line 303 of file buffer.cc.

References CheckInternalState(), Create(), GetInternalSize(), LOG_INTERNAL_STATE, ns3::Buffer::Data::m_count, ns3::Buffer::Data::m_data, m_data, ns3::Buffer::Data::m_dirtyEnd, ns3::Buffer::Data::m_dirtyStart, m_end, m_maxZeroAreaStart, m_start, m_zeroAreaEnd, m_zeroAreaStart, NS_ASSERT, NS_LOG_FUNCTION, and Recycle().

Referenced by ns3::Packet::Packet(), PbbTestCase::PbbTestCase(), ns3::Packet::AddHeader(), ns3::TcpHeader::CalculateHeaderChecksum(), ns3::UdpHeader::CalculateHeaderChecksum(), ns3::Icmpv6Header::CalculatePseudoHeaderChecksum(), TcpHeaderWithRFC793OptionTestCase::CheckCorrectDeserialize(), TcpHeaderWithRFC793OptionTestCase::CheckNoPadding(), TimInformationElementTest::CheckSerializationAgainstBuffer(), ns3::SixLowPanNetDevice::CompressLowPanNhc(), CreateFullCopy(), ns3::SixLowPanNetDevice::DecompressLowPanNhc(), Deserialize(), ns3::PbbTlv::Deserialize(), ns3::WifiInformationElement::DoDeserialize(), BasicMultiLinkElementTest::DoRun(), BufferTest::DoRun(), DsrFsHeaderTest::DoRun(), HeaderTest::DoRun(), TcpHeaderGetSetTestCase::DoRun(), TestEmptyOptionField::DoRun(), TestFulfilledAlignment::DoRun(), TestOptionWithAlignment::DoRun(), TestOptionWithoutAlignment::DoRun(), TcpHeaderWithRFC793OptionTestCase::OneOptionAtTime(), ns3::Ipv6ExtensionLooseRouting::Process(), ns3::Icmpv6DestinationUnreachable::Serialize(), ns3::Icmpv6ParameterError::Serialize(), ns3::Icmpv6TimeExceeded::Serialize(), ns3::Icmpv6TooBig::Serialize(), ns3::WifiInformationElement::SerializeFragments(), WifiEhtCapabilitiesIeTest::SerializeIntoBuffer(), WifiIeFragmentationTest::SerializeIntoBuffer(), ns3::PbbTlv::SetValue(), ns3::HeaderSerializationTestCase::TestHeaderSerialization(), PbbTestCase::TestSerialize(), TcpOptionTSTestCase::TestSerialize(), TcpOptionWSTestCase::TestSerialize(), and ns3::PcapFile::Write().

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

◆ Allocate()

Buffer::Data * ns3::Buffer::Allocate ( uint32_t reqSize)
staticprivate

Allocate a buffer data storage.

Parameters
reqSizethe storage size to create
Returns
a pointer to the allocated buffer storage

Definition at line 155 of file buffer.cc.

References ns3::ALLOC_OVER_PROVISION, data, NS_ASSERT, and NS_LOG_FUNCTION.

Referenced by Create().

+ Here is the caller graph for this function:

◆ Begin()

Buffer::Iterator ns3::Buffer::Begin ( ) const
inline
Returns
an Iterator which points to the start of this Buffer.

Definition at line 1063 of file buffer.h.

References CheckInternalState(), and NS_ASSERT.

Referenced by ns3::Packet::Packet(), PbbTestCase::PbbTestCase(), AddAtEnd(), ns3::Packet::AddHeader(), ns3::TcpHeader::CalculateHeaderChecksum(), ns3::UdpHeader::CalculateHeaderChecksum(), ns3::Icmpv6Header::CalculatePseudoHeaderChecksum(), TcpHeaderWithRFC793OptionTestCase::CheckCorrectDeserialize(), TcpHeaderWithRFC793OptionTestCase::CheckNoPadding(), TimInformationElementTest::CheckSerializationAgainstBuffer(), WifiEhtCapabilitiesIeTest::CheckSerializedByte(), WifiIeFragmentationTest::CheckSerializedByte(), ns3::SixLowPanNetDevice::CompressLowPanNhc(), CreateFullCopy(), ns3::SixLowPanNetDevice::DecompressLowPanNhc(), Deserialize(), ns3::dsr::DsrFsHeader::Deserialize(), ns3::dsr::DsrOptionField::Deserialize(), ns3::dsr::DsrOptionHeader::Deserialize(), ns3::dsr::DsrOptionRerrHeader::Deserialize(), ns3::Ipv6ExtensionHeader::Deserialize(), ns3::Ipv6OptionHeader::Deserialize(), ns3::OptionField::Deserialize(), ns3::PbbTlv::Deserialize(), ns3::WifiInformationElement::DoDeserialize(), BasicMultiLinkElementTest::DoRun(), BufferTest::DoRun(), DsrFsHeaderTest::DoRun(), HeaderTest::DoRun(), TcpHeaderGetSetTestCase::DoRun(), TestEmptyOptionField::DoRun(), TestFulfilledAlignment::DoRun(), TestOptionWithAlignment::DoRun(), TestOptionWithoutAlignment::DoRun(), TcpHeaderWithRFC793OptionTestCase::OneOptionAtTime(), ns3::WifiInformationElement::operator==(), ns3::Packet::PeekHeader(), ns3::Packet::PeekHeader(), ns3::Ipv6ExtensionLooseRouting::Process(), ns3::Packet::RemoveHeader(), ns3::Packet::RemoveHeader(), ns3::Asn1Header::Serialize(), ns3::dsr::DsrOptionField::Serialize(), ns3::dsr::DsrOptionHeader::Serialize(), ns3::dsr::DsrOptionRerrHeader::Serialize(), ns3::Icmpv6DestinationUnreachable::Serialize(), ns3::Icmpv6ParameterError::Serialize(), ns3::Icmpv6TimeExceeded::Serialize(), ns3::Icmpv6TooBig::Serialize(), ns3::Ipv6OptionHeader::Serialize(), ns3::OptionField::Serialize(), ns3::WifiInformationElement::SerializeFragments(), WifiEhtCapabilitiesIeTest::SerializeIntoBuffer(), WifiIeFragmentationTest::SerializeIntoBuffer(), ns3::PbbTlv::SetValue(), PbbTestCase::TestDeserialize(), TcpOptionTSTestCase::TestDeserialize(), TcpOptionWSTestCase::TestDeserialize(), ns3::HeaderSerializationTestCase::TestHeaderSerialization(), PbbTestCase::TestSerialize(), TcpOptionTSTestCase::TestSerialize(), TcpOptionWSTestCase::TestSerialize(), and ns3::PcapFile::Write().

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

◆ CheckInternalState()

bool ns3::Buffer::CheckInternalState ( ) const
private

Checks the internal buffer structures consistency.

Used only for debugging purposes.

Returns
true if the buffer status is consistent.

Definition at line 203 of file buffer.cc.

References LOG_INTERNAL_STATE, ns3::Buffer::Data::m_count, m_data, ns3::Buffer::Data::m_dirtyEnd, ns3::Buffer::Data::m_dirtyStart, m_end, ns3::Buffer::Data::m_size, m_start, m_zeroAreaEnd, m_zeroAreaStart, and NS_LOG_FUNCTION.

Referenced by Buffer(), ~Buffer(), AddAtEnd(), AddAtEnd(), AddAtStart(), Begin(), CreateFragment(), CreateFullCopy(), End(), Initialize(), operator=(), PeekData(), RemoveAtEnd(), RemoveAtStart(), and TransformIntoRealBuffer().

+ Here is the caller graph for this function:

◆ CopyData() [1/2]

void ns3::Buffer::CopyData ( std::ostream * os,
uint32_t size ) const

Copy the specified amount of data from the buffer to the given output stream.

Parameters
osthe output stream
sizethe maximum amount of bytes to copy. If zero, nothing is copied.

Definition at line 702 of file buffer.cc.

References anonymous_namespace{buffer.cc}::Zeroes::buffer, ns3::Buffer::Data::m_data, m_data, m_end, m_start, m_zeroAreaEnd, m_zeroAreaStart, NS_LOG_FUNCTION, and anonymous_namespace{buffer.cc}::Zeroes::size.

Referenced by ns3::Packet::CopyData(), ns3::Packet::CopyData(), BufferTest::DoRun(), and ns3::PcapFile::Write().

+ Here is the caller graph for this function:

◆ CopyData() [2/2]

uint32_t ns3::Buffer::CopyData ( uint8_t * buffer,
uint32_t size ) const

Copy the specified amount of data from the buffer to the given buffer.

Parameters
bufferthe output buffer
sizethe maximum amount of bytes to copy. If zero, nothing is copied.
Returns
the amount of bytes copied

Definition at line 731 of file buffer.cc.

References anonymous_namespace{buffer.cc}::Zeroes::buffer, ns3::Buffer::Data::m_data, m_data, m_end, m_start, m_zeroAreaEnd, m_zeroAreaStart, NS_LOG_FUNCTION, and anonymous_namespace{buffer.cc}::Zeroes::size.

◆ Create()

Buffer::Data * ns3::Buffer::Create ( uint32_t size)
staticprivate

Create a buffer data storage.

Parameters
sizethe storage size to create
Returns
a pointer to the created buffer storage

Definition at line 109 of file buffer.cc.

References Allocate(), data, Deallocate(), g_freeList, IS_INITIALIZED, IS_UNINITIALIZED, NS_ASSERT, and NS_LOG_FUNCTION.

Referenced by AddAtEnd(), AddAtStart(), and Initialize().

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

◆ CreateFragment()

Buffer ns3::Buffer::CreateFragment ( uint32_t start,
uint32_t length ) const
Parameters
startoffset from start of packet
length
Returns
a fragment of size length starting at offset start.

Definition at line 518 of file buffer.cc.

References CheckInternalState(), GetSize(), NS_ASSERT, NS_LOG_FUNCTION, RemoveAtEnd(), and RemoveAtStart().

Referenced by ns3::Packet::CreateFragment(), and BufferTest::DoRun().

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

◆ CreateFullCopy()

Buffer ns3::Buffer::CreateFullCopy ( ) const
private

Create a full copy of the buffer, including all the internal structures.

Returns
a copy of the buffer

Definition at line 530 of file buffer.cc.

References AddAtEnd(), AddAtStart(), Begin(), CheckInternalState(), End(), ns3::Buffer::Data::m_data, m_data, m_end, m_start, m_zeroAreaEnd, m_zeroAreaStart, NS_ASSERT, NS_LOG_FUNCTION, ns3::Buffer::Iterator::Prev(), ns3::Buffer::Iterator::Write(), and ns3::Buffer::Iterator::WriteU8().

Referenced by AddAtEnd(), and TransformIntoRealBuffer().

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

◆ Deallocate()

void ns3::Buffer::Deallocate ( Buffer::Data * data)
staticprivate

Deallocate the buffer memory.

Parameters
datathe buffer data storage

Definition at line 173 of file buffer.cc.

References data, NS_ASSERT, and NS_LOG_FUNCTION.

Referenced by ns3::Buffer::LocalStaticDestructor::~LocalStaticDestructor(), Create(), and Recycle().

+ Here is the caller graph for this function:

◆ Deserialize()

uint32_t ns3::Buffer::Deserialize ( const uint8_t * buffer,
uint32_t size )
Returns
zero if a complete buffer is not deserialized
Parameters
bufferpoints to buffer for deserialization
sizenumber of bytes to deserialize

The raw character buffer is deserialized and all the data is placed into this buffer.

Definition at line 637 of file buffer.cc.

References AddAtEnd(), AddAtStart(), Begin(), End(), Initialize(), NS_ASSERT, NS_LOG_FUNCTION, ns3::Buffer::Iterator::Prev(), and ns3::Buffer::Iterator::Write().

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

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

◆ End()

Buffer::Iterator ns3::Buffer::End ( ) const
inline
Returns
an Iterator which points to the end of this Buffer.

Definition at line 1070 of file buffer.h.

References CheckInternalState(), and NS_ASSERT.

Referenced by AddAtEnd(), ns3::dsr::DsrOptionField::AddDsrOption(), ns3::OptionField::AddOption(), ns3::Packet::AddTrailer(), CreateFullCopy(), Deserialize(), BufferTest::DoRun(), ns3::Packet::PeekTrailer(), ns3::Packet::RemoveTrailer(), ns3::Asn1Header::Serialize(), ns3::dsr::DsrOptionField::Serialize(), ns3::dsr::DsrOptionHeader::Serialize(), ns3::dsr::DsrOptionRerrHeader::Serialize(), ns3::Ipv6OptionHeader::Serialize(), ns3::OptionField::Serialize(), and ns3::Asn1Header::WriteOctet().

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

◆ GetInternalEnd()

uint32_t ns3::Buffer::GetInternalEnd ( ) const
private

Get the buffer end position.

Returns
the buffer end index.

Definition at line 296 of file buffer.cc.

References m_end, m_zeroAreaEnd, m_zeroAreaStart, and NS_LOG_FUNCTION.

Referenced by AddAtEnd().

+ Here is the caller graph for this function:

◆ GetInternalSize()

uint32_t ns3::Buffer::GetInternalSize ( ) const
private

Get the buffer real size.

Warning
The real size is the actual memory used by the buffer.
Returns
the memory used by the buffer.

Definition at line 289 of file buffer.cc.

References m_end, m_start, m_zeroAreaEnd, m_zeroAreaStart, and NS_LOG_FUNCTION.

Referenced by AddAtEnd(), and AddAtStart().

+ Here is the caller graph for this function:

◆ GetSerializedSize()

uint32_t ns3::Buffer::GetSerializedSize ( ) const

Return the number of bytes required for serialization.

Returns
the number of bytes.

Definition at line 555 of file buffer.cc.

References m_end, m_start, m_zeroAreaEnd, m_zeroAreaStart, and NS_LOG_FUNCTION.

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

+ Here is the caller graph for this function:

◆ GetSize()

◆ Initialize()

void ns3::Buffer::Initialize ( uint32_t zeroSize)
private

Initializes the buffer with a number of zeroes.

Parameters
zeroSizethe zeroes size

Definition at line 237 of file buffer.cc.

References CheckInternalState(), Create(), g_recommendedStart, m_data, ns3::Buffer::Data::m_dirtyEnd, ns3::Buffer::Data::m_dirtyStart, m_end, m_maxZeroAreaStart, ns3::Buffer::Data::m_size, m_start, m_zeroAreaEnd, m_zeroAreaStart, NS_ASSERT, and NS_LOG_FUNCTION.

Referenced by Buffer(), Buffer(), Buffer(), and Deserialize().

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

◆ operator=()

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

Assignment operator.

Parameters
othe buffer to copy
Returns
a reference to the buffer

Definition at line 252 of file buffer.cc.

References CheckInternalState(), g_recommendedStart, ns3::Buffer::Data::m_count, m_data, m_end, m_maxZeroAreaStart, m_start, m_zeroAreaEnd, m_zeroAreaStart, NS_ASSERT, and Recycle().

+ Here is the call graph for this function:

◆ PeekData()

const uint8_t * ns3::Buffer::PeekData ( ) const
Returns
a pointer to the start of the internal byte buffer.

The returned pointer points to an area of memory which is ns3::Buffer::GetSize () bytes big. Please, try to never ever use this method. It is really evil and is present only for a few specific uses.

Definition at line 692 of file buffer.cc.

References CheckInternalState(), ns3::Buffer::Data::m_data, m_data, m_start, NS_ASSERT, NS_LOG_FUNCTION, and TransformIntoRealBuffer().

Referenced by ns3::SixLowPanNetDevice::CompressLowPanNhc(), BufferTest::DoRun(), DsrFsHeaderTest::DoRun(), TestEmptyOptionField::DoRun(), TestFulfilledAlignment::DoRun(), TestOptionWithAlignment::DoRun(), TestOptionWithoutAlignment::DoRun(), BufferTest::EnsureWrittenBytes(), ns3::PbbTlv::operator==(), ns3::WifiInformationElement::operator==(), ns3::dsr::DsrFsHeader::Serialize(), ns3::Ipv6ExtensionHeader::Serialize(), and PbbTestCase::TestSerialize().

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

◆ Recycle()

void ns3::Buffer::Recycle ( Buffer::Data * data)
staticprivate

Recycle the buffer memory.

Parameters
datathe buffer data storage

Definition at line 90 of file buffer.cc.

References data, Deallocate(), g_freeList, g_maxSize, IS_DESTROYED, IS_INITIALIZED, IS_UNINITIALIZED, NS_ASSERT, and NS_LOG_FUNCTION.

Referenced by ~Buffer(), AddAtEnd(), AddAtStart(), and operator=().

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

◆ RemoveAtEnd()

void ns3::Buffer::RemoveAtEnd ( uint32_t end)
Parameters
endsize to remove

Remove bytes at the end of the Buffer. Any call to this method invalidates any Iterator pointing to this Buffer.

Definition at line 482 of file buffer.cc.

References CheckInternalState(), LOG_INTERNAL_STATE, m_end, m_maxZeroAreaStart, m_start, m_zeroAreaEnd, m_zeroAreaStart, NS_ASSERT, and NS_LOG_FUNCTION.

Referenced by ns3::PbbTlv::~PbbTlv(), CreateFragment(), ns3::dsr::DsrFsHeader::Deserialize(), ns3::Ipv6ExtensionHeader::Deserialize(), BufferTest::DoRun(), ns3::Packet::RemoveAtEnd(), and ns3::Packet::RemoveTrailer().

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

◆ RemoveAtStart()

void ns3::Buffer::RemoveAtStart ( uint32_t start)
Parameters
startsize to remove

Remove bytes at the start of the Buffer. Any call to this method invalidates any Iterator pointing to this Buffer.

Definition at line 436 of file buffer.cc.

References CheckInternalState(), LOG_INTERNAL_STATE, m_end, m_maxZeroAreaStart, m_start, m_zeroAreaEnd, m_zeroAreaStart, NS_ASSERT, and NS_LOG_FUNCTION.

Referenced by ns3::SixLowPanNetDevice::CompressLowPanNhc(), CreateFragment(), BufferTest::DoRun(), ns3::Packet::RemoveAtStart(), ns3::Packet::RemoveHeader(), and ns3::Packet::RemoveHeader().

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

◆ Serialize()

uint32_t ns3::Buffer::Serialize ( uint8_t * buffer,
uint32_t maxSize ) const
Returns
zero if buffer not large enough
Parameters
bufferpoints to serialization buffer
maxSizemax number of bytes to write

This buffer's contents are serialized into the raw character buffer parameter. Note: The zero length data is not copied entirely. Only the length of zero byte data is serialized.

Definition at line 571 of file buffer.cc.

References ns3::Buffer::Data::m_data, m_data, m_end, m_start, m_zeroAreaEnd, m_zeroAreaStart, and NS_LOG_FUNCTION.

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

+ Here is the caller graph for this function:

◆ TransformIntoRealBuffer()

void ns3::Buffer::TransformIntoRealBuffer ( ) const
private

Transform a "Virtual byte buffer" into a "Real byte buffer".

Definition at line 682 of file buffer.cc.

References CheckInternalState(), CreateFullCopy(), NS_ASSERT, and NS_LOG_FUNCTION.

Referenced by PeekData().

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

Member Data Documentation

◆ g_freeList

Buffer::FreeList * ns3::Buffer::g_freeList = nullptr
staticprivate

Buffer data container.

Definition at line 795 of file buffer.h.

Referenced by ns3::Buffer::LocalStaticDestructor::~LocalStaticDestructor(), Create(), and Recycle().

◆ g_localStaticDestructor

Buffer::LocalStaticDestructor ns3::Buffer::g_localStaticDestructor
staticprivate

Local static destructor.

Definition at line 796 of file buffer.h.

◆ g_maxSize

uint32_t ns3::Buffer::g_maxSize = 0
staticprivate

Max observed data size.

Definition at line 794 of file buffer.h.

Referenced by Recycle().

◆ g_recommendedStart

uint32_t ns3::Buffer::g_recommendedStart = 0
staticprivate

location in a newly-allocated buffer where you should start writing data.

i.e., m_start should be initialized to this value.

Definition at line 761 of file buffer.h.

Referenced by ~Buffer(), Initialize(), and operator=().

◆ m_data

◆ m_end

uint32_t ns3::Buffer::m_end
private

offset to the end of the data referenced by this Buffer instance from the start of m_data->m_data

Definition at line 782 of file buffer.h.

Referenced by AddAtEnd(), AddAtEnd(), AddAtStart(), CheckInternalState(), ns3::Buffer::Iterator::Construct(), CopyData(), CopyData(), CreateFullCopy(), GetInternalEnd(), GetInternalSize(), GetSerializedSize(), GetSize(), Initialize(), operator=(), RemoveAtEnd(), RemoveAtStart(), and Serialize().

◆ m_maxZeroAreaStart

uint32_t ns3::Buffer::m_maxZeroAreaStart
private

keep track of the maximum value of m_zeroAreaStart across the lifetime of a Buffer instance.

This variable is used purely as a source of information for the heuristics which decide on the position of the zero area in new buffers. It is read from the Buffer destructor to update the global heuristic data and these global heuristic data are used from the Buffer constructor to choose an initial value for m_zeroAreaStart.

Definition at line 755 of file buffer.h.

Referenced by ~Buffer(), AddAtEnd(), AddAtStart(), Initialize(), operator=(), RemoveAtEnd(), and RemoveAtStart().

◆ m_start

uint32_t ns3::Buffer::m_start
private

offset to the start of the data referenced by this Buffer instance from the start of m_data->m_data

Definition at line 777 of file buffer.h.

Referenced by AddAtEnd(), AddAtEnd(), AddAtStart(), CheckInternalState(), ns3::Buffer::Iterator::Construct(), CopyData(), CopyData(), CreateFullCopy(), GetInternalSize(), GetSerializedSize(), GetSize(), Initialize(), operator=(), PeekData(), RemoveAtEnd(), RemoveAtStart(), and Serialize().

◆ m_zeroAreaEnd

uint32_t ns3::Buffer::m_zeroAreaEnd
private

◆ m_zeroAreaStart

uint32_t ns3::Buffer::m_zeroAreaStart
private

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