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 #include <list>
38 #include <map>
39 #include <ostream>
40 #include <stdint.h>
41 #include <utility>
42 
43 namespace ns3
44 {
45 
61 /*
62  * Diagram of the end-device-status data structure. One instance of this class
63  * for each ED, that will be identified by its address.
64  *
65  * Public Access:
66  *
67  * (ED address) --- Current device parameters:
68  * - First Receive Window SF and DRRe
69  * - First Receive Window frequency
70  * - Second Window SF and DR
71  * - Second Receive Window frequency
72  * --- Reply
73  * - Need for reply (true/false)
74  * - Updated reply
75  * --- Received Packets
76  * - Received packets list (see below).
77  *
78  *
79  * Private Access:
80  *
81  * (Received packets list) - List of gateways that received the packet (see below)
82  * - SF of the received packet
83  * - Frequency of the received packet
84  * - Bandwidth of the received packet
85  *
86  * (Gateway list) - Time at which the packet was received
87  * - Reception power
88  */
89 
90 class LoraEndDeviceStatus : public Object
91 {
92  public:
93  /********************/
94  /* Reply management */
95  /********************/
96 
101  struct Reply
102  {
103  // The Mac Header to attach to the reply packet.
105 
106  // The Frame Header to attach to the reply packet.
108 
109  // The data packet that will be sent as a reply.
110  Ptr<Packet> payload;
111 
112  // Whether or not this device needs a reply
113  bool needsReply = false;
114  };
115 
124  bool NeedsReply(void);
125 
131  Ptr<Packet> GetCompleteReplyPacket(void);
132 
139 
146 
152  Ptr<Packet> GetReplyPayload(void);
153 
154  /***********************************/
155  /* Received packet list management */
156  /***********************************/
157 
163  {
164  Address gwAddress;
166  double rxPower;
167  };
168 
169  // List of gateways, with relative information
170  typedef std::map<Address, PacketInfoPerGw> GatewayList;
171 
176  {
177  // Members
178  Ptr<const Packet> packet = 0;
180  uint8_t sf;
181  double frequency;
182  };
183 
184  typedef std::list<std::pair<Ptr<const Packet>, ReceivedPacketInfo>> ReceivedPacketList;
185 
186  /*******************************************/
187  /* Proper LoraEndDeviceStatus class definition */
188  /*******************************************/
189 
190  static TypeId GetTypeId(void);
191 
193  LoraEndDeviceStatus(LoraDeviceAddress endDeviceAddress,
194  Ptr<LorawanMacEndDeviceClassA> endDeviceMac);
195  virtual ~LoraEndDeviceStatus();
196 
202  uint8_t GetModcod(void);
203 
209  uint8_t GetBeamId(void);
210 
217 
221  double GetFirstReceiveWindowFrequency(void);
222 
229  uint8_t GetSecondReceiveWindowOffset(void);
230 
235  double GetSecondReceiveWindowFrequency(void);
236 
243 
247  void SetModcod(uint8_t modcod);
248 
252  void SetBeamId(uint8_t beamId);
253 
257  void SetFirstReceiveWindowSpreadingFactor(uint8_t sf);
258 
262  void SetFirstReceiveWindowFrequency(double frequency);
263 
267  void SetSecondReceiveWindowOffset(uint8_t offset);
268 
272  void SetSecondReceiveWindowFrequency(double frequency);
273 
277  void SetReplyMacHeader(LorawanMacHeader macHeader);
278 
282  void SetReplyFrameHeader(LoraFrameHeader frameHeader);
283 
287  void SetReplyPayload(Ptr<Packet> replyPayload);
288 
289  Ptr<LorawanMacEndDeviceClassA> GetMac(void);
290 
292  // Other methods //
294 
298  void InsertReceivedPacket(Ptr<const Packet> receivedPacket, const Address& gwAddress);
299 
303  Ptr<const Packet> GetLastPacketReceivedFromDevice(void);
304 
310 
314  void InitializeReply(void);
315 
319  void AddMACCommand(Ptr<LorawanMacCommand> macCommand);
320 
324  void UpdateGatewayData(GatewayList gwList, Address gwAddress, double rcvPower);
325 
330 
331  void SetReceiveWindowOpportunity(EventId event);
332 
334 
338  std::map<double, Address> GetPowerGatewayMap(void);
339 
340  struct Reply m_reply; //<! Next reply intended for this device
341 
342  LoraDeviceAddress m_endDeviceAddress; //<! The address of this device
343 
344  friend std::ostream& operator<<(std::ostream& os, const LoraEndDeviceStatus& status);
345 
346  private:
347  // Receive window data
348  uint8_t m_modcod;
349  uint8_t m_beamId;
350  Address m_utAddress;
356 
357  ReceivedPacketList m_receivedPacketList; //<! List of received packets
358 
359  // NOTE Using this attribute is 'cheating', since we are assuming perfect
360  // synchronization between the info at the device and at the network server
361  Ptr<LorawanMacEndDeviceClassA> m_mac;
362 };
363 } // namespace ns3
364 
365 #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...