--- a/src/internet-node/ipv4-l3-protocol.cc Thu Jun 05 01:08:33 2008 +0200
+++ b/src/internet-node/ipv4-l3-protocol.cc Thu Jun 05 15:56:23 2008 -0700
@@ -30,6 +30,7 @@
#include "ns3/trace-source-accessor.h"
#include "ns3/object-vector.h"
#include "ns3/ipv4-header.h"
+#include "ns3/boolean.h"
#include "arp-l3-protocol.h"
#include "ipv4-l3-protocol.h"
@@ -57,6 +58,11 @@
UintegerValue (64),
MakeUintegerAccessor (&Ipv4L3Protocol::m_defaultTtl),
MakeUintegerChecker<uint8_t> ())
+ .AddAttribute ("CalcChecksum", "If true, we calculate the checksum of outgoing packets"
+ " and verify the checksum of incoming packets.",
+ BooleanValue (false),
+ MakeBooleanAccessor (&Ipv4L3Protocol::m_calcChecksum),
+ MakeBooleanChecker ())
.AddTraceSource ("Tx", "Send ipv4 packet to outgoing interface.",
MakeTraceSourceAccessor (&Ipv4L3Protocol::m_txTrace))
.AddTraceSource ("Rx", "Receive ipv4 packet from incoming interface.",
@@ -464,10 +470,15 @@
index++;
}
Ipv4Header ipHeader;
+ if (m_calcChecksum)
+ {
+ ipHeader.EnableChecksum ();
+ }
packet->RemoveHeader (ipHeader);
if (!ipHeader.IsChecksumOk ())
{
+ m_dropTrace (packet);
return;
}
@@ -490,6 +501,11 @@
Ipv4Header ipHeader;
+ if (m_calcChecksum)
+ {
+ ipHeader.EnableChecksum ();
+ }
+
ipHeader.SetSource (source);
ipHeader.SetDestination (destination);
ipHeader.SetProtocol (protocol);
--- a/src/internet-node/ipv4-l3-protocol.h Thu Jun 05 01:08:33 2008 +0200
+++ b/src/internet-node/ipv4-l3-protocol.h Thu Jun 05 15:56:23 2008 -0700
@@ -191,6 +191,7 @@
Ipv4InterfaceList m_interfaces;
uint32_t m_nInterfaces;
uint8_t m_defaultTtl;
+ bool m_calcChecksum;
uint16_t m_identification;
Ptr<Node> m_node;
TracedCallback<Ptr<const Packet>, uint32_t> m_txTrace;
--- a/src/node/ipv4-header.cc Thu Jun 05 01:08:33 2008 +0200
+++ b/src/node/ipv4-header.cc Thu Jun 05 15:56:23 2008 -0700
@@ -29,10 +29,9 @@
NS_OBJECT_ENSURE_REGISTERED (Ipv4Header);
-bool Ipv4Header::m_calcChecksum = false;
-
Ipv4Header::Ipv4Header ()
- : m_payloadSize (0),
+ : m_calcChecksum (false),
+ m_payloadSize (0),
m_identification (0),
m_tos (0),
m_ttl (0),
@@ -43,7 +42,7 @@
{}
void
-Ipv4Header::EnableChecksums (void)
+Ipv4Header::EnableChecksum (void)
{
m_calcChecksum = true;
}
--- a/src/node/ipv4-header.h Thu Jun 05 01:08:33 2008 +0200
+++ b/src/node/ipv4-header.h Thu Jun 05 15:56:23 2008 -0700
@@ -36,9 +36,9 @@
*/
Ipv4Header ();
/**
- * \brief Enable checksum calculation for IP (XXX currently has no effect)
+ * \brief Enable checksum calculation for this header.
*/
- static void EnableChecksums (void);
+ void EnableChecksum (void);
/**
* \param size the size of the payload in bytes
*/
@@ -134,7 +134,7 @@
* \returns true if the ipv4 checksum is correct, false otherwise.
*
* If Ipv4Header::EnableChecksums has not been called prior to
- * creating this packet, this method will always return true.
+ * deserializing this header, this method will always return true.
*/
bool IsChecksumOk (void) const;
@@ -152,7 +152,7 @@
MORE_FRAGMENTS = (1<<1)
};
- static bool m_calcChecksum;
+ bool m_calcChecksum;
uint16_t m_payloadSize;
uint16_t m_identification;