A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lorawan-mac-helper.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 University of Padova
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Davide Magrin <magrinda@dei.unipd.it>
18 */
19
20#ifndef LORAWAN_MAC_HELPER_H
21#define LORAWAN_MAC_HELPER_H
22
23#include "ns3/class-a-end-device-lorawan-mac.h"
24#include "ns3/gateway-lorawan-mac.h"
25#include "ns3/lora-channel.h"
26#include "ns3/lora-device-address-generator.h"
27#include "ns3/lora-phy.h"
28#include "ns3/lorawan-mac.h"
29#include "ns3/net-device.h"
30#include "ns3/node-container.h"
31#include "ns3/random-variable-stream.h"
32
33namespace ns3
34{
35namespace lorawan
36{
37
38/**
39 * \ingroup lorawan
40 *
41 * Helper class for configuring and installing the LorawanMac class on devices and gateways. The
42 * user must set all parameters before calling Install on nodes.
43 */
45{
46 public:
47 /**
48 * Define the kind of device. Can be either GW (Gateway) or ED (End Device).
49 */
51 {
53 ED_A
54 };
55
56 /**
57 * Define the operational region.
58 */
60 {
70 ALOHA
71 };
72
73 LorawanMacHelper(); //!< Default constructor
74
75 /**
76 * Set an attribute of the underlying MAC object.
77 *
78 * \param name The name of the attribute to set.
79 * \param v The value of the attribute.
80 */
81 void Set(std::string name, const AttributeValue& v);
82
83 /**
84 * Set the address generator to use for creation of these nodes.
85 *
86 * \param addrGen Pointer to the address generator object.
87 */
89
90 /**
91 * Set the kind of MAC this helper will create.
92 *
93 * \param dt The device type (either gateway or end device).
94 */
95 void SetDeviceType(enum DeviceType dt);
96
97 /**
98 * Set the region in which the device is to operate.
99 *
100 * \param region The region enum value.
101 */
102 void SetRegion(enum Regions region);
103
104 /**
105 * Create the LorawanMac instance and connect it to a device.
106 *
107 * \param node The node on which we wish to create a wifi MAC.
108 * \param device The device within which this MAC will be created.
109 * \return A newly-created LorawanMac object.
110 */
112
113 /**
114 * Initialize the end devices' data rate parameter.
115 *
116 * The Data Rate (DR) of each device is set to the maximum possible for its transmissions to be
117 * correctly received by the gateway measuring the best RSSI from the device, mimicking the DR
118 * maximization part of the default online LoRaWAN Adaptive Data Rate (ADR) algorithm. Please
119 * note that a single RSSI measurement between each device and gateway pair is taken for the DR
120 * assignment, so the assignment may be suboptimal in scenarios with a time-varying channel.
121 *
122 * This function uses the following convention (EU868) to compute the transmission range:
123 *
124 * DR5 -> SF7 \n
125 * DR4 -> SF8 \n
126 * DR3 -> SF9 \n
127 * DR2 -> SF10 \n
128 * DR1 -> SF11 \n
129 * DR0 -> SF12 \n
130 *
131 *
132 * It returns a DR distribution vector with the following counters:
133 *
134 * v[0] -> number of devices using DR5 \n
135 * v[1] -> number of devices using DR4 \n
136 * v[2] -> number of devices using DR3 \n
137 * v[3] -> number of devices using DR2 \n
138 * v[4] -> number of devices using DR1 \n
139 * v[5] -> number of devices using DR0, in range of at least a gateway \n
140 * v[6] -> number of devices using DR0, out of range \n
141 *
142 * \param endDevices The end devices to configure.
143 * \param gateways The gateways to consider for RSSI measurements.
144 * \param channel The radio channel to consider for RSSI measurements.
145 * \return A vector containing the final number of devices per DR.
146 */
147 static std::vector<int> SetSpreadingFactorsUp(NodeContainer endDevices,
148 NodeContainer gateways,
149 Ptr<LoraChannel> channel);
150
151 /**
152 * Randomly initialize the end devices' data rate parameter according to the given
153 * distribution.
154 *
155 * This function expects a data rate (DR) distribution vector of length 6 filled with real
156 * numbers summing up to 1. The value at index \f$i\f$ is considered to be the fraction of
157 * devices to be assigned DR \f$5-i\f$, for example:
158 *
159 * distribution[0] == 0.2 -> fraction of devices to be assigned to DR5 \n
160 * distribution[1] == 0.1 -> fraction of devices to be assigned to DR4 \n
161 * distribution[2] == 0.1 -> fraction of devices to be assigned to DR3 \n
162 * distribution[3] == 0.1 -> fraction of devices to be assigned to DR2 \n
163 * distribution[4] == 0.2 -> fraction of devices to be assigned to DR1 \n
164 * distribution[5] == 0.3 -> fraction of devices to be assigned to DR0 \n
165 *
166 *
167 * Devices are then randomly assigned a DR following the provided distribution.
168 *
169 * It returns a DR distribution vector with the following counters:
170 *
171 * v[0] -> number of devices using DR5 \n
172 * v[1] -> number of devices using DR4 \n
173 * v[2] -> number of devices using DR3 \n
174 * v[3] -> number of devices using DR2 \n
175 * v[4] -> number of devices using DR1 \n
176 * v[5] -> number of devices using DR0 \n
177 *
178 *
179 * \param endDevices The end devices to configure.
180 * \param gateways The gateways in the network (this is only a placeholder parameter).
181 * \param distribution The distribution (probability mass function) of DR assignment.
182 * \return A vector containing the final number of devices per DR.
183 *
184 * \todo Remove unused parameter gateways.
185 */
186 static std::vector<int> SetSpreadingFactorsGivenDistribution(NodeContainer endDevices,
187 NodeContainer gateways,
188 std::vector<double> distribution);
189
190 private:
191 /**
192 * Perform region-specific configurations for the 868 MHz EU band.
193 *
194 * \param edMac Pointer to the device MAC layer to configure.
195 */
197
198 /**
199 * Perform region-specific configurations for the 868 MHz EU band.
200 *
201 * \param gwMac Pointer to the gateway MAC layer to configure.
202 */
204
205 /**
206 * Apply configurations that are common both for the GatewayLorawanMac and the
207 * ClassAEndDeviceLorawanMac classes.
208 *
209 * \param lorawanMac Pointer to the MAC layer to configure.
210 */
211 void ApplyCommonEuConfigurations(Ptr<LorawanMac> lorawanMac) const;
212
213 /**
214 * Perform region-specific configurations for the SINGLECHANNEL band.
215 *
216 * \param edMac Pointer to the device MAC layer to configure.
217 */
219
220 /**
221 * Perform region-specific configurations for the SINGLECHANNEL band.
222 *
223 * \param gwMac Pointer to the gateway MAC layer to configure.
224 */
226
227 /**
228 * Apply configurations that are common both for the GatewayLorawanMac and the
229 * ClassAEndDeviceLorawanMac classes.
230 *
231 * \param lorawanMac Pointer to the MAC layer to configure.
232 */
234
235 /**
236 * Perform region-specific configurations for the ALOHA band.
237 *
238 * \param edMac Pointer to the device MAC layer to configure.
239 */
241
242 /**
243 * Perform region-specific configurations for the ALOHA band.
244 *
245 * \param gwMac Pointer to the gateway MAC layer to configure.
246 */
248
249 /**
250 * Apply configurations that are common both for the GatewayLorawanMac and the
251 * ClassAEndDeviceLorawanMac classes.
252 *
253 * \param lorawanMac Pointer to the MAC layer to configure.
254 */
255 void ApplyCommonAlohaConfigurations(Ptr<LorawanMac> lorawanMac) const;
256
257 ObjectFactory m_mac; //!< MAC-layer object factory
258 Ptr<LoraDeviceAddressGenerator> m_addrGen; //!< Pointer to the address generator to use
259 enum DeviceType m_deviceType; //!< The kind of device to install
260 enum Regions m_region; //!< The region in which the device will operate
261};
262
263} // namespace lorawan
264
265} // namespace ns3
266#endif /* LORA_PHY_HELPER_H */
Hold a value for an Attribute.
Definition: attribute.h:70
keep track of a set of node pointers.
Instantiate subclasses of ns3::Object.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Helper class for configuring and installing the LorawanMac class on devices and gateways.
void ConfigureForAlohaRegion(Ptr< ClassAEndDeviceLorawanMac > edMac) const
Perform region-specific configurations for the ALOHA band.
LorawanMacHelper()
Default constructor.
void SetDeviceType(enum DeviceType dt)
Set the kind of MAC this helper will create.
void SetAddressGenerator(Ptr< LoraDeviceAddressGenerator > addrGen)
Set the address generator to use for creation of these nodes.
static std::vector< int > SetSpreadingFactorsUp(NodeContainer endDevices, NodeContainer gateways, Ptr< LoraChannel > channel)
Initialize the end devices' data rate parameter.
void ApplyCommonEuConfigurations(Ptr< LorawanMac > lorawanMac) const
Apply configurations that are common both for the GatewayLorawanMac and the ClassAEndDeviceLorawanMac...
enum Regions m_region
The region in which the device will operate.
Regions
Define the operational region.
void SetRegion(enum Regions region)
Set the region in which the device is to operate.
void Set(std::string name, const AttributeValue &v)
Set an attribute of the underlying MAC object.
ObjectFactory m_mac
MAC-layer object factory.
Ptr< LorawanMac > Create(Ptr< Node > node, Ptr< NetDevice > device) const
Create the LorawanMac instance and connect it to a device.
static std::vector< int > SetSpreadingFactorsGivenDistribution(NodeContainer endDevices, NodeContainer gateways, std::vector< double > distribution)
Randomly initialize the end devices' data rate parameter according to the given distribution.
Ptr< LoraDeviceAddressGenerator > m_addrGen
Pointer to the address generator to use.
void ConfigureForSingleChannelRegion(Ptr< ClassAEndDeviceLorawanMac > edMac) const
Perform region-specific configurations for the SINGLECHANNEL band.
void ApplyCommonSingleChannelConfigurations(Ptr< LorawanMac > lorawanMac) const
Apply configurations that are common both for the GatewayLorawanMac and the ClassAEndDeviceLorawanMac...
DeviceType
Define the kind of device.
void ApplyCommonAlohaConfigurations(Ptr< LorawanMac > lorawanMac) const
Apply configurations that are common both for the GatewayLorawanMac and the ClassAEndDeviceLorawanMac...
enum DeviceType m_deviceType
The kind of device to install.
void ConfigureForEuRegion(Ptr< ClassAEndDeviceLorawanMac > edMac) const
Perform region-specific configurations for the 868 MHz EU band.
Every class exported by the ns3 library is enclosed in the ns3 namespace.