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 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19 * Adapted from 'mobility-helper.h' for group mobility by Tom Henderson
20 */
21
22#ifndef GROUP_MOBILITY_HELPER_H
23#define GROUP_MOBILITY_HELPER_H
24
25#include "ns3/attribute.h"
26#include "ns3/node-container.h"
27#include "ns3/object-factory.h"
28
29#include <vector>
30
31namespace ns3
32{
33
34class PositionAllocator;
35class MobilityModel;
36
37/**
38 * \ingroup mobility
39 * \brief Helper class used to assign positions and mobility models to nodes
40 * for a group mobility configuration.
41 *
42 * This helper can be used for group mobility configuration and installation
43 * onto a group of nodes, in which there is a reference (parent) mobility
44 * model that is the same for all nodes, and similarly configured (but
45 * distinct) child mobility models.
46 */
48{
49 public:
50 /**
51 * Construct a group mobility helper
52 */
54
55 /**
56 * Destroy a group mobility helper
57 */
59
60 /**
61 * Set the position allocator which will be used to allocate the initial
62 * position of the reference mobility model.
63 *
64 * \param allocator allocate initial reference mobility model position
65 */
67
68 /**
69 * Configure the position allocator which will be used to allocate
70 * the initial position of the reference mobility model.
71 *
72 * \tparam Ts \deduced Argument types
73 * \param type the type of position allocator to use.
74 * \param [in] args Name and AttributeValue pairs to set.
75 */
76 template <typename... Ts>
77 void SetReferencePositionAllocator(std::string type, Ts&&... args);
78
79 /**
80 * Set the position allocator which will be used to allocate the initial
81 * position of the member mobility models.
82 *
83 * \param allocator allocate initial member mobility model positions
84 */
86
87 /**
88 * Configure the position allocator which will be used to allocate the
89 * initial position of the member mobility models.
90 *
91 * \tparam Ts \deduced Argument types
92 * \param type the type of position allocator to use.
93 * \param [in] args Name and AttributeValue pairs to set.
94 */
95 template <typename... Ts>
96 void SetMemberPositionAllocator(std::string type, Ts&&... args);
97
98 /**
99 * Set the reference mobility model which will be installed as the parent
100 * mobility model during GroupMobilityModel::Install.
101 *
102 * \param mobility reference mobility model
103 */
105
106 /**
107 * Configure the reference mobility model which will be installed as the
108 * parent mobility model during GroupMobilityModel::Install.
109 *
110 * \tparam Ts \deduced Argument types
111 * \param type the type of mobility model to use.
112 * \param [in] args Name and AttributeValue pairs to set.
113 */
114 template <typename... Ts>
115 void SetReferenceMobilityModel(std::string type, Ts&&... args);
116
117 /**
118 * Configure the mobility model which will be installed as the
119 * member (child) mobility model during GroupMobilityModel::Install.
120 *
121 * Calls to MobilityHelper::Install will create an instance of a matching
122 * mobility model for each node.
123 *
124 * \tparam Ts \deduced Argument types
125 * \param type the type of mobility model to use.
126 * \param [in] args Name and AttributeValue pairs to set.
127 */
128 template <typename... Ts>
129 void SetMemberMobilityModel(std::string type, Ts&&... args);
130
131 /**
132 * \brief Install and configure a hierarchical mobility model to the
133 * given node, based on the configured reference and member models.
134 *
135 * If position allocators are configured, they will be invoked to
136 * set the initial position.
137 *
138 * \param node The node to configure
139 */
140 void Install(Ptr<Node> node);
141 /**
142 * \brief Install and configure a hierarchical mobility model to the
143 * given node, based on the configured reference and member models.
144 *
145 * If position allocators are configured, they will be invoked to
146 * set the initial position.
147 *
148 * \param nodeName The name of the node to configure
149 */
150 void Install(std::string nodeName);
151
152 /**
153 * \brief Install and configure a hierarchical mobility model to all nodes
154 * in the container, based on the configured reference and member models.
155 *
156 * If position allocators are configured, they will be invoked to
157 * set the initial positions.
158 *
159 * \param container The set of nodes to configure
160 */
161 void Install(NodeContainer container);
162
163 /**
164 * Assign a fixed random variable stream number to the random variables
165 * used by the mobility models on these nodes. Return the number of
166 * streams (possibly zero) that have been assigned. The Install()
167 * method should have previously been called by the user.
168 *
169 * \note If the PositionAllocator used contains random variables, they
170 * will not be affected by this call to AssignStreams because they are
171 * used earlier during Install() time. If the user needs to assign a fixed
172 * stream number to a PositionAllocator used with this helper, the user
173 * should instantiate it outside of the helper, call AssignStreams() on
174 * it, and then pass the pointer of it to this helper.
175 *
176 * \param c NodeContainer of the set of nodes containing the MobilityModels
177 * that should be modified to use a fixed stream
178 * \param stream first stream index to use
179 * \return the number of stream indices assigned by this helper
180 */
181 int64_t AssignStreams(NodeContainer c, int64_t stream);
182
183 private:
184 // Enable logging from template instantiations
185 NS_LOG_TEMPLATE_DECLARE; //!< the log component
186
188 false}; //!< flag for avoiding multiple SetPosition calls on the reference model
189 Ptr<MobilityModel> m_referenceMobility; //!< Reference mobility model
191 m_referencePosition; //!< Position allocator for use as reference position allocator
192 ObjectFactory m_memberMobilityFactory; //!< Object factory to create member mobility models
194 m_memberPosition; //!< Position allocator for use as member position allocator
195};
196
197/***************************************************************
198 * Implementation of the templates declared above.
199 ***************************************************************/
200
201template <typename... Ts>
202void
204{
205 ObjectFactory pos(type, std::forward<Ts>(args)...);
207 NS_ABORT_MSG_IF(!m_referencePosition, "Unable to create allocator from TypeId " << type);
208}
209
210template <typename... Ts>
211void
213{
214 ObjectFactory pos(type, std::forward<Ts>(args)...);
216 NS_ABORT_MSG_IF(!m_memberPosition, "Unable to create allocator from TypeId " << type);
217}
218
219template <typename... Ts>
220void
222{
223 NS_LOG_FUNCTION(this << type);
224 ObjectFactory mob(type, std::forward<Ts>(args)...);
226 NS_ABORT_MSG_IF(!m_referenceMobility, "Unable to create mobility from TypeId " << type);
227}
228
229template <typename... Ts>
230void
231GroupMobilityHelper::SetMemberMobilityModel(std::string type, Ts&&... args)
232{
233 NS_LOG_FUNCTION(this << type);
235 m_memberMobilityFactory.Set(std::forward<Ts>(args)...);
236}
237
238} // namespace ns3
239
240#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:522
Allocate a set of positions.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
#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.