satellite-gw-helper-dvb.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 <ns3/log.h>
25 #include <ns3/pointer.h>
26 #include <ns3/satellite-channel-estimation-error-container.h>
27 #include <ns3/satellite-channel.h>
28 #include <ns3/satellite-const-variables.h>
29 #include <ns3/satellite-enums.h>
30 #include <ns3/satellite-fwd-link-scheduler-default.h>
31 #include <ns3/satellite-fwd-link-scheduler-time-slicing.h>
32 #include <ns3/satellite-fwd-link-scheduler.h>
33 #include <ns3/satellite-gw-llc.h>
34 #include <ns3/satellite-gw-mac.h>
35 #include <ns3/satellite-gw-phy.h>
36 #include <ns3/satellite-id-mapper.h>
37 #include <ns3/satellite-link-results.h>
38 #include <ns3/satellite-lorawan-net-device.h>
39 #include <ns3/satellite-lower-layer-service.h>
40 #include <ns3/satellite-net-device.h>
41 #include <ns3/satellite-node-info.h>
42 #include <ns3/satellite-orbiter-net-device.h>
43 #include <ns3/satellite-packet-classifier.h>
44 #include <ns3/satellite-phy-rx-carrier-conf.h>
45 #include <ns3/satellite-topology.h>
46 #include <ns3/satellite-typedefs.h>
47 #include <ns3/singleton.h>
48 
49 NS_LOG_COMPONENT_DEFINE("SatGwHelperDvb");
50 
51 namespace ns3
52 {
53 
54 void
55 logonCallbackHelper(Ptr<SatNcc> ncc,
56  Ptr<SatLowerLayerServiceConf> llsConf,
57  Address utId,
58  uint32_t satId,
59  uint32_t beamId,
60  Callback<void, uint32_t> setRaChannelCallback)
61 {
62  ncc->AddUt(llsConf, utId, satId, beamId, setRaChannelCallback, true);
63 }
64 
65 NS_OBJECT_ENSURE_REGISTERED(SatGwHelperDvb);
66 
67 TypeId
69 {
70  static TypeId tid =
71  TypeId("ns3::SatGwHelperDvb").SetParent<SatGwHelper>().AddConstructor<SatGwHelperDvb>();
72  return tid;
73 }
74 
75 TypeId
77 {
78  return GetTypeId();
79 }
80 
82 {
83  // this default constructor should be never called
84  NS_FATAL_ERROR("Default constructor not supported!!!");
85 }
86 
88  uint32_t rtnLinkCarrierCount,
89  Ptr<SatSuperframeSeq> seq,
93  RandomAccessSettings_s randomAccessSettings)
94  : SatGwHelper(carrierBandwidthConverter,
95  rtnLinkCarrierCount,
96  seq,
97  readCb,
98  reserveCb,
99  sendCb,
100  randomAccessSettings)
101 {
102  NS_LOG_FUNCTION(this << rtnLinkCarrierCount << seq);
103 }
104 
105 Ptr<NetDevice>
107  uint32_t gwId,
108  uint32_t satId,
109  uint32_t beamId,
110  uint32_t feederSatId,
111  uint32_t feederBeamId,
112  Ptr<SatChannel> fCh,
113  Ptr<SatChannel> rCh,
115  Ptr<SatNcc> ncc,
116  Ptr<SatLowerLayerServiceConf> llsConf)
117 {
118  NS_LOG_FUNCTION(this << n << gwId << satId << beamId << fCh << rCh << ncc << llsConf);
119 
120  NetDeviceContainer container;
121 
122  // Create SatNetDevice
123  Ptr<SatNetDevice> dev;
124  switch (Singleton<SatTopology>::Get()->GetStandard())
125  {
126  case SatEnums::DVB: {
127  m_deviceFactory.SetTypeId("ns3::SatNetDevice");
128  dev = m_deviceFactory.Create<SatNetDevice>();
129  break;
130  }
131  case SatEnums::LORA: {
132  m_deviceFactory.SetTypeId("ns3::SatLorawanNetDevice");
133  dev = m_deviceFactory.Create<SatLorawanNetDevice>();
134  break;
135  }
136  default:
137  NS_FATAL_ERROR("Incorrect standard chosen");
138  }
139 
140  // Attach the SatNetDevices to nodes
141  n->AddDevice(dev);
142 
143  SatPhy::CreateParam_t params;
144  params.m_satId = satId;
145  params.m_beamId = beamId;
146  params.m_device = dev;
147  params.m_txCh = fCh;
148  params.m_rxCh = rCh;
149  params.m_standard = SatEnums::DVB_GW;
150 
151  // Create a packet classifier
152  Ptr<SatPacketClassifier> classifier = Create<SatPacketClassifier>();
153 
157  Ptr<SatChannelEstimationErrorContainer> cec;
158  // Not enabled, create only base class
160  {
161  cec = Create<SatSimpleChannelEstimationErrorContainer>();
162  }
163  // Create SatFwdLinkChannelEstimationErrorContainer
164  else
165  {
166  uint32_t minWfId = m_superframeSeq->GetWaveformConf()->GetMinWfId();
167  uint32_t maxWfId = m_superframeSeq->GetWaveformConf()->GetMaxWfId();
168  if (Singleton<SatTopology>::Get()->GetReturnLinkRegenerationMode() ==
170  Singleton<SatTopology>::Get()->GetReturnLinkRegenerationMode() ==
172  {
173  cec = Create<SatRtnLinkChannelEstimationErrorContainer>(minWfId, maxWfId);
174  }
175  else
176  {
177  cec = Create<SatFwdLinkChannelEstimationErrorContainer>();
178  }
179  }
180 
181  SatPhyRxCarrierConf::RxCarrierCreateParams_s parameters =
182  SatPhyRxCarrierConf::RxCarrierCreateParams_s();
183  parameters.m_errorModel = m_errorModel;
184  parameters.m_daConstantErrorRate = m_daConstantErrorRate;
185  parameters.m_daIfModel = m_daInterferenceModel;
186  parameters.m_raIfModel = m_raSettings.m_raInterferenceModel;
187  parameters.m_raIfEliminateModel = m_raSettings.m_raInterferenceEliminationModel;
188  parameters.m_linkRegenerationMode =
189  Singleton<SatTopology>::Get()->GetReturnLinkRegenerationMode();
190  parameters.m_bwConverter = m_carrierBandwidthConverter;
191  parameters.m_carrierCount = m_rtnLinkCarrierCount;
192  parameters.m_cec = cec;
193  parameters.m_raCollisionModel = m_raSettings.m_raCollisionModel;
194  parameters.m_raConstantErrorRate = m_raSettings.m_raConstantErrorRate;
195  parameters.m_randomAccessModel = m_raSettings.m_randomAccessModel;
196 
197  Ptr<SatGwPhy> phy = CreateObject<SatGwPhy>(
198  params,
200  parameters,
202  phy->SetChannelPairGetterCallback(cbChannel);
203 
204  ncc->SetUseLogon(m_superframeSeq->GetSuperframeConf(SatConstVariables::SUPERFRAME_SEQUENCE)
205  ->IsLogonEnabled());
206 
207  // Set fading
208  phy->SetTxFadingContainer(n->GetObject<SatBaseFading>());
209  phy->SetRxFadingContainer(n->GetObject<SatBaseFading>());
210 
211  Ptr<SatGwMac> mac = CreateObject<SatGwMac>(n, satId, beamId, feederSatId, feederBeamId);
212 
213  // Set the control message container callbacks
214  mac->SetReadCtrlCallback(m_readCtrlCb);
215  mac->SetReserveCtrlCallback(m_reserveCtrlCb);
216  mac->SetSendCtrlCallback(m_sendCtrlCb);
217 
218  mac->SetCrReceiveCallback(MakeCallback(&SatNcc::UtCrReceived, ncc));
219 
220  mac->SetHandoverCallback(MakeCallback(&SatNcc::MoveUtBetweenBeams, ncc));
221 
222  // Attach the Mac layer receiver to Phy
223  SatPhy::ReceiveCallback recCb = MakeCallback(&SatGwMac::Receive, mac);
224 
225  // Attach the NCC C/N0 update to Phy
226  SatPhy::CnoCallback cnoCb = MakeCallback(&SatNcc::UtCnoUpdated, ncc);
227 
228  // Attach the NCC random access load update to Phy
229  SatPhy::AverageNormalizedOfferedLoadCallback avgNormalizedOfferedLoadCb =
230  MakeCallback(&SatNcc::DoRandomAccessDynamicLoadControl, ncc);
231 
232  phy->SetAttribute("ReceiveCb", CallbackValue(recCb));
233  phy->SetAttribute("CnoCb", CallbackValue(cnoCb));
234  phy->SetAttribute("AverageNormalizedOfferedLoadCallback",
235  CallbackValue(avgNormalizedOfferedLoadCb));
236 
237  // Attach the PHY layer to SatNetDevice
238  dev->SetPhy(phy);
239 
240  // Attach the Mac layer to SatNetDevice
241  dev->SetMac(mac);
242 
243  // Create Logical Link Control (LLC) layer
244  Ptr<SatGwLlc> llc = CreateObject<SatGwLlc>();
245 
246  // Set the control msg read callback to LLC due to ARQ ACKs
247  llc->SetReadCtrlCallback(m_readCtrlCb);
248 
249  if (Singleton<SatTopology>::Get()->GetForwardLinkRegenerationMode() != SatEnums::TRANSPARENT &&
250  Singleton<SatTopology>::Get()->GetForwardLinkRegenerationMode() !=
252  {
253  llc->SetAdditionalHeaderSize(SatAddressE2ETag::SIZE);
254  }
255 
256  // Attach the LLC layer to SatNetDevice
257  dev->SetLlc(llc);
258 
259  // Attach the packet classifier
260  dev->SetPacketClassifier(classifier);
261 
262  // Attach the device receive callback to SatNetDevice
263  llc->SetReceiveCallback(MakeCallback(&SatNetDevice::Receive, dev));
264 
265  // Attach the transmit callback to PHY
266  mac->SetTransmitCallback(MakeCallback(&SatPhy::SendPdu, phy));
267 
268  // Attach the device receive callback to SatLlc
269  mac->SetReceiveCallback(MakeCallback(&SatLlc::Receive, llc));
270 
271  // Attach the logon receive callback to SatNcc
272  mac->SetLogonCallback(MakeBoundCallback(&logonCallbackHelper, ncc, llsConf));
273 
274  // Attach the beam handover callback to SatPhy
275  mac->SetBeamCallback(MakeCallback(&SatGwPhy::PerformHandover, phy));
276 
277  // Attach the control burst receive callback to SatNcc
278  mac->SetControlMessageReceivedCallback(MakeCallback(&SatNcc::ReceiveControlBurst, ncc));
279 
280  // Attach the remove UT to SatNcc
281  mac->SetRemoveUtCallback(MakeCallback(&SatNcc::RemoveUt, ncc));
282 
283  // Set the device address and pass it to MAC as well
284  Mac48Address addr = Mac48Address::Allocate();
285  dev->SetAddress(addr);
286 
287  Singleton<SatIdMapper>::Get()->AttachMacToTraceId(dev->GetAddress());
288  Singleton<SatIdMapper>::Get()->AttachMacToGwId(dev->GetAddress(), gwId);
289  Singleton<SatIdMapper>::Get()->AttachMacToBeamId(dev->GetAddress(), beamId);
290  Singleton<SatIdMapper>::Get()->AttachMacToSatId(dev->GetAddress(), satId + 1);
291 
292  // Create an encapsulator for control messages.
293  // Source = GW address
294  // Destination = broadcast address
295  // Flow id = by default 0
296  Ptr<SatQueue> queue = CreateObject<SatQueue>(SatEnums::CONTROL_FID);
297  Ptr<SatBaseEncapsulator> gwEncap =
298  CreateObject<SatBaseEncapsulator>(addr,
299  Mac48Address::GetBroadcast(),
300  addr,
301  Mac48Address::GetBroadcast(),
303  gwEncap->SetQueue(queue);
304  llc->AddEncap(addr, Mac48Address::GetBroadcast(), SatEnums::CONTROL_FID, gwEncap);
305  llc->SetCtrlMsgCallback(MakeCallback(&SatNetDevice::SendControlMsg, dev));
306 
307  phy->Initialize();
308 
309  // Create a node info to all the protocol layers
310  Ptr<SatNodeInfo> nodeInfo = Create<SatNodeInfo>(SatEnums::NT_GW, n->GetId(), addr);
311  dev->SetNodeInfo(nodeInfo);
312  llc->SetNodeInfo(nodeInfo);
313  mac->SetNodeInfo(nodeInfo);
314  phy->SetNodeInfo(nodeInfo);
315 
316  // Begin frame end scheduling for processes utilizing frame length as interval
317  // Node info needs to be set before the start in order to get the scheduling context correctly
318  // set
319  if (Singleton<SatTopology>::Get()->GetReturnLinkRegenerationMode() == SatEnums::TRANSPARENT)
320  {
321  phy->BeginEndScheduling();
322  }
323 
324  // TODO: When multiple carriers are supported. Multiple scheduler are needed too.
325  double carrierBandwidth =
327 
328  Ptr<SatFwdLinkScheduler> fwdLinkScheduler;
329  switch (m_fwdSchedulingAlgorithm)
330  {
332  fwdLinkScheduler =
333  CreateObject<SatFwdLinkSchedulerDefault>(m_bbFrameConf, addr, carrierBandwidth);
334  break;
336  fwdLinkScheduler =
337  CreateObject<SatFwdLinkSchedulerTimeSlicing>(m_bbFrameConf, addr, carrierBandwidth);
338  break;
339  default:
340  NS_FATAL_ERROR("Forward scheduling algorithm is not implemented");
341  }
342 
343  fwdLinkScheduler->SetSendControlMsgCallback(MakeCallback(&SatNetDevice::SendControlMsg, dev));
344 
345  // Attach the LLC Tx opportunity and scheduling context getter callbacks to SatFwdLinkScheduler
346  fwdLinkScheduler->SetTxOpportunityCallback(MakeCallback(&SatGwLlc::NotifyTxOpportunity, llc));
347  fwdLinkScheduler->SetSchedContextCallback(MakeCallback(&SatLlc::GetSchedulingContexts, llc));
348 
349  // set scheduler to Mac
350  mac->SetFwdScheduler(fwdLinkScheduler);
351 
352  mac->SetClearQueuesCallback(MakeCallback(&SatGwLlc::ClearQueues, llc));
353  mac->StartPeriodicTransmissions();
354 
355  Ptr<SatHandoverModule> handoverModule = n->GetObject<SatHandoverModule>();
356  if (handoverModule != nullptr)
357  {
358  handoverModule->SetHandoverRequestCallback(MakeCallback(&SatGwMac::ChangeBeam, mac));
359  mac->SetBeamSchedulerCallback(MakeCallback(&SatNcc::GetBeamScheduler, ncc));
360  mac->SetHandoverModule(handoverModule);
361  }
362 
363  Singleton<SatTopology>::Get()
364  ->AddGwLayersDvb(n, feederSatId, feederBeamId, satId, beamId, dev, llc, mac, phy);
365 
366  return dev;
367 }
368 
369 } // namespace ns3
static const uint32_t SIZE
Base class for fading models such as Markov-based fading or fading trace.
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)
SatGwHelperDvb()
Default constructor.
TypeId GetInstanceTypeId(void) const
static TypeId GetTypeId(void)
Get the type ID.
Creates needed objects for GW nodes like SatOrbiterNetDevice objects.
Ptr< SatSuperframeSeq > m_superframeSeq
SatPhy::ErrorModel m_errorModel
SatMac::SendCtrlMsgCallback m_sendCtrlCb
RandomAccessSettings_s m_raSettings
The used random access model settings.
SatEnums::FwdSchedulingAlgorithm_t m_fwdSchedulingAlgorithm
The forward link algorithm used.
bool m_enableChannelEstimationError
Enable channel estimation error modeling at forward link receiver (= UT).
SatMac::ReadCtrlMsgCallback m_readCtrlCb
ObjectFactory m_deviceFactory
Ptr< SatBbFrameConf > m_bbFrameConf
Ptr< SatLinkResults > m_linkResults
SatMac::ReserveCtrlMsgCallback m_reserveCtrlCb
SatPhy::InterferenceModel m_daInterferenceModel
SatTypedefs::CarrierBandwidthConverter_t m_carrierBandwidthConverter
virtual Ptr< Packet > NotifyTxOpportunity(uint32_t bytes, Mac48Address utAddr, uint8_t flowId, uint32_t &bytesLeft, uint32_t &nextMinTxO)
Called from lower layer (MAC) to inform a tx opportunity of certain amount of bytes.
virtual void ClearQueues()
Remove all packets from the queues.
void ChangeBeam(uint32_t satId, uint32_t beamId)
Method handling beam handover.
void Receive(SatPhy::PacketContainer_t packets, Ptr< SatSignalParameters >)
Receive packet from lower layer.
void PerformHandover(uint32_t satId, uint32_t beamId)
Change underlying SatChannel to send and receive data from a new satellite and beam.
void SetHandoverRequestCallback(SatHandoverModule::HandoverRequestCallback cb)
Set the handover recommendation message sending callback.
virtual void GetSchedulingContexts(std::vector< Ptr< SatSchedulingObject >> &output) const =0
Create and fill the scheduling objects based on LLC layer information.
virtual void Receive(Ptr< Packet > packet, Mac48Address source, Mac48Address dest)
Receive user data packet from lower layer.
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 ReceiveControlBurst(Address utId, uint32_t satId, uint32_t beamId)
Function to call when a control burst has been received.
void RemoveUt(Address utId, uint32_t satId, uint32_t beamId)
Remove a UT.
void MoveUtBetweenBeams(Address utId, uint32_t srcSatId, uint32_t srcBeamId, uint32_t destSatId, uint32_t destBeamId)
Check if a terminal can be moved between two beams.
void UtCrReceived(uint32_t satId, uint32_t beamId, Address utId, Ptr< SatCrMessage > crMsg)
Capacity request receiver.
Ptr< SatBeamScheduler > GetBeamScheduler(uint32_t satId, uint32_t beamId) const
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.
SatNetDevice to be utilized in the UT and GW nodes.
virtual void Receive(Ptr< const Packet > packet)
bool SendControlMsg(Ptr< SatControlMessage > msg, const Address &dest)
Callback< void, uint32_t, uint32_t, Address, Address, double, bool > CnoCallback
Definition: satellite-phy.h:94
virtual void SendPdu(PacketContainer_t, uint32_t carrierId, Time duration, SatSignalParameters::txInfo_s txInfo)
Send Pdu to the PHY tx module (for initial transmissions from either UT or GW)
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.
void logonCallbackHelper(Ptr< SatNcc > ncc, Ptr< SatLowerLayerServiceConf > llsConf, Address utId, uint32_t satId, uint32_t beamId, Callback< void, uint32_t > setRaChannelCallback)
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