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 
49 NS_LOG_COMPONENT_DEFINE("SatUtHelperLora");
50 
51 namespace ns3
52 {
53 
54 NS_OBJECT_ENSURE_REGISTERED(SatUtHelperLora);
55 
56 TypeId
58 {
59  static TypeId tid =
60  TypeId("ns3::SatUtHelperLora").SetParent<SatUtHelper>().AddConstructor<SatUtHelperLora>();
61  return tid;
62 }
63 
64 TypeId
66 {
67  NS_LOG_FUNCTION(this);
68 
69  return GetTypeId();
70 }
71 
73 {
74  NS_LOG_FUNCTION(this);
75 
76  // this default constructor should be never called
77  NS_FATAL_ERROR("SatUtHelperLora::SatUtHelperLora - Constructor not in use");
78 }
79 
81  uint32_t fwdLinkCarrierCount,
82  Ptr<SatSuperframeSeq> seq,
86  RandomAccessSettings_s randomAccessSettings)
87  : SatUtHelper(carrierBandwidthConverter,
88  fwdLinkCarrierCount,
89  seq,
90  readCb,
91  reserveCb,
92  sendCb,
93  randomAccessSettings)
94 {
95  NS_LOG_FUNCTION(this << fwdLinkCarrierCount << seq);
96 }
97 
98 Ptr<NetDevice>
100  uint32_t satId,
101  uint32_t beamId,
102  Ptr<SatChannel> fCh,
103  Ptr<SatChannel> rCh,
104  Ptr<SatNetDevice> gwNd,
105  Ptr<SatNcc> ncc,
106  Address satUserAddress,
109 {
110  NS_LOG_FUNCTION(this << n << satId << beamId << fCh << rCh << gwNd << ncc << satUserAddress);
111 
112  NetDeviceContainer container;
113 
114  // Create SatNetDevice
115  m_deviceFactory.SetTypeId("ns3::SatLorawanNetDevice");
116  Ptr<SatLorawanNetDevice> dev = m_deviceFactory.Create<SatLorawanNetDevice>();
117 
118  // Attach the SatNetDevice to node
119  n->AddDevice(dev);
120 
121  SatPhy::CreateParam_t params;
122  params.m_satId = satId;
123  params.m_beamId = beamId;
124  params.m_device = dev;
125  params.m_txCh = rCh;
126  params.m_rxCh = fCh;
127  params.m_standard = SatEnums::LORA_UT;
128 
132  Ptr<SatChannelEstimationErrorContainer> cec;
133  // Not enabled, create only base class
135  {
136  cec = Create<SatSimpleChannelEstimationErrorContainer>();
137  }
138  // Create SatFwdLinkChannelEstimationErrorContainer
139  else
140  {
141  cec = Create<SatFwdLinkChannelEstimationErrorContainer>();
142  }
143 
144  SatPhyRxCarrierConf::RxCarrierCreateParams_s parameters =
145  SatPhyRxCarrierConf::RxCarrierCreateParams_s();
146  parameters.m_errorModel = m_errorModel;
147  parameters.m_daConstantErrorRate = m_daConstantErrorRate;
148  parameters.m_daIfModel = m_daInterferenceModel;
149  parameters.m_raIfModel = m_raSettings.m_raInterferenceModel;
150  parameters.m_raIfEliminateModel = m_raSettings.m_raInterferenceEliminationModel;
151  parameters.m_linkRegenerationMode =
152  Singleton<SatTopology>::Get()->GetForwardLinkRegenerationMode();
153  parameters.m_bwConverter = m_carrierBandwidthConverter;
154  parameters.m_carrierCount = m_fwdLinkCarrierCount;
155  parameters.m_cec = cec;
156  parameters.m_raCollisionModel = m_raSettings.m_raCollisionModel;
157  parameters.m_randomAccessModel = m_raSettings.m_randomAccessModel;
158 
159  Ptr<SatUtPhy> phy = CreateObject<SatUtPhy>(
160  params,
162  parameters,
164  phy->SetChannelPairGetterCallback(cbChannel);
165 
166  // Set fading
167  phy->SetTxFadingContainer(n->GetObject<SatBaseFading>());
168  phy->SetRxFadingContainer(n->GetObject<SatBaseFading>());
169 
170  Ptr<LorawanMacEndDeviceClassA> mac =
171  CreateObject<LorawanMacEndDeviceClassA>(n, satId, beamId, m_superframeSeq);
172 
173  // TODO configuration for EU only
174  mac->SetTxDbmForTxPower(std::vector<double>{16, 14, 12, 10, 8, 6, 4, 2});
175 
176  SatLoraConf satLoraConf;
177  satLoraConf.SetConf(mac);
178 
179  // Attach the Mac layer receiver to Phy
180  SatPhy::ReceiveCallback recCb = MakeCallback(&LorawanMac::Receive, mac);
181 
182  phy->SetAttribute("ReceiveCb", CallbackValue(recCb));
183 
184  // Attach the PHY layer to SatNetDevice
185  dev->SetPhy(phy);
186 
187  // Attach the Mac layer to SatNetDevice
188  dev->SetMac(mac);
189  mac->SetDevice(dev);
190 
191  mac->SetPhy(phy);
192  mac->SetPhyRx(DynamicCast<SatLoraPhyRx>(phy->GetPhyRx()));
193  mac->SetRaModel(m_raSettings.m_randomAccessModel);
194 
195  // Set the device address and pass it to MAC as well
196  Mac48Address addr = Mac48Address::Allocate();
197  dev->SetAddress(addr);
198 
199  Singleton<SatIdMapper>::Get()->AttachMacToTraceId(dev->GetAddress());
200  Singleton<SatIdMapper>::Get()->AttachMacToUtId(dev->GetAddress());
201  Singleton<SatIdMapper>::Get()->AttachMacToBeamId(dev->GetAddress(), beamId);
202  Singleton<SatIdMapper>::Get()->AttachMacToSatId(dev->GetAddress(), satId + 1);
203 
204  // Create encapsulator and add it to UT's LLC
205  Mac48Address gwAddr = Mac48Address::ConvertFrom(gwNd->GetAddress());
206 
207  // set serving GW MAC address to RM
208  mac->SetRoutingUpdateCallback(cbRouting);
209  mac->SetGwAddress(gwAddr);
210 
211  mac->SetHandoverCallback(MakeCallback(&SatUtPhy::PerformHandover, phy));
212 
213  if (Singleton<SatTopology>::Get()->GetForwardLinkRegenerationMode() ==
215  {
216  mac->SetSatAddress(Mac48Address::ConvertFrom(satUserAddress));
217  mac->SetRegenerative(true);
218  }
219 
220  // Add UT to NCC
221  ncc->AddUt(m_llsConf,
222  dev->GetAddress(),
223  satId,
224  beamId,
225  MakeCallback(&LorawanMacEndDevice::SetRaChannel, mac));
226 
227  phy->Initialize();
228 
229  // Create a node info to all the protocol layers
230  Ptr<SatNodeInfo> nodeInfo = Create<SatNodeInfo>(SatEnums::NT_UT, n->GetId(), addr);
231  dev->SetNodeInfo(nodeInfo);
232  mac->SetNodeInfo(nodeInfo);
233  phy->SetNodeInfo(nodeInfo);
234 
235  Ptr<SatHandoverModule> handoverModule = n->GetObject<SatHandoverModule>();
236  if (handoverModule != nullptr)
237  {
238  handoverModule->SetHandoverRequestCallback(
239  MakeCallback(&LorawanMacEndDevice::ChangeBeam, mac));
240  mac->SetHandoverModule(handoverModule);
241  mac->SetBeamSchedulerCallback(MakeCallback(&SatNcc::GetBeamScheduler, ncc));
242  }
243 
244  Singleton<SatTopology>::Get()->AddUtLayersLora(n, satId, beamId, 0, dev, mac, phy);
245 
246  return dev;
247 }
248 
249 } // 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.
void SetHandoverRequestCallback(SatHandoverModule::HandoverRequestCallback cb)
Set the handover recommendation message sending callback.
A configuration class for the satellite reference system.
void SetConf(Ptr< LorawanMacGateway > gatewayMac)
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
Definition: satellite-phy.h:85
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.
Creates needed objects for UT nodes like SatOrbiterNetDevice objects.
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.
SatTypedefs::CarrierBandwidthConverter_t m_carrierBandwidthConverter
ObjectFactory m_deviceFactory
Ptr< SatSuperframeSeq > m_superframeSeq
TypeId GetInstanceTypeId(void) const
Derived from Object.
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.
Ptr< SatChannel > m_rxCh
Ptr< NetDevice > m_device
Ptr< SatChannel > m_txCh
SatEnums::SatLoraNodeType_t m_standard
Define RandomAccessSettings as a struct.
SatEnums::RandomAccessModel_t m_randomAccessModel
SatPhyRxCarrierConf::RandomAccessCollisionModel m_raCollisionModel
SatPhyRxCarrierConf::InterferenceEliminationModel m_raInterferenceEliminationModel
SatPhyRxCarrierConf::InterferenceModel m_raInterferenceModel