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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Davide Magrin <magrinda@dei.unipd.it>
7 */
8
10
11namespace ns3
12{
13namespace lorawan
14{
15
16NS_LOG_COMPONENT_DEFINE("NetworkControllerComponent");
17
18NS_OBJECT_ENSURE_REGISTERED(NetworkControllerComponent);
19
20TypeId
22{
23 static TypeId tid =
24 TypeId("ns3::NetworkControllerComponent").SetParent<Object>().SetGroupName("lorawan");
25 return tid;
26}
27
31
35
36////////////////////////////////
37// ConfirmedMessagesComponent //
38////////////////////////////////
41{
42 static TypeId tid = TypeId("ns3::ConfirmedMessagesComponent")
44 .AddConstructor<ConfirmedMessagesComponent>()
45 .SetGroupName("lorawan");
46 return tid;
47}
48
52
56
57void
60 Ptr<NetworkStatus> networkStatus)
61{
62 NS_LOG_FUNCTION(this->GetTypeId() << packet << networkStatus);
63
64 // Check whether the received packet requires an acknowledgment.
66 LoraFrameHeader fHdr;
67 fHdr.SetAsUplink();
68 Ptr<Packet> myPacket = packet->Copy();
69 myPacket->RemoveHeader(mHdr);
70 myPacket->RemoveHeader(fHdr);
71
72 NS_LOG_INFO("Received packet Mac Header: " << mHdr);
73 NS_LOG_INFO("Received packet Frame Header: " << fHdr);
74
76 {
77 NS_LOG_INFO("Packet requires confirmation");
78
79 // Set up the ACK bit on the reply
80 status->m_reply.frameHeader.SetAsDownlink();
81 status->m_reply.frameHeader.SetAck(true);
82 status->m_reply.frameHeader.SetAddress(fHdr.GetAddress());
83 status->m_reply.macHeader.SetMType(LorawanMacHeader::UNCONFIRMED_DATA_DOWN);
84 status->m_reply.needsReply = true;
85
86 // Note that the acknowledgment procedure dies here: "Acknowledgments
87 // are only snt in response to the latest message received and are never
88 // retransmitted". We interpret this to mean that only the current
89 // reception window can be used, and that the Ack field should be
90 // emptied in case transmission cannot be performed in the current
91 // window. Because of this, in this component's OnFailedReply method we
92 // void the ack bits.
93 }
94}
95
96void
98 Ptr<NetworkStatus> networkStatus)
99{
100 NS_LOG_FUNCTION(this << status << networkStatus);
101 // Nothing to do in this case
102}
103
104void
106 Ptr<NetworkStatus> networkStatus)
107{
108 NS_LOG_FUNCTION(this << networkStatus);
109
110 // Empty the Ack bit.
111 status->m_reply.frameHeader.SetAck(false);
112}
113
114////////////////////////
115// LinkCheckComponent //
116////////////////////////
117TypeId
119{
120 static TypeId tid = TypeId("ns3::LinkCheckComponent")
122 .AddConstructor<LinkCheckComponent>()
123 .SetGroupName("lorawan");
124 return tid;
125}
126
130
134
135void
138 Ptr<NetworkStatus> networkStatus)
139{
140 NS_LOG_FUNCTION(this->GetTypeId() << packet << networkStatus);
141
142 // We will only act just before reply, when all Gateways will have received
143 // the packet.
144}
145
146void
148 Ptr<NetworkStatus> networkStatus)
149{
150 NS_LOG_FUNCTION(this << status << networkStatus);
151
152 Ptr<Packet> myPacket = status->GetLastPacketReceivedFromDevice()->Copy();
153 LorawanMacHeader mHdr;
154 LoraFrameHeader fHdr;
155 fHdr.SetAsUplink();
156 myPacket->RemoveHeader(mHdr);
157 myPacket->RemoveHeader(fHdr);
158
160
161 // GetMacCommand returns 0 if no command is found
162 if (command)
163 {
164 status->m_reply.needsReply = true;
165
166 // Get the number of gateways that received the packet and the best
167 // margin
168 uint8_t gwCount = status->GetLastReceivedPacketInfo().gwList.size();
169
171 replyCommand->SetGwCnt(gwCount);
172 status->m_reply.frameHeader.SetAsDownlink();
173 status->m_reply.frameHeader.AddCommand(replyCommand);
174 status->m_reply.macHeader.SetMType(LorawanMacHeader::UNCONFIRMED_DATA_DOWN);
175 }
176 else
177 {
178 // Do nothing
179 }
180}
181
182void
184{
185 NS_LOG_FUNCTION(this->GetTypeId() << networkStatus);
186}
187} // namespace lorawan
188} // namespace ns3
A base class which provides memory management and object aggregation.
Definition object.h:78
Smart pointer class similar to boost::intrusive_ptr.
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
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:191
#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:264
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Every class exported by the ns3 library is enclosed in the ns3 namespace.