--- a/bindings/python/ns3_module_mobility.py Fri Oct 24 15:50:52 2008 -0700
+++ b/bindings/python/ns3_module_mobility.py Fri Oct 24 15:51:20 2008 -0700
@@ -150,21 +150,12 @@
cls.add_constructor([])
## static-speed-helper.h: ns3::StaticSpeedHelper::StaticSpeedHelper(ns3::Vector const & position) [constructor]
cls.add_constructor([param('ns3::Vector const &', 'position')])
- ## static-speed-helper.h: ns3::StaticSpeedHelper::StaticSpeedHelper(ns3::Vector const & position, ns3::Vector const & speed) [constructor]
- cls.add_constructor([param('ns3::Vector const &', 'position'), param('ns3::Vector const &', 'speed')])
- ## static-speed-helper.h: void ns3::StaticSpeedHelper::InitializePosition(ns3::Vector const & position) [member function]
- cls.add_method('InitializePosition',
+ ## static-speed-helper.h: ns3::StaticSpeedHelper::StaticSpeedHelper(ns3::Vector const & position, ns3::Vector const & vel) [constructor]
+ cls.add_constructor([param('ns3::Vector const &', 'position'), param('ns3::Vector const &', 'vel')])
+ ## static-speed-helper.h: void ns3::StaticSpeedHelper::SetPosition(ns3::Vector const & position) [member function]
+ cls.add_method('SetPosition',
'void',
[param('ns3::Vector const &', 'position')])
- ## static-speed-helper.h: void ns3::StaticSpeedHelper::Reset(ns3::Vector const & speed) [member function]
- cls.add_method('Reset',
- 'void',
- [param('ns3::Vector const &', 'speed')])
- ## static-speed-helper.h: ns3::Vector ns3::StaticSpeedHelper::GetCurrentPosition(ns3::Rectangle const & bounds) const [member function]
- cls.add_method('GetCurrentPosition',
- 'ns3::Vector',
- [param('ns3::Rectangle const &', 'bounds')],
- is_const=True)
## static-speed-helper.h: ns3::Vector ns3::StaticSpeedHelper::GetCurrentPosition() const [member function]
cls.add_method('GetCurrentPosition',
'ns3::Vector',
@@ -175,10 +166,10 @@
'ns3::Vector',
[],
is_const=True)
- ## static-speed-helper.h: void ns3::StaticSpeedHelper::SetSpeed(ns3::Vector const & speed) [member function]
- cls.add_method('SetSpeed',
+ ## static-speed-helper.h: void ns3::StaticSpeedHelper::SetVelocity(ns3::Vector const & vel) [member function]
+ cls.add_method('SetVelocity',
'void',
- [param('ns3::Vector const &', 'speed')])
+ [param('ns3::Vector const &', 'vel')])
## static-speed-helper.h: void ns3::StaticSpeedHelper::Pause() [member function]
cls.add_method('Pause',
'void',
@@ -187,6 +178,16 @@
cls.add_method('Unpause',
'void',
[])
+ ## static-speed-helper.h: void ns3::StaticSpeedHelper::UpdateWithBounds(ns3::Rectangle const & rectangle) const [member function]
+ cls.add_method('UpdateWithBounds',
+ 'void',
+ [param('ns3::Rectangle const &', 'rectangle')],
+ is_const=True)
+ ## static-speed-helper.h: void ns3::StaticSpeedHelper::Update() const [member function]
+ cls.add_method('Update',
+ 'void',
+ [],
+ is_const=True)
return
def register_Ns3Vector_methods(root_module, cls):
@@ -631,8 +632,8 @@
is_static=True)
## static-speed-mobility-model.h: ns3::StaticSpeedMobilityModel::StaticSpeedMobilityModel() [constructor]
cls.add_constructor([])
- ## static-speed-mobility-model.h: void ns3::StaticSpeedMobilityModel::SetSpeed(ns3::Vector const & speed) [member function]
- cls.add_method('SetSpeed',
+ ## static-speed-mobility-model.h: void ns3::StaticSpeedMobilityModel::SetVelocity(ns3::Vector const & speed) [member function]
+ cls.add_method('SetVelocity',
'void',
[param('ns3::Vector const &', 'speed')])
## static-speed-mobility-model.h: ns3::Vector ns3::StaticSpeedMobilityModel::DoGetPosition() const [member function]
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/samples/main-ns2-mob.cc Fri Oct 24 15:51:20 2008 -0700
@@ -0,0 +1,37 @@
+#include "ns3/core-module.h"
+#include "ns3/mobility-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/helper-module.h"
+#include "ns3/mobility-module.h"
+#include <iostream>
+
+using namespace ns3;
+
+static void
+CourseChange (std::ostream *os, std::string foo, Ptr<const MobilityModel> mobility)
+{
+ Vector pos = mobility->GetPosition ();
+ Vector vel = mobility->GetVelocity ();
+ *os << Simulator::Now () << " POS: x=" << pos.x << ", y=" << pos.y
+ << ", z=" << pos.z << "; VEL:" << vel.x << ", y=" << vel.y
+ << ", z=" << vel.z << std::endl;
+}
+
+int main (int argc, char *argv[])
+{
+ Ns2MobilityHelper mobility(argv[1]);
+ std::ofstream os;
+ os.open (argv[2]);
+ NodeContainer stas;
+ stas.Create (1);
+
+ mobility.Install ();
+
+ Config::Connect ("/NodeList/*/$ns3::MobilityModel/CourseChange",
+ MakeBoundCallback (&CourseChange, &os));
+
+ Simulator::Stop (Seconds (10.0));
+ Simulator::Run ();
+ Simulator::Destroy ();
+ return 0;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/samples/ns2-mob.tr Fri Oct 24 15:51:20 2008 -0700
@@ -0,0 +1,7 @@
+
+$node_(0) set X_ 0.0
+$node_(0) set Y_ 25.0
+$node_(0) set Z_ 0.0
+$ns_ at 3.0 "$node_(0) setdest 25 0 0"
+$ns_ at 4.8 "$node_(0) setdest 0 0 0"
+$ns_ at 5.0 "$node_(0) setdest 25 0 0"
--- a/samples/wscript Fri Oct 24 15:50:52 2008 -0700
+++ b/samples/wscript Fri Oct 24 15:51:20 2008 -0700
@@ -39,4 +39,8 @@
['core', 'simulator', 'mobility', 'wifi'])
obj.source = 'main-propagation-loss.cc'
+ obj = bld.create_ns3_program('main-ns2-mob',
+ ['core', 'simulator', 'mobility', 'wifi'])
+ obj.source = 'main-ns2-mob.cc'
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/core/abort.h Fri Oct 24 15:51:20 2008 -0700
@@ -0,0 +1,54 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2008 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
+ *
+ */
+#ifndef NS3_ABORT_H
+#define NS3_ABORT_H
+
+#include "fatal-error.h"
+
+#define NS_ABORT_IF(cond) \
+ do { \
+ if (cond) \
+ { \
+ std::cerr << "file=" << __FILE__ << \
+ ", line=" << __LINE__ << ", abort on=\""#cond << \
+ "\"" << std::endl; \
+ int *a = 0; \
+ *a = 0; \
+ } \
+ } while (false)
+
+#define NS_ABORT_MSG_IF(cond, msg) \
+ do { \
+ if (cond) \
+ { \
+ std::cerr << "file=" << __FILE__ << \
+ ", line=" << __LINE__ << ", abort on=\""#cond << \
+ "\", msg=\"" << msg << "\"" << std::endl; \
+ int *a = 0; \
+ *a = 0; \
+ } \
+ } while (false)
+
+#define NS_ABORT_UNLESS(cond) \
+ NS_ABORT_IF(!(cond))
+
+#define NS_ABORT_MSG_UNLESS(cond, msg) \
+ NS_ABORT_MSG_IF(!(cond),msg)
+
+#endif /* NS3_ABORT_H */
--- a/src/core/config.cc Fri Oct 24 15:50:52 2008 -0700
+++ b/src/core/config.cc Fri Oct 24 15:51:20 2008 -0700
@@ -30,6 +30,100 @@
namespace ns3 {
+namespace Config {
+
+MatchContainer::MatchContainer ()
+{}
+MatchContainer::MatchContainer (const std::vector<Ptr<Object> > &objects,
+ const std::vector<std::string> &contexts,
+ std::string path)
+ : m_objects (objects),
+ m_contexts (contexts),
+ m_path (path)
+{}
+MatchContainer::Iterator
+MatchContainer::Begin (void) const
+{
+ return m_objects.begin ();
+}
+MatchContainer::Iterator
+MatchContainer::End (void) const
+{
+ return m_objects.end ();
+}
+uint32_t
+MatchContainer::GetN (void) const
+{
+ return m_objects.size ();
+}
+Ptr<Object>
+MatchContainer::Get (uint32_t i) const
+{
+ return m_objects[i];
+}
+std::string
+MatchContainer::GetMatchedPath (uint32_t i) const
+{
+ return m_contexts[i];
+}
+std::string
+MatchContainer::GetPath (void) const
+{
+ return m_path;
+}
+
+void
+MatchContainer::Set (std::string name, const AttributeValue &value)
+{
+ for (Iterator tmp = Begin (); tmp != End (); ++tmp)
+ {
+ Ptr<Object> object = *tmp;
+ object->SetAttribute (name, value);
+ }
+}
+void
+MatchContainer::Connect (std::string name, const CallbackBase &cb)
+{
+ NS_ASSERT (m_objects.size () == m_contexts.size ());
+ for (uint32_t i = 0; i < m_objects.size (); ++i)
+ {
+ Ptr<Object> object = m_objects[i];
+ std::string ctx = m_contexts[i] + name;
+ object->TraceConnect (name, ctx, cb);
+ }
+}
+void
+MatchContainer::ConnectWithoutContext (std::string name, const CallbackBase &cb)
+{
+ for (Iterator tmp = Begin (); tmp != End (); ++tmp)
+ {
+ Ptr<Object> object = *tmp;
+ object->TraceConnectWithoutContext (name, cb);
+ }
+}
+void
+MatchContainer::Disconnect (std::string name, const CallbackBase &cb)
+{
+ NS_ASSERT (m_objects.size () == m_contexts.size ());
+ for (uint32_t i = 0; i < m_objects.size (); ++i)
+ {
+ Ptr<Object> object = m_objects[i];
+ std::string ctx = m_contexts[i] + name;
+ object->TraceDisconnect (name, ctx, cb);
+ }
+}
+void
+MatchContainer::DisconnectWithoutContext (std::string name, const CallbackBase &cb)
+{
+ for (Iterator tmp = Begin (); tmp != End (); ++tmp)
+ {
+ Ptr<Object> object = *tmp;
+ object->TraceDisconnectWithoutContext (name, cb);
+ }
+}
+
+} // namespace Config
+
class ArrayMatcher
{
public:
@@ -125,20 +219,40 @@
void Resolve (Ptr<Object> root);
private:
+ void Canonicalize (void);
void DoResolve (std::string path, Ptr<Object> root);
void DoArrayResolve (std::string path, const ObjectVectorValue &vector);
- void DoResolveOne (Ptr<Object> object, std::string name);
- std::string GetResolvedPath (std::string name) const;
- virtual void DoOne (Ptr<Object> object, std::string path, std::string name) = 0;
+ void DoResolveOne (Ptr<Object> object);
+ std::string GetResolvedPath (void) const;
+ virtual void DoOne (Ptr<Object> object, std::string path) = 0;
std::vector<std::string> m_workStack;
std::string m_path;
};
Resolver::Resolver (std::string path)
: m_path (path)
-{}
+{
+ Canonicalize ();
+}
Resolver::~Resolver ()
{}
+void
+Resolver::Canonicalize (void)
+{
+ // ensure that we start and end with a '/'
+ std::string::size_type tmp = m_path.find ("/");
+ if (tmp != 0)
+ {
+ // no slash at start
+ m_path = "/" + m_path;
+ }
+ tmp = m_path.find_last_of ("/");
+ if (tmp != (m_path.size () - 1))
+ {
+ // no slash at end
+ m_path = m_path + "/";
+ }
+}
void
Resolver::Resolve (Ptr<Object> root)
@@ -147,40 +261,34 @@
}
std::string
-Resolver::GetResolvedPath (std::string name) const
+Resolver::GetResolvedPath (void) const
{
- std::string fullPath = "";
+ std::string fullPath = "/";
for (std::vector<std::string>::const_iterator i = m_workStack.begin (); i != m_workStack.end (); i++)
{
- fullPath += "/" + *i;
+ fullPath += *i + "/";
}
- fullPath += "/" + name;
return fullPath;
}
void
-Resolver::DoResolveOne (Ptr<Object> object, std::string name)
+Resolver::DoResolveOne (Ptr<Object> object)
{
- NS_LOG_DEBUG ("resolved="<<GetResolvedPath (name));
- DoOne (object, GetResolvedPath (name), name);
+ NS_LOG_DEBUG ("resolved="<<GetResolvedPath ());
+ DoOne (object, GetResolvedPath ());
}
void
Resolver::DoResolve (std::string path, Ptr<Object> root)
{
- NS_ASSERT (path != "");
- std::string::size_type pos = path.find ("/");
- if (pos != 0)
- {
- NS_FATAL_ERROR ("path does not start with a \"/\": \""<<path<<"\"");
- return;
- }
+ NS_LOG_FUNCTION (path << root);
+ std::string::size_type tmp;
+ tmp = path.find ("/");
+ NS_ASSERT (tmp == 0);
std::string::size_type next = path.find ("/", 1);
if (next == std::string::npos)
{
- std::string attributeName = path.substr (1, path.size ()-1);
- NS_LOG_DEBUG ("handle attr="<<attributeName);
- DoOne (root, GetResolvedPath (attributeName), attributeName);
+ DoResolveOne (root);
return;
}
std::string item = path.substr (1, next-1);
@@ -191,12 +299,12 @@
{
// This is a call to GetObject
std::string tidString = item.substr (1, item.size () - 1);
- NS_LOG_DEBUG ("GetObject="<<tidString<<" on path="<<GetResolvedPath (""));
+ NS_LOG_DEBUG ("GetObject="<<tidString<<" on path="<<GetResolvedPath ());
TypeId tid = TypeId::LookupByName (tidString);
Ptr<Object> object = root->GetObject<Object> (tid);
if (object == 0)
{
- NS_LOG_DEBUG ("GetObject ("<<tidString<<") failed on path="<<GetResolvedPath (""));
+ NS_LOG_DEBUG ("GetObject ("<<tidString<<") failed on path="<<GetResolvedPath ());
return;
}
m_workStack.push_back (item);
@@ -210,21 +318,21 @@
struct TypeId::AttributeInfo info;
if (!tid.LookupAttributeByName (item, &info))
{
- NS_LOG_DEBUG ("Requested item="<<item<<" does not exist on path="<<GetResolvedPath (""));
+ NS_LOG_DEBUG ("Requested item="<<item<<" does not exist on path="<<GetResolvedPath ());
return;
}
// attempt to cast to a pointer checker.
const PointerChecker *ptr = dynamic_cast<const PointerChecker *> (PeekPointer (info.checker));
if (ptr != 0)
{
- NS_LOG_DEBUG ("GetAttribute(ptr)="<<item<<" on path="<<GetResolvedPath (""));
+ NS_LOG_DEBUG ("GetAttribute(ptr)="<<item<<" on path="<<GetResolvedPath ());
PointerValue ptr;
root->GetAttribute (item, ptr);
Ptr<Object> object = ptr.Get<Object> ();
if (object == 0)
{
NS_LOG_ERROR ("Requested object name=\""<<item<<
- "\" exists on path=\""<<GetResolvedPath ("")<<"\""
+ "\" exists on path=\""<<GetResolvedPath ()<<"\""
" but is null.");
return;
}
@@ -236,7 +344,7 @@
const ObjectVectorChecker *vectorChecker = dynamic_cast<const ObjectVectorChecker *> (PeekPointer (info.checker));
if (vectorChecker != 0)
{
- NS_LOG_DEBUG ("GetAttribute(vector)="<<item<<" on path="<<GetResolvedPath (""));
+ NS_LOG_DEBUG ("GetAttribute(vector)="<<item<<" on path="<<GetResolvedPath ());
ObjectVectorValue vector;
root->GetAttribute (item, vector);
m_workStack.push_back (item);
@@ -252,17 +360,13 @@
Resolver::DoArrayResolve (std::string path, const ObjectVectorValue &vector)
{
NS_ASSERT (path != "");
- std::string::size_type pos = path.find ("/");
- if (pos != 0)
- {
- NS_FATAL_ERROR ("path does not start with a \"/\": \""<<path<<"\"");
- return;
- }
+ std::string::size_type tmp;
+ tmp = path.find ("/");
+ NS_ASSERT (tmp == 0);
std::string::size_type next = path.find ("/", 1);
if (next == std::string::npos)
{
- NS_LOG_DEBUG ("vector path includes no index data on path=\""<<path<<"\"");
- return;
+ NS_FATAL_ERROR ("vector path includes no index data on path=\""<<path<<"\"");
}
std::string item = path.substr (1, next-1);
std::string pathLeft = path.substr (next, path.size ()-next);
@@ -290,6 +394,7 @@
void Connect (std::string path, const CallbackBase &cb);
void DisconnectWithoutContext (std::string path, const CallbackBase &cb);
void Disconnect (std::string path, const CallbackBase &cb);
+ Config::MatchContainer LookupMatches (std::string path);
void RegisterRootNamespaceObject (Ptr<Object> obj);
void UnregisterRootNamespaceObject (Ptr<Object> obj);
@@ -298,110 +403,86 @@
Ptr<Object> GetRootNamespaceObject (uint32_t i) const;
private:
+ void ParsePath (std::string path, std::string *root, std::string *leaf) const;
typedef std::vector<Ptr<Object> > Roots;
Roots m_roots;
};
void
+ConfigImpl::ParsePath (std::string path, std::string *root, std::string *leaf) const
+{
+ std::string::size_type slash = path.find_last_of ("/");
+ NS_ASSERT (slash != std::string::npos);
+ *root = path.substr (0, slash);
+ *leaf = path.substr (slash+1, path.size ()-(slash+1));
+ NS_LOG_FUNCTION (path << *root << *leaf);
+}
+
+void
ConfigImpl::Set (std::string path, const AttributeValue &value)
{
- class SetResolver : public Resolver
- {
- public:
- SetResolver (std::string path, const AttributeValue &value)
- : Resolver (path),
- m_value (value.Copy ()) {}
- private:
- virtual void DoOne (Ptr<Object> object, std::string path, std::string name) {
- object->SetAttribute (name, *m_value);
- }
- Ptr<const AttributeValue> m_value;
- } resolver = SetResolver (path, value);
- for (Roots::const_iterator i = m_roots.begin (); i != m_roots.end (); i++)
- {
- resolver.Resolve (*i);
- }
+ std::string root, leaf;
+ ParsePath (path, &root, &leaf);
+ Config::MatchContainer container = LookupMatches (root);
+ container.Set (leaf, value);
}
void
ConfigImpl::ConnectWithoutContext (std::string path, const CallbackBase &cb)
{
- class ConnectResolver : public Resolver
- {
- public:
- ConnectResolver (std::string path, const CallbackBase &cb)
- : Resolver (path),
- m_cb (cb) {}
- private:
- virtual void DoOne (Ptr<Object> object, std::string path, std::string name) {
- object->TraceConnectWithoutContext (name, m_cb);
- }
- CallbackBase m_cb;
- } resolver = ConnectResolver (path, cb);
- for (Roots::const_iterator i = m_roots.begin (); i != m_roots.end (); i++)
- {
- resolver.Resolve (*i);
- }
+ std::string root, leaf;
+ ParsePath (path, &root, &leaf);
+ Config::MatchContainer container = LookupMatches (root);
+ container.ConnectWithoutContext (leaf, cb);
}
void
ConfigImpl::DisconnectWithoutContext (std::string path, const CallbackBase &cb)
{
- class DisconnectResolver : public Resolver
- {
- public:
- DisconnectResolver (std::string path, const CallbackBase &cb)
- : Resolver (path),
- m_cb (cb) {}
- private:
- virtual void DoOne (Ptr<Object> object, std::string path, std::string name) {
- object->TraceDisconnectWithoutContext (name, m_cb);
- }
- CallbackBase m_cb;
- } resolver = DisconnectResolver (path, cb);
- for (Roots::const_iterator i = m_roots.begin (); i != m_roots.end (); i++)
- {
- resolver.Resolve (*i);
- }
+ std::string root, leaf;
+ ParsePath (path, &root, &leaf);
+ Config::MatchContainer container = LookupMatches (root);
+ container.DisconnectWithoutContext (leaf, cb);
}
void
ConfigImpl::Connect (std::string path, const CallbackBase &cb)
{
- class ConnectWithContextResolver : public Resolver
+ std::string root, leaf;
+ ParsePath (path, &root, &leaf);
+ Config::MatchContainer container = LookupMatches (root);
+ container.Connect (leaf, cb);
+}
+void
+ConfigImpl::Disconnect (std::string path, const CallbackBase &cb)
+{
+ std::string root, leaf;
+ ParsePath (path, &root, &leaf);
+ Config::MatchContainer container = LookupMatches (root);
+ container.Disconnect (leaf, cb);
+}
+
+Config::MatchContainer
+ConfigImpl::LookupMatches (std::string path)
+{
+ NS_LOG_FUNCTION (path);
+ class LookupMatchesResolver : public Resolver
{
public:
- ConnectWithContextResolver (std::string path, const CallbackBase &cb)
- : Resolver (path),
- m_cb (cb) {}
- private:
- virtual void DoOne (Ptr<Object> object, std::string path, std::string name) {
- object->TraceConnect (name, path, m_cb);
+ LookupMatchesResolver (std::string path)
+ : Resolver (path)
+ {}
+ virtual void DoOne (Ptr<Object> object, std::string path) {
+ m_objects.push_back (object);
+ m_contexts.push_back (path);
}
- CallbackBase m_cb;
- } resolver = ConnectWithContextResolver (path, cb);
+ std::vector<Ptr<Object> > m_objects;
+ std::vector<std::string> m_contexts;
+ } resolver = LookupMatchesResolver (path);
for (Roots::const_iterator i = m_roots.begin (); i != m_roots.end (); i++)
{
resolver.Resolve (*i);
}
+ return Config::MatchContainer (resolver.m_objects, resolver.m_contexts, path);
}
-void
-ConfigImpl::Disconnect (std::string path, const CallbackBase &cb)
-{
- class DisconnectWithContextResolver : public Resolver
- {
- public:
- DisconnectWithContextResolver (std::string path, const CallbackBase &cb)
- : Resolver (path),
- m_cb (cb) {}
- private:
- virtual void DoOne (Ptr<Object> object, std::string path, std::string name) {
- object->TraceDisconnect (name, path, m_cb);
- }
- CallbackBase m_cb;
- } resolver = DisconnectWithContextResolver (path, cb);
- for (Roots::const_iterator i = m_roots.begin (); i != m_roots.end (); i++)
- {
- resolver.Resolve (*i);
- }
-}
+
void
ConfigImpl::RegisterRootNamespaceObject (Ptr<Object> obj)
{
@@ -472,6 +553,10 @@
{
Singleton<ConfigImpl>::Get ()->Disconnect (path, cb);
}
+Config::MatchContainer LookupMatches (std::string path)
+{
+ return Singleton<ConfigImpl>::Get ()->LookupMatches (path);
+}
void RegisterRootNamespaceObject (Ptr<Object> obj)
{
--- a/src/core/config.h Fri Oct 24 15:50:52 2008 -0700
+++ b/src/core/config.h Fri Oct 24 15:51:20 2008 -0700
@@ -22,6 +22,7 @@
#include "ptr.h"
#include <string>
+#include <vector>
namespace ns3 {
@@ -110,6 +111,35 @@
*/
void Disconnect (std::string path, const CallbackBase &cb);
+class MatchContainer
+{
+public:
+ typedef std::vector<Ptr<Object> >::const_iterator Iterator;
+ MatchContainer ();
+ MatchContainer (const std::vector<Ptr<Object> > &objects,
+ const std::vector<std::string> &contexts,
+ std::string path);
+
+ MatchContainer::Iterator Begin (void) const;
+ MatchContainer::Iterator End (void) const;
+ uint32_t GetN (void) const;
+ Ptr<Object> Get (uint32_t i) const;
+ std::string GetMatchedPath (uint32_t i) const;
+ std::string GetPath (void) const;
+
+ void Set (std::string name, const AttributeValue &value);
+ void Connect (std::string name, const CallbackBase &cb);
+ void ConnectWithoutContext (std::string name, const CallbackBase &cb);
+ void Disconnect (std::string name, const CallbackBase &cb);
+ void DisconnectWithoutContext (std::string name, const CallbackBase &cb);
+private:
+ std::vector<Ptr<Object> > m_objects;
+ std::vector<std::string> m_contexts;
+ std::string m_path;
+};
+
+MatchContainer LookupMatches (std::string path);
+
/**
* \param obj a new root object
*
--- a/src/core/system-thread.h Fri Oct 24 15:50:52 2008 -0700
+++ b/src/core/system-thread.h Fri Oct 24 15:51:20 2008 -0700
@@ -84,6 +84,10 @@
* method provided to do this is Join (). If you call Join() you will block
* until the SystemThread run method returns.
*
+ * @warning The SystemThread uses SIGALRM to wake threads that are possibly
+ * blocked on IO.
+ * @see Shutdown
+ *
* @warning I've made the system thread class look like a normal ns3 object
* with smart pointers, and living in the heap. This makes it very easy to
* manage threads from a single master thread context. You should be very
@@ -128,9 +132,47 @@
*/
void Join (void);
+ /**
+ * @brief Indicates to a managed thread doing cooperative multithreading that
+ * its managing thread wants it to exit.
+ *
+ * It is often the case that we want a thread to be off doing work until such
+ * time as its job is done (typically when the simulation is done). We then
+ * want the thread to exit itself. This method provides a consistent way for
+ * the managing thread to communicate with the managed thread. After the
+ * manager thread calls this method, the Break() method will begin returning
+ * true, telling the managed thread to exit.
+ *
+ * This alone isn't really enough to merit these events, but in Unix, if a
+ * worker thread is doing blocking IO, it will need to be woken up from that
+ * read somehow. This method also provides that functionality, by sending a
+ * SIGALRM signal to the possibly blocked thread.
+ *
+ * @warning Uses SIGALRM to notifiy threads possibly blocked on IO. Beware
+ * if you are using signals.
+ * @see Break
+ */
+ void Shutdown (void);
+
+ /**
+ * @brief Indicates to a thread doing cooperative multithreading that
+ * its managing thread wants it to exit.
+ *
+ * It is often the case that we want a thread to be off doing work until such
+ * time as its job is done. We then want the thread to exit itself. This
+ * method allows a thread to query whether or not it should be running.
+ * Typically, the worker thread is running in a forever-loop, and will need to
+ * "break" out of that loop to exit -- thus the name.
+ *
+ * @see Shutdown
+ * @returns true if thread is expected to exit (break out of the forever-loop)
+ */
+ bool Break (void);
+
private:
SystemThreadImpl * m_impl;
mutable uint32_t m_count;
+ bool m_break;
};
void
--- a/src/core/unix-system-thread.cc Fri Oct 24 15:50:52 2008 -0700
+++ b/src/core/unix-system-thread.cc Fri Oct 24 15:51:20 2008 -0700
@@ -20,6 +20,7 @@
#include <pthread.h>
#include <string.h>
+#include <signal.h>
#include "fatal-error.h"
#include "system-thread.h"
#include "log.h"
@@ -49,11 +50,14 @@
void Start (void);
void Join (void);
+ void Shutdown (void);
+ bool Break (void);
private:
static void *DoRun (void *arg);
Callback<void> m_callback;
pthread_t m_thread;
+ bool m_break;
void * m_ret;
};
@@ -61,6 +65,13 @@
: m_callback (callback)
{
NS_LOG_FUNCTION_NOARGS ();
+ // Make sure we have a SIGALRM handler which does not terminate
+ // our process.
+ struct sigaction act;
+ act.sa_flags = 0;
+ sigemptyset (&act.sa_mask);
+ act.sa_handler = SIG_IGN;
+ sigaction (SIGALRM, &act, 0);
}
void
@@ -92,6 +103,26 @@
}
}
+ void
+SystemThreadImpl::Shutdown (void)
+{
+ NS_LOG_FUNCTION_NOARGS ();
+
+ m_break = true;
+
+ // send a SIGALRM signal on the target thread to make sure that it
+ // will unblock.
+ pthread_kill (m_thread, SIGALRM);
+}
+
+ bool
+SystemThreadImpl::Break (void)
+{
+ NS_LOG_FUNCTION_NOARGS ();
+
+ return m_break;
+}
+
void *
SystemThreadImpl::DoRun (void *arg)
{
@@ -136,4 +167,18 @@
m_impl->Join ();
}
+ void
+SystemThread::Shutdown (void)
+{
+ NS_LOG_FUNCTION_NOARGS ();
+ m_impl->Shutdown ();
+}
+
+ bool
+SystemThread::Break (void)
+{
+ NS_LOG_FUNCTION_NOARGS ();
+ return m_impl->Break ();
+}
+
} // namespace ns3
--- a/src/core/wscript Fri Oct 24 15:50:52 2008 -0700
+++ b/src/core/wscript Fri Oct 24 15:51:20 2008 -0700
@@ -116,7 +116,8 @@
'trace-source-accessor.h',
'config.h',
'object-vector.h',
- 'deprecated.h'
+ 'deprecated.h',
+ 'abort.h',
]
if sys.platform == 'win32':
--- a/src/helper/csma-helper.cc Fri Oct 24 15:50:52 2008 -0700
+++ b/src/helper/csma-helper.cc Fri Oct 24 15:51:20 2008 -0700
@@ -39,10 +39,10 @@
void
CsmaHelper::SetQueue (std::string type,
- std::string n1, const AttributeValue &v1,
- std::string n2, const AttributeValue &v2,
- std::string n3, const AttributeValue &v3,
- std::string n4, const AttributeValue &v4)
+ std::string n1, const AttributeValue &v1,
+ std::string n2, const AttributeValue &v2,
+ std::string n3, const AttributeValue &v3,
+ std::string n4, const AttributeValue &v4)
{
m_queueFactory.SetTypeId (type);
m_queueFactory.Set (n1, v1);
@@ -78,6 +78,13 @@
CsmaHelper::EnablePcap (std::string filename, uint32_t nodeid, uint32_t deviceid)
{
std::ostringstream oss;
+ oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/";
+ Config::MatchContainer matches = Config::LookupMatches (oss.str ());
+ if (matches.GetN () == 0)
+ {
+ return;
+ }
+ oss.str ("");
oss << filename << "-" << nodeid << "-" << deviceid << ".pcap";
Ptr<PcapWriter> pcap = Create<PcapWriter> ();
pcap->Open (oss.str ());
@@ -106,9 +113,9 @@
{
Ptr<Node> node = *i;
for (uint32_t j = 0; j < node->GetNDevices (); ++j)
- {
- devs.Add (node->GetDevice (j));
- }
+ {
+ devs.Add (node->GetDevice (j));
+ }
}
EnablePcap (filename, devs);
}
@@ -153,9 +160,9 @@
{
Ptr<Node> node = *i;
for (uint32_t j = 0; j < node->GetNDevices (); ++j)
- {
- devs.Add (node->GetDevice (j));
- }
+ {
+ devs.Add (node->GetDevice (j));
+ }
}
EnableAscii (os, devs);
}
--- a/src/helper/csma-helper.h Fri Oct 24 15:50:52 2008 -0700
+++ b/src/helper/csma-helper.h Fri Oct 24 15:51:20 2008 -0700
@@ -57,10 +57,10 @@
* CsmaNetDevice created through CsmaHelper::Install.
*/
void SetQueue (std::string type,
- std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (),
- std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (),
- std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (),
- std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue ());
+ std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (),
+ std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (),
+ std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (),
+ std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue ());
/**
* \param n1 the name of the attribute to set
--- a/src/helper/mobility-helper.cc Fri Oct 24 15:50:52 2008 -0700
+++ b/src/helper/mobility-helper.cc Fri Oct 24 15:51:20 2008 -0700
@@ -47,15 +47,15 @@
}
void
MobilityHelper::SetPositionAllocator (std::string type,
- std::string n1, const AttributeValue &v1,
- std::string n2, const AttributeValue &v2,
- std::string n3, const AttributeValue &v3,
- std::string n4, const AttributeValue &v4,
- std::string n5, const AttributeValue &v5,
- std::string n6, const AttributeValue &v6,
- std::string n7, const AttributeValue &v7,
- std::string n8, const AttributeValue &v8,
- std::string n9, const AttributeValue &v9)
+ std::string n1, const AttributeValue &v1,
+ std::string n2, const AttributeValue &v2,
+ std::string n3, const AttributeValue &v3,
+ std::string n4, const AttributeValue &v4,
+ std::string n5, const AttributeValue &v5,
+ std::string n6, const AttributeValue &v6,
+ std::string n7, const AttributeValue &v7,
+ std::string n8, const AttributeValue &v8,
+ std::string n9, const AttributeValue &v9)
{
ObjectFactory pos;
pos.SetTypeId (type);
@@ -73,15 +73,15 @@
void
MobilityHelper::SetMobilityModel (std::string type,
- std::string n1, const AttributeValue &v1,
- std::string n2, const AttributeValue &v2,
- std::string n3, const AttributeValue &v3,
- std::string n4, const AttributeValue &v4,
- std::string n5, const AttributeValue &v5,
- std::string n6, const AttributeValue &v6,
- std::string n7, const AttributeValue &v7,
- std::string n8, const AttributeValue &v8,
- std::string n9, const AttributeValue &v9)
+ std::string n1, const AttributeValue &v1,
+ std::string n2, const AttributeValue &v2,
+ std::string n3, const AttributeValue &v3,
+ std::string n4, const AttributeValue &v4,
+ std::string n5, const AttributeValue &v5,
+ std::string n6, const AttributeValue &v6,
+ std::string n7, const AttributeValue &v7,
+ std::string n8, const AttributeValue &v8,
+ std::string n9, const AttributeValue &v9)
{
m_mobility.SetTypeId (type);
m_mobility.Set (n1, v1);
@@ -122,29 +122,29 @@
Ptr<Object> object = *i;
Ptr<MobilityModel> model = object->GetObject<MobilityModel> ();
if (model == 0)
- {
- model = m_mobility.Create ()->GetObject<MobilityModel> ();
- if (model == 0)
- {
- NS_FATAL_ERROR ("The requested mobility model is not a mobility model: \""<<
- m_mobility.GetTypeId ().GetName ()<<"\"");
- }
- if (m_mobilityStack.empty ())
- {
- NS_LOG_DEBUG ("node="<<object<<", mob="<<model);
- object->AggregateObject (model);
- }
- else
- {
- // we need to setup a hierarchical mobility model
- Ptr<MobilityModel> parent = m_mobilityStack.back ();
- Ptr<MobilityModel> hierarchical =
- CreateObject<HierarchicalMobilityModel> ("Child", PointerValue (model),
- "Parent", PointerValue (parent));
- object->AggregateObject (hierarchical);
- NS_LOG_DEBUG ("node="<<object<<", mob="<<hierarchical);
- }
- }
+ {
+ model = m_mobility.Create ()->GetObject<MobilityModel> ();
+ if (model == 0)
+ {
+ NS_FATAL_ERROR ("The requested mobility model is not a mobility model: \""<<
+ m_mobility.GetTypeId ().GetName ()<<"\"");
+ }
+ if (m_mobilityStack.empty ())
+ {
+ NS_LOG_DEBUG ("node="<<object<<", mob="<<model);
+ object->AggregateObject (model);
+ }
+ else
+ {
+ // we need to setup a hierarchical mobility model
+ Ptr<MobilityModel> parent = m_mobilityStack.back ();
+ Ptr<MobilityModel> hierarchical =
+ CreateObject<HierarchicalMobilityModel> ("Child", PointerValue (model),
+ "Parent", PointerValue (parent));
+ object->AggregateObject (hierarchical);
+ NS_LOG_DEBUG ("node="<<object<<", mob="<<hierarchical);
+ }
+ }
Vector position = m_position->GetNext ();
model->SetPosition (position);
}
--- a/src/helper/mobility-helper.h Fri Oct 24 15:50:52 2008 -0700
+++ b/src/helper/mobility-helper.h Fri Oct 24 15:51:20 2008 -0700
@@ -72,15 +72,15 @@
* \param v9 the value of the attribute to set in the mobility model.
*/
void SetPositionAllocator (std::string type,
- std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (),
- std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (),
- std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (),
- std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue (),
- std::string n5 = "", const AttributeValue &v5 = EmptyAttributeValue (),
- std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (),
- std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue (),
- std::string n8 = "", const AttributeValue &v8 = EmptyAttributeValue (),
- std::string n9 = "", const AttributeValue &v9 = EmptyAttributeValue ());
+ std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (),
+ std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (),
+ std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (),
+ std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue (),
+ std::string n5 = "", const AttributeValue &v5 = EmptyAttributeValue (),
+ std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (),
+ std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue (),
+ std::string n8 = "", const AttributeValue &v8 = EmptyAttributeValue (),
+ std::string n9 = "", const AttributeValue &v9 = EmptyAttributeValue ());
/**
* \param type the type of mobility model to use.
@@ -107,15 +107,15 @@
* mobility model for each node.
*/
void SetMobilityModel (std::string type,
- std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (),
- std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (),
- std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (),
- std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue (),
- std::string n5 = "", const AttributeValue &v5 = EmptyAttributeValue (),
- std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (),
- std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue (),
- std::string n8 = "", const AttributeValue &v8 = EmptyAttributeValue (),
- std::string n9 = "", const AttributeValue &v9 = EmptyAttributeValue ());
+ std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (),
+ std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (),
+ std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (),
+ std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue (),
+ std::string n5 = "", const AttributeValue &v5 = EmptyAttributeValue (),
+ std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (),
+ std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue (),
+ std::string n8 = "", const AttributeValue &v8 = EmptyAttributeValue (),
+ std::string n9 = "", const AttributeValue &v9 = EmptyAttributeValue ());
/**
* \param reference item to push.
--- a/src/helper/node-container.cc Fri Oct 24 15:50:52 2008 -0700
+++ b/src/helper/node-container.cc Fri Oct 24 15:51:20 2008 -0700
@@ -35,14 +35,14 @@
Add (b);
}
NodeContainer::NodeContainer (const NodeContainer &a, const NodeContainer &b,
- const NodeContainer &c)
+ const NodeContainer &c)
{
Add (a);
Add (b);
Add (c);
}
NodeContainer::NodeContainer (const NodeContainer &a, const NodeContainer &b,
- const NodeContainer &c, const NodeContainer &d)
+ const NodeContainer &c, const NodeContainer &d)
{
Add (a);
Add (b);
--- a/src/helper/ns2-mobility-helper.cc Fri Oct 24 15:50:52 2008 -0700
+++ b/src/helper/ns2-mobility-helper.cc Fri Oct 24 15:51:20 2008 -0700
@@ -75,62 +75,65 @@
if (file.is_open())
{
while (!file.eof() )
- {
- std::string line;
- getline (file, line);
- std::string::size_type startNodeId = line.find_first_of ("(");
- std::string::size_type endNodeId = line.find_first_of (")");
- if (startNodeId == std::string::npos ||
- endNodeId == std::string::npos)
- {
- continue;
- }
- Ptr<StaticSpeedMobilityModel> model = GetMobilityModel (line.substr (startNodeId + 1,
- endNodeId - startNodeId),
- store);
- if (model == 0)
- {
- continue;
- }
- if (startNodeId == 6)
- {
- double value = ReadDouble (line.substr (endNodeId + 9, std::string::npos));
- std::string coordinate = line.substr (endNodeId + 6, 1);
+ {
+ std::string line;
+ getline (file, line);
+ std::string::size_type startNodeId = line.find_first_of ("(");
+ std::string::size_type endNodeId = line.find_first_of (")");
+ if (startNodeId == std::string::npos ||
+ endNodeId == std::string::npos)
+ {
+ continue;
+ }
+ Ptr<StaticSpeedMobilityModel> model = GetMobilityModel (line.substr (startNodeId + 1,
+ endNodeId - startNodeId),
+ store);
+ if (model == 0)
+ {
+ continue;
+ }
+ if (startNodeId == 6)
+ {
+ double value = ReadDouble (line.substr (endNodeId + 9, std::string::npos));
+ std::string coordinate = line.substr (endNodeId + 6, 1);
Vector position = model->GetPosition ();
- if (coordinate == "X")
- {
+ if (coordinate == "X")
+ {
position.x = value;
- NS_LOG_DEBUG ("X=" << value);
- }
- else if (coordinate == "Y")
- {
+ NS_LOG_DEBUG ("X=" << value);
+ }
+ else if (coordinate == "Y")
+ {
position.y = value;
- NS_LOG_DEBUG ("Y=" << value);
- }
- else if (coordinate == "Z")
- {
+ NS_LOG_DEBUG ("Y=" << value);
+ }
+ else if (coordinate == "Z")
+ {
position.z = value;
- NS_LOG_DEBUG ("Z=" << value);
- }
+ NS_LOG_DEBUG ("Z=" << value);
+ }
else
{
continue;
}
model->SetPosition (position);
- }
- else
- {
- double at = ReadDouble (line.substr (8, startNodeId - 17));
- std::string::size_type xSpeedEnd = line.find_first_of (" ", endNodeId + 10);
- std::string::size_type ySpeedEnd = line.find_first_of (" ", xSpeedEnd + 1);
- double xSpeed = ReadDouble (line.substr (endNodeId + 10, xSpeedEnd - endNodeId - 10));
- double ySpeed = ReadDouble (line.substr (xSpeedEnd + 1, ySpeedEnd - xSpeedEnd - 1));
- 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,
- Vector (xSpeed, ySpeed, zSpeed));
- }
- }
+ }
+ else
+ {
+ std::string::size_type atEnd = line.find_first_of (" ", 8);
+ std::string atStr = line.substr (8, atEnd-8);
+ NS_LOG_DEBUG (atStr);
+ double at = ReadDouble (atStr);
+ std::string::size_type xSpeedEnd = line.find_first_of (" ", endNodeId + 10);
+ std::string::size_type ySpeedEnd = line.find_first_of (" ", xSpeedEnd + 1);
+ double xSpeed = ReadDouble (line.substr (endNodeId + 10, xSpeedEnd - endNodeId - 10));
+ double ySpeed = ReadDouble (line.substr (xSpeedEnd + 1, ySpeedEnd - xSpeedEnd - 1));
+ 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::SetVelocity, model,
+ Vector (xSpeed, ySpeed, zSpeed));
+ }
+ }
file.close();
}
}
--- a/src/helper/ns2-mobility-helper.h Fri Oct 24 15:50:52 2008 -0700
+++ b/src/helper/ns2-mobility-helper.h Fri Oct 24 15:51:20 2008 -0700
@@ -90,14 +90,14 @@
MyObjectStore (T begin, T end)
: m_begin (begin),
m_end (end)
- {}
+ {}
virtual Ptr<Object> Get (uint32_t i) const {
T iterator = m_begin;
iterator += i;
if (iterator >= m_end)
- {
- return 0;
- }
+ {
+ return 0;
+ }
return *iterator;
}
private:
--- a/src/helper/olsr-helper.cc Fri Oct 24 15:50:52 2008 -0700
+++ b/src/helper/olsr-helper.cc Fri Oct 24 15:51:20 2008 -0700
@@ -30,14 +30,14 @@
void
OlsrHelper::SetAgent (std::string tid,
- std::string n0, const AttributeValue &v0,
- std::string n1, const AttributeValue &v1,
- std::string n2, const AttributeValue &v2,
- std::string n3, const AttributeValue &v3,
- std::string n4, const AttributeValue &v4,
- std::string n5, const AttributeValue &v5,
- std::string n6, const AttributeValue &v6,
- std::string n7, const AttributeValue &v7)
+ std::string n0, const AttributeValue &v0,
+ std::string n1, const AttributeValue &v1,
+ std::string n2, const AttributeValue &v2,
+ std::string n3, const AttributeValue &v3,
+ std::string n4, const AttributeValue &v4,
+ std::string n5, const AttributeValue &v5,
+ std::string n6, const AttributeValue &v6,
+ std::string n7, const AttributeValue &v7)
{
m_agentFactory.SetTypeId (tid);
m_agentFactory.Set (n0, v0);
--- a/src/helper/olsr-helper.h Fri Oct 24 15:50:52 2008 -0700
+++ b/src/helper/olsr-helper.h Fri Oct 24 15:51:20 2008 -0700
@@ -38,14 +38,14 @@
* \brief Set default OLSR routing agent attributes
*/
void SetAgent (std::string tid,
- std::string n0 = "", const AttributeValue &v0 = EmptyAttributeValue (),
- std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (),
- std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (),
- std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (),
- std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue (),
- std::string n5 = "", const AttributeValue &v5 = EmptyAttributeValue (),
- std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (),
- std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue ());
+ std::string n0 = "", const AttributeValue &v0 = EmptyAttributeValue (),
+ std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (),
+ std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (),
+ std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (),
+ std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue (),
+ std::string n5 = "", const AttributeValue &v5 = EmptyAttributeValue (),
+ std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (),
+ std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue ());
/**
* \brief Enable OLSR routing for a set of nodes
--- a/src/helper/point-to-point-helper.cc Fri Oct 24 15:50:52 2008 -0700
+++ b/src/helper/point-to-point-helper.cc Fri Oct 24 15:51:20 2008 -0700
@@ -39,10 +39,10 @@
void
PointToPointHelper::SetQueue (std::string type,
- std::string n1, const AttributeValue &v1,
- std::string n2, const AttributeValue &v2,
- std::string n3, const AttributeValue &v3,
- std::string n4, const AttributeValue &v4)
+ std::string n1, const AttributeValue &v1,
+ std::string n2, const AttributeValue &v2,
+ std::string n3, const AttributeValue &v3,
+ std::string n4, const AttributeValue &v4)
{
m_queueFactory.SetTypeId (type);
m_queueFactory.Set (n1, v1);
@@ -78,6 +78,13 @@
PointToPointHelper::EnablePcap (std::string filename, uint32_t nodeid, uint32_t deviceid)
{
std::ostringstream oss;
+ oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::PointToPointNetDevice/";
+ Config::MatchContainer matches = Config::LookupMatches (oss.str ());
+ if (matches.GetN () == 0)
+ {
+ return;
+ }
+ oss.str ("");
oss << filename << "-" << nodeid << "-" << deviceid << ".pcap";
Ptr<PcapWriter> pcap = Create<PcapWriter> ();
pcap->Open (oss.str ());
@@ -106,9 +113,9 @@
{
Ptr<Node> node = *i;
for (uint32_t j = 0; j < node->GetNDevices (); ++j)
- {
- devs.Add (node->GetDevice (j));
- }
+ {
+ devs.Add (node->GetDevice (j));
+ }
}
EnablePcap (filename, devs);
}
@@ -153,9 +160,9 @@
{
Ptr<Node> node = *i;
for (uint32_t j = 0; j < node->GetNDevices (); ++j)
- {
- devs.Add (node->GetDevice (j));
- }
+ {
+ devs.Add (node->GetDevice (j));
+ }
}
EnableAscii (os, devs);
}
--- a/src/helper/point-to-point-helper.h Fri Oct 24 15:50:52 2008 -0700
+++ b/src/helper/point-to-point-helper.h Fri Oct 24 15:51:20 2008 -0700
@@ -57,10 +57,10 @@
* PointToPointNetDevice created through PointToPointHelper::Install.
*/
void SetQueue (std::string type,
- std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (),
- std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (),
- std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (),
- std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue ());
+ std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (),
+ std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (),
+ std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (),
+ std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue ());
/**
* \param name the name of the attribute to set
--- a/src/helper/wifi-helper.cc Fri Oct 24 15:50:52 2008 -0700
+++ b/src/helper/wifi-helper.cc Fri Oct 24 15:51:20 2008 -0700
@@ -40,30 +40,30 @@
namespace ns3 {
static void PcapPhyTxEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet,
- WifiMode mode, WifiPreamble preamble,
- uint8_t txLevel)
+ WifiMode mode, WifiPreamble preamble,
+ uint8_t txLevel)
{
writer->WritePacket (packet);
}
static void PcapPhyRxEvent (Ptr<PcapWriter> writer,
- Ptr<const Packet> packet, double snr, WifiMode mode,
- enum WifiPreamble preamble)
+ Ptr<const Packet> packet, double snr, WifiMode mode,
+ enum WifiPreamble preamble)
{
writer->WritePacket (packet);
}
static void AsciiPhyTxEvent (std::ostream *os, std::string context,
- Ptr<const Packet> packet,
- WifiMode mode, WifiPreamble preamble,
- uint8_t txLevel)
+ Ptr<const Packet> packet,
+ WifiMode mode, WifiPreamble preamble,
+ uint8_t txLevel)
{
*os << "+ " << Simulator::Now () << " " << context << " " << *packet << std::endl;
}
static void AsciiPhyRxOkEvent (std::ostream *os, std::string context,
- Ptr<const Packet> packet, double snr, WifiMode mode,
- enum WifiPreamble preamble)
+ Ptr<const Packet> packet, double snr, WifiMode mode,
+ enum WifiPreamble preamble)
{
*os << "r " << Simulator::Now () << " " << context << " " << *packet << std::endl;
}
@@ -78,14 +78,14 @@
void
WifiHelper::SetRemoteStationManager (std::string type,
- std::string n0, const AttributeValue &v0,
- std::string n1, const AttributeValue &v1,
- std::string n2, const AttributeValue &v2,
- std::string n3, const AttributeValue &v3,
- std::string n4, const AttributeValue &v4,
- std::string n5, const AttributeValue &v5,
- std::string n6, const AttributeValue &v6,
- std::string n7, const AttributeValue &v7)
+ std::string n0, const AttributeValue &v0,
+ std::string n1, const AttributeValue &v1,
+ std::string n2, const AttributeValue &v2,
+ std::string n3, const AttributeValue &v3,
+ std::string n4, const AttributeValue &v4,
+ std::string n5, const AttributeValue &v5,
+ std::string n6, const AttributeValue &v6,
+ std::string n7, const AttributeValue &v7)
{
m_stationManager = ObjectFactory ();
m_stationManager.SetTypeId (type);
@@ -101,14 +101,14 @@
void
WifiHelper::SetMac (std::string type,
- std::string n0, const AttributeValue &v0,
- std::string n1, const AttributeValue &v1,
- std::string n2, const AttributeValue &v2,
- std::string n3, const AttributeValue &v3,
- std::string n4, const AttributeValue &v4,
- std::string n5, const AttributeValue &v5,
- std::string n6, const AttributeValue &v6,
- std::string n7, const AttributeValue &v7)
+ std::string n0, const AttributeValue &v0,
+ std::string n1, const AttributeValue &v1,
+ std::string n2, const AttributeValue &v2,
+ std::string n3, const AttributeValue &v3,
+ std::string n4, const AttributeValue &v4,
+ std::string n5, const AttributeValue &v5,
+ std::string n6, const AttributeValue &v6,
+ std::string n7, const AttributeValue &v7)
{
m_mac = ObjectFactory ();
m_mac.SetTypeId (type);
@@ -124,14 +124,14 @@
void
WifiHelper::SetPhy (std::string type,
- std::string n0, const AttributeValue &v0,
- std::string n1, const AttributeValue &v1,
- std::string n2, const AttributeValue &v2,
- std::string n3, const AttributeValue &v3,
- std::string n4, const AttributeValue &v4,
- std::string n5, const AttributeValue &v5,
- std::string n6, const AttributeValue &v6,
- std::string n7, const AttributeValue &v7)
+ std::string n0, const AttributeValue &v0,
+ std::string n1, const AttributeValue &v1,
+ std::string n2, const AttributeValue &v2,
+ std::string n3, const AttributeValue &v3,
+ std::string n4, const AttributeValue &v4,
+ std::string n5, const AttributeValue &v5,
+ std::string n6, const AttributeValue &v6,
+ std::string n7, const AttributeValue &v7)
{
m_phy = ObjectFactory ();
m_phy.SetTypeId (type);
@@ -149,6 +149,13 @@
WifiHelper::EnablePcap (std::string filename, uint32_t nodeid, uint32_t deviceid)
{
std::ostringstream oss;
+ oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/";
+ Config::MatchContainer matches = Config::LookupMatches (oss.str ());
+ if (matches.GetN () == 0)
+ {
+ return;
+ }
+ oss.str ("");
oss << filename << "-" << nodeid << "-" << deviceid << ".pcap";
Ptr<PcapWriter> pcap = Create<PcapWriter> ();
pcap->Open (oss.str ());
@@ -177,9 +184,9 @@
{
Ptr<Node> node = *i;
for (uint32_t j = 0; j < node->GetNDevices (); ++j)
- {
- devs.Add (node->GetDevice (j));
- }
+ {
+ devs.Add (node->GetDevice (j));
+ }
}
EnablePcap (filename, devs);
}
@@ -218,9 +225,9 @@
{
Ptr<Node> node = *i;
for (uint32_t j = 0; j < node->GetNDevices (); ++j)
- {
- devs.Add (node->GetDevice (j));
- }
+ {
+ devs.Add (node->GetDevice (j));
+ }
}
EnableAscii (os, devs);
}
--- a/src/helper/wifi-helper.h Fri Oct 24 15:50:52 2008 -0700
+++ b/src/helper/wifi-helper.h Fri Oct 24 15:51:20 2008 -0700
@@ -65,14 +65,14 @@
* in the requested station manager.
*/
void SetRemoteStationManager (std::string type,
- std::string n0 = "", const AttributeValue &v0 = EmptyAttributeValue (),
- std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (),
- std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (),
- std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (),
- std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue (),
- std::string n5 = "", const AttributeValue &v5 = EmptyAttributeValue (),
- std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (),
- std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue ());
+ std::string n0 = "", const AttributeValue &v0 = EmptyAttributeValue (),
+ std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (),
+ std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (),
+ std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (),
+ std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue (),
+ std::string n5 = "", const AttributeValue &v5 = EmptyAttributeValue (),
+ std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (),
+ std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue ());
/**
* \param type the type of ns3::WifiMac to create.
@@ -97,14 +97,14 @@
* in the requested mac.
*/
void SetMac (std::string type,
- std::string n0 = "", const AttributeValue &v0 = EmptyAttributeValue (),
- std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (),
- std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (),
- std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (),
- std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue (),
- std::string n5 = "", const AttributeValue &v5 = EmptyAttributeValue (),
- std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (),
- std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue ());
+ std::string n0 = "", const AttributeValue &v0 = EmptyAttributeValue (),
+ std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (),
+ std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (),
+ std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (),
+ std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue (),
+ std::string n5 = "", const AttributeValue &v5 = EmptyAttributeValue (),
+ std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (),
+ std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue ());
/**
* \param phyType the type of ns3::WifiPhy to create.
@@ -129,14 +129,14 @@
* in the requested phy.
*/
void SetPhy (std::string phyType,
- std::string n0 = "", const AttributeValue &v0 = EmptyAttributeValue (),
- std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (),
- std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (),
- std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (),
- std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue (),
- std::string n5 = "", const AttributeValue &v5 = EmptyAttributeValue (),
- std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (),
- std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue ());
+ std::string n0 = "", const AttributeValue &v0 = EmptyAttributeValue (),
+ std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (),
+ std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (),
+ std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (),
+ std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue (),
+ std::string n5 = "", const AttributeValue &v5 = EmptyAttributeValue (),
+ std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (),
+ std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue ());
--- a/src/internet-stack/nsc-tcp-socket-impl.cc Fri Oct 24 15:50:52 2008 -0700
+++ b/src/internet-stack/nsc-tcp-socket-impl.cc Fri Oct 24 15:51:20 2008 -0700
@@ -330,34 +330,19 @@
return -1;
}
- bool txEmpty = m_txBuffer.empty();
+ uint32_t sent = p->GetSize ();
if (m_state == ESTABLISHED)
{
- if (txEmpty)
- {
- m_txBuffer.push(p);
- m_txBufferSize += p->GetSize ();
- }
- if (!SendPendingData())
- {
- if (m_errno == ERROR_AGAIN)
- {
- return txEmpty ? p->GetSize () : -1;
- }
- if (txEmpty)
- {
- m_txBuffer.pop ();
- m_txBufferSize = 0;
- }
- return -1;
- }
+ m_txBuffer.push(p);
+ m_txBufferSize += sent;
+ SendPendingData();
}
else
{ // SYN_SET -- Queue Data
m_txBuffer.push(p);
- m_txBufferSize += p->GetSize ();
+ m_txBufferSize += sent;
}
- return p->GetSize ();
+ return sent;
}
else
{
@@ -436,6 +421,7 @@
NS_LOG_FUNCTION_NOARGS ();
if (m_deliveryQueue.empty() )
{
+ m_errno = ERROR_AGAIN;
return 0;
}
Ptr<Packet> p = m_deliveryQueue.front ();
@@ -446,6 +432,7 @@
}
else
{
+ m_errno = ERROR_AGAIN;
p = 0;
}
return p;
@@ -637,6 +624,7 @@
size_t size, written = 0;
do {
+ NS_ASSERT (!m_txBuffer.empty ());
Ptr<Packet> &p = m_txBuffer.front ();
size = p->GetSize ();
NS_ASSERT (size > 0);
@@ -645,12 +633,6 @@
ret = m_nscTcpSocket->send_data((const char *)p->PeekData (), size);
if (ret <= 0)
{
- m_errno = GetNativeNs3Errno(ret);
- if (m_errno != ERROR_AGAIN)
- {
- NS_LOG_WARN ("Error (" << ret << ") " <<
- "during send_data, ns-3 errno set to" << m_errno);
- }
break;
}
written += ret;
--- a/src/mobility/random-direction-2d-mobility-model.cc Fri Oct 24 15:50:52 2008 -0700
+++ b/src/mobility/random-direction-2d-mobility-model.cc Fri Oct 24 15:51:20 2008 -0700
@@ -76,8 +76,9 @@
void
RandomDirection2dMobilityModel::BeginPause (void)
{
+ m_helper.Update ();
+ m_helper.Pause ();
Time pause = Seconds (m_pause.GetValue ());
- m_helper.Pause ();
m_event = Simulator::Schedule (pause, &RandomDirection2dMobilityModel::ResetDirectionAndSpeed, this);
NotifyCourseChange ();
}
@@ -86,12 +87,14 @@
RandomDirection2dMobilityModel::SetDirectionAndSpeed (double direction)
{
NS_LOG_FUNCTION_NOARGS ();
+ m_helper.UpdateWithBounds (m_bounds);
+ Vector position = m_helper.GetCurrentPosition ();
double speed = m_speed.GetValue ();
const Vector vector (std::cos (direction) * speed,
std::sin (direction) * speed,
0.0);
- Vector position = m_helper.GetCurrentPosition (m_bounds);
- m_helper.Reset (vector);
+ m_helper.SetVelocity (vector);
+ m_helper.Unpause ();
Vector next = m_bounds.CalculateIntersection (position, vector);
Time delay = Seconds (CalculateDistance (position, next) / speed);
m_event = Simulator::Schedule (delay,
@@ -103,7 +106,8 @@
{
double direction = UniformVariable::GetSingleValue (0, PI);
- Vector position = m_helper.GetCurrentPosition (m_bounds);
+ m_helper.UpdateWithBounds (m_bounds);
+ Vector position = m_helper.GetCurrentPosition ();
switch (m_bounds.GetClosestSide (position))
{
case Rectangle::RIGHT:
@@ -124,12 +128,13 @@
Vector
RandomDirection2dMobilityModel::DoGetPosition (void) const
{
- return m_helper.GetCurrentPosition (m_bounds);
+ m_helper.UpdateWithBounds (m_bounds);
+ return m_helper.GetCurrentPosition ();
}
void
RandomDirection2dMobilityModel::DoSetPosition (const Vector &position)
{
- m_helper.InitializePosition (position);
+ m_helper.SetPosition (position);
Simulator::Remove (m_event);
m_event = Simulator::ScheduleNow (&RandomDirection2dMobilityModel::Start, this);
}
--- a/src/mobility/random-walk-2d-mobility-model.cc Fri Oct 24 15:50:52 2008 -0700
+++ b/src/mobility/random-walk-2d-mobility-model.cc Fri Oct 24 15:51:20 2008 -0700
@@ -80,12 +80,14 @@
void
RandomWalk2dMobilityModel::Start (void)
{
+ m_helper.Update ();
double speed = m_speed.GetValue ();
double direction = m_direction.GetValue ();
Vector vector (std::cos (direction) * speed,
std::sin (direction) * speed,
0.0);
- m_helper.Reset (vector);
+ m_helper.SetVelocity (vector);
+ m_helper.Unpause ();
Time delayLeft;
if (m_mode == RandomWalk2dMobilityModel::MODE_TIME)
@@ -124,7 +126,8 @@
void
RandomWalk2dMobilityModel::Rebound (Time delayLeft)
{
- Vector position = m_helper.GetCurrentPosition (m_bounds);
+ m_helper.UpdateWithBounds (m_bounds);
+ Vector position = m_helper.GetCurrentPosition ();
Vector speed = m_helper.GetVelocity ();
switch (m_bounds.GetClosestSide (position))
{
@@ -137,7 +140,8 @@
speed.y = - speed.y;
break;
}
- m_helper.Reset (speed);
+ m_helper.SetVelocity (speed);
+ m_helper.Unpause ();
DoWalk (delayLeft);
}
@@ -150,13 +154,14 @@
Vector
RandomWalk2dMobilityModel::DoGetPosition (void) const
{
- return m_helper.GetCurrentPosition (m_bounds);
+ m_helper.UpdateWithBounds (m_bounds);
+ return m_helper.GetCurrentPosition ();
}
void
RandomWalk2dMobilityModel::DoSetPosition (const Vector &position)
{
NS_ASSERT (m_bounds.IsInside (position));
- m_helper.InitializePosition (position);
+ m_helper.SetPosition (position);
Simulator::Remove (m_event);
m_event = Simulator::ScheduleNow (&RandomWalk2dMobilityModel::Start, this);
}
--- a/src/mobility/random-waypoint-mobility-model.cc Fri Oct 24 15:50:52 2008 -0700
+++ b/src/mobility/random-waypoint-mobility-model.cc Fri Oct 24 15:51:20 2008 -0700
@@ -62,6 +62,7 @@
void
RandomWaypointMobilityModel::BeginWalk (void)
{
+ m_helper.Update ();
Vector m_current = m_helper.GetCurrentPosition ();
Vector destination = m_position->GetNext ();
double speed = m_speed.GetValue ();
@@ -70,7 +71,7 @@
double dz = (destination.z - m_current.z);
double k = speed / std::sqrt (dx*dx + dy*dy + dz*dz);
- m_helper.Reset (Vector (k*dx, k*dy, k*dz));
+ m_helper.SetVelocity (Vector (k*dx, k*dy, k*dz));
Time travelDelay = Seconds (CalculateDistance (destination, m_current) / speed);
m_event = Simulator::Schedule (travelDelay,
&RandomWaypointMobilityModel::Start, this);
@@ -80,21 +81,23 @@
void
RandomWaypointMobilityModel::Start (void)
{
- Time pause = Seconds (m_pause.GetValue ());
+ m_helper.Update ();
m_helper.Pause ();
+ Time pause = Seconds (m_pause.GetValue ());
+ m_event = Simulator::Schedule (pause, &RandomWaypointMobilityModel::BeginWalk, this);
NotifyCourseChange ();
- m_event = Simulator::Schedule (pause, &RandomWaypointMobilityModel::BeginWalk, this);
}
Vector
RandomWaypointMobilityModel::DoGetPosition (void) const
{
+ m_helper.Update ();
return m_helper.GetCurrentPosition ();
}
void
RandomWaypointMobilityModel::DoSetPosition (const Vector &position)
{
- m_helper.InitializePosition (position);
+ m_helper.SetPosition (position);
Simulator::Remove (m_event);
Simulator::ScheduleNow (&RandomWaypointMobilityModel::Start, this);
}
--- a/src/mobility/static-speed-helper.cc Fri Oct 24 15:50:52 2008 -0700
+++ b/src/mobility/static-speed-helper.cc Fri Oct 24 15:51:20 2008 -0700
@@ -29,67 +29,56 @@
: m_position (position)
{}
StaticSpeedHelper::StaticSpeedHelper (const Vector &position,
- const Vector &speed)
+ const Vector &vel)
: m_position (position),
- m_speed (speed),
+ m_velocity (vel),
m_paused (true)
{}
void
-StaticSpeedHelper::InitializePosition (const Vector &position)
+StaticSpeedHelper::SetPosition (const Vector &position)
{
m_position = position;
- m_speed.x = 0.0;
- m_speed.y = 0.0;
- m_speed.z = 0.0;
+ m_velocity = Vector (0.0, 0.0, 0.0);
m_lastUpdate = Simulator::Now ();
- m_paused = true;
}
Vector
StaticSpeedHelper::GetCurrentPosition (void) const
{
- Update ();
return m_position;
}
Vector
StaticSpeedHelper::GetVelocity (void) const
{
- return m_paused? Vector (0.0, 0.0, 0.0) : m_speed;
+ return m_paused? Vector (0.0, 0.0, 0.0) : m_velocity;
}
void
-StaticSpeedHelper::SetSpeed (const Vector &speed)
+StaticSpeedHelper::SetVelocity (const Vector &vel)
{
- Update ();
- m_speed = speed;
+ m_velocity = vel;
+ m_lastUpdate = Simulator::Now ();
}
void
StaticSpeedHelper::Update (void) const
{
- if (m_paused)
- {
- return;
- }
Time now = Simulator::Now ();
NS_ASSERT (m_lastUpdate <= now);
Time deltaTime = now - m_lastUpdate;
m_lastUpdate = now;
+ if (m_paused)
+ {
+ return;
+ }
double deltaS = deltaTime.GetSeconds ();
- m_position.x += m_speed.x * deltaS;
- m_position.y += m_speed.y * deltaS;
- m_position.z += m_speed.z * deltaS;
+ m_position.x += m_velocity.x * deltaS;
+ m_position.y += m_velocity.y * deltaS;
+ m_position.z += m_velocity.z * deltaS;
}
-void
-StaticSpeedHelper::Reset (const Vector &speed)
-{
- Update ();
- m_speed = speed;
- Unpause ();
-}
void
-StaticSpeedHelper::UpdateFull (const Rectangle &bounds) const
+StaticSpeedHelper::UpdateWithBounds (const Rectangle &bounds) const
{
Update ();
m_position.x = std::min (bounds.xMax, m_position.x);
@@ -98,28 +87,16 @@
m_position.y = std::max (bounds.yMin, m_position.y);
}
-Vector
-StaticSpeedHelper::GetCurrentPosition (const Rectangle &bounds) const
-{
- UpdateFull (bounds);
- return m_position;
-}
-
void
StaticSpeedHelper::Pause (void)
{
- Update ();
m_paused = true;
}
void
StaticSpeedHelper::Unpause (void)
{
- if (m_paused)
- {
- m_lastUpdate = Simulator::Now ();
- m_paused = false;
- }
+ m_paused = false;
}
} // namespace ns3
--- a/src/mobility/static-speed-helper.h Fri Oct 24 15:50:52 2008 -0700
+++ b/src/mobility/static-speed-helper.h Fri Oct 24 15:51:20 2008 -0700
@@ -33,23 +33,21 @@
StaticSpeedHelper ();
StaticSpeedHelper (const Vector &position);
StaticSpeedHelper (const Vector &position,
- const Vector &speed);
- void InitializePosition (const Vector &position);
+ const Vector &vel);
- void Reset (const Vector &speed);
- Vector GetCurrentPosition (const Rectangle &bounds) const;
+ void SetPosition (const Vector &position);
Vector GetCurrentPosition (void) const;
Vector GetVelocity (void) const;
- void SetSpeed (const Vector &speed);
+ void SetVelocity (const Vector &vel);
void Pause (void);
void Unpause (void);
- private:
+ void UpdateWithBounds (const Rectangle &rectangle) const;
void Update (void) const;
- void UpdateFull (const Rectangle &rectangle) const;
+ private:
mutable Time m_lastUpdate;
mutable Vector m_position;
- Vector m_speed;
+ Vector m_velocity;
bool m_paused;
};
--- a/src/mobility/static-speed-mobility-model.cc Fri Oct 24 15:50:52 2008 -0700
+++ b/src/mobility/static-speed-mobility-model.cc Fri Oct 24 15:51:20 2008 -0700
@@ -39,9 +39,11 @@
{}
void
-StaticSpeedMobilityModel::SetSpeed (const Vector &speed)
+StaticSpeedMobilityModel::SetVelocity (const Vector &speed)
{
- m_helper.SetSpeed (speed);
+ m_helper.Update ();
+ m_helper.SetVelocity (speed);
+ m_helper.Unpause ();
NotifyCourseChange ();
}
@@ -49,12 +51,13 @@
Vector
StaticSpeedMobilityModel::DoGetPosition (void) const
{
+ m_helper.Update ();
return m_helper.GetCurrentPosition ();
}
void
StaticSpeedMobilityModel::DoSetPosition (const Vector &position)
{
- m_helper.InitializePosition (position);
+ m_helper.SetPosition (position);
NotifyCourseChange ();
}
Vector
--- a/src/mobility/static-speed-mobility-model.h Fri Oct 24 15:50:52 2008 -0700
+++ b/src/mobility/static-speed-mobility-model.h Fri Oct 24 15:51:20 2008 -0700
@@ -49,7 +49,7 @@
* Set the current speed now to (dx,dy,dz)
* Unit is meters/s
*/
- void SetSpeed (const Vector &speed);
+ void SetVelocity (const Vector &speed);
private:
virtual Vector DoGetPosition (void) const;
virtual void DoSetPosition (const Vector &position);