Bug 1102: IPv4 fragment offset
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
*/
|
||||
|
||||
#include "ns3/assert.h"
|
||||
#include "ns3/abort.h"
|
||||
#include "ns3/log.h"
|
||||
#include "ns3/header.h"
|
||||
#include "ipv4-header.h"
|
||||
@@ -71,8 +72,6 @@ Ipv4Header::SetIdentification (uint16_t identification)
|
||||
m_identification = identification;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
Ipv4Header::SetTos (uint8_t tos)
|
||||
{
|
||||
@@ -116,15 +115,20 @@ Ipv4Header::IsDontFragment (void) const
|
||||
}
|
||||
|
||||
void
|
||||
Ipv4Header::SetFragmentOffset (uint16_t offset)
|
||||
Ipv4Header::SetFragmentOffset (uint16_t offsetBytes)
|
||||
{
|
||||
NS_ASSERT (!(offset & (~0x3fff)));
|
||||
m_fragmentOffset = offset;
|
||||
// check if the user is trying to set an invalid offset
|
||||
NS_ABORT_MSG_IF ((offsetBytes & 0x7), "offsetBytes must be multiple of 8 bytes");
|
||||
m_fragmentOffset = offsetBytes;
|
||||
}
|
||||
uint16_t
|
||||
Ipv4Header::GetFragmentOffset (void) const
|
||||
{
|
||||
NS_ASSERT (!(m_fragmentOffset & (~0x3fff)));
|
||||
if ((m_fragmentOffset+m_payloadSize+5*4) > 65535)
|
||||
{
|
||||
NS_LOG_WARN("Fragment will exceed the maximum packet size once reassembled");
|
||||
}
|
||||
|
||||
return m_fragmentOffset;
|
||||
}
|
||||
|
||||
@@ -223,7 +227,7 @@ Ipv4Header::Print (std::ostream &os) const
|
||||
<< "ttl " << m_ttl << " "
|
||||
<< "id " << m_identification << " "
|
||||
<< "protocol " << m_protocol << " "
|
||||
<< "offset " << m_fragmentOffset << " "
|
||||
<< "offset (bytes) " << m_fragmentOffset << " "
|
||||
<< "flags [" << flags << "] "
|
||||
<< "length: " << (m_payloadSize + 5 * 4)
|
||||
<< " "
|
||||
|
||||
@@ -70,9 +70,12 @@ public:
|
||||
*/
|
||||
void SetMayFragment (void);
|
||||
/**
|
||||
* \param offset the ipv4 fragment offset
|
||||
* 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.
|
||||
* \param offsetBytes the ipv4 fragment offset measured in bytes from the start.
|
||||
*/
|
||||
void SetFragmentOffset (uint16_t offset);
|
||||
void SetFragmentOffset (uint16_t offsetBytes);
|
||||
/**
|
||||
* \param ttl the ipv4 TTL
|
||||
*/
|
||||
@@ -110,7 +113,7 @@ public:
|
||||
*/
|
||||
bool IsDontFragment (void) const;
|
||||
/**
|
||||
* \returns the offset of this fragment.
|
||||
* \returns the offset of this fragment measured in bytes from the start.
|
||||
*/
|
||||
uint16_t GetFragmentOffset (void) const;
|
||||
/**
|
||||
@@ -159,7 +162,7 @@ private:
|
||||
uint32_t m_ttl : 8;
|
||||
uint32_t m_protocol : 8;
|
||||
uint32_t m_flags : 3;
|
||||
uint16_t m_fragmentOffset : 13;
|
||||
uint16_t m_fragmentOffset;
|
||||
Ipv4Address m_source;
|
||||
Ipv4Address m_destination;
|
||||
uint16_t m_checksum;
|
||||
|
||||
Reference in New Issue
Block a user