diff --git a/examples/routing/aodv.cc b/examples/routing/aodv.cc index 30e3c845e..de1de85cd 100644 --- a/examples/routing/aodv.cc +++ b/examples/routing/aodv.cc @@ -199,7 +199,7 @@ AodvExample::InstallInternetStack () void AodvExample::InstallApplications () { - V4PingHelper ping (interfaces.GetAddress(size - 1)); + V4PingHelper ping (interfaces.GetAddress (size - 1)); ping.SetAttribute ("Verbose", BooleanValue (true)); ApplicationContainer p = ping.Install (nodes.Get (0)); @@ -208,7 +208,7 @@ AodvExample::InstallApplications () // move node away Ptr node = nodes.Get (size/2); - Ptr mob = node->GetObject(); - Simulator::Schedule (Seconds (totalTime/3), &MobilityModel::SetPosition, mob, Vector(1e5, 1e5, 1e5)); + Ptr mob = node->GetObject (); + Simulator::Schedule (Seconds (totalTime/3), &MobilityModel::SetPosition, mob, Vector (1e5, 1e5, 1e5)); } diff --git a/src/contrib/average.h b/src/contrib/average.h index 8deddc0e1..186a6ee84 100644 --- a/src/contrib/average.h +++ b/src/contrib/average.h @@ -29,7 +29,10 @@ template class Average { public: - Average () : size(0), min (std::numeric_limits::max ()), max (0), avg (0), avg2 (0) {} + Average () : + size (0), min (std::numeric_limits::max ()), max (0), avg (0), avg2 (0) + { + } /// Add new value void Update (T const & x) diff --git a/src/helper/aodv-helper.cc b/src/helper/aodv-helper.cc index 42180a207..e0e8f79af 100644 --- a/src/helper/aodv-helper.cc +++ b/src/helper/aodv-helper.cc @@ -26,7 +26,8 @@ namespace ns3 { -AodvHelper::AodvHelper() : Ipv4RoutingHelper () +AodvHelper::AodvHelper() : + Ipv4RoutingHelper () { m_agentFactory.SetTypeId ("ns3::aodv::RoutingProtocol"); } diff --git a/src/internet-stack/ipv4-l3-protocol.cc b/src/internet-stack/ipv4-l3-protocol.cc index 1f0086e99..72385ce91 100644 --- a/src/internet-stack/ipv4-l3-protocol.cc +++ b/src/internet-stack/ipv4-l3-protocol.cc @@ -699,9 +699,9 @@ Ipv4L3Protocol::IpForward (Ptr rtentry, Ptr p, const Ip ipHeader.SetTtl (ipHeader.GetTtl () - 1); if (ipHeader.GetTtl () == 0) { - // Do not reply to ICMP or to multicast/broadcast IP address - if (ipHeader.GetProtocol () != Icmpv4L4Protocol::PROT_NUMBER && - ipHeader.GetDestination ().IsBroadcast () == false && + // Do not reply to ICMP or to multicast/broadcast IP address + if (ipHeader.GetProtocol () != Icmpv4L4Protocol::PROT_NUMBER && + ipHeader.GetDestination ().IsBroadcast () == false && ipHeader.GetDestination ().IsMulticast () == false) { Ptr icmp = GetIcmp (); diff --git a/src/node/socket.cc b/src/node/socket.cc index 46d32d8d2..33c9c8db6 100644 --- a/src/node/socket.cc +++ b/src/node/socket.cc @@ -45,9 +45,9 @@ Ptr Socket::CreateSocket (Ptr node, TypeId tid) { Ptr s; - NS_ASSERT(node != 0); + NS_ASSERT (node != 0); Ptr socketFactory = node->GetObject (tid); - NS_ASSERT(socketFactory != 0); + NS_ASSERT (socketFactory != 0); s = socketFactory->CreateSocket (); NS_ASSERT (s != 0); return s; diff --git a/src/routing/manet/aodv/aodv-neighbor.cc b/src/routing/manet/aodv/aodv-neighbor.cc index 47bcea274..344e5c246 100644 --- a/src/routing/manet/aodv/aodv-neighbor.cc +++ b/src/routing/manet/aodv/aodv-neighbor.cc @@ -36,7 +36,8 @@ namespace ns3 { namespace aodv { -Neighbors::Neighbors (Time delay) : m_ntimer (Timer::CANCEL_ON_DESTROY) +Neighbors::Neighbors (Time delay) : + m_ntimer (Timer::CANCEL_ON_DESTROY) { m_ntimer.SetDelay(delay); m_ntimer.SetFunction(&Neighbors::Purge, this); diff --git a/src/routing/manet/aodv/aodv-packet.cc b/src/routing/manet/aodv/aodv-packet.cc index 3c5ce5636..6856b37b3 100644 --- a/src/routing/manet/aodv/aodv-packet.cc +++ b/src/routing/manet/aodv/aodv-packet.cc @@ -37,16 +37,6 @@ namespace aodv TypeHeader::TypeHeader (MessageType t) : m_type (t), m_valid (true) { - switch (m_type) - { - case AODVTYPE_RREQ: - case AODVTYPE_RREP: - case AODVTYPE_RERR: - case AODVTYPE_RREP_ACK: - break; - default: - m_valid = false; - } } TypeId diff --git a/src/routing/manet/aodv/aodv-routing-protocol.cc b/src/routing/manet/aodv/aodv-routing-protocol.cc index acbe6519d..b8eab282c 100644 --- a/src/routing/manet/aodv/aodv-routing-protocol.cc +++ b/src/routing/manet/aodv/aodv-routing-protocol.cc @@ -74,7 +74,7 @@ RoutingProtocol::RoutingProtocol () : m_dpd (PathDiscoveryTime), m_nb(HelloInterval), m_rreqCount (0), - htimer (Timer::CANCEL_ON_DESTROY), + m_htimer (Timer::CANCEL_ON_DESTROY), m_rreqRateLimitTimer (Timer::CANCEL_ON_DESTROY) { if (EnableHello) @@ -424,8 +424,8 @@ RoutingProtocol::SetIpv4 (Ptr ipv4) if (EnableHello) { - htimer.SetFunction (&RoutingProtocol::HelloTimerExpire, this); - htimer.Schedule (MilliSeconds (UniformVariable ().GetInteger (0, 100))); + m_htimer.SetFunction (&RoutingProtocol::HelloTimerExpire, this); + m_htimer.Schedule (MilliSeconds (UniformVariable ().GetInteger (0, 100))); } m_ipv4 = ipv4; @@ -501,7 +501,7 @@ RoutingProtocol::NotifyInterfaceDown (uint32_t i) if (m_socketAddresses.empty ()) { NS_LOG_LOGIC ("No aodv interfaces"); - htimer.Cancel (); + m_htimer.Cancel (); m_nb.Clear (); m_routingTable.Clear (); return; @@ -579,7 +579,7 @@ RoutingProtocol::NotifyRemoveAddress (uint32_t i, Ipv4InterfaceAddress address) if (m_socketAddresses.empty ()) { NS_LOG_LOGIC ("No aodv interfaces"); - htimer.Cancel (); + m_htimer.Cancel (); m_nb.Clear (); m_routingTable.Clear (); return; @@ -672,8 +672,8 @@ RoutingProtocol::SendRequest (Ipv4Address dst) ScheduleRreqRetry (dst); if (EnableHello) { - htimer.Cancel (); - htimer.Schedule (HelloInterval - Scalar (0.01) * MilliSeconds (UniformVariable ().GetInteger (0, 10))); + m_htimer.Cancel (); + m_htimer.Schedule (HelloInterval - Scalar (0.01) * MilliSeconds (UniformVariable ().GetInteger (0, 10))); } } @@ -896,8 +896,8 @@ RoutingProtocol::RecvRequest (Ptr p, Ipv4Address receiver, Ipv4Address s if (EnableHello) { - htimer.Cancel (); - htimer.Schedule (HelloInterval - Scalar(0.1)*MilliSeconds(UniformVariable().GetInteger (0, 10))); + m_htimer.Cancel (); + m_htimer.Schedule (HelloInterval - Scalar(0.1)*MilliSeconds(UniformVariable().GetInteger (0, 10))); } } @@ -1260,9 +1260,9 @@ RoutingProtocol::HelloTimerExpire () { NS_LOG_FUNCTION(this); SendHello (); - htimer.Cancel (); + m_htimer.Cancel (); Time t = Scalar(0.01)*MilliSeconds(UniformVariable().GetInteger (0, 100)); - htimer.Schedule (HelloInterval - t); + m_htimer.Schedule (HelloInterval - t); } void diff --git a/src/routing/manet/aodv/aodv-routing-protocol.h b/src/routing/manet/aodv/aodv-routing-protocol.h index a23cf9530..c0cdfd7cd 100644 --- a/src/routing/manet/aodv/aodv-routing-protocol.h +++ b/src/routing/manet/aodv/aodv-routing-protocol.h @@ -229,7 +229,7 @@ private: void Drop(Ptr, const Ipv4Header &, Socket::SocketErrno); /// Hello timer - Timer htimer; + Timer m_htimer; /// Schedule next send of hello message void HelloTimerExpire (); /// RREQ rate limit timer diff --git a/src/routing/manet/aodv/aodv-rqueue.cc b/src/routing/manet/aodv/aodv-rqueue.cc index 1a3b49acb..85da4fc93 100644 --- a/src/routing/manet/aodv/aodv-rqueue.cc +++ b/src/routing/manet/aodv/aodv-rqueue.cc @@ -87,14 +87,15 @@ bool RequestQueue::Dequeue (Ipv4Address dst, QueueEntry & entry) { Purge (); - for (std::vector::iterator i = m_queue.begin (); i - != m_queue.end (); ++i) - if (i->GetIpv4Header ().GetDestination () == dst) - { - entry = *i; - m_queue.erase (i); - return true; - } + for (std::vector::iterator i = m_queue.begin (); i != m_queue.end (); ++i) + { + if (i->GetIpv4Header ().GetDestination () == dst) + { + entry = *i; + m_queue.erase (i); + return true; + } + } return false; } diff --git a/src/routing/manet/aodv/aodv-rtable.cc b/src/routing/manet/aodv/aodv-rtable.cc index b98580674..66328a088 100644 --- a/src/routing/manet/aodv/aodv-rtable.cc +++ b/src/routing/manet/aodv/aodv-rtable.cc @@ -43,10 +43,10 @@ namespace aodv RoutingTableEntry::RoutingTableEntry (Ptr dev, Ipv4Address dst, bool vSeqNo, u_int32_t seqNo, Ipv4InterfaceAddress iface, u_int16_t hops, Ipv4Address nextHop, Time lifetime) : + m_ackTimer (Timer::CANCEL_ON_DESTROY), m_validSeqNo (vSeqNo), m_seqNo (seqNo), m_hops (hops), m_lifeTime (lifetime + Simulator::Now ()), m_iface (iface), m_flag (VALID), - m_reqCount (0), m_blackListState (false), m_blackListTimeout (Simulator::Now ()), - m_ackTimer (Timer::CANCEL_ON_DESTROY) + m_reqCount (0), m_blackListState (false), m_blackListTimeout (Simulator::Now ()) { m_ipv4Route = Create (); m_ipv4Route->SetDestination (dst); @@ -164,7 +164,8 @@ RoutingTableEntry::Print (std::ostream & os) const The Routing Table */ -RoutingTable::RoutingTable (Time t) : m_badLinkLifetime (t) +RoutingTable::RoutingTable (Time t) : + m_badLinkLifetime (t) { } @@ -233,10 +234,12 @@ RoutingTable::GetListOfDestinationWithNextHop (Ipv4Address nextHop, std::map::const_iterator i = m_ipv4AddressEntry.begin (); i != m_ipv4AddressEntry.end (); ++i) - if (i->second.GetNextHop () == nextHop) - { - unreachable.insert (std::make_pair (i->first, i->second.GetSeqNo ())); - } + { + if (i->second.GetNextHop () == nextHop) + { + unreachable.insert (std::make_pair (i->first, i->second.GetSeqNo ())); + } + } } void diff --git a/src/routing/manet/aodv/aodv-rtable.h b/src/routing/manet/aodv/aodv-rtable.h index 234f1a0db..e8747585c 100644 --- a/src/routing/manet/aodv/aodv-rtable.h +++ b/src/routing/manet/aodv/aodv-rtable.h @@ -127,6 +127,8 @@ public: bool IsUnidirectional () const { return m_blackListState; } void SetBalcklistTimeout (Time t) { m_blackListTimeout = t; } Time GetBlacklistTimeout () const { return m_blackListTimeout; } + /// RREP_ACK timer + Timer m_ackTimer; //\} /** @@ -175,9 +177,6 @@ private: bool m_blackListState; /// Time for which the node is put into the blacklist Time m_blackListTimeout; -public: - /// RREP_ACK timer - Timer m_ackTimer; }; /** diff --git a/src/routing/manet/aodv/id-cache.cc b/src/routing/manet/aodv/id-cache.cc deleted file mode 100644 index 01107e5de..000000000 --- a/src/routing/manet/aodv/id-cache.cc +++ /dev/null @@ -1,134 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2009 IITP RAS - * - * 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 - * - * Based on - * NS-2 AODV model developed by the CMU/MONARCH group and optimized and - * tuned by Samir Das and Mahesh Marina, University of Cincinnati; - * - * AODV-UU implementation by Erik Nordström of Uppsala University - * http://core.it.uu.se/core/index.php/AODV-UU - * - * Authors: Elena Borovkova - * Pavel Boyko - */ -#include "id-cache.h" -#include "ns3/test.h" -#include - -namespace ns3 -{ -namespace aodv -{ -void -IdCache::InsertId (Ipv4Address addr, uint32_t id, Time saveTime) -{ - if (LookupId (addr, id)) - return; - struct UniqueId uniqueId = - { addr, id, saveTime + Simulator::Now () }; - m_idCache.push_back (uniqueId); -} -bool -IdCache::LookupId (Ipv4Address addr, uint32_t id) -{ - Purge (); - for (std::vector::const_iterator i = m_idCache.begin (); - i != m_idCache.end (); ++i) - if (i->m_context == addr && i->m_id == id) - return true; - return false; -} -void -IdCache::Purge () -{ - m_idCache.erase (remove_if (m_idCache.begin (), m_idCache.end (), - IsExpired ()), m_idCache.end ()); -} - -uint32_t -IdCache::GetSize () -{ - Purge (); - return m_idCache.size (); -} - -//----------------------------------------------------------------------------- -// Tests -//----------------------------------------------------------------------------- -/// Unit test for id cache -struct IdCacheTest : public TestCase -{ - IdCacheTest () : TestCase ("Id Cache") - {} - virtual bool DoRun(); - void CheckTimeout1 (); - void CheckTimeout2 (); - void CheckTimeout3 (); - - IdCache cache; -}; - -bool -IdCacheTest::DoRun () -{ - cache.InsertId (Ipv4Address ("1.2.3.4"), 3, Seconds(5)); - NS_TEST_EXPECT_MSG_EQ (cache.LookupId (Ipv4Address ("1.2.3.4"), 4), false, "Unknown ID"); - NS_TEST_EXPECT_MSG_EQ (cache.LookupId (Ipv4Address ("4.3.2.1"), 3), false, "Unknown address"); - NS_TEST_EXPECT_MSG_EQ (cache.LookupId (Ipv4Address ("1.2.3.4"), 3), true, "Known address & ID"); - cache.InsertId (Ipv4Address ("1.1.1.1"), 4, Seconds(5)); - cache.InsertId (Ipv4Address ("1.1.1.1"), 4, Seconds(5)); - cache.InsertId (Ipv4Address ("2.2.2.2"), 5, Seconds(16)); - cache.InsertId (Ipv4Address ("3.3.3.3"), 6, Seconds(27)); - NS_TEST_EXPECT_MSG_EQ (cache.GetSize (), 4, "trivial"); - - Simulator::Schedule (Seconds(1), &IdCacheTest::CheckTimeout1, this); - Simulator::Schedule (Seconds(6), &IdCacheTest::CheckTimeout2, this); - Simulator::Schedule (Seconds(30), &IdCacheTest::CheckTimeout3, this); - Simulator::Run (); - Simulator::Destroy (); - - return GetErrorStatus (); -} - -void -IdCacheTest::CheckTimeout1 () -{ - NS_TEST_EXPECT_MSG_EQ (cache.GetSize (), 4, "Nothing expire"); -} - -void -IdCacheTest::CheckTimeout2 () -{ - NS_TEST_EXPECT_MSG_EQ (cache.GetSize (), 2, "2 records left"); -} - -void -IdCacheTest::CheckTimeout3 () -{ - NS_TEST_EXPECT_MSG_EQ (cache.GetSize (), 0, "All records expire"); -} -//----------------------------------------------------------------------------- -class IdCacheTestSuite : public TestSuite -{ -public: - IdCacheTestSuite () : TestSuite ("routing-id-cache", UNIT) - { - AddTestCase (new IdCacheTest); - } -} g_idCacheTestSuite; - -}} diff --git a/src/routing/manet/aodv/id-cache.h b/src/routing/manet/aodv/id-cache.h deleted file mode 100644 index caa0663e9..000000000 --- a/src/routing/manet/aodv/id-cache.h +++ /dev/null @@ -1,78 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2009 IITP RAS - * - * 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 - * - * Based on - * NS-2 AODV model developed by the CMU/MONARCH group and optimized and - * tuned by Samir Das and Mahesh Marina, University of Cincinnati; - * - * AODV-UU implementation by Erik Nordström of Uppsala University - * http://core.it.uu.se/core/index.php/AODV-UU - * - * Authors: Elena Borovkova - * Pavel Boyko - */ - -#ifndef IDCACHE_H_ -#define IDCACHE_H_ - -#include "ns3/ipv4-address.h" -#include "ns3/simulator.h" -#include - -namespace ns3 -{ -namespace aodv -{ - -/** - * \ingroup aodv - * \brief packets identification cache - */ -class IdCache -{ -public: - /// c-tor - IdCache () {} - /// Insert entry (addr, id) in cache if it does not exist before - void InsertId (Ipv4Address addr, uint32_t id, Time saveTime); - /// Check that entry (addr, id) exists in cache - bool LookupId (Ipv4Address addr, uint32_t id); - /// Remove all expired entries - void Purge (); - /// Return number of entries in cache - uint32_t - GetSize (); -private: - struct UniqueId - { - Ipv4Address m_context; - uint32_t m_id; - Time m_expire; - }; - struct IsExpired - { - bool operator() (const struct UniqueId & u) const - { - return (u.m_expire < Simulator::Now ()); - } - }; - std::vector m_idCache; -}; - -} -} -#endif /* IDCACHE_H_ */