lora-end-device-status.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 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  * Authors: Martina Capuzzo <capuzzom@dei.unipd.it>
18  * Davide Magrin <magrinda@dei.unipd.it>
19  *
20  * Modified by: Bastien Tauran <bastien.tauran@viveris.fr>
21  */
22 
23 #ifndef LORA_END_DEVICE_STATUS_H
24 #define LORA_END_DEVICE_STATUS_H
25 
26 #include "lora-device-address.h"
27 #include "lora-frame-header.h"
29 #include "lorawan-mac-header.h"
30 
31 #include <ns3/ipv4-header.h>
32 #include <ns3/net-device.h>
33 #include <ns3/object.h>
34 #include <ns3/pointer.h>
35 
36 #include <iostream>
37 
38 namespace ns3
39 {
40 
56 /*
57  * Diagram of the end-device-status data structure. One instance of this class
58  * for each ED, that will be identified by its address.
59  *
60  * Public Access:
61  *
62  * (ED address) --- Current device parameters:
63  * - First Receive Window SF and DRRe
64  * - First Receive Window frequency
65  * - Second Window SF and DR
66  * - Second Receive Window frequency
67  * --- Reply
68  * - Need for reply (true/false)
69  * - Updated reply
70  * --- Received Packets
71  * - Received packets list (see below).
72  *
73  *
74  * Private Access:
75  *
76  * (Received packets list) - List of gateways that received the packet (see below)
77  * - SF of the received packet
78  * - Frequency of the received packet
79  * - Bandwidth of the received packet
80  *
81  * (Gateway list) - Time at which the packet was received
82  * - Reception power
83  */
84 
85 class LoraEndDeviceStatus : public Object
86 {
87  public:
88  /********************/
89  /* Reply management */
90  /********************/
91 
96  struct Reply
97  {
98  // The Mac Header to attach to the reply packet.
100 
101  // The Frame Header to attach to the reply packet.
103 
104  // The data packet that will be sent as a reply.
105  Ptr<Packet> payload;
106 
107  // Whether or not this device needs a reply
108  bool needsReply = false;
109  };
110 
119  bool NeedsReply(void);
120 
126  Ptr<Packet> GetCompleteReplyPacket(void);
127 
134 
141 
147  Ptr<Packet> GetReplyPayload(void);
148 
149  /***********************************/
150  /* Received packet list management */
151  /***********************************/
152 
158  {
159  Address gwAddress;
161  double rxPower;
162  };
163 
164  // List of gateways, with relative information
165  typedef std::map<Address, PacketInfoPerGw> GatewayList;
166 
171  {
172  // Members
173  Ptr<const Packet> packet = 0;
175  uint8_t sf;
176  double frequency;
177  };
178 
179  typedef std::list<std::pair<Ptr<const Packet>, ReceivedPacketInfo>> ReceivedPacketList;
180 
181  /*******************************************/
182  /* Proper LoraEndDeviceStatus class definition */
183  /*******************************************/
184 
185  static TypeId GetTypeId(void);
186 
188  LoraEndDeviceStatus(LoraDeviceAddress endDeviceAddress,
189  Ptr<LorawanMacEndDeviceClassA> endDeviceMac);
190  virtual ~LoraEndDeviceStatus();
191 
197  uint8_t GetModcod(void);
198 
204  uint8_t GetBeamId(void);
205 
212 
216  double GetFirstReceiveWindowFrequency(void);
217 
224  uint8_t GetSecondReceiveWindowOffset(void);
225 
230  double GetSecondReceiveWindowFrequency(void);
231 
238 
242  void SetModcod(uint8_t modcod);
243 
247  void SetBeamId(uint8_t beamId);
248 
252  void SetFirstReceiveWindowSpreadingFactor(uint8_t sf);
253 
257  void SetFirstReceiveWindowFrequency(double frequency);
258 
262  void SetSecondReceiveWindowOffset(uint8_t offset);
263 
267  void SetSecondReceiveWindowFrequency(double frequency);
268 
272  void SetReplyMacHeader(LorawanMacHeader macHeader);
273 
277  void SetReplyFrameHeader(LoraFrameHeader frameHeader);
278 
282  void SetReplyPayload(Ptr<Packet> replyPayload);
283 
284  Ptr<LorawanMacEndDeviceClassA> GetMac(void);
285 
287  // Other methods //
289 
293  void InsertReceivedPacket(Ptr<const Packet> receivedPacket, const Address& gwAddress);
294 
298  Ptr<const Packet> GetLastPacketReceivedFromDevice(void);
299 
305 
309  void InitializeReply(void);
310 
314  void AddMACCommand(Ptr<LorawanMacCommand> macCommand);
315 
319  void UpdateGatewayData(GatewayList gwList, Address gwAddress, double rcvPower);
320 
325 
326  void SetReceiveWindowOpportunity(EventId event);
327 
329 
333  std::map<double, Address> GetPowerGatewayMap(void);
334 
335  struct Reply m_reply; //<! Next reply intended for this device
336 
337  LoraDeviceAddress m_endDeviceAddress; //<! The address of this device
338 
339  friend std::ostream& operator<<(std::ostream& os, const LoraEndDeviceStatus& status);
340 
341  private:
342  // Receive window data
343  uint8_t m_modcod;
344  uint8_t m_beamId;
350 
351  ReceivedPacketList m_receivedPacketList; //<! List of received packets
352 
353  // NOTE Using this attribute is 'cheating', since we are assuming perfect
354  // synchronization between the info at the device and at the network server
355  Ptr<LorawanMacEndDeviceClassA> m_mac;
356 };
357 } // namespace ns3
358 
359 #endif /* LORA_END_DEVICE_STATUS_H */
This class represents the device address of a LoraWAN End Device.
This class represents the Network Server's knowledge about an End Device in the LoRaWAN network it is...
uint8_t GetBeamId(void)
Get the beam ID this device is using.
double GetFirstReceiveWindowFrequency(void)
Get the first window frequency of this device.
ReceivedPacketList GetReceivedPacketList(void)
Get the received packet list.
void AddMACCommand(Ptr< LorawanMacCommand > macCommand)
Add MAC command to the list.
Ptr< Packet > GetReplyPayload(void)
Get the data of the reply packet.
void SetSecondReceiveWindowFrequency(double frequency)
Set the second window frequency of this device.
void SetSecondReceiveWindowOffset(uint8_t offset)
Set 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.
void UpdateGatewayData(GatewayList gwList, Address gwAddress, double rcvPower)
Update Gateway data when more then one gateway receive the same packet.
void SetBeamId(uint8_t beamId)
Set the beam ID this device is using.
uint8_t GetFirstReceiveWindowSpreadingFactor(void)
Get the spreading factor this device is using in the first receive window.
friend std::ostream & operator<<(std::ostream &os, const LoraEndDeviceStatus &status)
LorawanMacHeader GetReplyMacHeader(void)
Get the reply packet mac header.
std::list< std::pair< Ptr< const Packet >, ReceivedPacketInfo > > ReceivedPacketList
void SetReplyMacHeader(LorawanMacHeader macHeader)
Set the reply packet mac header.
bool NeedsReply(void)
Whether the end device needs a reply.
LoraEndDeviceStatus::ReceivedPacketInfo GetLastReceivedPacketInfo(void)
Return the information about the last packet that was received from the device.
uint8_t GetModcod(void)
Get the modcod this device is using.
Ptr< Packet > GetCompleteReplyPacket(void)
Get the reply packet.
void SetReplyPayload(Ptr< Packet > replyPayload)
Set the packet reply payload.
void SetReplyFrameHeader(LoraFrameHeader frameHeader)
Set the reply packet frame header.
std::map< Address, PacketInfoPerGw > GatewayList
void InitializeReply(void)
Initialize reply.
Ptr< LorawanMacEndDeviceClassA > m_mac
Pointer to the MAC layer of this device.
double GetSecondReceiveWindowFrequency(void)
Return the second window frequency of this device.
Ptr< const Packet > GetLastPacketReceivedFromDevice(void)
Return the last packet that was received from this device.
uint8_t GetSecondReceiveWindowOffset(void)
Get the offset of spreading factor this device is using in the second receive window with respect to ...
void SetModcod(uint8_t modcod)
Set the modcod this device is using.
void InsertReceivedPacket(Ptr< const Packet > receivedPacket, const Address &gwAddress)
Insert a received packet in the packet list.
bool HasReceiveWindowOpportunityScheduled()
Returns whether we already decided we will schedule a transmission to this ED.
LoraFrameHeader GetReplyFrameHeader(void)
Get the reply packet frame header.
ReceivedPacketList m_receivedPacketList
void SetFirstReceiveWindowFrequency(double frequency)
Set the first window frequency of this device.
LoraDeviceAddress m_endDeviceAddress
void SetReceiveWindowOpportunity(EventId event)
std::map< double, Address > GetPowerGatewayMap(void)
Return an ordered list of the best gateways.
Ptr< LorawanMacEndDeviceClassA > GetMac(void)
This class represents the Frame header (FHDR) used in a LoraWAN network.
This class represents the Mac header of a LoRaWAN packet.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
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.
GatewayList gwList
List of gateways that received this packet.
Ptr< const Packet > packet
The received packet.
Structure representing the reply that the network server will send this device at the first opportuni...