Packet header for IPv4. More...
#include <ipv4-header.h>
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 | SetMoreFragments (void) |
void | SetLastFragment (void) |
void | SetDontFragment (void) |
void | SetMayFragment (void) |
void | SetFragmentOffset (uint16_t offset) |
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 |
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. | |
Private Types | |
enum | FlagsE { DONT_FRAGMENT = (1<<0), MORE_FRAGMENTS = (1<<1) } |
Private Attributes | |
bool | m_calcChecksum |
uint16_t | m_payloadSize |
uint16_t | m_identification |
uint32_t | m_tos: 8 |
uint32_t | m_ttl: 8 |
uint32_t | m_protocol: 8 |
uint32_t | m_flags: 3 |
uint16_t | m_fragmentOffset: 13 |
Ipv4Address | m_source |
Ipv4Address | m_destination |
uint16_t | m_checksum |
bool | m_goodChecksum |
Packet header for IPv4.
Definition at line 31 of file ipv4-header.h.
enum ns3::Ipv4Header::FlagsE [private] |
Definition at line 149 of file ipv4-header.h.
ns3::Ipv4Header::Ipv4Header | ( | ) |
Construct a null IPv4 header.
Definition at line 32 of file ipv4-header.cc.
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.
Definition at line 278 of file ipv4-header.cc.
References ns3::Buffer::Iterator::CalculateIpChecksum(), DONT_FRAGMENT, GetSerializedSize(), m_calcChecksum, m_checksum, m_destination, m_flags, m_fragmentOffset, m_goodChecksum, m_identification, m_payloadSize, m_protocol, m_source, m_tos, m_ttl, MORE_FRAGMENTS, 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(), and ns3::Icmpv4DestinationUnreachable::Deserialize().
void ns3::Ipv4Header::EnableChecksum | ( | void | ) |
Enable checksum calculation for this header.
Definition at line 46 of file ipv4-header.cc.
References m_calcChecksum.
Referenced by ns3::NscTcpL4Protocol::Receive(), ns3::Ipv4L3Protocol::Receive(), and ns3::Ipv4L3Protocol::Send().
Ipv4Address ns3::Ipv4Header::GetDestination | ( | void | ) | const |
Definition at line 169 of file ipv4-header.cc.
References m_destination.
Referenced by ns3::Ipv4L3Protocol::DoForward(), ns3::Ipv4L3Protocol::Forwarding(), ns3::Ipv4RawSocketImpl::ForwardUp(), ns3::Ipv4L3Protocol::ForwardUp(), ns3::Icmpv4L4Protocol::HandleDestUnreach(), ns3::Ipv4L3Protocol::Lookup(), ns3::olsr::RoutingTable::RequestRoute(), ns3::Ipv4StaticRouting::RequestRoute(), ns3::Ipv4GlobalRouting::RequestRoute(), ns3::Ipv4L3Protocol::Send(), and ns3::Ipv4L3Protocol::SendRealOut().
uint16_t ns3::Ipv4Header::GetFragmentOffset | ( | void | ) | const |
Definition at line 124 of file ipv4-header.cc.
References m_fragmentOffset, and NS_ASSERT.
uint16_t ns3::Ipv4Header::GetIdentification | ( | void | ) | const |
Definition at line 63 of file ipv4-header.cc.
References m_identification.
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.
Definition at line 191 of file ipv4-header.cc.
References GetTypeId().
uint16_t ns3::Ipv4Header::GetPayloadSize | ( | void | ) | const |
Definition at line 57 of file ipv4-header.cc.
References m_payloadSize.
uint8_t ns3::Ipv4Header::GetProtocol | ( | void | ) | const |
Definition at line 142 of file ipv4-header.cc.
References m_protocol.
Referenced by ns3::Ipv4RawSocketImpl::ForwardUp(), and ns3::Ipv4L3Protocol::ForwardUp().
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.
Definition at line 233 of file ipv4-header.cc.
Referenced by Deserialize(), ns3::Icmpv4TimeExceeded::GetSerializedSize(), ns3::Icmpv4DestinationUnreachable::GetSerializedSize(), ns3::Icmpv4TimeExceeded::Serialize(), and ns3::Icmpv4DestinationUnreachable::Serialize().
Ipv4Address ns3::Ipv4Header::GetSource | ( | void | ) | const |
Definition at line 158 of file ipv4-header.cc.
References m_source.
Referenced by ns3::Ipv4L3Protocol::Forwarding(), ns3::Ipv4RawSocketImpl::ForwardUp(), ns3::Ipv4L3Protocol::ForwardUp(), ns3::Icmpv4L4Protocol::HandleDestUnreach(), ns3::Ipv4StaticRouting::RequestRoute(), and ns3::Ipv4GlobalRouting::RequestRoute().
uint8_t ns3::Ipv4Header::GetTos | ( | void | ) | const |
Definition at line 81 of file ipv4-header.cc.
References m_tos.
uint8_t ns3::Ipv4Header::GetTtl | ( | void | ) | const |
Definition at line 136 of file ipv4-header.cc.
References m_ttl.
Referenced by ns3::Ipv4L3Protocol::DoForward(), and ns3::Icmpv4L4Protocol::HandleDestUnreach().
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.
Definition at line 182 of file ipv4-header.cc.
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.
Definition at line 176 of file ipv4-header.cc.
References m_goodChecksum.
Referenced by ns3::Ipv4L3Protocol::Receive().
bool ns3::Ipv4Header::IsDontFragment | ( | void | ) | const |
Definition at line 112 of file ipv4-header.cc.
References DONT_FRAGMENT, and m_flags.
Referenced by ns3::Ipv4L3Protocol::Send(), and ns3::Ipv4L3Protocol::SendRealOut().
bool ns3::Ipv4Header::IsLastFragment | ( | void | ) | const |
Definition at line 96 of file ipv4-header.cc.
References m_flags, and MORE_FRAGMENTS.
void ns3::Ipv4Header::Print | ( | std::ostream & | os | ) | const [virtual] |
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.
Definition at line 196 of file ipv4-header.cc.
References DONT_FRAGMENT, m_destination, m_flags, m_fragmentOffset, m_identification, m_payloadSize, m_protocol, m_source, m_tos, m_ttl, and MORE_FRAGMENTS.
Referenced by ns3::Icmpv4TimeExceeded::Print(), and ns3::Icmpv4DestinationUnreachable::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.
Definition at line 239 of file ipv4-header.cc.
References ns3::Buffer::Iterator::CalculateIpChecksum(), DONT_FRAGMENT, ns3::Ipv4Address::Get(), m_calcChecksum, m_destination, m_flags, m_fragmentOffset, m_identification, m_payloadSize, m_protocol, m_source, m_tos, m_ttl, MORE_FRAGMENTS, 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(), and ns3::Icmpv4DestinationUnreachable::Serialize().
void ns3::Ipv4Header::SetDestination | ( | Ipv4Address | destination | ) |
destination | the destination of this packet. |
Definition at line 164 of file ipv4-header.cc.
References m_destination.
Referenced by ns3::NscTcpL4Protocol::Receive(), and ns3::Ipv4L3Protocol::Send().
void ns3::Ipv4Header::SetDontFragment | ( | void | ) |
Don't fragment this packet: if you need to anyway, drop it.
Definition at line 102 of file ipv4-header.cc.
References DONT_FRAGMENT, and m_flags.
Referenced by ns3::Ipv4L3Protocol::Send().
void ns3::Ipv4Header::SetFragmentOffset | ( | uint16_t | offset | ) |
offset | the ipv4 fragment offset |
Definition at line 118 of file ipv4-header.cc.
References m_fragmentOffset, and NS_ASSERT.
void ns3::Ipv4Header::SetIdentification | ( | uint16_t | identification | ) |
identification | the Identification field of IPv4 packets. |
By default, set to zero.
Definition at line 68 of file ipv4-header.cc.
References m_identification.
Referenced by ns3::Ipv4L3Protocol::Send().
void ns3::Ipv4Header::SetLastFragment | ( | void | ) |
This packet is the last packet of a fragmented ipv4 packet.
Definition at line 91 of file ipv4-header.cc.
References m_flags, and MORE_FRAGMENTS.
void ns3::Ipv4Header::SetMayFragment | ( | void | ) |
If you need to fragment this packet, you can do it.
Definition at line 107 of file ipv4-header.cc.
References DONT_FRAGMENT, and m_flags.
Referenced by ns3::Ipv4L3Protocol::Send().
void ns3::Ipv4Header::SetMoreFragments | ( | void | ) |
This packet is not the last packet of a fragmented ipv4 packet.
Definition at line 86 of file ipv4-header.cc.
References m_flags, and MORE_FRAGMENTS.
void ns3::Ipv4Header::SetPayloadSize | ( | uint16_t | size | ) |
size | the size of the payload in bytes |
Definition at line 52 of file ipv4-header.cc.
References m_payloadSize.
Referenced by ns3::NscTcpL4Protocol::Receive(), and ns3::Ipv4L3Protocol::Send().
void ns3::Ipv4Header::SetProtocol | ( | uint8_t | num | ) |
num | the ipv4 protocol field |
Definition at line 147 of file ipv4-header.cc.
References m_protocol.
Referenced by ns3::NscTcpL4Protocol::Receive(), and ns3::Ipv4L3Protocol::Send().
void ns3::Ipv4Header::SetSource | ( | Ipv4Address | source | ) |
source | the source of this packet |
Definition at line 153 of file ipv4-header.cc.
References m_source.
Referenced by ns3::NscTcpL4Protocol::Receive(), and ns3::Ipv4L3Protocol::Send().
void ns3::Ipv4Header::SetTos | ( | uint8_t | tos | ) |
tos | the 8 bits of Ipv4 TOS. |
Definition at line 76 of file ipv4-header.cc.
References m_tos.
void ns3::Ipv4Header::SetTtl | ( | uint8_t | ttl | ) |
ttl | the ipv4 TTL |
Definition at line 131 of file ipv4-header.cc.
References m_ttl.
Referenced by ns3::Ipv4L3Protocol::DoForward(), ns3::NscTcpL4Protocol::Receive(), and ns3::Ipv4L3Protocol::Send().
bool ns3::Ipv4Header::m_calcChecksum [private] |
Definition at line 154 of file ipv4-header.h.
Referenced by Deserialize(), EnableChecksum(), and Serialize().
uint16_t ns3::Ipv4Header::m_checksum [private] |
Definition at line 165 of file ipv4-header.h.
Referenced by Deserialize().
Ipv4Address ns3::Ipv4Header::m_destination [private] |
Definition at line 164 of file ipv4-header.h.
Referenced by Deserialize(), GetDestination(), Print(), Serialize(), and SetDestination().
uint32_t ns3::Ipv4Header::m_flags [private] |
Definition at line 161 of file ipv4-header.h.
Referenced by Deserialize(), IsDontFragment(), IsLastFragment(), Print(), Serialize(), SetDontFragment(), SetLastFragment(), SetMayFragment(), and SetMoreFragments().
uint16_t ns3::Ipv4Header::m_fragmentOffset [private] |
Definition at line 162 of file ipv4-header.h.
Referenced by Deserialize(), GetFragmentOffset(), Print(), Serialize(), and SetFragmentOffset().
bool ns3::Ipv4Header::m_goodChecksum [private] |
Definition at line 166 of file ipv4-header.h.
Referenced by Deserialize(), and IsChecksumOk().
uint16_t ns3::Ipv4Header::m_identification [private] |
Definition at line 157 of file ipv4-header.h.
Referenced by Deserialize(), GetIdentification(), Print(), Serialize(), and SetIdentification().
uint16_t ns3::Ipv4Header::m_payloadSize [private] |
Definition at line 156 of file ipv4-header.h.
Referenced by Deserialize(), GetPayloadSize(), Print(), Serialize(), and SetPayloadSize().
uint32_t ns3::Ipv4Header::m_protocol [private] |
Definition at line 160 of file ipv4-header.h.
Referenced by Deserialize(), GetProtocol(), Print(), Serialize(), and SetProtocol().
Ipv4Address ns3::Ipv4Header::m_source [private] |
Definition at line 163 of file ipv4-header.h.
Referenced by Deserialize(), GetSource(), Print(), Serialize(), and SetSource().
uint32_t ns3::Ipv4Header::m_tos [private] |
Definition at line 158 of file ipv4-header.h.
Referenced by Deserialize(), GetTos(), Print(), Serialize(), and SetTos().
uint32_t ns3::Ipv4Header::m_ttl [private] |
Definition at line 159 of file ipv4-header.h.
Referenced by Deserialize(), GetTtl(), Print(), Serialize(), and SetTtl().