satellite-gw-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/log.h>
27 #include <ns3/lorawan-ground-mac-gateway.h>
28 #include <ns3/lorawan-mac-gateway.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-gw-phy.h>
35 #include <ns3/satellite-id-mapper.h>
36 #include <ns3/satellite-link-results.h>
37 #include <ns3/satellite-lorawan-net-device.h>
38 #include <ns3/satellite-lower-layer-service.h>
39 #include <ns3/satellite-net-device.h>
40 #include <ns3/satellite-node-info.h>
41 #include <ns3/satellite-orbiter-net-device.h>
42 #include <ns3/satellite-phy-rx-carrier-conf.h>
43 #include <ns3/satellite-topology.h>
44 #include <ns3/satellite-typedefs.h>
45 #include <ns3/singleton.h>
46 
47 NS_LOG_COMPONENT_DEFINE("SatGwHelperLora");
48 
49 namespace ns3
50 {
51 
52 NS_OBJECT_ENSURE_REGISTERED(SatGwHelperLora);
53 
54 TypeId
56 {
57  static TypeId tid =
58  TypeId("ns3::SatGwHelperLora").SetParent<SatGwHelper>().AddConstructor<SatGwHelperLora>();
59  return tid;
60 }
61 
62 TypeId
64 {
65  return GetTypeId();
66 }
67 
69 {
70  // this default constructor should be never called
71  NS_FATAL_ERROR("Default constructor not supported!!!");
72 }
73 
75  uint32_t rtnLinkCarrierCount,
76  Ptr<SatSuperframeSeq> seq,
80  RandomAccessSettings_s randomAccessSettings)
81  : SatGwHelper(carrierBandwidthConverter,
82  rtnLinkCarrierCount,
83  seq,
84  readCb,
85  reserveCb,
86  sendCb,
87  randomAccessSettings)
88 {
89  NS_LOG_FUNCTION(this << rtnLinkCarrierCount << seq);
90 }
91 
92 Ptr<NetDevice>
94  uint32_t gwId,
95  uint32_t satId,
96  uint32_t beamId,
97  uint32_t feederSatId,
98  uint32_t feederBeamId,
99  Ptr<SatChannel> fCh,
100  Ptr<SatChannel> rCh,
102  Ptr<SatNcc> ncc,
103  Ptr<SatLowerLayerServiceConf> llsConf)
104 {
105  NS_LOG_FUNCTION(this << n << gwId << satId << beamId << fCh << rCh << ncc << llsConf);
106 
107  NetDeviceContainer container;
108 
109  // Create SatNetDevice
110  m_deviceFactory.SetTypeId("ns3::SatLorawanNetDevice");
111  Ptr<SatLorawanNetDevice> dev = m_deviceFactory.Create<SatLorawanNetDevice>();
112 
113  // Attach the SatNetDevices to nodes
114  n->AddDevice(dev);
115 
116  SatPhy::CreateParam_t params;
117  params.m_satId = satId;
118  params.m_beamId = beamId;
119  params.m_device = dev;
120  params.m_txCh = fCh;
121  params.m_rxCh = rCh;
122  params.m_standard = SatEnums::LORA_GW;
123 
127  Ptr<SatChannelEstimationErrorContainer> cec;
128  // Not enabled, create only base class
130  {
131  cec = Create<SatSimpleChannelEstimationErrorContainer>();
132  }
133  // Create SatFwdLinkChannelEstimationErrorContainer
134  else
135  {
136  uint32_t minWfId = m_superframeSeq->GetWaveformConf()->GetMinWfId();
137  uint32_t maxWfId = m_superframeSeq->GetWaveformConf()->GetMaxWfId();
138  if (Singleton<SatTopology>::Get()->GetReturnLinkRegenerationMode() ==
140  Singleton<SatTopology>::Get()->GetReturnLinkRegenerationMode() ==
142  {
143  cec = Create<SatRtnLinkChannelEstimationErrorContainer>(minWfId, maxWfId);
144  }
145  else
146  {
147  cec = Create<SatFwdLinkChannelEstimationErrorContainer>();
148  }
149  }
150 
151  SatPhyRxCarrierConf::RxCarrierCreateParams_s parameters =
152  SatPhyRxCarrierConf::RxCarrierCreateParams_s();
153  parameters.m_errorModel = m_errorModel;
154  parameters.m_daConstantErrorRate = m_daConstantErrorRate;
155  parameters.m_daIfModel = m_daInterferenceModel;
156  parameters.m_raIfModel = m_raSettings.m_raInterferenceModel;
157  parameters.m_raIfEliminateModel = m_raSettings.m_raInterferenceEliminationModel;
158  parameters.m_linkRegenerationMode =
159  Singleton<SatTopology>::Get()->GetReturnLinkRegenerationMode();
160  parameters.m_bwConverter = m_carrierBandwidthConverter;
161  parameters.m_carrierCount = m_rtnLinkCarrierCount;
162  parameters.m_cec = cec;
163  parameters.m_raCollisionModel = m_raSettings.m_raCollisionModel;
164  parameters.m_raConstantErrorRate = m_raSettings.m_raConstantErrorRate;
165  parameters.m_randomAccessModel = m_raSettings.m_randomAccessModel;
166 
167  Ptr<SatGwPhy> phy = CreateObject<SatGwPhy>(
168  params,
170  parameters,
172 
173  // ncc->SetUseLora(true);
174 
175  // Set fading
176  phy->SetTxFadingContainer(n->GetObject<SatBaseFading>());
177  phy->SetRxFadingContainer(n->GetObject<SatBaseFading>());
178 
179  Ptr<LorawanMacGateway> mac = CreateObject<LorawanGroundMacGateway>(satId, beamId);
180 
181  SatLoraConf satLoraConf;
182  satLoraConf.SetConf(mac);
183 
184  // Attach the Mac layer receiver to Phy
185  SatPhy::ReceiveCallback recCb = MakeCallback(&LorawanMac::Receive, mac);
186 
187  // Attach the NCC C/N0 update to Phy
188  SatPhy::CnoCallback cnoCb = MakeCallback(&SatNcc::UtCnoUpdated, ncc);
189 
190  // Attach the NCC random access load update to Phy
191  SatPhy::AverageNormalizedOfferedLoadCallback avgNormalizedOfferedLoadCb =
192  MakeCallback(&SatNcc::DoRandomAccessDynamicLoadControl, ncc);
193 
194  phy->SetAttribute("ReceiveCb", CallbackValue(recCb));
195  phy->SetAttribute("CnoCb", CallbackValue(cnoCb));
196  phy->SetAttribute("AverageNormalizedOfferedLoadCallback",
197  CallbackValue(avgNormalizedOfferedLoadCb));
198 
199  // Attach the PHY layer to SatNetDevice
200  dev->SetPhy(phy);
201 
202  // Attach the Mac layer to SatNetDevice
203  dev->SetMac(mac);
204  mac->SetDevice(dev);
205 
206  mac->SetPhy(phy);
207 
208  // Set the device address and pass it to MAC as well
209  Mac48Address addr = Mac48Address::Allocate();
210  dev->SetAddress(addr);
211 
212  Singleton<SatIdMapper>::Get()->AttachMacToTraceId(dev->GetAddress());
213  Singleton<SatIdMapper>::Get()->AttachMacToGwId(dev->GetAddress(), gwId);
214  Singleton<SatIdMapper>::Get()->AttachMacToBeamId(dev->GetAddress(), beamId);
215  Singleton<SatIdMapper>::Get()->AttachMacToSatId(dev->GetAddress(), satId + 1);
216 
217  phy->Initialize();
218 
219  // Create a node info to all the protocol layers
220  Ptr<SatNodeInfo> nodeInfo = Create<SatNodeInfo>(SatEnums::NT_GW, n->GetId(), addr);
221  dev->SetNodeInfo(nodeInfo);
222  mac->SetNodeInfo(nodeInfo);
223  phy->SetNodeInfo(nodeInfo);
224 
225  // Begin frame end scheduling for processes utilizing frame length as interval
226  // Node info needs to be set before the start in order to get the scheduling context correctly
227  // set
228  if (Singleton<SatTopology>::Get()->GetReturnLinkRegenerationMode() == SatEnums::TRANSPARENT)
229  {
230  phy->BeginEndScheduling();
231  }
232 
233  Singleton<SatTopology>::Get()->AddGwLayersLora(n,
234  feederSatId,
235  feederBeamId,
236  satId,
237  beamId,
238  dev,
239  DynamicCast<LorawanGroundMacGateway>(mac),
240  phy);
241 
242  return dev;
243 }
244 
245 } // namespace ns3
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.
Creates needed objects for GW nodes like SatOrbiterNetDevice objects.
Ptr< SatSuperframeSeq > m_superframeSeq
SatPhy::ErrorModel m_errorModel
RandomAccessSettings_s m_raSettings
The used random access model settings.
bool m_enableChannelEstimationError
Enable channel estimation error modeling at forward link receiver (= UT).
ObjectFactory m_deviceFactory
Ptr< SatLinkResults > m_linkResults
SatPhy::InterferenceModel m_daInterferenceModel
SatTypedefs::CarrierBandwidthConverter_t m_carrierBandwidthConverter
virtual Ptr< NetDevice > Install(Ptr< Node > n, uint32_t gwId, uint32_t satId, uint32_t beamId, uint32_t feederSatId, uint32_t feederBeamId, Ptr< SatChannel > fCh, Ptr< SatChannel > rCh, SatPhy::ChannelPairGetterCallback cbChannel, Ptr< SatNcc > ncc, Ptr< SatLowerLayerServiceConf > llsConf)
SatGwHelperLora()
Default constructor.
static TypeId GetTypeId(void)
Get the type ID.
TypeId GetInstanceTypeId(void) const
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< 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.
void DoRandomAccessDynamicLoadControl(uint32_t satId, uint32_t beamId, uint32_t carrierId, uint8_t allocationChannelId, double averageNormalizedOfferedLoad)
Function for adjusting the random access allocation channel specific load.
void UtCnoUpdated(uint32_t satId, uint32_t beamId, Address sourceMac, Address gwId, double cno, bool isSatelliteMac)
Update UT specific C/N0 information.
Callback< void, uint32_t, uint32_t, Address, Address, double, bool > CnoCallback
Definition: satellite-phy.h:94
Callback< void, uint32_t, uint32_t, uint32_t, uint8_t, double > AverageNormalizedOfferedLoadCallback
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.
constexpr uint8_t SUPERFRAME_SEQUENCE
Used superframe sequence in the RTN link.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
SatPhyRxCarrierConf::InterferenceModel m_raInterferenceModel
SatPhyRxCarrierConf::InterferenceEliminationModel m_raInterferenceEliminationModel
SatEnums::RandomAccessModel_t m_randomAccessModel
SatPhyRxCarrierConf::RandomAccessCollisionModel m_raCollisionModel
Creation parameters for base PHY object.
Ptr< SatChannel > m_rxCh
Ptr< NetDevice > m_device
Ptr< SatChannel > m_txCh
SatEnums::SatLoraNodeType_t m_standard