--- a/src/common/packet.cc Fri Jun 06 13:57:59 2008 -0400
+++ b/src/common/packet.cc Fri Jun 06 13:58:28 2008 -0400
@@ -308,6 +308,7 @@
Tag *tag = dynamic_cast<Tag *> (constructor ());
NS_ASSERT (tag != 0);
os << " ";
+ item.GetTag (*tag);
tag->Print (os);
if (i.HasNext ())
{
--- a/src/internet-node/ipv4-l3-protocol.cc Fri Jun 06 13:57:59 2008 -0400
+++ b/src/internet-node/ipv4-l3-protocol.cc Fri Jun 06 13:58:28 2008 -0400
@@ -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 Fri Jun 06 13:57:59 2008 -0400
+++ b/src/internet-node/ipv4-l3-protocol.h Fri Jun 06 13:58:28 2008 -0400
@@ -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 Fri Jun 06 13:57:59 2008 -0400
+++ b/src/node/ipv4-header.cc Fri Jun 06 13:58:28 2008 -0400
@@ -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;
}
@@ -178,6 +177,22 @@
return m_goodChecksum;
}
+uint16_t
+Ipv4Header::ChecksumCalculate(Buffer::Iterator &i, uint16_t size)
+{
+ /* see RFC 1071 to understand this code. */
+ uint32_t sum = 0;
+
+ for (int j = 0; j < size/2; j++)
+ sum += i.ReadU16 ();
+
+ if (size & 1)
+ sum += i.ReadU8 ();
+
+ while (sum >> 16)
+ sum = (sum & 0xffff) + (sum >> 16);
+ return ~sum;
+}
TypeId
Ipv4Header::GetTypeId (void)
@@ -266,16 +281,12 @@
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);
+ i = start;
+ uint16_t checksum = ChecksumCalculate(i, 20);
NS_LOG_LOGIC ("checksum=" <<checksum);
i = start;
i.Next (10);
i.WriteU16 (checksum);
-#endif
}
}
uint32_t
@@ -313,18 +324,11 @@
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
+ i = start;
+ uint16_t checksum = ChecksumCalculate(i, headerSize);
+ NS_LOG_LOGIC ("checksum=" <<checksum);
+
+ m_goodChecksum = (checksum == 0);
}
return GetSerializedSize ();
}
--- a/src/node/ipv4-header.h Fri Jun 06 13:57:59 2008 -0400
+++ b/src/node/ipv4-header.h Fri Jun 06 13:58:28 2008 -0400
@@ -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
*/
@@ -131,10 +131,10 @@
Ipv4Address GetDestination (void) const;
/**
- * \returns true if the upv4 checksum is correct, false otherwise.
+ * \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;
@@ -146,12 +146,13 @@
virtual uint32_t Deserialize (Buffer::Iterator start);
private:
+ static uint16_t ChecksumCalculate(Buffer::Iterator &i, uint16_t len);
enum FlagsE {
DONT_FRAGMENT = (1<<0),
MORE_FRAGMENTS = (1<<1)
};
- static bool m_calcChecksum;
+ bool m_calcChecksum;
uint16_t m_payloadSize;
uint16_t m_identification;
--- a/src/routing/olsr/olsr-agent-impl.cc Fri Jun 06 13:57:59 2008 -0400
+++ b/src/routing/olsr/olsr-agent-impl.cc Fri Jun 06 13:58:28 2008 -0400
@@ -38,6 +38,7 @@
#include "ns3/inet-socket-address.h"
#include "ns3/boolean.h"
#include "ns3/uinteger.h"
+#include "ns3/enum.h"
#include "ns3/trace-source-accessor.h"
/********** Useful macros **********/
@@ -53,17 +54,6 @@
-/********** Intervals **********/
-
-/// HELLO messages emission interval.
-#define OLSR_HELLO_INTERVAL Seconds (2)
-
-/// TC messages emission interval.
-#define OLSR_TC_INTERVAL Seconds (5)
-
-/// MID messages emission interval.
-#define OLSR_MID_INTERVAL OLSR_TC_INTERVAL
-
///
/// \brief Period at which a node must cite every link and every neighbor.
///
@@ -77,11 +67,11 @@
/// Neighbor holding time.
#define OLSR_NEIGHB_HOLD_TIME (Scalar (3) * OLSR_REFRESH_INTERVAL)
/// Top holding time.
-#define OLSR_TOP_HOLD_TIME (Scalar (3) * OLSR_TC_INTERVAL)
+#define OLSR_TOP_HOLD_TIME (Scalar (3) * m_tcInterval)
/// Dup holding time.
#define OLSR_DUP_HOLD_TIME Seconds (30)
/// MID holding time.
-#define OLSR_MID_HOLD_TIME (Scalar (3) * OLSR_MID_INTERVAL)
+#define OLSR_MID_HOLD_TIME (Scalar (3) * m_midInterval)
/********** Link types **********/
@@ -122,7 +112,7 @@
/********** Miscellaneous constants **********/
/// Maximum allowed jitter.
-#define OLSR_MAXJITTER (OLSR_HELLO_INTERVAL.GetSeconds () / 4)
+#define OLSR_MAXJITTER (m_helloInterval.GetSeconds () / 4)
/// Maximum allowed sequence number.
#define OLSR_MAX_SEQ_NUM 65535
/// Random number between [0-OLSR_MAXJITTER] used to jitter OLSR packet transmission.
@@ -156,22 +146,26 @@
static TypeId tid = TypeId ("ns3::olsr::AgentImpl")
.SetParent<Agent> ()
.AddConstructor<AgentImpl> ()
- .AddAttribute ("HelloInterval", "XXX",
- TimeValue (OLSR_HELLO_INTERVAL),
+ .AddAttribute ("HelloInterval", "HELLO messages emission interval.",
+ TimeValue (Seconds (2)),
MakeTimeAccessor (&AgentImpl::m_helloInterval),
MakeTimeChecker ())
- .AddAttribute ("TcInterval", "XXX",
- TimeValue (OLSR_TC_INTERVAL),
+ .AddAttribute ("TcInterval", "TC messages emission interval.",
+ TimeValue (Seconds (5)),
MakeTimeAccessor (&AgentImpl::m_tcInterval),
MakeTimeChecker ())
- .AddAttribute ("MidInterval", "XXX",
- TimeValue (OLSR_MID_INTERVAL),
+ .AddAttribute ("MidInterval", "MID messages emission interval. Normally it is equal to TcInterval.",
+ TimeValue (Seconds (5)),
MakeTimeAccessor (&AgentImpl::m_midInterval),
MakeTimeChecker ())
- .AddAttribute ("Willingness", "XXX",
- UintegerValue (OLSR_WILL_DEFAULT),
- MakeUintegerAccessor (&AgentImpl::m_willingness),
- MakeUintegerChecker<uint8_t> ())
+ .AddAttribute ("Willingness", "Willingness of a node to carry and forward traffic for other nodes.",
+ EnumValue (OLSR_WILL_DEFAULT),
+ MakeEnumAccessor (&AgentImpl::m_willingness),
+ MakeEnumChecker (OLSR_WILL_NEVER, "never",
+ OLSR_WILL_LOW, "low",
+ OLSR_WILL_DEFAULT, "default",
+ OLSR_WILL_HIGH, "high",
+ OLSR_WILL_ALWAYS, "always"))
.AddTraceSource ("Rx", "Receive OLSR packet.",
MakeTraceSourceAccessor (&AgentImpl::m_rxPacketTrace))
.AddTraceSource ("Tx", "Send OLSR packet.",
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/routing/olsr/waf Fri Jun 06 13:58:28 2008 -0400
@@ -0,0 +1,1 @@
+exec "`dirname "$0"`"/../../../waf "$@"