21 #include "ns3/assert.h"
22 #include "ns3/abort.h"
24 #include "ns3/header.h"
25 #include "ipv4-header.h"
31 NS_OBJECT_ENSURE_REGISTERED (Ipv4Header);
34 : m_calcChecksum (false),
43 m_goodChecksum (true),
52 m_calcChecksum =
true;
72 return m_identification;
78 m_identification = identification;
161 return "Unrecognized DSCP";
189 return "Unknown ECN";
203 m_flags |= MORE_FRAGMENTS;
209 m_flags &= ~MORE_FRAGMENTS;
215 return !(m_flags & MORE_FRAGMENTS);
222 m_flags |= DONT_FRAGMENT;
228 m_flags &= ~DONT_FRAGMENT;
234 return (m_flags & DONT_FRAGMENT);
242 NS_ABORT_MSG_IF ((offsetBytes & 0x7),
"offsetBytes must be multiple of 8 bytes");
243 m_fragmentOffset = offsetBytes;
249 if ((m_fragmentOffset+m_payloadSize+5*4) > 65535)
251 NS_LOG_WARN(
"Fragment will exceed the maximum packet size once reassembled");
254 return m_fragmentOffset;
280 m_protocol = protocol;
306 return m_destination;
314 return m_goodChecksum;
318 Ipv4Header::GetTypeId (
void)
322 .AddConstructor<Ipv4Header> ()
342 else if (m_flags & MORE_FRAGMENTS &&
343 m_flags & DONT_FRAGMENT)
347 else if (m_flags & DONT_FRAGMENT)
351 else if (m_flags & MORE_FRAGMENTS)
359 os <<
"tos 0x" << std::hex << m_tos << std::dec <<
" "
362 <<
"ttl " << m_ttl <<
" "
363 <<
"id " << m_identification <<
" "
364 <<
"protocol " << m_protocol <<
" "
365 <<
"offset (bytes) " << m_fragmentOffset <<
" "
366 <<
"flags [" << flags <<
"] "
367 <<
"length: " << (m_payloadSize + 5 * 4)
369 << m_source <<
" > " << m_destination
386 uint8_t verIhl = (4 << 4) | (5);
391 uint32_t fragmentOffset = m_fragmentOffset / 8;
392 uint8_t flagsFrag = (fragmentOffset >> 8) & 0x1f;
393 if (m_flags & DONT_FRAGMENT)
397 if (m_flags & MORE_FRAGMENTS)
402 uint8_t frag = fragmentOffset & 0xff;
425 uint8_t verIhl = i.
ReadU8 ();
426 uint8_t ihl = verIhl & 0x0f;
427 uint16_t headerSize = ihl * 4;
431 m_payloadSize = size - headerSize;
433 uint8_t flags = i.
ReadU8 ();
437 m_flags |= DONT_FRAGMENT;
441 m_flags |= MORE_FRAGMENTS;
444 m_fragmentOffset = i.
ReadU8 () & 0x1f;
445 m_fragmentOffset <<= 8;
446 m_fragmentOffset |= i.
ReadU8 ();
447 m_fragmentOffset <<= 3;
454 m_headerSize = headerSize;
462 m_goodChecksum = (checksum == 0);
uint16_t CalculateIpChecksum(uint16_t size)
Calculate the checksum.
#define NS_LOG_FUNCTION(parameters)
#define NS_ASSERT(condition)
#define NS_LOG_COMPONENT_DEFINE(name)
uint32_t ReadNtohU32(void)
iterator in a Buffer instance
void WriteU16(uint16_t data)
void WriteHtonU16(uint16_t data)
#define NS_LOG_LOGIC(msg)
void WriteHtonU32(uint32_t data)
void Set(uint32_t address)
Ipv4 addresses are stored in host order in this class.
void WriteU8(uint8_t data)
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if cond is true.
uint16_t ReadNtohU16(void)
a unique identifier for an interface.
TypeId SetParent(TypeId tid)