[Doxygen] network module

This commit is contained in:
Tommaso Pecorella
2014-03-13 09:29:47 +01:00
parent 4517c16fe7
commit 19db0e31cb
70 changed files with 2448 additions and 522 deletions

View File

@@ -25,7 +25,7 @@
#include <ostream>
#include "ns3/assert.h"
#define noBUFFER_FREE_LIST 1
#define BUFFER_FREE_LIST 1
namespace ns3 {
@@ -80,7 +80,7 @@ namespace ns3 {
* |--------^ m_start
* |-------------------^ m_zeroAreaStart
* |-----------------------------^ m_end - (m_zeroAreaEnd - m_zeroAreaStart)
* virtual byte buffer: |xxxxxxxxxxxx0000000000000.........|
* Virtual byte buffer: |xxxxxxxxxxxx0000000000000.........|
* |--------^ m_start
* |--------------------^ m_zeroAreaStart
* |---------------------------------^ m_zeroAreaEnd
@@ -378,37 +378,101 @@ public:
private:
friend class Buffer;
/**
* Constructor - initializes the iterator to point to the buffer start
*
* \param buffer the buffer this iterator refers to
*/
inline Iterator (Buffer const*buffer);
inline Iterator (Buffer const*buffer, bool);
/**
* Constructor - initializes the iterator to point to the buffer end
*
* \param buffer the buffer this iterator refers to
* \param dummy not used param
*/
inline Iterator (Buffer const*buffer, bool dummy);
/**
* Initializes the iterator values
*
* \param buffer the buffer this iterator refers to
*/
inline void Construct (const Buffer *buffer);
/**
* Checks that the [start, end) is not in the "virtual zero area".
*
* \param start start buffer position
* \param end end buffer position
* \returns true if [start, end) is not in the "virtual zero area".
*/
bool CheckNoZero (uint32_t start, uint32_t end) const;
/**
* Checks that the buffer position is not in the "virtual zero area".
*
* \param i buffer position
* \returns true if not in the "virtual zero area".
*/
bool Check (uint32_t i) const;
/**
* \return the two bytes read in the buffer.
*
* Read data and advance the Iterator by the number of bytes
* read.
* The data is read in network format and return in host format.
*
* \warning this is the slow version, please use ReadNtohU16 (void)
*/
uint16_t SlowReadNtohU16 (void);
/**
* \return the four bytes read in the buffer.
*
* Read data and advance the Iterator by the number of bytes
* read.
* The data is read in network format and return in host format.
*
* \warning this is the slow version, please use ReadNtohU32 (void)
*/
uint32_t SlowReadNtohU32 (void);
/**
* \brief Returns an appropriate message indicating a read error
* \returns the error message
*/
std::string GetReadErrorMessage (void) const;
/**
* \brief Returns an appropriate message indicating a write error
*
* The message depends on the actual Buffer::Iterator status.
*
* \returns the error message
*/
std::string GetWriteErrorMessage (void) const;
/* offset in virtual bytes from the start of the data buffer to the
/**
* offset in virtual bytes from the start of the data buffer to the
* start of the "virtual zero area".
*/
uint32_t m_zeroStart;
/* offset in virtual bytes from the start of the data buffer to the
/**
* offset in virtual bytes from the start of the data buffer to the
* end of the "virtual zero area".
*/
uint32_t m_zeroEnd;
/* offset in virtual bytes from the start of the data buffer to the
/**
* offset in virtual bytes from the start of the data buffer to the
* start of the data which can be read by this iterator
*/
uint32_t m_dataStart;
/* offset in virtual bytes from the start of the data buffer to the
/**
* offset in virtual bytes from the start of the data buffer to the
* end of the data which can be read by this iterator
*/
uint32_t m_dataEnd;
/* offset in virtual bytes from the start of the data buffer to the
/**
* offset in virtual bytes from the start of the data buffer to the
* current position represented by this iterator.
*/
uint32_t m_current;
/* a pointer to the underlying byte buffer. All offsets are relative
/**
* a pointer to the underlying byte buffer. All offsets are relative
* to this pointer.
*/
uint8_t *m_data;
@@ -498,10 +562,17 @@ private:
*/
inline Buffer::Iterator End (void) const;
/**
* \brief Create a full copy of the buffer, including
* all the internal structures.
*
* \returns a copy of the buffer
*/
Buffer CreateFullCopy (void) const;
/**
* \return the number of bytes required for serialization
* \brief Return the number of bytes required for serialization.
* \return the number of bytes.
*/
uint32_t GetSerializedSize (void) const;
@@ -527,7 +598,15 @@ private:
*/
uint32_t Deserialize (const uint8_t* buffer, uint32_t size);
/**
* \brief Returns the current buffer start offset
* \return the offset
*/
int32_t GetCurrentStartOffset (void) const;
/**
* \brief Returns the current buffer end offset
* \return the offset
*/
int32_t GetCurrentEndOffset (void) const;
/**
@@ -538,12 +617,44 @@ private:
*/
void CopyData (std::ostream *os, uint32_t size) const;
/**
* Copy the specified amount of data from the buffer to the given buffer.
*
* @param buffer the output buffer
* @param size the maximum amount of bytes to copy. If zero, nothing is copied.
* @returns the amount of bytes copied
*/
uint32_t CopyData (uint8_t *buffer, uint32_t size) const;
/**
* \brief Copy constructor
* \param o the buffer to copy
*/
inline Buffer (Buffer const &o);
/**
* \brief Assignment operator
* \param o the buffer to copy
* \return a reference to the buffer
*/
Buffer &operator = (Buffer const &o);
Buffer ();
/**
* \brief Constructor
*
* The buffer will be initialized with zeroes up to its size.
*
* \param dataSize the buffer size
*/
Buffer (uint32_t dataSize);
/**
* \brief Constructor
*
* If initialize is set to true, the buffer will be initialized
* with zeroes up to its size.
*
* \param dataSize the buffer size.
* \param initialize initialize the buffer with zeroes.
*/
Buffer (uint32_t dataSize, bool initialize);
~Buffer ();
private:
@@ -563,40 +674,92 @@ private:
*/
struct Data
{
/* The reference count of an instance of this data structure.
/**
* The reference count of an instance of this data structure.
* Each buffer which references an instance holds a count.
*/
*/
uint32_t m_count;
/* the size of the m_data field below.
/**
* the size of the m_data field below.
*/
uint32_t m_size;
/* offset from the start of the m_data field below to the
/**
* offset from the start of the m_data field below to the
* start of the area in which user bytes were written.
*/
uint32_t m_dirtyStart;
/* offset from the start of the m_data field below to the
/**
* offset from the start of the m_data field below to the
* end of the area in which user bytes were written.
*/
uint32_t m_dirtyEnd;
/* The real data buffer holds _at least_ one byte.
/**
* The real data buffer holds _at least_ one byte.
* Its real size is stored in the m_size field.
*/
uint8_t m_data[1];
};
/**
* \brief Transform a "Virtual byte buffer" into a "Real byte buffer"
*/
void TransformIntoRealBuffer (void) const;
/**
* \brief Checks the internal buffer structures consistency
*
* Used only for debugging purposes.
*
* \returns true if the buffer status is consistent.
*/
bool CheckInternalState (void) const;
/**
* \brief Initializes the buffer with a number of zeroes.
*
* \param zeroSize the zeroes size
*/
void Initialize (uint32_t zeroSize);
/**
* \brief Get the buffer real size.
* \warning The real size is the actual memory used by the buffer.
* \returns the memory used by the buffer.
*/
uint32_t GetInternalSize (void) const;
/**
* \brief Get the buffer end position.
* \returns the buffer end index.
*/
uint32_t GetInternalEnd (void) const;
/**
* \brief Recycle the buffer memory
* \param data the buffer data storage
*/
static void Recycle (struct Buffer::Data *data);
/**
* \brief Create a buffer data storage
* \param size the storage size to create
* \returns a pointer to the created buffer storage
*/
static struct Buffer::Data *Create (uint32_t size);
/**
* \brief Allocate a buffer data storage
* \param reqSize the storage size to create
* \returns a pointer to the allocated buffer storage
*/
static struct Buffer::Data *Allocate (uint32_t reqSize);
/**
* \brief Deallocate the buffer memory
* \param data the buffer data storage
*/
static void Deallocate (struct Buffer::Data *data);
struct Data *m_data;
struct Data *m_data; //!< the buffer data storage
/* keep track of the maximum value of m_zeroAreaStart across
/**
* 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.
@@ -613,32 +776,38 @@ private:
*/
static uint32_t g_recommendedStart;
/* offset to the start of the virtual zero area from the start
/**
* offset to the start of the virtual zero area from the start
* of m_data->m_data
*/
uint32_t m_zeroAreaStart;
/* offset to the end of the virtual zero area from the start
/**
* offset to the end of the virtual zero area from the start
* of m_data->m_data
*/
uint32_t m_zeroAreaEnd;
/* offset to the start of the data referenced by this Buffer
/**
* offset to the start of the data referenced by this Buffer
* instance from the start of m_data->m_data
*/
uint32_t m_start;
/* offset to the end of the data referenced by this Buffer
/**
* offset to the end of the data referenced by this Buffer
* instance from the start of m_data->m_data
*/
uint32_t m_end;
#ifdef BUFFER_FREE_LIST
/// Container for buffer data
typedef std::vector<struct Buffer::Data*> FreeList;
/// Local static destructor structure
struct LocalStaticDestructor
{
~LocalStaticDestructor ();
};
static uint32_t g_maxSize;
static FreeList *g_freeList;
static struct LocalStaticDestructor g_localStaticDestructor;
static uint32_t g_maxSize; //!< Max observed data size
static FreeList *g_freeList; //!< Buffer data container
static struct LocalStaticDestructor g_localStaticDestructor; //!< Local static destructor
#endif
};