[aodv] Code style fixes proposed by Faker in his review

This commit is contained in:
Pavel Boyko
2009-10-26 10:11:26 +03:00
parent e02daf1db4
commit db4c9efc2e
14 changed files with 49 additions and 263 deletions

View File

@@ -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> node = nodes.Get (size/2);
Ptr<MobilityModel> mob = node->GetObject<MobilityModel>();
Simulator::Schedule (Seconds (totalTime/3), &MobilityModel::SetPosition, mob, Vector(1e5, 1e5, 1e5));
Ptr<MobilityModel> mob = node->GetObject<MobilityModel> ();
Simulator::Schedule (Seconds (totalTime/3), &MobilityModel::SetPosition, mob, Vector (1e5, 1e5, 1e5));
}

View File

@@ -29,7 +29,10 @@ template <typename T = double>
class Average
{
public:
Average () : size(0), min (std::numeric_limits<T>::max ()), max (0), avg (0), avg2 (0) {}
Average () :
size (0), min (std::numeric_limits<T>::max ()), max (0), avg (0), avg2 (0)
{
}
/// Add new value
void Update (T const & x)

View File

@@ -26,7 +26,8 @@
namespace ns3
{
AodvHelper::AodvHelper() : Ipv4RoutingHelper ()
AodvHelper::AodvHelper() :
Ipv4RoutingHelper ()
{
m_agentFactory.SetTypeId ("ns3::aodv::RoutingProtocol");
}

View File

@@ -699,9 +699,9 @@ Ipv4L3Protocol::IpForward (Ptr<Ipv4Route> rtentry, Ptr<const Packet> 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<Icmpv4L4Protocol> icmp = GetIcmp ();

View File

@@ -45,9 +45,9 @@ Ptr<Socket>
Socket::CreateSocket (Ptr<Node> node, TypeId tid)
{
Ptr<Socket> s;
NS_ASSERT(node != 0);
NS_ASSERT (node != 0);
Ptr<SocketFactory> socketFactory = node->GetObject<SocketFactory> (tid);
NS_ASSERT(socketFactory != 0);
NS_ASSERT (socketFactory != 0);
s = socketFactory->CreateSocket ();
NS_ASSERT (s != 0);
return s;

View File

@@ -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);

View File

@@ -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

View File

@@ -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> 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<Packet> 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

View File

@@ -229,7 +229,7 @@ private:
void Drop(Ptr<const Packet>, const Ipv4Header &, Socket::SocketErrno);
/// Hello timer
Timer htimer;
Timer m_htimer;
/// Schedule next send of hello message
void HelloTimerExpire ();
/// RREQ rate limit timer

View File

@@ -87,14 +87,15 @@ bool
RequestQueue::Dequeue (Ipv4Address dst, QueueEntry & entry)
{
Purge ();
for (std::vector<QueueEntry>::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<QueueEntry>::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;
}

View File

@@ -43,10 +43,10 @@ namespace aodv
RoutingTableEntry::RoutingTableEntry (Ptr<NetDevice> 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<Ipv4Route> ();
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<Ipv
unreachable.clear ();
for (std::map<Ipv4Address, RoutingTableEntry>::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

View File

@@ -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;
};
/**

View File

@@ -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 <borovkovaes@iitp.ru>
* Pavel Boyko <boyko@iitp.ru>
*/
#include "id-cache.h"
#include "ns3/test.h"
#include <algorithm>
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<UniqueId>::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;
}}

View File

@@ -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 <borovkovaes@iitp.ru>
* Pavel Boyko <boyko@iitp.ru>
*/
#ifndef IDCACHE_H_
#define IDCACHE_H_
#include "ns3/ipv4-address.h"
#include "ns3/simulator.h"
#include <vector>
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<UniqueId> m_idCache;
};
}
}
#endif /* IDCACHE_H_ */