satellite-orbiter-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: Sami Rantanen <sami.rantanen@magister.fi>
20  * Author: Mathias Ettinger <mettinger@viveris.toulouse.fr>
21  */
22 
24 
25 #include "satellite-helper.h"
27 #include "satellite-lora-conf.h"
28 
29 #include "ns3/config.h"
30 #include "ns3/double.h"
31 #include "ns3/enum.h"
32 #include "ns3/log.h"
33 #include "ns3/lorawan-mac-gateway.h"
34 #include "ns3/lorawan-orbiter-mac-gateway.h"
35 #include "ns3/names.h"
36 #include "ns3/packet.h"
37 #include "ns3/pointer.h"
38 #include "ns3/satellite-channel-estimation-error-container.h"
39 #include "ns3/satellite-const-variables.h"
40 #include "ns3/satellite-id-mapper.h"
41 #include "ns3/satellite-orbiter-feeder-llc.h"
42 #include "ns3/satellite-orbiter-feeder-mac.h"
43 #include "ns3/satellite-orbiter-feeder-phy.h"
44 #include "ns3/satellite-orbiter-net-device-lora.h"
45 #include "ns3/satellite-orbiter-user-llc.h"
46 #include "ns3/satellite-orbiter-user-mac.h"
47 #include "ns3/satellite-orbiter-user-phy.h"
48 #include "ns3/satellite-phy-rx-carrier-conf.h"
49 #include "ns3/satellite-phy-rx.h"
50 #include "ns3/satellite-phy-tx.h"
51 #include "ns3/satellite-topology.h"
52 #include "ns3/satellite-typedefs.h"
53 #include "ns3/satellite-utils.h"
54 #include "ns3/singleton.h"
55 #include "ns3/uinteger.h"
56 
57 #include <algorithm>
58 #include <string>
59 #include <utility>
60 #include <vector>
61 
62 NS_LOG_COMPONENT_DEFINE("SatOrbiterHelperLora");
63 
64 namespace ns3
65 {
66 
67 NS_OBJECT_ENSURE_REGISTERED(SatOrbiterHelperLora);
68 
69 TypeId
71 {
72  static TypeId tid = TypeId("ns3::SatOrbiterHelperLora")
73  .SetParent<SatOrbiterHelper>()
74  .AddConstructor<SatOrbiterHelperLora>();
75  return tid;
76 }
77 
78 TypeId
80 {
81  NS_LOG_FUNCTION(this);
82 
83  return GetTypeId();
84 }
85 
88 {
89  NS_LOG_FUNCTION(this);
90 
91  // this default constructor should be never called
92  NS_ASSERT(false);
93 }
94 
96  SatTypedefs::CarrierBandwidthConverter_t bandwidthConverterCb,
97  uint32_t rtnLinkCarrierCount,
98  uint32_t fwdLinkCarrierCount,
99  Ptr<SatSuperframeSeq> seq,
100  SatMac::ReadCtrlMsgCallback fwdReadCb,
101  SatMac::ReadCtrlMsgCallback rtnReadCb,
102  RandomAccessSettings_s randomAccessSettings)
103  : SatOrbiterHelper(bandwidthConverterCb,
104  rtnLinkCarrierCount,
105  fwdLinkCarrierCount,
106  seq,
107  fwdReadCb,
108  rtnReadCb,
109  randomAccessSettings)
110 {
111  NS_LOG_FUNCTION(this << rtnLinkCarrierCount << fwdLinkCarrierCount);
112 
113  m_deviceFactory.SetTypeId("ns3::SatOrbiterNetDeviceLora");
114 }
115 
116 Ptr<SatOrbiterNetDevice>
118 {
119  NS_LOG_FUNCTION(this);
120 
121  return m_deviceFactory.Create<SatOrbiterNetDeviceLora>();
122 }
123 
124 void
125 SatOrbiterHelperLora::AttachChannelsUser(Ptr<SatOrbiterNetDevice> dev,
126  Ptr<SatChannel> uf,
127  Ptr<SatChannel> ur,
128  Ptr<SatAntennaGainPattern> userAgp,
129  Ptr<SatNcc> ncc,
130  uint32_t satId,
131  uint32_t userBeamId)
132 {
133  NS_LOG_FUNCTION(this << dev << uf << ur << userAgp << satId << userBeamId);
134 
135  NS_ASSERT_MSG(
136  Singleton<SatTopology>::Get()->GetForwardLinkRegenerationMode() ==
137  Singleton<SatTopology>::Get()->GetReturnLinkRegenerationMode(),
138  "Regeneration level must be the same on forward and return in Lora configuration");
139  NS_ASSERT_MSG(
140  Singleton<SatTopology>::Get()->GetForwardLinkRegenerationMode() == SatEnums::TRANSPARENT ||
141  Singleton<SatTopology>::Get()->GetForwardLinkRegenerationMode() ==
143  "Satellite can only be transparent or with network regenration in Lora configuration");
144 
145  SatPhy::CreateParam_t params;
146  params.m_satId = satId;
147  params.m_beamId = userBeamId;
148  params.m_device = dev;
149  params.m_standard =
150  Singleton<SatTopology>::Get()->GetForwardLinkRegenerationMode() == SatEnums::TRANSPARENT
153 
157  Ptr<SatChannelEstimationErrorContainer> cec =
158  Create<SatSimpleChannelEstimationErrorContainer>();
159 
160  SatPhyRxCarrierConf::RxCarrierCreateParams_s parametersUser =
161  SatPhyRxCarrierConf::RxCarrierCreateParams_s();
162  parametersUser.m_errorModel = m_rtnErrorModel;
163  parametersUser.m_daConstantErrorRate = m_rtnDaConstantErrorRate;
164  parametersUser.m_daIfModel = m_daRtnLinkInterferenceModel;
165  parametersUser.m_raIfModel = m_raSettings.m_raRtnInterferenceModel;
166  parametersUser.m_raIfEliminateModel = m_raSettings.m_raInterferenceEliminationModel;
167  parametersUser.m_linkRegenerationMode =
168  Singleton<SatTopology>::Get()->GetReturnLinkRegenerationMode();
169  parametersUser.m_bwConverter = m_carrierBandwidthConverter;
170  parametersUser.m_carrierCount = m_rtnLinkCarrierCount;
171  parametersUser.m_cec = cec;
172  parametersUser.m_raCollisionModel = m_raSettings.m_raCollisionModel;
173  parametersUser.m_randomAccessModel = m_raSettings.m_randomAccessModel;
174 
175  params.m_txCh = uf;
176  params.m_rxCh = ur;
177 
178  Ptr<SatOrbiterUserPhy> uPhy = CreateObject<SatOrbiterUserPhy>(
179  params,
181  parametersUser,
183 
184  // Note, that currently we have only one set of antenna patterns,
185  // which are utilized in both in user link and feeder link, and
186  // in both uplink and downlink directions.
187  uPhy->SetTxAntennaGainPattern(userAgp, dev->GetNode()->GetObject<SatMobilityModel>());
188  uPhy->SetRxAntennaGainPattern(userAgp, dev->GetNode()->GetObject<SatMobilityModel>());
189 
190  dev->AddUserPhy(uPhy, userBeamId);
191 
192  uPhy->Initialize();
193 
194  ncc->SetUseLora(true);
195 
196  Mac48Address userAddress;
197 
198  // Connect callbacks on forward link
199  switch (Singleton<SatTopology>::Get()->GetForwardLinkRegenerationMode())
200  {
201  case SatEnums::TRANSPARENT: {
202  // Create layers
203  Ptr<SatOrbiterUserMac> uTransparentMac = CreateObject<SatOrbiterUserMac>(satId, userBeamId);
204 
205  Ptr<SatNodeInfo> niPhyUser =
206  Create<SatNodeInfo>(SatEnums::NT_SAT,
207  m_nodeIds[satId],
208  Mac48Address::ConvertFrom(dev->GetAddress()));
209  uPhy->SetNodeInfo(niPhyUser);
210  uTransparentMac->SetNodeInfo(niPhyUser);
211 
212  // Return link
214  uPhy->SetAttribute("ReceiveCb", CallbackValue(uCb));
215 
216  uTransparentMac->SetReceiveNetDeviceCallback(
217  MakeCallback(&SatOrbiterNetDevice::ReceiveUser, dev));
218 
219  Singleton<SatTopology>::Get()->AddOrbiterUserLayersDvb(dev->GetNode(),
220  satId,
221  userBeamId,
222  dev,
223  nullptr,
224  uTransparentMac,
225  uPhy);
226  break;
227  }
229  // Create layers
230  Ptr<LorawanMacGateway> uRegenerationMac =
231  CreateObject<LorawanOrbiterMacGateway>(satId, userBeamId);
232 
233  dev->AddUserMac(uRegenerationMac, userBeamId);
234  uRegenerationMac->SetDevice(dev);
235 
236  uRegenerationMac->SetReadCtrlCallback(m_rtnReadCtrlCb);
237 
238  SatLoraConf satLoraConf;
239  satLoraConf.SetConf(uRegenerationMac);
240 
241  // Attach the Mac layer receiver to Phy
242  SatPhy::ReceiveCallback recCb = MakeCallback(&LorawanMac::Receive, uRegenerationMac);
243  uPhy->SetAttribute("ReceiveCb", CallbackValue(recCb));
244 
245  // Create a node info to PHY and MAC layers
246  userAddress = Mac48Address::Allocate();
247  Ptr<SatNodeInfo> niUser =
248  Create<SatNodeInfo>(SatEnums::NT_SAT, m_nodeIds[satId], userAddress);
249  uPhy->SetNodeInfo(niUser);
250  uRegenerationMac->SetNodeInfo(niUser);
251 
252  dev->AddUserPair(userBeamId, userAddress);
253 
254  uRegenerationMac->SetPhy(uPhy);
255 
256  Singleton<SatTopology>::Get()->AddOrbiterUserLayersLora(
257  dev->GetNode(),
258  satId,
259  userBeamId,
260  dev,
261  DynamicCast<LorawanOrbiterMacGateway>(uRegenerationMac),
262  uPhy);
263 
264  break;
265  }
266  default:
267  NS_FATAL_ERROR("Regeneration mode unknown");
268  }
269 
270  if (Singleton<SatTopology>::Get()->GetReturnLinkRegenerationMode() != SatEnums::TRANSPARENT)
271  {
272  uPhy->BeginEndScheduling();
273  uPhy->SetSendControlMsgToFeederCallback(
274  MakeCallback(&SatOrbiterNetDevice::SendControlMsgToFeeder, dev));
275  }
276 }
277 
278 } // namespace ns3
virtual void Receive(SatPhy::PacketContainer_t packets, Ptr< SatSignalParameters >)=0
Receive a packet from the lower layer.
A configuration class for the satellite reference system.
void SetConf(Ptr< LorawanMacGateway > gatewayMac)
Callback< Ptr< SatControlMessage >, uint32_t > ReadCtrlMsgCallback
Callback to read control messages from container storing control messages.
Keep track of the current position and velocity of an object in satellite network.
Creates needed objects for Satellite node like SatorbiterNetDevice objects.
Ptr< SatLinkResults > m_rtnLinkResults
Return channel link results (DVB-RCS2) are created if ErrorModel is configured to be AVI.
RandomAccessSettings_s m_raSettings
The used random access model settings.
std::vector< uint32_t > m_nodeIds
Satellites node id.
SatPhy::ErrorModel m_rtnErrorModel
Ptr< SatSuperframeSeq > m_superframeSeq
Superframe sequence.
SatPhy::InterferenceModel m_daRtnLinkInterferenceModel
SatTypedefs::CarrierBandwidthConverter_t m_carrierBandwidthConverter
SatMac::ReadCtrlMsgCallback m_rtnReadCtrlCb
Control return link messages callback.
static TypeId GetTypeId(void)
Get the type ID.
virtual Ptr< SatOrbiterNetDevice > CreateOrbiterNetDevice()
Create a SatOrbiterNetDevice instance, with correct type infered from child classes.
virtual void AttachChannelsUser(Ptr< SatOrbiterNetDevice > dev, Ptr< SatChannel > uf, Ptr< SatChannel > ur, Ptr< SatAntennaGainPattern > userAgp, Ptr< SatNcc > ncc, uint32_t satId, uint32_t userBeamId)
virtual bool SendControlMsgToFeeder(Ptr< SatControlMessage > msg, const Address &dest, Ptr< SatSignalParameters > rxParams)=0
Send a control packet on the feeder link.
void ReceiveUser(SatPhy::PacketContainer_t packets, Ptr< SatSignalParameters > rxParams)
Receive the packet from the lower layers.
SatOrbiterNetDeviceLora to be utilized in geostationary satellite.
Callback< void, PacketContainer_t, Ptr< SatSignalParameters > > ReceiveCallback
Definition: satellite-phy.h:85
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_raRtnInterferenceModel
SatPhyRxCarrierConf::RandomAccessCollisionModel m_raCollisionModel
SatPhyRxCarrierConf::InterferenceEliminationModel m_raInterferenceEliminationModel
Creation parameters for base PHY object.
Ptr< SatChannel > m_rxCh
Ptr< NetDevice > m_device
Ptr< SatChannel > m_txCh
SatEnums::SatLoraNodeType_t m_standard