A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
network-controller-components.cc
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 * Author: Davide Magrin <magrinda@dei.unipd.it>
18 */
19
21
22namespace ns3
23{
24namespace lorawan
25{
26
27NS_LOG_COMPONENT_DEFINE("NetworkControllerComponent");
28
29NS_OBJECT_ENSURE_REGISTERED(NetworkControllerComponent);
30
31TypeId
33{
34 static TypeId tid =
35 TypeId("ns3::NetworkControllerComponent").SetParent<Object>().SetGroupName("lorawan");
36 return tid;
37}
38
40{
41}
42
44{
45}
46
47////////////////////////////////
48// ConfirmedMessagesComponent //
49////////////////////////////////
52{
53 static TypeId tid = TypeId("ns3::ConfirmedMessagesComponent")
55 .AddConstructor<ConfirmedMessagesComponent>()
56 .SetGroupName("lorawan");
57 return tid;
58}
59
61{
62}
63
65{
66}
67
68void
71 Ptr<NetworkStatus> networkStatus)
72{
73 NS_LOG_FUNCTION(this->GetTypeId() << packet << networkStatus);
74
75 // Check whether the received packet requires an acknowledgment.
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
107void
109 Ptr<NetworkStatus> networkStatus)
110{
111 NS_LOG_FUNCTION(this << status << networkStatus);
112 // Nothing to do in this case
113}
114
115void
117 Ptr<NetworkStatus> networkStatus)
118{
119 NS_LOG_FUNCTION(this << networkStatus);
120
121 // Empty the Ack bit.
122 status->m_reply.frameHeader.SetAck(false);
123}
124
125////////////////////////
126// LinkCheckComponent //
127////////////////////////
128TypeId
130{
131 static TypeId tid = TypeId("ns3::LinkCheckComponent")
133 .AddConstructor<LinkCheckComponent>()
134 .SetGroupName("lorawan");
135 return tid;
136}
137
139{
140}
141
143{
144}
145
146void
149 Ptr<NetworkStatus> networkStatus)
150{
151 NS_LOG_FUNCTION(this->GetTypeId() << packet << networkStatus);
152
153 // We will only act just before reply, when all Gateways will have received
154 // the packet.
155}
156
157void
159 Ptr<NetworkStatus> networkStatus)
160{
161 NS_LOG_FUNCTION(this << status << networkStatus);
162
163 Ptr<Packet> myPacket = status->GetLastPacketReceivedFromDevice()->Copy();
164 LorawanMacHeader mHdr;
165 LoraFrameHeader fHdr;
166 fHdr.SetAsUplink();
167 myPacket->RemoveHeader(mHdr);
168 myPacket->RemoveHeader(fHdr);
169
171
172 // GetMacCommand returns 0 if no command is found
173 if (command)
174 {
175 status->m_reply.needsReply = true;
176
177 // Get the number of gateways that received the packet and the best
178 // margin
179 uint8_t gwCount = status->GetLastReceivedPacketInfo().gwList.size();
180
181 Ptr<LinkCheckAns> replyCommand = Create<LinkCheckAns>();
182 replyCommand->SetGwCnt(gwCount);
183 status->m_reply.frameHeader.SetAsDownlink();
184 status->m_reply.frameHeader.AddCommand(replyCommand);
185 status->m_reply.macHeader.SetMType(LorawanMacHeader::UNCONFIRMED_DATA_DOWN);
186 }
187 else
188 {
189 // Do nothing
190 }
191}
192
193void
195{
196 NS_LOG_FUNCTION(this->GetTypeId() << networkStatus);
197}
198} // namespace lorawan
199} // namespace ns3
A base class which provides memory management and object aggregation.
Definition: object.h:89
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
void BeforeSendingReply(Ptr< EndDeviceStatus > status, Ptr< NetworkStatus > networkStatus) override
Function called as a downlink reply is about to leave the NetworkServer application.
void OnFailedReply(Ptr< EndDeviceStatus > status, Ptr< NetworkStatus > networkStatus) override
Method that is called when a packet cannot be sent in the downlink.
void OnReceivedPacket(Ptr< const Packet > packet, Ptr< EndDeviceStatus > status, Ptr< NetworkStatus > networkStatus) override
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.
Ptr< T > GetMacCommand()
Return a pointer to the first MacCommand of type T, or 0 if no such MacCommand exists in this header.
void SetAsUplink()
State that this is an uplink message.
LoraDeviceAddress GetAddress() const
Get this header's device address value.
This class represents the Mac header of a LoRaWAN packet.
uint8_t GetMType() const
Get the message type from the header.
Generic class describing a component of the NetworkController.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Every class exported by the ns3 library is enclosed in the ns3 namespace.