Loading...
Searching...
No Matches
lorawan-orbiter-mac-gateway.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2017 University of Padova
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Davide Magrin <magrinda@dei.unipd.it>
19 *
20 * Modified by: Bastien Tauran <bastien.tauran@viveris.fr>
21 */
22
24
25#include "lora-beam-tag.h"
26#include "lora-frame-header.h"
27#include "lorawan-mac-header.h"
31
32#include "ns3/log.h"
33
34namespace ns3
35{
36
37NS_LOG_COMPONENT_DEFINE("LorawanOrbiterMacGateway");
38
39NS_OBJECT_ENSURE_REGISTERED(LorawanOrbiterMacGateway);
40
41TypeId
43{
44 static TypeId tid = TypeId("ns3::LorawanOrbiterMacGateway")
45 .SetParent<LorawanMacGateway>()
46 .AddConstructor<LorawanOrbiterMacGateway>();
47 return tid;
48}
49
51{
52 NS_FATAL_ERROR("Default constructor not in use");
53}
54
56 : LorawanMacGateway(satId, beamId)
57{
58 NS_LOG_FUNCTION(this);
59}
60
62{
63 NS_LOG_FUNCTION(this);
64}
65
66void
68{
69 NS_LOG_FUNCTION(this << packet);
70
71 // Get DataRate to send this packet with
72 LoraTag tag;
73 packet->RemovePacketTag(tag);
74 uint8_t modcod = tag.GetModcod();
75 uint8_t dataRate = tag.GetDataRate();
76 double frequency = tag.GetFrequency();
77 NS_LOG_DEBUG("DR: " << (uint32_t)unsigned(dataRate));
78 NS_LOG_DEBUG("SF: " << (uint32_t)unsigned(GetSfFromDataRate(dataRate)));
79 NS_LOG_DEBUG("BW: " << GetBandwidthFromDataRate(dataRate));
80 NS_LOG_DEBUG("Freq: " << frequency << " MHz");
81 packet->AddPacketTag(tag);
82
84 {
85 // Add a SatAddressTag tag with this device's address as the source address.
86 packet->AddByteTag(SatAddressTag(m_nodeInfo->GetMacAddress()));
87
88 // Add a SatDevTimeTag tag for packet delay computation at the receiver end.
89 SatDevTimeTag satDevTag;
90 packet->RemovePacketTag(satDevTag);
91 packet->AddPacketTag(SatDevTimeTag(Simulator::Now()));
92 }
93
94 // Make sure we can transmit this packet
95 if (m_channelHelper.GetWaitingTime(CreateObject<LoraLogicalChannel>(frequency)) > Time(0))
96 {
97 // We cannot send now!
98 NS_LOG_WARN("Trying to send a packet but Duty Cycle won't allow it. Aborting.");
99 return;
100 }
101
102 if (IsTransmitting())
103 {
104 // Gateway already transmitting!
105 NS_LOG_WARN("Gateway is already transmitting. Aborting.");
106 return;
107 }
108
109 LoraTxParameters params;
110 params.sf = GetSfFromDataRate(dataRate);
111 params.headerDisabled = false;
113 params.bandwidthHz = GetBandwidthFromDataRate(dataRate);
114 params.nPreamble = 8;
115 params.crcEnabled = 1;
117
121 txInfo.modCod = (SatEnums::SatModcod_t)modcod;
122 txInfo.sliceId = 0;
123 txInfo.waveformId = 0;
124
125 // Get the duration
126 Time duration = GetOnAirTime(packet, params);
127
128 NS_LOG_DEBUG("Duration: " << duration.GetSeconds());
129
130 // Add the event to the channelHelper to keep track of duty cycle
131 m_channelHelper.AddEvent(duration, CreateObject<LoraLogicalChannel>(frequency));
132
133 SatMacTag mTag;
134 mTag.SetDestAddress(Mac48Address::GetBroadcast());
135 mTag.SetSourceAddress(Mac48Address::ConvertFrom(m_device->GetAddress()));
136 packet->AddPacketTag(mTag);
137
139 packets.push_back(packet);
140 uint32_t carrierId = 0;
141
142 // Send the packet to the PHY layer to send it on the channel
143 m_phy->SendPdu(packets, carrierId, duration, txInfo);
144
145 m_sentNewPacket(packet);
146}
147
148void
150 Ptr<SatSignalParameters> /*rxParams*/)
151{
152 NS_LOG_FUNCTION(this << packets);
153
154 // Invoke the `Rx` and `RxDelay` trace sources.
155 RxTraces(packets);
156
157 Ptr<Packet> packet;
158 for (SatPhy::PacketContainer_t::iterator i = packets.begin(); i != packets.end(); i++)
159 {
160 packet = *i;
161 // Make a copy of the packet to work on
162 Ptr<Packet> packetCopy = packet->Copy();
163
164 SatMacTag mTag;
165 packetCopy->RemovePacketTag(mTag);
166
167 // Only forward the packet if it's uplink
168 LorawanMacHeader macHdr;
169 packetCopy->PeekHeader(macHdr);
170
171 // TODO useless condition ?
172 if (macHdr.IsUplink())
173 {
174 LoraBeamTag beamTag = LoraBeamTag(GetBeamId());
175 packetCopy->AddPacketTag(beamTag);
176
177 Ptr<SatOrbiterNetDeviceLora> orbiterNetDevice =
178 m_device->GetObject<SatOrbiterNetDeviceLora>();
179 NS_ASSERT(orbiterNetDevice != nullptr);
180 orbiterNetDevice->ReceivePacketUser(packetCopy, m_nodeInfo->GetMacAddress());
181
182 NS_LOG_DEBUG("Received packet: " << packet);
183
184 m_receivedPacket(packet);
185 }
186 else
187 {
188 NS_LOG_DEBUG("Not forwarding downlink message to NetDevice");
189 }
190 }
191}
192} // namespace ns3
Tag used to save various data about a packet, like its Spreading Factor and data about interference.
Tag used to save various data about a packet, like its Spreading Factor and data about interference.
Definition lora-tag.h:41
double GetFrequency(void)
Get the frequency of the packet.
Definition lora-tag.cc:142
uint8_t GetDataRate(void)
Get the data rate for this packet.
Definition lora-tag.cc:148
uint8_t GetModcod(void)
Get the modcod for this packet.
Definition lora-tag.cc:160
This class represents the Mac header of a LoRaWAN packet.
bool IsUplink(void) const
Check whether this header is for an uplink message.
TracedCallback< Ptr< const Packet > > m_receivedPacket
Trace source that is fired when a packet reaches the MAC layer.
Time GetOnAirTime(Ptr< Packet > packet, LoraTxParameters txParams)
Compute the time that a packet with certain characteristics will take to be transmitted.
Ptr< SatPhy > m_phy
The PHY instance that sits under this MAC layer.
TracedCallback< Ptr< const Packet > > m_sentNewPacket
Trace source that is fired when a new APP layer packet arrives at the MAC layer.
uint8_t GetSfFromDataRate(uint8_t dataRate)
Get the SF corresponding to a data rate, based on this MAC's region.
Ptr< NetDevice > m_device
The device this MAC layer is installed on.
LoraLogicalChannelHelper m_channelHelper
The LoraLogicalChannelHelper instance that is assigned to this MAC.
double GetBandwidthFromDataRate(uint8_t dataRate)
Get the BW corresponding to a data rate, based on this MAC's region.
virtual void Send(Ptr< Packet > packet)
Send a packet.
virtual void Receive(SatPhy::PacketContainer_t packets, Ptr< SatSignalParameters >)
Receive a packet from the lower layer.
This class implements a tag that carries the MAC address of the sender of the packet.
Time tag used to identify the time when packet is enqueued at device level.
SatModcod_t
Modulation scheme and coding rate for DVB-S2.
uint32_t GetBeamId() const
Get beam ID of the object.
void RxTraces(SatPhy::PacketContainer_t packets)
Invoke the Rx trace source for each received packet.
bool m_isStatisticsTagsEnabled
EnableStatisticsTags attribute.
Ptr< SatNodeInfo > m_nodeInfo
Node info containing node related information, such as node type, node id and MAC address (of the Sat...
This class implements a tag that carries the satellite MAC specific information, such as source and d...
void SetDestAddress(Mac48Address dest)
Set destination MAC address.
void SetSourceAddress(Mac48Address source)
Set source MAC address.
SatOrbiterNetDeviceLora to be utilized in geostationary satellite.
SatSignalParameters::PacketsInBurst_t PacketContainer_t
Define PacketContainer in SatPhy.
static double GetCodingRate(SatEnums::SatModcod_t modcod)
Gets the coding rate of a certain MODCOD.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
Structure to collect all parameters that are used to compute the duration of a packet (excluding payl...
bool lowDataRateOptimizationEnabled
Whether Low Data Rate Optimization is enabled.
uint32_t nPreamble
Number of preamble symbols.
bool headerDisabled
Whether to use implicit header mode.
uint8_t sf
Spreading Factor.
double bandwidthHz
Bandwidth in Hz.
bool crcEnabled
Whether Cyclic Redundancy Check is enabled.
Struct for storing the packet specific Tx information.