10#include "ns3/assert.h"
12#include "ns3/simulator.h"
211 i.
Write(buffer, size);
232 byteTagList.
Adjust(-start);
276 m_buffer.RemoveAtStart(deserialized);
278 m_metadata.RemoveHeader(header, deserialized);
287 m_buffer.RemoveAtStart(deserialized);
289 m_metadata.RemoveHeader(header, deserialized);
330 m_metadata.RemoveTrailer(trailer, deserialized);
351 m_buffer.AddAtEnd(packet->m_buffer);
391 return m_buffer.CopyData(buffer, size);
423 Tag* tag =
dynamic_cast<Tag*
>(constructor());
439 std::ostringstream oss;
482 auto chunk =
dynamic_cast<Chunk*
>(instance);
488 chunk->Deserialize(item.
current, end);
494 chunk->Deserialize(start, item.
current);
498 chunk->Deserialize(item.
current);
550 Chunk *chunk =
dynamic_cast<Chunk *
> (instance);
555 std::string attrName = item.
tid.GetAttributeName (j);
559 os << attrName <<
"=" << value;
607 size += ((
m_nixVector->GetSerializedSize() + 3) & (~3));
636 size += ((
m_metadata.GetSerializedSize() + 3) & (~3));
643 size += ((
m_buffer.GetSerializedSize() + 3) & (~3));
654 auto p =
reinterpret_cast<uint32_t*
>(buffer);
681 p += ((nixSize + 3) & (~3)) / 4;
708 *p++ = byteTagSize + 4;
719 p += ((byteTagSize + 3) & (~3)) / 4;
723 size += packetTagSize;
732 *p++ = packetTagSize + 4;
743 p += ((packetTagSize + 3) & (~3)) / 4;
759 serialized =
m_metadata.Serialize(
reinterpret_cast<uint8_t*
>(p), metaSize);
767 p += ((metaSize + 3) & (~3)) / 4;
783 serialized =
m_buffer.Serialize(
reinterpret_cast<uint8_t*
>(p), bufSize);
798 auto p =
reinterpret_cast<const uint32_t*
>(buffer);
811 uint32_t nixDeserialized = nix->Deserialize(p, nixSize);
812 if (!nixDeserialized)
821 p += ((((nixSize - 4) + 3) & (~3)) / 4);
833 if (!byteTagDeserialized)
840 p += ((((byteTagSize - 4) + 3) & (~3)) / 4);
851 if (!packetTagDeserialized)
858 p += ((((packetTagSize - 4) + 3) & (~3)) / 4);
859 size -= packetTagSize;
869 m_metadata.Deserialize(
reinterpret_cast<const uint8_t*
>(p), metaSize);
870 if (!metadataDeserialized)
878 p += ((((metaSize - 4) + 3) & (~3)) / 4);
889 m_buffer.Deserialize(
reinterpret_cast<const uint8_t*
>(p), bufSize);
890 if (!bufferDeserialized)
996 Tag* tag =
dynamic_cast<Tag*
>(instance);
iterator in a Buffer instance
void Write(const uint8_t *buffer, uint32_t size)
void Next()
go forward by one byte
automatically resized byte buffer
Identifies a byte tag and a set of bytes within a packet to which the tag applies.
TypeId m_tid
the ns3::TypeId associated to this tag.
uint32_t m_start
the index of the first byte tagged by this tag.
uint32_t GetEnd() const
The index is an offset from the start of the packet.
TagBuffer m_buffer
the buffer associated with this tag.
Item(TypeId tid, uint32_t start, uint32_t end, TagBuffer buffer)
Constructor.
void GetTag(Tag &tag) const
Read the requested tag and store it in the user-provided tag instance.
uint32_t GetStart() const
The index is an offset from the start of the packet.
uint32_t m_end
the index of the last byte tagged by this tag.
Iterator over the set of byte tags in a packet.
ByteTagIterator(ByteTagList::Iterator i)
Copy Constructor.
ByteTagList::Iterator m_current
actual position over the set of byte tags in a packet
An iterator for iterating through a byte tag list.
keep track of the byte tags stored in a packet.
void Adjust(int32_t adjustment)
Adjust the offsets stored internally by the adjustment delta.
void AddAtStart(int32_t prependOffset)
Make sure that all offsets are bigger than prependOffset which represents the location where new byte...
bool IsNull() const
Check for null implementation.
abstract base class for ns3::Header and ns3::Trailer
virtual uint32_t Deserialize(Buffer::Iterator start)=0
Deserialize the object from a buffer iterator.
Anchor the ns-3 type and attribute system.
virtual TypeId GetInstanceTypeId() const =0
Get the most derived TypeId for this Object.
void GetAttribute(std::string name, AttributeValue &value, bool permissive=false) const
Get the value of an attribute, raising fatal errors if unsuccessful.
PacketTagIterator GetPacketTagIterator() const
Returns an object which can be used to iterate over the list of packet tags.
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Buffer m_buffer
the packet buffer (it's actual contents)
static void EnableChecking()
Enable packets metadata checking.
void AddAtEnd(Ptr< const Packet > packet)
Concatenate the input packet at the end of the current packet.
uint32_t RemoveTrailer(Trailer &trailer)
Remove a deserialized trailer from the internal buffer.
PacketMetadata::ItemIterator BeginItem() const
Returns an iterator which points to the first 'item' stored in this buffer.
void SetNixVector(Ptr< NixVector > nixVector) const
Set the packet nix-vector.
ByteTagList m_byteTagList
the ByteTag list
Ptr< NixVector > GetNixVector() const
Get the packet nix-vector.
void PrintByteTags(std::ostream &os) const
Iterate over the byte tags present in this packet, and invoke the Print method of each tag stored in ...
void AddHeader(const Header &header)
Add header to this packet.
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
static uint32_t m_globalUid
Global counter of packets Uid.
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
void RemoveAtEnd(uint32_t size)
Remove size bytes from the end of the current packet.
uint32_t Deserialize(const uint8_t *buffer, uint32_t size)
Deserializes a packet.
uint32_t GetSerializedSize() const
Returns number of bytes required for packet serialization.
void RemoveAtStart(uint32_t size)
Remove size bytes from the start of the current packet.
PacketTagList m_packetTagList
the packet's Tag list
Ptr< Packet > Copy() const
performs a COW copy of the packet.
void PrintPacketTags(std::ostream &os) const
Print the list of packet tags.
Packet & operator=(const Packet &o)
Basic assignment.
bool FindFirstMatchingByteTag(Tag &tag) const
Finds the first tag matching the parameter Tag type.
uint32_t Serialize(uint8_t *buffer, uint32_t maxSize) const
Serialize a packet, tags, and metadata into a byte buffer.
void RemoveAllByteTags()
Remove all byte tags stored in this packet.
Packet()
Create an empty packet with a new uid (as returned by getUid).
void AddPacketTag(const Tag &tag) const
Add a packet tag.
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
void RemoveAllPacketTags()
Remove all packet tags.
Ptr< Packet > CreateFragment(uint32_t start, uint32_t length) const
Create a new packet which contains a fragment of the original packet.
uint32_t PeekTrailer(Trailer &trailer)
Deserialize but does not remove a trailer from the internal buffer.
void Print(std::ostream &os) const
Print the packet contents.
uint64_t GetUid() const
Returns the packet's Uid.
void AddByteTag(const Tag &tag) const
Tag each byte included in this packet with a new byte tag.
std::string ToString() const
Return a string representation of the packet.
static void EnablePrinting()
Enable printing packets metadata.
void AddTrailer(const Trailer &trailer)
Add trailer to this packet.
void AddPaddingAtEnd(uint32_t size)
Add a zero-filled padding to the packet.
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
ByteTagIterator GetByteTagIterator() const
Returns an iterator over the set of byte tags included in this packet.
PacketMetadata m_metadata
the packet's metadata
Ptr< NixVector > m_nixVector
the packet's Nix vector
bool ReplacePacketTag(Tag &tag)
Replace the value of a packet tag.
Identifies a packet tag within a packet.
Item(const PacketTagList::TagData *data)
Constructor.
void GetTag(Tag &tag) const
Read the requested tag and store it in the user-provided tag instance.
const PacketTagList::TagData * m_data
the tag data
Iterator over the set of packet tags in a packet.
const PacketTagList::TagData * m_current
actual position over the set of tags in a packet
friend class Packet
Friend class.
PacketTagIterator(const PacketTagList::TagData *head)
Constructor.
List of the packet tags stored in a packet.
Smart pointer class similar to boost::intrusive_ptr.
Control the scheduling of simulation events.
tag a set of bytes in a packet
virtual uint32_t GetSerializedSize() const =0
virtual void Serialize(TagBuffer i) const =0
virtual void Print(std::ostream &os) const =0
virtual void Deserialize(TagBuffer i)=0
Protocol trailer serialization and deserialization.
virtual void Serialize(Buffer::Iterator start) const =0
uint32_t Deserialize(Buffer::Iterator end) override=0
virtual uint32_t GetSerializedSize() const =0
a unique identifier for an interface.
Callback< ObjectBase * > GetConstructor() const
Get the constructor callback.
bool HasConstructor() const
Check if this TypeId has a constructor.
std::size_t GetAttributeN() const
Get the number of attributes.
std::string GetName() const
Get the name.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
An item specifies an individual tag within a byte buffer.
TypeId tid
type of the tag
TagBuffer buf
the data for the tag as generated by Tag::Serialize
int32_t end
offset to the end of the tag from the virtual byte buffer
int32_t start
offset to the start of the tag from the virtual byte buffer
Tree node for sharing serialized tags.