21 #include "ns3/assert.h" 23 #include "ns3/simulator.h" 116 (uint8_t*)m_data->data + m_data->size));
139 m_metadata (static_cast<uint64_t> (
Simulator::GetSystemId ()) << 32 | m_globalUid, 0),
146 : m_buffer (o.m_buffer),
147 m_byteTagList (o.m_byteTagList),
148 m_packetTagList (o.m_packetTagList),
149 m_metadata (o.m_metadata)
181 m_metadata (static_cast<uint64_t> (
Simulator::GetSystemId ()) << 32 | m_globalUid, size),
187 : m_buffer (0, false),
207 m_metadata (static_cast<uint64_t> (
Simulator::GetSystemId ()) << 32 | m_globalUid, size),
213 i.
Write (buffer, size);
219 m_byteTagList (byteTagList),
220 m_packetTagList (packetTagList),
221 m_metadata (metadata),
404 if (constructor.
IsNull ())
412 Tag *tag =
dynamic_cast<Tag *
> (constructor ());
428 std::ostringstream oss;
469 Chunk *chunk =
dynamic_cast<Chunk *
> (instance);
537 Chunk *chunk =
dynamic_cast<Chunk *
> (instance);
542 std::string attrName = item.
tid.GetAttributeName (j);
546 os << attrName <<
"=" << value;
640 uint32_t* p =
reinterpret_cast<uint32_t *
> (buffer);
647 if (size + nixSize <= maxSize)
656 uint32_t serialized =
662 p += ((nixSize+3) & (~3)) / 4;
679 if (size + 4 <= maxSize)
692 if (size + byteTagSize <= maxSize)
697 *p++ = byteTagSize + 4;
706 p += ((byteTagSize+3) & (~3)) / 4;
720 if (size + packetTagSize <= maxSize)
725 *p++ = packetTagSize + 4;
726 size += packetTagSize;
734 p += ((packetTagSize+3) & (~3)) / 4;
748 if (size + metaSize <= maxSize)
762 p += ((metaSize+3) & (~3)) / 4;
776 if (size + bufSize <= maxSize)
784 uint32_t serialized =
m_buffer.
Serialize (reinterpret_cast<uint8_t *> (p), bufSize);
804 const uint32_t* p =
reinterpret_cast<const uint32_t *
> (buffer);
808 uint32_t nixSize = *p++;
817 uint32_t nixDeserialized = nix->
Deserialize (p, nixSize);
818 if (!nixDeserialized)
827 p += ((((nixSize - 4) + 3) & (~3)) / 4);
832 uint32_t byteTagSize = *p++;
838 uint32_t byteTagDeserialized =
840 if (!byteTagDeserialized)
847 p += ((((byteTagSize - 4) + 3) & (~3)) / 4);
851 uint32_t packetTagSize = *p++;
857 uint32_t packetTagDeserialized =
859 if (!packetTagDeserialized)
866 p += ((((packetTagSize - 4) + 3) & (~3)) / 4);
867 size -= packetTagSize;
870 uint32_t metaSize = *p++;
876 uint32_t metadataDeserialized =
878 if (!metadataDeserialized)
886 p += ((((metaSize - 4) + 3) & (~3)) / 4);
890 uint32_t bufSize = *p++;
896 uint32_t bufferDeserialized =
898 if (!bufferDeserialized)
928 static_cast<int32_t
> (
start),
929 static_cast<int32_t> (end));
1001 Tag *tag =
dynamic_cast<Tag *
> (instance);
uint32_t Deserialize(const uint32_t *buffer, uint32_t size)
Deserialize tag list from the provided buffer.
bool FindFirstMatchingByteTag(Tag &tag) const
Finds the first tag matching the parameter Tag type.
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
PacketMetadata m_metadata
the packet's metadata
bool Remove(Tag &tag)
Remove (the first instance of) tag from the list.
Callback< ObjectBase * > GetConstructor(void) const
Get the constructor callback.
TypeId GetTypeId(void) const
std::string GetName(void) const
Get the name.
void AddAtStart(uint32_t start)
uint64_t GetUid(void) const
Returns the packet's Uid.
void Print(std::ostream &os) const
Print the packet contents.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
bool HasConstructor(void) const
Check if this TypeId has a constructor.
Control the scheduling of simulation events.
void RemoveAtEnd(uint32_t end)
struct TagData * next
Pointer to next in list.
uint32_t Deserialize(uint8_t const *buffer, uint32_t size)
Deserializes a packet.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
void RemoveAtStart(uint32_t start)
virtual uint32_t GetSerializedSize(void) const =0
uint32_t GetSerializedSize(void) const
Returns number of bytes required for packet serialization.
TypeId GetTypeId(void) const
automatically resized byte buffer
List of the packet tags stored in a packet.
uint32_t GetSerializedSize(void) const
Returns number of bytes required for packet serialization.
keep track of the byte tags stored in a packet.
Ptr< Packet > CreateFragment(uint32_t start, uint32_t length) const
Create a new packet which contains a fragment of the original packet.
static uint32_t m_globalUid
Global counter of packets Uid.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
TagBuffer Add(TypeId tid, uint32_t bufferSize, int32_t start, int32_t end)
uint32_t GetStart(void) const
The index is an offset from the start of the packet.
void Adjust(int32_t adjustment)
Adjust the offsets stored internally by the adjustment delta.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Buffer m_buffer
the packet buffer (it's actual contents)
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Anchor the ns-3 type and attribute system.
Item(TypeId tid, uint32_t start, uint32_t end, TagBuffer buffer)
Constructor.
Packet & operator=(const Packet &o)
Basic assignment.
void PrintPacketTags(std::ostream &os) const
Print the list of packet tags.
virtual uint32_t Deserialize(Buffer::Iterator start)=0
Deserialize the object from a buffer iterator.
iterator in a Buffer instance
const struct PacketTagList::TagData * Head(void) const
ByteTagList::Iterator m_current
actual position over the set of byte tags in a packet
Packet()
Create an empty packet with a new uid (as returned by getUid).
std::ostream & operator<<(std::ostream &os, const Angles &a)
uint32_t PeekTrailer(Trailer &trailer)
Deserialize but does not remove a trailer from the internal buffer.
void AddAtEnd(int32_t appendOffset)
Make sure that all offsets are smaller than appendOffset which represents the location where new byte...
void AddAtEnd(Ptr< const Packet > packet)
Concatenate the input packet at the end of the current packet.
void RemoveAll(void)
Removes all of the tags from the ByteTagList.
Tree node for sharing serialized tags.
uint32_t Deserialize(const uint8_t *buffer, uint32_t size)
void RemoveAllPacketTags(void)
Remove all packet tags.
Identifies a byte tag and a set of bytes within a packet to which the tag applies.
void RemoveAtStart(uint32_t size)
Remove size bytes from the start of the current packet.
uint32_t GetSerializedSize(void) const
Returns number of bytes required for packet serialization.
bool Replace(Tag &tag)
Replace the value of a tag.
uint32_t Serialize(uint32_t *buffer, uint32_t maxSize) const
ByteTagList::Iterator Begin(int32_t offsetStart, int32_t offsetEnd) const
static void EnablePrinting(void)
Enable printing packets metadata.
TypeId m_tid
the ns3::TypeId associated to this tag.
void SetNixVector(Ptr< NixVector > nixVector)
Set the packet nix-vector.
virtual void Print(std::ostream &os) const =0
Print the object contents.
ByteTagList m_byteTagList
the ByteTag list
void CopyData(std::ostream *os, uint32_t size) const
Copy the specified amount of data from the buffer to the given output stream.
bool ReplacePacketTag(Tag &tag)
Replace the value of a packet tag.
uint32_t GetSerializedSize(void) const
uint32_t GetSerializedSize(void) const
Return the number of bytes required for serialization.
static void EnableChecking(void)
Enable packets metadata checking.
std::string ToString(void) const
Return a string representation of the packet.
void AddPaddingAtEnd(uint32_t size)
Add a zero-filled padding to the packet.
void Next(void)
go forward by one byte
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
int32_t start
offset to the start of the tag from the virtual byte buffer
virtual uint32_t Deserialize(Buffer::Iterator end)=0
Iterator over the set of packet tags in a packet.
const struct PacketTagList::TagData * m_current
actual position over the set of tags in a packet
struct ByteTagList::Iterator::Item Next(void)
Returns the next Item from the ByteTagList.
void AddAtEnd(uint32_t end)
Protocol trailer serialization and deserialization.
virtual void Serialize(TagBuffer i) const =0
tag a set of bytes in a packet
PacketTagIterator GetPacketTagIterator(void) const
Returns an object which can be used to iterate over the list of packet tags.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
PacketTagIterator(const struct PacketTagList::TagData *head)
Constructor.
void AddTrailer(const Trailer &trailer)
Add trailer to this packet.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
void RemoveAtEnd(uint32_t size)
Remove size bytes from the end of the current packet.
friend class Packet
Friend class.
Iterator over the set of byte tags in a packet.
virtual void Deserialize(TagBuffer i)=0
uint32_t RemoveTrailer(Trailer &trailer)
Remove a deserialized trailer from the internal buffer.
bool Peek(Tag &tag) const
Find a tag and return its value.
PacketTagList m_packetTagList
the packet's Tag list
Ptr< NixVector > Copy(void) const
int32_t end
offset to the end of the tag from the virtual byte buffer
uint32_t Serialize(uint8_t *buffer, uint32_t maxSize) const
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 ...
Identifies a packet tag within a packet.
PacketMetadata::ItemIterator BeginItem(void) const
Returns an iterator which points to the first 'item' stored in this buffer.
void Add(Tag const &tag) const
Add a tag to the head of this branch.
Buffer::Iterator End(void) const
TypeId tid
type of the tag
Item(const struct PacketTagList::TagData *data)
Constructor.
uint32_t GetEnd(void) const
The index is an offset from the start of the packet.
TagBuffer buf
the data for the tag as generated by Tag::Serialize
An iterator for iterating through a byte tag list.
void GetTag(Tag &tag) const
Read the requested tag and store it in the user-provided tag instance.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
void AddPacketTag(const Tag &tag) const
Add a packet tag.
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
std::size_t GetAttributeN(void) const
Get the number of attributes.
virtual TypeId GetInstanceTypeId(void) const =0
Get the most derived TypeId for this Object.
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
void AddAtStart(int32_t prependOffset)
Make sure that all offsets are bigger than prependOffset which represents the location where new byte...
void RemoveAllByteTags(void)
Remove all byte tags stored in this packet.
virtual uint32_t GetSerializedSize(void) const =0
Ptr< NixVector > GetNixVector(void) const
Get the packet nix-vector.
Ptr< NixVector > m_nixVector
the packet's Nix vector
uint32_t Deserialize(const uint32_t *buffer, uint32_t size)
uint32_t GetSize(void) const
Buffer CreateFragment(uint32_t start, uint32_t length) const
void Write(uint8_t const *buffer, uint32_t size)
virtual void Serialize(Buffer::Iterator start) const =0
uint32_t GetOffsetStart(void) const
Returns the offset from the start of the virtual byte buffer to the ByteTagList.
ByteTagIterator(ByteTagList::Iterator i)
Copy Constructor.
uint32_t Serialize(uint32_t *buffer, uint32_t maxSize) const
Serialize the tag list into a byte buffer.
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
void GetTag(Tag &tag) const
Read the requested tag and store it in the user-provided tag instance.
bool IsNull(void) const
Check for null implementation.
void RemoveAll(void)
Remove all tags from this list (up to the first merge).
uint32_t Deserialize(const uint32_t *buffer, uint32_t size)
Deserialize tag list from the provided buffer.
a unique identifier for an interface.
uint32_t Serialize(uint32_t *buffer, uint32_t maxSize) const
Serialize the tag list into a byte buffer.
void GetAttribute(std::string name, AttributeValue &value) const
Get the value of an attribute, raising fatal errors if unsuccessful.
void AddByteTag(const Tag &tag) const
Tag each byte included in this packet with a new byte tag.
abstract base class for ns3::Header and ns3::Trailer
Buffer::Iterator Begin(void) const
void AddHeader(const Header &header)
Add header to this packet.
ByteTagIterator GetByteTagIterator(void) const
Returns an iterator over the set of byte tags included in this packet.
virtual void Print(std::ostream &os) const =0
uint32_t Serialize(uint8_t *buffer, uint32_t maxSize) const
Serialize a packet, tags, and metadata into a byte buffer.
bool HasNext(void) const
Used to determine if the iterator is at the end of the byteTagList.
An item specifies an individual tag within a byte buffer.