ns-3
|
Packet header for IPv4. More...
#include <ipv4-header.h>
Public Types | |
enum | DscpType { DscpDefault = 0x00, CS1 = 0x20, AF11 = 0x28, AF12 = 0x30, AF13 = 0x38, CS2 = 0x40, AF21 = 0x48, AF22 = 0x50, AF23 = 0x58, CS3 = 0x60, AF31 = 0x68, AF32 = 0x70, AF33 = 0x78, CS4 = 0x80, AF41 = 0x88, AF42 = 0x90, AF43 = 0x98, CS5 = 0xA0, EF = 0xB8, CS6 = 0xC0, CS7 = 0xE0 } |
DiffServ Code Points Code Points defined in Assured Forwarding (AF) RFC 2597 Expedited Forwarding (EF) RFC 2598 Default and Class Selector (CS) RFC 2474. | |
enum | EcnType { NotECT = 0x00, ECT1 = 0x01, ECT0 = 0x02, CE = 0x03 } |
ECN Type defined in RFC 3168. | |
Public Member Functions | |
Ipv4Header () | |
Construct a null IPv4 header. | |
void | EnableChecksum (void) |
Enable checksum calculation for this header. | |
void | SetPayloadSize (uint16_t size) |
void | SetIdentification (uint16_t identification) |
void | SetTos (uint8_t tos) |
void | SetDscp (DscpType dscp) |
Set DSCP Field. | |
void | SetEcn (EcnType ecn) |
Set ECN Field. | |
void | SetMoreFragments (void) |
void | SetLastFragment (void) |
void | SetDontFragment (void) |
void | SetMayFragment (void) |
void | SetFragmentOffset (uint16_t offsetBytes) |
void | SetTtl (uint8_t ttl) |
void | SetProtocol (uint8_t num) |
void | SetSource (Ipv4Address source) |
void | SetDestination (Ipv4Address destination) |
uint16_t | GetPayloadSize (void) const |
uint16_t | GetIdentification (void) const |
uint8_t | GetTos (void) const |
DscpType | GetDscp (void) const |
std::string | DscpTypeToString (DscpType dscp) const |
EcnType | GetEcn (void) const |
std::string | EcnTypeToString (EcnType ecn) const |
bool | IsLastFragment (void) const |
bool | IsDontFragment (void) const |
uint16_t | GetFragmentOffset (void) const |
uint8_t | GetTtl (void) const |
uint8_t | GetProtocol (void) const |
Ipv4Address | GetSource (void) const |
Ipv4Address | GetDestination (void) const |
bool | IsChecksumOk (void) const |
virtual TypeId | GetInstanceTypeId (void) const |
virtual void | Print (std::ostream &os) const |
virtual uint32_t | GetSerializedSize (void) const |
virtual void | Serialize (Buffer::Iterator start) const |
virtual uint32_t | Deserialize (Buffer::Iterator start) |
Static Public Member Functions | |
static TypeId | GetTypeId (void) |
This method returns the TypeId associated to ns3::Ipv4Header. |
Packet header for IPv4.
uint32_t ns3::Ipv4Header::Deserialize | ( | Buffer::Iterator | start | ) | [virtual] |
start | an iterator which points to where the header should written. |
This method is used by Packet::RemoveHeader to re-create a header from the byte buffer of a packet. The data read is expected to match bit-for-bit the representation of this header in real networks.
Implements ns3::Header.
References ns3::Buffer::Iterator::CalculateIpChecksum(), GetSerializedSize(), NS_ASSERT, NS_LOG_LOGIC, ns3::Buffer::Iterator::Prev(), ns3::Buffer::Iterator::ReadNtohU16(), ns3::Buffer::Iterator::ReadNtohU32(), ns3::Buffer::Iterator::ReadU16(), ns3::Buffer::Iterator::ReadU8(), and ns3::Ipv4Address::Set().
Referenced by ns3::Icmpv4TimeExceeded::Deserialize().
std::string ns3::Ipv4Header::DscpTypeToString | ( | DscpType | dscp | ) | const |
Referenced by Print().
std::string ns3::Ipv4Header::EcnTypeToString | ( | EcnType | ecn | ) | const |
Referenced by Print().
Ipv4Address ns3::Ipv4Header::GetDestination | ( | void | ) | const |
Referenced by ns3::IpcsClassifier::Classify(), ns3::Ipv4FlowClassifier::Classify(), ns3::RrcEntity::Classify(), ns3::TcpSocketBase::DoForwardUp(), ns3::aodv::RequestQueue::Enqueue(), ns3::dsdv::PacketQueue::Enqueue(), ns3::aodv::QueueEntry::operator==(), ns3::dsdv::QueueEntry::operator==(), ns3::Icmpv4L4Protocol::Receive(), ns3::NscTcpL4Protocol::Receive(), ns3::UdpL4Protocol::Receive(), ns3::TcpL4Protocol::Receive(), ns3::aodv::RoutingProtocol::RouteInput(), ns3::Ipv4StaticRouting::RouteInput(), ns3::Ipv4ListRouting::RouteInput(), ns3::Ipv4GlobalRouting::RouteInput(), ns3::aodv::RoutingProtocol::RouteOutput(), ns3::dsdv::RoutingProtocol::RouteOutput(), ns3::Ipv4StaticRouting::RouteOutput(), ns3::Ipv4ListRouting::RouteOutput(), ns3::Ipv4GlobalRouting::RouteOutput(), and ns3::Ipv4RawSocketImpl::SendTo().
Ipv4Header::DscpType ns3::Ipv4Header::GetDscp | ( | void | ) | const |
Referenced by Print().
Ipv4Header::EcnType ns3::Ipv4Header::GetEcn | ( | void | ) | const |
Referenced by Print().
uint16_t ns3::Ipv4Header::GetFragmentOffset | ( | void | ) | const |
References NS_LOG_WARN.
uint16_t ns3::Ipv4Header::GetIdentification | ( | void | ) | const |
Referenced by ns3::Ipv4FlowClassifier::Classify().
TypeId ns3::Ipv4Header::GetInstanceTypeId | ( | void | ) | const [virtual] |
This method is typically implemented by ns3::Object::GetInstanceTypeId but some classes which derive from ns3::ObjectBase directly have to implement it themselves.
Implements ns3::ObjectBase.
References GetTypeId().
uint16_t ns3::Ipv4Header::GetPayloadSize | ( | void | ) | const |
Referenced by ns3::Ipv4L3Protocol::Receive().
uint8_t ns3::Ipv4Header::GetProtocol | ( | void | ) | const |
Referenced by ns3::IpcsClassifier::Classify(), ns3::Ipv4FlowClassifier::Classify(), and ns3::RrcEntity::Classify().
uint32_t ns3::Ipv4Header::GetSerializedSize | ( | void | ) | const [virtual] |
This method is used by Packet::AddHeader to store a header into the byte buffer of a packet. This method should return the number of bytes which are needed to store the full header data by Serialize.
Implements ns3::Header.
Referenced by Deserialize(), ns3::Icmpv4TimeExceeded::GetSerializedSize(), and ns3::Icmpv4TimeExceeded::Serialize().
Ipv4Address ns3::Ipv4Header::GetSource | ( | void | ) | const |
Referenced by ns3::IpcsClassifier::Classify(), ns3::Ipv4FlowClassifier::Classify(), ns3::RrcEntity::Classify(), ns3::TcpSocketBase::DoForwardUp(), ns3::aodv::DuplicatePacketDetection::IsDuplicate(), ns3::Icmpv4L4Protocol::Receive(), ns3::NscTcpL4Protocol::Receive(), ns3::UdpL4Protocol::Receive(), ns3::TcpL4Protocol::Receive(), ns3::aodv::RoutingProtocol::RouteInput(), ns3::Ipv4StaticRouting::RouteInput(), ns3::Ipv4GlobalRouting::RouteInput(), ns3::Ipv4ListRouting::RouteOutput(), and ns3::Ipv4RawSocketImpl::SendTo().
uint8_t ns3::Ipv4Header::GetTos | ( | void | ) | const |
uint8_t ns3::Ipv4Header::GetTtl | ( | void | ) | const |
Referenced by ns3::aodv::RoutingProtocol::RouteInput().
TypeId ns3::Ipv4Header::GetTypeId | ( | void | ) | [static] |
This method returns the TypeId associated to ns3::Ipv4Header.
No Attributes defined for this type.
No TraceSources defined for this type.
Reimplemented from ns3::Header.
References ns3::TypeId::SetParent().
Referenced by GetInstanceTypeId().
bool ns3::Ipv4Header::IsChecksumOk | ( | void | ) | const |
If Ipv4Header::EnableChecksums has not been called prior to deserializing this header, this method will always return true.
Referenced by ns3::Ipv4L3Protocol::Receive().
bool ns3::Ipv4Header::IsDontFragment | ( | void | ) | const |
bool ns3::Ipv4Header::IsLastFragment | ( | void | ) | const |
void ns3::Ipv4Header::Print | ( | std::ostream & | os | ) | const [virtual] |
os | output stream This method is used by Packet::Print to print the content of a trailer as ascii data to a c++ output stream. Although the trailer is free to format its output as it wishes, it is recommended to follow a few rules to integrate with the packet pretty printer: start with flags, small field values located between a pair of parens. Values should be separated by whitespace. Follow the parens with the important fields, separated by whitespace. i.e.: (field1 val1 field2 val2 field3 val3) field4 val4 field5 val5 |
Implements ns3::Header.
References DscpTypeToString(), EcnTypeToString(), GetDscp(), and GetEcn().
Referenced by ns3::Icmpv4TimeExceeded::Print().
void ns3::Ipv4Header::Serialize | ( | Buffer::Iterator | start | ) | const [virtual] |
start | an iterator which points to where the header should be written. |
This method is used by Packet::AddHeader to store a header into the byte buffer of a packet. The data written is expected to match bit-for-bit the representation of this header in a real network.
Implements ns3::Header.
References ns3::Buffer::Iterator::CalculateIpChecksum(), ns3::Ipv4Address::Get(), ns3::Buffer::Iterator::Next(), NS_LOG_LOGIC, ns3::Buffer::Iterator::WriteHtonU16(), ns3::Buffer::Iterator::WriteHtonU32(), ns3::Buffer::Iterator::WriteU16(), and ns3::Buffer::Iterator::WriteU8().
Referenced by ns3::Icmpv4TimeExceeded::Serialize().
void ns3::Ipv4Header::SetDestination | ( | Ipv4Address | destination | ) |
destination | the destination of this packet. |
Referenced by ns3::NscTcpL4Protocol::Receive(), ns3::TcpL4Protocol::Send(), ns3::Ipv4RawSocketImpl::SendTo(), and ns3::TcpSocketBase::SetupEndpoint().
void ns3::Ipv4Header::SetDontFragment | ( | void | ) |
Don't fragment this packet: if you need to anyway, drop it.
void ns3::Ipv4Header::SetDscp | ( | DscpType | dscp | ) |
Set DSCP Field.
dscp | DSCP value |
void ns3::Ipv4Header::SetEcn | ( | EcnType | ecn | ) |
Set ECN Field.
ecn | ECN Type |
void ns3::Ipv4Header::SetFragmentOffset | ( | uint16_t | offsetBytes | ) |
The offset is measured in bytes for the packet start. Mind that IPv4 "fragment offset" field is 13 bits long and is measured in 8-bytes words. Hence, the function does enforce that the offset is a multiple of 8.
offsetBytes | the ipv4 fragment offset measured in bytes from the start. |
References NS_ABORT_MSG_IF.
void ns3::Ipv4Header::SetIdentification | ( | uint16_t | identification | ) |
identification | the Identification field of IPv4 packets. |
By default, set to zero.
void ns3::Ipv4Header::SetLastFragment | ( | void | ) |
This packet is the last packet of a fragmented ipv4 packet.
void ns3::Ipv4Header::SetMayFragment | ( | void | ) |
If you need to fragment this packet, you can do it.
void ns3::Ipv4Header::SetMoreFragments | ( | void | ) |
This packet is not the last packet of a fragmented ipv4 packet.
void ns3::Ipv4Header::SetPayloadSize | ( | uint16_t | size | ) |
size | the size of the payload in bytes |
Referenced by ns3::NscTcpL4Protocol::Receive().
void ns3::Ipv4Header::SetProtocol | ( | uint8_t | num | ) |
num | the ipv4 protocol field |
Referenced by ns3::NscTcpL4Protocol::Receive(), ns3::TcpL4Protocol::Send(), and ns3::Ipv4RawSocketImpl::SendTo().
void ns3::Ipv4Header::SetSource | ( | Ipv4Address | source | ) |
source | the source of this packet |
Referenced by ns3::NscTcpL4Protocol::Receive().
void ns3::Ipv4Header::SetTos | ( | uint8_t | tos | ) |
tos | the 8 bits of Ipv4 TOS. |
void ns3::Ipv4Header::SetTtl | ( | uint8_t | ttl | ) |
ttl | the ipv4 TTL |
Referenced by ns3::NscTcpL4Protocol::Receive().