ns3::Buffer Class Reference
[Packet]

automatically resized byte buffer More...

#include <buffer.h>

Collaboration diagram for ns3::Buffer:
Collaboration graph
[legend]

List of all members.

Classes

class  Iterator
 iterator in a Buffer instance More...

Public Member Functions

uint32_t GetSize (void) const
uint8_t const * PeekData (void) const
bool AddAtStart (uint32_t start)
bool AddAtEnd (uint32_t end)
void AddAtEnd (const Buffer &o)
void RemoveAtStart (uint32_t start)
void RemoveAtEnd (uint32_t end)
Buffer CreateFragment (uint32_t start, uint32_t length) const
Buffer::Iterator Begin (void) const
Buffer::Iterator End (void) const
Buffer CreateFullCopy (void) const
int32_t GetCurrentStartOffset (void) const
int32_t GetCurrentEndOffset (void) const
 Buffer (Buffer const &o)
Bufferoperator= (Buffer const &o)
 Buffer ()
 Buffer (uint32_t dataSize)
 ~Buffer ()

Private Member Functions

void TransformIntoRealBuffer (void) const
bool CheckInternalState (void) const
void Initialize (uint32_t zeroSize)
uint32_t GetInternalSize (void) const
uint32_t GetInternalEnd (void) const

Static Private Member Functions

static void Recycle (struct BufferData *data)
static struct BufferDataCreate (uint32_t size)

Private Attributes

struct BufferDatam_data
uint32_t m_zeroAreaStart
uint32_t m_zeroAreaEnd
uint32_t m_start
uint32_t m_end

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.

Definition at line 96 of file buffer.h.


Constructor & Destructor Documentation

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

Definition at line 204 of file buffer.cc.

References Initialize(), and NS_LOG_FUNCTION.

ns3::Buffer::Buffer ( uint32_t  dataSize  ) 

Definition at line 210 of file buffer.cc.

References Initialize(), and NS_LOG_FUNCTION.

ns3::Buffer::~Buffer (  ) 

Member Function Documentation

void ns3::Buffer::AddAtEnd ( const Buffer o  ) 
Parameters:
o the 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 457 of file buffer.cc.

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

bool ns3::Buffer::AddAtEnd ( uint32_t  end  ) 
Parameters:
end size to reserve
Returns:
true if the buffer needed resizing, false otherwise.

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 400 of file buffer.cc.

References CheckInternalState(), Create(), ns3::g_nAddNoRealloc, ns3::g_nAddRealloc, GetInternalEnd(), GetInternalSize(), HEURISTICS, LOG_INTERNAL_STATE, ns3::BufferData::m_count, ns3::BufferData::m_data, m_data, ns3::BufferData::m_dirtyEnd, ns3::BufferData::m_dirtyStart, m_end, m_start, m_zeroAreaEnd, m_zeroAreaStart, NS_ASSERT, NS_LOG_FUNCTION, and Recycle().

Referenced by ns3::Packet::AddAtEnd(), AddAtEnd(), ns3::Packet::AddPaddingAtEnd(), ns3::Packet::AddTrailer(), CreateFullCopy(), ns3::BufferTest::RunTests(), and ns3::Packet::Serialize().

bool ns3::Buffer::AddAtStart ( uint32_t  start  ) 
Parameters:
start size to reserve
Returns:
true if the buffer needed resizing, false otherwise.

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 347 of file buffer.cc.

References CheckInternalState(), Create(), ns3::g_nAddNoRealloc, ns3::g_nAddRealloc, GetInternalSize(), HEURISTICS, LOG_INTERNAL_STATE, ns3::BufferData::m_count, ns3::BufferData::m_data, m_data, ns3::BufferData::m_dirtyEnd, ns3::BufferData::m_dirtyStart, m_end, m_start, m_zeroAreaEnd, m_zeroAreaStart, NS_ASSERT, NS_LOG_FUNCTION, and Recycle().

Referenced by ns3::Packet::AddHeader(), CreateFullCopy(), ns3::Packet::Packet(), ns3::BufferTest::RunTests(), and ns3::Packet::Serialize().

Buffer::Iterator ns3::Buffer::Begin ( void   )  const
bool ns3::Buffer::CheckInternalState ( void   )  const [private]
BufferData * ns3::Buffer::Create ( uint32_t  size  )  [static, read, private]
Buffer ns3::Buffer::CreateFragment ( uint32_t  start,
uint32_t  length 
) const
Parameters:
start offset from start of packet
length 
Returns:
a fragment of size length starting at offset start.

Definition at line 579 of file buffer.cc.

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

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

Buffer ns3::Buffer::CreateFullCopy ( void   )  const
Buffer::Iterator ns3::Buffer::End ( void   )  const
int32_t ns3::Buffer::GetCurrentEndOffset ( void   )  const
int32_t ns3::Buffer::GetCurrentStartOffset ( void   )  const
uint32_t ns3::Buffer::GetInternalEnd ( void   )  const [private]

Definition at line 341 of file buffer.cc.

References m_end, m_zeroAreaEnd, and m_zeroAreaStart.

Referenced by AddAtEnd().

uint32_t ns3::Buffer::GetInternalSize ( void   )  const [private]

Definition at line 336 of file buffer.cc.

References m_end, m_start, m_zeroAreaEnd, and m_zeroAreaStart.

Referenced by AddAtEnd(), and AddAtStart().

uint32_t ns3::Buffer::GetSize ( void   )  const
void ns3::Buffer::Initialize ( uint32_t  zeroSize  )  [private]
Buffer & ns3::Buffer::operator= ( Buffer const &  o  ) 
uint8_t const * ns3::Buffer::PeekData ( void   )  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 638 of file buffer.cc.

References CheckInternalState(), ns3::BufferData::m_data, m_data, m_start, NS_ASSERT, and TransformIntoRealBuffer().

Referenced by ns3::BufferTest::EnsureWrittenBytes(), ns3::Packet::PeekData(), and ns3::BufferTest::RunTests().

void ns3::Buffer::Recycle ( struct BufferData data  )  [static, private]
void ns3::Buffer::RemoveAtEnd ( uint32_t  end  ) 
Parameters:
end size 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 543 of file buffer.cc.

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

Referenced by CreateFragment(), ns3::Packet::Deserialize(), ns3::PacketMetadata::ItemIterator::Next(), ns3::Packet::RemoveAtEnd(), ns3::Packet::RemoveTrailer(), and ns3::BufferTest::RunTests().

void ns3::Buffer::RemoveAtStart ( uint32_t  start  ) 
Parameters:
start size 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 498 of file buffer.cc.

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

Referenced by CreateFragment(), ns3::Packet::Deserialize(), ns3::PacketMetadata::ItemIterator::Next(), ns3::Packet::RemoveAtStart(), ns3::Packet::RemoveHeader(), and ns3::BufferTest::RunTests().

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

Definition at line 628 of file buffer.cc.

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

Referenced by PeekData().


Member Data Documentation

struct BufferData* ns3::Buffer::m_data [private]
uint32_t ns3::Buffer::m_end [private]
uint32_t ns3::Buffer::m_start [private]
uint32_t ns3::Buffer::m_zeroAreaEnd [private]
uint32_t ns3::Buffer::m_zeroAreaStart [private]

The documentation for this class was generated from the following files:
Generated on Thu Dec 3 14:09:55 2009 for NS-3 by  doxygen 1.6.3