A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lorawan-mac.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 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
20#include "lorawan-mac.h"
21
22#include "ns3/log.h"
23
24namespace ns3
25{
26namespace lorawan
27{
28
29NS_LOG_COMPONENT_DEFINE("LorawanMac");
30
32
33TypeId
35{
36 static TypeId tid =
37 TypeId("ns3::LorawanMac")
39 .SetGroupName("lorawan")
40 .AddTraceSource("SentNewPacket",
41 "Trace source indicating a new packet "
42 "arrived at the MAC layer",
44 "ns3::Packet::TracedCallback")
45 .AddTraceSource("ReceivedPacket",
46 "Trace source indicating a packet "
47 "was correctly received at the MAC layer",
49 "ns3::Packet::TracedCallback")
50 .AddTraceSource("CannotSendBecauseDutyCycle",
51 "Trace source indicating a packet "
52 "could not be sent immediately because of duty cycle limitations",
54 "ns3::Packet::TracedCallback");
55 return tid;
56}
57
59{
60 NS_LOG_FUNCTION(this);
61}
62
64{
65 NS_LOG_FUNCTION(this);
66}
67
68void
70{
71 m_device = device;
72}
73
76{
77 return m_device;
78}
79
82{
83 return m_phy;
84}
85
86void
88{
89 // Set the phy
90 m_phy = phy;
91
92 // Connect the receive callbacks
93 m_phy->SetReceiveOkCallback(MakeCallback(&LorawanMac::Receive, this));
94 m_phy->SetReceiveFailedCallback(MakeCallback(&LorawanMac::FailedReception, this));
95 m_phy->SetTxFinishedCallback(MakeCallback(&LorawanMac::TxFinished, this));
96}
97
100{
101 return m_channelHelper;
102}
103
104void
106{
107 m_channelHelper = helper;
108}
109
110uint8_t
112{
113 NS_LOG_FUNCTION(this << unsigned(dataRate));
114
115 // Check we are in range
116 if (dataRate >= m_sfForDataRate.size())
117 {
118 return 0;
119 }
120
121 return m_sfForDataRate.at(dataRate);
122}
123
124double
126{
127 NS_LOG_FUNCTION(this << unsigned(dataRate));
128
129 // Check we are in range
130 if (dataRate > m_bandwidthForDataRate.size())
131 {
132 return 0;
133 }
134
135 return m_bandwidthForDataRate.at(dataRate);
136}
137
138double
140{
141 NS_LOG_FUNCTION(this << unsigned(txPower));
142
143 if (txPower > m_txDbmForTxPower.size())
144 {
145 return 0;
146 }
147
148 return m_txDbmForTxPower.at(txPower);
149}
150
151void
152LorawanMac::SetSfForDataRate(std::vector<uint8_t> sfForDataRate)
153{
154 m_sfForDataRate = sfForDataRate;
155}
156
157void
158LorawanMac::SetBandwidthForDataRate(std::vector<double> bandwidthForDataRate)
159{
160 m_bandwidthForDataRate = bandwidthForDataRate;
161}
162
163void
164LorawanMac::SetMaxAppPayloadForDataRate(std::vector<uint32_t> maxAppPayloadForDataRate)
165{
166 m_maxAppPayloadForDataRate = maxAppPayloadForDataRate;
167}
168
169void
170LorawanMac::SetTxDbmForTxPower(std::vector<double> txDbmForTxPower)
171{
172 m_txDbmForTxPower = txDbmForTxPower;
173}
174
175void
177{
178 m_nPreambleSymbols = nPreambleSymbols;
179}
180
181int
183{
184 return m_nPreambleSymbols;
185}
186
187void
189{
190 m_replyDataRateMatrix = replyDataRateMatrix;
191}
192} // namespace lorawan
193} // 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
This class supports LorawanMac instances by managing a list of the logical channels that the device i...
std::vector< double > m_txDbmForTxPower
A vector holding the power that corresponds to a certain TxPower value.
Definition: lorawan-mac.h:283
TracedCallback< Ptr< const Packet > > m_cannotSendBecauseDutyCycle
The trace source that is fired when a packet cannot be sent because of duty cycle limitations.
Definition: lorawan-mac.h:231
void SetLogicalLoraChannelHelper(LogicalLoraChannelHelper helper)
Set the LogicalLoraChannelHelper this MAC instance will use.
Definition: lorawan-mac.cc:105
std::vector< uint8_t > m_sfForDataRate
A vector holding the spreading factor each data rate corresponds to.
Definition: lorawan-mac.h:262
void SetSfForDataRate(std::vector< uint8_t > sfForDataRate)
Set the vector to use to check up correspondence between spreading factor and data rate.
Definition: lorawan-mac.cc:152
LorawanMac()
Default constructor.
Definition: lorawan-mac.cc:58
TracedCallback< Ptr< const Packet > > m_receivedPacket
Trace source that is fired when a packet reaches the MAC layer.
Definition: lorawan-mac.h:236
void SetDevice(Ptr< NetDevice > device)
Set the device this MAC layer is installed on.
Definition: lorawan-mac.cc:69
virtual void FailedReception(Ptr< const Packet > packet)=0
Function called by lower layers to inform this layer that reception of a packet we were locked on fai...
std::vector< uint32_t > m_maxAppPayloadForDataRate
A vector holding the maximum app payload size that corresponds to a certain data rate.
Definition: lorawan-mac.h:273
~LorawanMac() override
Destructor.
Definition: lorawan-mac.cc:63
double GetDbmForTxPower(uint8_t txPower)
Get the transmission power in dBm that corresponds, in this region, to the encoded 8-bit txPower.
Definition: lorawan-mac.cc:139
void SetPhy(Ptr< LoraPhy > phy)
Set the underlying PHY layer.
Definition: lorawan-mac.cc:87
uint8_t GetSfFromDataRate(uint8_t dataRate)
Get the spreading factor corresponding to a data rate, based on this MAC's region.
Definition: lorawan-mac.cc:111
double GetBandwidthFromDataRate(uint8_t dataRate)
Get the bandwidth corresponding to a data rate, based on this MAC's region.
Definition: lorawan-mac.cc:125
void SetTxDbmForTxPower(std::vector< double > txDbmForTxPower)
Set the vector to use to check up which transmission power in Dbm corresponds to a certain TxPower va...
Definition: lorawan-mac.cc:170
ReplyDataRateMatrix m_replyDataRateMatrix
The matrix that decides the data rate the gateway will use in a reply based on the end device's sendi...
Definition: lorawan-mac.h:289
static TypeId GetTypeId()
Register this type.
Definition: lorawan-mac.cc:34
LogicalLoraChannelHelper m_channelHelper
The LogicalLoraChannelHelper instance that is assigned to this MAC.
Definition: lorawan-mac.h:257
virtual void Receive(Ptr< const Packet > packet)=0
Receive a packet from the lower layer.
int GetNPreambleSymbols() const
Get the number of PHY preamble symbols this MAC is set to use.
Definition: lorawan-mac.cc:182
Ptr< LoraPhy > GetPhy()
Get the underlying PHY layer.
Definition: lorawan-mac.cc:81
virtual void TxFinished(Ptr< const Packet > packet)=0
Perform actions after sending a packet.
void SetMaxAppPayloadForDataRate(std::vector< uint32_t > maxAppPayloadForDataRate)
Set the maximum App layer payload for a set data rate.
Definition: lorawan-mac.cc:164
TracedCallback< Ptr< const Packet > > m_sentNewPacket
Trace source that is fired when a new APP layer packet arrives at the MAC layer.
Definition: lorawan-mac.h:242
LogicalLoraChannelHelper GetLogicalLoraChannelHelper()
Get the logical lora channel helper associated with this MAC.
Definition: lorawan-mac.cc:99
Ptr< LoraPhy > m_phy
The PHY instance that sits under this MAC layer.
Definition: lorawan-mac.h:247
std::vector< double > m_bandwidthForDataRate
A vector holding the bandwidth each data rate corresponds to.
Definition: lorawan-mac.h:267
void SetNPreambleSymbols(int nPreambleSymbols)
Set the number of PHY preamble symbols this MAC is set to use.
Definition: lorawan-mac.cc:176
void SetReplyDataRateMatrix(ReplyDataRateMatrix replyDataRateMatrix)
Set the matrix to use when deciding with which data rate to respond.
Definition: lorawan-mac.cc:188
void SetBandwidthForDataRate(std::vector< double > bandwidthForDataRate)
Set the vector to use to check up correspondence between bandwidth and data rate.
Definition: lorawan-mac.cc:158
Ptr< NetDevice > m_device
The device this MAC layer is installed on.
Definition: lorawan-mac.h:252
int m_nPreambleSymbols
The number of symbols to use in the PHY preamble.
Definition: lorawan-mac.h:278
Ptr< NetDevice > GetDevice()
Get the device this MAC layer is installed on.
Definition: lorawan-mac.cc:75
std::array< std::array< uint8_t, 6 >, 8 > ReplyDataRateMatrix
Matrix structure to store possible data rate value to be used by a LoRaWAN end device for listening d...
Definition: lorawan-mac.h:64
#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_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:700