20 #include "ns3/mobility-helper.h" 21 #include "ns3/mobility-model.h" 22 #include "ns3/position-allocator.h" 23 #include "ns3/hierarchical-mobility-model.h" 25 #include "ns3/pointer.h" 26 #include "ns3/config.h" 27 #include "ns3/simulator.h" 28 #include "ns3/names.h" 29 #include "ns3/string.h" 38 m_position = CreateObjectWithAttributes<RandomRectanglePositionAllocator>
39 (
"X",
StringValue (
"ns3::ConstantRandomVariable[Constant=0.0]"),
40 "Y",
StringValue (
"ns3::ConstantRandomVariable[Constant=0.0]"));
139 NS_FATAL_ERROR (
"The requested mobility model is not a mobility model: \""<<
145 object->AggregateObject (model);
152 CreateObjectWithAttributes<HierarchicalMobilityModel> (
"Child",
PointerValue (model),
165 Ptr<Node> node = Names::Find<Node> (nodeName);
191 if (v <= 1e-4 && v >= -1e-4)
195 else if (v <= 1e-3 && v >= 0)
199 else if (v >= -1e-3 && v <= 0)
214 <<
" node=" << node->
GetId ();
215 Vector pos =
mobility->GetPosition ();
219 Vector vel =
mobility->GetVelocity ();
223 std::streamsize saved_precision = os->precision ();
224 std::ios::fmtflags saved_flags = os->flags ();
226 os->setf (std::ios::fixed,std::ios::floatfield);
227 *os <<
" pos=" << pos.x <<
":" << pos.y <<
":" << pos.z
228 <<
" vel=" << vel.x <<
":" << vel.y <<
":" << vel.z
230 os->flags (saved_flags);
231 os->precision (saved_precision);
237 std::ostringstream oss;
238 oss <<
"/NodeList/" << nodeid <<
"/$ns3::MobilityModel/CourseChange";
258 int64_t currentStream = stream;
267 currentStream +=
mobility->AssignStreams (currentStream);
270 return (currentStream - stream);
285 double dist = rxPosition -> GetDistanceFrom (txPosition);
286 distSq = dist * dist;
void InstallAll(void)
Perform the work of MobilityHelper::Install on all nodes which exist in the simulation.
std::string GetName(void) const
Get the name.
Smart pointer class similar to boost::intrusive_ptr.
uint32_t GetId(void) const
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Hold variables of type string.
static double GetDistanceSquaredBetween(Ptr< Node > n1, Ptr< Node > n2)
Hold a value for an Attribute.
Callback< R > MakeBoundCallback(R(*fnPtr)(TX), ARG a1)
Make Callbacks with one bound argument.
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
~MobilityHelper()
Destroy a Mobility Helper.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
int64_t AssignStreams(NodeContainer c, int64_t stream)
Assign a fixed random variable stream number to the random variables used by the mobility models (inc...
void PushReferenceMobilityModel(Ptr< Object > reference)
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
Ptr< PositionAllocator > m_position
Position allocator for use in hierarchical mobility model.
Keep track of the current position and velocity of an object.
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...
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
static void CourseChanged(Ptr< OutputStreamWrapper > stream, Ptr< const MobilityModel > mobility)
Output course change events from mobility model to output stream.
static void EnableAscii(Ptr< OutputStreamWrapper > stream, uint32_t nodeid)
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
bool ConnectWithoutContextFailSafe(std::string path, const CallbackBase &cb)
This function will attempt to find all trace sources which match the input path and will then connect...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ObjectFactory m_mobility
Object factory to create mobility objects.
keep track of a set of node pointers.
Hold objects of type Ptr<T>.
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 reference
reference tag
std::string GetMobilityModelType(void) const
static Time Now(void)
Return the current simulation virtual time.
void SetPosition(const Vector &position)
TypeId GetTypeId(void) const
Get the TypeId which will be created by this ObjectFactory.
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
static NodeContainer GetGlobal(void)
Create a NodeContainer that contains a list of all nodes created through NodeContainer::Create() and ...
std::vector< Ptr< MobilityModel > > m_mobilityStack
Internal stack of mobility models.
Instantiate subclasses of ns3::Object.
MobilityHelper()
Construct a Mobility Helper which is used to make life easier when working with mobility models...
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
static void EnableAsciiAll(Ptr< OutputStreamWrapper > stream)
void PopReferenceMobilityModel(void)
Remove the top item from the top of the stack of "reference mobility models".
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
std::ostream * GetStream(void)
Return a pointer to an ostream previously set in the wrapper.
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
Allocate a set of positions.