Loading...
Searching...
No Matches
satellite-ut-helper-lora.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2013 Magister Solutions Ltd
4 * Copyright (c) 2018 CNES
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation;
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Author: Bastien Tauran <bastien.tauran@viveris.fr>
20 */
21
23
24#include "satellite-lora-conf.h"
25
26#include "ns3/callback.h"
27#include "ns3/log.h"
28#include "ns3/lorawan-mac-end-device-class-a.h"
29#include "ns3/pointer.h"
30#include "ns3/satellite-channel-estimation-error-container.h"
31#include "ns3/satellite-channel.h"
32#include "ns3/satellite-const-variables.h"
33#include "ns3/satellite-enums.h"
34#include "ns3/satellite-id-mapper.h"
35#include "ns3/satellite-lorawan-net-device.h"
36#include "ns3/satellite-net-device.h"
37#include "ns3/satellite-node-info.h"
38#include "ns3/satellite-phy-rx-carrier-conf.h"
39#include "ns3/satellite-phy-rx.h"
40#include "ns3/satellite-phy-tx.h"
41#include "ns3/satellite-queue.h"
42#include "ns3/satellite-topology.h"
43#include "ns3/satellite-typedefs.h"
44#include "ns3/satellite-ut-phy.h"
45#include "ns3/singleton.h"
46
47#include <vector>
48
49NS_LOG_COMPONENT_DEFINE("SatUtHelperLora");
50
51namespace ns3
52{
53
54NS_OBJECT_ENSURE_REGISTERED(SatUtHelperLora);
55
56TypeId
58{
59 static TypeId tid =
60 TypeId("ns3::SatUtHelperLora").SetParent<SatUtHelper>().AddConstructor<SatUtHelperLora>();
61 return tid;
62}
63
65{
66 NS_LOG_FUNCTION(this);
67
68 // this default constructor should be never called
69 NS_FATAL_ERROR("SatUtHelperLora::SatUtHelperLora - Constructor not in use");
70}
71
73 uint32_t fwdLinkCarrierCount,
74 Ptr<SatSuperframeSeq> seq,
78 RandomAccessSettings_s randomAccessSettings)
79 : SatUtHelper(carrierBandwidthConverter,
80 fwdLinkCarrierCount,
81 seq,
82 readCb,
83 reserveCb,
84 sendCb,
85 randomAccessSettings)
86{
87 NS_LOG_FUNCTION(this << fwdLinkCarrierCount << seq);
88}
89
90Ptr<NetDevice>
92 uint32_t satId,
93 uint32_t beamId,
94 Ptr<SatChannel> fCh,
95 Ptr<SatChannel> rCh,
96 Ptr<SatNetDevice> gwNd,
97 Ptr<SatNcc> ncc,
98 Address satUserAddress,
101{
102 NS_LOG_FUNCTION(this << n << satId << beamId << fCh << rCh << gwNd << ncc << satUserAddress);
103
104 NetDeviceContainer container;
105
106 // Create SatNetDevice
107 m_deviceFactory.SetTypeId("ns3::SatLorawanNetDevice");
108 Ptr<SatLorawanNetDevice> dev = m_deviceFactory.Create<SatLorawanNetDevice>();
109
110 // Attach the SatNetDevice to node
111 n->AddDevice(dev);
112
114 params.m_satId = satId;
115 params.m_beamId = beamId;
116 params.m_device = dev;
117 params.m_txCh = rCh;
118 params.m_rxCh = fCh;
120
124 Ptr<SatChannelEstimationErrorContainer> cec;
125 // Not enabled, create only base class
127 {
128 cec = Create<SatSimpleChannelEstimationErrorContainer>();
129 }
130 // Create SatFwdLinkChannelEstimationErrorContainer
131 else
132 {
133 cec = Create<SatFwdLinkChannelEstimationErrorContainer>();
134 }
135
136 SatPhyRxCarrierConf::RxCarrierCreateParams_s parameters =
137 SatPhyRxCarrierConf::RxCarrierCreateParams_s();
138 parameters.m_errorModel = m_errorModel;
139 parameters.m_daConstantErrorRate = m_daConstantErrorRate;
140 parameters.m_daIfModel = m_daInterferenceModel;
141 parameters.m_raIfModel = m_raSettings.m_raInterferenceModel;
142 parameters.m_raIfEliminateModel = m_raSettings.m_raInterferenceEliminationModel;
143 parameters.m_linkRegenerationMode =
144 Singleton<SatTopology>::Get()->GetForwardLinkRegenerationMode();
145 parameters.m_bwConverter = m_carrierBandwidthConverter;
146 parameters.m_carrierCount = m_fwdLinkCarrierCount;
147 parameters.m_cec = cec;
148 parameters.m_raCollisionModel = m_raSettings.m_raCollisionModel;
149 parameters.m_randomAccessModel = m_raSettings.m_randomAccessModel;
150
151 Ptr<SatUtPhy> phy = CreateObject<SatUtPhy>(
152 params,
154 parameters,
156 phy->SetChannelPairGetterCallback(cbChannel);
157
158 // Set fading
159 phy->SetTxFadingContainer(n->GetObject<SatBaseFading>());
160 phy->SetRxFadingContainer(n->GetObject<SatBaseFading>());
161
162 Ptr<LorawanMacEndDeviceClassA> mac =
163 CreateObject<LorawanMacEndDeviceClassA>(n, satId, beamId, m_superframeSeq);
164
165 // TODO configuration for EU only
166 mac->SetTxDbmForTxPower(std::vector<double>{16, 14, 12, 10, 8, 6, 4, 2});
167
168 Ptr<SatLoraConf> satLoraConf = CreateObject<SatLoraConf>();
169 satLoraConf->SetConf(mac);
170
171 // Attach the Mac layer receiver to Phy
172 SatPhy::ReceiveCallback recCb = MakeCallback(&LorawanMac::Receive, mac);
173
174 phy->SetAttribute("ReceiveCb", CallbackValue(recCb));
175
176 // Attach the PHY layer to SatNetDevice
177 dev->SetPhy(phy);
178
179 // Attach the Mac layer to SatNetDevice
180 dev->SetMac(mac);
181 mac->SetDevice(dev);
182
183 mac->SetPhy(phy);
184 mac->SetPhyRx(DynamicCast<SatLoraPhyRx>(phy->GetPhyRx()));
185 mac->SetRaModel(m_raSettings.m_randomAccessModel);
186
187 // Set the device address and pass it to MAC as well
188 Mac48Address addr = Mac48Address::Allocate();
189 dev->SetAddress(addr);
190
191 Singleton<SatIdMapper>::Get()->AttachMacToTraceId(dev->GetAddress());
192 Singleton<SatIdMapper>::Get()->AttachMacToUtId(dev->GetAddress());
193 Singleton<SatIdMapper>::Get()->AttachMacToBeamId(dev->GetAddress(), beamId);
194 Singleton<SatIdMapper>::Get()->AttachMacToSatId(dev->GetAddress(), satId + 1);
195
196 // Create encapsulator and add it to UT's LLC
197 Mac48Address gwAddr = Mac48Address::ConvertFrom(gwNd->GetAddress());
198
199 // set serving GW MAC address to RM
200 mac->SetRoutingUpdateCallback(cbRouting);
201 mac->SetGwAddress(gwAddr);
202
203 mac->SetHandoverCallback(MakeCallback(&SatUtPhy::PerformHandover, phy));
204
205 if (Singleton<SatTopology>::Get()->GetForwardLinkRegenerationMode() ==
207 {
208 mac->SetSatAddress(Mac48Address::ConvertFrom(satUserAddress));
209 mac->SetRegenerative(true);
210 }
211
212 // Add UT to NCC
213 ncc->AddUt(m_llsConf,
214 dev->GetAddress(),
215 satId,
216 beamId,
217 MakeCallback(&LorawanMacEndDevice::SetRaChannel, mac));
218
219 phy->Initialize();
220
221 // Create a node info to all the protocol layers
222 Ptr<SatNodeInfo> nodeInfo = Create<SatNodeInfo>(SatEnums::NT_UT, n->GetId(), addr);
223 dev->SetNodeInfo(nodeInfo);
224 mac->SetNodeInfo(nodeInfo);
225 phy->SetNodeInfo(nodeInfo);
226
227 Ptr<SatHandoverModule> handoverModule = n->GetObject<SatHandoverModule>();
228 if (handoverModule != nullptr)
229 {
230 handoverModule->SetHandoverRequestCallback(
231 MakeCallback(&LorawanMacEndDevice::ChangeBeam, mac));
232 mac->SetHandoverModule(handoverModule);
233 mac->SetBeamSchedulerCallback(MakeCallback(&SatNcc::GetBeamScheduler, ncc));
234 }
235
236 Singleton<SatTopology>::Get()->AddUtLayersLora(n, satId, beamId, 0, dev, mac, phy);
237
238 return dev;
239}
240
241} // namespace ns3
void ChangeBeam(uint32_t satId, uint32_t beamId)
Method handling beam handover.
void SetRaChannel(uint32_t raChannel)
Set RA channel assigned for this UT.
virtual void Receive(SatPhy::PacketContainer_t packets, Ptr< SatSignalParameters >)=0
Receive a packet from the lower layer.
Base class for fading models such as Markov-based fading or fading trace.
SatLorawanNetDevice to be utilized in the UT and GW nodes for IoT configuration.
Callback< uint32_t, Ptr< SatControlMessage > > ReserveCtrlMsgCallback
Callback to reserve an id and initially store the control message.
Callback< void, Address, Address > RoutingUpdateCallback
Callback to update routing and ARP tables after handover.
Callback< uint32_t, uint32_t > SendCtrlMsgCallback
Callback to send a control message and allocate a recv ID for it.
Callback< Ptr< SatControlMessage >, uint32_t > ReadCtrlMsgCallback
Callback to read control messages from container storing control messages.
Ptr< SatBeamScheduler > GetBeamScheduler(uint32_t satId, uint32_t beamId) const
Callback< void, PacketContainer_t, Ptr< SatSignalParameters > > ReceiveCallback
Callback< SatChannelPair::ChannelPair_t, uint32_t, uint32_t > ChannelPairGetterCallback
Callback for retrieving a pair of SatChannel associated to a beam.
Callback< double, SatEnums::ChannelType_t, uint32_t, SatEnums::CarrierBandwidthType_t > CarrierBandwidthConverter_t
Callback for carrier bandwidths.
SatPhy::ErrorModel m_errorModel
SatPhy::InterferenceModel m_daInterferenceModel
RandomAccessSettings_s m_raSettings
The used random access model settings.
bool m_enableChannelEstimationError
Enable channel estimation error modeling at forward link receiver (= UT).
Ptr< SatLinkResults > m_linkResults
Ptr< SatLowerLayerServiceConf > m_llsConf
Configured lower layer service configuration.
SatUtHelper()
Default constructor.
SatTypedefs::CarrierBandwidthConverter_t m_carrierBandwidthConverter
ObjectFactory m_deviceFactory
Ptr< SatSuperframeSeq > m_superframeSeq
Creates needed objects for LORA UT nodes like SatOrbiterNetDevice objects.
SatUtHelperLora()
Default constructor.
virtual Ptr< NetDevice > Install(Ptr< Node > n, uint32_t satId, uint32_t beamId, Ptr< SatChannel > fCh, Ptr< SatChannel > rCh, Ptr< SatNetDevice > gwNd, Ptr< SatNcc > ncc, Address satUserAddress, SatPhy::ChannelPairGetterCallback cbChannel, SatMac::RoutingUpdateCallback cbRouting)
static TypeId GetTypeId(void)
Derived from Object.
void PerformHandover(uint32_t satId, uint32_t beamId)
Change underlying SatChannel to send and receive data from a new satellite and beam.
constexpr uint8_t SUPERFRAME_SEQUENCE
Used superframe sequence in the RTN link.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
Creation parameters for base PHY object.
SatEnums::SatLoraNodeType_t m_standard
Define RandomAccessSettings as a struct.