Loading...
Searching...
No Matches
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#include <stdint.h>
26
27namespace ns3
28{
29
30NS_LOG_COMPONENT_DEFINE("LoraNetworkControllerComponent");
31
32NS_OBJECT_ENSURE_REGISTERED(LoraNetworkControllerComponent);
33
34TypeId
36{
37 static TypeId tid = TypeId("ns3::LoraNetworkControllerComponent").SetParent<Object>();
38 return tid;
39}
40
41// Constructor and destructor
45
49
51// LoraConfirmedMessagesComponent //
53TypeId
55{
56 static TypeId tid = TypeId("ns3::LoraConfirmedMessagesComponent")
58 .AddConstructor<LoraConfirmedMessagesComponent>();
59 return tid;
60}
61
65
69
70void
72 Ptr<LoraEndDeviceStatus> status,
73 Ptr<LoraNetworkStatus> networkStatus)
74{
75 NS_LOG_FUNCTION(this->GetTypeId() << packet << networkStatus);
76
77 // Check whether the received packet requires an acknowledgment.
79 LoraFrameHeader fHdr;
80 fHdr.SetAsUplink();
81 Ptr<Packet> myPacket = packet->Copy();
82 myPacket->RemoveHeader(mHdr);
83 myPacket->RemoveHeader(fHdr);
84
85 NS_LOG_INFO("Received packet Mac Header: " << mHdr);
86 NS_LOG_INFO("Received packet Frame Header: " << fHdr);
87
89 {
90 NS_LOG_INFO("Packet requires confirmation");
91
92 // Set up the ACK bit on the reply
93 status->m_reply.frameHeader.SetAsDownlink();
94 status->m_reply.frameHeader.SetAck(true);
95 status->m_reply.frameHeader.SetAddress(fHdr.GetAddress());
96 status->m_reply.macHeader.SetMType(LorawanMacHeader::UNCONFIRMED_DATA_DOWN);
97 status->m_reply.needsReply = true;
98
99 // Note that the acknowledgment procedure dies here: "Acknowledgments
100 // are only snt in response to the latest message received and are never
101 // retransmitted". We interpret this to mean that only the current
102 // reception window can be used, and that the Ack field should be
103 // emptied in case transmission cannot be performed in the current
104 // window. Because of this, in this component's OnFailedReply method we
105 // void the ack bits.
106 }
107}
108
109void
111 Ptr<LoraNetworkStatus> networkStatus)
112{
113 NS_LOG_FUNCTION(this << status << networkStatus);
114 // Nothing to do in this case
115}
116
117void
118LoraConfirmedMessagesComponent::OnFailedReply(Ptr<LoraEndDeviceStatus> status,
119 Ptr<LoraNetworkStatus> networkStatus)
120{
121 NS_LOG_FUNCTION(this << networkStatus);
122
123 // Empty the Ack bit.
124 status->m_reply.frameHeader.SetAck(false);
125}
126
128// LoraLinkCheckComponent //
130TypeId
132{
133 static TypeId tid = TypeId("ns3::LoraLinkCheckComponent")
135 .AddConstructor<LoraLinkCheckComponent>();
136 return tid;
137}
138
142
146
147void
149 Ptr<LoraEndDeviceStatus> status,
150 Ptr<LoraNetworkStatus> networkStatus)
151{
152 NS_LOG_FUNCTION(this->GetTypeId() << packet << networkStatus);
153
154 // We will only act just before reply, when all Gateways will have received
155 // the packet.
156}
157
158void
159LoraLinkCheckComponent::BeforeSendingReply(Ptr<LoraEndDeviceStatus> status,
160 Ptr<LoraNetworkStatus> networkStatus)
161{
162 NS_LOG_FUNCTION(this << status << networkStatus);
163
164 Ptr<Packet> myPacket = status->GetLastPacketReceivedFromDevice()->Copy();
165 LorawanMacHeader mHdr;
166 LoraFrameHeader fHdr;
167 fHdr.SetAsUplink();
168 myPacket->RemoveHeader(mHdr);
169 myPacket->RemoveHeader(fHdr);
170
171 Ptr<LinkCheckReq> command = fHdr.GetLorawanMacCommand<LinkCheckReq>();
172
173 // GetMacCommand returns 0 if no command is found
174 if (command)
175 {
176 status->m_reply.needsReply = true;
177
178 // Get the number of gateways that received the packet and the best
179 // margin
180 uint8_t gwCount = status->GetLastReceivedPacketInfo().gwList.size();
181
182 Ptr<LinkCheckAns> replyCommand = CreateObject<LinkCheckAns>();
183 replyCommand->SetGwCnt(gwCount);
184 status->m_reply.frameHeader.SetAsDownlink();
185 status->m_reply.frameHeader.AddCommand(replyCommand);
186 status->m_reply.macHeader.SetMType(LorawanMacHeader::UNCONFIRMED_DATA_DOWN);
187 }
188 else
189 {
190 // Do nothing
191 }
192}
193
194void
195LoraLinkCheckComponent::OnFailedReply(Ptr<LoraEndDeviceStatus> status,
196 Ptr<LoraNetworkStatus> networkStatus)
197{
198 NS_LOG_FUNCTION(this->GetTypeId() << networkStatus);
199}
200} // 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.