A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
end-device-status.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 University of Padova
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Martina Capuzzo <capuzzom@dei.unipd.it>
7 * Davide Magrin <magrinda@dei.unipd.it>
8 */
9
10#ifndef END_DEVICE_STATUS_H
11#define END_DEVICE_STATUS_H
12
13#include "lora-frame-header.h"
14#include "lorawan-mac-header.h"
15
16#include "ns3/object.h"
17#include "ns3/packet.h"
18
19#include <map>
20
21namespace ns3
22{
23namespace lorawan
24{
25
27
28/**
29 * @ingroup lorawan
30 *
31 * This class represents the network server's knowledge about an end device in
32 * the LoRaWAN network it is administering.
33 *
34 * The network server's NetworkStatus component contains a list of instances of
35 * this class, one for each device in the network. Each instance contains all
36 * the parameters and information of the end device and the packets received
37 * from it. Furthermore, this class holds the reply packet that the network
38 * server will send to this device at the first available receive window. Upon
39 * new packet arrivals at the network server, the OnReceivedPacket method is
40 * called to update the information regarding the last received packet and its
41 * parameters.
42 *
43 * Diagram of the end-device-status data structure. One instance of this class
44 * for each end device, that will be identified by its address.
45 *
46 * Public Access:
47 *
48 * (End device address) --- Current device parameters:
49 * - First Receive Window Spreading Factor (SF) and Data Rate (DR)
50 * - First Receive Window frequency [Hz]
51 * - Second Window Spreading Factor (SF) and Data Rate (DR)
52 * - Second Receive Window frequency [Hz]
53 * --- Reply
54 * - Need for reply (true/false)
55 * - Updated reply
56 * --- Received Packets
57 * - Received packets list (see below).
58 *
59 *
60 * Private Access:
61 *
62 * (Received packets list) - List of gateways that received the packet (see below)
63 * - Spreading Factor (SF) of the received packet
64 * - Frequency [Hz] of the received packet
65 * - Bandwidth [Hz] of the received packet
66 *
67 * (Gateway list) - Time at which the packet was received
68 * - Reception power
69 */
70class EndDeviceStatus : public Object
71{
72 public:
73 /********************/
74 /* Reply management */
75 /********************/
76
77 /**
78 * Structure representing the reply that the network server will send this
79 * device at the first opportunity.
80 */
81 struct Reply
82 {
83 LorawanMacHeader macHeader; //!< The MAC Header to attach to the reply packet.
84 LoraFrameHeader frameHeader; //!< The Frame Header to attach to the reply packet.
85 Ptr<Packet> payload; //!< The data packet that will be sent as a reply.
86 bool needsReply = false; //!< Whether or not this device needs a reply
87 };
88
89 /**
90 * Whether the end device needs a reply.
91 *
92 * This is determined by looking at headers and payload of the Reply
93 * structure: if they are empty, no reply should be needed.
94 *
95 * @return A boolean value signaling if the end device needs a reply.
96 */
97 bool NeedsReply() const;
98
99 /**
100 * Get the reply packet.
101 *
102 * @return A pointer to the packet reply (data + headers).
103 */
105
106 /**
107 * Get the reply packet mac header.
108 *
109 * @return The packet reply mac header.
110 */
112
113 /**
114 * Get the reply packet frame header.
115 *
116 * @return The packet reply frame header.
117 */
119
120 /**
121 * Get the data of the reply packet.
122 *
123 * @return A pointer to the packet reply.
124 */
126
127 /***********************************/
128 /* Received packet list management */
129 /***********************************/
130
131 /**
132 * Structure saving information regarding the packet reception in
133 * each gateway.
134 */
136 {
137 Address gwAddress; //!< Address of the gateway that received the packet.
138 Time receivedTime; //!< Time at which the packet was received by this gateway.
139 double rxPower; //!< Reception power of the packet at this gateway.
140 };
141
142 /**
143 * typedef of a list of gateways with relative reception information.
144 */
145 typedef std::map<Address, PacketInfoPerGw> GatewayList;
146
147 /**
148 * Structure saving information regarding all packet receptions.
149 */
151 {
152 // Members
153 Ptr<const Packet> packet = nullptr; //!< The received packet
154 GatewayList gwList; //!< List of gateways that received this packet
155 uint8_t sf; //!< Spreading factor used to send this packet
156 uint32_t frequencyHz; //!< Carrier frequency [Hz] used to send this packet
157 };
158
159 /**
160 * typedef of a list of packets paired to their reception info.
161 */
162 typedef std::list<std::pair<Ptr<const Packet>, ReceivedPacketInfo>> ReceivedPacketList;
163
164 /*******************************************/
165 /* Proper EndDeviceStatus class definition */
166 /*******************************************/
167
168 /**
169 * Register this type.
170 * @return The object TypeId.
171 */
172 static TypeId GetTypeId();
173
174 EndDeviceStatus(); //!< Default constructor
175 ~EndDeviceStatus() override; //!< Destructor
176
177 /**
178 * Constructor with initialization parameters.
179 *
180 * @param endDeviceAddress Address of the end device.
181 * @param endDeviceMac Pointer to the MAC layer of the end device.
182 */
183 EndDeviceStatus(LoraDeviceAddress endDeviceAddress,
184 Ptr<ClassAEndDeviceLorawanMac> endDeviceMac);
185
186 /**
187 * Get the spreading factor this device is using in the first receive window.
188 *
189 * @return An unsigned 8-bit integer containing the spreading factor.
190 */
192
193 /**
194 * Get the first window frequency of this device.
195 *
196 * @return The frequency [Hz].
197 */
199
200 /**
201 * Get the spreading factor this device is using in the second
202 * receive window.
203 *
204 * @return An unsigned 8-bit integer containing the spreading factor.
205 */
207
208 /**
209 * Return the second window frequency of this device.
210 *
211 * @return The frequency [Hz].
212 */
214
215 /**
216 * Get the received packet list.
217 *
218 * @return The received packet list.
219 */
221
222 /**
223 * Set the spreading factor this device is using in the first receive window.
224 *
225 * @param sf The spreading factor.
226 */
228
229 /**
230 * Set the first window frequency of this device.
231 *
232 * @param frequencyHz The frequency [Hz].
233 */
235
236 /**
237 * Set the spreading factor this device is using in the second receive window.
238 *
239 * @param sf The spreading factor.
240 */
242
243 /**
244 * Set the second window frequency of this device.
245 *
246 * @param frequencyHz The frequency [Hz].
247 */
249
250 /**
251 * Set the reply packet mac header.
252 *
253 * @param macHeader The mac header (MHDR).
254 */
255 void SetReplyMacHeader(LorawanMacHeader macHeader);
256
257 /**
258 * Set the reply packet frame header.
259 *
260 * @param frameHeader The frame header (FHDR + FPort).
261 */
262 void SetReplyFrameHeader(LoraFrameHeader frameHeader);
263
264 /**
265 * Set the packet reply payload.
266 *
267 * @param replyPayload Packet containing the FRMPayload.
268 */
269 void SetReplyPayload(Ptr<Packet> replyPayload);
270
271 /**
272 * Get the MAC layer of the end device.
273 *
274 * @return A pointer to the MAC layer.
275 */
277
278 //////////////////////
279 // Other methods //
280 //////////////////////
281
282 /**
283 * Insert a received packet in the packet list.
284 *
285 * @param receivedPacket The packet received.
286 * @param gwAddress The address of the receiver gateway.
287 */
288 void InsertReceivedPacket(Ptr<const Packet> receivedPacket, const Address& gwAddress);
289
290 /**
291 * Return the last packet that was received from this device.
292 *
293 * @return The last received packet.
294 */
296
297 /**
298 * Return the information about the last packet that was received from the
299 * device.
300 *
301 * @return The information about the last received packet.
302 */
304
305 /**
306 * Reset the next reply state.
307 */
308 void InitializeReply();
309
310 /**
311 * Add MAC command to the frame header of next reply.
312 *
313 * @param macCommand The MAC command.
314 */
315 void AddMACCommand(Ptr<MacCommand> macCommand);
316
317 /**
318 * Check if there is already a running reception window event scheduled for this end device.
319 *
320 * @return True if a reception window event is already scheduled, false otherwise.
321 */
323
324 /**
325 * Store next scheduled reception window event.
326 *
327 * @param event The event.
328 */
330
331 /**
332 * Cancel next scheduled reception window event.
333 */
335
336 /**
337 * Get the gateways which received the last packet from the end device. Gateways are mapped
338 * to their measured reception power of the last packet, in ascending order.
339 *
340 * @return The ordered map of reception power values and gateways.
341 */
342 std::map<double, Address> GetPowerGatewayMap();
343
344 struct Reply m_reply; //!< Next reply intended for this device
345 LoraDeviceAddress m_endDeviceAddress; //!< The address of this device
346
347 /**
348 * Stream insertion operator.
349 *
350 * @param os The stream.
351 * @param status The status.
352 * @return A reference to the stream.
353 */
354 friend std::ostream& operator<<(std::ostream& os, const EndDeviceStatus& status);
355
356 private:
357 // Receive window data
358 uint8_t m_firstReceiveWindowSpreadingFactor = 0; //!< Spreading Factor (SF) for RX1 window
359 uint32_t m_firstReceiveWindowFrequencyHz = 0; //!< Frequency [Hz] for RX1 window
360 uint8_t m_secondReceiveWindowSpreadingFactor = 0; //!< Spreading Factor (SF) for RX2 window.
361 uint32_t m_secondReceiveWindowFrequencyHz = 869525000; //!< Frequency [Hz] for RX2 window
362 EventId m_receiveWindowEvent; //!< Event storing the next scheduled downlink transmission
363
364 ReceivedPacketList m_receivedPacketList; //!< List of received packets
365
366 /// @note Using this attribute is 'cheating', since we are assuming perfect
367 /// synchronization between the info at the device and at the network server
368 Ptr<ClassAEndDeviceLorawanMac> m_mac; //!< Pointer to the MAC layer of this device
369};
370
371} // namespace lorawan
372} // namespace ns3
373
374#endif /* DEVICE_STATUS_H */
a polymophic address class
Definition address.h:114
An identifier for simulation events.
Definition event-id.h:45
Object()
Caller graph was not generated because of its size.
Definition object.cc:93
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
a unique identifier for an interface.
Definition type-id.h:50
Class representing the MAC layer of a Class A LoRaWAN device.
EndDeviceStatus::ReceivedPacketInfo GetLastReceivedPacketInfo()
Return the information about the last packet that was received from the device.
uint8_t m_secondReceiveWindowSpreadingFactor
Spreading Factor (SF) for RX2 window.
bool HasReceiveWindowOpportunityScheduled()
Check if there is already a running reception window event scheduled for this end device.
void SetReplyMacHeader(LorawanMacHeader macHeader)
Set the reply packet mac header.
void SetReplyFrameHeader(LoraFrameHeader frameHeader)
Set the reply packet frame header.
static TypeId GetTypeId()
Register this type.
Ptr< Packet > GetReplyPayload()
Get the data of the reply packet.
std::list< std::pair< Ptr< const Packet >, ReceivedPacketInfo > > ReceivedPacketList
typedef of a list of packets paired to their reception info.
uint32_t GetFirstReceiveWindowFrequency() const
Get the first window frequency of this device.
void SetSecondReceiveWindowSpreadingFactor(uint8_t sf)
Set the spreading factor this device is using in the second receive window.
LorawanMacHeader GetReplyMacHeader() const
Get the reply packet mac header.
uint8_t m_firstReceiveWindowSpreadingFactor
Spreading Factor (SF) for RX1 window.
void InsertReceivedPacket(Ptr< const Packet > receivedPacket, const Address &gwAddress)
Insert a received packet in the packet list.
EventId m_receiveWindowEvent
Event storing the next scheduled downlink transmission.
struct Reply m_reply
Next reply intended for this device.
LoraDeviceAddress m_endDeviceAddress
The address of this device.
bool NeedsReply() const
Whether the end device needs a reply.
LoraFrameHeader GetReplyFrameHeader() const
Get the reply packet frame header.
uint32_t GetSecondReceiveWindowFrequency() const
Return the second window frequency of this device.
std::map< Address, PacketInfoPerGw > GatewayList
typedef of a list of gateways with relative reception information.
ReceivedPacketList m_receivedPacketList
List of received packets.
void RemoveReceiveWindowOpportunity()
Cancel next scheduled reception window event.
void SetReceiveWindowOpportunity(EventId event)
Store next scheduled reception window event.
ReceivedPacketList GetReceivedPacketList() const
Get the received packet list.
void SetFirstReceiveWindowFrequency(uint32_t frequencyHz)
Set the first window frequency of this device.
Ptr< const Packet > GetLastPacketReceivedFromDevice()
Return the last packet that was received from this device.
void SetReplyPayload(Ptr< Packet > replyPayload)
Set the packet reply payload.
uint32_t m_firstReceiveWindowFrequencyHz
Frequency [Hz] for RX1 window.
friend std::ostream & operator<<(std::ostream &os, const EndDeviceStatus &status)
Stream insertion operator.
void AddMACCommand(Ptr< MacCommand > macCommand)
Add MAC command to the frame header of next reply.
uint8_t GetFirstReceiveWindowSpreadingFactor() const
Get the spreading factor this device is using in the first receive window.
void SetFirstReceiveWindowSpreadingFactor(uint8_t sf)
Set the spreading factor this device is using in the first receive window.
Ptr< ClassAEndDeviceLorawanMac > m_mac
Pointer to the MAC layer of this device.
void InitializeReply()
Reset the next reply state.
std::map< double, Address > GetPowerGatewayMap()
Get the gateways which received the last packet from the end device.
uint8_t GetSecondReceiveWindowSpreadingFactor() const
Get the spreading factor this device is using in the second receive window.
uint32_t m_secondReceiveWindowFrequencyHz
Frequency [Hz] for RX2 window.
void SetSecondReceiveWindowFrequency(uint32_t frequencyHz)
Set the second window frequency of this device.
Ptr< Packet > GetCompleteReplyPacket()
Get the reply packet.
~EndDeviceStatus() override
Destructor.
EndDeviceStatus()
Default constructor.
Ptr< ClassAEndDeviceLorawanMac > GetMac()
Get the MAC layer of the end device.
This class represents the device address of a LoraWAN end device.
This class represents the Frame header (FHDR) used in a LoraWAN network.
This class represents the Mac header of a LoRaWAN packet.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Structure saving information regarding the packet reception in each gateway.
Time receivedTime
Time at which the packet was received by this gateway.
Address gwAddress
Address of the gateway that received the packet.
double rxPower
Reception power of the packet at this gateway.
Structure saving information regarding all packet receptions.
uint32_t frequencyHz
Carrier frequency [Hz] used to send this packet.
GatewayList gwList
List of gateways that received this packet.
Ptr< const Packet > packet
The received packet.
uint8_t sf
Spreading factor used to send this packet.
Structure representing the reply that the network server will send this device at the first opportuni...
LorawanMacHeader macHeader
The MAC Header to attach to the reply packet.
bool needsReply
Whether or not this device needs a reply.
Ptr< Packet > payload
The data packet that will be sent as a reply.
LoraFrameHeader frameHeader
The Frame Header to attach to the reply packet.