From 2b7b6628f3e59ab1171d9f636d8274146687b4e6 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 4 Jun 2008 16:59:41 -0700 Subject: [PATCH 1/5] bug 212: Packet::PrintTags fails --- src/common/packet.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/common/packet.cc b/src/common/packet.cc index b2f67c479..82f167d35 100644 --- a/src/common/packet.cc +++ b/src/common/packet.cc @@ -308,6 +308,7 @@ Packet::PrintTags (std::ostream &os) const Tag *tag = dynamic_cast (constructor ()); NS_ASSERT (tag != 0); os << " "; + item.GetTag (*tag); tag->Print (os); if (i.HasNext ()) { From c3557faf08cfafd3eb5a8ab3997b8e2fa736149c Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Thu, 5 Jun 2008 11:21:50 +0100 Subject: [PATCH 2/5] Add waf proxy script --- src/routing/olsr/waf | 1 + 1 file changed, 1 insertion(+) create mode 100755 src/routing/olsr/waf diff --git a/src/routing/olsr/waf b/src/routing/olsr/waf new file mode 100755 index 000000000..4283ec141 --- /dev/null +++ b/src/routing/olsr/waf @@ -0,0 +1 @@ +exec "`dirname "$0"`"/../../../waf "$@" From b469955b1e71df2d8a0c8d99896f2e626f873ea3 Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Thu, 5 Jun 2008 11:46:15 +0100 Subject: [PATCH 3/5] Add OLSR attribute documentation; make Willingness an enum attribute instead of uint. Closes #211 --- src/routing/olsr/olsr-agent-impl.cc | 42 +++++++++++++---------------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/src/routing/olsr/olsr-agent-impl.cc b/src/routing/olsr/olsr-agent-impl.cc index 2d240e897..b9a9ea7e4 100644 --- a/src/routing/olsr/olsr-agent-impl.cc +++ b/src/routing/olsr/olsr-agent-impl.cc @@ -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 @@ AgentImpl::GetTypeId (void) static TypeId tid = TypeId ("ns3::olsr::AgentImpl") .SetParent () .AddConstructor () - .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 ()) + .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.", From 64e2c2bb8f60fe7b7c25735cdbe19fd9ab183498 Mon Sep 17 00:00:00 2001 From: Florian Westphal Date: Thu, 5 Jun 2008 01:08:33 +0200 Subject: [PATCH 4/5] Add ipv4 header checksum support. --- src/node/ipv4-header.cc | 41 +++++++++++++++++++++++------------------ src/node/ipv4-header.h | 3 ++- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/node/ipv4-header.cc b/src/node/ipv4-header.cc index 3c7fb355f..a9660c8dd 100644 --- a/src/node/ipv4-header.cc +++ b/src/node/ipv4-header.cc @@ -178,6 +178,22 @@ Ipv4Header::IsChecksumOk (void) const 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 +282,12 @@ Ipv4Header::Serialize (Buffer::Iterator start) const 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=" < ()) + .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 @@ Ipv4L3Protocol::Receive( Ptr device, Ptr packet, uint16_t pro index++; } Ipv4Header ipHeader; + if (m_calcChecksum) + { + ipHeader.EnableChecksum (); + } packet->RemoveHeader (ipHeader); if (!ipHeader.IsChecksumOk ()) { + m_dropTrace (packet); return; } @@ -490,6 +501,11 @@ Ipv4L3Protocol::Send (Ptr packet, Ipv4Header ipHeader; + if (m_calcChecksum) + { + ipHeader.EnableChecksum (); + } + ipHeader.SetSource (source); ipHeader.SetDestination (destination); ipHeader.SetProtocol (protocol); diff --git a/src/internet-node/ipv4-l3-protocol.h b/src/internet-node/ipv4-l3-protocol.h index 7b65269d7..40f0be5bd 100644 --- a/src/internet-node/ipv4-l3-protocol.h +++ b/src/internet-node/ipv4-l3-protocol.h @@ -191,6 +191,7 @@ private: Ipv4InterfaceList m_interfaces; uint32_t m_nInterfaces; uint8_t m_defaultTtl; + bool m_calcChecksum; uint16_t m_identification; Ptr m_node; TracedCallback, uint32_t> m_txTrace; diff --git a/src/node/ipv4-header.cc b/src/node/ipv4-header.cc index a9660c8dd..758358f98 100644 --- a/src/node/ipv4-header.cc +++ b/src/node/ipv4-header.cc @@ -29,10 +29,9 @@ namespace ns3 { 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 @@ Ipv4Header::Ipv4Header () {} void -Ipv4Header::EnableChecksums (void) +Ipv4Header::EnableChecksum (void) { m_calcChecksum = true; } diff --git a/src/node/ipv4-header.h b/src/node/ipv4-header.h index 54f6a8474..59ae97fe4 100644 --- a/src/node/ipv4-header.h +++ b/src/node/ipv4-header.h @@ -36,9 +36,9 @@ public: */ 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 @@ public: * \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 @@ private: MORE_FRAGMENTS = (1<<1) }; - static bool m_calcChecksum; + bool m_calcChecksum; uint16_t m_payloadSize; uint16_t m_identification;