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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Davide Magrin <magrinda@dei.unipd.it>
7 */
8
9#ifndef LORAWAN_MAC_HELPER_H
10#define LORAWAN_MAC_HELPER_H
11
12#include "ns3/lora-channel.h"
13#include "ns3/lora-device-address-generator.h"
14#include "ns3/node-container.h"
15#include "ns3/object-factory.h"
16
17namespace ns3
18{
19namespace lorawan
20{
21
24class LorawanMac;
25
26/**
27 * @ingroup lorawan
28 *
29 * Helper class for configuring and installing the LorawanMac class on devices and gateways. The
30 * user must set all parameters before calling Install on nodes.
31 */
33{
34 public:
35 /**
36 * Define the kind of device. Can be either GW (Gateway) or ED (End Device).
37 */
39 {
42 };
43
44 /**
45 * Define the operational region.
46 */
60
61 LorawanMacHelper(); //!< Default constructor
62
63 /**
64 * Set an attribute of the underlying MAC object.
65 *
66 * @param name The name of the attribute to set.
67 * @param v The value of the attribute.
68 */
69 void Set(std::string name, const AttributeValue& v);
70
71 /**
72 * Set the address generator to use for creation of these nodes.
73 *
74 * @param addrGen Pointer to the address generator object.
75 */
77
78 /**
79 * Set the kind of MAC this helper will create.
80 *
81 * @param dt The device type (either gateway or end device).
82 */
83 void SetDeviceType(enum DeviceType dt);
84
85 /**
86 * Set the region in which the device is to operate.
87 *
88 * @param region The region enum value.
89 */
90 void SetRegion(enum Regions region);
91
92 /**
93 * Create the LorawanMac instance and connect it to a device.
94 *
95 * @param node The node on which we wish to create a wifi MAC.
96 * @param device The device within which this MAC will be created.
97 * @return A newly-created LorawanMac object.
98 */
100
101 /**
102 * Initialize the end devices' data rate parameter.
103 *
104 * The Data Rate (DR) of each device is set to the maximum possible for its transmissions to be
105 * correctly received by the gateway measuring the best RSSI from the device, mimicking the DR
106 * maximization part of the default online LoRaWAN Adaptive Data Rate (ADR) algorithm. Please
107 * note that a single RSSI measurement between each device and gateway pair is taken for the DR
108 * assignment, so the assignment may be suboptimal in scenarios with a time-varying channel.
109 *
110 * This function uses the following convention (EU868) to compute the transmission range:
111 *
112 * DR5 -> SF7 \n
113 * DR4 -> SF8 \n
114 * DR3 -> SF9 \n
115 * DR2 -> SF10 \n
116 * DR1 -> SF11 \n
117 * DR0 -> SF12 \n
118 *
119 *
120 * It returns a DR distribution vector with the following counters:
121 *
122 * v[0] -> number of devices using DR5 \n
123 * v[1] -> number of devices using DR4 \n
124 * v[2] -> number of devices using DR3 \n
125 * v[3] -> number of devices using DR2 \n
126 * v[4] -> number of devices using DR1 \n
127 * v[5] -> number of devices using DR0, in range of at least a gateway \n
128 * v[6] -> number of devices using DR0, out of range \n
129 *
130 * @param endDevices The end devices to configure.
131 * @param gateways The gateways to consider for RSSI measurements.
132 * @param channel The radio channel to consider for RSSI measurements.
133 * @return A vector containing the final number of devices per DR.
134 */
135 static std::vector<int> SetSpreadingFactorsUp(NodeContainer endDevices,
136 NodeContainer gateways,
137 Ptr<LoraChannel> channel);
138
139 /**
140 * Randomly initialize the end devices' data rate parameter according to the given
141 * distribution.
142 *
143 * This function expects a data rate (DR) distribution vector of length 6 filled with real
144 * numbers summing up to 1. The value at index \f$i\f$ is considered to be the fraction of
145 * devices to be assigned DR \f$5-i\f$, for example:
146 *
147 * distribution[0] == 0.2 -> fraction of devices to be assigned to DR5 \n
148 * distribution[1] == 0.1 -> fraction of devices to be assigned to DR4 \n
149 * distribution[2] == 0.1 -> fraction of devices to be assigned to DR3 \n
150 * distribution[3] == 0.1 -> fraction of devices to be assigned to DR2 \n
151 * distribution[4] == 0.2 -> fraction of devices to be assigned to DR1 \n
152 * distribution[5] == 0.3 -> fraction of devices to be assigned to DR0 \n
153 *
154 *
155 * Devices are then randomly assigned a DR following the provided distribution.
156 *
157 * It returns a DR distribution vector with the following counters:
158 *
159 * v[0] -> number of devices using DR5 \n
160 * v[1] -> number of devices using DR4 \n
161 * v[2] -> number of devices using DR3 \n
162 * v[3] -> number of devices using DR2 \n
163 * v[4] -> number of devices using DR1 \n
164 * v[5] -> number of devices using DR0 \n
165 *
166 *
167 * @param endDevices The end devices to configure.
168 * @param gateways The gateways in the network (this is only a placeholder parameter).
169 * @param distribution The distribution (probability mass function) of DR assignment.
170 * @return A vector containing the final number of devices per DR.
171 *
172 * @todo Remove unused parameter gateways.
173 */
174 static std::vector<int> SetSpreadingFactorsGivenDistribution(NodeContainer endDevices,
175 NodeContainer gateways,
176 std::vector<double> distribution);
177
178 private:
179 /**
180 * Perform region-specific configurations for the 868 MHz EU band.
181 *
182 * @param edMac Pointer to the device MAC layer to configure.
183 */
185
186 /**
187 * Perform region-specific configurations for the 868 MHz EU band.
188 *
189 * @param gwMac Pointer to the gateway MAC layer to configure.
190 */
192
193 /**
194 * Apply configurations that are common both for the GatewayLorawanMac and the
195 * ClassAEndDeviceLorawanMac classes.
196 *
197 * @param lorawanMac Pointer to the MAC layer to configure.
198 */
199 void ApplyCommonEuConfigurations(Ptr<LorawanMac> lorawanMac) const;
200
201 /**
202 * Perform region-specific configurations for the SINGLECHANNEL band.
203 *
204 * @param edMac Pointer to the device MAC layer to configure.
205 */
207
208 /**
209 * Perform region-specific configurations for the SINGLECHANNEL band.
210 *
211 * @param gwMac Pointer to the gateway MAC layer to configure.
212 */
214
215 /**
216 * Apply configurations that are common both for the GatewayLorawanMac and the
217 * ClassAEndDeviceLorawanMac classes.
218 *
219 * @param lorawanMac Pointer to the MAC layer to configure.
220 */
222
223 /**
224 * Perform region-specific configurations for the ALOHA band.
225 *
226 * @param edMac Pointer to the device MAC layer to configure.
227 */
229
230 /**
231 * Perform region-specific configurations for the ALOHA band.
232 *
233 * @param gwMac Pointer to the gateway MAC layer to configure.
234 */
236
237 /**
238 * Apply configurations that are common both for the GatewayLorawanMac and the
239 * ClassAEndDeviceLorawanMac classes.
240 *
241 * @param lorawanMac Pointer to the MAC layer to configure.
242 */
243 void ApplyCommonAlohaConfigurations(Ptr<LorawanMac> lorawanMac) const;
244
245 ObjectFactory m_mac; //!< MAC-layer object factory
246 Ptr<LoraDeviceAddressGenerator> m_addrGen; //!< Pointer to the address generator to use
247 enum DeviceType m_deviceType; //!< The kind of device to install
248 enum Regions m_region; //!< The region in which the device will operate
249};
250
251} // namespace lorawan
252} // namespace ns3
253
254#endif /* LORA_PHY_HELPER_H */
uint32_t v
Hold a value for an Attribute.
Definition attribute.h:59
keep track of a set of node pointers.
Instantiate subclasses of ns3::Object.
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
Class representing the MAC layer of a Class A LoRaWAN device.
Class representing the MAC layer of a LoRaWAN gateway.
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.
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...
Ptr< LorawanMac > Install(Ptr< Node > node, Ptr< NetDevice > device) const
Create the LorawanMac instance and connect it to a device.
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.
Class representing the LoRaWAN MAC layer.
Definition lorawan-mac.h:36
Every class exported by the ns3 library is enclosed in the ns3 namespace.