A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
group-mobility-helper.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 INRIA
3 * Copyright (c) 2021 University of Washington: Group mobility changes
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
8 * Adapted from 'mobility-helper.cc' for group mobility by Tom Henderson
9 */
10
12
13#include "ns3/config.h"
14#include "ns3/hierarchical-mobility-model.h"
15#include "ns3/log.h"
16#include "ns3/mobility-model.h"
17#include "ns3/names.h"
18#include "ns3/pointer.h"
19#include "ns3/position-allocator.h"
20#include "ns3/simulator.h"
21#include "ns3/string.h"
22
23#include <iostream>
24
25namespace ns3
26{
27
28NS_LOG_COMPONENT_DEFINE("GroupMobilityHelper");
29
34
38
39void
44
45void
50
51void
56
57void
59{
60 NS_ABORT_MSG_IF(node->GetObject<MobilityModel>(), "Mobility model already installed");
61 NS_ABORT_MSG_IF(!m_referenceMobility, "Reference mobility model is empty");
62 NS_ABORT_MSG_UNLESS(m_memberMobilityFactory.IsTypeIdSet(), "Member mobility factory is unset");
64 {
65 Vector referencePosition = m_referencePosition->GetNext();
66 m_referenceMobility->SetPosition(referencePosition);
68 }
70 hierarchical->SetParent(m_referenceMobility);
72 NS_ABORT_MSG_IF(!child, "Member mobility factory did not produce a MobilityModel");
74 {
75 Vector position = m_memberPosition->GetNext();
76 child->SetPosition(position);
77 }
78 hierarchical->SetChild(child);
79 NS_LOG_DEBUG("node=" << node << ", mob=" << hierarchical);
80 node->AggregateObject(hierarchical);
81}
82
83void
84GroupMobilityHelper::Install(std::string nodeName)
85{
86 Ptr<Node> node = Names::Find<Node>(nodeName);
87 Install(node);
88}
89
90void
92{
93 for (auto i = c.Begin(); i != c.End(); ++i)
94 {
95 Install(*i);
96 }
97}
98
99int64_t
101{
102 int64_t currentStream = stream;
103 Ptr<Node> node;
104 bool firstNode = true;
106 for (auto i = c.Begin(); i != c.End(); ++i)
107 {
108 node = (*i);
109 mobility = node->GetObject<HierarchicalMobilityModel>();
110 if (!mobility)
111 {
112 NS_FATAL_ERROR("Did not find a HierarchicalMobilityModel");
113 }
114 if (firstNode)
115 {
116 // Assign streams only once for the reference node
117 currentStream += mobility->GetParent()->AssignStreams(currentStream);
118 firstNode = false;
119 }
120 currentStream += mobility->GetChild()->AssignStreams(currentStream);
121 }
122 return (currentStream - stream);
123}
124
125} // namespace ns3
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...
ObjectFactory m_memberMobilityFactory
Object factory to create member mobility models.
void SetMemberPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of the member mobility...
void Install(Ptr< Node > node)
Install and configure a hierarchical mobility model to the given node, based on the configured refere...
void SetReferenceMobilityModel(Ptr< MobilityModel > mobility)
Set the reference mobility model which will be installed as the parent mobility model during GroupMob...
bool m_referencePositionSet
flag for avoiding multiple SetPosition calls on the reference model
~GroupMobilityHelper()
Destroy a group mobility helper.
Ptr< PositionAllocator > m_referencePosition
Position allocator for use as reference position allocator.
Ptr< PositionAllocator > m_memberPosition
Position allocator for use as member position allocator.
void SetReferencePositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of the reference mobil...
Ptr< MobilityModel > m_referenceMobility
Reference mobility model.
GroupMobilityHelper()
Construct a group mobility helper.
Keep track of the current position and velocity of an object.
static Ptr< T > Find(std::string path)
Given a name path string, look to see if there's an object in the system with that associated to it.
Definition names.h:443
keep track of a set of node pointers.
Iterator End() const
Get an iterator which indicates past-the-last Node in the container.
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.
bool IsTypeIdSet() const
Check if the ObjectFactory has been configured with a TypeId.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition object.h:511
Smart pointer class similar to boost::intrusive_ptr.
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
Definition abort.h:133
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition abort.h:97
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_TEMPLATE_DEFINE(name)
Initialize a reference to a Log component.
Definition log.h:225
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Every class exported by the ns3 library is enclosed in the ns3 namespace.