A Discrete-Event Network Simulator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ns3::PacketMetadata Class Reference

handle packet metadata about packet headers and trailers More...

#include <packet-metadata.h>


struct  Data
class  DataFreeList
struct  ExtraItem
struct  Item
class  ItemIterator
struct  SmallItem

Public Member Functions

 PacketMetadata (uint64_t uid, uint32_t size)
 PacketMetadata (PacketMetadata const &o)
void AddAtEnd (PacketMetadata const &o)
void AddHeader (Header const &header, uint32_t size)
void AddPaddingAtEnd (uint32_t end)
void AddTrailer (Trailer const &trailer, uint32_t size)
ItemIterator BeginItem (Buffer buffer) const
PacketMetadata CreateFragment (uint32_t start, uint32_t end) const
uint32_t Deserialize (const uint8_t *buffer, uint32_t size)
uint32_t GetSerializedSize (void) const
uint64_t GetUid (void) const
PacketMetadataoperator= (PacketMetadata const &o)
void RemoveAtEnd (uint32_t end)
void RemoveAtStart (uint32_t start)
void RemoveHeader (Header const &header, uint32_t size)
void RemoveTrailer (Trailer const &trailer, uint32_t size)
uint32_t Serialize (uint8_t *buffer, uint32_t maxSize) const

Static Public Member Functions

static void Enable (void)
static void EnableChecking (void)

Private Member Functions

uint16_t AddBig (uint32_t head, uint32_t tail, const PacketMetadata::SmallItem *item, const PacketMetadata::ExtraItem *extraItem)
uint16_t AddSmall (const PacketMetadata::SmallItem *item)
void Append16 (uint16_t value, uint8_t *buffer)
void Append32 (uint32_t value, uint8_t *buffer)
void AppendValue (uint32_t value, uint8_t *buffer)
void AppendValueExtra (uint32_t value, uint8_t *buffer)
void DoAddHeader (uint32_t uid, uint32_t size)
uint32_t GetTotalSize (void) const
uint32_t GetUleb128Size (uint32_t value) const
bool IsPointerOk (uint16_t pointer) const
bool IsSharedPointerOk (uint16_t pointer) const
bool IsStateOk (void) const
uint32_t ReadItems (uint16_t current, struct PacketMetadata::SmallItem *item, struct PacketMetadata::ExtraItem *extraItem) const
uint32_t ReadUleb128 (const uint8_t **pBuffer) const
void ReplaceTail (PacketMetadata::SmallItem *item, PacketMetadata::ExtraItem *extraItem, uint32_t available)
void Reserve (uint32_t n)
void ReserveCopy (uint32_t n)
void UpdateHead (uint16_t written)
void UpdateTail (uint16_t written)

Static Private Member Functions

static uint8_t * AddToRaw (const uint8_t *data, uint32_t dataSize, uint8_t *start, uint8_t *current, uint32_t maxSize)
static uint8_t * AddToRawU16 (const uint16_t &data, uint8_t *start, uint8_t *current, uint32_t maxSize)
static uint8_t * AddToRawU32 (const uint32_t &data, uint8_t *start, uint8_t *current, uint32_t maxSize)
static uint8_t * AddToRawU64 (const uint64_t &data, uint8_t *start, uint8_t *current, uint32_t maxSize)
static uint8_t * AddToRawU8 (const uint8_t &data, uint8_t *start, uint8_t *current, uint32_t maxSize)
static struct
Allocate (uint32_t n)
static struct
Create (uint32_t size)
static void Deallocate (struct PacketMetadata::Data *data)
static uint8_t * ReadFromRawU16 (uint16_t &data, const uint8_t *start, const uint8_t *current, uint32_t maxSize)
static uint8_t * ReadFromRawU32 (uint32_t &data, const uint8_t *start, const uint8_t *current, uint32_t maxSize)
static uint8_t * ReadFromRawU64 (uint64_t &data, const uint8_t *start, const uint8_t *current, uint32_t maxSize)
static uint8_t * ReadFromRawU8 (uint8_t &data, const uint8_t *start, const uint8_t *current, uint32_t maxSize)
static void Recycle (struct PacketMetadata::Data *data)

Private Attributes

struct Datam_data
uint16_t m_head
uint64_t m_packetUid
uint16_t m_tail
uint16_t m_used

Static Private Attributes

static uint16_t m_chunkUid = 0
static bool m_enable = false
static bool m_enableChecking = false
static DataFreeList m_freeList
static uint32_t m_maxSize = 0
static bool m_metadataSkipped = false


class ItemIterator

Detailed Description

handle packet metadata about packet headers and trailers

This class is used by the Packet class to record every operation performed on the packet's buffer. This class also provides an implementation of the Packet::Print methods which uses the metadata to analyse the content of the packet's buffer.

To achieve this, this class maintains a linked list of so-called "items", each of which represents a header or a trailer, or payload, or a fragment of any of these. Each item contains a "next" and a "prev" field which point to the next and previous entries in the linked list. The PacketMetadata class maintains a pair of pointers to the head and the tail of the linked list.

Each entry in the list also maintains:

  • its native size (the size it had when it was first added to the packet)
  • its type: identifies what kind of header, what kind of trailer, if it is payload or not
  • the uid of the packet to which it was first added
  • the start and end of the area represented by a fragment if it is one.

This linked list is flattened in a byte buffer stored in struct PacketMetadata::Data. Each entry of the linked list is identified by an offset which identifies the first byte of the entry from the start of the data buffer. The size of this data buffer is 2^16-1 bytes maximum which somewhat limits the number of entries which can be stored in this linked list but it is quite unlikely to hit this limit in practice.

Each item of the linked list is a variable-sized byte buffer made of a number of fields. Some of these fields are stored as fixed-size 32 bit integers, others as fixed-size 16 bit integers, and some others as variable-size 32-bit integers. The variable-size 32 bit integers are stored using the uleb128 encoding.

Definition at line 79 of file packet-metadata.h.

Member Function Documentation

PacketMetadata ns3::PacketMetadata::CreateFragment ( uint32_t  start,
uint32_t  end 
) const
startthe amount of stuff to remove from the start
endthe amount of stuff to remove from the end

Calling this method is equivalent to calling RemoveAtStart (start) and then, RemoveAtEnd (end).

Definition at line 656 of file packet-metadata.cc.


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

uint32_t ns3::PacketMetadata::ReadItems ( uint16_t  current,
struct PacketMetadata::SmallItem item,
struct PacketMetadata::ExtraItem extraItem 
) const
currentthe offset we should start reading the data from
itempointer to where we should store the data to return to the caller
extraItempointer to where we should store the data to return to the caller
the number of bytes read.

Definition at line 540 of file packet-metadata.cc.


Referenced by ReplaceTail().

void ns3::PacketMetadata::ReplaceTail ( PacketMetadata::SmallItem item,
PacketMetadata::ExtraItem extraItem,
uint32_t  available 
itemthe item data to write
extraItemthe extra item data to write
availablethe number of bytes which can be written without having to rewrite the buffer entirely.

Definition at line 457 of file packet-metadata.cc.

References m_head, NS_ASSERT, NS_LOG_FUNCTION, and ReadItems().

Member Data Documentation

uint16_t ns3::PacketMetadata::m_head

head -(next)-> tail ^ | -–(prev)—|

Definition at line 356 of file packet-metadata.h.

Referenced by ReplaceTail().

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