satellite-ut-helper.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 
23 #include "satellite-ut-helper.h"
24 
25 #include <ns3/callback.h>
26 #include <ns3/config.h>
27 #include <ns3/double.h>
28 #include <ns3/enum.h>
29 #include <ns3/log.h>
30 #include <ns3/lorawan-mac-end-device-class-a.h>
31 #include <ns3/names.h>
32 #include <ns3/nstime.h>
33 #include <ns3/pointer.h>
34 #include <ns3/satellite-base-encapsulator.h>
35 #include <ns3/satellite-channel-estimation-error-container.h>
36 #include <ns3/satellite-channel.h>
37 #include <ns3/satellite-const-variables.h>
38 #include <ns3/satellite-enums.h>
39 #include <ns3/satellite-generic-stream-encapsulator-arq.h>
40 #include <ns3/satellite-generic-stream-encapsulator.h>
41 #include <ns3/satellite-gw-llc.h>
42 #include <ns3/satellite-id-mapper.h>
43 #include <ns3/satellite-lora-conf.h>
44 #include <ns3/satellite-lorawan-net-device.h>
45 #include <ns3/satellite-mac-tag.h>
46 #include <ns3/satellite-mobility-observer.h>
47 #include <ns3/satellite-net-device.h>
48 #include <ns3/satellite-node-info.h>
49 #include <ns3/satellite-packet-classifier.h>
50 #include <ns3/satellite-phy-rx-carrier-conf.h>
51 #include <ns3/satellite-phy-rx.h>
52 #include <ns3/satellite-phy-tx.h>
53 #include <ns3/satellite-queue.h>
54 #include <ns3/satellite-request-manager.h>
55 #include <ns3/satellite-return-link-encapsulator-arq.h>
56 #include <ns3/satellite-return-link-encapsulator.h>
57 #include <ns3/satellite-typedefs.h>
58 #include <ns3/satellite-ut-handover-module.h>
59 #include <ns3/satellite-ut-llc.h>
60 #include <ns3/satellite-ut-mac.h>
61 #include <ns3/satellite-ut-phy.h>
62 #include <ns3/satellite-ut-scheduler.h>
63 #include <ns3/satellite-utils.h>
64 #include <ns3/singleton.h>
65 #include <ns3/string.h>
66 #include <ns3/uinteger.h>
67 
68 NS_LOG_COMPONENT_DEFINE("SatUtHelper");
69 
70 namespace ns3
71 {
72 
73 NS_OBJECT_ENSURE_REGISTERED(SatUtHelper);
74 
75 TypeId
77 {
78  static TypeId tid =
79  TypeId("ns3::SatUtHelper")
80  .SetParent<Object>()
81  .AddConstructor<SatUtHelper>()
82  .AddAttribute("DaFwdLinkInterferenceModel",
83  "Forward link interference model for dedicated access",
85  MakeEnumAccessor(&SatUtHelper::m_daInterferenceModel),
86  MakeEnumChecker(SatPhyRxCarrierConf::IF_CONSTANT,
87  "Constant",
89  "Trace",
91  "PerPacket",
93  "PerFragment"))
94  .AddAttribute("FwdLinkErrorModel",
95  "Forward link error model",
96  EnumValue(SatPhyRxCarrierConf::EM_AVI),
97  MakeEnumAccessor(&SatUtHelper::m_errorModel),
98  MakeEnumChecker(SatPhyRxCarrierConf::EM_NONE,
99  "None",
101  "Constant",
103  "AVI"))
104  .AddAttribute("FwdLinkConstantErrorRate",
105  "Constant error rate",
106  DoubleValue(0.01),
107  MakeDoubleAccessor(&SatUtHelper::m_daConstantErrorRate),
108  MakeDoubleChecker<double>())
109  .AddAttribute("LowerLayerServiceConf",
110  "Pointer to lower layer service configuration.",
111  PointerValue(),
112  MakePointerAccessor(&SatUtHelper::m_llsConf),
113  MakePointerChecker<SatLowerLayerServiceConf>())
114  .AddAttribute("EnableChannelEstimationError",
115  "Enable channel estimation error in forward link receiver at UT.",
116  BooleanValue(true),
117  MakeBooleanAccessor(&SatUtHelper::m_enableChannelEstimationError),
118  MakeBooleanChecker())
119  .AddAttribute("UseCrdsaOnlyForControlPackets",
120  "CRDSA utilized only for control packets or also for user data.",
121  BooleanValue(false),
122  MakeBooleanAccessor(&SatUtHelper::m_crdsaOnlyForControl),
123  MakeBooleanChecker())
124  .AddAttribute("AsynchronousReturnAccess",
125  "Use asynchronous access methods on the return channel.",
126  BooleanValue(false),
127  MakeBooleanAccessor(&SatUtHelper::m_asyncAccess),
128  MakeBooleanChecker())
129  .AddTraceSource("Creation",
130  "Creation traces",
131  MakeTraceSourceAccessor(&SatUtHelper::m_creationTrace),
132  "ns3::SatTypedefs::CreationCallback");
133  return tid;
134 }
135 
136 TypeId
138 {
139  NS_LOG_FUNCTION(this);
140 
141  return GetTypeId();
142 }
143 
145  : m_carrierBandwidthConverter(),
146  m_fwdLinkCarrierCount(),
147  m_superframeSeq(),
148  m_daInterferenceModel(SatPhyRxCarrierConf::IF_CONSTANT),
149  m_errorModel(SatPhyRxCarrierConf::EM_AVI),
150  m_daConstantErrorRate(0.0),
151  m_linkResults(),
152  m_llsConf(),
153  m_enableChannelEstimationError(false),
154  m_crdsaOnlyForControl(false),
155  m_asyncAccess(false),
156  m_raSettings()
157 {
158  NS_LOG_FUNCTION(this);
159 
160  // this default constructor should be never called
161  NS_FATAL_ERROR("SatUtHelper::SatUtHelper - Constructor not in use");
162 }
163 
165  uint32_t fwdLinkCarrierCount,
166  Ptr<SatSuperframeSeq> seq,
170  RandomAccessSettings_s randomAccessSettings)
171  : m_carrierBandwidthConverter(carrierBandwidthConverter),
172  m_fwdLinkCarrierCount(fwdLinkCarrierCount),
173  m_superframeSeq(seq),
174  m_readCtrlCb(readCb),
175  m_reserveCtrlCb(reserveCb),
176  m_sendCtrlCb(sendCb),
177  m_daInterferenceModel(SatPhyRxCarrierConf::IF_CONSTANT),
178  m_errorModel(SatPhyRxCarrierConf::EM_AVI),
179  m_daConstantErrorRate(0.0),
180  m_linkResults(),
181  m_llsConf(),
182  m_enableChannelEstimationError(false),
183  m_crdsaOnlyForControl(false),
184  m_raSettings(randomAccessSettings)
185 {
186  NS_LOG_FUNCTION(this << fwdLinkCarrierCount << seq);
187  m_deviceFactory.SetTypeId("ns3::SatNetDevice");
188  m_channelFactory.SetTypeId("ns3::SatChannel");
189 
190  m_llsConf = CreateObject<SatLowerLayerServiceConf>();
191 }
192 
193 void
194 SatUtHelper::Initialize(Ptr<SatLinkResultsFwd> lrFwd)
195 {
196  NS_LOG_FUNCTION(this);
197  /*
198  * Forward channel link results (DVB-S2 or DVB-S2X) are created for UTs.
199  */
201  {
202  m_linkResults = lrFwd;
203  }
204 }
205 
206 void
207 SatUtHelper::SetDeviceAttribute(std::string n1, const AttributeValue& v1)
208 {
209  NS_LOG_FUNCTION(this << n1);
210 
211  m_deviceFactory.Set(n1, v1);
212 }
213 
214 void
215 SatUtHelper::SetChannelAttribute(std::string n1, const AttributeValue& v1)
216 {
217  NS_LOG_FUNCTION(this << n1);
218 
219  m_channelFactory.Set(n1, v1);
220 }
221 
222 void
223 SatUtHelper::SetPhyAttribute(std::string n1, const AttributeValue& v1)
224 {
225  NS_LOG_FUNCTION(this << n1);
226 
227  Config::SetDefault("ns3::SatUtPhy::" + n1, v1);
228 }
229 
230 NetDeviceContainer
231 SatUtHelper::InstallDvb(NodeContainer c,
232  uint32_t satId,
233  uint32_t beamId,
234  Ptr<SatChannel> fCh,
235  Ptr<SatChannel> rCh,
236  Ptr<SatNetDevice> gwNd,
237  Ptr<SatNcc> ncc,
238  Address satUserAddress,
241  SatEnums::RegenerationMode_t forwardLinkRegenerationMode,
242  SatEnums::RegenerationMode_t returnLinkRegenerationMode)
243 {
244  NS_LOG_FUNCTION(this << beamId << fCh << rCh);
245 
246  NetDeviceContainer devs;
247 
248  for (NodeContainer::Iterator i = c.Begin(); i != c.End(); i++)
249  {
250  devs.Add(InstallDvb(*i,
251  satId,
252  beamId,
253  fCh,
254  rCh,
255  gwNd,
256  ncc,
257  satUserAddress,
258  cbChannel,
259  cbRouting,
260  forwardLinkRegenerationMode,
261  returnLinkRegenerationMode));
262  }
263 
264  return devs;
265 }
266 
267 Ptr<NetDevice>
269  uint32_t satId,
270  uint32_t beamId,
271  Ptr<SatChannel> fCh,
272  Ptr<SatChannel> rCh,
273  Ptr<SatNetDevice> gwNd,
274  Ptr<SatNcc> ncc,
275  Address satUserAddress,
278  SatEnums::RegenerationMode_t forwardLinkRegenerationMode,
279  SatEnums::RegenerationMode_t returnLinkRegenerationMode)
280 {
281  NS_LOG_FUNCTION(this << n << beamId << fCh << rCh);
282 
283  NetDeviceContainer container;
284 
285  // Create SatNetDevice
286  m_deviceFactory.SetTypeId("ns3::SatNetDevice");
287  Ptr<SatNetDevice> dev = m_deviceFactory.Create<SatNetDevice>();
288 
289  // Attach the SatNetDevice to node
290  n->AddDevice(dev);
291 
292  SatPhy::CreateParam_t params;
293  params.m_satId = satId;
294  params.m_beamId = beamId;
295  params.m_device = dev;
296  params.m_txCh = rCh;
297  params.m_rxCh = fCh;
298  params.m_standard = SatEnums::DVB_UT;
299 
300  // Create a packet classifier
301  Ptr<SatPacketClassifier> classifier = Create<SatPacketClassifier>();
302 
306  Ptr<SatChannelEstimationErrorContainer> cec;
307  // Not enabled, create only base class
309  {
310  cec = Create<SatSimpleChannelEstimationErrorContainer>();
311  }
312  // Create SatFwdLinkChannelEstimationErrorContainer
313  else
314  {
315  cec = Create<SatFwdLinkChannelEstimationErrorContainer>();
316  }
317 
318  SatPhyRxCarrierConf::RxCarrierCreateParams_s parameters =
319  SatPhyRxCarrierConf::RxCarrierCreateParams_s();
320  parameters.m_errorModel = m_errorModel;
321  parameters.m_daConstantErrorRate = m_daConstantErrorRate;
322  parameters.m_daIfModel = m_daInterferenceModel;
323  parameters.m_raIfModel = m_raSettings.m_raInterferenceModel;
324  parameters.m_raIfEliminateModel = m_raSettings.m_raInterferenceEliminationModel;
325  parameters.m_linkRegenerationMode = forwardLinkRegenerationMode;
326  parameters.m_bwConverter = m_carrierBandwidthConverter;
327  parameters.m_carrierCount = m_fwdLinkCarrierCount;
328  parameters.m_cec = cec;
329  parameters.m_raCollisionModel = m_raSettings.m_raCollisionModel;
330  parameters.m_randomAccessModel = m_raSettings.m_randomAccessModel;
331 
332  Ptr<SatUtPhy> phy = CreateObject<SatUtPhy>(
333  params,
335  parameters,
337  forwardLinkRegenerationMode);
338  phy->SetChannelPairGetterCallback(cbChannel);
339 
340  // Set fading
341  phy->SetTxFadingContainer(n->GetObject<SatBaseFading>());
342  phy->SetRxFadingContainer(n->GetObject<SatBaseFading>());
343 
344  Ptr<SatUtMac> mac = CreateObject<SatUtMac>(satId,
345  beamId,
347  forwardLinkRegenerationMode,
348  returnLinkRegenerationMode,
350 
351  // Set the control message container callbacks
352  mac->SetReadCtrlCallback(m_readCtrlCb);
353  mac->SetReserveCtrlCallback(m_reserveCtrlCb);
354  mac->SetSendCtrlCallback(m_sendCtrlCb);
355 
356  // Set timing advance callback to mac (if not asynchronous access)
358  {
359  Ptr<SatMobilityObserver> observer = n->GetObject<SatMobilityObserver>();
360  NS_ASSERT(observer != NULL);
361 
363  MakeCallback(&SatMobilityObserver::GetTimingAdvance, observer);
364  mac->SetTimingAdvanceCallback(timingCb);
365  }
366 
367  // Attach the Mac layer receiver to Phy
368  SatPhy::ReceiveCallback recCb = MakeCallback(&SatUtMac::Receive, mac);
369 
370  phy->SetAttribute("ReceiveCb", CallbackValue(recCb));
371  mac->SetTxCheckCallback(MakeCallback(&SatUtPhy::IsTxPossible, phy));
372 
373  // Create callback to inform phy layer slices subscription
374  mac->SetSliceSubscriptionCallback(MakeCallback(&SatUtPhy::UpdateSliceSubscription, phy));
375 
376  // Create Logical Link Control (LLC) layer
377  Ptr<SatUtLlc> llc =
378  CreateObject<SatUtLlc>(forwardLinkRegenerationMode, returnLinkRegenerationMode);
379 
380  // Set the control msg read callback to LLC due to ARQ ACKs
381  llc->SetReadCtrlCallback(m_readCtrlCb);
382 
383  // Create a request manager and attach it to LLC, and set control message callback to RM
384  Ptr<SatRequestManager> rm = CreateObject<SatRequestManager>();
385  llc->SetRequestManager(rm);
386  rm->SetCtrlMsgCallback(MakeCallback(&SatNetDevice::SendControlMsg, dev));
387 
388  if (returnLinkRegenerationMode != SatEnums::TRANSPARENT &&
389  returnLinkRegenerationMode != SatEnums::REGENERATION_PHY)
390  {
391  llc->SetAdditionalHeaderSize(SatAddressE2ETag::SIZE);
392  rm->SetHeaderOffsetVbdc(38.0 / (38 - 2 - SatAddressE2ETag::SIZE));
393  }
394 
395  // Set the callback to check whether control msg transmissions are possible
396  rm->SetCtrlMsgTxPossibleCallback(MakeCallback(&SatUtMac::ControlMsgTransmissionPossible, mac));
397 
398  // Set the callback to check whether logon msg transmissions are possible
399  rm->SetLogonMsgTxPossibleCallback(MakeCallback(&SatUtMac::LogonMsgTransmissionPossible, mac));
400 
401  // Set TBTP callback to UT MAC
402  mac->SetAssignedDaResourcesCallback(MakeCallback(&SatRequestManager::AssignedDaResources, rm));
403 
404  // Set Send Logon callback to UT MAC
405  mac->SetSendLogonCallback(MakeCallback(&SatRequestManager::SendLogonMessage, rm));
406 
407  // Attach the PHY layer to SatNetDevice
408  dev->SetPhy(phy);
409 
410  // Attach the Mac layer to SatNetDevice
411  dev->SetMac(mac);
412 
413  // Attach the LLC layer to SatNetDevice
414  dev->SetLlc(llc);
415 
416  // Attach the packet classifier
417  dev->SetPacketClassifier(classifier);
418 
419  // Attach the Mac layer C/N0 updates receiver to Phy
420  SatPhy::CnoCallback cnoCb = MakeCallback(&SatRequestManager::CnoUpdated, rm);
421  phy->SetAttribute("CnoCb", CallbackValue(cnoCb));
422 
423  // Set the device address and pass it to MAC as well
424  Mac48Address addr = Mac48Address::Allocate();
425  dev->SetAddress(addr);
426 
427  Singleton<SatIdMapper>::Get()->AttachMacToTraceId(dev->GetAddress());
428  Singleton<SatIdMapper>::Get()->AttachMacToUtId(dev->GetAddress());
429  Singleton<SatIdMapper>::Get()->AttachMacToBeamId(dev->GetAddress(), beamId);
430  Singleton<SatIdMapper>::Get()->AttachMacToSatId(dev->GetAddress(), satId + 1);
431 
432  // Create encapsulator and add it to UT's LLC
433  Mac48Address gwAddr = Mac48Address::ConvertFrom(gwNd->GetAddress());
434 
435  // Create an encapsulator for control messages.
436  // Source = UT MAC address
437  // Destination = GW MAC address (or SAT user MAC address if regenerative)
438  // Flow id = by default 0
439  Ptr<SatBaseEncapsulator> utEncap;
440  if (returnLinkRegenerationMode == SatEnums::REGENERATION_NETWORK)
441  {
442  utEncap = CreateObject<SatBaseEncapsulator>(addr,
443  Mac48Address::ConvertFrom(satUserAddress),
444  addr,
445  gwAddr,
447  }
448  else
449  {
450  utEncap =
451  CreateObject<SatBaseEncapsulator>(addr, gwAddr, addr, gwAddr, SatEnums::CONTROL_FID);
452  }
453 
454  // Create queue event callbacks to MAC (for random access) and RM (for on-demand DAMA)
457  {
458  macCb = MakeCallback(&SatUtMac::ReceiveQueueEventEssa, mac);
459  }
460  else
461  {
462  macCb = MakeCallback(&SatUtMac::ReceiveQueueEvent, mac);
463  }
464  SatQueue::LogonCallback logonCb = MakeCallback(&SatUtMac::SendLogon, mac);
466 
467  // Create a queue
468  Ptr<SatQueue> queue = CreateObject<SatQueue>(SatEnums::CONTROL_FID);
469  queue->AddLogonCallback(logonCb);
470  queue->AddQueueEventCallback(macCb);
471  queue->AddQueueEventCallback(rmCb);
472  utEncap->SetQueue(queue);
473  if (returnLinkRegenerationMode == SatEnums::REGENERATION_NETWORK)
474  {
475  llc->AddEncap(addr,
476  Mac48Address::ConvertFrom(satUserAddress),
478  utEncap);
479  }
480  else
481  {
482  llc->AddEncap(addr, gwAddr, SatEnums::CONTROL_FID, utEncap);
483  }
484  rm->AddQueueCallback(SatEnums::CONTROL_FID, MakeCallback(&SatQueue::GetQueueStatistics, queue));
485 
486  // Add callbacks to LLC for future need. LLC creates encapsulators and
487  // decapsulators dynamically 'on-a-need-basis'.
488  llc->SetCtrlMsgCallback(MakeCallback(&SatNetDevice::SendControlMsg, dev));
489  llc->SetMacQueueEventCallback(macCb);
490 
491  // set serving GW MAC address to RM
492  mac->SetRoutingUpdateCallback(cbRouting);
493  mac->SetGatewayUpdateCallback(MakeCallback(&SatUtLlc::SetGwAddress, llc));
494  mac->SetGwAddress(gwAddr);
495 
496  // Attach the transmit callback to PHY
497  mac->SetTransmitCallback(MakeCallback(&SatPhy::SendPdu, phy));
498 
499  // Attach the PHY handover callback to SatMac
500  mac->SetHandoverCallback(MakeCallback(&SatUtPhy::PerformHandover, phy));
501 
502  // Attach the LLC receive callback to SatMac
503  mac->SetReceiveCallback(MakeCallback(&SatLlc::Receive, llc));
504 
505  llc->SetReceiveCallback(MakeCallback(&SatNetDevice::Receive, dev));
506 
507  Ptr<SatSuperframeConf> superFrameConf =
509  bool enableLogon = superFrameConf->IsLogonEnabled();
510  uint32_t logonChannelId = superFrameConf->GetLogonChannelIndex();
511 
512  // Add UT to NCC
513  if (enableLogon)
514  {
515  ncc->ReserveLogonChannel(logonChannelId);
516  }
517  else
518  {
519  ncc->AddUt(m_llsConf,
520  dev->GetAddress(),
521  satId,
522  beamId,
523  MakeCallback(&SatUtMac::SetRaChannel, mac));
524  }
525 
526  phy->Initialize();
527 
528  // Create UT scheduler for MAC and connect callbacks to LLC
529  Ptr<SatUtScheduler> utScheduler = CreateObject<SatUtScheduler>(m_llsConf);
530  utScheduler->SetTxOpportunityCallback(MakeCallback(&SatUtLlc::NotifyTxOpportunity, llc));
531  utScheduler->SetSchedContextCallback(MakeCallback(&SatLlc::GetSchedulingContexts, llc));
532  mac->SetAttribute("Scheduler", PointerValue(utScheduler));
533 
534  // Create a node info to all the protocol layers
535  Ptr<SatNodeInfo> nodeInfo = Create<SatNodeInfo>(SatEnums::NT_UT, n->GetId(), addr);
536  dev->SetNodeInfo(nodeInfo);
537  llc->SetNodeInfo(nodeInfo);
538  mac->SetNodeInfo(nodeInfo);
539  phy->SetNodeInfo(nodeInfo);
540 
541  rm->Initialize(m_llsConf, m_superframeSeq->GetDuration(0));
542 
544  {
545  Ptr<SatRandomAccessConf> randomAccessConf =
546  CreateObject<SatRandomAccessConf>(m_llsConf, m_superframeSeq);
547 
549  Ptr<SatRandomAccess> randomAccess =
550  CreateObject<SatRandomAccess>(randomAccessConf, m_raSettings.m_randomAccessModel);
551 
554  {
555  randomAccess->SetAreBuffersEmptyCallback(
556  MakeCallback(&SatLlc::ControlBuffersEmpty, llc));
557  }
558  else
559  {
560  randomAccess->SetAreBuffersEmptyCallback(MakeCallback(&SatLlc::BuffersEmpty, llc));
561  }
562 
564  mac->SetRandomAccess(randomAccess);
565  if (enableLogon)
566  {
567  mac->SetLogonChannel(logonChannelId);
568  mac->LogOff();
569  }
570  }
571  else if (enableLogon)
572  {
573  NS_FATAL_ERROR("Cannot simulate logon without a RA frame");
574  }
575 
576  Ptr<SatUtHandoverModule> utHandoverModule = n->GetObject<SatUtHandoverModule>();
577  if (utHandoverModule != NULL)
578  {
579  utHandoverModule->SetHandoverRequestCallback(
581  mac->SetBeamCheckerCallback(
582  MakeCallback(&SatUtHandoverModule::CheckForHandoverRecommendation, utHandoverModule));
583  mac->SetAskedBeamCallback(
584  MakeCallback(&SatUtHandoverModule::GetAskedBeamId, utHandoverModule));
585  mac->SetBeamScheculerCallback(MakeCallback(&SatNcc::GetBeamScheduler, ncc));
586  mac->SetUpdateGwAddressCallback(MakeCallback(&SatRequestManager::SetGwAddress, rm));
587  }
588 
589  return dev;
590 }
591 
592 NetDeviceContainer
593 SatUtHelper::InstallLora(NodeContainer c,
594  uint32_t satId,
595  uint32_t beamId,
596  Ptr<SatChannel> fCh,
597  Ptr<SatChannel> rCh,
598  Ptr<SatNetDevice> gwNd,
599  Ptr<SatNcc> ncc,
600  Address satUserAddress,
603  SatEnums::RegenerationMode_t forwardLinkRegenerationMode,
604  SatEnums::RegenerationMode_t returnLinkRegenerationMode)
605 {
606  NS_LOG_FUNCTION(this << beamId << fCh << rCh);
607 
608  NetDeviceContainer devs;
609 
610  for (NodeContainer::Iterator i = c.Begin(); i != c.End(); i++)
611  {
612  devs.Add(InstallLora(*i,
613  satId,
614  beamId,
615  fCh,
616  rCh,
617  gwNd,
618  ncc,
619  satUserAddress,
620  cbChannel,
621  cbRouting,
622  forwardLinkRegenerationMode,
623  returnLinkRegenerationMode));
624  }
625 
626  return devs;
627 }
628 
629 Ptr<NetDevice>
631  uint32_t satId,
632  uint32_t beamId,
633  Ptr<SatChannel> fCh,
634  Ptr<SatChannel> rCh,
635  Ptr<SatNetDevice> gwNd,
636  Ptr<SatNcc> ncc,
637  Address satUserAddress,
640  SatEnums::RegenerationMode_t forwardLinkRegenerationMode,
641  SatEnums::RegenerationMode_t returnLinkRegenerationMode)
642 {
643  NS_LOG_FUNCTION(this << n << beamId << fCh << rCh);
644 
645  NetDeviceContainer container;
646 
647  // Create SatNetDevice
648  m_deviceFactory.SetTypeId("ns3::SatLorawanNetDevice");
649  Ptr<SatLorawanNetDevice> dev = m_deviceFactory.Create<SatLorawanNetDevice>();
650 
651  // Attach the SatNetDevice to node
652  n->AddDevice(dev);
653 
654  SatPhy::CreateParam_t params;
655  params.m_satId = satId;
656  params.m_beamId = beamId;
657  params.m_device = dev;
658  params.m_txCh = rCh;
659  params.m_rxCh = fCh;
660  params.m_standard = SatEnums::LORA_UT;
661 
665  Ptr<SatChannelEstimationErrorContainer> cec;
666  // Not enabled, create only base class
668  {
669  cec = Create<SatSimpleChannelEstimationErrorContainer>();
670  }
671  // Create SatFwdLinkChannelEstimationErrorContainer
672  else
673  {
674  cec = Create<SatFwdLinkChannelEstimationErrorContainer>();
675  }
676 
677  SatPhyRxCarrierConf::RxCarrierCreateParams_s parameters =
678  SatPhyRxCarrierConf::RxCarrierCreateParams_s();
679  parameters.m_errorModel = m_errorModel;
680  parameters.m_daConstantErrorRate = m_daConstantErrorRate;
681  parameters.m_daIfModel = m_daInterferenceModel;
682  parameters.m_raIfModel = m_raSettings.m_raInterferenceModel;
683  parameters.m_raIfEliminateModel = m_raSettings.m_raInterferenceEliminationModel;
684  parameters.m_linkRegenerationMode = forwardLinkRegenerationMode;
685  parameters.m_bwConverter = m_carrierBandwidthConverter;
686  parameters.m_carrierCount = m_fwdLinkCarrierCount;
687  parameters.m_cec = cec;
688  parameters.m_raCollisionModel = m_raSettings.m_raCollisionModel;
689  parameters.m_randomAccessModel = m_raSettings.m_randomAccessModel;
690 
691  Ptr<SatUtPhy> phy = CreateObject<SatUtPhy>(
692  params,
694  parameters,
696  forwardLinkRegenerationMode);
697  phy->SetChannelPairGetterCallback(cbChannel);
698 
699  // Set fading
700  phy->SetTxFadingContainer(n->GetObject<SatBaseFading>());
701  phy->SetRxFadingContainer(n->GetObject<SatBaseFading>());
702 
703  Ptr<LorawanMacEndDeviceClassA> mac =
704  CreateObject<LorawanMacEndDeviceClassA>(satId, beamId, m_superframeSeq);
705 
706  // TODO configuration for EU only
707  mac->SetTxDbmForTxPower(std::vector<double>{16, 14, 12, 10, 8, 6, 4, 2});
708 
709  SatLoraConf satLoraConf;
710  satLoraConf.SetConf(mac);
711 
712  // Attach the Mac layer receiver to Phy
713  SatPhy::ReceiveCallback recCb = MakeCallback(&LorawanMac::Receive, mac);
714 
715  phy->SetAttribute("ReceiveCb", CallbackValue(recCb));
716 
717  // Attach the PHY layer to SatNetDevice
718  dev->SetPhy(phy);
719 
720  // Attach the Mac layer to SatNetDevice
721  dev->SetLorawanMac(mac);
722  mac->SetDevice(dev);
723 
724  mac->SetPhy(phy);
725  mac->SetPhyRx(DynamicCast<SatLoraPhyRx>(phy->GetPhyRx()));
726  mac->SetRaModel(m_raSettings.m_randomAccessModel);
727 
728  // Set the device address and pass it to MAC as well
729  Mac48Address addr = Mac48Address::Allocate();
730  dev->SetAddress(addr);
731 
732  Singleton<SatIdMapper>::Get()->AttachMacToTraceId(dev->GetAddress());
733  Singleton<SatIdMapper>::Get()->AttachMacToUtId(dev->GetAddress());
734  Singleton<SatIdMapper>::Get()->AttachMacToBeamId(dev->GetAddress(), beamId);
735  Singleton<SatIdMapper>::Get()->AttachMacToSatId(dev->GetAddress(), satId + 1);
736 
737  // Create encapsulator and add it to UT's LLC
738  Mac48Address gwAddr = Mac48Address::ConvertFrom(gwNd->GetAddress());
739 
740  // set serving GW MAC address to RM
741  mac->SetRoutingUpdateCallback(cbRouting);
742  mac->SetGwAddress(gwAddr);
743 
744  // Add UT to NCC
745  ncc->AddUt(m_llsConf,
746  dev->GetAddress(),
747  satId,
748  beamId,
749  MakeCallback(&LorawanMacEndDevice::SetRaChannel, mac));
750 
751  phy->Initialize();
752 
753  // Create a node info to all the protocol layers
754  Ptr<SatNodeInfo> nodeInfo = Create<SatNodeInfo>(SatEnums::NT_UT, n->GetId(), addr);
755  dev->SetNodeInfo(nodeInfo);
756  mac->SetNodeInfo(nodeInfo);
757  phy->SetNodeInfo(nodeInfo);
758 
759  return dev;
760 }
761 
762 void
763 SatUtHelper::EnableCreationTraces(Ptr<OutputStreamWrapper> stream, CallbackBase& cb)
764 {
765  NS_LOG_FUNCTION(this);
766 
767  TraceConnect("Creation", "SatUtHelper", cb);
768 }
769 
770 } // namespace ns3
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.
static const uint32_t SIZE
Base class for fading models such as Markov-based fading or fading trace.
RegenerationMode_t
The regeneration mode used in satellites.
virtual bool BuffersEmpty() const
Are buffers empty?
virtual void GetSchedulingContexts(std::vector< Ptr< SatSchedulingObject >> &output) const =0
Create and fill the scheduling objects based on LLC layer information.
virtual bool ControlBuffersEmpty() const
Are buffers empty?
virtual void Receive(Ptr< Packet > packet, Mac48Address source, Mac48Address dest)
Receive user data packet from lower layer.
A configuration class for the GEO 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.
Observes given mobilities and keeps track of certain wanted properties.
Time GetTimingAdvance(void)
Get timing advance.
Ptr< SatBeamScheduler > GetBeamScheduler(uint32_t satId, uint32_t beamId) const
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:93
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, PacketContainer_t, Ptr< SatSignalParameters > > ReceiveCallback
Definition: satellite-phy.h:84
Callback< SatChannelPair::ChannelPair_t, uint32_t, uint32_t > ChannelPairGetterCallback
Callback for retrieving a pair of SatChannel associated to a beam.
Information of beam users liken UTs and their users.
Callback< void, SatQueue::QueueEvent_t, uint8_t > QueueEventCallback
Callback to indicate queue related event.
Callback< void, Ptr< Packet > > LogonCallback
logon msg sending callback
QueueStats_t GetQueueStatistics(bool reset)
GetQueueStatistics returns a struct of KPIs.
void AssignedDaResources(uint8_t rcIndex, uint32_t bytes)
Sat UT MAC informs that certain amount of resources have been received in TBTP.
void SendLogonMessage()
Send a logon message to the gateway.
void ReceiveQueueEvent(SatQueue::QueueEvent_t event, uint8_t rcIndex)
Receive a queue event.
void SendHandoverRecommendation(uint32_t beamId)
Send a handover recommendation message to the gateway.
void SetGwAddress(Mac48Address address)
Set the GW address needed for CR transmission.
void CnoUpdated(uint32_t satId, uint32_t beamId, Address sourceMac, Address gwId, double cno, bool isSatelliteMac)
Update C/N0 information from lower layer.
Callback< double, SatEnums::ChannelType_t, uint32_t, SatEnums::CarrierBandwidthType_t > CarrierBandwidthConverter_t
Callback for carrier bandwidths.
void SetHandoverRequestCallback(SatUtHandoverModule::HandoverRequestCallback cb)
Set the handover recommendation message sending callback.
bool CheckForHandoverRecommendation(uint32_t satId, uint32_t beamId)
Inspect whether or not the given beam is still suitable for the underlying mobility model.
uint32_t GetAskedBeamId()
Get the best beam ID.
NetDeviceContainer InstallLora(NodeContainer c, 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, SatEnums::RegenerationMode_t forwardLinkRegenerationMode, SatEnums::RegenerationMode_t returnLinkRegenerationMode)
void EnableCreationTraces(Ptr< OutputStreamWrapper > stream, CallbackBase &cb)
Enables creation traces to be written in given file.
SatPhy::ErrorModel m_errorModel
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
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).
SatMac::ReadCtrlMsgCallback m_readCtrlCb
TracedCallback< std::string > m_creationTrace
Trace callback for creation traces.
void SetPhyAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Phy created by the helper.
void Initialize(Ptr< SatLinkResultsFwd > lrFwd)
ObjectFactory m_channelFactory
Ptr< SatLinkResults > m_linkResults
Ptr< SatLowerLayerServiceConf > m_llsConf
Configured lower layer service configuration.
NetDeviceContainer InstallDvb(NodeContainer c, 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, SatEnums::RegenerationMode_t forwardLinkRegenerationMode, SatEnums::RegenerationMode_t returnLinkRegenerationMode)
SatUtHelper()
Default constructor.
SatTypedefs::CarrierBandwidthConverter_t m_carrierBandwidthConverter
ObjectFactory m_deviceFactory
bool m_crdsaOnlyForControl
Planned CRDSA usage:
SatMac::SendCtrlMsgCallback m_sendCtrlCb
Ptr< SatSuperframeSeq > m_superframeSeq
SatMac::ReserveCtrlMsgCallback m_reserveCtrlCb
static TypeId GetTypeId(void)
Derived from Object.
TypeId GetInstanceTypeId(void) const
Derived from Object.
void SetDeviceAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each NetDevice created by the helper.
void SetGwAddress(Mac48Address address)
Set the GW address.
virtual Ptr< Packet > NotifyTxOpportunity(uint32_t bytes, Mac48Address utAddr, uint8_t rcIndex, uint32_t &bytesLeft, uint32_t &nextMinTxO)
Called from lower layer (MAC) to inform a Tx opportunity of certain amount of bytes.
virtual void ReceiveQueueEventEssa(SatQueue::QueueEvent_t event, uint8_t rcIndex)
Receive a queue event:
virtual void Receive(SatPhy::PacketContainer_t packets, Ptr< SatSignalParameters >)
Receive packet from lower layer.
void SendLogon(Ptr< Packet > packet)
Receive a logon message to transmit /param packet The logon packet to send.
virtual void ReceiveQueueEvent(SatQueue::QueueEvent_t event, uint8_t rcIndex)
Receive a queue event:
Callback< Time > TimingAdvanceCallback
void SetRaChannel(uint32_t raChannel)
Set RA channel assigned for this UT.
bool ControlMsgTransmissionPossible() const
Method to check whether a transmission of a control msg is somewhat possible.
bool LogonMsgTransmissionPossible() const
Method to check whether a transmission of a logon msg is somewhat possible.
void PerformHandover(uint32_t beamId)
Change underlying SatChannel to send and receive data from a new beam.
bool IsTxPossible(void) const
Inform whether or not the underlying Tx channel is properly configured for transmission.
void UpdateSliceSubscription(uint8_t slice)
Updates the slices subscription list.
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