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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Davide Magrin <magrinda@dei.unipd.it>
7 */
8
9#include "lorawan-mac.h"
10
11#include "ns3/log.h"
12
13namespace ns3
14{
15namespace lorawan
16{
17
18NS_LOG_COMPONENT_DEFINE("LorawanMac");
19
21
22TypeId
24{
25 static TypeId tid =
26 TypeId("ns3::LorawanMac")
28 .SetGroupName("lorawan")
29 .AddTraceSource("SentNewPacket",
30 "Trace source indicating a new packet "
31 "arrived at the MAC layer",
33 "ns3::Packet::TracedCallback")
34 .AddTraceSource("ReceivedPacket",
35 "Trace source indicating a packet "
36 "was correctly received at the MAC layer",
38 "ns3::Packet::TracedCallback")
39 .AddTraceSource("CannotSendBecauseDutyCycle",
40 "Trace source indicating a packet "
41 "could not be sent immediately because of duty cycle limitations",
43 "ns3::Packet::TracedCallback");
44 return tid;
45}
46
51
56
57void
59{
60 m_device = device;
61}
62
65{
66 return m_device;
67}
68
71{
72 return m_phy;
73}
74
75void
77{
78 // Set the phy
79 m_phy = phy;
80
81 // Connect the receive callbacks
82 m_phy->SetReceiveOkCallback(MakeCallback(&LorawanMac::Receive, this));
83 m_phy->SetReceiveFailedCallback(MakeCallback(&LorawanMac::FailedReception, this));
84 m_phy->SetTxFinishedCallback(MakeCallback(&LorawanMac::TxFinished, this));
85}
86
92
93void
98
99uint8_t
101{
102 NS_LOG_FUNCTION(this << unsigned(dataRate));
103
104 // Check we are in range
105 if (dataRate >= m_sfForDataRate.size())
106 {
107 return 0;
108 }
109
110 return m_sfForDataRate.at(dataRate);
111}
112
113double
115{
116 NS_LOG_FUNCTION(this << unsigned(dataRate));
117
118 // Check we are in range
119 if (dataRate > m_bandwidthForDataRate.size())
120 {
121 return 0;
122 }
123
124 return m_bandwidthForDataRate.at(dataRate);
125}
126
127double
129{
130 NS_LOG_FUNCTION(this << unsigned(txPower));
131
132 if (txPower > m_txDbmForTxPower.size())
133 {
134 return 0;
135 }
136
137 return m_txDbmForTxPower.at(txPower);
138}
139
140void
141LorawanMac::SetSfForDataRate(std::vector<uint8_t> sfForDataRate)
142{
143 m_sfForDataRate = sfForDataRate;
144}
145
146void
147LorawanMac::SetBandwidthForDataRate(std::vector<double> bandwidthForDataRate)
148{
149 m_bandwidthForDataRate = bandwidthForDataRate;
150}
151
152void
153LorawanMac::SetMaxAppPayloadForDataRate(std::vector<uint32_t> maxAppPayloadForDataRate)
154{
155 m_maxAppPayloadForDataRate = maxAppPayloadForDataRate;
156}
157
158void
159LorawanMac::SetTxDbmForTxPower(std::vector<double> txDbmForTxPower)
160{
161 m_txDbmForTxPower = txDbmForTxPower;
162}
163
164void
166{
167 m_nPreambleSymbols = nPreambleSymbols;
168}
169
170int
175
176void
178{
179 m_replyDataRateMatrix = replyDataRateMatrix;
180}
181} // namespace lorawan
182} // 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
std::vector< double > m_txDbmForTxPower
A vector holding the power that corresponds to a certain TxPower value.
TracedCallback< Ptr< const Packet > > m_cannotSendBecauseDutyCycle
The trace source that is fired when a packet cannot be sent because of duty cycle limitations.
std::vector< uint8_t > m_sfForDataRate
A vector holding the spreading factor each data rate corresponds to.
void SetSfForDataRate(std::vector< uint8_t > sfForDataRate)
Set the vector to use to check up correspondence between spreading factor and data rate.
LorawanMac()
Default constructor.
TracedCallback< Ptr< const Packet > > m_receivedPacket
Trace source that is fired when a packet reaches the MAC layer.
void SetDevice(Ptr< NetDevice > device)
Set the device this MAC layer is installed on.
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.
Ptr< LogicalLoraChannelHelper > GetLogicalLoraChannelHelper()
Get the logical lora channel helper associated with this MAC.
~LorawanMac() override
Destructor.
double GetDbmForTxPower(uint8_t txPower)
Get the transmission power in dBm that corresponds, in this region, to the encoded 8-bit txPower.
void SetPhy(Ptr< LoraPhy > phy)
Set the underlying PHY layer.
uint8_t GetSfFromDataRate(uint8_t dataRate)
Get the spreading factor corresponding to a data rate, based on this MAC's region.
double GetBandwidthFromDataRate(uint8_t dataRate)
Get the bandwidth corresponding to a data rate, based on this MAC's region.
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...
ReplyDataRateMatrix m_replyDataRateMatrix
The matrix that decides the data rate the gateway will use in a reply based on the end device's sendi...
static TypeId GetTypeId()
Register this type.
virtual void Receive(Ptr< const Packet > packet)=0
Receive a packet from the lower layer.
void SetLogicalLoraChannelHelper(Ptr< LogicalLoraChannelHelper > helper)
Set the LogicalLoraChannelHelper this MAC instance will use.
Ptr< LogicalLoraChannelHelper > m_channelHelper
The LogicalLoraChannelHelper instance that is assigned to this MAC.
int GetNPreambleSymbols() const
Get the number of PHY preamble symbols this MAC is set to use.
Ptr< LoraPhy > GetPhy()
Get the underlying PHY layer.
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.
TracedCallback< Ptr< const Packet > > m_sentNewPacket
Trace source that is fired when a new APP layer packet arrives at the MAC layer.
Ptr< LoraPhy > m_phy
The PHY instance that sits under this MAC layer.
std::vector< double > m_bandwidthForDataRate
A vector holding the bandwidth each data rate corresponds to.
void SetNPreambleSymbols(int nPreambleSymbols)
Set the number of PHY preamble symbols this MAC is set to use.
void SetReplyDataRateMatrix(ReplyDataRateMatrix replyDataRateMatrix)
Set the matrix to use when deciding with which data rate to respond.
void SetBandwidthForDataRate(std::vector< double > bandwidthForDataRate)
Set the vector to use to check up correspondence between bandwidth and data rate.
Ptr< NetDevice > m_device
The device this MAC layer is installed on.
int m_nPreambleSymbols
The number of symbols to use in the PHY preamble.
Ptr< NetDevice > GetDevice()
Get the device this MAC layer is installed on.
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:53
#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_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
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:684