satellite-orbiter-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: Sami Rantanen <sami.rantanen@magister.fi>
20  * Author: Mathias Ettinger <mettinger@viveris.toulouse.fr>
21  */
22 
24 
25 #include "satellite-helper.h"
27 
28 #include "ns3/config.h"
29 #include "ns3/double.h"
30 #include "ns3/enum.h"
31 #include "ns3/log.h"
32 #include "ns3/names.h"
33 #include "ns3/packet.h"
34 #include "ns3/pointer.h"
35 #include "ns3/satellite-channel-estimation-error-container.h"
36 #include "ns3/satellite-const-variables.h"
37 #include "ns3/satellite-id-mapper.h"
38 #include "ns3/satellite-orbiter-feeder-llc.h"
39 #include "ns3/satellite-orbiter-feeder-mac.h"
40 #include "ns3/satellite-orbiter-feeder-phy.h"
41 #include "ns3/satellite-orbiter-net-device-dvb.h"
42 #include "ns3/satellite-orbiter-user-llc.h"
43 #include "ns3/satellite-orbiter-user-mac.h"
44 #include "ns3/satellite-orbiter-user-phy.h"
45 #include "ns3/satellite-phy-rx-carrier-conf.h"
46 #include "ns3/satellite-phy-rx.h"
47 #include "ns3/satellite-phy-tx.h"
48 #include "ns3/satellite-topology.h"
49 #include "ns3/satellite-typedefs.h"
50 #include "ns3/satellite-utils.h"
51 #include "ns3/singleton.h"
52 #include "ns3/uinteger.h"
53 
54 #include <algorithm>
55 #include <string>
56 #include <utility>
57 #include <vector>
58 
59 NS_LOG_COMPONENT_DEFINE("SatOrbiterHelperDvb");
60 
61 namespace ns3
62 {
63 
64 NS_OBJECT_ENSURE_REGISTERED(SatOrbiterHelperDvb);
65 
66 TypeId
68 {
69  static TypeId tid = TypeId("ns3::SatOrbiterHelperDvb")
70  .SetParent<SatOrbiterHelper>()
71  .AddConstructor<SatOrbiterHelperDvb>();
72  return tid;
73 }
74 
75 TypeId
77 {
78  NS_LOG_FUNCTION(this);
79 
80  return GetTypeId();
81 }
82 
85 {
86  NS_LOG_FUNCTION(this);
87 
88  // this default constructor should be never called
89  NS_ASSERT(false);
90 }
91 
93  SatTypedefs::CarrierBandwidthConverter_t bandwidthConverterCb,
94  uint32_t rtnLinkCarrierCount,
95  uint32_t fwdLinkCarrierCount,
96  Ptr<SatSuperframeSeq> seq,
99  RandomAccessSettings_s randomAccessSettings)
100  : SatOrbiterHelper(bandwidthConverterCb,
101  rtnLinkCarrierCount,
102  fwdLinkCarrierCount,
103  seq,
104  fwdReadCb,
105  rtnReadCb,
106  randomAccessSettings)
107 {
108  NS_LOG_FUNCTION(this << rtnLinkCarrierCount << fwdLinkCarrierCount);
109 
110  m_deviceFactory.SetTypeId("ns3::SatOrbiterNetDeviceDvb");
111 }
112 
113 Ptr<SatOrbiterNetDevice>
115 {
116  NS_LOG_FUNCTION(this);
117 
118  return m_deviceFactory.Create<SatOrbiterNetDeviceDvb>();
119 }
120 
121 void
122 SatOrbiterHelperDvb::AttachChannelsUser(Ptr<SatOrbiterNetDevice> dev,
123  Ptr<SatChannel> uf,
124  Ptr<SatChannel> ur,
125  Ptr<SatAntennaGainPattern> userAgp,
126  Ptr<SatNcc> ncc,
127  uint32_t satId,
128  uint32_t userBeamId)
129 {
130  NS_LOG_FUNCTION(this << dev << uf << ur << userAgp << satId << userBeamId);
131 
132  SatPhy::CreateParam_t params;
133  params.m_satId = satId;
134  params.m_beamId = userBeamId;
135  params.m_device = dev;
137 
141  Ptr<SatChannelEstimationErrorContainer> cec =
142  Create<SatSimpleChannelEstimationErrorContainer>();
143 
144  SatPhyRxCarrierConf::RxCarrierCreateParams_s parametersUser =
145  SatPhyRxCarrierConf::RxCarrierCreateParams_s();
146  parametersUser.m_errorModel = m_rtnErrorModel;
147  parametersUser.m_daConstantErrorRate = m_rtnDaConstantErrorRate;
148  parametersUser.m_daIfModel = m_daRtnLinkInterferenceModel;
149  parametersUser.m_raIfModel = m_raSettings.m_raRtnInterferenceModel;
150  parametersUser.m_raIfEliminateModel = m_raSettings.m_raInterferenceEliminationModel;
151  parametersUser.m_linkRegenerationMode =
152  Singleton<SatTopology>::Get()->GetReturnLinkRegenerationMode();
153  parametersUser.m_bwConverter = m_carrierBandwidthConverter;
154  parametersUser.m_carrierCount = m_rtnLinkCarrierCount;
155  parametersUser.m_cec = cec;
156  parametersUser.m_raCollisionModel = m_raSettings.m_raCollisionModel;
157  parametersUser.m_randomAccessModel = m_raSettings.m_randomAccessModel;
158 
159  params.m_txCh = uf;
160  params.m_rxCh = ur;
161 
162  Ptr<SatOrbiterUserPhy> uPhy = CreateObject<SatOrbiterUserPhy>(
163  params,
165  parametersUser,
167 
168  // Note, that currently we have only one set of antenna patterns,
169  // which are utilized in both in user link and feeder link, and
170  // in both uplink and downlink directions.
171  uPhy->SetTxAntennaGainPattern(userAgp, dev->GetNode()->GetObject<SatMobilityModel>());
172  uPhy->SetRxAntennaGainPattern(userAgp, dev->GetNode()->GetObject<SatMobilityModel>());
173 
174  dev->AddUserPhy(uPhy, userBeamId);
175 
176  uPhy->Initialize();
177 
178  Ptr<SatOrbiterUserMac> uMac;
179  Ptr<SatOrbiterUserLlc> uLlc;
180 
181  uMac = CreateObject<SatOrbiterUserMac>(satId, userBeamId);
182 
183  Mac48Address userAddress;
184 
185  // Create layers needed depending on max regeneration mode
186  switch (std::max(Singleton<SatTopology>::Get()->GetForwardLinkRegenerationMode(),
187  Singleton<SatTopology>::Get()->GetReturnLinkRegenerationMode()))
188  {
191  // Create a node info to PHY layers
192  Ptr<SatNodeInfo> niPhyUser =
193  Create<SatNodeInfo>(SatEnums::NT_SAT,
194  m_nodeIds[satId],
195  Mac48Address::ConvertFrom(dev->GetAddress()));
196  uPhy->SetNodeInfo(niPhyUser);
197  uMac->SetNodeInfo(niPhyUser);
198 
199  break;
200  }
202  // Create LLC layer
203  uLlc = CreateObject<SatOrbiterUserLlc>();
204 
205  dev->AddUserMac(uMac, userBeamId);
206 
207  uMac->SetReadCtrlCallback(m_rtnReadCtrlCb);
208  uLlc->SetReadCtrlCallback(m_rtnReadCtrlCb);
209 
210  // Create a node info to PHY and MAC layers
211  userAddress = Mac48Address::Allocate();
212  Ptr<SatNodeInfo> niUser =
213  Create<SatNodeInfo>(SatEnums::NT_SAT, m_nodeIds[satId], userAddress);
214  uPhy->SetNodeInfo(niUser);
215  uMac->SetNodeInfo(niUser);
216  uLlc->SetNodeInfo(niUser);
217 
218  dev->AddUserPair(userBeamId, userAddress);
219 
220  break;
221  }
223  // Create LLC layer
224  uLlc = CreateObject<SatOrbiterUserLlc>();
225 
226  dev->AddUserMac(uMac, userBeamId);
227 
228  uMac->SetReadCtrlCallback(m_rtnReadCtrlCb);
229  uLlc->SetReadCtrlCallback(m_rtnReadCtrlCb);
230 
231  // Create a node info to PHY and MAC layers
232  userAddress = Mac48Address::Allocate();
233  Ptr<SatNodeInfo> niUser =
234  Create<SatNodeInfo>(SatEnums::NT_SAT, m_nodeIds[satId], userAddress);
235  uPhy->SetNodeInfo(niUser);
236  uMac->SetNodeInfo(niUser);
237  uLlc->SetNodeInfo(niUser);
238 
239  dev->AddUserPair(userBeamId, userAddress);
240 
241  break;
242  }
243  default:
244  NS_FATAL_ERROR("Forward or return link regeneration mode unknown");
245  }
246 
247  // Connect callbacks on forward link
248  switch (Singleton<SatTopology>::Get()->GetForwardLinkRegenerationMode())
249  {
252  // Nothing to do on user side
253  break;
254  }
256  uMac->SetTransmitCallback(MakeCallback(&SatOrbiterUserPhy::SendPduWithParams, uPhy));
257 
258  double carrierBandwidth = m_carrierBandwidthConverter(SatEnums::FORWARD_USER_CH,
259  0,
261  Ptr<SatFwdLinkScheduler> fwdScheduler =
262  CreateObject<SatScpcScheduler>(m_bbFrameConfFwd, userAddress, carrierBandwidth);
263  uMac->SetFwdScheduler(fwdScheduler);
264  uMac->SetLlc(uLlc);
265  uMac->StartPeriodicTransmissions();
266 
267  // Attach the LLC Tx opportunity and scheduling context getter callbacks to
268  // SatFwdLinkScheduler
269  fwdScheduler->SetTxOpportunityCallback(
270  MakeCallback(&SatOrbiterLlc::NotifyTxOpportunity, uLlc));
271  fwdScheduler->SetSchedContextCallback(MakeCallback(&SatLlc::GetSchedulingContexts, uLlc));
272 
273  break;
274  }
275  default:
276  NS_FATAL_ERROR("Forward link regeneration mode unknown");
277  }
278 
279  // Connect callbacks on return link
280  switch (Singleton<SatTopology>::Get()->GetReturnLinkRegenerationMode())
281  {
285  uPhy->SetAttribute("ReceiveCb", CallbackValue(uCb));
286 
287  uMac->SetReceiveNetDeviceCallback(MakeCallback(&SatOrbiterNetDevice::ReceiveUser, dev));
288 
289  break;
290  }
292  SatPhy::ReceiveCallback uCb = MakeCallback(&SatOrbiterUserMac::Receive, uMac);
293  uPhy->SetAttribute("ReceiveCb", CallbackValue(uCb));
294 
295  uMac->SetReceiveNetDeviceCallback(MakeCallback(&SatOrbiterNetDevice::ReceiveUser, dev));
296 
297  break;
298  }
300  SatPhy::ReceiveCallback uCb = MakeCallback(&SatOrbiterUserMac::Receive, uMac);
301  uPhy->SetAttribute("ReceiveCb", CallbackValue(uCb));
302 
303  uMac->SetReceiveCallback(MakeCallback(&SatOrbiterUserLlc::Receive, uLlc));
304 
305  uLlc->SetReceiveSatelliteCallback(
306  MakeCallback(&SatOrbiterNetDevice::ReceivePacketUser, dev));
307 
308  break;
309  }
310  default:
311  NS_FATAL_ERROR("Return link regeneration mode unknown");
312  }
313 
314  if (Singleton<SatTopology>::Get()->GetReturnLinkRegenerationMode() != SatEnums::TRANSPARENT)
315  {
316  uPhy->BeginEndScheduling();
317  uPhy->SetSendControlMsgToFeederCallback(
318  MakeCallback(&SatOrbiterNetDevice::SendControlMsgToFeeder, dev));
319  }
320 
321  Singleton<SatTopology>::Get()
322  ->AddOrbiterUserLayersDvb(dev->GetNode(), satId, userBeamId, dev, uLlc, uMac, uPhy);
323 }
324 
325 } // namespace ns3
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.
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.
SatOrbiterHelperDvb()
Default constructor.
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)
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< SatBbFrameConf > m_bbFrameConfFwd
Ptr< SatSuperframeSeq > m_superframeSeq
Superframe sequence.
SatPhy::InterferenceModel m_daRtnLinkInterferenceModel
SatTypedefs::CarrierBandwidthConverter_t m_carrierBandwidthConverter
SatMac::ReadCtrlMsgCallback m_rtnReadCtrlCb
Control return link messages callback.
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.
SatOrbiterNetDeviceDvb to be utilized in geostationary satellite.
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.
virtual void ReceivePacketUser(Ptr< Packet > packet, const Address &userAddress)=0
Receive the packet from the lower layers, in network regeneration on return link.
void Receive(SatPhy::PacketContainer_t packets, Ptr< SatSignalParameters > txParams)
Receive packet from lower layer.
virtual void SendPduWithParams(Ptr< SatSignalParameters > rxParams)
Send Pdu to the PHY tx module (for satellite switch packet forwarding)
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