lora-network-controller-components.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2018 University of Padova
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Davide Magrin <magrinda@dei.unipd.it>
19  *
20  * Modified by: Bastien Tauran <bastien.tauran@viveris.fr>
21  */
22 
24 
25 namespace ns3
26 {
27 
28 NS_LOG_COMPONENT_DEFINE("LoraNetworkControllerComponent");
29 
30 NS_OBJECT_ENSURE_REGISTERED(LoraNetworkControllerComponent);
31 
32 TypeId
34 {
35  static TypeId tid = TypeId("ns3::LoraNetworkControllerComponent").SetParent<Object>();
36  return tid;
37 }
38 
39 // Constructor and destructor
41 {
42 }
43 
45 {
46 }
47 
49 // LoraConfirmedMessagesComponent //
51 TypeId
53 {
54  static TypeId tid = TypeId("ns3::LoraConfirmedMessagesComponent")
55  .SetParent<LoraNetworkControllerComponent>()
56  .AddConstructor<LoraConfirmedMessagesComponent>();
57  return tid;
58 }
59 
61 {
62 }
63 
65 {
66 }
67 
68 void
70  Ptr<LoraEndDeviceStatus> status,
71  Ptr<LoraNetworkStatus> networkStatus)
72 {
73  NS_LOG_FUNCTION(this->GetTypeId() << packet << networkStatus);
74 
75  // Check whether the received packet requires an acknowledgment.
76  LorawanMacHeader mHdr;
77  LoraFrameHeader fHdr;
78  fHdr.SetAsUplink();
79  Ptr<Packet> myPacket = packet->Copy();
80  myPacket->RemoveHeader(mHdr);
81  myPacket->RemoveHeader(fHdr);
82 
83  NS_LOG_INFO("Received packet Mac Header: " << mHdr);
84  NS_LOG_INFO("Received packet Frame Header: " << fHdr);
85 
87  {
88  NS_LOG_INFO("Packet requires confirmation");
89 
90  // Set up the ACK bit on the reply
91  status->m_reply.frameHeader.SetAsDownlink();
92  status->m_reply.frameHeader.SetAck(true);
93  status->m_reply.frameHeader.SetAddress(fHdr.GetAddress());
94  status->m_reply.macHeader.SetMType(LorawanMacHeader::UNCONFIRMED_DATA_DOWN);
95  status->m_reply.needsReply = true;
96 
97  // Note that the acknowledgment procedure dies here: "Acknowledgments
98  // are only snt in response to the latest message received and are never
99  // retransmitted". We interpret this to mean that only the current
100  // reception window can be used, and that the Ack field should be
101  // emptied in case transmission cannot be performed in the current
102  // window. Because of this, in this component's OnFailedReply method we
103  // void the ack bits.
104  }
105 }
106 
107 void
109  Ptr<LoraNetworkStatus> networkStatus)
110 {
111  NS_LOG_FUNCTION(this << status << networkStatus);
112  // Nothing to do in this case
113 }
114 
115 void
116 LoraConfirmedMessagesComponent::OnFailedReply(Ptr<LoraEndDeviceStatus> status,
117  Ptr<LoraNetworkStatus> networkStatus)
118 {
119  NS_LOG_FUNCTION(this << networkStatus);
120 
121  // Empty the Ack bit.
122  status->m_reply.frameHeader.SetAck(false);
123 }
124 
126 // LoraLinkCheckComponent //
128 TypeId
130 {
131  static TypeId tid = TypeId("ns3::LoraLinkCheckComponent")
132  .SetParent<LoraNetworkControllerComponent>()
133  .AddConstructor<LoraLinkCheckComponent>();
134  return tid;
135 }
136 
138 {
139 }
140 
142 {
143 }
144 
145 void
147  Ptr<LoraEndDeviceStatus> status,
148  Ptr<LoraNetworkStatus> networkStatus)
149 {
150  NS_LOG_FUNCTION(this->GetTypeId() << packet << networkStatus);
151 
152  // We will only act just before reply, when all Gateways will have received
153  // the packet.
154 }
155 
156 void
157 LoraLinkCheckComponent::BeforeSendingReply(Ptr<LoraEndDeviceStatus> status,
158  Ptr<LoraNetworkStatus> networkStatus)
159 {
160  NS_LOG_FUNCTION(this << status << networkStatus);
161 
162  Ptr<Packet> myPacket = status->GetLastPacketReceivedFromDevice()->Copy();
163  LorawanMacHeader mHdr;
164  LoraFrameHeader fHdr;
165  fHdr.SetAsUplink();
166  myPacket->RemoveHeader(mHdr);
167  myPacket->RemoveHeader(fHdr);
168 
169  Ptr<LinkCheckReq> command = fHdr.GetLorawanMacCommand<LinkCheckReq>();
170 
171  // GetMacCommand returns 0 if no command is found
172  if (command)
173  {
174  status->m_reply.needsReply = true;
175 
176  // Get the number of gateways that received the packet and the best
177  // margin
178  uint8_t gwCount = status->GetLastReceivedPacketInfo().gwList.size();
179 
180  Ptr<LinkCheckAns> replyCommand = Create<LinkCheckAns>();
181  replyCommand->SetGwCnt(gwCount);
182  status->m_reply.frameHeader.SetAsDownlink();
183  status->m_reply.frameHeader.AddCommand(replyCommand);
184  status->m_reply.macHeader.SetMType(LorawanMacHeader::UNCONFIRMED_DATA_DOWN);
185  }
186  else
187  {
188  // Do nothing
189  }
190 }
191 
192 void
193 LoraLinkCheckComponent::OnFailedReply(Ptr<LoraEndDeviceStatus> status,
194  Ptr<LoraNetworkStatus> networkStatus)
195 {
196  NS_LOG_FUNCTION(this->GetTypeId() << networkStatus);
197 }
198 } // namespace ns3
void OnFailedReply(Ptr< LoraEndDeviceStatus > status, Ptr< LoraNetworkStatus > networkStatus)
Method that is called when a packet cannot be sent in the downlink.
void BeforeSendingReply(Ptr< LoraEndDeviceStatus > status, Ptr< LoraNetworkStatus > networkStatus)
void OnReceivedPacket(Ptr< const Packet > packet, Ptr< LoraEndDeviceStatus > status, Ptr< LoraNetworkStatus > networkStatus)
This method checks whether the received packet requires an acknowledgment and sets up the appropriate...
This class represents the Frame header (FHDR) used in a LoraWAN network.
void SetAsUplink(void)
State that this is an uplink message.
Ptr< T > GetLorawanMacCommand(void)
Return a pointer to a LorawanMacCommand, or 0 if the LorawanMacCommand does not exist in this header.
LoraDeviceAddress GetAddress(void) const
Get this header's device address value.
Generic class describing a component of the NetworkController.
This class represents the Mac header of a LoRaWAN packet.
uint8_t GetMType(void) const
Get the message type from the header.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.