Loading...
Searching...
No Matches
satellite-ut-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/callback.h"
25#include "ns3/log.h"
26#include "ns3/pointer.h"
27#include "ns3/satellite-base-encapsulator.h"
28#include "ns3/satellite-channel-estimation-error-container.h"
29#include "ns3/satellite-channel.h"
30#include "ns3/satellite-const-variables.h"
31#include "ns3/satellite-enums.h"
32#include "ns3/satellite-generic-stream-encapsulator-arq.h"
33#include "ns3/satellite-generic-stream-encapsulator.h"
34#include "ns3/satellite-gw-llc.h"
35#include "ns3/satellite-handover-module.h"
36#include "ns3/satellite-id-mapper.h"
37#include "ns3/satellite-mobility-observer.h"
38#include "ns3/satellite-net-device.h"
39#include "ns3/satellite-node-info.h"
40#include "ns3/satellite-packet-classifier.h"
41#include "ns3/satellite-phy-rx-carrier-conf.h"
42#include "ns3/satellite-phy-rx.h"
43#include "ns3/satellite-phy-tx.h"
44#include "ns3/satellite-queue.h"
45#include "ns3/satellite-request-manager.h"
46#include "ns3/satellite-return-link-encapsulator-arq.h"
47#include "ns3/satellite-return-link-encapsulator.h"
48#include "ns3/satellite-topology.h"
49#include "ns3/satellite-typedefs.h"
50#include "ns3/satellite-ut-llc.h"
51#include "ns3/satellite-ut-mac.h"
52#include "ns3/satellite-ut-phy.h"
53#include "ns3/satellite-ut-scheduler.h"
54#include "ns3/satellite-utils.h"
55#include "ns3/singleton.h"
56
57NS_LOG_COMPONENT_DEFINE("SatUtHelperDvb");
58
59namespace ns3
60{
61
62NS_OBJECT_ENSURE_REGISTERED(SatUtHelperDvb);
63
64TypeId
66{
67 static TypeId tid =
68 TypeId("ns3::SatUtHelperDvb").SetParent<SatUtHelper>().AddConstructor<SatUtHelperDvb>();
69 return tid;
70}
71
73{
74 NS_LOG_FUNCTION(this);
75
76 // this default constructor should be never called
77 NS_FATAL_ERROR("SatUtHelperDvb::SatUtHelperDvb - Constructor not in use");
78}
79
81 uint32_t fwdLinkCarrierCount,
82 Ptr<SatSuperframeSeq> seq,
86 RandomAccessSettings_s randomAccessSettings)
87 : SatUtHelper(carrierBandwidthConverter,
88 fwdLinkCarrierCount,
89 seq,
90 readCb,
91 reserveCb,
92 sendCb,
93 randomAccessSettings)
94{
95 NS_LOG_FUNCTION(this << fwdLinkCarrierCount << seq);
96}
97
98Ptr<NetDevice>
100 uint32_t satId,
101 uint32_t beamId,
102 Ptr<SatChannel> fCh,
103 Ptr<SatChannel> rCh,
104 Ptr<SatNetDevice> gwNd,
105 Ptr<SatNcc> ncc,
106 Address satUserAddress,
109{
110 NS_LOG_FUNCTION(this << n << satId << beamId << fCh << rCh << gwNd << ncc << satUserAddress);
111
112 NetDeviceContainer container;
113
114 // Create SatNetDevice
115 m_deviceFactory.SetTypeId("ns3::SatNetDevice");
116 Ptr<SatNetDevice> dev = m_deviceFactory.Create<SatNetDevice>();
117
118 // Attach the SatNetDevice to node
119 n->AddDevice(dev);
120
122 params.m_satId = satId;
123 params.m_beamId = beamId;
124 params.m_device = dev;
125 params.m_txCh = rCh;
126 params.m_rxCh = fCh;
128
129 // Create a packet classifier
130 Ptr<SatPacketClassifier> classifier = Create<SatPacketClassifier>();
131
135 Ptr<SatChannelEstimationErrorContainer> cec;
136 // Not enabled, create only base class
138 {
139 cec = Create<SatSimpleChannelEstimationErrorContainer>();
140 }
141 // Create SatFwdLinkChannelEstimationErrorContainer
142 else
143 {
144 cec = Create<SatFwdLinkChannelEstimationErrorContainer>();
145 }
146
147 SatPhyRxCarrierConf::RxCarrierCreateParams_s parameters =
148 SatPhyRxCarrierConf::RxCarrierCreateParams_s();
149 parameters.m_errorModel = m_errorModel;
150 parameters.m_daConstantErrorRate = m_daConstantErrorRate;
151 parameters.m_daIfModel = m_daInterferenceModel;
152 parameters.m_raIfModel = m_raSettings.m_raInterferenceModel;
153 parameters.m_raIfEliminateModel = m_raSettings.m_raInterferenceEliminationModel;
154 parameters.m_linkRegenerationMode =
155 Singleton<SatTopology>::Get()->GetForwardLinkRegenerationMode();
156 parameters.m_bwConverter = m_carrierBandwidthConverter;
157 parameters.m_carrierCount = m_fwdLinkCarrierCount;
158 parameters.m_cec = cec;
159 parameters.m_raCollisionModel = m_raSettings.m_raCollisionModel;
160 parameters.m_randomAccessModel = m_raSettings.m_randomAccessModel;
161
162 Ptr<SatUtPhy> phy = CreateObject<SatUtPhy>(
163 params,
165 parameters,
167 phy->SetChannelPairGetterCallback(cbChannel);
168
169 // Set fading
170 phy->SetTxFadingContainer(n->GetObject<SatBaseFading>());
171 phy->SetRxFadingContainer(n->GetObject<SatBaseFading>());
172
173 Ptr<SatUtMac> mac =
174 CreateObject<SatUtMac>(n, satId, beamId, m_superframeSeq, m_crdsaOnlyForControl);
175
176 // Set the control message container callbacks
177 mac->SetReadCtrlCallback(m_readCtrlCb);
178 mac->SetReserveCtrlCallback(m_reserveCtrlCb);
179 mac->SetSendCtrlCallback(m_sendCtrlCb);
180
181 // Set timing advance callback to mac (if not asynchronous access)
182 if (m_raSettings.m_randomAccessModel != SatEnums::RA_MODEL_ESSA)
183 {
184 Ptr<SatMobilityObserver> observer = n->GetObject<SatMobilityObserver>();
185 NS_ASSERT(observer != nullptr);
186
188 MakeCallback(&SatMobilityObserver::GetTimingAdvance, observer);
189 mac->SetTimingAdvanceCallback(timingCb);
190 }
191
192 // Attach the Mac layer receiver to Phy
193 SatPhy::ReceiveCallback recCb = MakeCallback(&SatUtMac::Receive, mac);
194
195 phy->SetAttribute("ReceiveCb", CallbackValue(recCb));
196 mac->SetTxCheckCallback(MakeCallback(&SatUtPhy::IsTxPossible, phy));
197
198 // Create callback to inform phy layer slices subscription
199 mac->SetSliceSubscriptionCallback(MakeCallback(&SatUtPhy::UpdateSliceSubscription, phy));
200
201 // Create Logical Link Control (LLC) layer
202 Ptr<SatUtLlc> llc = CreateObject<SatUtLlc>();
203
204 // Set the control msg read callback to LLC due to ARQ ACKs
205 llc->SetReadCtrlCallback(m_readCtrlCb);
206
207 // Create a request manager and attach it to LLC, and set control message callback to RM
208 Ptr<SatRequestManager> rm = CreateObject<SatRequestManager>();
209 llc->SetRequestManager(rm);
210 rm->SetCtrlMsgCallback(MakeCallback(&SatNetDevice::SendControlMsg, dev));
211
212 if (Singleton<SatTopology>::Get()->GetReturnLinkRegenerationMode() != SatEnums::TRANSPARENT &&
213 Singleton<SatTopology>::Get()->GetReturnLinkRegenerationMode() !=
215 {
216 llc->SetAdditionalHeaderSize(SatAddressE2ETag::SIZE);
217 rm->SetHeaderOffsetVbdc(38.0 / (38 - 2 - SatAddressE2ETag::SIZE));
218 }
219
220 // Set the callback to check whether control msg transmissions are possible
221 rm->SetCtrlMsgTxPossibleCallback(MakeCallback(&SatUtMac::ControlMsgTransmissionPossible, mac));
222
223 // Set the callback to check whether logon msg transmissions are possible
224 rm->SetLogonMsgTxPossibleCallback(MakeCallback(&SatUtMac::LogonMsgTransmissionPossible, mac));
225
226 // Set TBTP callback to UT MAC
227 mac->SetAssignedDaResourcesCallback(MakeCallback(&SatRequestManager::AssignedDaResources, rm));
228
229 // Set Send Logon callback to UT MAC
230 mac->SetSendLogonCallback(MakeCallback(&SatRequestManager::SendLogonMessage, rm));
231
232 // Attach the PHY layer to SatNetDevice
233 dev->SetPhy(phy);
234
235 // Attach the Mac layer to SatNetDevice
236 dev->SetMac(mac);
237
238 // Attach the LLC layer to SatNetDevice
239 dev->SetLlc(llc);
240
241 // Attach the packet classifier
242 dev->SetPacketClassifier(classifier);
243
244 // Attach the Mac layer C/N0 updates receiver to Phy
245 SatPhy::CnoCallback cnoCb = MakeCallback(&SatRequestManager::CnoUpdated, rm);
246 phy->SetAttribute("CnoCb", CallbackValue(cnoCb));
247
248 // Set the device address and pass it to MAC as well
249 Mac48Address addr = Mac48Address::Allocate();
250 dev->SetAddress(addr);
251
252 Singleton<SatIdMapper>::Get()->AttachMacToTraceId(dev->GetAddress());
253 Singleton<SatIdMapper>::Get()->AttachMacToUtId(dev->GetAddress());
254 Singleton<SatIdMapper>::Get()->AttachMacToBeamId(dev->GetAddress(), beamId);
255 Singleton<SatIdMapper>::Get()->AttachMacToSatId(dev->GetAddress(), satId + 1);
256
257 // Create encapsulator and add it to UT's LLC
258 Mac48Address gwAddr = Mac48Address::ConvertFrom(gwNd->GetAddress());
259
260 // Create an encapsulator for control messages.
261 // Source = UT MAC address
262 // Destination = GW MAC address (or SAT user MAC address if regenerative)
263 // Flow id = by default 0
264 Ptr<SatBaseEncapsulator> utEncap;
265 if (Singleton<SatTopology>::Get()->GetReturnLinkRegenerationMode() ==
267 {
268 utEncap = CreateObject<SatBaseEncapsulator>(addr,
269 Mac48Address::ConvertFrom(satUserAddress),
270 addr,
271 gwAddr,
273 }
274 else
275 {
276 utEncap =
277 CreateObject<SatBaseEncapsulator>(addr, gwAddr, addr, gwAddr, SatEnums::CONTROL_FID);
278 }
279
280 // Create queue event callbacks to MAC (for random access) and RM (for on-demand DAMA)
282 if (m_raSettings.m_randomAccessModel == SatEnums::RA_MODEL_ESSA)
283 {
284 macCb = MakeCallback(&SatUtMac::ReceiveQueueEventEssa, mac);
285 }
286 else
287 {
288 macCb = MakeCallback(&SatUtMac::ReceiveQueueEvent, mac);
289 }
290 SatQueue::LogonCallback logonCb = MakeCallback(&SatUtMac::SendLogon, mac);
292
293 // Create a queue
294 Ptr<SatQueue> queue = CreateObject<SatQueue>(SatEnums::CONTROL_FID);
295 queue->AddLogonCallback(logonCb);
296 queue->AddQueueEventCallback(macCb);
297 queue->AddQueueEventCallback(rmCb);
298 utEncap->SetQueue(queue);
299 if (Singleton<SatTopology>::Get()->GetReturnLinkRegenerationMode() ==
301 {
302 llc->AddEncap(addr,
303 Mac48Address::ConvertFrom(satUserAddress),
305 utEncap);
306 }
307 else
308 {
309 llc->AddEncap(addr, gwAddr, SatEnums::CONTROL_FID, utEncap);
310 }
311 rm->AddQueueCallback(SatEnums::CONTROL_FID, MakeCallback(&SatQueue::GetQueueStatistics, queue));
312
313 // Add callbacks to LLC for future need. LLC creates encapsulators and
314 // decapsulators dynamically 'on-a-need-basis'.
315 llc->SetCtrlMsgCallback(MakeCallback(&SatNetDevice::SendControlMsg, dev));
316 llc->SetMacQueueEventCallback(macCb);
317
318 // set serving GW MAC address to RM
319 mac->SetRoutingUpdateCallback(cbRouting);
320 mac->SetGatewayUpdateCallback(MakeCallback(&SatUtLlc::SetGwAddress, llc));
321 mac->SetGwAddress(gwAddr);
322
323 // Attach the transmit callback to PHY
324 mac->SetTransmitCallback(MakeCallback(&SatPhy::SendPdu, phy));
325
326 // Attach the PHY handover callback to SatMac
327 mac->SetHandoverCallback(MakeCallback(&SatUtPhy::PerformHandover, phy));
328
329 // Attach the LLC receive callback to SatMac
330 mac->SetReceiveCallback(MakeCallback(&SatLlc::Receive, llc));
331
332 llc->SetReceiveCallback(MakeCallback(&SatNetDevice::Receive, dev));
333
334 Ptr<SatSuperframeConf> superFrameConf =
336 bool enableLogon = superFrameConf->IsLogonEnabled();
337 uint32_t logonChannelId = superFrameConf->GetLogonChannelIndex();
338
339 // Add UT to NCC
340 if (enableLogon)
341 {
342 ncc->ReserveLogonChannel(logonChannelId);
343 }
344 else
345 {
346 ncc->AddUt(m_llsConf,
347 dev->GetAddress(),
348 satId,
349 beamId,
350 MakeCallback(&SatUtMac::SetRaChannel, mac));
351 }
352
353 phy->Initialize();
354
355 // Create UT scheduler for MAC and connect callbacks to LLC
356 Ptr<SatUtScheduler> utScheduler = CreateObject<SatUtScheduler>(m_llsConf);
357 utScheduler->SetTxOpportunityCallback(MakeCallback(&SatUtLlc::NotifyTxOpportunity, llc));
358 utScheduler->SetSchedContextCallback(MakeCallback(&SatLlc::GetSchedulingContexts, llc));
359 mac->SetAttribute("Scheduler", PointerValue(utScheduler));
360
361 // Create a node info to all the protocol layers
362 Ptr<SatNodeInfo> nodeInfo = Create<SatNodeInfo>(SatEnums::NT_UT, n->GetId(), addr);
363 dev->SetNodeInfo(nodeInfo);
364 llc->SetNodeInfo(nodeInfo);
365 mac->SetNodeInfo(nodeInfo);
366 phy->SetNodeInfo(nodeInfo);
367
368 rm->Initialize(m_llsConf, m_superframeSeq->GetDuration(0));
369
370 if (m_raSettings.m_randomAccessModel != SatEnums::RA_MODEL_OFF)
371 {
372 Ptr<SatRandomAccessConf> randomAccessConf =
373 CreateObject<SatRandomAccessConf>(m_llsConf, m_superframeSeq);
374
376 Ptr<SatRandomAccess> randomAccess =
377 CreateObject<SatRandomAccess>(randomAccessConf, m_raSettings.m_randomAccessModel);
378
381 {
382 randomAccess->SetAreBuffersEmptyCallback(
383 MakeCallback(&SatLlc::ControlBuffersEmpty, llc));
384 }
385 else
386 {
387 randomAccess->SetAreBuffersEmptyCallback(MakeCallback(&SatLlc::BuffersEmpty, llc));
388 }
389
391 mac->SetRandomAccess(randomAccess);
392 if (enableLogon)
393 {
394 mac->SetLogonChannel(logonChannelId);
395 mac->LogOff();
396 }
397 }
398 else if (enableLogon)
399 {
400 NS_FATAL_ERROR("Cannot simulate logon without a RA frame");
401 }
402
403 Ptr<SatHandoverModule> handoverModule = n->GetObject<SatHandoverModule>();
404 if (handoverModule != nullptr)
405 {
406 handoverModule->SetHandoverRequestCallback(
408 mac->SetHandoverModule(handoverModule);
409 mac->SetBeamSchedulerCallback(MakeCallback(&SatNcc::GetBeamScheduler, ncc));
410 mac->SetUpdateGwAddressCallback(MakeCallback(&SatRequestManager::SetGwAddress, rm));
411 }
412
413 Singleton<SatTopology>::Get()->AddUtLayersDvb(n, satId, beamId, 0, dev, llc, mac, phy);
414
415 return dev;
416}
417
418} // namespace ns3
static const uint32_t SIZE
Base class for fading models such as Markov-based fading or fading trace.
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.
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
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
Callback< SatChannelPair::ChannelPair_t, uint32_t, uint32_t > ChannelPairGetterCallback
Callback for retrieving a pair of SatChannel associated to a beam.
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 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.
void SendHandoverRecommendation(uint32_t satId, uint32_t beamId)
Send a handover recommendation message to the gateway.
Callback< double, SatEnums::ChannelType_t, uint32_t, SatEnums::CarrierBandwidthType_t > CarrierBandwidthConverter_t
Callback for carrier bandwidths.
Creates needed objects for DVB UT nodes like SatOrbiterNetDevice objects.
virtual Ptr< NetDevice > Install(Ptr< Node > n, 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)
static TypeId GetTypeId(void)
Derived from Object.
SatUtHelperDvb()
Default constructor.
SatPhy::ErrorModel m_errorModel
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
Ptr< SatLinkResults > m_linkResults
Ptr< SatLowerLayerServiceConf > m_llsConf
Configured lower layer service configuration.
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
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.
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.
void PerformHandover(uint32_t satId, uint32_t beamId)
Change underlying SatChannel to send and receive data from a new satellite and beam.
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.
SatEnums::SatLoraNodeType_t m_standard
Define RandomAccessSettings as a struct.