merge with HEAD

This commit is contained in:
Mathieu Lacage
2008-05-16 10:29:34 -07:00
29 changed files with 63 additions and 220 deletions

View File

@@ -268,7 +268,6 @@ main (int argc, char *argv[])
{
subnetAlloc->Add (Vector (0.0, j, 0.0));
}
mobility.EnableNotifier ();
mobility.PushReferenceMobilityModel (backbone.Get (i));
mobility.SetPositionAllocator (subnetAlloc);
mobility.SetMobilityModel ("ns3::RandomDirection2dMobilityModel",
@@ -344,7 +343,7 @@ main (int argc, char *argv[])
CsmaHelper::EnablePcap ("mixed-wireless", appSink->GetId (), 0);
#ifdef ENABLE_FOR_TRACING_EXAMPLE
Config::Connect ("/NodeList/*/$MobilityModelNotifier/CourseChange",
Config::Connect ("/NodeList/*/$MobilityModel/CourseChange",
MakeCallback (&CourseChangeCallback));
#endif

View File

@@ -25,7 +25,6 @@ int main (int argc, char *argv[])
c.Create (10000);
MobilityHelper mobility;
mobility.EnableNotifier ();
mobility.SetPositionAllocator ("ns3::RandomDiscPositionAllocator",
"X", StringValue ("100.0"),
"Y", StringValue ("100.0"),

View File

@@ -8,7 +8,7 @@
using namespace ns3;
static void
CourseChange (ns3::TraceContext const&, Ptr<const MobilityModel> mobility)
CourseChange (std::string foo, Ptr<const MobilityModel> mobility)
{
Vector pos = mobility->GetPosition ();
Vector vel = mobility->GetVelocity ();
@@ -22,7 +22,7 @@ int main (int argc, char *argv[])
Config::SetDefault ("ns3::RandomWalk2dMobilityModel::Mode", StringValue ("Time"));
Config::SetDefault ("ns3::RandomWalk2dMobilityModel::Time", StringValue ("2s"));
Config::SetDefault ("ns3::RandomWalk2dMobilityModel::Speed", StringValue ("Constant:1.0"));
Config::SetDefault ("ns3::RandomWalk2dMobilityModel::Bounds", StringValue ("0:200:0:100"));
Config::SetDefault ("ns3::RandomWalk2dMobilityModel::Bounds", StringValue ("0|200|0|200"));
CommandLine cmd;
cmd.Parse (argc, argv);
@@ -31,7 +31,6 @@ int main (int argc, char *argv[])
c.Create (100);
MobilityHelper mobility;
mobility.EnableNotifier ();
mobility.SetPositionAllocator ("ns3::RandomDiscPositionAllocator",
"X", StringValue ("100.0"),
"Y", StringValue ("100.0"),
@@ -40,9 +39,9 @@ int main (int argc, char *argv[])
"Mode", StringValue ("Time"),
"Time", StringValue ("2s"),
"Speed", StringValue ("Constant:1.0"),
"Bounds", StringValue ("0:200:0:100"));
"Bounds", StringValue ("0|200|0|200"));
mobility.InstallAll ();
Config::Connect ("/NodeList/*/$ns3::MobilityModelNotifier/CourseChange",
Config::Connect ("/NodeList/*/$ns3::MobilityModel/CourseChange",
MakeCallback (&CourseChange));
Simulator::StopAt (Seconds (100.0));

View File

@@ -93,7 +93,7 @@ UdpEchoClient::StartApplication (void)
{
NS_LOG_FUNCTION_NOARGS ();
if (!m_socket)
if (m_socket == 0)
{
TypeId tid = TypeId::LookupByName ("ns3::Udp");
Ptr<SocketFactory> socketFactory =
@@ -113,10 +113,10 @@ UdpEchoClient::StopApplication ()
{
NS_LOG_FUNCTION_NOARGS ();
if (!m_socket)
if (m_socket != 0)
{
m_socket->SetRecvCallback(MakeNullCallback<void, Ptr<Socket>, Ptr<Packet>,
const Address &> ());
m_socket->SetRecvCallback(MakeNullCallback<void, Ptr<Socket>,
Ptr<Packet>, const Address &> ());
}
Simulator::Cancel(m_sendEvent);

View File

@@ -69,13 +69,14 @@ UdpEchoServer::StartApplication (void)
{
NS_LOG_FUNCTION_NOARGS ();
if (!m_socket)
if (m_socket == 0)
{
TypeId tid = TypeId::LookupByName ("ns3::Udp");
Ptr<SocketFactory> socketFactory =
GetNode ()->GetObject<SocketFactory> (tid);
m_socket = socketFactory->CreateSocket ();
InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), m_port);
InetSocketAddress local =
InetSocketAddress (Ipv4Address::GetAny (), m_port);
m_socket->Bind (local);
}
@@ -87,7 +88,7 @@ UdpEchoServer::StopApplication ()
{
NS_LOG_FUNCTION_NOARGS ();
if (!m_socket)
if (m_socket != 0)
{
m_socket->SetRecvCallback(MakeNullCallback<void, Ptr<Socket>,
Ptr<Packet>, const Address &> ());

View File

@@ -420,7 +420,6 @@ private:
* fire.
*
* @see class CallBackTraceSource
* @see class TraceResolver
*/
TracedCallback<Ptr<const Packet> > m_rxTrace;
TracedCallback<Ptr<const Packet> > m_dropTrace;

View File

@@ -267,7 +267,6 @@ private:
* fire.
*
* @see class CallBackTraceSource
* @see class TraceResolver
*/
TracedCallback<Ptr<const Packet> > m_rxTrace;
/**
@@ -275,7 +274,6 @@ private:
* fire.
*
* @see class CallBackTraceSource
* @see class TraceResolver
*/
TracedCallback<Ptr<const Packet> > m_dropTrace;

View File

@@ -19,7 +19,6 @@
*/
#include "ns3/mobility-helper.h"
#include "ns3/mobility-model.h"
#include "ns3/mobility-model-notifier.h"
#include "ns3/position-allocator.h"
#include "ns3/hierarchical-mobility-model.h"
#include "ns3/log.h"
@@ -30,7 +29,6 @@ namespace ns3 {
NS_LOG_COMPONENT_DEFINE ("MobilityHelper");
MobilityHelper::MobilityHelper ()
: m_notifierEnabled (false)
{
m_position = CreateObject<RandomRectanglePositionAllocator>
("X", RandomVariableValue (ConstantVariable (0.0)),
@@ -40,16 +38,6 @@ MobilityHelper::MobilityHelper ()
MobilityHelper::~MobilityHelper ()
{}
void
MobilityHelper::EnableNotifier (void)
{
m_notifierEnabled = true;
}
void
MobilityHelper::DisableNotifier (void)
{
m_notifierEnabled = false;
}
void
MobilityHelper::SetPositionAllocator (Ptr<PositionAllocator> allocator)
{
m_position = allocator;
@@ -156,15 +144,6 @@ MobilityHelper::Install (NodeContainer c)
}
Vector position = m_position->GetNext ();
model->SetPosition (position);
if (m_notifierEnabled)
{
Ptr<MobilityModelNotifier> notifier =
object->GetObject<MobilityModelNotifier> ();
if (notifier == 0)
{
object->AggregateObject (CreateObject<MobilityModelNotifier> ());
}
}
}
}

View File

@@ -42,20 +42,6 @@ public:
MobilityHelper ();
~MobilityHelper ();
/**
* After this method is called, every call to MobilityHelper::Install
* will also attach to the new ns3::MobilityModel an ns3::MobilityModelNotifier
* which can be used to listen to CourseChange events.
*/
void EnableNotifier (void);
/**
* After this method is called, no ns3::MobilityModelNotifier object will
* be associated to any new ns3::MobilityModel created by MobilityHelper::Install.
* This will make it impossible to listen to "CourseChange" events from these
* new ns3::MobilityModel instances.
*/
void DisableNotifier (void);
/**
* \param allocator allocate initial node positions
*
@@ -169,9 +155,6 @@ public:
* subclass (the type of which was set with MobilityHelper::SetMobilityModel),
* aggregates it to the mode, and sets an initial position based on the current
* position allocator (set through MobilityHelper::SetPositionAllocator).
* Optionally, this method will also create and aggregate a
* ns3::MobilityModelNotifier to generate 'CourseChange' events based on the
* boolean flag set by MobilityHelper::EnableNotifierAll and MobilityHelper::DisableNotifier.
*/
void Install (NodeContainer container);
@@ -183,7 +166,6 @@ public:
private:
std::vector<Ptr<MobilityModel> > m_mobilityStack;
bool m_notifierEnabled;
ObjectFactory m_mobility;
Ptr<PositionAllocator> m_position;
};

View File

@@ -24,7 +24,6 @@
#include "ns3/node-list.h"
#include "ns3/node.h"
#include "ns3/static-speed-mobility-model.h"
#include "ns3/mobility-model-notifier.h"
#include "ns2-mobility-helper.h"
NS_LOG_COMPONENT_DEFINE ("Ns2MobilityHelper");
@@ -36,17 +35,6 @@ Ns2MobilityHelper::Ns2MobilityHelper (std::string filename)
: m_filename (filename)
{}
void
Ns2MobilityHelper::EnableNotifier (void)
{
m_notifierEnabled = true;
}
void
Ns2MobilityHelper::DisableNotifier (void)
{
m_notifierEnabled = false;
}
Ptr<StaticSpeedMobilityModel>
@@ -67,12 +55,6 @@ Ns2MobilityHelper::GetMobilityModel (std::string idString, const ObjectStore &st
model = CreateObject<StaticSpeedMobilityModel> ();
object->AggregateObject (model);
}
Ptr<MobilityModelNotifier> notifier = object->GetObject<MobilityModelNotifier> ();
if (notifier == 0)
{
notifier = CreateObject<MobilityModelNotifier> ();
object->AggregateObject (notifier);
}
return model;
}

View File

@@ -42,9 +42,6 @@ public:
*/
Ns2MobilityHelper (std::string filename);
void EnableNotifier (void);
void DisableNotifier (void);
/**
* Read the ns2 trace file and configure the movement
* patterns of all nodes contained in the global ns3::NodeList
@@ -77,7 +74,6 @@ private:
Ptr<StaticSpeedMobilityModel> GetMobilityModel (std::string idString, const ObjectStore &store) const;
double ReadDouble (std::string valueString) const;
std::string m_filename;
bool m_notifierEnabled;
};
} // namespace ns3

View File

@@ -31,7 +31,7 @@ class ArpCache;
class NetDevice;
class Node;
class Packet;
class TraceContext;
/**
* \brief An implementation of the ARP protocol
*/

View File

@@ -31,7 +31,6 @@ namespace ns3 {
class NetDevice;
class Packet;
class TraceContext;
/**
* \brief The IPv4 representation of a network interface

View File

@@ -32,7 +32,6 @@ namespace ns3 {
class Ipv4L4Protocol;
class Node;
class TraceContext;
/**
* \brief L4 Ipv4 Demux

View File

@@ -31,8 +31,6 @@ namespace ns3 {
class Packet;
class Ipv4Address;
class TraceResolver;
class TraceContext;
/**
* \brief L4 Protocol base class

View File

@@ -37,7 +37,6 @@
namespace ns3 {
class Node;
class TraceContext;
class Socket;
class TcpHeader;
/**

View File

@@ -32,7 +32,6 @@
namespace ns3 {
class Node;
class TraceContext;
class Socket;
/**
* \brief Implementation of the UDP protocol

View File

@@ -18,7 +18,6 @@
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#include "hierarchical-mobility-model.h"
#include "mobility-model-notifier.h"
#include "ns3/pointer.h"
namespace ns3 {
@@ -52,28 +51,14 @@ void
HierarchicalMobilityModel::SetChild (Ptr<MobilityModel> model)
{
m_child = model;
Ptr<MobilityModelNotifier> notifier =
m_child->GetObject<MobilityModelNotifier> ();
if (notifier == 0)
{
notifier = CreateObject<MobilityModelNotifier> ();
m_child->AggregateObject (notifier);
}
notifier->TraceConnectWithoutContext ("CourseChange", MakeCallback (&HierarchicalMobilityModel::ChildChanged, this));
m_child->TraceConnectWithoutContext ("CourseChange", MakeCallback (&HierarchicalMobilityModel::ChildChanged, this));
}
void
HierarchicalMobilityModel::SetParent (Ptr<MobilityModel> model)
{
m_parent = model;
Ptr<MobilityModelNotifier> notifier =
m_parent->GetObject<MobilityModelNotifier> ();
if (notifier == 0)
{
notifier = CreateObject<MobilityModelNotifier> ();
m_parent->AggregateObject (notifier);
}
notifier->TraceConnectWithoutContext ("CourseChange", MakeCallback (&HierarchicalMobilityModel::ParentChanged, this));
m_parent->TraceConnectWithoutContext ("CourseChange", MakeCallback (&HierarchicalMobilityModel::ParentChanged, this));
}

View File

@@ -1,47 +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 "mobility-model-notifier.h"
#include "ns3/trace-source-accessor.h"
namespace ns3 {
TypeId
MobilityModelNotifier::GetTypeId (void)
{
static TypeId tid = TypeId ("MobilityModelNotifier")
.SetParent<Object> ()
.AddConstructor<MobilityModelNotifier> ()
.AddTraceSource ("CourseChange",
"The value of the position and/or velocity vector changed",
MakeTraceSourceAccessor (&MobilityModelNotifier::m_trace))
;
return tid;
}
MobilityModelNotifier::MobilityModelNotifier ()
{}
void
MobilityModelNotifier::Notify (Ptr<const MobilityModel> position) const
{
m_trace (position);
}
} // namespace ns3

View File

@@ -1,53 +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 MOBILITY_MODEL_NOTIFIER_H
#define MOBILITY_MODEL_NOTIFIER_H
#include "ns3/object.h"
#include "ns3/callback.h"
#include "ns3/traced-callback.h"
#include "mobility-model.h"
namespace ns3 {
/**
* \brief notify listeners of position changes.
*/
class MobilityModelNotifier : public Object
{
public:
static TypeId GetTypeId (void);
/**
* Create a new position notifier
*/
MobilityModelNotifier ();
/**
* \param position the position which just changed.
*/
void Notify (Ptr<const MobilityModel> position) const;
private:
TracedCallback<Ptr<const MobilityModel> > m_trace;
};
} // namespace ns3
#endif /* MOBILITY_MODEL_NOTIFIER_H */

View File

@@ -17,10 +17,12 @@
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#include "mobility-model.h"
#include "mobility-model-notifier.h"
#include <math.h>
#include "mobility-model.h"
#include "ns3/trace-source-accessor.h"
namespace ns3 {
TypeId
@@ -39,6 +41,9 @@ MobilityModel::GetTypeId (void)
VectorValue (Vector (0.0, 0.0, 0.0)), // ignored initial value.
MakeVectorAccessor (&MobilityModel::GetVelocity),
MakeVectorChecker ())
.AddTraceSource ("CourseChange",
"The value of the position and/or velocity vector changed",
MakeTraceSourceAccessor (&MobilityModel::m_courseChangeTrace))
;
return tid;
}
@@ -77,11 +82,7 @@ MobilityModel::GetDistanceFrom (Ptr<const MobilityModel> other) const
void
MobilityModel::NotifyCourseChange (void) const
{
Ptr<MobilityModelNotifier> notifier = GetObject<MobilityModelNotifier> ();
if (notifier != 0)
{
notifier->Notify (this);
}
m_courseChangeTrace(this);
}
} // namespace ns3

View File

@@ -20,9 +20,11 @@
#ifndef MOBILITY_MODEL_H
#define MOBILITY_MODEL_H
#include "ns3/object.h"
#include "vector.h"
#include "ns3/object.h"
#include "ns3/traced-callback.h"
namespace ns3 {
/**
@@ -84,6 +86,13 @@ private:
* implement this method.
*/
virtual Vector DoGetVelocity (void) const = 0;
/**
* Used to alert subscribers that a change in direction, velocity,
* or position has occurred.
*/
TracedCallback<Ptr<const MobilityModel> > m_courseChangeTrace;
};
}; // namespace ns3

View File

@@ -5,8 +5,8 @@
* - a set of mobility models which are used to track and maintain
* the "current" cartesian position and speed of an object.
*
* - a "course change notifier" which can be used to register listeners
* to the course changes of a mobility model: ns3::MobilityModelNotifier.
* - a "course change notifier" trace which can be used to register
* listeners to the course changes of a mobility model
*
* The mobility models themselves are:
* - ns3::StaticMobilityModel: a model which maintains a constant position

View File

@@ -6,7 +6,6 @@ def build(bld):
'vector.cc',
'hierarchical-mobility-model.cc',
'mobility-model.cc',
'mobility-model-notifier.cc',
'position-allocator.cc',
'rectangle.cc',
'static-mobility-model.cc',
@@ -23,7 +22,6 @@ def build(bld):
'vector.h',
'hierarchical-mobility-model.h',
'mobility-model.h',
'mobility-model-notifier.h',
'position-allocator.h',
'rectangle.h',
'static-mobility-model.h',

View File

@@ -32,7 +32,6 @@
namespace ns3 {
class Node;
class TraceContext;
class Channel;
class Packet;

View File

@@ -186,6 +186,11 @@ Node::ReceiveFromDevice (Ptr<NetDevice> device, Ptr<Packet> packet,
uint16_t protocol, const Address &from)
{
bool found = false;
// if there are (potentially) multiple handlers, we need to copy the
// packet before passing it to each handler, because handlers may
// modify it.
bool copyNeeded = (m_handlers.size () > 1);
for (ProtocolHandlerList::iterator i = m_handlers.begin ();
i != m_handlers.end (); i++)
{
@@ -195,7 +200,7 @@ Node::ReceiveFromDevice (Ptr<NetDevice> device, Ptr<Packet> packet,
if (i->protocol == 0 ||
i->protocol == protocol)
{
i->handler (device, packet, protocol, from);
i->handler (device, (copyNeeded ? packet->Copy () : packet), protocol, from);
found = true;
}
}

View File

@@ -29,7 +29,6 @@
namespace ns3 {
class TraceContext;
class NetDevice;
class Application;
class Packet;

View File

@@ -111,11 +111,11 @@ PacketSocket::DoBind (const PacketSocketAddress &address)
Ptr<NetDevice> dev ;
if (address.IsSingleDevice ())
{
dev = 0;
dev = m_node->GetDevice (address.GetSingleDevice ());
}
else
{
dev = m_node->GetDevice (address.GetSingleDevice ());
dev = 0;
}
m_node->RegisterProtocolHandler (MakeCallback (&PacketSocket::ForwardUp, this),
address.GetProtocol (), dev);

View File

@@ -533,6 +533,21 @@ GlobalRouter::DiscoverLSAs (void)
{
Ptr<NetDevice> ndLocal = node->GetDevice(i);
// Check if it is an IP interface (could be a pure L2 NetDevice)
bool isIp = false;
for (uint32_t i = 0; i < ipv4Local->GetNInterfaces (); ++i )
{
if (ipv4Local->GetNetDevice (i) == ndLocal)
{
isIp = true;
break;
}
}
if (!isIp)
{
continue;
}
if (ndLocal->IsBroadcast () && !ndLocal->IsPointToPoint () )
{
NS_LOG_LOGIC ("Broadcast link");
@@ -623,6 +638,10 @@ GlobalRouter::DiscoverLSAs (void)
// router (to use OSPF lingo) is running.
//
Ptr<Channel> ch = ndLocal->GetChannel();
if (ch == NULL)
{
continue;
}
Ptr<NetDevice> ndRemote = GetAdjacent(ndLocal, ch);
//
// The adjacent net device is aggregated to a node. We need to ask that net