19#include "ns3/mobility-helper.h"
21#include "ns3/config.h"
22#include "ns3/hierarchical-mobility-model.h"
24#include "ns3/mobility-model.h"
26#include "ns3/pointer.h"
27#include "ns3/position-allocator.h"
28#include "ns3/simulator.h"
29#include "ns3/string.h"
40 m_position = CreateObjectWithAttributes<RandomRectanglePositionAllocator>(
42 StringValue(
"ns3::ConstantRandomVariable[Constant=0.0]"),
44 StringValue(
"ns3::ConstantRandomVariable[Constant=0.0]"));
94 NS_FATAL_ERROR(
"The requested mobility model is not a mobility model: \""
100 object->AggregateObject(model);
107 CreateObjectWithAttributes<HierarchicalMobilityModel>(
"Child",
111 object->AggregateObject(hierarchical);
112 NS_LOG_DEBUG(
"node=" <<
object <<
", mob=" << hierarchical);
116 model->SetPosition(position);
122 Ptr<Node> node = Names::Find<Node>(nodeName);
150 if (v <= 1e-4 && v >= -1e-4)
154 else if (v <= 1e-3 && v >= 0)
158 else if (v >= -1e-3 && v <= 0)
171 std::ostream* os = stream->GetStream();
172 Vector pos = mobility->GetPosition();
173 Vector vel = mobility->GetVelocity();
174 *os <<
"now=" <<
Simulator::Now() <<
" node=" << mobility->GetObject<
Node>()->GetId();
181 std::streamsize saved_precision = os->precision();
182 std::ios::fmtflags saved_flags = os->flags();
184 os->setf(std::ios::fixed, std::ios::floatfield);
185 *os <<
" pos=" << pos.x <<
":" << pos.y <<
":" << pos.z <<
" vel=" << vel.x <<
":" << vel.y
186 <<
":" << vel.z << std::endl;
187 os->flags(saved_flags);
188 os->precision(saved_precision);
194 std::ostringstream oss;
195 oss <<
"/NodeList/" << nodeid <<
"/$ns3::MobilityModel/CourseChange";
219 int64_t currentStream = stream;
228 currentStream += mobility->AssignStreams(currentStream);
231 return (currentStream - stream);
246 double dist = rxPosition->GetDistanceFrom(txPosition);
247 distSq = dist * dist;
void PopReferenceMobilityModel()
Remove the top item from the top of the stack of "reference mobility models".
int64_t AssignStreams(NodeContainer c, int64_t stream)
Assign a fixed random variable stream number to the random variables used by the mobility models on t...
static void EnableAsciiAll(Ptr< OutputStreamWrapper > stream)
static double GetDistanceSquaredBetween(Ptr< Node > n1, Ptr< Node > n2)
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
ObjectFactory m_mobility
Object factory to create mobility objects.
static void CourseChanged(Ptr< OutputStreamWrapper > stream, Ptr< const MobilityModel > mobility)
Output course change events from mobility model to output stream.
std::string GetMobilityModelType() const
~MobilityHelper()
Destroy a Mobility Helper.
Ptr< PositionAllocator > m_position
Position allocator for use in hierarchical mobility model.
void PushReferenceMobilityModel(Ptr< Object > reference)
void InstallAll() const
Perform the work of MobilityHelper::Install on all nodes which exist in the simulation.
MobilityHelper()
Construct a Mobility Helper which is used to make life easier when working with mobility models.
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
static void EnableAscii(Ptr< OutputStreamWrapper > stream, uint32_t nodeid)
std::vector< Ptr< MobilityModel > > m_mobilityStack
Internal stack of mobility models.
Keep track of the current position and velocity of an object.
keep track of a set of node pointers.
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Iterator End() const
Get an iterator which indicates past-the-last Node in the container.
static NodeContainer GetGlobal()
Create a NodeContainer that contains a list of all nodes created through NodeContainer::Create() and ...
Iterator Begin() const
Get an iterator which refers to the first Node in the container.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
TypeId GetTypeId() const
Get the TypeId which will be created by this ObjectFactory.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Hold objects of type Ptr<T>.
Smart pointer class similar to boost::intrusive_ptr.
static Time Now()
Return the current simulation virtual time.
Hold variables of type string.
std::string GetName() const
Get the name.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
bool ConnectWithoutContextFailSafe(std::string path, const CallbackBase &cb)
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
auto MakeBoundCallback(R(*fnPtr)(Args...), BArgs &&... bargs)
Make Callbacks with varying number of bound arguments.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static double DoRound(double v)
Utility function that rounds |1e-4| < input value < |1e-3| up to +/- 1e-3 and value <= |1e-4| to zero...