A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
group-mobility-helper.h
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.h' for group mobility by Tom Henderson
9 */
10
11#ifndef GROUP_MOBILITY_HELPER_H
12#define GROUP_MOBILITY_HELPER_H
13
14#include "ns3/attribute.h"
15#include "ns3/node-container.h"
16#include "ns3/object-factory.h"
17
18#include <vector>
19
20namespace ns3
21{
22
23class PositionAllocator;
24class MobilityModel;
25
26/**
27 * \ingroup mobility
28 * \brief Helper class used to assign positions and mobility models to nodes
29 * for a group mobility configuration.
30 *
31 * This helper can be used for group mobility configuration and installation
32 * onto a group of nodes, in which there is a reference (parent) mobility
33 * model that is the same for all nodes, and similarly configured (but
34 * distinct) child mobility models.
35 */
37{
38 public:
39 /**
40 * Construct a group mobility helper
41 */
43
44 /**
45 * Destroy a group mobility helper
46 */
48
49 /**
50 * Set the position allocator which will be used to allocate the initial
51 * position of the reference mobility model.
52 *
53 * \param allocator allocate initial reference mobility model position
54 */
56
57 /**
58 * Configure the position allocator which will be used to allocate
59 * the initial position of the reference mobility model.
60 *
61 * \tparam Ts \deduced Argument types
62 * \param type the type of position allocator to use.
63 * \param [in] args Name and AttributeValue pairs to set.
64 */
65 template <typename... Ts>
66 void SetReferencePositionAllocator(std::string type, Ts&&... args);
67
68 /**
69 * Set the position allocator which will be used to allocate the initial
70 * position of the member mobility models.
71 *
72 * \param allocator allocate initial member mobility model positions
73 */
75
76 /**
77 * Configure the position allocator which will be used to allocate the
78 * initial position of the member mobility models.
79 *
80 * \tparam Ts \deduced Argument types
81 * \param type the type of position allocator to use.
82 * \param [in] args Name and AttributeValue pairs to set.
83 */
84 template <typename... Ts>
85 void SetMemberPositionAllocator(std::string type, Ts&&... args);
86
87 /**
88 * Set the reference mobility model which will be installed as the parent
89 * mobility model during GroupMobilityModel::Install.
90 *
91 * \param mobility reference mobility model
92 */
94
95 /**
96 * Configure the reference mobility model which will be installed as the
97 * parent mobility model during GroupMobilityModel::Install.
98 *
99 * \tparam Ts \deduced Argument types
100 * \param type the type of mobility model to use.
101 * \param [in] args Name and AttributeValue pairs to set.
102 */
103 template <typename... Ts>
104 void SetReferenceMobilityModel(std::string type, Ts&&... args);
105
106 /**
107 * Configure the mobility model which will be installed as the
108 * member (child) mobility model during GroupMobilityModel::Install.
109 *
110 * Calls to MobilityHelper::Install will create an instance of a matching
111 * mobility model for each node.
112 *
113 * \tparam Ts \deduced Argument types
114 * \param type the type of mobility model to use.
115 * \param [in] args Name and AttributeValue pairs to set.
116 */
117 template <typename... Ts>
118 void SetMemberMobilityModel(std::string type, Ts&&... args);
119
120 /**
121 * \brief Install and configure a hierarchical mobility model to the
122 * given node, based on the configured reference and member models.
123 *
124 * If position allocators are configured, they will be invoked to
125 * set the initial position.
126 *
127 * \param node The node to configure
128 */
129 void Install(Ptr<Node> node);
130 /**
131 * \brief Install and configure a hierarchical mobility model to the
132 * given node, based on the configured reference and member models.
133 *
134 * If position allocators are configured, they will be invoked to
135 * set the initial position.
136 *
137 * \param nodeName The name of the node to configure
138 */
139 void Install(std::string nodeName);
140
141 /**
142 * \brief Install and configure a hierarchical mobility model to all nodes
143 * in the container, based on the configured reference and member models.
144 *
145 * If position allocators are configured, they will be invoked to
146 * set the initial positions.
147 *
148 * \param container The set of nodes to configure
149 */
150 void Install(NodeContainer container);
151
152 /**
153 * Assign a fixed random variable stream number to the random variables
154 * used by the mobility models on these nodes. Return the number of
155 * streams (possibly zero) that have been assigned. The Install()
156 * method should have previously been called by the user.
157 *
158 * \note If the PositionAllocator used contains random variables, they
159 * will not be affected by this call to AssignStreams because they are
160 * used earlier during Install() time. If the user needs to assign a fixed
161 * stream number to a PositionAllocator used with this helper, the user
162 * should instantiate it outside of the helper, call AssignStreams() on
163 * it, and then pass the pointer of it to this helper.
164 *
165 * \param c NodeContainer of the set of nodes containing the MobilityModels
166 * that should be modified to use a fixed stream
167 * \param stream first stream index to use
168 * \return the number of stream indices assigned by this helper
169 */
170 int64_t AssignStreams(NodeContainer c, int64_t stream);
171
172 private:
173 // Enable logging from template instantiations
174 NS_LOG_TEMPLATE_DECLARE; //!< the log component
175
177 false}; //!< flag for avoiding multiple SetPosition calls on the reference model
178 Ptr<MobilityModel> m_referenceMobility; //!< Reference mobility model
180 m_referencePosition; //!< Position allocator for use as reference position allocator
181 ObjectFactory m_memberMobilityFactory; //!< Object factory to create member mobility models
183 m_memberPosition; //!< Position allocator for use as member position allocator
184};
185
186/***************************************************************
187 * Implementation of the templates declared above.
188 ***************************************************************/
189
190template <typename... Ts>
191void
193{
194 ObjectFactory pos(type, std::forward<Ts>(args)...);
196 NS_ABORT_MSG_IF(!m_referencePosition, "Unable to create allocator from TypeId " << type);
197}
198
199template <typename... Ts>
200void
202{
203 ObjectFactory pos(type, std::forward<Ts>(args)...);
205 NS_ABORT_MSG_IF(!m_memberPosition, "Unable to create allocator from TypeId " << type);
206}
207
208template <typename... Ts>
209void
211{
212 NS_LOG_FUNCTION(this << type);
213 ObjectFactory mob(type, std::forward<Ts>(args)...);
215 NS_ABORT_MSG_IF(!m_referenceMobility, "Unable to create mobility from TypeId " << type);
216}
217
218template <typename... Ts>
219void
220GroupMobilityHelper::SetMemberMobilityModel(std::string type, Ts&&... args)
221{
222 NS_LOG_FUNCTION(this << type);
224 m_memberMobilityFactory.Set(std::forward<Ts>(args)...);
225}
226
227} // namespace ns3
228
229#endif /* GROUP_MOBILITY_HELPER_H */
Helper class used to assign positions and mobility models to nodes for a group mobility configuration...
void SetMemberMobilityModel(std::string type, Ts &&... args)
Configure the mobility model which will be installed as the member (child) mobility model during Grou...
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...
NS_LOG_TEMPLATE_DECLARE
the log component
Ptr< MobilityModel > m_referenceMobility
Reference mobility model.
GroupMobilityHelper()
Construct a group mobility helper.
Keep track of the current position and velocity of an object.
keep track of a set of node pointers.
Instantiate subclasses of ns3::Object.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
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.
Definition object.h:511
Allocate a set of positions.
Smart pointer class similar to boost::intrusive_ptr.
#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_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.