network packets
More...
#include <packet.h>
List of all members.
Detailed Description
network packets
Each network packet contains a byte buffer, a set of tags, and metadata.
- The byte buffer stores the serialized content of the headers and trailers added to a packet. The serialized representation of these headers is expected to match that of real network packets bit for bit (although nothing forces you to do this) which means that the content of a packet buffer is expected to be that of a real packet.
- Each tag tags a subset of the bytes in the packet byte buffer with the information stored in the tag. A classic example of a tag is a FlowIdTag which contains a flow id: the set of bytes tagged by this tag implicitely belong to the attached flow id.
- The metadata describes the type of the headers and trailers which were serialized in the byte buffer. The maintenance of metadata is optional and disabled by default. To enable it, you must call Packet::EnableMetadata and this will allow you to get non-empty output from Packet::Print and Packet::Print.
Implementing a new type of Header or Trailer for a new protocol is pretty easy and is a matter of creating a subclass of the ns3::Header or of the ns3::Trailer base class, and implementing the methods described in their respective API documentation.
Implementing a new type of Tag requires roughly the same amount of work and this work is described in the ns3::Tag API documentation.
The performance aspects of the Packet API are discussed in Packet Performance
Constructor & Destructor Documentation
Create an empty packet with a new uid (as returned by getUid).
ns3::Packet::Packet |
( |
uint32_t |
size |
) |
|
Create a packet with a zero-filled payload. The memory necessary for the payload is not allocated: it will be allocated at any later point if you attempt to fragment this packet or to access the zero-filled bytes. The packet is allocated with a new uid (as returned by getUid).
- Parameters:
-
| size | the size of the zero-filled payload |
ns3::Packet::Packet |
( |
uint8_t const * |
buffer, |
|
|
uint32_t |
size | |
|
) |
| | |
Create a packet with payload filled with the content of this buffer. The input data is copied: the input buffer is untouched.
- Parameters:
-
| buffer | the data to store in the packet. |
| size | the size of the input buffer. |
Member Function Documentation
void ns3::Packet::AddAtEnd |
( |
Ptr< const Packet > |
packet |
) |
|
Concatenate the input packet at the end of the current packet. This does not alter the uid of either packet.
- Parameters:
-
| packet | packet to concatenate |
void ns3::Packet::AddHeader |
( |
const Header & |
header |
) |
|
Add header to this packet. This method invokes the Header::GetSerializedSize and Header::Serialize methods to reserve space in the buffer and request the header to serialize itself in the packet buffer.
- Parameters:
-
| header | a reference to the header to add to this packet. |
void ns3::Packet::AddPaddingAtEnd |
( |
uint32_t |
size |
) |
|
- Parameters:
-
| size | number of padding bytes to add. |
void ns3::Packet::AddTag |
( |
const Tag & |
tag |
) |
const |
- Parameters:
-
| tag | the new tag to add to this packet |
Tag each byte included in this packet with the new tag.
Note that adding a tag is a const operation which is pretty un-intuitive. The rationale is that the content and behavior of a packet is _not_ changed when a tag is added to a packet: any code which was not aware of the new tag is going to work just the same if the new tag is added. The real reason why adding a tag was made a const operation is to allow a trace sink which gets a packet to tag the packet, even if the packet is const (and most trace sources should use const packets because it would be totally evil to allow a trace sink to modify the content of a packet).
void ns3::Packet::AddTrailer |
( |
const Trailer & |
trailer |
) |
|
Add trailer to this packet. This method invokes the Trailer::GetSerializedSize and Trailer::Serialize methods to reserve space in the buffer and request the trailer to serialize itself in the packet buffer.
- Parameters:
-
| trailer | a reference to the trailer to add to this packet. |
Ptr<Packet> ns3::Packet::CreateFragment |
( |
uint32_t |
start, |
|
|
uint32_t |
length | |
|
) |
| | const |
Create a new packet which contains a fragment of the original packet. The returned packet shares the same uid as this packet.
- Parameters:
-
| start | offset from start of packet to start of fragment to create |
| length | length of fragment to create |
- Returns:
- a fragment of the original packet
void ns3::Packet::Deserialize |
( |
Buffer |
buffer |
) |
|
- Parameters:
-
This method reads a byte buffer as created by Packet::Serialize and restores the state of the Packet to what it was prior to calling Serialize.
This method will trigger calls to the Deserialize method of each tag stored in this packet.
This method will typically be used by parallel simulations where the simulated system is partitioned and each partition runs on a different CPU.
static void ns3::Packet::EnableChecking |
( |
void |
|
) |
[static] |
The packet metadata is also used to perform extensive sanity checks at runtime when performing operations on a Packet. For example, this metadata is used to verify that when you remove a header from a packet, this same header was actually present at the front of the packet. These errors will be detected and will abort the program.
static void ns3::Packet::EnablePrinting |
( |
void |
|
) |
[static] |
By default, packets do not keep around enough metadata to perform the operations requested by the Print methods. If you want to be able to invoke any of the two Print methods, you need to invoke this method at least once during the simulation setup and before any packet is created.
bool ns3::Packet::FindFirstMatchingTag |
( |
Tag & |
tag |
) |
const |
- Parameters:
-
| tag | the tag to search in this packet |
- Returns:
- true if the requested tag type was found, false otherwise.
If the requested tag type is found, it is copied in the user's provided tag instance.
uint32_t ns3::Packet::GetSize |
( |
void |
|
) |
const |
- Returns:
- the size in bytes of the packet (including the zero-filled initial payload)
- Returns:
- an iterator over the set of tags included in this packet.
uint32_t ns3::Packet::GetUid |
( |
void |
|
) |
const |
A packet is allocated a new uid when it is created empty or with zero-filled payload.
Note: This uid is an internal uid and cannot be counted on to provide an accurate counter of how many "simulated packets" of a particular protocol are in the system. It is not trivial to make this uid into such a counter, because of questions such as what should the uid be when the packet is sent over broadcast media, or when fragmentation occurs. If a user wants to trace actual packet counts, he or she should look at e.g. the IP ID field or transport sequence numbers, or other packet or frame counters at other protocol layers.
- Returns:
- an integer identifier which uniquely identifies this packet.
uint8_t const* ns3::Packet::PeekData |
( |
void |
|
) |
const |
If you try to change the content of the buffer returned by this method, you will die.
- Returns:
- a pointer to the internal buffer of the packet.
uint32_t ns3::Packet::PeekHeader |
( |
Header & |
header |
) |
|
Deserialize but does _not_ remove the header from the internal buffer. This method invokes Header::Deserialize.
- Parameters:
-
| header | a reference to the header to read from the internal buffer. |
- Returns:
- the number of bytes read from the packet.
uint32_t ns3::Packet::PeekTrailer |
( |
Trailer & |
trailer |
) |
|
Deserialize but does _not_ remove a trailer from the internal buffer. This method invokes the Trailer::Deserialize method.
- Parameters:
-
| trailer | a reference to the trailer to read from the internal buffer. |
- Returns:
- the number of bytes read from the end of the packet.
void ns3::Packet::Print |
( |
std::ostream & |
os |
) |
const |
- Parameters:
-
| os | output stream in which the data should be printed. |
Iterate over the headers and trailers present in this packet, from the first header to the last trailer and invoke, for each of them, the user-provided method Header::DoPrint or Trailer::DoPrint methods.
void ns3::Packet::PrintTags |
( |
std::ostream & |
os |
) |
const |
- Parameters:
-
| os | output stream in which the data should be printed. |
Iterate over the tags present in this packet, and invoke the Print method of each tag stored in the packet.
void ns3::Packet::RemoveAllTags |
( |
void |
|
) |
|
Remove all the tags stored in this packet.
void ns3::Packet::RemoveAtEnd |
( |
uint32_t |
size |
) |
|
Remove size bytes from the end of the current packet It is safe to remove more bytes that what is present in the packet.
- Parameters:
-
| size | number of bytes from remove |
void ns3::Packet::RemoveAtStart |
( |
uint32_t |
size |
) |
|
Remove size bytes from the start of the current packet. It is safe to remove more bytes that what is present in the packet.
- Parameters:
-
| size | number of bytes from remove |
uint32_t ns3::Packet::RemoveHeader |
( |
Header & |
header |
) |
|
Deserialize and remove the header from the internal buffer. This method invokes Header::Deserialize.
- Parameters:
-
| header | a reference to the header to remove from the internal buffer. |
- Returns:
- the number of bytes removed from the packet.
uint32_t ns3::Packet::RemoveTrailer |
( |
Trailer & |
trailer |
) |
|
Remove a deserialized trailer from the internal buffer. This method invokes the Deserialize method.
- Parameters:
-
| trailer | a reference to the trailer to remove from the internal buffer. |
- Returns:
- the number of bytes removed from the end of the packet.
Buffer ns3::Packet::Serialize |
( |
void |
|
) |
const |
- Returns:
- a byte buffer
This method creates a serialized representation of a Packet object ready to be transmitted over a network to another system. This serialized representation contains a copy of the packet byte buffer, the tag list, and the packet metadata (if there is one).
This method will trigger calls to the Serialize and GetSerializedSize methods of each tag stored in this packet.
This method will typically be used by parallel simulations where the simulated system is partitioned and each partition runs on a different CPU.
The documentation for this class was generated from the following file: