merge with HEAD

This commit is contained in:
Mathieu Lacage
2007-11-17 18:58:47 +01:00
107 changed files with 3202 additions and 790 deletions

View File

@@ -109,7 +109,7 @@ void
OnOffApplication::SetMaxBytes(uint32_t maxBytes)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << maxBytes << ")");
NS_LOG_PARAMS (this << maxBytes);
m_maxBytes = maxBytes;
}
@@ -117,7 +117,7 @@ void
OnOffApplication::SetDefaultRate (const DataRate &rate)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << &rate << ")");
NS_LOG_PARAMS (&rate);
g_defaultRate.SetValue (rate);
}
@@ -125,7 +125,7 @@ void
OnOffApplication::SetDefaultSize (uint32_t size)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << size << ")");
NS_LOG_PARAMS (size);
g_defaultSize.SetValue (size);
}

View File

@@ -40,9 +40,8 @@ UdpEchoClient::UdpEchoClient (
Application(n)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << n << ", " << serverAddress <<
", " << serverPort << ", " << count << ", " << interval <<
", " << size << ")");
NS_LOG_PARAMS (this << n << serverAddress << serverPort << count
<< interval << size);
Construct (n, serverAddress, serverPort, count, interval, size);
}
@@ -62,9 +61,8 @@ UdpEchoClient::Construct (
uint32_t size)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << n << ", " << serverAddress <<
", " << serverPort << ", " << count << ", " << interval <<
", " << size << ")");
NS_LOG_PARAMS (this << n << serverAddress << serverPort
<< count << interval << size);
m_node = n;
m_serverAddress = serverAddress;
@@ -154,7 +152,7 @@ UdpEchoClient::Receive(
const Address &from)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << socket << ", " << packet << ", " << from << ")");
NS_LOG_PARAMS (this << socket << packet << from);
if (InetSocketAddress::IsMatchingType (from))
{

View File

@@ -38,7 +38,7 @@ UdpEchoServer::UdpEchoServer (
Application(n)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << n << ", " << port << ")");
NS_LOG_PARAMS (this << n << port);
Construct (n, port);
}
@@ -54,7 +54,7 @@ UdpEchoServer::Construct (
uint16_t port)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << n << ", " << port << ")");
NS_LOG_PARAMS (this << n << port);
m_node = n;
m_port = port;
@@ -106,7 +106,7 @@ UdpEchoServer::Receive(
const Address &from)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << socket << ", " << packet << ", " << from << ")");
NS_LOG_PARAMS (this << socket << packet << from);
if (InetSocketAddress::IsMatchingType (from))
{

View File

@@ -145,32 +145,32 @@ uint64_t DataRate::Parse(const std::string s)
return v;
}
bool DataRate::operator < (const DataRate& rhs)
bool DataRate::operator < (const DataRate& rhs) const
{
return m_bps<rhs.m_bps;
}
bool DataRate::operator <= (const DataRate& rhs)
bool DataRate::operator <= (const DataRate& rhs) const
{
return m_bps<=rhs.m_bps;
}
bool DataRate::operator > (const DataRate& rhs)
bool DataRate::operator > (const DataRate& rhs) const
{
return m_bps>rhs.m_bps;
}
bool DataRate::operator >= (const DataRate& rhs)
bool DataRate::operator >= (const DataRate& rhs) const
{
return m_bps>=rhs.m_bps;
}
bool DataRate::operator == (const DataRate& rhs)
bool DataRate::operator == (const DataRate& rhs) const
{
return m_bps==rhs.m_bps;
}
bool DataRate::operator != (const DataRate& rhs)
bool DataRate::operator != (const DataRate& rhs) const
{
return m_bps!=rhs.m_bps;
}

View File

@@ -72,12 +72,12 @@ class DataRate
*/
DataRate (const std::string s);
bool operator < (const DataRate& rhs);
bool operator <= (const DataRate& rhs);
bool operator > (const DataRate& rhs);
bool operator >= (const DataRate& rhs);
bool operator == (const DataRate& rhs);
bool operator != (const DataRate& rhs);
bool operator < (const DataRate& rhs) const;
bool operator <= (const DataRate& rhs) const;
bool operator > (const DataRate& rhs) const;
bool operator >= (const DataRate& rhs) const;
bool operator == (const DataRate& rhs) const;
bool operator != (const DataRate& rhs) const;
/**
* \brief Calculate transmission time

300
src/common/error-model.cc Normal file
View File

@@ -0,0 +1,300 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2007 University of Washington
*
* 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
*
* Author: Tom Henderson <tomhend@u.washington.edu>
* This code has been ported from ns-2 (queue/errmodel.{cc,h}
*/
#include <math.h>
#include "error-model.h"
#include "ns3/packet.h"
#include "ns3/assert.h"
#include "ns3/log.h"
#include "ns3/random-variable.h"
#include "ns3/default-value.h"
NS_LOG_COMPONENT_DEFINE ("ErrorModel");
namespace ns3 {
static ClassIdDefaultValue g_classIdErrorModelDefaultValue ("ErrorModel",
"Error Model", ErrorModel::iid, "RateErrorModel");
const InterfaceId ErrorModel::iid =
MakeInterfaceId ("ErrorModel", Object::iid);
ErrorModel::ErrorModel () :
m_enable (true)
{
NS_LOG_FUNCTION;
SetInterfaceId (ErrorModel::iid);
}
ErrorModel::~ErrorModel ()
{
NS_LOG_FUNCTION;
}
Ptr<ErrorModel>
ErrorModel::CreateDefault (void)
{
NS_LOG_FUNCTION;
ClassId classId = g_classIdErrorModelDefaultValue.GetValue ();
Ptr<ErrorModel> em = ComponentManager::Create<ErrorModel> (classId,
ErrorModel::iid);
return em;
}
bool
ErrorModel::IsCorrupt (Packet& p)
{
NS_LOG_FUNCTION;
bool result;
// Insert any pre-conditions here
result = DoCorrupt (p);
// Insert any post-conditions here
return result;
}
void
ErrorModel::Reset (void)
{
NS_LOG_FUNCTION;
DoReset ();
}
void
ErrorModel::Enable (void)
{
NS_LOG_FUNCTION;
m_enable = true;
}
void
ErrorModel::Disable (void)
{
NS_LOG_FUNCTION;
m_enable = false;
}
bool
ErrorModel::IsEnabled (void) const
{
NS_LOG_FUNCTION;
return m_enable;
}
//
// RateErrorModel
//
const InterfaceId RateErrorModel::iid =
MakeInterfaceId ("RateErrorModel", ErrorModel::iid);
const ClassId RateErrorModel::cid =
MakeClassId<RateErrorModel> ("RateErrorModel", ErrorModel::iid,
RateErrorModel::iid);
// Defaults for rate/size
static NumericDefaultValue<double> g_defaultRateErrorModelErrorRate
("RateErrorModelErrorRate", "The error rate for the error model", 0.0);
static EnumDefaultValue<enum ErrorUnit>
g_defaultRateErrorModelErrorUnit ("RateErrorModelErrorUnit",
"The error unit for this error model",
EU_BYTE, "EU_BYTE",
EU_PKT, "EU_PKT",
EU_BIT, "EU_BIT",
0, (void*)0);
RateErrorModel::RateErrorModel () :
m_unit (g_defaultRateErrorModelErrorUnit.GetValue() ),
m_rate (g_defaultRateErrorModelErrorRate.GetValue() )
{
NS_LOG_FUNCTION;
// Assume a uniform random variable if user does not specify
m_ranvar = new UniformVariable ();
SetInterfaceId (RateErrorModel::iid);
}
RateErrorModel::~RateErrorModel ()
{
NS_LOG_FUNCTION;
delete m_ranvar;
}
enum ErrorUnit
RateErrorModel::GetUnit (void) const
{
NS_LOG_FUNCTION;
return m_unit;
}
void
RateErrorModel::SetUnit (enum ErrorUnit error_unit)
{
NS_LOG_FUNCTION;
m_unit = error_unit;
}
double
RateErrorModel::GetRate (void) const
{
NS_LOG_FUNCTION;
return m_rate;
}
void
RateErrorModel::SetRate (double rate)
{
NS_LOG_FUNCTION;
m_rate = rate;
}
void
RateErrorModel::SetRandomVariable (const RandomVariable &ranvar)
{
NS_LOG_FUNCTION;
delete m_ranvar;
m_ranvar = ranvar.Copy ();
}
bool
RateErrorModel::DoCorrupt (Packet& p)
{
NS_LOG_FUNCTION;
if (!m_enable)
{
return false;
}
switch (m_unit)
{
case EU_PKT:
return DoCorruptPkt (p);
case EU_BYTE:
return DoCorruptByte (p);
case EU_BIT:
return DoCorruptBit (p);
default:
NS_ASSERT_MSG (false, "m_unit not supported yet");
break;
}
return false;
}
bool
RateErrorModel::DoCorruptPkt (Packet& p)
{
NS_LOG_FUNCTION;
return (m_ranvar->GetValue () < m_rate);
}
bool
RateErrorModel::DoCorruptByte (Packet& p)
{
NS_LOG_FUNCTION;
// compute pkt error rate, assume uniformly distributed byte error
double per = 1 - pow (1.0 - m_rate, p.GetSize ());
return (m_ranvar->GetValue () < per);
}
bool
RateErrorModel::DoCorruptBit(Packet& p)
{
NS_LOG_FUNCTION;
// compute pkt error rate, assume uniformly distributed bit error
double per = 1 - pow (1.0 - m_rate, (8 * p.GetSize ()) );
return (m_ranvar->GetValue () < per);
}
void
RateErrorModel::DoReset (void)
{
NS_LOG_FUNCTION;
/* re-initialize any state; no-op for now */
}
//
// ListErrorModel
//
const InterfaceId ListErrorModel::iid =
MakeInterfaceId ("ListErrorModel", ErrorModel::iid);
const ClassId ListErrorModel::cid =
MakeClassId<ListErrorModel> ("ListErrorModel", ErrorModel::iid,
ListErrorModel::iid);
ListErrorModel::ListErrorModel ()
{
NS_LOG_FUNCTION;
SetInterfaceId (ListErrorModel::iid);
}
ListErrorModel::~ListErrorModel ()
{
NS_LOG_FUNCTION;
}
std::list<uint32_t>
ListErrorModel::GetList (void) const
{
NS_LOG_FUNCTION;
return m_packetList;
}
void
ListErrorModel::SetList (const std::list<uint32_t> &packetlist)
{
NS_LOG_FUNCTION;
m_packetList = packetlist;
}
// When performance becomes a concern, the list provided could be
// converted to a dynamically-sized array of uint32_t to avoid
// list iteration below.
bool
ListErrorModel::DoCorrupt (Packet& p)
{
NS_LOG_FUNCTION;
if (!m_enable)
{
return false;
}
uint32_t uid = p.GetUid ();
for (PacketListCI i = m_packetList.begin ();
i != m_packetList.end (); i++)
{
if (uid == *i)
{
return true;
}
}
return false;
}
void
ListErrorModel::DoReset (void)
{
NS_LOG_FUNCTION;
m_packetList.clear();
}
} //namespace ns3

236
src/common/error-model.h Normal file
View File

@@ -0,0 +1,236 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2007 University of Washington
*
* 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
*
* Author: Tom Henderson <tomhend@u.washington.edu>
* This code has been ported from ns-2 (queue/errmodel.{cc,h}
*/
#ifndef ERROR_MODEL_H
#define ERROR_MODEL_H
#include <list>
#include "ns3/object.h"
#include "ns3/component-manager.h"
namespace ns3 {
class Packet;
class RandomVariable;
/**
* \brief General error model that can be used to corrupt packets
*
* This object is used to flag packets as being lost/errored or not.
* It is part of the Object framework and can be aggregated to
* other ns3 objects and handled by the Ptr class.
*
* The main method is IsCorrupt(Packet& p) which returns true if
* the packet is to be corrupted according to the underlying model.
* Depending on the error model, the packet itself may have its packet
* data buffer errored or not, or side information may be returned to
* the client in the form of a packet tag.
* The object can have state (resettable by Reset()).
* The object can also be enabled and disabled via two public member functions.
*
* Typical code (simplified) to use an ErrorModel may look something like
* this:
* \code
* Ptr<ErrorModel> rem = Create<RateErrorModel> ();
* rem->SetRandomVariable (UniformVariable ());
* rem->SetRate (0.001);
* ...
* Packet p;
* if (rem->IsCorrupt (p))
* {
* dropTrace(p);
* } else {
* Forward (p);
* }
* \endcode
*
* Two practical error models, a ListErrorModel and a RateErrorModel,
* are currently implemented.
*/
class ErrorModel : public Object
{
public:
static const InterfaceId iid;
/**
* A factory method to generate a preconfigured default ErrorModel for use
* \return an ErrorModel smart pointer that is the default ErrorModel
* type defined
*/
static Ptr<ErrorModel> CreateDefault (void);
ErrorModel ();
virtual ~ErrorModel ();
/**
* \returns true if the Packet is to be considered as errored/corrupted
* \param pkt Packet to apply error model to
*/
bool IsCorrupt (Packet& pkt);
/**
* Reset any state associated with the error model
*/
void Reset (void);
/**
* Enable the error model
*/
void Enable (void);
/**
* Disable the error model
*/
void Disable (void);
/**
* \return true if error model is enabled; false otherwise
*/
bool IsEnabled (void) const;
protected:
bool m_enable;
private:
/*
* These methods must be implemented by subclasses
*/
virtual bool DoCorrupt (Packet&) = 0;
virtual void DoReset (void) = 0;
};
enum ErrorUnit
{
EU_BIT,
EU_BYTE,
EU_PKT
};
/**
* \brief Determine which packets are errored corresponding to an underlying
* distribution, rate, and unit.
*
* This object is used to flag packets as being lost/errored or not.
* The two parameters that govern the behavior are the rate (or
* equivalently, the mean duration/spacing between errors), and the
* unit (which may be per-bit, per-byte, and per-packet).
* Users can optionally provide a RandomVariable object; the default
* is to use a Uniform(0,1) distribution.
* Reset() on this model will do nothing
*
* IsCorrupt() will not modify the packet data buffer
*/
class RateErrorModel : public ErrorModel
{
public:
static const InterfaceId iid;
static const ClassId cid;
RateErrorModel ();
virtual ~RateErrorModel ();
/**
* \returns the ErrorUnit being used by the underlying model
*/
enum ErrorUnit GetUnit (void) const;
/**
* \param error_unit the ErrorUnit to be used by the underlying model
*/
void SetUnit (enum ErrorUnit error_unit);
/**
* \returns the error rate being applied by the model
*/
double GetRate (void) const;
/**
* \param rate the error rate to be used by the model
*/
void SetRate (double rate);
/**
* \param ranvar A random variable distribution to generate random variates
*/
void SetRandomVariable (const RandomVariable &ranvar);
private:
virtual bool DoCorrupt (Packet& p);
virtual bool DoCorruptPkt (Packet& p);
virtual bool DoCorruptByte (Packet& p);
virtual bool DoCorruptBit (Packet& p);
virtual void DoReset (void);
enum ErrorUnit m_unit;
double m_rate;
RandomVariable* m_ranvar;
};
/**
* \brief Provide a list of Packet uids to corrupt
*
* This object is used to flag packets as being lost/errored or not.
* A note on performance: the list is assumed to be unordered, and
* in general, Packet uids received may be unordered. Therefore,
* each call to IsCorrupt() will result in a walk of the list with
* the present underlying implementation.
*
* Note also that if one wants to target multiple packets from looking
* at an (unerrored) trace file, the act of erroring a given packet may
* cause subsequent packet uids to change. For instance, suppose one wants
* to error packets 11 and 17 on a given device. It may be that erroring
* packet 11 will cause the subsequent uid stream to change and 17 may no
* longer correspond to the second packet that one wants to lose. Therefore,
* be advised that it might take some trial and error to select the
* right uids when multiple are provided.
*
* Reset() on this model will clear the list
*
* IsCorrupt() will not modify the packet data buffer
*/
class ListErrorModel : public ErrorModel
{
public:
static const InterfaceId iid;
static const ClassId cid;
ListErrorModel ();
virtual ~ListErrorModel ();
/**
* \return a copy of the underlying list
*/
std::list<uint32_t> GetList (void) const;
/**
* \param packetlist The list of packet uids to error.
*
* This method overwrites any previously provided list.
*/
void SetList (const std::list<uint32_t> &packetlist);
private:
virtual bool DoCorrupt (Packet& p);
virtual void DoReset (void);
typedef std::list<uint32_t> PacketList;
typedef std::list<uint32_t>::const_iterator PacketListCI;
PacketList m_packetList;
};
} //namespace ns3
#endif

View File

@@ -703,7 +703,7 @@ PacketMetadata::DoAddHeader (uint32_t uid, uint32_t size)
m_metadataSkipped = true;
return;
}
NS_LOG_PARAM ("(uid=" << uid << ", size=" << size << ")");
NS_LOG_PARAMS ("(uid=" << uid << ", size=" << size << ")");
struct PacketMetadata::SmallItem item;
item.next = m_head;
@@ -723,7 +723,7 @@ PacketMetadata::DoRemoveHeader (uint32_t uid, uint32_t size)
m_metadataSkipped = true;
return;
}
NS_LOG_PARAM ("(uid=" << uid << ", size=" << size << ")");
NS_LOG_PARAMS ("(uid=" << uid << ", size=" << size << ")");
struct PacketMetadata::SmallItem item;
struct PacketMetadata::ExtraItem extraItem;
uint32_t read = ReadItems (m_head, &item, &extraItem);

View File

@@ -14,6 +14,7 @@ def build(bld):
'pcap-writer.cc',
'data-rate.cc',
'gnuplot.cc',
'error-model.cc',
]
headers = bld.create_obj('ns3header')
@@ -31,4 +32,5 @@ def build(bld):
'pcap-writer.h',
'data-rate.h',
'gnuplot.h',
'error-model.h',
]

View File

@@ -461,7 +461,7 @@ DefaultValueTest::RunTests (void)
DefaultValue::Bind ("test-c", "257");
NumericDefaultValue<float> x ("test-x", "help-x", 10.0);
NumericDefaultValue<double> y ("test-y", "help-y", 10.0);
DefaultValue::Bind ("test-y", "-3");
EnumDefaultValue<enum MyEnum> e ("test-e", "help-e",
MY_ENUM_C, "C",

View File

@@ -219,6 +219,7 @@ private:
virtual bool DoParseValue (const std::string &value);
virtual std::string DoGetType (void) const;
virtual std::string DoGetDefaultValue (void) const;
T RealMin (void) const;
T m_defaultValue;
T m_minValue;
T m_maxValue;
@@ -413,7 +414,7 @@ NumericDefaultValue<T>::NumericDefaultValue (std::string name,
T defaultValue)
: DefaultValueBase (name, help),
m_defaultValue (defaultValue),
m_minValue (std::numeric_limits<T>::min ()),
m_minValue (RealMin ()),
m_maxValue (std::numeric_limits<T>::max ()),
m_value (defaultValue)
{
@@ -505,6 +506,21 @@ NumericDefaultValue<T>::DoGetDefaultValue (void) const
return oss.str ();
}
template <typename T>
T
NumericDefaultValue<T>::RealMin (void) const
{
if (std::numeric_limits<T>::is_integer)
{
return std::numeric_limits<T>::min ();
}
else
{
return -std::numeric_limits<T>::max ();
}
}
/**************************************************************
**************************************************************/

View File

@@ -341,6 +341,11 @@ LogComponentPrintList (void)
}
}
ParameterLogger g_parameterLogger;
EndParameterListStruct EndParameterList;
} // namespace ns3
#endif // NS3_LOG_ENABLE

View File

@@ -75,6 +75,7 @@
#endif
/**
* \ingroup logging
* \param msg message to output
@@ -88,6 +89,84 @@
#ifdef NS3_LOG_ENABLE
namespace ns3 {
struct EndParameterListStruct {};
extern EndParameterListStruct EndParameterList;
struct ParameterName
{
const char *name;
ParameterName (const char *name_) : name (name_) {}
};
class ParameterLogger : public std::ostream
{
int m_itemNumber;
const char *m_parameterName;
public:
ParameterLogger ()
: m_itemNumber (0)
{}
template<typename T>
ParameterLogger& operator<< (T param)
{
switch (m_itemNumber)
{
case 0: // first item is actually the function name
if (m_parameterName)
{
std::clog << m_parameterName << "=" << param;
m_parameterName = 0;
}
else
{
std::clog << param;
}
break;
case 1:
if (m_parameterName)
{
std::clog << ", " << m_parameterName << "=" << param;
m_parameterName = 0;
}
else
{
std::clog << ", " << param;
}
break;
default: // parameter following a previous parameter
std::clog << ", " << param;
break;
}
m_itemNumber++;
return *this;
}
ParameterLogger&
operator << (ParameterName paramName)
{
m_parameterName = paramName.name;
return *this;
}
ParameterLogger&
operator << (EndParameterListStruct dummy)
{
std::clog << ")" << std::endl;
m_itemNumber = 0;
return *this;
}
};
extern ParameterLogger g_parameterLogger;
}
/**
* \param level the log level
* \param msg the message to log
@@ -142,8 +221,33 @@
#define NS_LOG_FUNCTION \
NS_LOG_F(ns3::LOG_FUNCTION)
#define NS_LOG_PARAM(msg) \
NS_LOG(ns3::LOG_PARAM, msg)
#define NS_LOG_PARAMS(parameters) \
do \
{ \
if (g_log.IsEnabled (ns3::LOG_PARAM)) \
{ \
g_parameterLogger << __PRETTY_FUNCTION__ \
<< parameters \
<< EndParameterList; \
} \
} \
while (false)
#define NS_LOG_PARAMS_BEGIN() \
if (g_log.IsEnabled (ns3::LOG_PARAM)) \
{ \
g_parameterLogger << __PRETTY_FUNCTION__;
#define NS_LOG_PARAM(param) \
g_parameterLogger << ParameterName (#param) << param;
#define NS_LOG_PARAMS_END() \
g_parameterLogger << EndParameterList; \
}
#define NS_LOG_LOGIC(msg) \
NS_LOG(ns3::LOG_LOGIC, msg)
@@ -164,7 +268,10 @@
#define NS_LOG_DEBUG(msg)
#define NS_LOG_INFO(msg)
#define NS_LOG_FUNCTION
#define NS_LOG_PARAM(msg)
#define NS_LOG_PARAMS(parameters)
#define NS_LOG_PARAMS_BEGIN()
#define NS_LOG_PARAM(param)
#define NS_LOG_PARAMS_END()
#define NS_LOG_LOGIC(msg)
#define NS_LOG_UNCOND(msg)

View File

@@ -42,7 +42,6 @@ namespace ns3{
//-----------------------------------------------------------------------------
// RandomVariable methods
uint32_t RandomVariable::runNumber = 0;
bool RandomVariable::initialized = false; // True if RngStream seed set
bool RandomVariable::useDevRandom = false; // True if use /dev/random
bool RandomVariable::globalSeedSet = false; // True if GlobalSeed called
@@ -50,6 +49,7 @@ int RandomVariable::devRandom = -1;
uint32_t RandomVariable::globalSeed[6];
unsigned long RandomVariable::heuristic_sequence;
RngStream* RandomVariable::m_static_generator = 0;
uint32_t RandomVariable::runNumber = 0;
//the static object random_variable_initializer initializes the static members
//of RandomVariable
@@ -58,9 +58,9 @@ static class RandomVariableInitializer
public:
RandomVariableInitializer()
{
RandomVariable::Initialize(); // sets the static package seed
RandomVariable::m_static_generator = new RngStream();
RandomVariable::m_static_generator->InitializeStream();
// RandomVariable::Initialize(); // sets the static package seed
// RandomVariable::m_static_generator = new RngStream();
// RandomVariable::m_static_generator->InitializeStream();
}
~RandomVariableInitializer()
{
@@ -69,15 +69,20 @@ static class RandomVariableInitializer
} random_variable_initializer;
RandomVariable::RandomVariable()
: m_generator(NULL)
{
m_generator = new RngStream();
m_generator->InitializeStream();
m_generator->ResetNthSubstream(RandomVariable::runNumber);
// m_generator = new RngStream();
// m_generator->InitializeStream();
// m_generator->ResetNthSubstream(RandomVariable::runNumber);
}
RandomVariable::RandomVariable(const RandomVariable& r)
:m_generator(0)
{
m_generator = new RngStream(*r.m_generator);
if(r.m_generator)
{
m_generator = new RngStream(*r.m_generator);
}
}
RandomVariable::~RandomVariable()
@@ -97,6 +102,12 @@ void RandomVariable::UseDevRandom(bool udr)
void RandomVariable::GetSeed(uint32_t seed[6])
{
if(!m_generator)
{
m_generator = new RngStream();
m_generator->InitializeStream();
m_generator->ResetNthSubstream(RandomVariable::runNumber);
}
m_generator->GetState(seed);
}
@@ -202,6 +213,16 @@ UniformVariable::UniformVariable(const UniformVariable& c)
double UniformVariable::GetValue()
{
if(!RandomVariable::initialized)
{
RandomVariable::Initialize();
}
if(!m_generator)
{
m_generator = new RngStream();
m_generator->InitializeStream();
m_generator->ResetNthSubstream(RandomVariable::runNumber);
}
return m_min + m_generator->RandU01() * (m_max - m_min);
}
@@ -212,6 +233,12 @@ RandomVariable* UniformVariable::Copy() const
double UniformVariable::GetSingleValue(double s, double l)
{
if(!RandomVariable::m_static_generator)
{
RandomVariable::Initialize(); // sets the static package seed
RandomVariable::m_static_generator = new RngStream();
RandomVariable::m_static_generator->InitializeStream();
}
return s + m_static_generator->RandU01() * (l - s);;
}
@@ -305,6 +332,16 @@ ExponentialVariable::ExponentialVariable(const ExponentialVariable& c)
double ExponentialVariable::GetValue()
{
if(!RandomVariable::initialized)
{
RandomVariable::Initialize();
}
if(!m_generator)
{
m_generator = new RngStream();
m_generator->InitializeStream();
m_generator->ResetNthSubstream(RandomVariable::runNumber);
}
double r = -m_mean*log(m_generator->RandU01());
if (m_bound != 0 && r > m_bound) return m_bound;
return r;
@@ -316,6 +353,12 @@ RandomVariable* ExponentialVariable::Copy() const
}
double ExponentialVariable::GetSingleValue(double m, double b/*=0*/)
{
if(!RandomVariable::m_static_generator)
{
RandomVariable::Initialize(); // sets the static package seed
RandomVariable::m_static_generator = new RngStream();
RandomVariable::m_static_generator->InitializeStream();
}
double r = -m*log(m_static_generator->RandU01());
if (b != 0 && r > b) return b;
return r;
@@ -341,6 +384,16 @@ ParetoVariable::ParetoVariable(const ParetoVariable& c)
double ParetoVariable::GetValue()
{
if(!RandomVariable::initialized)
{
RandomVariable::Initialize();
}
if(!m_generator)
{
m_generator = new RngStream();
m_generator->InitializeStream();
m_generator->ResetNthSubstream(RandomVariable::runNumber);
}
double scale = m_mean * ( m_shape - 1.0) / m_shape;
double r = (scale * ( 1.0 / pow(m_generator->RandU01(), 1.0 / m_shape)));
if (m_bound != 0 && r > m_bound) return m_bound;
@@ -354,6 +407,12 @@ RandomVariable* ParetoVariable::Copy() const
double ParetoVariable::GetSingleValue(double m, double s, double b/*=0*/)
{
if(!RandomVariable::m_static_generator)
{
RandomVariable::Initialize(); // sets the static package seed
RandomVariable::m_static_generator = new RngStream();
RandomVariable::m_static_generator->InitializeStream();
}
double scale = m * ( s - 1.0) / s;
double r = (scale * ( 1.0 / pow(m_static_generator->RandU01(), 1.0 / s)));
if (b != 0 && r > b) return b;
@@ -375,6 +434,16 @@ WeibullVariable::WeibullVariable(const WeibullVariable& c)
double WeibullVariable::GetValue()
{
if(!RandomVariable::initialized)
{
RandomVariable::Initialize();
}
if(!m_generator)
{
m_generator = new RngStream();
m_generator->InitializeStream();
m_generator->ResetNthSubstream(RandomVariable::runNumber);
}
double exponent = 1.0 / m_alpha;
double r = m_mean * pow( -log(m_generator->RandU01()), exponent);
if (m_bound != 0 && r > m_bound) return m_bound;
@@ -388,6 +457,12 @@ RandomVariable* WeibullVariable::Copy() const
double WeibullVariable::GetSingleValue(double m, double s, double b/*=0*/)
{
if(!RandomVariable::m_static_generator)
{
RandomVariable::Initialize(); // sets the static package seed
RandomVariable::m_static_generator = new RngStream();
RandomVariable::m_static_generator->InitializeStream();
}
double exponent = 1.0 / s;
double r = m * pow( -log(m_static_generator->RandU01()), exponent);
if (b != 0 && r > b) return b;
@@ -412,6 +487,16 @@ NormalVariable::NormalVariable(const NormalVariable& c)
double NormalVariable::GetValue()
{
if(!RandomVariable::initialized)
{
RandomVariable::Initialize();
}
if(!m_generator)
{
m_generator = new RngStream();
m_generator->InitializeStream();
m_generator->ResetNthSubstream(RandomVariable::runNumber);
}
if (m_nextValid)
{ // use previously generated
m_nextValid = false;
@@ -445,6 +530,12 @@ RandomVariable* NormalVariable::Copy() const
double NormalVariable::GetSingleValue(double m, double v, double b)
{
if(!RandomVariable::m_static_generator)
{
RandomVariable::Initialize(); // sets the static package seed
RandomVariable::m_static_generator = new RngStream();
RandomVariable::m_static_generator->InitializeStream();
}
if (m_static_nextValid)
{ // use previously generated
m_static_nextValid = false;
@@ -495,6 +586,16 @@ EmpiricalVariable::~EmpiricalVariable() { }
double EmpiricalVariable::GetValue()
{ // Return a value from the empirical distribution
// This code based (loosely) on code by Bruce Mah (Thanks Bruce!)
if(!RandomVariable::initialized)
{
RandomVariable::Initialize();
}
if(!m_generator)
{
m_generator = new RngStream();
m_generator->InitializeStream();
m_generator->ResetNthSubstream(RandomVariable::runNumber);
}
if (emp.size() == 0) return 0.0; // HuH? No empirical data
if (!validated) Validate(); // Insure in non-decreasing
double r = m_generator->RandU01();
@@ -642,6 +743,16 @@ LogNormalVariable::LogNormalVariable (double mu, double sigma)
double
LogNormalVariable::GetValue ()
{
if(!RandomVariable::initialized)
{
RandomVariable::Initialize();
}
if(!m_generator)
{
m_generator = new RngStream();
m_generator->InitializeStream();
m_generator->ResetNthSubstream(RandomVariable::runNumber);
}
double u, v, r2, normal, z;
do
@@ -665,6 +776,12 @@ LogNormalVariable::GetValue ()
double LogNormalVariable::GetSingleValue (double mu, double sigma)
{
if(!RandomVariable::m_static_generator)
{
RandomVariable::Initialize(); // sets the static package seed
RandomVariable::m_static_generator = new RngStream();
RandomVariable::m_static_generator->InitializeStream();
}
double u, v, r2, normal, z;
do
{
@@ -698,6 +815,16 @@ TriangularVariable::TriangularVariable(const TriangularVariable& c)
double TriangularVariable::GetValue()
{
if(!RandomVariable::initialized)
{
RandomVariable::Initialize();
}
if(!m_generator)
{
m_generator = new RngStream();
m_generator->InitializeStream();
m_generator->ResetNthSubstream(RandomVariable::runNumber);
}
double u = m_generator->RandU01();
if(u <= (m_mode - m_min) / (m_max - m_min) )
return m_min + sqrt(u * (m_max - m_min) * (m_mode - m_min) );
@@ -712,6 +839,12 @@ RandomVariable* TriangularVariable::Copy() const
double TriangularVariable::GetSingleValue(double s, double l, double mean)
{
if(!RandomVariable::m_static_generator)
{
RandomVariable::Initialize(); // sets the static package seed
RandomVariable::m_static_generator = new RngStream();
RandomVariable::m_static_generator->InitializeStream();
}
double mode = 3.0*mean-s-l;
double u = m_static_generator->RandU01();
if(u <= (mode - s) / (l - s) )

View File

@@ -71,7 +71,7 @@ public:
* \brief Returns a random double from the underlying distribution
* \return A floating point random value
*/
virtual double GetValue() = 0;
virtual double GetValue() = 0;
/**
* \brief Returns a random integer integer from the underlying distribution
@@ -173,19 +173,19 @@ public:
*/
static void SetRunNumber(uint32_t n);
private:
static void Initialize(); // Initialize the RNG system
static void GetRandomSeeds(uint32_t seeds[6]);
private:
static bool initialized; // True if package seed is set
static bool useDevRandom; // True if using /dev/random desired
static bool globalSeedSet; // True if global seed has been specified
static int devRandom; // File handle for /dev/random
static uint32_t globalSeed[6]; // The global seed to use
static uint32_t runNumber;
friend class RandomVariableInitializer;
protected:
static unsigned long heuristic_sequence;
static RngStream* m_static_generator;
static uint32_t runNumber;
static void Initialize(); // Initialize the RNG system
static bool initialized; // True if package seed is set
RngStream* m_generator; //underlying generator being wrapped
};

View File

@@ -68,8 +68,7 @@ CsmaChannel::CsmaChannel(
m_delay (delay)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << Channel::GetName() << ", " << bps.GetBitRate() <<
", " << delay << ")");
NS_LOG_PARAMS (this << Channel::GetName() << bps.GetBitRate() << delay);
Init();
}
@@ -83,8 +82,7 @@ CsmaChannel::CsmaChannel(
m_delay (delay)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << name << ", " << bps.GetBitRate() << ", " << delay <<
")");
NS_LOG_PARAMS (this << name << bps.GetBitRate() << delay);
Init();
}
@@ -97,7 +95,7 @@ int32_t
CsmaChannel::Attach(Ptr<CsmaNetDevice> device)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << device << ")");
NS_LOG_PARAMS (this << device);
NS_ASSERT(device != 0);
CsmaDeviceRec rec(device);
@@ -110,7 +108,7 @@ bool
CsmaChannel::Reattach(Ptr<CsmaNetDevice> device)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << device << ")");
NS_LOG_PARAMS (this << device);
NS_ASSERT(device != 0);
std::vector<CsmaDeviceRec>::iterator it;
@@ -136,7 +134,7 @@ bool
CsmaChannel::Reattach(uint32_t deviceId)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << deviceId << ")");
NS_LOG_PARAMS (this << deviceId);
if (deviceId < m_deviceList.size())
{
@@ -158,7 +156,7 @@ bool
CsmaChannel::Detach(uint32_t deviceId)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << deviceId << ")");
NS_LOG_PARAMS (this << deviceId);
if (deviceId < m_deviceList.size())
{
@@ -189,7 +187,7 @@ bool
CsmaChannel::Detach(Ptr<CsmaNetDevice> device)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << device << ")");
NS_LOG_PARAMS (this << device);
NS_ASSERT(device != 0);
std::vector<CsmaDeviceRec>::iterator it;
@@ -208,7 +206,7 @@ bool
CsmaChannel::TransmitStart(Packet& p, uint32_t srcId)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << &p << ", " << srcId << ")");
NS_LOG_PARAMS (this << &p << srcId);
NS_LOG_INFO ("UID is " << p.GetUid () << ")");
if (m_state != IDLE)
@@ -240,7 +238,7 @@ bool
CsmaChannel::TransmitEnd()
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << &m_currentPkt << ", " << m_currentSrc << ")");
NS_LOG_PARAMS (this << &m_currentPkt << m_currentSrc);
NS_LOG_INFO ("UID is " << m_currentPkt.GetUid () << ")");
NS_ASSERT(m_state == TRANSMITTING);
@@ -266,7 +264,7 @@ void
CsmaChannel::PropagationCompleteEvent()
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << &m_currentPkt << ")");
NS_LOG_PARAMS (this << &m_currentPkt);
NS_LOG_INFO ("UID is " << m_currentPkt.GetUid () << ")");
NS_ASSERT(m_state == PROPAGATING);

View File

@@ -28,6 +28,7 @@
#include "ns3/ethernet-header.h"
#include "ns3/ethernet-trailer.h"
#include "ns3/llc-snap-header.h"
#include "ns3/error-model.h"
NS_LOG_COMPONENT_DEFINE ("CsmaNetDevice");
@@ -82,10 +83,11 @@ CsmaTraceType::Get (void) const
CsmaNetDevice::CsmaNetDevice (Ptr<Node> node)
: NetDevice (node, Mac48Address::Allocate ()),
m_bps (DataRate (0xffffffff))
m_bps (DataRate (0xffffffff)),
m_receiveErrorModel (0)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << node << ")");
NS_LOG_PARAMS (this << node);
m_encapMode = IP_ARP;
Init(true, true);
}
@@ -93,10 +95,11 @@ CsmaNetDevice::CsmaNetDevice (Ptr<Node> node)
CsmaNetDevice::CsmaNetDevice (Ptr<Node> node, Mac48Address addr,
CsmaEncapsulationMode encapMode)
: NetDevice(node, addr),
m_bps (DataRate (0xffffffff))
m_bps (DataRate (0xffffffff)),
m_receiveErrorModel (0)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << node << ")");
NS_LOG_PARAMS (this << node);
m_encapMode = encapMode;
Init(true, true);
@@ -109,7 +112,7 @@ CsmaNetDevice::CsmaNetDevice (Ptr<Node> node, Mac48Address addr,
m_bps (DataRate (0xffffffff))
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << node << ")");
NS_LOG_PARAMS (this << node);
m_encapMode = encapMode;
Init(sendEnable, receiveEnable);
@@ -142,7 +145,7 @@ CsmaNetDevice&
CsmaNetDevice::operator= (const CsmaNetDevice nd)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << &nd << ")");
NS_LOG_PARAMS (this << &nd);
return *this;
}
*/
@@ -195,7 +198,10 @@ void
CsmaNetDevice::SetDataRate (DataRate bps)
{
NS_LOG_FUNCTION;
m_bps = bps;
if (!m_channel || bps <= m_channel->GetDataRate ())
{
m_bps = bps;
}
}
void
@@ -507,7 +513,7 @@ bool
CsmaNetDevice::Attach (Ptr<CsmaChannel> ch)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << &ch << ")");
NS_LOG_PARAMS (this << &ch);
m_channel = ch;
@@ -526,11 +532,20 @@ void
CsmaNetDevice::AddQueue (Ptr<Queue> q)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << q << ")");
NS_LOG_PARAMS (this << q);
m_queue = q;
}
void CsmaNetDevice::AddReceiveErrorModel (Ptr<ErrorModel> em)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << em << ")");
m_receiveErrorModel = em;
AddInterface (em);
}
void
CsmaNetDevice::Receive (const Packet& packet)
{
@@ -593,38 +608,48 @@ CsmaNetDevice::Receive (const Packet& packet)
return;
}
m_rxTrace (p);
if (m_receiveErrorModel && m_receiveErrorModel->IsCorrupt (p) )
{
NS_LOG_LOGIC ("Dropping pkt due to error model ");
m_dropTrace (packet);
// Do not forward up; let this packet go
}
else
{
m_rxTrace (p);
//
// protocol must be initialized to avoid a compiler warning in the RAW
// case that breaks the optimized build.
//
uint16_t protocol = 0;
uint16_t protocol = 0;
switch (m_encapMode)
{
case ETHERNET_V1:
case IP_ARP:
protocol = header.GetLengthType();
break;
case LLC: {
LlcSnapHeader llc;
p.RemoveHeader (llc);
protocol = llc.GetType ();
} break;
case RAW:
NS_ASSERT (false);
break;
switch (m_encapMode)
{
case ETHERNET_V1:
case IP_ARP:
protocol = header.GetLengthType();
break;
case LLC:
{
LlcSnapHeader llc;
p.RemoveHeader (llc);
protocol = llc.GetType ();
}
break;
case RAW:
NS_ASSERT (false);
break;
}
ForwardUp (p, protocol, header.GetSource ());
return;
}
ForwardUp (p, protocol, header.GetSource ());
return;
}
Address
CsmaNetDevice::MakeMulticastAddress(Ipv4Address multicastGroup) const
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << multicastGroup << ")");
NS_LOG_PARAMS (this << multicastGroup);
//
// First, get the generic multicast address.
//
@@ -687,4 +712,5 @@ CsmaNetDevice::DoGetChannel(void) const
return m_channel;
}
} // namespace ns3

View File

@@ -40,6 +40,7 @@ namespace ns3 {
class Queue;
class CsmaChannel;
class ErrorModel;
/**
* \brief hold in a TraceContext the type of trace source from a CsmaNetDevice
@@ -192,6 +193,16 @@ enum CsmaEncapsulationMode {
* ownership.
*/
void AddQueue (Ptr<Queue> queue);
/**
* Attach a receive ErrorModel to the CsmaNetDevice.
*
* The CsmaNetDevice may optionally include an ErrorModel in
* the packet receive chain.
*
* @see ErrorModel
* @param em a pointer to the ErrorModel
*/
void AddReceiveErrorModel(Ptr<ErrorModel> em);
/**
* Receive a packet from a connected CsmaChannel.
*
@@ -453,6 +464,12 @@ private:
* @see class DropTailQueue
*/
Ptr<Queue> m_queue;
/**
* Error model for receive packet events
*/
Ptr<ErrorModel> m_receiveErrorModel;
/**
* NOT TESTED
* The trace source for the packet reception events that the device can

View File

@@ -52,8 +52,7 @@ PointToPointChannel::PointToPointChannel(
m_nDevices(0)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << Channel::GetName() << ", " << bps.GetBitRate() <<
", " << delay << ")");
NS_LOG_PARAMS (this << Channel::GetName() << bps.GetBitRate() << delay);
}
PointToPointChannel::PointToPointChannel(
@@ -67,15 +66,14 @@ PointToPointChannel::PointToPointChannel(
m_nDevices(0)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << name << ", " << bps.GetBitRate() << ", " <<
delay << ")");
NS_LOG_PARAMS (this << name << bps.GetBitRate() << delay);
}
void
PointToPointChannel::Attach(Ptr<PointToPointNetDevice> device)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << device << ")");
NS_LOG_PARAMS (this << device);
NS_ASSERT(m_nDevices < N_DEVICES && "Only two devices permitted");
NS_ASSERT(device != 0);
@@ -99,7 +97,7 @@ PointToPointChannel::TransmitStart(Packet& p,
const Time& txTime)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << &p << ", " << src << ")");
NS_LOG_PARAMS (this << &p << src);
NS_LOG_LOGIC ("UID is " << p.GetUid () << ")");
NS_ASSERT(m_link[0].m_state != INITIALIZING);

View File

@@ -26,6 +26,7 @@
#include "ns3/composite-trace-resolver.h"
#include "ns3/mac48-address.h"
#include "ns3/llc-snap-header.h"
#include "ns3/error-model.h"
#include "point-to-point-net-device.h"
#include "point-to-point-channel.h"
@@ -38,14 +39,28 @@ DataRateDefaultValue PointToPointNetDevice::g_defaultRate(
"The default data rate for point to point links",
DataRate ("10Mb/s"));
PointToPointTraceType::PointToPointTraceType ()
PointToPointTraceType::PointToPointTraceType (enum Type type)
: m_type (type)
{
NS_LOG_FUNCTION;
}
PointToPointTraceType::PointToPointTraceType ()
: m_type (RX)
{
NS_LOG_FUNCTION;
}
void
PointToPointTraceType::Print (std::ostream &os) const
{
os << "dev-rx";
switch (m_type) {
case RX:
os << "dev-rx";
break;
case DROP:
os << "dev-drop";
break;
}
}
uint16_t
@@ -63,6 +78,12 @@ PointToPointTraceType::GetTypeName (void) const
return "ns3::PointToPointTraceType";
}
enum PointToPointTraceType::Type
PointToPointTraceType::Get (void) const
{
NS_LOG_FUNCTION;
return m_type;
}
PointToPointNetDevice::PointToPointNetDevice (Ptr<Node> node,
const DataRate& rate)
@@ -73,10 +94,12 @@ PointToPointNetDevice::PointToPointNetDevice (Ptr<Node> node,
m_tInterframeGap (Seconds(0)),
m_channel (0),
m_queue (0),
m_rxTrace ()
m_rxTrace (),
m_dropTrace (),
m_receiveErrorModel (0)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << node << ")");
NS_LOG_PARAMS (this << node);
//
// XXX BUGBUG
//
@@ -94,6 +117,7 @@ PointToPointNetDevice::~PointToPointNetDevice()
{
NS_LOG_FUNCTION;
m_queue = 0;
m_receiveErrorModel = 0;
}
void
@@ -127,7 +151,10 @@ void PointToPointNetDevice::DoDispose()
void PointToPointNetDevice::SetDataRate(const DataRate& bps)
{
NS_LOG_FUNCTION;
m_bps = bps;
if (!m_channel || bps <= m_channel->GetDataRate ())
{
m_bps = bps;
}
}
void PointToPointNetDevice::SetInterframeGap(const Time& t)
@@ -174,7 +201,7 @@ bool PointToPointNetDevice::SendTo (const Packet& packet, const Address& dest,
PointToPointNetDevice::TransmitStart (Packet &p)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << &p << ")");
NS_LOG_PARAMS (this << &p);
NS_LOG_LOGIC ("UID is " << p.GetUid () << ")");
//
// This function is called to start the process of transmitting a packet.
@@ -221,7 +248,12 @@ PointToPointNetDevice::GetTraceResolver (void) const
TraceDoc ("receive MAC packet",
"const Packet &", "packet received"),
m_rxTrace,
PointToPointTraceType ());
PointToPointTraceType (PointToPointTraceType::RX));
resolver->AddSource ("drop",
TraceDoc ("drop MAC packet",
"const Packet &", "packet dropped"),
m_dropTrace,
PointToPointTraceType (PointToPointTraceType::DROP));
resolver->SetParentResolver (NetDevice::GetTraceResolver ());
return resolver;
}
@@ -230,7 +262,7 @@ bool
PointToPointNetDevice::Attach (Ptr<PointToPointChannel> ch)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << &ch << ")");
NS_LOG_PARAMS (this << &ch);
m_channel = ch;
@@ -257,21 +289,38 @@ PointToPointNetDevice::Attach (Ptr<PointToPointChannel> ch)
void PointToPointNetDevice::AddQueue (Ptr<Queue> q)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << q << ")");
NS_LOG_PARAMS (this << q);
m_queue = q;
}
void PointToPointNetDevice::AddReceiveErrorModel (Ptr<ErrorModel> em)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << em << ")");
m_receiveErrorModel = em;
AddInterface (em);
}
void PointToPointNetDevice::Receive (Packet& p)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << &p << ")");
NS_LOG_PARAMS (this << &p);
uint16_t protocol = 0;
Packet packet = p;
m_rxTrace (packet);
ProcessHeader(packet, protocol);
ForwardUp (packet, protocol, GetBroadcast ());
if (m_receiveErrorModel && m_receiveErrorModel->IsCorrupt (p) )
{
m_dropTrace (packet);
// Do not forward up; let this packet go
}
else
{
m_rxTrace (packet);
ProcessHeader(packet, protocol);
ForwardUp (packet, protocol, GetBroadcast ());
}
}
Ptr<Queue> PointToPointNetDevice::GetQueue(void) const

View File

@@ -37,6 +37,7 @@ namespace ns3 {
class Queue;
class PointToPointChannel;
class ErrorModel;
/**
* \brief hold in a TraceContext the type of trace source from a PointToPointNetDevice
@@ -44,10 +45,21 @@ class PointToPointChannel;
class PointToPointTraceType : public TraceContextElement
{
public:
enum Type {
RX,
DROP
};
PointToPointTraceType (enum Type type);
PointToPointTraceType ();
void Print (std::ostream &os) const;
static uint16_t GetUid (void);
std::string GetTypeName (void) const;
/**
* \returns the type of the trace source which generated an event.
*/
enum Type Get (void) const;
private:
enum Type m_type;
};
/**
@@ -133,6 +145,16 @@ public:
* ownership.
*/
void AddQueue (Ptr<Queue> queue);
/**
* Attach a receive ErrorModel to the PointToPointNetDevice.
*
* The PointToPointNetDevice may optionally include an ErrorModel in
* the packet receive chain.
*
* @see ErrorModel
* @param em a pointer to the ErrorModel
*/
void AddReceiveErrorModel(Ptr<ErrorModel> em);
/**
* Receive a packet from a connected PointToPointChannel.
*
@@ -288,11 +310,23 @@ private:
* @see class TraceResolver
*/
CallbackTraceSource<const Packet &> m_rxTrace;
/**
* The trace source for the packet drop events that the device can
* fire.
*
* @see class CallBackTraceSource
* @see class TraceResolver
*/
CallbackTraceSource<const Packet &> m_dropTrace;
/**
* Default data rate. Used for all newly created p2p net devices
*/
static DataRateDefaultValue g_defaultRate;
/**
* Error model for receive packet events
*/
Ptr<ErrorModel> m_receiveErrorModel;
};
}; // namespace ns3

View File

@@ -62,6 +62,30 @@ PointToPointTopology::AddPointToPointLink(
return channel;
}
Ptr<PointToPointNetDevice>
PointToPointTopology::GetNetDevice (Ptr<Node> n, Ptr<PointToPointChannel> chan)
{
Ptr<PointToPointNetDevice> found = 0;
// The PointToPoint channel is used to find the relevant NetDevice
NS_ASSERT (chan->GetNDevices () == 2);
Ptr<PointToPointNetDevice> nd1 = chan->GetDevice (0);
Ptr<PointToPointNetDevice> nd2 = chan->GetDevice (1);
if ( nd1->GetNode ()->GetId () == n->GetId () )
{
found = nd1;
}
else if ( nd2->GetNode ()->GetId () == n->GetId () )
{
found = nd2;
}
else
{
NS_ASSERT (found);
}
return found;
}
void
PointToPointTopology::AddIpv4Addresses(
Ptr<const PointToPointChannel> chan,

View File

@@ -55,6 +55,17 @@ public:
static Ptr<PointToPointChannel> AddPointToPointLink(
Ptr<Node> n1, Ptr<Node> n2, const DataRate& dataRate, const Time& delay);
/**
* \param n Node
* \param chan PointToPointChannel connected to node n
* \return Pointer to the corresponding PointToPointNetDevice
*
* Utility function to retrieve a PointToPointNetDevice pointer
* corresponding to the input parameters
*/
static Ptr<PointToPointNetDevice> GetNetDevice(
Ptr<Node> n, Ptr<PointToPointChannel> chan);
/**
* \param chan PointToPointChannel to use
* \param n1 Node

View File

@@ -6,6 +6,7 @@
#include "dcf-manager.h"
#include "mac-parameters.h"
namespace ns3 {
class DcfManagerTest;
@@ -14,12 +15,25 @@ class DcfStateTest : public DcfState
{
public:
DcfStateTest (DcfManagerTest *test, uint32_t i);
void QueueTx (uint64_t txTime, uint64_t expectedGrantTime);
private:
friend class DcfManagerTest;
virtual bool NeedsAccess (void) const;
virtual void NotifyAccessGranted (void);
virtual void NotifyInternalCollision (void);
virtual void NotifyCollision (void);
typedef std::pair<uint64_t,uint64_t> ExpectedGrant;
typedef std::list<ExpectedGrant> ExpectedGrants;
struct ExpectedCollision {
uint64_t at;
uint32_t nSlots;
};
typedef std::list<struct ExpectedCollision> ExpectedCollisions;
ExpectedCollisions m_expectedInternalCollision;
ExpectedCollisions m_expectedCollision;
ExpectedGrants m_expectedGrants;
DcfManagerTest *m_test;
uint32_t m_i;
};
@@ -39,27 +53,23 @@ public:
private:
void StartTest (uint64_t slotTime, uint64_t sifs, uint64_t ackTxDuration);
void AddDcfState (uint32_t cwMin, uint32_t cwMax, uint32_t aifsn);
void AddDcfState (uint32_t aifsn);
void EndTest (void);
void ExpectAccessGranted (uint64_t time, uint32_t from);
void ExpectInternalCollision (uint64_t time, uint32_t from);
void ExpectCollision (uint64_t time, uint32_t from);
void ExpectInternalCollision (uint64_t time, uint32_t from, uint32_t nSlots);
void ExpectCollision (uint64_t time, uint32_t from, uint32_t nSlots);
void AddRxOkEvt (uint64_t at, uint64_t duration);
void AddRxErrorEvt (uint64_t at, uint64_t duration);
void AddTxEvt (uint64_t at, uint64_t duration);
void AddNavReset (uint64_t at, uint64_t duration);
void AddNavStart (uint64_t at, uint64_t duration);
void AddAccessRequest (uint64_t time, uint32_t from);
void AddAccessRequest (uint64_t at, uint64_t txTime,
uint64_t expectedGrantTime, uint32_t from);
void DoAccessRequest (uint64_t txTime, uint64_t expectedGrantTime, DcfStateTest *state);
typedef std::vector<DcfStateTest *> DcfStates;
typedef std::list<std::pair<uint64_t, uint32_t> > ExpectedEvent;
DcfManager *m_dcfManager;
MacParameters *m_parameters;
DcfStates m_dcfStates;
ExpectedEvent m_expectedAccessGranted;
ExpectedEvent m_expectedInternalCollision;
ExpectedEvent m_expectedCollision;
bool m_result;
};
@@ -68,10 +78,15 @@ private:
DcfStateTest::DcfStateTest (DcfManagerTest *test, uint32_t i)
: m_test (test), m_i(i)
{}
void
DcfStateTest::QueueTx (uint64_t txTime, uint64_t expectedGrantTime)
{
m_expectedGrants.push_back (std::make_pair (txTime, expectedGrantTime));
}
bool
DcfStateTest::NeedsAccess (void) const
{
return true;
return !m_expectedGrants.empty ();
}
void
DcfStateTest::NotifyAccessGranted (void)
@@ -81,15 +96,11 @@ DcfStateTest::NotifyAccessGranted (void)
void
DcfStateTest::NotifyInternalCollision (void)
{
UpdateFailedCw ();
StartBackoffNow (0);
m_test->NotifyInternalCollision (m_i);
}
void
DcfStateTest::NotifyCollision (void)
{
UpdateFailedCw ();
StartBackoffNow (0);
m_test->NotifyCollision (m_i);
}
@@ -102,12 +113,13 @@ DcfManagerTest::DcfManagerTest ()
void
DcfManagerTest::NotifyAccessGranted (uint32_t i)
{
DcfStateTest *state = m_dcfStates[i];
bool result = true;
NS_TEST_ASSERT (!m_expectedAccessGranted.empty ());
std::pair<uint64_t, uint32_t> expected = m_expectedAccessGranted.front ();
m_expectedAccessGranted.pop_front ();
NS_TEST_ASSERT_EQUAL (MicroSeconds (expected.first), Simulator::Now ());
NS_TEST_ASSERT_EQUAL (expected.second, i);
NS_TEST_ASSERT (!state->m_expectedGrants.empty ());
std::pair<uint64_t, uint64_t> expected = state->m_expectedGrants.front ();
state->m_expectedGrants.pop_front ();
NS_TEST_ASSERT_EQUAL (Simulator::Now (), MicroSeconds (expected.second));
m_dcfManager->NotifyTxStartNow (MicroSeconds (expected.first));
if (!result)
{
m_result = result;
@@ -116,12 +128,13 @@ DcfManagerTest::NotifyAccessGranted (uint32_t i)
void
DcfManagerTest::NotifyInternalCollision (uint32_t i)
{
DcfStateTest *state = m_dcfStates[i];
bool result = true;
NS_TEST_ASSERT (!m_expectedInternalCollision.empty ());
std::pair<uint64_t, uint32_t> expected = m_expectedInternalCollision.front ();
m_expectedInternalCollision.pop_front ();
NS_TEST_ASSERT_EQUAL (MicroSeconds (expected.first), Simulator::Now ());
NS_TEST_ASSERT_EQUAL (expected.second, i);
NS_TEST_ASSERT (!state->m_expectedInternalCollision.empty ());
struct DcfStateTest::ExpectedCollision expected = state->m_expectedInternalCollision.front ();
state->m_expectedInternalCollision.pop_front ();
NS_TEST_ASSERT_EQUAL (Simulator::Now (), MicroSeconds (expected.at));
state->StartBackoffNow (expected.nSlots);
if (!result)
{
m_result = result;
@@ -130,12 +143,13 @@ DcfManagerTest::NotifyInternalCollision (uint32_t i)
void
DcfManagerTest::NotifyCollision (uint32_t i)
{
DcfStateTest *state = m_dcfStates[i];
bool result = true;
NS_TEST_ASSERT (!m_expectedCollision.empty ());
std::pair<uint64_t, uint32_t> expected = m_expectedCollision.front ();
m_expectedCollision.pop_front ();
NS_TEST_ASSERT_EQUAL (MicroSeconds (expected.first), Simulator::Now ());
NS_TEST_ASSERT_EQUAL (expected.second, i);
NS_TEST_ASSERT (!state->m_expectedCollision.empty ());
struct DcfStateTest::ExpectedCollision expected = state->m_expectedCollision.front ();
state->m_expectedCollision.pop_front ();
NS_TEST_ASSERT_EQUAL (Simulator::Now (), MicroSeconds (expected.at));
state->StartBackoffNow (expected.nSlots);
if (!result)
{
m_result = result;
@@ -144,19 +158,22 @@ DcfManagerTest::NotifyCollision (uint32_t i)
void
DcfManagerTest::ExpectAccessGranted (uint64_t time, uint32_t from)
DcfManagerTest::ExpectInternalCollision (uint64_t time, uint32_t nSlots, uint32_t from)
{
m_expectedAccessGranted.push_back (std::make_pair (time, from));
DcfStateTest *state = m_dcfStates[from];
struct DcfStateTest::ExpectedCollision col;
col.at = time;
col.nSlots = nSlots;
state->m_expectedInternalCollision.push_back (col);
}
void
DcfManagerTest::ExpectInternalCollision (uint64_t time, uint32_t from)
DcfManagerTest::ExpectCollision (uint64_t time, uint32_t nSlots, uint32_t from)
{
m_expectedInternalCollision.push_back (std::make_pair (time, from));
}
void
DcfManagerTest::ExpectCollision (uint64_t time, uint32_t from)
{
m_expectedCollision.push_back (std::make_pair (time, from));
DcfStateTest *state = m_dcfStates[from];
struct DcfStateTest::ExpectedCollision col;
col.at = time;
col.nSlots = nSlots;
state->m_expectedCollision.push_back (col);
}
void
@@ -169,10 +186,9 @@ DcfManagerTest::StartTest (uint64_t slotTime, uint64_t sifs, uint64_t ackTxDurat
}
void
DcfManagerTest::AddDcfState (uint32_t cwMin, uint32_t cwMax, uint32_t aifsn)
DcfManagerTest::AddDcfState (uint32_t aifsn)
{
DcfStateTest *state = new DcfStateTest (this, m_dcfStates.size ());
state->SetCwBounds (cwMin, cwMax);
state->SetAifsn (aifsn);
m_dcfStates.push_back (state);
m_dcfManager->Add (state);
@@ -183,13 +199,14 @@ DcfManagerTest::EndTest (void)
{
bool result = true;
Simulator::Run ();
NS_TEST_ASSERT (m_expectedAccessGranted.empty ());
NS_TEST_ASSERT (m_expectedInternalCollision.empty ());
NS_TEST_ASSERT (m_expectedCollision.empty ());
Simulator::Destroy ();
for (DcfStates::const_iterator i = m_dcfStates.begin (); i != m_dcfStates.end (); i++)
{
delete *i;
DcfStateTest *state = *i;
NS_TEST_ASSERT (state->m_expectedGrants.empty ());
NS_TEST_ASSERT (state->m_expectedInternalCollision.empty ());
NS_TEST_ASSERT (state->m_expectedCollision.empty ());
delete state;
}
m_dcfStates.clear ();
delete m_dcfManager;
@@ -218,13 +235,7 @@ DcfManagerTest::AddRxErrorEvt (uint64_t at, uint64_t duration)
Simulator::Schedule (MicroSeconds (at+duration) - Now (),
&DcfManager::NotifyRxEndErrorNow, m_dcfManager);
}
void
DcfManagerTest::AddTxEvt (uint64_t at, uint64_t duration)
{
Simulator::Schedule (MicroSeconds (at) - Now (),
&DcfManager::NotifyTxStartNow, m_dcfManager,
MicroSeconds (duration));
}
void
DcfManagerTest::AddNavReset (uint64_t at, uint64_t duration)
{
@@ -240,11 +251,19 @@ DcfManagerTest::AddNavStart (uint64_t at, uint64_t duration)
MicroSeconds (duration));
}
void
DcfManagerTest::AddAccessRequest (uint64_t time, uint32_t from)
DcfManagerTest::AddAccessRequest (uint64_t at, uint64_t txTime,
uint64_t expectedGrantTime, uint32_t from)
{
Simulator::Schedule (MicroSeconds (time) - Now (),
&DcfManager::RequestAccess,
m_dcfManager, m_dcfStates[from]);
Simulator::Schedule (MicroSeconds (at) - Now (),
&DcfManagerTest::DoAccessRequest, this,
txTime, expectedGrantTime, m_dcfStates[from]);
}
void
DcfManagerTest::DoAccessRequest (uint64_t txTime, uint64_t expectedGrantTime, DcfStateTest *state)
{
state->QueueTx (txTime, expectedGrantTime);
m_dcfManager->RequestAccess (state);
}
@@ -255,14 +274,145 @@ DcfManagerTest::RunTests (void)
{
m_result = true;
StartTest (1 /* slot time */, 3 /* sifs */, 10 /* ack tx dur */);
AddDcfState (8 /* cwmin */, 64 /* cwmax */, 1 /* aifsn */);
AddAccessRequest (1 /* at */ , 0 /* from */);
ExpectAccessGranted (4 /* at */, 0 /* from */);
AddAccessRequest (10 /* at */ , 0 /* from */);
ExpectAccessGranted (10 /* at */, 0 /* from */);
// 0 3 4 5 8 9 10 12
// | sifs | aifsn | tx | sifs | aifsn | | tx |
//
StartTest (1, 3, 10);
AddDcfState (1);
AddAccessRequest (1, 1, 4, 0);
AddAccessRequest (10, 2, 10, 0);
EndTest ();
// The test below mainly intends to test the case where the medium
// becomes busy in the middle of a backoff slot: the backoff counter
// must not be decremented for this backoff slot. This is the case
// below for the backoff slot starting at time 78us.
//
// 20 60 66 70 74 78 80 100 106 110 114 118 120
// | rx | sifs | aifsn | bslot0 | bslot1 | | rx | sifs | aifsn | bslot2 | bslot3 | tx |
// |
// 30 request access. backoff slots: 4
StartTest (4, 6 , 10);
AddDcfState (1);
AddRxOkEvt (20, 40);
AddRxOkEvt (80, 20);
AddAccessRequest (30, 2, 118, 0);
ExpectCollision (30, 4, 0); // backoff: 4 slots
EndTest ();
// Test the case where the backoff slots is zero.
//
// 20 60 66 70 72
// | rx | sifs | aifsn | tx |
// |
// 30 request access. backoff slots: 0
StartTest (4, 6 , 10);
AddDcfState (1);
AddRxOkEvt (20, 40);
AddAccessRequest (30, 2, 70, 0);
ExpectCollision (30, 0, 0); // backoff: 0 slots
EndTest ();
// The test below is subject to some discussion because I am
// not sure I understand the intent of the spec here.
// i.e., what happens if you make a request to get access
// to the medium during the difs idle time after a busy period ?
// do you need to start a backoff ? Or do you need to wait until
// the end of difs and access the medium ?
// Here, we wait until the end of difs and access the medium.
//
// 20 60 66 70 72
// | rx | sifs | aifsn | tx |
// |
// 62 request access.
//
StartTest (4, 6 , 10);
AddDcfState (1);
AddRxOkEvt (20, 40);
AddAccessRequest (62, 2, 70, 0);
EndTest ();
// Test an EIFS
//
// 20 60 66 76 80 84 88 92 96 98
// | rx | sifs | acktxttime | aifsn | bslot0 | bslot1 | bslot2 | bslot3 | tx |
// | | <---------eifs----------->|
// 30 request access. backoff slots: 4
StartTest (4, 6, 10);
AddDcfState (1);
AddRxErrorEvt (20, 40);
AddAccessRequest (30, 2, 96, 0);
ExpectCollision (30, 4, 0); // backoff: 4 slots
EndTest ();
// Test an EIFS which is interupted by a successfull transmission.
//
// 20 60 66 69 75 81 85 89 93 97 101 103
// | rx | sifs | | rx | sifs | aifsn | bslot0 | bslot1 | bslot2 | bslot3 | tx |
// | | <--eifs-->|
// 30 request access. backoff slots: 4
StartTest (4, 6, 10);
AddDcfState (1);
AddRxErrorEvt (20, 40);
AddAccessRequest (30, 2, 101, 0);
ExpectCollision (30, 4, 0); // backoff: 4 slots
AddRxOkEvt (69, 6);
EndTest ();
// Test two DCFs which suffer an internal collision. the first DCF has a higher
// priority than the second DCF.
//
// 20 60 66 70 74 78 88
// DCF0 | rx | sifs | aifsn | bslot0 | bslot1 | tx |
// DCF1 | rx | sifs | aifsn | aifsn | aifsn | | sifs | aifsn | aifsn | aifsn | bslot | tx |
// 94 98 102 106 110 112
StartTest (4, 6, 10);
AddDcfState (1); // high priority DCF
AddDcfState (3); // low priority DCF
AddRxOkEvt (20, 40);
AddAccessRequest (30, 10, 78, 0);
ExpectCollision (30, 2, 0); // backoff: 2 slot
AddAccessRequest (40, 2, 110, 1);
ExpectCollision (40, 0, 1); // backoff: 0 slot
ExpectInternalCollision (78, 1, 1); // backoff: 1 slot
EndTest ();
//
// test simple NAV count. This scenario modelizes a simple DATA+ACK handshake
// where the data rate used for the ACK is higher than expected by the DATA source
// so, the data exchange completes before the end of nav.
//
StartTest (4, 6, 10);
AddDcfState (1);
AddRxOkEvt (20, 40);
AddNavStart (60, 15);
AddRxOkEvt (66, 5);
AddNavStart (71, 0);
AddAccessRequest (30, 10, 93, 0);
ExpectCollision (30, 2, 0); // backoff: 2 slot
EndTest ();
//
// test more complex NAV handling by a CF-poll. This scenario modelizes a
// simple DATA+ACK handshake interrupted by a CF-poll which resets the
// NAV counter.
//
StartTest (4, 6, 10);
AddDcfState (1);
AddRxOkEvt (20, 40);
AddNavStart (60, 15);
AddRxOkEvt (66, 5);
AddNavReset (71, 2);
AddAccessRequest (30, 10, 91, 0);
ExpectCollision (30, 2, 0); // backoff: 2 slot
EndTest ();
return m_result;
}

View File

@@ -55,16 +55,18 @@ DcfState::UpdateFailedCw (void)
m_cw = cw;
}
void
DcfState::UpdateBackoffSlotsNow (uint32_t nSlots)
DcfState::UpdateBackoffSlotsNow (uint32_t nSlots, Time backoffUpdateBound)
{
uint32_t n = std::min (nSlots, m_backoffSlots);
m_backoffSlots -= n;
m_backoffStart = backoffUpdateBound;
}
void
DcfState::StartBackoffNow (uint32_t nSlots)
{
NS_ASSERT (m_backoffSlots == 0);
MY_DEBUG ("start backoff="<<nSlots<<" slots");
m_backoffSlots = nSlots;
m_backoffStart = Simulator::Now ();
}
@@ -183,20 +185,11 @@ void
DcfManager::RequestAccess (DcfState *state)
{
UpdateBackoff ();
if (m_accessTimeout.IsRunning ())
{
/* we don't need to do anything because we have an access
* timer which will expire soon.
*/
MY_DEBUG ("access timer running. will be notified");
return;
}
/**
* Since no access timeout is running, and if we have no
* backoff running for this DcfState, start a new backoff
* if needed.
*/
if (GetBackoffEndFor (state) <= Simulator::Now () &&
* If there is a collision, generate a backoff
* by notifying the collision to the user.
*/
if (state->GetBackoffSlots () == 0 &&
IsBusy ())
{
MY_DEBUG ("medium is busy: collision");
@@ -205,7 +198,6 @@ DcfManager::RequestAccess (DcfState *state)
*/
state->NotifyCollision ();
}
DoGrantAccess ();
DoRestartAccessTimeoutIfNeeded ();
}
@@ -220,21 +212,21 @@ DcfManager::DoGrantAccess (void)
{
DcfState *state = *i;
if (state->NeedsAccess () &&
GetBackoffEndFor (state) < Simulator::Now ())
GetBackoffEndFor (state) <= Simulator::Now ())
{
/**
* This is the first dcf we find with an expired backoff and which
* needs access to the medium. i.e., it has data to send.
*/
MY_DEBUG ("dcf " << k << " needs access. backoff expired. access granted.");
state->NotifyAccessGranted ();
i++; // go to the next item in the list.
k++;
std::vector<DcfState *> internalCollisionStates;
for (States::const_iterator j = i; j != m_states.end (); j++, k++)
{
DcfState *state = *j;
if (state->NeedsAccess () &&
GetBackoffEndFor (state) < Simulator::Now ())
DcfState *otherState = *j;
if (otherState->NeedsAccess () &&
GetBackoffEndFor (otherState) <= Simulator::Now ())
{
MY_DEBUG ("dcf " << k << " needs access. backoff expired. internal collision.");
/**
@@ -242,9 +234,23 @@ DcfManager::DoGrantAccess (void)
* has expired and which needed access to the medium
* must be notified that we did get an internal collision.
*/
state->NotifyInternalCollision ();
internalCollisionStates.push_back (otherState);
}
}
/**
* Now, we notify all of these changes in one go. It is necessary to
* perform first the calculations of which states are colliding and then
* only apply the changes because applying the changes through notification
* could change the global state of the manager, and, thus, could change
* the result of the calculations.
*/
state->NotifyAccessGranted ();
for (std::vector<DcfState *>::const_iterator k = internalCollisionStates.begin ();
k != internalCollisionStates.end (); k++)
{
(*k)->NotifyInternalCollision ();
}
break;
}
i++;
@@ -318,7 +324,7 @@ DcfManager::UpdateBackoff (void)
if (backoffStart <= Simulator::Now ())
{
Scalar nSlots = (Simulator::Now () - backoffStart) / m_slotTime;
uint32_t nIntSlots = lrint (nSlots.GetDouble ());
uint32_t nIntSlots = lrint (nSlots.GetDouble ());
/**
* For each DcfState, calculate how many backoff slots elapsed since
* the last time its backoff counter was updated. If the number of
@@ -328,7 +334,8 @@ DcfManager::UpdateBackoff (void)
if (nIntSlots > state->GetAifsn ())
{
MY_DEBUG ("dcf " << k << " dec backoff slots=" << nIntSlots);
state->UpdateBackoffSlotsNow (nIntSlots);
Time backoffUpdateBound = backoffStart + Scalar (nIntSlots) * m_slotTime;
state->UpdateBackoffSlotsNow (nIntSlots, backoffUpdateBound);
}
}
}
@@ -348,29 +355,30 @@ DcfManager::DoRestartAccessTimeoutIfNeeded (void)
DcfState *state = *i;
if (state->NeedsAccess ())
{
accessTimeoutNeeded = true;
expectedBackoffEnd = std::min (expectedBackoffEnd, GetBackoffEndFor (state));
Time tmp = GetBackoffEndFor (state);
if (tmp > Simulator::Now ())
{
accessTimeoutNeeded = true;
expectedBackoffEnd = std::min (expectedBackoffEnd, tmp);
}
}
}
if (accessTimeoutNeeded)
{
MY_DEBUG ("expected backoff end="<<expectedBackoffEnd);
if (expectedBackoffEnd > Simulator::Now ())
Time expectedBackoffDelay = expectedBackoffEnd - Simulator::Now ();
if (m_accessTimeout.IsRunning () &&
Simulator::GetDelayLeft (m_accessTimeout) > expectedBackoffDelay)
{
Time expectedBackoffDelay = expectedBackoffEnd - Simulator::Now ();
if (m_accessTimeout.IsRunning () &&
Simulator::GetDelayLeft (m_accessTimeout) > expectedBackoffDelay)
{
m_accessTimeout.Cancel ();
}
if (m_accessTimeout.IsExpired ())
{
m_accessTimeout = Simulator::Schedule (expectedBackoffDelay,
&DcfManager::AccessTimeout, this);
}
m_accessTimeout.Cancel ();
}
if (m_accessTimeout.IsExpired ())
{
m_accessTimeout = Simulator::Schedule (expectedBackoffDelay,
&DcfManager::AccessTimeout, this);
}
}
}
}
void
DcfManager::NotifyRxStartNow (Time duration)

View File

@@ -29,7 +29,7 @@ private:
uint32_t GetBackoffSlots (void) const;
Time GetBackoffStart (void) const;
void UpdateBackoffSlotsNow (uint32_t nSlots);
void UpdateBackoffSlotsNow (uint32_t nSlots, Time backoffUpdateBound);
virtual bool NeedsAccess (void) const = 0;
virtual void NotifyAccessGranted (void) = 0;
@@ -38,6 +38,9 @@ private:
uint32_t m_aifsn;
uint32_t m_backoffSlots;
// the backoffStart variable is used to keep track of the
// time at which a backoff was started or the time at which
// the backoff counter was last updated.
Time m_backoffStart;
uint32_t m_cwMin;
uint32_t m_cwMax;

View File

@@ -288,8 +288,8 @@ LogDistancePropagationLossModel::GetRxPower (double txPowerDbm,
*
* rx = rx0(tx) - 10 * n * log (d/d0)
*/
static Ptr<StaticMobilityModel> zero = Create<StaticMobilityModel> (Position (0.0, 0.0, 0.0));
static Ptr<StaticMobilityModel> reference = Create<StaticMobilityModel> (Position (m_referenceDistance, 0.0, 0.0));
static Ptr<StaticMobilityModel> zero = Create<StaticMobilityModel> (Vector (0.0, 0.0, 0.0));
static Ptr<StaticMobilityModel> reference = Create<StaticMobilityModel> (Vector (m_referenceDistance, 0.0, 0.0));
double rx0 = m_reference->GetRxPower (txPowerDbm, zero, reference);
double pathLossDb = 10 * m_exponent * log10 (distance / m_referenceDistance);
double rxPowerDbm = rx0 - pathLossDb;

View File

@@ -64,7 +64,7 @@ void
ArpIpv4Interface::SendTo (Packet p, Ipv4Address dest)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << &p << ", " << dest << ")");
NS_LOG_PARAMS (this << &p << dest);
NS_ASSERT (GetDevice () != 0);
if (GetDevice ()->NeedsArp ())

View File

@@ -93,7 +93,7 @@ Ipv4EndPoint *
Ipv4EndPointDemux::Allocate (Ipv4Address address)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << this << ", " << address << ")");
NS_LOG_PARAMS (this << address);
uint16_t port = AllocateEphemeralPort ();
if (port == 0)
{
@@ -117,7 +117,7 @@ Ipv4EndPoint *
Ipv4EndPointDemux::Allocate (Ipv4Address address, uint16_t port)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << this << ", " << address << ", " << port << ")");
NS_LOG_PARAMS (this << address << port);
if (LookupLocal (address, port))
{
NS_LOG_WARN ("Duplicate address/port; failing.");
@@ -134,10 +134,7 @@ Ipv4EndPointDemux::Allocate (Ipv4Address localAddress, uint16_t localPort,
Ipv4Address peerAddress, uint16_t peerPort)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(localAddress=" << localAddress
<< ", localPort=" << localPort
<< ", peerAddress=" << peerAddress
<< ", peerPort=" << peerPort << ")");
NS_LOG_PARAMS (this << localAddress << localPort << peerAddress << peerPort);
for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++)
{
if ((*i)->GetLocalPort () == localPort &&
@@ -189,8 +186,15 @@ Ipv4EndPointDemux::Lookup (Ipv4Address daddr, uint16_t dport,
Ipv4EndPoint *generic = 0;
EndPoints retval;
NS_LOG_PARAM ("(daddr=" << daddr << ", dport=" << dport
<< ", saddr=" << saddr << ", sport=" << sport << ")");
//NS_LOG_PARAMS (this << daddr << dport << saddr << sport);
NS_LOG_PARAMS_BEGIN ();
NS_LOG_PARAM (this);
NS_LOG_PARAM (daddr);
NS_LOG_PARAM (dport);
NS_LOG_PARAM (saddr);
NS_LOG_PARAM (sport);
NS_LOG_PARAM (incomingInterface);
NS_LOG_PARAMS_END ();
for (EndPointsI i = m_endPoints.begin (); i != m_endPoints.end (); i++)
{

View File

@@ -41,7 +41,7 @@ Ipv4Interface::Ipv4Interface (Ptr<NetDevice> nd)
m_metric(1)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << &nd << ")");
NS_LOG_PARAMS (this << &nd);
}
Ipv4Interface::~Ipv4Interface ()
@@ -68,7 +68,7 @@ void
Ipv4Interface::SetAddress (Ipv4Address a)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << a << ")");
NS_LOG_PARAMS (this << a);
m_address = a;
}
@@ -76,7 +76,7 @@ void
Ipv4Interface::SetNetworkMask (Ipv4Mask mask)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << mask << ")");
NS_LOG_PARAMS (this << mask);
m_netmask = mask;
}
@@ -101,7 +101,7 @@ void
Ipv4Interface::SetMetric (uint16_t metric)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << metric << ")");
NS_LOG_PARAMS ("(" << metric << ")");
m_metric = metric;
}

View File

@@ -233,7 +233,7 @@ Ipv4L3Protocol::AddHostRouteTo (Ipv4Address dest,
uint32_t interface)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << dest << ", " << nextHop << ", " << interface << ")");
NS_LOG_PARAMS (this << dest << nextHop << interface);
m_staticRouting->AddHostRouteTo (dest, nextHop, interface);
}
@@ -242,7 +242,7 @@ Ipv4L3Protocol::AddHostRouteTo (Ipv4Address dest,
uint32_t interface)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << dest << ", " << interface << ")");
NS_LOG_PARAMS (this << dest << interface);
m_staticRouting->AddHostRouteTo (dest, interface);
}
@@ -253,8 +253,7 @@ Ipv4L3Protocol::AddNetworkRouteTo (Ipv4Address network,
uint32_t interface)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << network << ", " << networkMask << ", " << nextHop <<
", " << interface << ")");
NS_LOG_PARAMS (this << network << networkMask << nextHop << interface);
m_staticRouting->AddNetworkRouteTo (network, networkMask, nextHop, interface);
}
@@ -264,8 +263,7 @@ Ipv4L3Protocol::AddNetworkRouteTo (Ipv4Address network,
uint32_t interface)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << network << ", " << networkMask << ", " << interface <<
")");
NS_LOG_PARAMS (this << network << networkMask << interface);
m_staticRouting->AddNetworkRouteTo (network, networkMask, interface);
}
@@ -274,7 +272,7 @@ Ipv4L3Protocol::SetDefaultRoute (Ipv4Address nextHop,
uint32_t interface)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << nextHop << ", " << interface << ")");
NS_LOG_PARAMS (this << nextHop << interface);
m_staticRouting->SetDefaultRoute (nextHop, interface);
}
@@ -285,7 +283,7 @@ Ipv4L3Protocol::Lookup (
Ipv4RoutingProtocol::RouteReplyCallback routeReply)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << &ipHeader << ", " << &packet << &routeReply << ")");
NS_LOG_PARAMS (this << &ipHeader << &packet << &routeReply);
Lookup (Ipv4RoutingProtocol::IF_INDEX_ANY, ipHeader, packet, routeReply);
}
@@ -298,8 +296,7 @@ Ipv4L3Protocol::Lookup (
Ipv4RoutingProtocol::RouteReplyCallback routeReply)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << ifIndex << ", " << &ipHeader << ", " << &packet <<
&routeReply << ")");
NS_LOG_PARAMS (this << ifIndex << &ipHeader << &packet << &routeReply);
for (Ipv4RoutingProtocolList::const_iterator rprotoIter =
m_routingProtocols.begin ();
@@ -348,7 +345,7 @@ Ipv4L3Protocol::AddRoutingProtocol (Ptr<Ipv4RoutingProtocol> routingProtocol,
int priority)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << &routingProtocol << ", " << priority << ")");
NS_LOG_PARAMS (this << &routingProtocol << priority);
m_routingProtocols.push_back
(std::pair<int, Ptr<Ipv4RoutingProtocol> > (-priority, routingProtocol));
m_routingProtocols.sort ();
@@ -372,7 +369,7 @@ void
Ipv4L3Protocol::RemoveRoute (uint32_t index)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM("(" << index << ")");
NS_LOG_PARAMS (this << index);
m_staticRouting->RemoveRoute (index);
}
@@ -383,8 +380,7 @@ Ipv4L3Protocol::AddMulticastRoute (Ipv4Address origin,
std::vector<uint32_t> outputInterfaces)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << origin << ", " << group << ", " << inputInterface <<
", " << &outputInterfaces << ")");
NS_LOG_PARAMS (this << origin << group << inputInterface << &outputInterfaces);
m_staticRouting->AddMulticastRoute (origin, group, inputInterface,
outputInterfaces);
@@ -394,7 +390,7 @@ void
Ipv4L3Protocol::SetDefaultMulticastRoute (uint32_t outputInterface)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << outputInterface << ")");
NS_LOG_PARAMS (this << outputInterface);
m_staticRouting->SetDefaultMulticastRoute (outputInterface);
}
@@ -410,7 +406,7 @@ Ipv4MulticastRoute *
Ipv4L3Protocol::GetMulticastRoute (uint32_t index) const
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << index << ")");
NS_LOG_PARAMS (this << index);
return m_staticRouting->GetMulticastRoute (index);
}
@@ -420,8 +416,7 @@ Ipv4L3Protocol::RemoveMulticastRoute (Ipv4Address origin,
uint32_t inputInterface)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << origin << ", " << group << ", " << inputInterface <<
")");
NS_LOG_PARAMS (this << origin << group << inputInterface);
m_staticRouting->RemoveMulticastRoute (origin, group, inputInterface);
}
@@ -429,7 +424,7 @@ void
Ipv4L3Protocol::RemoveMulticastRoute (uint32_t index)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << index << ")");
NS_LOG_PARAMS (this << index);
m_staticRouting->RemoveMulticastRoute (index);
}
@@ -437,7 +432,7 @@ uint32_t
Ipv4L3Protocol::AddInterface (Ptr<NetDevice> device)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << &device << ")");
NS_LOG_PARAMS (this << &device);
Ptr<Ipv4Interface> interface = Create<ArpIpv4Interface> (m_node, device);
return AddIpv4Interface (interface);
}
@@ -446,7 +441,7 @@ uint32_t
Ipv4L3Protocol::AddIpv4Interface (Ptr<Ipv4Interface>interface)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << interface << ")");
NS_LOG_PARAMS (this << interface);
uint32_t index = m_nInterfaces;
m_interfaces.push_back (interface);
m_nInterfaces++;
@@ -457,7 +452,7 @@ Ptr<Ipv4Interface>
Ipv4L3Protocol::GetInterface (uint32_t index) const
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << index << ")");
NS_LOG_PARAMS (this << index);
uint32_t tmp = 0;
for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++)
{
@@ -481,7 +476,7 @@ uint32_t
Ipv4L3Protocol::FindInterfaceForAddr (Ipv4Address addr) const
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << addr << ")");
NS_LOG_PARAMS (this << addr);
uint32_t ifIndex = 0;
for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin ();
@@ -503,7 +498,7 @@ uint32_t
Ipv4L3Protocol::FindInterfaceForAddr (Ipv4Address addr, Ipv4Mask mask) const
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << addr << ", " << mask << ")");
NS_LOG_PARAMS (this << addr << mask);
uint32_t ifIndex = 0;
for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin ();
@@ -525,7 +520,7 @@ Ptr<Ipv4Interface>
Ipv4L3Protocol::FindInterfaceForDevice (Ptr<const NetDevice> device)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << &device << ")");
NS_LOG_PARAMS (this << &device);
for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++)
{
if ((*i)->GetDevice () == device)
@@ -540,8 +535,7 @@ void
Ipv4L3Protocol::Receive( Ptr<NetDevice> device, const Packet& p, uint16_t protocol, const Address &from)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << &device << ", " << &p << ", " << protocol << ", " <<
from << ")");
NS_LOG_PARAMS (this << &device << &p << protocol << from);
NS_LOG_LOGIC ("Packet from " << from);
@@ -585,8 +579,7 @@ Ipv4L3Protocol::Send (Packet const &packet,
uint8_t protocol)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << &packet << ", " << source << ", " << ", " <<
destination << ", " << protocol << ")");
NS_LOG_PARAMS (this << &packet << source << destination << protocol);
Ipv4Header ipHeader;
@@ -637,8 +630,7 @@ Ipv4L3Protocol::SendRealOut (bool found,
Ipv4Header const &ipHeader)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << found << ", " << &route << ", " << &packet <<
&ipHeader << ")");
NS_LOG_PARAMS (this << found << &route << &packet << &ipHeader);
if (!found)
{
@@ -673,8 +665,7 @@ Ipv4L3Protocol::Forwarding (
Ptr<NetDevice> device)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << ifIndex << ", " << &packet << ", " << &ipHeader <<
", " << device << ")");
NS_LOG_PARAMS (ifIndex << &packet << &ipHeader<< device);
for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin ();
i != m_interfaces.end (); i++)
@@ -751,7 +742,7 @@ Ipv4L3Protocol::ForwardUp (Packet p, Ipv4Header const&ip,
Ptr<Ipv4Interface> incomingInterface)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << &p << ", " << &ip << ")");
NS_LOG_PARAMS (this << &p << &ip);
Ptr<Ipv4L4Demux> demux = m_node->QueryInterface<Ipv4L4Demux> (Ipv4L4Demux::iid);
Ptr<Ipv4L4Protocol> protocol = demux->GetProtocol (ip.GetProtocol ());
@@ -762,7 +753,7 @@ void
Ipv4L3Protocol::JoinMulticastGroup (Ipv4Address origin, Ipv4Address group)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << origin << ", " << group << ")");
NS_LOG_PARAMS (this << origin << group);
m_multicastGroups.push_back(
std::pair<Ipv4Address, Ipv4Address> (origin, group));
}
@@ -771,7 +762,7 @@ void
Ipv4L3Protocol::LeaveMulticastGroup (Ipv4Address origin, Ipv4Address group)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << origin << ", " << group << ")");
NS_LOG_PARAMS (this << origin << group);
for (Ipv4MulticastGroupList::iterator i = m_multicastGroups.begin ();
i != m_multicastGroups.end ();
@@ -789,7 +780,7 @@ void
Ipv4L3Protocol::SetAddress (uint32_t i, Ipv4Address address)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << i << ", " << address << ")");
NS_LOG_PARAMS (this << i << address);
Ptr<Ipv4Interface> interface = GetInterface (i);
interface->SetAddress (address);
}
@@ -798,7 +789,7 @@ void
Ipv4L3Protocol::SetNetworkMask (uint32_t i, Ipv4Mask mask)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << i << ", " << mask << ")");
NS_LOG_PARAMS (this << i << mask);
Ptr<Ipv4Interface> interface = GetInterface (i);
interface->SetNetworkMask (mask);
}
@@ -807,7 +798,7 @@ Ipv4Mask
Ipv4L3Protocol::GetNetworkMask (uint32_t i) const
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << i << ")");
NS_LOG_PARAMS (this << i);
Ptr<Ipv4Interface> interface = GetInterface (i);
return interface->GetNetworkMask ();
}
@@ -816,7 +807,7 @@ Ipv4Address
Ipv4L3Protocol::GetAddress (uint32_t i) const
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << i << ")");
NS_LOG_PARAMS (this << i);
Ptr<Ipv4Interface> interface = GetInterface (i);
return interface->GetAddress ();
}
@@ -825,7 +816,7 @@ void
Ipv4L3Protocol::SetMetric (uint32_t i, uint16_t metric)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << i << ", " << metric << ")");
NS_LOG_PARAMS ("(" << i << ", " << metric << ")");
Ptr<Ipv4Interface> interface = GetInterface (i);
interface->SetMetric (metric);
}
@@ -834,7 +825,7 @@ uint16_t
Ipv4L3Protocol::GetMetric (uint32_t i) const
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << i << ")");
NS_LOG_PARAMS ("(" << i << ")");
Ptr<Ipv4Interface> interface = GetInterface (i);
return interface->GetMetric ();
}
@@ -844,7 +835,7 @@ Ipv4L3Protocol::GetIfIndexForDestination (
Ipv4Address destination, uint32_t& ifIndex) const
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << destination << ", " << &ifIndex << ")");
NS_LOG_PARAMS (this << destination << &ifIndex);
//
// The first thing we do in trying to determine a source address is to
// consult the routing protocols. These will also check for a default route
@@ -911,7 +902,7 @@ uint16_t
Ipv4L3Protocol::GetMtu (uint32_t i) const
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << i << ")");
NS_LOG_PARAMS (this << i);
Ptr<Ipv4Interface> interface = GetInterface (i);
return interface->GetMtu ();
}
@@ -920,7 +911,7 @@ bool
Ipv4L3Protocol::IsUp (uint32_t i) const
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << i << ")");
NS_LOG_PARAMS (this << i);
Ptr<Ipv4Interface> interface = GetInterface (i);
return interface->IsUp ();
}
@@ -929,7 +920,7 @@ void
Ipv4L3Protocol::SetUp (uint32_t i)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << i << ")");
NS_LOG_PARAMS (this << i);
Ptr<Ipv4Interface> interface = GetInterface (i);
interface->SetUp ();
@@ -948,7 +939,7 @@ void
Ipv4L3Protocol::SetDown (uint32_t ifaceIndex)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << ifaceIndex << ")");
NS_LOG_PARAMS (this << ifaceIndex);
Ptr<Ipv4Interface> interface = GetInterface (ifaceIndex);
interface->SetDown ();

View File

@@ -47,7 +47,7 @@ void
Ipv4LoopbackInterface::SendTo (Packet packet, Ipv4Address dest)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << &packet << ", " << dest << ")");
NS_LOG_PARAMS (this << &packet << dest);
Ptr<Ipv4L3Protocol> ipv4 =
m_node->QueryInterface<Ipv4L3Protocol> (Ipv4L3Protocol::iid);

View File

@@ -522,8 +522,7 @@ Ipv4StaticRouting::RequestRoute (
RouteReplyCallback routeReply)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << ifIndex << &ipHeader << ", " << &packet << ", " <<
&routeReply << ")");
NS_LOG_PARAMS (this << ifIndex << &ipHeader << &packet << &routeReply);
NS_LOG_LOGIC ("source = " << ipHeader.GetSource ());
@@ -576,7 +575,7 @@ bool
Ipv4StaticRouting::RequestIfIndex (Ipv4Address destination, uint32_t& ifIndex)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << destination << ", " << &ifIndex << ")");
NS_LOG_PARAMS (this << destination << &ifIndex);
//
// First, see if this is a multicast packet we have a route for. If we
// have a route, then send the packet down each of the specified interfaces.

View File

@@ -83,7 +83,7 @@ Ipv4EndPoint *
UdpL4Protocol::Allocate (Ipv4Address address)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << address << ")");
NS_LOG_PARAMS (this << address);
return m_endPoints->Allocate (address);
}
@@ -91,7 +91,7 @@ Ipv4EndPoint *
UdpL4Protocol::Allocate (uint16_t port)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << port << ")");
NS_LOG_PARAMS (this << port);
return m_endPoints->Allocate (port);
}
@@ -99,7 +99,7 @@ Ipv4EndPoint *
UdpL4Protocol::Allocate (Ipv4Address address, uint16_t port)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << address << ", " << port << ")");
NS_LOG_PARAMS (this << address << port);
return m_endPoints->Allocate (address, port);
}
Ipv4EndPoint *
@@ -107,8 +107,7 @@ UdpL4Protocol::Allocate (Ipv4Address localAddress, uint16_t localPort,
Ipv4Address peerAddress, uint16_t peerPort)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << localAddress << ", " << localPort << ", " <<
peerAddress << ", " << peerPort << ")");
NS_LOG_PARAMS (this << localAddress << localPort << peerAddress << peerPort);
return m_endPoints->Allocate (localAddress, localPort,
peerAddress, peerPort);
}
@@ -117,7 +116,7 @@ void
UdpL4Protocol::DeAllocate (Ipv4EndPoint *endPoint)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << endPoint << ")");
NS_LOG_PARAMS (this << endPoint);
m_endPoints->DeAllocate (endPoint);
}
@@ -128,8 +127,7 @@ UdpL4Protocol::Receive(Packet& packet,
Ptr<Ipv4Interface> interface)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << &packet << ", " << source << ", " << destination <<
")");
NS_LOG_PARAMS (this << &packet << source << destination);
UdpHeader udpHeader;
packet.RemoveHeader (udpHeader);
@@ -149,8 +147,7 @@ UdpL4Protocol::Send (Packet packet,
uint16_t sport, uint16_t dport)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << &packet << ", " << saddr << ", " << daddr << ", " <<
sport << ", " << dport << ")");
NS_LOG_PARAMS (this << &packet << saddr << daddr << sport << dport);
UdpHeader udpHeader;
udpHeader.SetDestination (dport);

View File

@@ -117,7 +117,7 @@ int
UdpSocket::Bind (const Address &address)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM("(" << address << ")");
NS_LOG_PARAMS (this << address);
if (!InetSocketAddress::IsMatchingType (address))
{
@@ -175,7 +175,7 @@ int
UdpSocket::Connect(const Address & address)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << address << ")");
NS_LOG_PARAMS (this << address);
Ipv4Route routeToDest;
InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
m_defaultAddress = transport.GetIpv4 ();
@@ -190,7 +190,7 @@ int
UdpSocket::Send (const Packet &p)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << &p << ")");
NS_LOG_PARAMS (this << &p);
if (!m_connected)
{
@@ -226,7 +226,7 @@ int
UdpSocket::DoSendTo (const Packet &p, const Address &address)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << &p << ", " << address << ")");
NS_LOG_PARAMS (this << &p << address);
if (!m_connected)
{
@@ -248,7 +248,7 @@ int
UdpSocket::DoSendTo (const Packet &p, Ipv4Address dest, uint16_t port)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << &p << ", " << dest << ", " << port << ")");
NS_LOG_PARAMS (this << &p << dest << port);
Ipv4Route routeToDest;
@@ -308,7 +308,7 @@ int
UdpSocket::SendTo(const Address &address, const Packet &p)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << address << ", " << &p << ")");
NS_LOG_PARAMS (this << address << &p);
InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
Ipv4Address ipv4 = transport.GetIpv4 ();
uint16_t port = transport.GetPort ();
@@ -319,7 +319,7 @@ void
UdpSocket::ForwardUp (const Packet &packet, Ipv4Address ipv4, uint16_t port)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << &packet << ", " << ipv4 << ", " << port << ")");
NS_LOG_PARAMS (this << &packet << ipv4 << port);
if (m_shutdownRecv)
{

View File

@@ -46,7 +46,7 @@ GridTopology::LayoutOneRowFirst (Ptr<Object> object, uint32_t i)
Ptr<MobilityModel> mobility = ComponentManager::Create<MobilityModel> (m_positionClassId,
MobilityModel::iid);
object->AddInterface (mobility);
mobility->Set (Position (x, y, 0.0));
mobility->SetPosition (Vector (x, y, 0.0));
}
void
@@ -58,7 +58,7 @@ GridTopology::LayoutOneColumnFirst (Ptr<Object> object, uint32_t i)
Ptr<MobilityModel> mobility = ComponentManager::Create<MobilityModel> (m_positionClassId,
MobilityModel::iid);
object->AddInterface (mobility);
mobility->Set (Position (x, y, 0.0));
mobility->SetPosition (Vector (x, y, 0.0));
}

View File

@@ -56,34 +56,34 @@ HierarchicalMobilityModel::GetParent (void) const
return m_parent;
}
Position
HierarchicalMobilityModel::DoGet (void) const
Vector
HierarchicalMobilityModel::DoGetPosition (void) const
{
Position parentPosition = m_parent->Get ();
Position childPosition = m_child->Get ();
return Position (parentPosition.x + childPosition.x,
Vector parentPosition = m_parent->GetPosition ();
Vector childPosition = m_child->GetPosition ();
return Vector (parentPosition.x + childPosition.x,
parentPosition.y + childPosition.y,
parentPosition.z + childPosition.z);
}
void
HierarchicalMobilityModel::DoSet (const Position &position)
HierarchicalMobilityModel::DoSetPosition (const Vector &position)
{
// This implementation of DoSet is really an arbitraty choice.
// This implementation of DoSetPosition is really an arbitraty choice.
// anything else would have been ok.
Position parentPosition = m_parent->Get ();
Position childPosition (position.x - parentPosition.x,
Vector parentPosition = m_parent->GetPosition ();
Vector childPosition (position.x - parentPosition.x,
position.y - parentPosition.y,
position.z - parentPosition.z);
m_child->Set (childPosition);
m_child->SetPosition (childPosition);
}
Speed
HierarchicalMobilityModel::DoGetSpeed (void) const
Vector
HierarchicalMobilityModel::DoGetVelocity (void) const
{
Speed parentSpeed = m_parent->GetSpeed ();
Speed childSpeed = m_child->GetSpeed ();
Speed speed (parentSpeed.dx + childSpeed.dx,
parentSpeed.dy + childSpeed.dy,
parentSpeed.dz + childSpeed.dz);
Vector parentSpeed = m_parent->GetVelocity ();
Vector childSpeed = m_child->GetVelocity ();
Vector speed (parentSpeed.x + childSpeed.x,
parentSpeed.y + childSpeed.y,
parentSpeed.z + childSpeed.z);
return speed;
}

View File

@@ -58,9 +58,9 @@ public:
Ptr<MobilityModel> GetParent (void) const;
private:
virtual Position DoGet (void) const;
virtual void DoSet (const Position &position);
virtual Speed DoGetSpeed (void) const;
virtual Vector DoGetPosition (void) const;
virtual void DoSetPosition (const Vector &position);
virtual Vector DoGetVelocity (void) const;
void ParentChanged (const TraceContext &context, Ptr<const MobilityModel> model);
void ChildChanged (const TraceContext &context, Ptr<const MobilityModel> model);

View File

@@ -33,28 +33,28 @@ MobilityModel::MobilityModel ()
MobilityModel::~MobilityModel ()
{}
Position
MobilityModel::Get (void) const
Vector
MobilityModel::GetPosition (void) const
{
return DoGet ();
return DoGetPosition ();
}
Speed
MobilityModel::GetSpeed (void) const
Vector
MobilityModel::GetVelocity (void) const
{
return DoGetSpeed ();
return DoGetVelocity ();
}
void
MobilityModel::Set (const Position &position)
MobilityModel::SetPosition (const Vector &position)
{
DoSet (position);
DoSetPosition (position);
}
double
MobilityModel::GetDistanceFrom (Ptr<const MobilityModel> other) const
{
Position oPosition = other->DoGet ();
Position position = DoGet ();
Vector oPosition = other->DoGetPosition ();
Vector position = DoGetPosition ();
return CalculateDistance (position, oPosition);
}

View File

@@ -21,8 +21,7 @@
#define MOBILITY_MODEL_H
#include "ns3/object.h"
#include "position.h"
#include "speed.h"
#include "vector.h"
namespace ns3 {
@@ -43,15 +42,15 @@ public:
/**
* \returns the current position
*/
Position Get (void) const;
Vector GetPosition (void) const;
/**
* \param position the position to set.
*/
void Set (const Position &position);
void SetPosition (const Vector &position);
/**
* \returns the current position.
* \returns the current velocity.
*/
Speed GetSpeed (void) const;
Vector GetVelocity (void) const;
/**
* \param position a reference to another mobility model
* \returns the distance between the two objects. Unit is meters.
@@ -70,21 +69,21 @@ private:
* Concrete subclasses of this base class must
* implement this method.
*/
virtual Position DoGet (void) const = 0;
virtual Vector DoGetPosition (void) const = 0;
/**
* \param position the position to set.
*
* Concrete subclasses of this base class must
* implement this method.
*/
virtual void DoSet (const Position &position) = 0;
virtual void DoSetPosition (const Vector &position) = 0;
/**
* \returns the current speed.
* \returns the current velocity.
*
* Concrete subclasses of this base class must
* implement this method.
*/
virtual Speed DoGetSpeed (void) const = 0;
virtual Vector DoGetVelocity (void) const = 0;
};
}; // namespace ns3

View File

@@ -97,7 +97,7 @@ Ns2MobilityFileTopology::LayoutObjectStore (const ObjectStore &store) const
{
double value = ReadDouble (line.substr (endNodeId + 9, std::string::npos));
std::string coordinate = line.substr (endNodeId + 6, 1);
Position position = model->Get ();
Vector position = model->GetPosition ();
if (coordinate == "X")
{
position.x = value;
@@ -117,7 +117,7 @@ Ns2MobilityFileTopology::LayoutObjectStore (const ObjectStore &store) const
{
continue;
}
model->Set (position);
model->SetPosition (position);
}
else
{
@@ -129,7 +129,7 @@ Ns2MobilityFileTopology::LayoutObjectStore (const ObjectStore &store) const
double zSpeed = ReadDouble (line.substr (ySpeedEnd + 1, std::string::npos));
NS_LOG_DEBUG ("at=" << at << "xSpeed=" << xSpeed << ", ySpeed=" << ySpeed << ", zSpeed=" << zSpeed);
Simulator::Schedule (Seconds (at), &StaticSpeedMobilityModel::SetSpeed, model,
Speed (xSpeed, ySpeed, zSpeed));
Vector (xSpeed, ySpeed, zSpeed));
}
}
file.close();

View File

@@ -153,12 +153,12 @@ RandomDirection2dMobilityModel::SetDirectionAndSpeed (double direction)
{
NS_LOG_FUNCTION;
double speed = m_parameters->m_speedVariable->GetValue ();
const Speed vector (std::cos (direction) * speed,
std::sin (direction) * speed,
0.0);
Position position = m_helper.GetCurrentPosition (m_parameters->m_bounds);
const Vector vector (std::cos (direction) * speed,
std::sin (direction) * speed,
0.0);
Vector position = m_helper.GetCurrentPosition (m_parameters->m_bounds);
m_helper.Reset (vector);
Position next = m_parameters->m_bounds.CalculateIntersection (position, vector);
Vector next = m_parameters->m_bounds.CalculateIntersection (position, vector);
Time delay = Seconds (CalculateDistance (position, next) / speed);
m_event = Simulator::Schedule (delay,
&RandomDirection2dMobilityModel::BeginPause, this);
@@ -169,7 +169,7 @@ RandomDirection2dMobilityModel::ResetDirectionAndSpeed (void)
{
double direction = UniformVariable::GetSingleValue (0, PI);
Position position = m_helper.GetCurrentPosition (m_parameters->m_bounds);
Vector position = m_helper.GetCurrentPosition (m_parameters->m_bounds);
switch (m_parameters->m_bounds.GetClosestSide (position))
{
case Rectangle::RIGHT:
@@ -187,22 +187,22 @@ RandomDirection2dMobilityModel::ResetDirectionAndSpeed (void)
}
SetDirectionAndSpeed (direction);
}
Position
RandomDirection2dMobilityModel::DoGet (void) const
Vector
RandomDirection2dMobilityModel::DoGetPosition (void) const
{
return m_helper.GetCurrentPosition (m_parameters->m_bounds);
}
void
RandomDirection2dMobilityModel::DoSet (const Position &position)
RandomDirection2dMobilityModel::DoSetPosition (const Vector &position)
{
m_helper.InitializePosition (position);
Simulator::Remove (m_event);
m_event = Simulator::ScheduleNow (&RandomDirection2dMobilityModel::Start, this);
}
Speed
RandomDirection2dMobilityModel::DoGetSpeed (void) const
Vector
RandomDirection2dMobilityModel::DoGetVelocity (void) const
{
return m_helper.GetSpeed ();
return m_helper.GetVelocity ();
}

View File

@@ -110,9 +110,9 @@ class RandomDirection2dMobilityModel : public MobilityModel
void SetDirectionAndSpeed (double direction);
void InitializeDirectionAndSpeed (void);
virtual void DoDispose (void);
virtual Position DoGet (void) const;
virtual void DoSet (const Position &position);
virtual Speed DoGetSpeed (void) const;
virtual Vector DoGetPosition (void) const;
virtual void DoSetPosition (const Vector &position);
virtual Vector DoGetVelocity (void) const;
static const double PI;
Ptr<RandomDirection2dMobilityModelParameters> m_parameters;

View File

@@ -91,12 +91,12 @@ RandomRectanglePosition::~RandomRectanglePosition ()
m_x = 0;
m_y = 0;
}
Position
Vector
RandomRectanglePosition::Get (void) const
{
double x = m_x->GetValue ();
double y = m_y->GetValue ();
return Position (x, y, 0.0);
return Vector (x, y, 0.0);
}
RandomDiscPosition::RandomDiscPosition ()
@@ -120,7 +120,7 @@ RandomDiscPosition::~RandomDiscPosition ()
m_theta = 0;
m_rho = 0;
}
Position
Vector
RandomDiscPosition::Get (void) const
{
double theta = m_theta->GetValue ();
@@ -128,7 +128,7 @@ RandomDiscPosition::Get (void) const
double x = m_x + std::cos (theta) * rho;
double y = m_y + std::sin (theta) * rho;
NS_LOG_DEBUG ("Disc position x=" << x << ", y=" << y);
return Position (x, y, 0.0);
return Vector (x, y, 0.0);
}

View File

@@ -22,7 +22,7 @@
#include "ns3/object.h"
#include "ns3/component-manager.h"
#include "position.h"
#include "vector.h"
namespace ns3 {
@@ -42,7 +42,7 @@ public:
/**
* \returns the next randomly-choosen position.
*/
virtual Position Get (void) const = 0;
virtual Vector Get (void) const = 0;
};
/**
@@ -68,7 +68,7 @@ public:
RandomRectanglePosition (const RandomVariable &x,
const RandomVariable &y);
virtual ~RandomRectanglePosition ();
virtual Position Get (void) const;
virtual Vector Get (void) const;
private:
RandomVariable *m_x;
RandomVariable *m_y;
@@ -106,7 +106,7 @@ public:
const RandomVariable &rho,
double x, double y);
virtual ~RandomDiscPosition ();
virtual Position Get (void) const;
virtual Vector Get (void) const;
private:
RandomVariable *m_theta;
RandomVariable *m_rho;

View File

@@ -70,8 +70,8 @@ RandomTopology::LayoutOne (Ptr<Object> object)
Ptr<MobilityModel> mobility = ComponentManager::Create<MobilityModel> (m_mobilityModel,
MobilityModel::iid);
object->AddInterface (mobility);
Position position = m_positionModel->Get ();
mobility->Set (position);
Vector position = m_positionModel->Get ();
mobility->SetPosition (position);
}

View File

@@ -143,9 +143,9 @@ RandomWalk2dMobilityModel::Start (void)
{
double speed = m_parameters->m_speed->GetValue ();
double direction = m_parameters->m_direction->GetValue ();
Speed vector (std::cos (direction) * speed,
std::sin (direction) * speed,
0.0);
Vector vector (std::cos (direction) * speed,
std::sin (direction) * speed,
0.0);
m_helper.Reset (vector);
Time delayLeft;
@@ -163,11 +163,11 @@ RandomWalk2dMobilityModel::Start (void)
void
RandomWalk2dMobilityModel::DoWalk (Time delayLeft)
{
Position position = m_helper.GetCurrentPosition ();
Speed speed = m_helper.GetSpeed ();
Position nextPosition = position;
nextPosition.x += speed.dx * delayLeft.GetSeconds ();
nextPosition.y += speed.dy * delayLeft.GetSeconds ();
Vector position = m_helper.GetCurrentPosition ();
Vector speed = m_helper.GetVelocity ();
Vector nextPosition = position;
nextPosition.x += speed.x * delayLeft.GetSeconds ();
nextPosition.y += speed.y * delayLeft.GetSeconds ();
if (m_parameters->m_bounds.IsInside (nextPosition))
{
m_event = Simulator::Schedule (delayLeft, &RandomWalk2dMobilityModel::Start, this);
@@ -175,7 +175,7 @@ RandomWalk2dMobilityModel::DoWalk (Time delayLeft)
else
{
nextPosition = m_parameters->m_bounds.CalculateIntersection (position, speed);
Time delay = Seconds ((nextPosition.x - position.x) / speed.dx);
Time delay = Seconds ((nextPosition.x - position.x) / speed.x);
m_event = Simulator::Schedule (delay, &RandomWalk2dMobilityModel::Rebound, this,
delayLeft - delay);
}
@@ -185,17 +185,17 @@ RandomWalk2dMobilityModel::DoWalk (Time delayLeft)
void
RandomWalk2dMobilityModel::Rebound (Time delayLeft)
{
Position position = m_helper.GetCurrentPosition (m_parameters->m_bounds);
Speed speed = m_helper.GetSpeed ();
Vector position = m_helper.GetCurrentPosition (m_parameters->m_bounds);
Vector speed = m_helper.GetVelocity ();
switch (m_parameters->m_bounds.GetClosestSide (position))
{
case Rectangle::RIGHT:
case Rectangle::LEFT:
speed.dx = - speed.dx;
speed.x = - speed.x;
break;
case Rectangle::TOP:
case Rectangle::BOTTOM:
speed.dy = - speed.dy;
speed.y = - speed.y;
break;
}
m_helper.Reset (speed);
@@ -209,23 +209,23 @@ RandomWalk2dMobilityModel::DoDispose (void)
// chain up
MobilityModel::DoDispose ();
}
Position
RandomWalk2dMobilityModel::DoGet (void) const
Vector
RandomWalk2dMobilityModel::DoGetPosition (void) const
{
return m_helper.GetCurrentPosition (m_parameters->m_bounds);
}
void
RandomWalk2dMobilityModel::DoSet (const Position &position)
RandomWalk2dMobilityModel::DoSetPosition (const Vector &position)
{
NS_ASSERT (m_parameters->m_bounds.IsInside (position));
m_helper.InitializePosition (position);
Simulator::Remove (m_event);
m_event = Simulator::ScheduleNow (&RandomWalk2dMobilityModel::Start, this);
}
Speed
RandomWalk2dMobilityModel::DoGetSpeed (void) const
Vector
RandomWalk2dMobilityModel::DoGetVelocity (void) const
{
return m_helper.GetSpeed ();
return m_helper.GetVelocity ();
}

View File

@@ -141,9 +141,9 @@ class RandomWalk2dMobilityModel : public MobilityModel
void Rebound (Time timeLeft);
void DoWalk (Time timeLeft);
virtual void DoDispose (void);
virtual Position DoGet (void) const;
virtual void DoSet (const Position &position);
virtual Speed DoGetSpeed (void) const;
virtual Vector DoGetPosition (void) const;
virtual void DoSetPosition (const Vector &position);
virtual Vector DoGetVelocity (void) const;
StaticSpeedHelper m_helper;
EventId m_event;

View File

@@ -117,15 +117,15 @@ RandomWaypointMobilityModel::RandomWaypointMobilityModel (Ptr<RandomWaypointMobi
void
RandomWaypointMobilityModel::BeginWalk (void)
{
Position m_current = m_helper.GetCurrentPosition ();
Position destination = m_parameters->m_position->Get ();
Vector m_current = m_helper.GetCurrentPosition ();
Vector destination = m_parameters->m_position->Get ();
double speed = m_parameters->m_speed->GetValue ();
double dx = (destination.x - m_current.x);
double dy = (destination.y - m_current.y);
double dz = (destination.z - m_current.z);
double k = speed / std::sqrt (dx*dx + dy*dy + dz*dz);
m_helper.Reset (Speed (k*dx, k*dy, k*dz));
m_helper.Reset (Vector (k*dx, k*dy, k*dz));
Time travelDelay = Seconds (CalculateDistance (destination, m_current) / speed);
m_event = Simulator::Schedule (travelDelay,
&RandomWaypointMobilityModel::Start, this);
@@ -141,22 +141,22 @@ RandomWaypointMobilityModel::Start (void)
m_event = Simulator::Schedule (pause, &RandomWaypointMobilityModel::BeginWalk, this);
}
Position
RandomWaypointMobilityModel::DoGet (void) const
Vector
RandomWaypointMobilityModel::DoGetPosition (void) const
{
return m_helper.GetCurrentPosition ();
}
void
RandomWaypointMobilityModel::DoSet (const Position &position)
RandomWaypointMobilityModel::DoSetPosition (const Vector &position)
{
m_helper.InitializePosition (position);
Simulator::Remove (m_event);
Simulator::ScheduleNow (&RandomWaypointMobilityModel::Start, this);
}
Speed
RandomWaypointMobilityModel::DoGetSpeed (void) const
Vector
RandomWaypointMobilityModel::DoGetVelocity (void) const
{
return m_helper.GetSpeed ();
return m_helper.GetVelocity ();
}

View File

@@ -100,9 +100,9 @@ public:
private:
void Start (void);
void BeginWalk (void);
virtual Position DoGet (void) const;
virtual void DoSet (const Position &position);
virtual Speed DoGetSpeed (void) const;
virtual Vector DoGetPosition (void) const;
virtual void DoSetPosition (const Vector &position);
virtual Vector DoGetVelocity (void) const;
StaticSpeedHelper m_helper;
Ptr<RandomWaypointMobilityModelParameters> m_parameters;

View File

@@ -18,8 +18,7 @@
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#include "rectangle.h"
#include "position.h"
#include "speed.h"
#include "vector.h"
#include "ns3/assert.h"
#include <cmath>
#include <algorithm>
@@ -42,7 +41,7 @@ Rectangle::Rectangle ()
{}
bool
Rectangle::IsInside (const Position &position) const
Rectangle::IsInside (const Vector &position) const
{
return
position.x <= this->xMax && position.x >= this->xMin &&
@@ -50,7 +49,7 @@ Rectangle::IsInside (const Position &position) const
}
Rectangle::Side
Rectangle::GetClosestSide (const Position &position) const
Rectangle::GetClosestSide (const Vector &position) const
{
double xMinDist = std::abs (position.x - this->xMin);
double xMaxDist = std::abs (this->xMax - position.x);
@@ -82,38 +81,38 @@ Rectangle::GetClosestSide (const Position &position) const
}
}
Position
Rectangle::CalculateIntersection (const Position &current, const Speed &speed) const
Vector
Rectangle::CalculateIntersection (const Vector &current, const Vector &speed) const
{
double xMaxY = current.y + (this->xMax - current.x) / speed.dx * speed.dy;
double xMinY = current.y + (this->xMin - current.x) / speed.dx * speed.dy;
double yMaxX = current.x + (this->yMax - current.y) / speed.dy * speed.dx;
double yMinX = current.x + (this->yMin - current.y) / speed.dy * speed.dx;
double xMaxY = current.y + (this->xMax - current.x) / speed.x * speed.y;
double xMinY = current.y + (this->xMin - current.x) / speed.x * speed.y;
double yMaxX = current.x + (this->yMax - current.y) / speed.y * speed.x;
double yMinX = current.x + (this->yMin - current.y) / speed.y * speed.x;
bool xMaxYOk = (xMaxY <= this->yMax && xMaxY >= this->yMin);
bool xMinYOk = (xMinY <= this->yMax && xMinY >= this->yMin);
bool yMaxXOk = (yMaxX <= this->xMax && yMaxX >= this->xMin);
bool yMinXOk = (yMinX <= this->xMax && yMinX >= this->xMin);
if (xMaxYOk && speed.dx >= 0)
if (xMaxYOk && speed.x >= 0)
{
return Position (this->xMax, xMaxY, 0.0);
return Vector (this->xMax, xMaxY, 0.0);
}
else if (xMinYOk && speed.dx <= 0)
else if (xMinYOk && speed.x <= 0)
{
return Position (this->xMin, xMinY, 0.0);
return Vector (this->xMin, xMinY, 0.0);
}
else if (yMaxXOk && speed.dy >= 0)
else if (yMaxXOk && speed.y >= 0)
{
return Position (yMaxX, this->yMax, 0.0);
return Vector (yMaxX, this->yMax, 0.0);
}
else if (yMinXOk && speed.dy <= 0)
else if (yMinXOk && speed.y <= 0)
{
return Position (yMinX, this->yMin, 0.0);
return Vector (yMinX, this->yMin, 0.0);
}
else
{
NS_ASSERT (false);
// quiet compiler
return Position (0.0, 0.0, 0.0);
return Vector (0.0, 0.0, 0.0);
}
}

View File

@@ -22,8 +22,7 @@
namespace ns3 {
class Position;
class Speed;
class Vector;
/**
* \brief a 2d rectangle
@@ -51,9 +50,9 @@ public:
* Create a zero-sized rectangle located at coordinates (0.0,0.0)
*/
Rectangle ();
bool IsInside (const Position &position) const;
Side GetClosestSide (const Position &position) const;
Position CalculateIntersection (const Position &current, const Speed &speed) const;
bool IsInside (const Vector &position) const;
Side GetClosestSide (const Vector &position) const;
Vector CalculateIntersection (const Vector &current, const Vector &speed) const;
double xMin;
double xMax;

View File

@@ -1,36 +0,0 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2007 INRIA
*
* 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
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#include "speed.h"
namespace ns3 {
Speed::Speed (double _dx, double _dy, double _dz)
: dx (_dx),
dy (_dy),
dz (_dz)
{}
Speed::Speed ()
: dx (0.0),
dy (0.0),
dz (0.0)
{}
} // namespace ns3

View File

@@ -1,61 +0,0 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2007 INRIA
*
* 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
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#ifndef SPEED_H
#define SPEED_H
namespace ns3 {
/**
* \brief keep track of 3d cartesian speed vectors
*
* Unit is meters/s.
*/
class Speed
{
public:
/**
* \param _dx x coordinate of speed vector
* \param _dy y coordinate of speed vector
* \param _dz z coordinate of speed vector
*
* Create speed vector (_dx, _dy, _dz)
*/
Speed (double _dx, double _dy, double _dz);
/**
* Create speed vector (0.0, 0.0, 0.0)
*/
Speed ();
/**
* x coordinate of speed vector
*/
double dx;
/**
* y coordinate of speed vector
*/
double dy;
/**
* z coordinate of speed vector
*/
double dz;
};
} // namespace ns3
#endif /* SPEED_H */

View File

@@ -28,7 +28,7 @@ StaticMobilityModel::StaticMobilityModel ()
{
SetInterfaceId (StaticMobilityModel::iid);
}
StaticMobilityModel::StaticMobilityModel (const Position &position)
StaticMobilityModel::StaticMobilityModel (const Vector &position)
: m_position (position)
{
SetInterfaceId (StaticMobilityModel::iid);
@@ -36,21 +36,21 @@ StaticMobilityModel::StaticMobilityModel (const Position &position)
StaticMobilityModel::~StaticMobilityModel ()
{}
Position
StaticMobilityModel::DoGet (void) const
Vector
StaticMobilityModel::DoGetPosition (void) const
{
return m_position;
}
void
StaticMobilityModel::DoSet (const Position &position)
StaticMobilityModel::DoSetPosition (const Vector &position)
{
m_position = position;
NotifyCourseChange ();
}
Speed
StaticMobilityModel::DoGetSpeed (void) const
Vector
StaticMobilityModel::DoGetVelocity (void) const
{
return Speed ();
return Vector (0.0, 0.0, 0.0);
}
}; // namespace ns3

View File

@@ -44,15 +44,15 @@ public:
* Create a position located at coordinates (x,y,z).
* Unit is meters
*/
StaticMobilityModel (const Position &position);
StaticMobilityModel (const Vector &position);
virtual ~StaticMobilityModel ();
private:
virtual Position DoGet (void) const;
virtual void DoSet (const Position &position);
virtual Speed DoGetSpeed (void) const;
virtual Vector DoGetPosition (void) const;
virtual void DoSetPosition (const Vector &position);
virtual Vector DoGetVelocity (void) const;
Position m_position;
Vector m_position;
};
}; // namespace ns3

View File

@@ -25,40 +25,40 @@ namespace ns3 {
StaticSpeedHelper::StaticSpeedHelper ()
{}
StaticSpeedHelper::StaticSpeedHelper (const Position &position)
StaticSpeedHelper::StaticSpeedHelper (const Vector &position)
: m_position (position)
{}
StaticSpeedHelper::StaticSpeedHelper (const Position &position,
const Speed &speed)
StaticSpeedHelper::StaticSpeedHelper (const Vector &position,
const Vector &speed)
: m_position (position),
m_speed (speed),
m_paused (true)
{}
void
StaticSpeedHelper::InitializePosition (const Position &position)
StaticSpeedHelper::InitializePosition (const Vector &position)
{
m_position = position;
m_speed.dx = 0.0;
m_speed.dy = 0.0;
m_speed.dz = 0.0;
m_speed.x = 0.0;
m_speed.y = 0.0;
m_speed.z = 0.0;
m_lastUpdate = Simulator::Now ();
m_paused = true;
}
Position
Vector
StaticSpeedHelper::GetCurrentPosition (void) const
{
Update ();
return m_position;
}
Speed
StaticSpeedHelper::GetSpeed (void) const
Vector
StaticSpeedHelper::GetVelocity (void) const
{
return m_paused? Speed (0, 0, 0) : m_speed;
return m_paused? Vector (0.0, 0.0, 0.0) : m_speed;
}
void
StaticSpeedHelper::SetSpeed (const Speed &speed)
StaticSpeedHelper::SetSpeed (const Vector &speed)
{
Update ();
m_speed = speed;
@@ -76,13 +76,13 @@ StaticSpeedHelper::Update (void) const
Time deltaTime = now - m_lastUpdate;
m_lastUpdate = now;
double deltaS = deltaTime.GetSeconds ();
m_position.x += m_speed.dx * deltaS;
m_position.y += m_speed.dy * deltaS;
m_position.z += m_speed.dz * deltaS;
m_position.x += m_speed.x * deltaS;
m_position.y += m_speed.y * deltaS;
m_position.z += m_speed.z * deltaS;
}
void
StaticSpeedHelper::Reset (const Speed &speed)
StaticSpeedHelper::Reset (const Vector &speed)
{
Update ();
m_speed = speed;
@@ -98,7 +98,7 @@ StaticSpeedHelper::UpdateFull (const Rectangle &bounds) const
m_position.y = std::max (bounds.yMin, m_position.y);
}
Position
Vector
StaticSpeedHelper::GetCurrentPosition (const Rectangle &bounds) const
{
UpdateFull (bounds);

View File

@@ -21,8 +21,7 @@
#define STATIC_SPEED_HELPER_H
#include "ns3/nstime.h"
#include "position.h"
#include "speed.h"
#include "vector.h"
namespace ns3 {
@@ -32,16 +31,16 @@ class StaticSpeedHelper
{
public:
StaticSpeedHelper ();
StaticSpeedHelper (const Position &position);
StaticSpeedHelper (const Position &position,
const Speed &speed);
void InitializePosition (const Position &position);
StaticSpeedHelper (const Vector &position);
StaticSpeedHelper (const Vector &position,
const Vector &speed);
void InitializePosition (const Vector &position);
void Reset (const Speed &speed);
Position GetCurrentPosition (const Rectangle &bounds) const;
Position GetCurrentPosition (void) const;
Speed GetSpeed (void) const;
void SetSpeed (const Speed &speed);
void Reset (const Vector &speed);
Vector GetCurrentPosition (const Rectangle &bounds) const;
Vector GetCurrentPosition (void) const;
Vector GetVelocity (void) const;
void SetSpeed (const Vector &speed);
void Pause (void);
void Unpause (void);
@@ -49,8 +48,8 @@ class StaticSpeedHelper
void Update (void) const;
void UpdateFull (const Rectangle &rectangle) const;
mutable Time m_lastUpdate;
mutable Position m_position;
Speed m_speed;
mutable Vector m_position;
Vector m_speed;
bool m_paused;
};

View File

@@ -33,13 +33,13 @@ StaticSpeedMobilityModel::StaticSpeedMobilityModel ()
{
SetInterfaceId (StaticSpeedMobilityModel::iid);
}
StaticSpeedMobilityModel::StaticSpeedMobilityModel (const Position &position)
StaticSpeedMobilityModel::StaticSpeedMobilityModel (const Vector &position)
: m_helper (position)
{
SetInterfaceId (StaticSpeedMobilityModel::iid);
}
StaticSpeedMobilityModel::StaticSpeedMobilityModel (const Position &position,
const Speed &speed)
StaticSpeedMobilityModel::StaticSpeedMobilityModel (const Vector &position,
const Vector &speed)
: m_helper (position, speed)
{
SetInterfaceId (StaticSpeedMobilityModel::iid);
@@ -49,28 +49,28 @@ StaticSpeedMobilityModel::~StaticSpeedMobilityModel ()
{}
void
StaticSpeedMobilityModel::SetSpeed (const Speed speed)
StaticSpeedMobilityModel::SetSpeed (const Vector &speed)
{
m_helper.SetSpeed (speed);
NotifyCourseChange ();
}
Position
StaticSpeedMobilityModel::DoGet (void) const
Vector
StaticSpeedMobilityModel::DoGetPosition (void) const
{
return m_helper.GetCurrentPosition ();
}
void
StaticSpeedMobilityModel::DoSet (const Position &position)
StaticSpeedMobilityModel::DoSetPosition (const Vector &position)
{
m_helper.InitializePosition (position);
NotifyCourseChange ();
}
Speed
StaticSpeedMobilityModel::DoGetSpeed (void) const
Vector
StaticSpeedMobilityModel::DoGetVelocity (void) const
{
return m_helper.GetSpeed ();
return m_helper.GetVelocity ();
}
}; // namespace ns3

View File

@@ -25,7 +25,6 @@
#include "ns3/nstime.h"
#include "ns3/component-manager.h"
#include "static-speed-helper.h"
#include "speed.h"
namespace ns3 {
@@ -48,15 +47,15 @@ public:
* Create a position located at coordinates (x,y,z) with
* speed (0,0,0).
*/
StaticSpeedMobilityModel (const Position &position);
StaticSpeedMobilityModel (const Vector &position);
/**
*
* Create a position located at coordinates (x,y,z) with
* speed (dx,dy,dz).
* Unit is meters and meters/s
*/
StaticSpeedMobilityModel (const Position &position,
const Speed &speed);
StaticSpeedMobilityModel (const Vector &position,
const Vector &speed);
virtual ~StaticSpeedMobilityModel ();
/**
@@ -65,11 +64,11 @@ public:
* Set the current speed now to (dx,dy,dz)
* Unit is meters/s
*/
void SetSpeed (const Speed speed);
void SetSpeed (const Vector &speed);
private:
virtual Position DoGet (void) const;
virtual void DoSet (const Position &position);
virtual Speed DoGetSpeed (void) const;
virtual Vector DoGetPosition (void) const;
virtual void DoSetPosition (const Vector &position);
virtual Vector DoGetVelocity (void) const;
void Update (void) const;
StaticSpeedHelper m_helper;
};

View File

@@ -17,26 +17,26 @@
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#include "position.h"
#include "vector.h"
#include <cmath>
namespace ns3 {
Position::Position (double _x, double _y, double _z)
Vector::Vector (double _x, double _y, double _z)
: x (_x),
y (_y),
z (_z)
{}
Position::Position ()
Vector::Vector ()
: x (0.0),
y (0.0),
z (0.0)
{}
double
CalculateDistance (const Position &a, const Position &b)
CalculateDistance (const Vector &a, const Vector &b)
{
double dx = b.x - a.x;
double dy = b.y - a.y;

View File

@@ -17,8 +17,8 @@
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#ifndef POSITION_H
#define POSITION_H
#ifndef VECTOR_H
#define VECTOR_H
namespace ns3 {
@@ -27,37 +27,37 @@ namespace ns3 {
*
* Unit is meters.
*/
class Position
class Vector
{
public:
/**
* \param _x x coordinate of position vector
* \param _y y coordinate of position vector
* \param _z z coordinate of position vector
* \param _x x coordinate of vector vector
* \param _y y coordinate of vector vector
* \param _z z coordinate of vector vector
*
* Create position vector (_x, _y, _z)
* Create vector vector (_x, _y, _z)
*/
Position (double _x, double _y, double _z);
Vector (double _x, double _y, double _z);
/**
* Create position vector (0.0, 0.0, 0.0)
* Create vector vector (0.0, 0.0, 0.0)
*/
Position ();
Vector ();
/**
* x coordinate of position vector
* x coordinate of vector vector
*/
double x;
/**
* y coordinate of position vector
* y coordinate of vector vector
*/
double y;
/**
* z coordinate of position vector
* z coordinate of vector vector
*/
double z;
};
double CalculateDistance (const Position &a, const Position &b);
double CalculateDistance (const Vector &a, const Vector &b);
} // namespace ns3
#endif /* POSITION_H */
#endif /* VECTOR_H */

View File

@@ -3,16 +3,15 @@
def build(bld):
mobility = bld.create_ns3_module('mobility', ['core', 'simulator'])
mobility.source = [
'vector.cc',
'grid-topology.cc',
'hierarchical-mobility-model.cc',
'mobility-model.cc',
'mobility-model-notifier.cc',
'position.cc',
'random-position.cc',
'random-topology.cc',
'rectangle.cc',
'rectangle-default-value.cc',
'speed.cc',
'static-mobility-model.cc',
'static-speed-helper.cc',
'static-speed-mobility-model.cc',
@@ -24,16 +23,15 @@ def build(bld):
headers = bld.create_obj('ns3header')
headers.source = [
'vector.h',
'grid-topology.h',
'hierarchical-mobility-model.h',
'mobility-model.h',
'mobility-model-notifier.h',
'position.h',
'random-position.h',
'random-topology.h',
'rectangle.h',
'rectangle-default-value.h',
'speed.h',
'static-mobility-model.h',
'static-speed-helper.h',
'static-speed-mobility-model.h',

View File

@@ -37,7 +37,7 @@ Channel::Channel (std::string name)
: m_name(name)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << name << ")");
NS_LOG_PARAMS (this << name);
SetInterfaceId (Channel::iid);
}
@@ -50,7 +50,7 @@ Channel::~Channel ()
Channel::SetName(std::string name)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << name << ")");
NS_LOG_PARAMS (this << name);
m_name = name;
}

View File

@@ -45,7 +45,7 @@ void
DropTailQueue::SetMaxPackets (uint32_t npackets)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << npackets << ")");
NS_LOG_PARAMS (this << npackets);
m_maxPackets = npackets;
}
@@ -61,7 +61,7 @@ bool
DropTailQueue::DoEnqueue (const Packet& p)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << &p << ")");
NS_LOG_PARAMS (this << &p);
if (m_packets.size () >= m_maxPackets)
{
@@ -78,7 +78,7 @@ bool
DropTailQueue::DoDequeue (Packet& p)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << &p << ")");
NS_LOG_PARAMS (this << &p);
if (m_packets.empty())
{
@@ -98,7 +98,7 @@ bool
DropTailQueue::DoPeek (Packet& p)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << &p << ")");
NS_LOG_PARAMS (this << &p);
if (m_packets.empty())
{
@@ -111,4 +111,69 @@ DropTailQueue::DoPeek (Packet& p)
return true;
}
} // namespace ns3
#ifdef RUN_SELF_TESTS
#include "ns3/test.h"
namespace ns3 {
class DropTailQueueTest: public Test {
public:
virtual bool RunTests (void);
DropTailQueueTest ();
};
DropTailQueueTest::DropTailQueueTest ()
: Test ("DropTailQueue") {}
bool
DropTailQueueTest::RunTests (void)
{
bool result = true;
DropTailQueue queue;
queue.SetMaxPackets (3);
Packet p1, p2, p3, p4;
NS_TEST_ASSERT_EQUAL (queue.GetNPackets (), 0);
queue.Enqueue (p1);
NS_TEST_ASSERT_EQUAL (queue.GetNPackets (), 1);
queue.Enqueue (p2);
NS_TEST_ASSERT_EQUAL (queue.GetNPackets (), 2);
queue.Enqueue (p3);
NS_TEST_ASSERT_EQUAL (queue.GetNPackets (), 3);
queue.Enqueue (p4); // will be dropped
NS_TEST_ASSERT_EQUAL (queue.GetNPackets (), 3);
Packet p;
NS_TEST_ASSERT (queue.Dequeue (p));
NS_TEST_ASSERT_EQUAL (queue.GetNPackets (), 2);
NS_TEST_ASSERT_EQUAL (p.GetUid (), p1.GetUid ());
NS_TEST_ASSERT (queue.Dequeue (p));
NS_TEST_ASSERT_EQUAL (queue.GetNPackets (), 1);
NS_TEST_ASSERT_EQUAL (p.GetUid (), p2.GetUid ());
NS_TEST_ASSERT (queue.Dequeue (p));
NS_TEST_ASSERT_EQUAL (queue.GetNPackets (), 0);
NS_TEST_ASSERT_EQUAL (p.GetUid (), p3.GetUid ());
NS_TEST_ASSERT (!queue.Dequeue (p));
return result;
}
static DropTailQueueTest gDropTailQueueTest;
}; // namespace ns3
#endif /* RUN_SELF_TESTS */

