network packets
More...
#include <packet.h>
List of all members.
Detailed Description
network packets
Each network packet contains a byte buffer, a set of byte tags, a set of packet 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.
- 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::EnablePrinting and this will allow you to get non-empty output from Packet::Print and Packet::Print. If you wish to only enable checking of metadata, and do not need any printing capability, you can call Packet::EnableChecking: its runtime cost is lower than Packet::EnablePrinting.
- The set of tags contain simulation-specific information which cannot be stored in the packet byte buffer because the protocol headers or trailers have no standard-conformant field for this information. So-called 'byte' tags are used to tag a subset of the bytes in the packet byte buffer while 'packet' tags are used to tag the packet itself. The main difference between these two kinds of tags is what happens when packets are copied, fragmented, and reassembled: 'byte' tags follow bytes while 'packet' tags follow packets. Another important difference between these two kinds of tags is that byte tags cannot be removed and are expected to be written once, and read many times, while packet tags are expected to be written once, read many times, and removed exactly once. An example of a 'byte' tag is a FlowIdTag which contains a flow id and is set by the application generating traffic. An example of a 'packet' tag is a cross-layer qos class id set by an application and processed by a lower-level MAC layer.
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::AddByteTag |
( |
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::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::AddPacketTag |
( |
const Tag & |
tag |
) |
const |
- Parameters:
-
| tag | the tag to store in this packet |
Add a tag to this packet. This method calls the Tag::GetSerializedSize and, then, Tag::Serialize.
Note that this method is const, that is, it does not modify the state of this packet, which is fairly un-intuitive.
void ns3::Packet::AddPaddingAtEnd |
( |
uint32_t |
size |
) |
|
- Parameters:
-
| size | number of padding bytes to add. |
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. |
uint32_t ns3::Packet::CopyData |
( |
uint8_t * |
buffer, |
|
|
uint32_t |
size | |
|
) |
| | const |
- Parameters:
-
| buffer | a pointer to a byte buffer where the packet data should be copied. |
| size | the size of the byte buffer. |
- Returns:
- the number of bytes read from the packet
No more than size bytes will be copied by this function.
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::FindFirstMatchingByteTag |
( |
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.
- Returns:
- an iterator over the set of byte tags included in this packet.
- Returns:
- an object which can be used to iterate over the list of packet tags.
uint32_t ns3::Packet::GetSize |
( |
void |
|
) |
const |
- Returns:
- the size in bytes of the packet (including the zero-filled initial payload)
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. Note that this method is now deprecated and will be removed in the next version of ns-3. If you need to get access to the content of the byte buffer of a packet, you need to call ns3::Packet::CopyData to perform an explicit copy.
- Returns:
- a pointer to the internal buffer of the packet.
uint32_t ns3::Packet::PeekHeader |
( |
Header & |
header |
) |
const |
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.
bool ns3::Packet::PeekPacketTag |
( |
Tag & |
tag |
) |
const |
- Parameters:
-
| tag | the tag to search in this packet |
- Returns:
- true if the requested tag is found, false otherwise.
Search a matching tag and call Tag::Deserialize if it is found.
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::PrintByteTags |
( |
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::PrintPacketTags |
( |
std::ostream & |
os |
) |
const |
void ns3::Packet::RemoveAllByteTags |
( |
void |
|
) |
|
Remove all the tags stored in this packet.
void ns3::Packet::RemoveAllPacketTags |
( |
void |
|
) |
|
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.
bool ns3::Packet::RemovePacketTag |
( |
Tag & |
tag |
) |
|
- Parameters:
-
| tag | the tag to remove from this packet |
- Returns:
- true if the requested tag is found, false otherwise.
Remove a tag from this packet. This method calls Tag::Deserialize if the tag is found.
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: