bug 207: ipv4-header.h needed in src/node module.
--- a/src/internet-node/ipv4-header.cc Wed Jun 04 10:09:29 2008 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,331 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2005 INRIA
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-
-#include "ns3/assert.h"
-#include "ns3/log.h"
-#include "ns3/header.h"
-#include "ipv4-header.h"
-
-NS_LOG_COMPONENT_DEFINE ("Ipv4Header");
-
-namespace ns3 {
-
-NS_OBJECT_ENSURE_REGISTERED (Ipv4Header);
-
-bool Ipv4Header::m_calcChecksum = false;
-
-Ipv4Header::Ipv4Header ()
- : m_payloadSize (0),
- m_identification (0),
- m_tos (0),
- m_ttl (0),
- m_protocol (0),
- m_flags (0),
- m_fragmentOffset (0),
- m_goodChecksum (true)
-{}
-
-void
-Ipv4Header::EnableChecksums (void)
-{
- m_calcChecksum = true;
-}
-
-void
-Ipv4Header::SetPayloadSize (uint16_t size)
-{
- m_payloadSize = size;
-}
-uint16_t
-Ipv4Header::GetPayloadSize (void) const
-{
- return m_payloadSize;
-}
-
-uint16_t
-Ipv4Header::GetIdentification (void) const
-{
- return m_identification;
-}
-void
-Ipv4Header::SetIdentification (uint16_t identification)
-{
- m_identification = identification;
-}
-
-
-
-void
-Ipv4Header::SetTos (uint8_t tos)
-{
- m_tos = tos;
-}
-uint8_t
-Ipv4Header::GetTos (void) const
-{
- return m_tos;
-}
-void
-Ipv4Header::SetMoreFragments (void)
-{
- m_flags |= MORE_FRAGMENTS;
-}
-void
-Ipv4Header::SetLastFragment (void)
-{
- m_flags &= ~MORE_FRAGMENTS;
-}
-bool
-Ipv4Header::IsLastFragment (void) const
-{
- return !(m_flags & MORE_FRAGMENTS);
-}
-
-void
-Ipv4Header::SetDontFragment (void)
-{
- m_flags |= DONT_FRAGMENT;
-}
-void
-Ipv4Header::SetMayFragment (void)
-{
- m_flags &= ~DONT_FRAGMENT;
-}
-bool
-Ipv4Header::IsDontFragment (void) const
-{
- return (m_flags & DONT_FRAGMENT);
-}
-
-void
-Ipv4Header::SetFragmentOffset (uint16_t offset)
-{
- NS_ASSERT (!(offset & (~0x3fff)));
- m_fragmentOffset = offset;
-}
-uint16_t
-Ipv4Header::GetFragmentOffset (void) const
-{
- NS_ASSERT (!(m_fragmentOffset & (~0x3fff)));
- return m_fragmentOffset;
-}
-
-void
-Ipv4Header::SetTtl (uint8_t ttl)
-{
- m_ttl = ttl;
-}
-uint8_t
-Ipv4Header::GetTtl (void) const
-{
- return m_ttl;
-}
-
-uint8_t
-Ipv4Header::GetProtocol (void) const
-{
- return m_protocol;
-}
-void
-Ipv4Header::SetProtocol (uint8_t protocol)
-{
- m_protocol = protocol;
-}
-
-void
-Ipv4Header::SetSource (Ipv4Address source)
-{
- m_source = source;
-}
-Ipv4Address
-Ipv4Header::GetSource (void) const
-{
- return m_source;
-}
-
-void
-Ipv4Header::SetDestination (Ipv4Address dst)
-{
- m_destination = dst;
-}
-Ipv4Address
-Ipv4Header::GetDestination (void) const
-{
- return m_destination;
-}
-
-
-bool
-Ipv4Header::IsChecksumOk (void) const
-{
- return m_goodChecksum;
-}
-
-
-TypeId
-Ipv4Header::GetTypeId (void)
-{
- static TypeId tid = TypeId ("ns3::Ipv4Header")
- .SetParent<Header> ()
- .AddConstructor<Ipv4Header> ()
- ;
- return tid;
-}
-TypeId
-Ipv4Header::GetInstanceTypeId (void) const
-{
- return GetTypeId ();
-}
-void
-Ipv4Header::Print (std::ostream &os) const
-{
- // ipv4, right ?
- std::string flags;
- if (m_flags == 0)
- {
- flags = "none";
- }
- else if (m_flags & MORE_FRAGMENTS &&
- m_flags & DONT_FRAGMENT)
- {
- flags = "MF|DF";
- }
- else if (m_flags & DONT_FRAGMENT)
- {
- flags = "DF";
- }
- else if (m_flags & MORE_FRAGMENTS)
- {
- flags = "MF";
- }
- else
- {
- flags = "XX";
- }
- os << "tos 0x" << std::hex << m_tos << std::dec << " "
- << "ttl " << m_ttl << " "
- << "id " << m_identification << " "
- << "offset " << m_fragmentOffset << " "
- << "flags [" << flags << "] "
- << "length: " << (m_payloadSize + 5 * 4)
- << " "
- << m_source << " > " << m_destination
- ;
-}
-uint32_t
-Ipv4Header::GetSerializedSize (void) const
-{
- return 5 * 4;
-}
-
-void
-Ipv4Header::Serialize (Buffer::Iterator start) const
-{
- Buffer::Iterator i = start;
-
- uint8_t verIhl = (4 << 4) | (5);
- i.WriteU8 (verIhl);
- i.WriteU8 (m_tos);
- i.WriteHtonU16 (m_payloadSize + 5*4);
- i.WriteHtonU16 (m_identification);
- uint32_t fragmentOffset = m_fragmentOffset / 8;
- uint8_t flagsFrag = (fragmentOffset >> 8) & 0x1f;
- if (m_flags & DONT_FRAGMENT)
- {
- flagsFrag |= (1<<6);
- }
- if (m_flags & MORE_FRAGMENTS)
- {
- flagsFrag |= (1<<5);
- }
- i.WriteU8 (flagsFrag);
- uint8_t frag = fragmentOffset & 0xff;
- i.WriteU8 (frag);
- i.WriteU8 (m_ttl);
- i.WriteU8 (m_protocol);
- i.WriteHtonU16 (0);
- i.WriteHtonU32 (m_source.Get ());
- i.WriteHtonU32 (m_destination.Get ());
-
- if (m_calcChecksum)
- {
-#if 0
- // XXX we need to add Buffer::Iterator::PeekData method
- uint8_t *data = start.PeekData ();
- uint16_t checksum = UtilsChecksumCalculate (0, data, GetSize ());
- checksum = UtilsChecksumComplete (checksum);
- NS_LOG_LOGIC ("checksum=" <<checksum);
- i = start;
- i.Next (10);
- i.WriteU16 (checksum);
-#endif
- }
-}
-uint32_t
-Ipv4Header::Deserialize (Buffer::Iterator start)
-{
- Buffer::Iterator i = start;
- uint8_t verIhl = i.ReadU8 ();
- uint8_t ihl = verIhl & 0x0f;
- uint16_t headerSize = ihl * 4;
- NS_ASSERT ((verIhl >> 4) == 4);
- m_tos = i.ReadU8 ();
- uint16_t size = i.ReadNtohU16 ();
- m_payloadSize = size - headerSize;
- m_identification = i.ReadNtohU16 ();
- uint8_t flags = i.ReadU8 ();
- m_flags = 0;
- if (flags & (1<<6))
- {
- m_flags |= DONT_FRAGMENT;
- }
- if (flags & (1<<5))
- {
- m_flags |= MORE_FRAGMENTS;
- }
- //XXXX I think we should clear some bits in fragmentOffset !
- i.Prev ();
- m_fragmentOffset = i.ReadNtohU16 ();
- m_fragmentOffset *= 8;
- m_ttl = i.ReadU8 ();
- m_protocol = i.ReadU8 ();
- i.Next (2); // checksum
- m_source.Set (i.ReadNtohU32 ());
- m_destination.Set (i.ReadNtohU32 ());
-
- if (m_calcChecksum)
- {
-#if 0
- uint8_t *data = start.PeekData ();
- uint16_t localChecksum = UtilsChecksumCalculate (0, data, headerSize);
- if (localChecksum == 0xffff)
- {
- m_goodChecksum = true;
- }
- else
- {
- m_goodChecksum = false;
- }
-#endif
- }
- return GetSerializedSize ();
-}
-
-}; // namespace ns3
--- a/src/internet-node/ipv4-header.h Wed Jun 04 10:09:29 2008 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,171 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2005 INRIA
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-
-#ifndef IPV4_HEADER_H
-#define IPV4_HEADER_H
-
-#include "ns3/header.h"
-#include "ns3/ipv4-address.h"
-
-namespace ns3 {
-/**
- * \brief Packet header for IPv4
- */
-class Ipv4Header : public Header
-{
-public:
- /**
- * \brief Construct a null IPv4 header
- */
- Ipv4Header ();
- /**
- * \brief Enable checksum calculation for IP (XXX currently has no effect)
- */
- static void EnableChecksums (void);
- /**
- * \param size the size of the payload in bytes
- */
- void SetPayloadSize (uint16_t size);
- /**
- * \param identification the Identification field of IPv4 packets.
- *
- * By default, set to zero.
- */
- void SetIdentification (uint16_t identification);
- /**
- * \param tos the 8 bits of Ipv4 TOS.
- */
- void SetTos (uint8_t tos);
- /**
- * This packet is not the last packet of a fragmented ipv4 packet.
- */
- void SetMoreFragments (void);
- /**
- * This packet is the last packet of a fragmented ipv4 packet.
- */
- void SetLastFragment (void);
- /**
- * Don't fragment this packet: if you need to anyway, drop it.
- */
- void SetDontFragment (void);
- /**
- * If you need to fragment this packet, you can do it.
- */
- void SetMayFragment (void);
- /**
- * \param offset the ipv4 fragment offset
- */
- void SetFragmentOffset (uint16_t offset);
- /**
- * \param ttl the ipv4 TTL
- */
- void SetTtl (uint8_t ttl);
- /**
- * \param num the ipv4 protocol field
- */
- void SetProtocol (uint8_t num);
- /**
- * \param source the source of this packet
- */
- void SetSource (Ipv4Address source);
- /**
- * \param destination the destination of this packet.
- */
- void SetDestination (Ipv4Address destination);
- /**
- * \returns the size of the payload in bytes
- */
- uint16_t GetPayloadSize (void) const;
- /**
- * \returns the identification field of this packet.
- */
- uint16_t GetIdentification (void) const;
- /**
- * \returns the TOS field of this packet.
- */
- uint8_t GetTos (void) const;
- /**
- * \returns true if this is the last fragment of a packet, false otherwise.
- */
- bool IsLastFragment (void) const;
- /**
- * \returns true if this is this packet can be fragmented.
- */
- bool IsDontFragment (void) const;
- /**
- * \returns the offset of this fragment.
- */
- uint16_t GetFragmentOffset (void) const;
- /**
- * \returns the TTL field of this packet
- */
- uint8_t GetTtl (void) const;
- /**
- * \returns the protocol field of this packet
- */
- uint8_t GetProtocol (void) const;
- /**
- * \returns the source address of this packet
- */
- Ipv4Address GetSource (void) const;
- /**
- * \returns the destination address of this packet
- */
- Ipv4Address GetDestination (void) const;
-
- /**
- * \returns true if the upv4 checksum is correct, false otherwise.
- *
- * If Ipv4Header::EnableChecksums has not been called prior to
- * creating this packet, this method will always return true.
- */
- bool IsChecksumOk (void) const;
-
- static TypeId GetTypeId (void);
- 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);
-private:
-
- enum FlagsE {
- DONT_FRAGMENT = (1<<0),
- MORE_FRAGMENTS = (1<<1)
- };
-
- static 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;
- bool m_goodChecksum;
-};
-
-} // namespace ns3
-
-
-#endif /* IPV4_HEADER_H */
--- a/src/internet-node/ipv4-l3-protocol.cc Wed Jun 04 10:09:29 2008 -0700
+++ b/src/internet-node/ipv4-l3-protocol.cc Wed Jun 04 10:18:57 2008 -0700
@@ -29,11 +29,11 @@
#include "ns3/uinteger.h"
#include "ns3/trace-source-accessor.h"
#include "ns3/object-vector.h"
+#include "ns3/ipv4-header.h"
#include "arp-l3-protocol.h"
#include "ipv4-l3-protocol.h"
#include "ipv4-l4-protocol.h"
-#include "ipv4-header.h"
#include "ipv4-interface.h"
#include "ipv4-loopback-interface.h"
#include "arp-ipv4-interface.h"
--- a/src/internet-node/ipv4-l3-protocol.h Wed Jun 04 10:09:29 2008 -0700
+++ b/src/internet-node/ipv4-l3-protocol.h Wed Jun 04 10:18:57 2008 -0700
@@ -27,7 +27,7 @@
#include "ns3/ptr.h"
#include "ns3/ipv4.h"
#include "ns3/traced-callback.h"
-#include "ipv4-header.h"
+#include "ns3/ipv4-header.h"
#include "ipv4-static-routing.h"
namespace ns3 {
--- a/src/internet-node/ipv4-static-routing.h Wed Jun 04 10:09:29 2008 -0700
+++ b/src/internet-node/ipv4-static-routing.h Wed Jun 04 10:18:57 2008 -0700
@@ -25,7 +25,7 @@
#include <list>
#include <stdint.h>
#include "ns3/ipv4-address.h"
-#include "ipv4-header.h"
+#include "ns3/ipv4-header.h"
#include "ns3/ptr.h"
#include "ns3/ipv4.h"
--- a/src/internet-node/wscript Wed Jun 04 10:09:29 2008 -0700
+++ b/src/internet-node/wscript Wed Jun 04 10:18:57 2008 -0700
@@ -7,7 +7,6 @@
'internet-stack.cc',
'ipv4-l4-demux.cc',
'ipv4-l4-protocol.cc',
- 'ipv4-header.cc',
'udp-header.cc',
'tcp-header.cc',
'ipv4-checksum.cc',
@@ -37,7 +36,6 @@
headers.module = 'internet-node'
headers.source = [
'internet-stack.h',
- 'ipv4-header.h',
'udp-header.h',
'tcp-header.h',
'sequence-number.h',
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/node/ipv4-header.cc Wed Jun 04 10:18:57 2008 -0700
@@ -0,0 +1,331 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2005 INRIA
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+
+#include "ns3/assert.h"
+#include "ns3/log.h"
+#include "ns3/header.h"
+#include "ipv4-header.h"
+
+NS_LOG_COMPONENT_DEFINE ("Ipv4Header");
+
+namespace ns3 {
+
+NS_OBJECT_ENSURE_REGISTERED (Ipv4Header);
+
+bool Ipv4Header::m_calcChecksum = false;
+
+Ipv4Header::Ipv4Header ()
+ : m_payloadSize (0),
+ m_identification (0),
+ m_tos (0),
+ m_ttl (0),
+ m_protocol (0),
+ m_flags (0),
+ m_fragmentOffset (0),
+ m_goodChecksum (true)
+{}
+
+void
+Ipv4Header::EnableChecksums (void)
+{
+ m_calcChecksum = true;
+}
+
+void
+Ipv4Header::SetPayloadSize (uint16_t size)
+{
+ m_payloadSize = size;
+}
+uint16_t
+Ipv4Header::GetPayloadSize (void) const
+{
+ return m_payloadSize;
+}
+
+uint16_t
+Ipv4Header::GetIdentification (void) const
+{
+ return m_identification;
+}
+void
+Ipv4Header::SetIdentification (uint16_t identification)
+{
+ m_identification = identification;
+}
+
+
+
+void
+Ipv4Header::SetTos (uint8_t tos)
+{
+ m_tos = tos;
+}
+uint8_t
+Ipv4Header::GetTos (void) const
+{
+ return m_tos;
+}
+void
+Ipv4Header::SetMoreFragments (void)
+{
+ m_flags |= MORE_FRAGMENTS;
+}
+void
+Ipv4Header::SetLastFragment (void)
+{
+ m_flags &= ~MORE_FRAGMENTS;
+}
+bool
+Ipv4Header::IsLastFragment (void) const
+{
+ return !(m_flags & MORE_FRAGMENTS);
+}
+
+void
+Ipv4Header::SetDontFragment (void)
+{
+ m_flags |= DONT_FRAGMENT;
+}
+void
+Ipv4Header::SetMayFragment (void)
+{
+ m_flags &= ~DONT_FRAGMENT;
+}
+bool
+Ipv4Header::IsDontFragment (void) const
+{
+ return (m_flags & DONT_FRAGMENT);
+}
+
+void
+Ipv4Header::SetFragmentOffset (uint16_t offset)
+{
+ NS_ASSERT (!(offset & (~0x3fff)));
+ m_fragmentOffset = offset;
+}
+uint16_t
+Ipv4Header::GetFragmentOffset (void) const
+{
+ NS_ASSERT (!(m_fragmentOffset & (~0x3fff)));
+ return m_fragmentOffset;
+}
+
+void
+Ipv4Header::SetTtl (uint8_t ttl)
+{
+ m_ttl = ttl;
+}
+uint8_t
+Ipv4Header::GetTtl (void) const
+{
+ return m_ttl;
+}
+
+uint8_t
+Ipv4Header::GetProtocol (void) const
+{
+ return m_protocol;
+}
+void
+Ipv4Header::SetProtocol (uint8_t protocol)
+{
+ m_protocol = protocol;
+}
+
+void
+Ipv4Header::SetSource (Ipv4Address source)
+{
+ m_source = source;
+}
+Ipv4Address
+Ipv4Header::GetSource (void) const
+{
+ return m_source;
+}
+
+void
+Ipv4Header::SetDestination (Ipv4Address dst)
+{
+ m_destination = dst;
+}
+Ipv4Address
+Ipv4Header::GetDestination (void) const
+{
+ return m_destination;
+}
+
+
+bool
+Ipv4Header::IsChecksumOk (void) const
+{
+ return m_goodChecksum;
+}
+
+
+TypeId
+Ipv4Header::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::Ipv4Header")
+ .SetParent<Header> ()
+ .AddConstructor<Ipv4Header> ()
+ ;
+ return tid;
+}
+TypeId
+Ipv4Header::GetInstanceTypeId (void) const
+{
+ return GetTypeId ();
+}
+void
+Ipv4Header::Print (std::ostream &os) const
+{
+ // ipv4, right ?
+ std::string flags;
+ if (m_flags == 0)
+ {
+ flags = "none";
+ }
+ else if (m_flags & MORE_FRAGMENTS &&
+ m_flags & DONT_FRAGMENT)
+ {
+ flags = "MF|DF";
+ }
+ else if (m_flags & DONT_FRAGMENT)
+ {
+ flags = "DF";
+ }
+ else if (m_flags & MORE_FRAGMENTS)
+ {
+ flags = "MF";
+ }
+ else
+ {
+ flags = "XX";
+ }
+ os << "tos 0x" << std::hex << m_tos << std::dec << " "
+ << "ttl " << m_ttl << " "
+ << "id " << m_identification << " "
+ << "offset " << m_fragmentOffset << " "
+ << "flags [" << flags << "] "
+ << "length: " << (m_payloadSize + 5 * 4)
+ << " "
+ << m_source << " > " << m_destination
+ ;
+}
+uint32_t
+Ipv4Header::GetSerializedSize (void) const
+{
+ return 5 * 4;
+}
+
+void
+Ipv4Header::Serialize (Buffer::Iterator start) const
+{
+ Buffer::Iterator i = start;
+
+ uint8_t verIhl = (4 << 4) | (5);
+ i.WriteU8 (verIhl);
+ i.WriteU8 (m_tos);
+ i.WriteHtonU16 (m_payloadSize + 5*4);
+ i.WriteHtonU16 (m_identification);
+ uint32_t fragmentOffset = m_fragmentOffset / 8;
+ uint8_t flagsFrag = (fragmentOffset >> 8) & 0x1f;
+ if (m_flags & DONT_FRAGMENT)
+ {
+ flagsFrag |= (1<<6);
+ }
+ if (m_flags & MORE_FRAGMENTS)
+ {
+ flagsFrag |= (1<<5);
+ }
+ i.WriteU8 (flagsFrag);
+ uint8_t frag = fragmentOffset & 0xff;
+ i.WriteU8 (frag);
+ i.WriteU8 (m_ttl);
+ i.WriteU8 (m_protocol);
+ i.WriteHtonU16 (0);
+ i.WriteHtonU32 (m_source.Get ());
+ i.WriteHtonU32 (m_destination.Get ());
+
+ if (m_calcChecksum)
+ {
+#if 0
+ // XXX we need to add Buffer::Iterator::PeekData method
+ uint8_t *data = start.PeekData ();
+ uint16_t checksum = UtilsChecksumCalculate (0, data, GetSize ());
+ checksum = UtilsChecksumComplete (checksum);
+ NS_LOG_LOGIC ("checksum=" <<checksum);
+ i = start;
+ i.Next (10);
+ i.WriteU16 (checksum);
+#endif
+ }
+}
+uint32_t
+Ipv4Header::Deserialize (Buffer::Iterator start)
+{
+ Buffer::Iterator i = start;
+ uint8_t verIhl = i.ReadU8 ();
+ uint8_t ihl = verIhl & 0x0f;
+ uint16_t headerSize = ihl * 4;
+ NS_ASSERT ((verIhl >> 4) == 4);
+ m_tos = i.ReadU8 ();
+ uint16_t size = i.ReadNtohU16 ();
+ m_payloadSize = size - headerSize;
+ m_identification = i.ReadNtohU16 ();
+ uint8_t flags = i.ReadU8 ();
+ m_flags = 0;
+ if (flags & (1<<6))
+ {
+ m_flags |= DONT_FRAGMENT;
+ }
+ if (flags & (1<<5))
+ {
+ m_flags |= MORE_FRAGMENTS;
+ }
+ //XXXX I think we should clear some bits in fragmentOffset !
+ i.Prev ();
+ m_fragmentOffset = i.ReadNtohU16 ();
+ m_fragmentOffset *= 8;
+ m_ttl = i.ReadU8 ();
+ m_protocol = i.ReadU8 ();
+ i.Next (2); // checksum
+ m_source.Set (i.ReadNtohU32 ());
+ m_destination.Set (i.ReadNtohU32 ());
+
+ if (m_calcChecksum)
+ {
+#if 0
+ uint8_t *data = start.PeekData ();
+ uint16_t localChecksum = UtilsChecksumCalculate (0, data, headerSize);
+ if (localChecksum == 0xffff)
+ {
+ m_goodChecksum = true;
+ }
+ else
+ {
+ m_goodChecksum = false;
+ }
+#endif
+ }
+ return GetSerializedSize ();
+}
+
+}; // namespace ns3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/node/ipv4-header.h Wed Jun 04 10:18:57 2008 -0700
@@ -0,0 +1,171 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2005 INRIA
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+
+#ifndef IPV4_HEADER_H
+#define IPV4_HEADER_H
+
+#include "ns3/header.h"
+#include "ns3/ipv4-address.h"
+
+namespace ns3 {
+/**
+ * \brief Packet header for IPv4
+ */
+class Ipv4Header : public Header
+{
+public:
+ /**
+ * \brief Construct a null IPv4 header
+ */
+ Ipv4Header ();
+ /**
+ * \brief Enable checksum calculation for IP (XXX currently has no effect)
+ */
+ static void EnableChecksums (void);
+ /**
+ * \param size the size of the payload in bytes
+ */
+ void SetPayloadSize (uint16_t size);
+ /**
+ * \param identification the Identification field of IPv4 packets.
+ *
+ * By default, set to zero.
+ */
+ void SetIdentification (uint16_t identification);
+ /**
+ * \param tos the 8 bits of Ipv4 TOS.
+ */
+ void SetTos (uint8_t tos);
+ /**
+ * This packet is not the last packet of a fragmented ipv4 packet.
+ */
+ void SetMoreFragments (void);
+ /**
+ * This packet is the last packet of a fragmented ipv4 packet.
+ */
+ void SetLastFragment (void);
+ /**
+ * Don't fragment this packet: if you need to anyway, drop it.
+ */
+ void SetDontFragment (void);
+ /**
+ * If you need to fragment this packet, you can do it.
+ */
+ void SetMayFragment (void);
+ /**
+ * \param offset the ipv4 fragment offset
+ */
+ void SetFragmentOffset (uint16_t offset);
+ /**
+ * \param ttl the ipv4 TTL
+ */
+ void SetTtl (uint8_t ttl);
+ /**
+ * \param num the ipv4 protocol field
+ */
+ void SetProtocol (uint8_t num);
+ /**
+ * \param source the source of this packet
+ */
+ void SetSource (Ipv4Address source);
+ /**
+ * \param destination the destination of this packet.
+ */
+ void SetDestination (Ipv4Address destination);
+ /**
+ * \returns the size of the payload in bytes
+ */
+ uint16_t GetPayloadSize (void) const;
+ /**
+ * \returns the identification field of this packet.
+ */
+ uint16_t GetIdentification (void) const;
+ /**
+ * \returns the TOS field of this packet.
+ */
+ uint8_t GetTos (void) const;
+ /**
+ * \returns true if this is the last fragment of a packet, false otherwise.
+ */
+ bool IsLastFragment (void) const;
+ /**
+ * \returns true if this is this packet can be fragmented.
+ */
+ bool IsDontFragment (void) const;
+ /**
+ * \returns the offset of this fragment.
+ */
+ uint16_t GetFragmentOffset (void) const;
+ /**
+ * \returns the TTL field of this packet
+ */
+ uint8_t GetTtl (void) const;
+ /**
+ * \returns the protocol field of this packet
+ */
+ uint8_t GetProtocol (void) const;
+ /**
+ * \returns the source address of this packet
+ */
+ Ipv4Address GetSource (void) const;
+ /**
+ * \returns the destination address of this packet
+ */
+ Ipv4Address GetDestination (void) const;
+
+ /**
+ * \returns true if the upv4 checksum is correct, false otherwise.
+ *
+ * If Ipv4Header::EnableChecksums has not been called prior to
+ * creating this packet, this method will always return true.
+ */
+ bool IsChecksumOk (void) const;
+
+ static TypeId GetTypeId (void);
+ 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);
+private:
+
+ enum FlagsE {
+ DONT_FRAGMENT = (1<<0),
+ MORE_FRAGMENTS = (1<<1)
+ };
+
+ static 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;
+ bool m_goodChecksum;
+};
+
+} // namespace ns3
+
+
+#endif /* IPV4_HEADER_H */
--- a/src/node/ipv4.h Wed Jun 04 10:09:29 2008 -0700
+++ b/src/node/ipv4.h Wed Jun 04 10:18:57 2008 -0700
@@ -32,8 +32,7 @@
class NetDevice;
class Packet;
class Ipv4Route;
-class Ipv4Header; // XXX: ipv4-header.h needs to move from module
- // "internet-node" to module "node"
+class Ipv4Header;
/**
* \ingroup node
--- a/src/node/wscript Wed Jun 04 10:09:29 2008 -0700
+++ b/src/node/wscript Wed Jun 04 10:18:57 2008 -0700
@@ -11,6 +11,7 @@
'node.cc',
'ipv4-address.cc',
'ipv4-address-generator.cc',
+ 'ipv4-header.cc',
'net-device.cc',
'address-utils.cc',
'llc-snap-header.cc',
@@ -46,6 +47,7 @@
'node.h',
'ipv4-address.h',
'ipv4-address-generator.h',
+ 'ipv4-header.h',
'net-device.h',
'address-utils.h',
'ipv4-route.h',