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 "lora-phy.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
62
63void
65{
66 m_device = device;
67}
68
71{
72 return m_device;
73}
74
77{
78 return m_phy;
79}
80
81void
83{
84 // Set the phy
85 m_phy = phy;
86
87 // Connect the receive callbacks
88 m_phy->SetReceiveOkCallback(MakeCallback(&LorawanMac::Receive, this));
89 m_phy->SetReceiveFailedCallback(MakeCallback(&LorawanMac::FailedReception, this));
90 m_phy->SetTxFinishedCallback(MakeCallback(&LorawanMac::TxFinished, this));
91}
92
98
99void
104
105uint8_t
106LorawanMac::GetSfFromDataRate(uint8_t dataRate) const
107{
108 NS_LOG_FUNCTION(this << unsigned(dataRate));
109
110 // Check we are in range
111 if (dataRate >= m_sfForDataRate.size())
112 {
113 return 0;
114 }
115
116 return m_sfForDataRate.at(dataRate);
117}
118
121{
122 NS_LOG_FUNCTION(this << unsigned(dataRate));
123
124 // Check we are in range
125 if (dataRate > m_bandwidthForDataRate.size())
126 {
127 return 0;
128 }
129
130 return m_bandwidthForDataRate.at(dataRate);
131}
132
133double
134LorawanMac::GetDbmForTxPower(uint8_t txPower) const
135{
136 NS_LOG_FUNCTION(this << unsigned(txPower));
137
138 if (txPower > m_txDbmForTxPower.size() - 1)
139 {
140 return -1;
141 }
142
143 return m_txDbmForTxPower.at(txPower);
144}
145
146void
147LorawanMac::SetSfForDataRate(std::vector<uint8_t> sfForDataRate)
148{
149 m_sfForDataRate = sfForDataRate;
150}
151
152void
153LorawanMac::SetBandwidthForDataRate(std::vector<uint32_t> bandwidthForDataRate)
154{
155 m_bandwidthForDataRate = bandwidthForDataRate;
156}
157
158void
159LorawanMac::SetMaxMacPayloadForDataRate(std::vector<uint32_t> maxMacPayloadForDataRate)
160{
161 m_maxMacPayloadForDataRate = maxMacPayloadForDataRate;
162}
163
164void
165LorawanMac::SetTxDbmForTxPower(std::vector<double> txDbmForTxPower)
166{
167 m_txDbmForTxPower = txDbmForTxPower;
168}
169
170void
172{
173 m_nPreambleSymbols = nPreambleSymbols;
174}
175
176int
181
182void
184{
185 m_replyDataRateMatrix = replyDataRateMatrix;
186}
187
188} // namespace lorawan
189} // namespace ns3
Object()
Caller graph was not generated because of its size.
Definition object.cc:93
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
a unique identifier for an interface.
Definition type-id.h:50
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:999
Class representing the LoRaWAN MAC layer.
Definition lorawan-mac.h:36
std::vector< double > m_txDbmForTxPower
A vector holding the power that corresponds to a certain TxPower value.
Ptr< LoraPhy > GetPhy() const
Get the underlying PHY layer.
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
Inform this layer that reception of a packet we were locked on failed.
void SetMaxMacPayloadForDataRate(std::vector< uint32_t > maxMacPayloadForDataRate)
Set the maximum LoRaWAN MACPayload size for a set data rate.
~LorawanMac() override
Destructor.
void SetPhy(Ptr< LoraPhy > phy)
Set the underlying PHY layer.
void SetBandwidthForDataRate(std::vector< uint32_t > bandwidthForDataRate)
Set the vector to use to check up correspondence between bandwidth and data rate.
Callback< void, Ptr< Packet > > ReceiveCallback
This type defines the callback of a higher layer that a LorawanMac(-derived) object invokes to pass a...
Definition lorawan-mac.h:44
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...
std::vector< uint32_t > m_maxMacPayloadForDataRate
A vector holding the maximum MACPayload size that corresponds to a certain data rate.
static TypeId GetTypeId()
Register this type.
uint32_t GetBandwidthFromDataRate(uint8_t dataRate) const
Get the bandwidth corresponding to a data rate, based on this MAC's region.
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.
uint8_t GetSfFromDataRate(uint8_t dataRate) const
Get the spreading factor corresponding to a data rate, based on this MAC's region.
Ptr< LogicalLoraChannelHelper > m_channelHelper
The LogicalLoraChannelHelper instance that is assigned to this MAC.
ReceiveCallback m_receiveCallback
! Callback to forward to upper layers
int GetNPreambleSymbols() const
Get the number of PHY preamble symbols this MAC is set to use.
Ptr< NetDevice > GetDevice() const
Get the device this MAC layer is installed on.
virtual void TxFinished(Ptr< const Packet > packet)=0
Perform actions after sending a packet.
Ptr< LogicalLoraChannelHelper > GetLogicalLoraChannelHelper() const
Get the logical lora channel helper associated with this MAC.
double GetDbmForTxPower(uint8_t txPower) const
Get the transmission power in dBm that corresponds, in this region, to the encoded 8-bit txPower.
std::vector< uint32_t > m_bandwidthForDataRate
A vector holding the bandwidth each data rate corresponds to.
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.
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 SetReceiveCallback(ReceiveCallback cb)
Set the callback to be used to notify higher layers when a packet has been received.
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.
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:51
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:690
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:194
#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.