View File

@@ -36,13 +36,11 @@ Ipv4::~Ipv4 ()
{}
uint32_t
Ipv4::GetIfIndexByAddress (Ptr<Node> node, Ipv4Address a, Ipv4Mask amask)
Ipv4::GetIfIndexByAddress (Ipv4Address addr, Ipv4Mask mask)
{
Ptr<Ipv4> ipv4 = node->QueryInterface<Ipv4> (Ipv4::iid);
NS_ASSERT_MSG (ipv4, "Ipv4::GetIfIndexByAddress: No Ipv4 interface");
for (uint32_t i = 0; i < ipv4->GetNInterfaces (); i++)
for (uint32_t i = 0; i < GetNInterfaces (); i++)
{
if (ipv4->GetAddress (i).CombineMask(amask) == a.CombineMask(amask) )
if (GetAddress (i).CombineMask(mask) == addr.CombineMask(mask) )
{
return i;
}
@@ -52,44 +50,4 @@ Ipv4::GetIfIndexByAddress (Ptr<Node> node, Ipv4Address a, Ipv4Mask amask)
return 0;
}
//
// XXX BUGBUG I don't think this is really the right approach here. The call
// to GetRoute () filters down into Ipv4L3Protocol where it translates into
// a call into the Ipv4 static routing package. This bypasses any other
// routing packages. At a minimum, the name is misleading.
//
bool
Ipv4::GetRouteToDestination (
Ptr<Node> node,
Ipv4Route& route,
Ipv4Address a,
Ipv4Mask amask)
{
Ipv4Route tempRoute;
Ptr<Ipv4> ipv4 = node->QueryInterface<Ipv4> (Ipv4::iid);
NS_ASSERT_MSG (ipv4, "Ipv4::GetRouteToDestination: No Ipv4 interface");
for (uint32_t i = 0; i < ipv4->GetNRoutes (); i++)
{
tempRoute = ipv4->GetRoute (i);
// Host route found
if ( tempRoute.IsNetwork () == false && tempRoute.GetDest () == a )
{
route = tempRoute;
return true;
}
else if ( tempRoute.IsNetwork () &&
tempRoute.GetDestNetwork () == a.CombineMask(amask) )
{
route = tempRoute;
return true;
}
else if ( tempRoute.IsDefault () )
{
route = tempRoute;
return true;
}
}
return false;
}
} // namespace ns3

View File

@@ -449,16 +449,16 @@ public:
*/
virtual void SetDown (uint32_t i) = 0;
/**
* Convenience functions (Doxygen still needed)
*
* Return the ifIndex corresponding to the Ipv4Address provided.
*/
static uint32_t GetIfIndexByAddress (Ptr<Node> node, Ipv4Address a,
Ipv4Mask amask = Ipv4Mask("255.255.255.255"));
static bool GetRouteToDestination (Ptr<Node> node, Ipv4Route& route,
Ipv4Address a, Ipv4Mask amask = Ipv4Mask("255.255.255.255"));
/**
* \brief Convenience function to return the ifIndex corresponding
* to the Ipv4Address provided
*
* \param addr Ipv4Address
* \param mask corresponding Ipv4Mask
* \returns ifIndex corresponding to a/amask
*/
virtual uint32_t GetIfIndexByAddress (Ipv4Address addr,
Ipv4Mask mask = Ipv4Mask("255.255.255.255"));
};
} // namespace ns3

View File

@@ -222,22 +222,26 @@ PacketSocket::SendTo(const Address &address, const Packet &p)
PacketSocketAddress ad;
if (m_state == STATE_CLOSED)
{
NS_LOG_LOGIC ("ERROR_BADF");
m_errno = ERROR_BADF;
return -1;
}
if (m_state == STATE_OPEN)
{
// XXX should return another error here.
NS_LOG_LOGIC ("ERROR_INVAL");
m_errno = ERROR_INVAL;
return -1;
}
if (m_shutdownSend)
{
NS_LOG_LOGIC ("ERROR_SHUTDOWN");
m_errno = ERROR_SHUTDOWN;
return -1;
}
if (!PacketSocketAddress::IsMatchingType (address))
{
NS_LOG_LOGIC ("ERROR_AFNOSUPPORT");
m_errno = ERROR_AFNOSUPPORT;
return -1;
}
@@ -250,6 +254,7 @@ PacketSocket::SendTo(const Address &address, const Packet &p)
Ptr<NetDevice> device = m_node->GetDevice (ad.GetSingleDevice ());
if (!device->Send (p, dest, ad.GetProtocol ()))
{
NS_LOG_LOGIC ("error: NetDevice::Send error");
error = true;
}
}
@@ -260,6 +265,7 @@ PacketSocket::SendTo(const Address &address, const Packet &p)
Ptr<NetDevice> device = m_node->GetDevice (i);
if (!device->Send (p, dest, ad.GetProtocol ()))
{
NS_LOG_LOGIC ("error: NetDevice::Send error");
error = true;
}
}
@@ -271,6 +277,7 @@ PacketSocket::SendTo(const Address &address, const Packet &p)
if (error)
{
NS_LOG_LOGIC ("ERROR_INVAL 2");
m_errno = ERROR_INVAL;
return -1;
}

View File

@@ -139,7 +139,7 @@ bool
Queue::Enqueue (const Packet& p)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << &p << ")");
NS_LOG_PARAMS (this << &p);
NS_LOG_LOGIC ("m_traceEnqueue (p)");
m_traceEnqueue (p);
@@ -157,7 +157,7 @@ bool
Queue::Dequeue (Packet &p)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << &p << ")");
NS_LOG_PARAMS (this << &p);
bool retval = DoDequeue (p);
@@ -189,7 +189,7 @@ bool
Queue::Peek (Packet &p)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << &p << ")");
NS_LOG_PARAMS (this << &p);
return DoPeek (p);
}
@@ -264,7 +264,7 @@ void
Queue::Drop (const Packet& p)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << &p << ")");
NS_LOG_PARAMS (this << &p);
m_nTotalDroppedPackets++;
m_nTotalDroppedBytes += p.GetSize ();

View File

@@ -52,7 +52,7 @@ CandidateQueue::Clear (void)
CandidateQueue::Push (SPFVertex *vNew)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << vNew << ")");
NS_LOG_PARAMS (this << vNew);
CandidateList_t::iterator i = m_candidates.begin ();

View File

@@ -975,7 +975,7 @@ GlobalRouteManagerImpl::DebugSPFCalculate (Ipv4Address root)
GlobalRouteManagerImpl::SPFCalculate (Ipv4Address root)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << root << ")");
NS_LOG_PARAMS (this << root);
SPFVertex *v;
//
@@ -1172,7 +1172,7 @@ GlobalRouteManagerImpl::FindOutgoingInterfaceId (Ipv4Address a, Ipv4Mask amask)
// we're looking for. If we find one, return the corresponding interface
// index.
//
return (Ipv4::GetIfIndexByAddress (node, a, amask) );
return (ipv4->GetIfIndexByAddress (a, amask) );
}
}
//

View File

@@ -58,8 +58,7 @@ GlobalRoutingLinkRecord::GlobalRoutingLinkRecord (
m_metric (metric)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << linkType << ", " << linkId << ", " << linkData <<
", " << metric << ")");
NS_LOG_PARAMS (this << linkType << linkId << linkData << metric);
}
GlobalRoutingLinkRecord::~GlobalRoutingLinkRecord ()
@@ -157,8 +156,7 @@ GlobalRoutingLSA::GlobalRoutingLSA (
m_status(status)
{
NS_LOG_FUNCTION;
NS_LOG_PARAM ("(" << status << ", " << linkStateId << ", " <<
advertisingRtr << ")");
NS_LOG_PARAMS (this << status << linkStateId << advertisingRtr);
}
GlobalRoutingLSA::GlobalRoutingLSA (GlobalRoutingLSA& lsa)

View File

@@ -2112,40 +2112,3 @@ AgentImpl::IfaceAssocTupleTimerExpire (IfaceAssocTuple tuple)
}} // namespace olsr, ns3
#ifdef RUN_SELF_TESTS
#include "ns3/test.h"
namespace ns3 {
class OlsrTest : public ns3::Test {
private:
public:
OlsrTest ();
virtual bool RunTests (void);
};
OlsrTest::OlsrTest ()
: ns3::Test ("Olsr")
{}
bool
OlsrTest::RunTests (void)
{
bool result = true;
return result;
}
static OlsrTest gOlsrTest;
}
#endif /* RUN_SELF_TESTS */

View File

@@ -48,8 +48,6 @@ namespace olsr {
class AgentImpl : public Agent
{
friend class OlsrTest;
public:
AgentImpl (Ptr<Node> node);

View File

@@ -32,7 +32,7 @@ static class SchedulerListFactory : public SchedulerFactory
public:
SchedulerListFactory ()
{
SchedulerFactory::AddDefault (this, "List");
SchedulerFactory::Add (this, "List");
}
private:
virtual Scheduler *DoCreate (void) const

View File

@@ -43,7 +43,7 @@ static class SchedulerMapFactory : public SchedulerFactory
public:
SchedulerMapFactory ()
{
SchedulerFactory::Add (this, "Map");
SchedulerFactory::AddDefault (this, "Map");
}
private:
virtual Scheduler *DoCreate (void) const

View File

@@ -360,62 +360,62 @@ TimeTests::~TimeTests ()
bool TimeTests::RunTests (void)
{
bool ok = true;
bool result = true;
Time t0, t1;
CheckOld(&ok);
CheckOld(&result);
t0 = MilliSeconds ((uint64_t)10.0);
t1 = MilliSeconds ((uint64_t)11.0);
CheckOperations(t0, t1, &ok);
CheckOperations(t0, t1, &result);
// t0 = Seconds ((uint64_t)10.0);
// t1 = Seconds ((uint64_t)11.0);
// CheckOperations(t0, t1, &ok);
// CheckOperations(t0, t1, &result);
CheckConversions((uint64_t)5, &ok);
CheckConversions((uint64_t)0, &ok);
CheckConversions((uint64_t)783, &ok);
CheckConversions((uint64_t)1132, &ok);
// CheckConversions((uint64_t)3341039, &ok);
CheckConversions((uint64_t)5, &result);
CheckConversions((uint64_t)0, &result);
CheckConversions((uint64_t)783, &result);
CheckConversions((uint64_t)1132, &result);
// CheckConversions((uint64_t)3341039, &result);
// Now vary the precision and check the conversions
if (TimeStepPrecision::Get () != TimeStepPrecision::NS) {
ok = false;
result = false;
}
CheckPrecision(TimeStepPrecision::US, 7, &ok);
CheckPrecision(TimeStepPrecision::US, 7, &result);
CheckConversions((uint64_t)7, &ok);
CheckConversions((uint64_t)546, &ok);
CheckConversions((uint64_t)6231, &ok);
// CheckConversions((uint64_t)1234639, &ok);
CheckConversions((uint64_t)7, &result);
CheckConversions((uint64_t)546, &result);
CheckConversions((uint64_t)6231, &result);
// CheckConversions((uint64_t)1234639, &result);
CheckPrecision(TimeStepPrecision::MS, 3, &ok);
CheckPrecision(TimeStepPrecision::MS, 3, &result);
CheckConversions((uint64_t)3, &ok);
CheckConversions((uint64_t)134, &ok);
CheckConversions((uint64_t)2341, &ok);
// CheckConversions((uint64_t)8956239, &ok);
CheckConversions((uint64_t)3, &result);
CheckConversions((uint64_t)134, &result);
CheckConversions((uint64_t)2341, &result);
// CheckConversions((uint64_t)8956239, &result);
CheckPrecision(TimeStepPrecision::PS, 21, &ok);
CheckPrecision(TimeStepPrecision::PS, 21, &result);
CheckConversions((uint64_t)4, &ok);
CheckConversions((uint64_t)342, &ok);
CheckConversions((uint64_t)1327, &ok);
// CheckConversions((uint64_t)5439627, &ok);
CheckConversions((uint64_t)4, &result);
CheckConversions((uint64_t)342, &result);
CheckConversions((uint64_t)1327, &result);
// CheckConversions((uint64_t)5439627, &result);
CheckPrecision(TimeStepPrecision::NS, 12, &ok);
CheckConversions((uint64_t)12, &ok);
CheckPrecision(TimeStepPrecision::NS, 12, &result);
CheckConversions((uint64_t)12, &result);
CheckPrecision(TimeStepPrecision::S, 7, &ok);
CheckConversions((uint64_t)7, &ok);
CheckPrecision(TimeStepPrecision::S, 7, &result);
CheckConversions((uint64_t)7, &result);
CheckPrecision(TimeStepPrecision::FS, 5, &ok);
CheckConversions((uint64_t)5, &ok);
CheckPrecision(TimeStepPrecision::FS, 5, &result);
CheckConversions((uint64_t)5, &result);
TimeStepPrecision::Set (TimeStepPrecision::NS);
@@ -426,7 +426,17 @@ bool TimeTests::RunTests (void)
DefaultValue::Bind ("TimeStepPrecision", "PS");
DefaultValue::Bind ("TimeStepPrecision", "FS");
return ok;
Time tooBig = TimeStep (0x8000000000000000LL);
NS_TEST_ASSERT (tooBig.IsNegative ());
tooBig = TimeStep (0xffffffffffffffffLL);
NS_TEST_ASSERT (tooBig.IsNegative ());
tooBig = TimeStep (0x7fffffffffffffffLL);
NS_TEST_ASSERT (tooBig.IsPositive ());
tooBig += TimeStep (1);
NS_TEST_ASSERT (tooBig.IsNegative ());
return result;
}
void TimeTests::CheckOld (bool *ok)