branch merge
This commit is contained in:
@@ -150,21 +150,12 @@ def register_Ns3StaticSpeedHelper_methods(root_module, cls):
|
||||
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 @@ def register_Ns3StaticSpeedHelper_methods(root_module, cls):
|
||||
'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 @@ def register_Ns3StaticSpeedHelper_methods(root_module, cls):
|
||||
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 @@ def register_Ns3StaticSpeedMobilityModel_methods(root_module, cls):
|
||||
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]
|
||||
|
||||
@@ -1356,6 +1356,11 @@ def register_Ns3Socket_methods(root_module, cls):
|
||||
cls.add_method('RecvFrom',
|
||||
'int',
|
||||
[param('uint8_t *', 'buf'), param('uint32_t', 'size'), param('uint32_t', 'flags'), param('ns3::Address &', 'fromAddress')])
|
||||
## socket.h: int ns3::Socket::GetSockName(ns3::Address & address) const [member function]
|
||||
cls.add_method('GetSockName',
|
||||
'int',
|
||||
[param('ns3::Address &', 'address')],
|
||||
is_pure_virtual=True, is_const=True, is_virtual=True)
|
||||
## socket.h: void ns3::Socket::NotifyConnectionSucceeded() [member function]
|
||||
cls.add_method('NotifyConnectionSucceeded',
|
||||
'void',
|
||||
|
||||
37
samples/main-ns2-mob.cc
Normal file
37
samples/main-ns2-mob.cc
Normal file
@@ -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;
|
||||
}
|
||||
7
samples/ns2-mob.tr
Normal file
7
samples/ns2-mob.tr
Normal file
@@ -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"
|
||||
@@ -39,4 +39,8 @@ def build(bld):
|
||||
['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'
|
||||
|
||||
|
||||
|
||||
54
src/core/abort.h
Normal file
54
src/core/abort.h
Normal file
@@ -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 */
|
||||
@@ -30,6 +30,100 @@ NS_LOG_COMPONENT_DEFINE ("Config");
|
||||
|
||||
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 @@ public:
|
||||
|
||||
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 @@ Resolver::Resolve (Ptr<Object> root)
|
||||
}
|
||||
|
||||
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 @@ Resolver::DoResolve (std::string path, Ptr<Object> root)
|
||||
{
|
||||
// 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 @@ Resolver::DoResolve (std::string path, Ptr<Object> root)
|
||||
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 @@ Resolver::DoResolve (std::string path, Ptr<Object> root)
|
||||
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 @@ void
|
||||
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 @@ public:
|
||||
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 @@ public:
|
||||
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
|
||||
{
|
||||
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);
|
||||
}
|
||||
CallbackBase m_cb;
|
||||
} resolver = ConnectWithContextResolver (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.Connect (leaf, cb);
|
||||
}
|
||||
void
|
||||
ConfigImpl::Disconnect (std::string path, const CallbackBase &cb)
|
||||
{
|
||||
class DisconnectWithContextResolver : public Resolver
|
||||
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:
|
||||
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);
|
||||
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 = DisconnectWithContextResolver (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::RegisterRootNamespaceObject (Ptr<Object> obj)
|
||||
{
|
||||
@@ -472,6 +553,10 @@ Disconnect (std::string path, const CallbackBase &cb)
|
||||
{
|
||||
Singleton<ConfigImpl>::Get ()->Disconnect (path, cb);
|
||||
}
|
||||
Config::MatchContainer LookupMatches (std::string path)
|
||||
{
|
||||
return Singleton<ConfigImpl>::Get ()->LookupMatches (path);
|
||||
}
|
||||
|
||||
void RegisterRootNamespaceObject (Ptr<Object> obj)
|
||||
{
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#include "ptr.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
@@ -110,6 +111,35 @@ void Connect (std::string path, const CallbackBase &cb);
|
||||
*/
|
||||
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
|
||||
*
|
||||
|
||||
@@ -148,8 +148,9 @@ public:
|
||||
* 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
|
||||
* @returns true if thread is expected to exit
|
||||
*/
|
||||
void Shutdown (void);
|
||||
|
||||
|
||||
@@ -116,7 +116,8 @@ def build(bld):
|
||||
'trace-source-accessor.h',
|
||||
'config.h',
|
||||
'object-vector.h',
|
||||
'deprecated.h'
|
||||
'deprecated.h',
|
||||
'abort.h',
|
||||
]
|
||||
|
||||
if sys.platform == 'win32':
|
||||
|
||||
@@ -76,6 +76,9 @@ NqapWifiMac::NqapWifiMac ()
|
||||
m_dca->SetTxFailedCallback (MakeCallback (&NqapWifiMac::TxFailed, this));
|
||||
|
||||
m_beaconDca = CreateObject<DcaTxop> ();
|
||||
m_beaconDca->SetAifsn(1);
|
||||
m_beaconDca->SetMinCw(0);
|
||||
m_beaconDca->SetMaxCw(0);
|
||||
m_beaconDca->SetLow (m_low);
|
||||
m_beaconDca->SetManager (m_dcfManager);
|
||||
}
|
||||
|
||||
@@ -39,10 +39,10 @@ CsmaHelper::CsmaHelper ()
|
||||
|
||||
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 @@ void
|
||||
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 @@ CsmaHelper::EnablePcap (std::string filename, NodeContainer n)
|
||||
{
|
||||
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 @@ CsmaHelper::EnableAscii (std::ostream &os, NodeContainer n)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -57,10 +57,10 @@ public:
|
||||
* 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
|
||||
|
||||
@@ -47,15 +47,15 @@ MobilityHelper::SetPositionAllocator (Ptr<PositionAllocator> allocator)
|
||||
}
|
||||
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 @@ MobilityHelper::SetPositionAllocator (std::string type,
|
||||
|
||||
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 @@ MobilityHelper::Install (NodeContainer c)
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -72,15 +72,15 @@ public:
|
||||
* \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 @@ public:
|
||||
* 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.
|
||||
|
||||
@@ -35,14 +35,14 @@ NodeContainer::NodeContainer (const NodeContainer &a, const NodeContainer &b)
|
||||
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);
|
||||
|
||||
@@ -75,62 +75,65 @@ Ns2MobilityHelper::LayoutObjectStore (const ObjectStore &store) const
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,14 +90,14 @@ Ns2MobilityHelper::Install (T begin, T end) const
|
||||
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:
|
||||
|
||||
@@ -30,14 +30,14 @@ OlsrHelper::OlsrHelper ()
|
||||
|
||||
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);
|
||||
|
||||
@@ -38,14 +38,14 @@ public:
|
||||
* \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
|
||||
|
||||
@@ -39,10 +39,10 @@ PointToPointHelper::PointToPointHelper ()
|
||||
|
||||
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 @@ void
|
||||
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 @@ PointToPointHelper::EnablePcap (std::string filename, NodeContainer n)
|
||||
{
|
||||
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 @@ PointToPointHelper::EnableAscii (std::ostream &os, NodeContainer n)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -57,10 +57,10 @@ public:
|
||||
* 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
|
||||
|
||||
@@ -40,30 +40,30 @@ NS_LOG_COMPONENT_DEFINE ("WifiHelper");
|
||||
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 @@ WifiHelper::WifiHelper ()
|
||||
|
||||
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 @@ WifiHelper::SetRemoteStationManager (std::string type,
|
||||
|
||||
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 @@ WifiHelper::SetMac (std::string type,
|
||||
|
||||
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 @@ void
|
||||
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 @@ WifiHelper::EnablePcap (std::string filename, NodeContainer n)
|
||||
{
|
||||
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 @@ WifiHelper::EnableAscii (std::ostream &os, NodeContainer n)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -65,14 +65,14 @@ public:
|
||||
* 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 @@ public:
|
||||
* 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 @@ public:
|
||||
* 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 ());
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -64,6 +64,8 @@ NscTcpSocketImpl::GetTypeId ()
|
||||
: m_endPoint (0),
|
||||
m_node (0),
|
||||
m_tcp (0),
|
||||
m_localAddress (Ipv4Address::GetZero ()),
|
||||
m_localPort (0),
|
||||
m_peerAddress ("0.0.0.0", 0),
|
||||
m_errno (ERROR_NOTERROR),
|
||||
m_shutdownSend (false),
|
||||
@@ -328,34 +330,19 @@ NscTcpSocketImpl::Send (const Ptr<Packet> p, uint32_t flags)
|
||||
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
|
||||
{
|
||||
@@ -434,6 +421,7 @@ NscTcpSocketImpl::Recv (uint32_t maxSize, uint32_t flags)
|
||||
NS_LOG_FUNCTION_NOARGS ();
|
||||
if (m_deliveryQueue.empty() )
|
||||
{
|
||||
m_errno = ERROR_AGAIN;
|
||||
return 0;
|
||||
}
|
||||
Ptr<Packet> p = m_deliveryQueue.front ();
|
||||
@@ -444,6 +432,7 @@ NscTcpSocketImpl::Recv (uint32_t maxSize, uint32_t flags)
|
||||
}
|
||||
else
|
||||
{
|
||||
m_errno = ERROR_AGAIN;
|
||||
p = 0;
|
||||
}
|
||||
return p;
|
||||
@@ -466,6 +455,14 @@ NscTcpSocketImpl::RecvFrom (uint32_t maxSize, uint32_t flags,
|
||||
return packet;
|
||||
}
|
||||
|
||||
int
|
||||
NscTcpSocketImpl::GetSockName (Address &address) const
|
||||
{
|
||||
NS_LOG_FUNCTION_NOARGS ();
|
||||
address = InetSocketAddress(m_localAddress, m_localPort);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
NscTcpSocketImpl::GetRxAvailable (void) const
|
||||
{
|
||||
@@ -627,6 +624,7 @@ bool NscTcpSocketImpl::SendPendingData (void)
|
||||
size_t size, written = 0;
|
||||
|
||||
do {
|
||||
NS_ASSERT (!m_txBuffer.empty ());
|
||||
Ptr<Packet> &p = m_txBuffer.front ();
|
||||
size = p->GetSize ();
|
||||
NS_ASSERT (size > 0);
|
||||
@@ -635,12 +633,6 @@ bool NscTcpSocketImpl::SendPendingData (void)
|
||||
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;
|
||||
|
||||
@@ -81,6 +81,7 @@ public:
|
||||
virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags);
|
||||
virtual Ptr<Packet> RecvFrom (uint32_t maxSize, uint32_t flags,
|
||||
Address &fromAddress);
|
||||
virtual int GetSockName (Address &address) const;
|
||||
|
||||
private:
|
||||
void NSCWakeup(void);
|
||||
|
||||
@@ -62,6 +62,8 @@ TcpSocketImpl::GetTypeId ()
|
||||
m_endPoint (0),
|
||||
m_node (0),
|
||||
m_tcp (0),
|
||||
m_localAddress (Ipv4Address::GetZero ()),
|
||||
m_localPort (0),
|
||||
m_errno (ERROR_NOTERROR),
|
||||
m_shutdownSend (false),
|
||||
m_shutdownRecv (false),
|
||||
@@ -553,6 +555,14 @@ TcpSocketImpl::RecvFrom (uint32_t maxSize, uint32_t flags,
|
||||
return packet;
|
||||
}
|
||||
|
||||
int
|
||||
TcpSocketImpl::GetSockName (Address &address) const
|
||||
{
|
||||
NS_LOG_FUNCTION_NOARGS ();
|
||||
address = InetSocketAddress(m_localAddress, m_localPort);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
TcpSocketImpl::ForwardUp (Ptr<Packet> packet, Ipv4Address ipv4, uint16_t port)
|
||||
{
|
||||
|
||||
@@ -94,6 +94,7 @@ public:
|
||||
virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags);
|
||||
virtual Ptr<Packet> RecvFrom (uint32_t maxSize, uint32_t flags,
|
||||
Address &fromAddress);
|
||||
virtual int GetSockName (Address &address) const;
|
||||
|
||||
private:
|
||||
friend class Tcp;
|
||||
|
||||
@@ -437,6 +437,21 @@ UdpSocketImpl::RecvFrom (uint32_t maxSize, uint32_t flags,
|
||||
return packet;
|
||||
}
|
||||
|
||||
int
|
||||
UdpSocketImpl::GetSockName (Address &address) const
|
||||
{
|
||||
NS_LOG_FUNCTION_NOARGS ();
|
||||
if (m_endPoint != 0)
|
||||
{
|
||||
address = InetSocketAddress (m_endPoint->GetLocalAddress (), m_endPoint->GetLocalPort());
|
||||
}
|
||||
else
|
||||
{
|
||||
address = InetSocketAddress(Ipv4Address::GetZero(), 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
UdpSocketImpl::ForwardUp (Ptr<Packet> packet, Ipv4Address ipv4, uint16_t port)
|
||||
{
|
||||
|
||||
@@ -73,6 +73,7 @@ public:
|
||||
virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags);
|
||||
virtual Ptr<Packet> RecvFrom (uint32_t maxSize, uint32_t flags,
|
||||
Address &fromAddress);
|
||||
virtual int GetSockName (Address &address) const;
|
||||
|
||||
private:
|
||||
// Attributes set through UdpSocket base class
|
||||
|
||||
@@ -76,8 +76,9 @@ RandomDirection2dMobilityModel::Start (void)
|
||||
void
|
||||
RandomDirection2dMobilityModel::BeginPause (void)
|
||||
{
|
||||
Time pause = Seconds (m_pause.GetValue ());
|
||||
m_helper.Update ();
|
||||
m_helper.Pause ();
|
||||
Time pause = Seconds (m_pause.GetValue ());
|
||||
m_event = Simulator::Schedule (pause, &RandomDirection2dMobilityModel::ResetDirectionAndSpeed, this);
|
||||
NotifyCourseChange ();
|
||||
}
|
||||
@@ -86,12 +87,14 @@ void
|
||||
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 @@ RandomDirection2dMobilityModel::ResetDirectionAndSpeed (void)
|
||||
{
|
||||
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 @@ RandomDirection2dMobilityModel::ResetDirectionAndSpeed (void)
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -80,12 +80,14 @@ RandomWalk2dMobilityModel::RandomWalk2dMobilityModel ()
|
||||
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 @@ RandomWalk2dMobilityModel::DoWalk (Time delayLeft)
|
||||
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 @@ RandomWalk2dMobilityModel::Rebound (Time delayLeft)
|
||||
speed.y = - speed.y;
|
||||
break;
|
||||
}
|
||||
m_helper.Reset (speed);
|
||||
m_helper.SetVelocity (speed);
|
||||
m_helper.Unpause ();
|
||||
DoWalk (delayLeft);
|
||||
}
|
||||
|
||||
@@ -150,13 +154,14 @@ RandomWalk2dMobilityModel::DoDispose (void)
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -62,6 +62,7 @@ RandomWaypointMobilityModel::RandomWaypointMobilityModel ()
|
||||
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 @@ RandomWaypointMobilityModel::BeginWalk (void)
|
||||
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 @@ RandomWaypointMobilityModel::BeginWalk (void)
|
||||
void
|
||||
RandomWaypointMobilityModel::Start (void)
|
||||
{
|
||||
Time pause = Seconds (m_pause.GetValue ());
|
||||
m_helper.Update ();
|
||||
m_helper.Pause ();
|
||||
NotifyCourseChange ();
|
||||
Time pause = Seconds (m_pause.GetValue ());
|
||||
m_event = Simulator::Schedule (pause, &RandomWaypointMobilityModel::BeginWalk, this);
|
||||
NotifyCourseChange ();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -29,67 +29,56 @@ StaticSpeedHelper::StaticSpeedHelper (const Vector &position)
|
||||
: 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 @@ StaticSpeedHelper::UpdateFull (const Rectangle &bounds) const
|
||||
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
|
||||
|
||||
@@ -33,23 +33,21 @@ class StaticSpeedHelper
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
@@ -39,9 +39,11 @@ StaticSpeedMobilityModel::~StaticSpeedMobilityModel ()
|
||||
{}
|
||||
|
||||
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 @@ StaticSpeedMobilityModel::SetSpeed (const Vector &speed)
|
||||
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
|
||||
|
||||
@@ -49,7 +49,7 @@ public:
|
||||
* 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);
|
||||
|
||||
@@ -57,6 +57,8 @@ PacketSocket::PacketSocket () : m_rxAvailable (0)
|
||||
m_shutdownSend = false;
|
||||
m_shutdownRecv = false;
|
||||
m_errno = ERROR_NOTERROR;
|
||||
m_isSingleDevice = false;
|
||||
m_device = 0;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -429,4 +431,27 @@ PacketSocket::RecvFrom (uint32_t maxSize, uint32_t flags, Address &fromAddress)
|
||||
return packet;
|
||||
}
|
||||
|
||||
int
|
||||
PacketSocket::GetSockName (Address &address) const
|
||||
{
|
||||
NS_LOG_FUNCTION_NOARGS ();
|
||||
PacketSocketAddress ad = PacketSocketAddress::ConvertFrom(address);
|
||||
|
||||
ad.SetProtocol (m_protocol);
|
||||
if (m_isSingleDevice)
|
||||
{
|
||||
Ptr<NetDevice> device = m_node->GetDevice (ad.GetSingleDevice ());
|
||||
ad.SetPhysicalAddress(device->GetAddress());
|
||||
ad.SetSingleDevice (m_device);
|
||||
}
|
||||
else
|
||||
{
|
||||
ad.SetPhysicalAddress(Address());
|
||||
ad.SetAllDevices ();
|
||||
}
|
||||
address = ad;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}//namespace ns3
|
||||
|
||||
@@ -101,6 +101,7 @@ public:
|
||||
virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags);
|
||||
virtual Ptr<Packet> RecvFrom (uint32_t maxSize, uint32_t flags,
|
||||
Address &fromAddress);
|
||||
virtual int GetSockName (Address &address) const;
|
||||
|
||||
private:
|
||||
void ForwardUp (Ptr<NetDevice> device, Ptr<const Packet> packet,
|
||||
|
||||
@@ -487,6 +487,10 @@ public:
|
||||
*/
|
||||
int RecvFrom (uint8_t* buf, uint32_t size, uint32_t flags,
|
||||
Address &fromAddress);
|
||||
/**
|
||||
* \returns the address name this socket is associated with.
|
||||
*/
|
||||
virtual int GetSockName (Address &address) const = 0;
|
||||
|
||||
protected:
|
||||
void NotifyConnectionSucceeded (void);
|
||||
|
||||
Reference in New Issue
Block a user