satellite-phy-rx.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: Jani Puttonen <jani.puttonen@magister.fi>
20  * Author: Mathias Ettinger <mettinger@toulouse.viveris.fr>
21  */
22 
23 #include "satellite-phy-rx.h"
24 
26 #include "satellite-net-device.h"
34 #include "satellite-phy.h"
36 #include "satellite-utils.h"
37 
38 #include <ns3/antenna-model.h>
39 #include <ns3/log.h>
40 #include <ns3/object-factory.h>
41 #include <ns3/object-vector.h>
42 
43 NS_LOG_COMPONENT_DEFINE("SatPhyRx");
44 
45 namespace ns3
46 {
47 
48 NS_OBJECT_ENSURE_REGISTERED(SatPhyRx);
49 
51  : m_beamId(),
52  m_maxAntennaGain(),
53  m_antennaLoss(),
54  m_defaultFadingValue()
55 {
56  NS_LOG_FUNCTION(this);
57 }
58 
60 {
61  NS_LOG_FUNCTION(this);
62 }
63 
64 void
66 {
67  NS_LOG_FUNCTION(this);
68  m_mobility = 0;
69  m_device = 0;
71  m_rxCarriers.clear();
72  Object::DoDispose();
73 }
74 
75 TypeId
77 {
78  static TypeId tid = TypeId("ns3::SatPhyRx")
79  .SetParent<Object>()
80  .AddAttribute("RxCarrierList",
81  "The list of RX carriers associated to this Phy RX.",
82  ObjectVectorValue(),
83  MakeObjectVectorAccessor(&SatPhyRx::m_rxCarriers),
84  MakeObjectVectorChecker<SatPhyRxCarrier>());
85  return tid;
86 }
87 
88 Ptr<NetDevice>
90 {
91  NS_LOG_FUNCTION(this);
92  NS_ASSERT(m_device != nullptr);
93 
94  return m_device;
95 }
96 
97 void
98 SatPhyRx::SetDevice(Ptr<NetDevice> d)
99 {
100  NS_LOG_FUNCTION(this << d);
101  NS_ASSERT(m_device == nullptr);
102 
103  m_device = d;
104 }
105 
106 void
108 {
109  NS_LOG_FUNCTION(this << gain_Db);
110 
112 }
113 
114 double
115 SatPhyRx::GetAntennaGain(Ptr<MobilityModel> mobility)
116 {
117  NS_LOG_FUNCTION(this);
118 
119  double gain_W(m_maxAntennaGain);
120 
121  // Get the receive antenna gain at the transmitter position.
122  // E.g. UT transmits to the satellite receiver.
124  {
125  Ptr<SatMobilityModel> m = DynamicCast<SatMobilityModel>(mobility);
126  gain_W = m_antennaGainPattern->GetAntennaGain_lin(m->GetGeoPosition(), m_satMobility);
127  }
128 
134  return gain_W;
135 }
136 
137 void
139 {
140  NS_LOG_FUNCTION(this << fadingValue);
141  m_defaultFadingValue = fadingValue;
142 }
143 
144 double
145 SatPhyRx::GetFadingValue(Address macAddress, SatEnums::ChannelType_t channelType)
146 {
147  NS_LOG_FUNCTION(this << macAddress << channelType);
148 
149  double fadingValue = m_defaultFadingValue;
150 
151  if (m_fadingContainer)
152  {
153  fadingValue = m_fadingContainer->GetFading(macAddress, channelType);
154  }
155  // Returns value 1 if fading is not set, as fading value is used as multiplier
156  return fadingValue;
157 }
158 
159 void
160 SatPhyRx::SetFadingContainer(Ptr<SatBaseFading> fadingContainer)
161 {
162  NS_LOG_FUNCTION(this);
163  NS_ASSERT(m_fadingContainer == nullptr);
164 
165  m_fadingContainer = fadingContainer;
166 }
167 
168 void
170 {
171  NS_LOG_FUNCTION(this << gain_Db);
172 
174 }
175 
176 double
178 {
179  NS_LOG_FUNCTION(this);
180 
181  return m_antennaLoss;
182 }
183 
184 Mac48Address
186 {
187  NS_LOG_FUNCTION(this);
188 
189  return m_macAddress;
190 }
191 
192 void
193 SatPhyRx::SetNodeInfo(const Ptr<SatNodeInfo> nodeInfo)
194 {
195  NS_LOG_FUNCTION(this << nodeInfo->GetNodeId());
196 
197  m_macAddress = nodeInfo->GetMacAddress();
198 
199  for (std::vector<Ptr<SatPhyRxCarrier>>::iterator it = m_rxCarriers.begin();
200  it != m_rxCarriers.end();
201  ++it)
202  {
203  (*it)->SetNodeInfo(nodeInfo);
204  }
205 }
206 
207 void
209 {
210  NS_LOG_FUNCTION(this);
211 
212  for (std::vector<Ptr<SatPhyRxCarrier>>::iterator it = m_rxCarriers.begin();
213  it != m_rxCarriers.end();
214  ++it)
215  {
216  (*it)->BeginEndScheduling();
217  }
218 }
219 
220 void
222 {
223  NS_LOG_FUNCTION(this);
224  NS_ASSERT(!m_rxCarriers.empty());
225 
226  for (std::vector<Ptr<SatPhyRxCarrier>>::iterator it = m_rxCarriers.begin();
227  it != m_rxCarriers.end();
228  ++it)
229  {
230  (*it)->SetReceiveCb(cb);
231  }
232 }
233 
234 void
236 {
237  NS_LOG_FUNCTION(this << &cb);
238  NS_ASSERT(!m_rxCarriers.empty());
239 
240  for (std::vector<Ptr<SatPhyRxCarrier>>::iterator it = m_rxCarriers.begin();
241  it != m_rxCarriers.end();
242  ++it)
243  {
244  (*it)->SetCnoCb(cb);
245  }
246 }
247 
248 void
250 {
251  NS_LOG_FUNCTION(this << &cb);
252  NS_ASSERT(!m_rxCarriers.empty());
253 
254  for (std::vector<Ptr<SatPhyRxCarrier>>::iterator it = m_rxCarriers.begin();
255  it != m_rxCarriers.end();
256  ++it)
257  {
258  (*it)->SetAverageNormalizedOfferedLoadCallback(cb);
259  }
260 }
261 
262 Ptr<MobilityModel>
264 {
265  NS_LOG_FUNCTION(this);
266  NS_ASSERT(m_mobility != nullptr);
267 
268  return m_mobility;
269 }
270 
271 void
272 SatPhyRx::SetMobility(Ptr<MobilityModel> m)
273 {
274  NS_LOG_FUNCTION(this << m);
275  m_mobility = m;
276 }
277 
278 void
279 SatPhyRx::SetAntennaGainPattern(Ptr<SatAntennaGainPattern> agp, Ptr<SatMobilityModel> mobility)
280 {
281  NS_LOG_FUNCTION(this << agp);
282  NS_ASSERT(m_antennaGainPattern == nullptr);
283 
284  m_antennaGainPattern = agp;
285  m_satMobility = mobility;
286 }
287 
288 void
289 SatPhyRx::ConfigurePhyRxCarriers(Ptr<SatPhyRxCarrierConf> carrierConf,
290  Ptr<SatSuperframeConf> superFrameConf)
291 {
292  NS_LOG_FUNCTION(this);
293  NS_ASSERT(m_rxCarriers.empty());
294 
295  Ptr<SatPhyRxCarrier> rxc(nullptr);
296  bool isRandomAccessCarrier(false);
297 
298  SatEnums::RandomAccessModel_t raModel = carrierConf->GetRandomAccessModel();
299  SatEnums::RegenerationMode_t regenerationMode = carrierConf->GetLinkRegenerationMode();
300 
301  for (uint32_t i = 0; i < carrierConf->GetCarrierCount(); ++i)
302  {
303  NS_LOG_INFO(this << " Create carrier: " << i);
304  Ptr<SatWaveformConf> waveformConf =
305  superFrameConf->GetCarrierFrameConf(i)->GetWaveformConf();
306 
307  if (regenerationMode == SatEnums::TRANSPARENT)
308  {
309  switch (carrierConf->GetChannelType())
310  {
312  // Satellite is the receiver in feeder uplink
313  rxc = CreateObject<SatPhyRxCarrierUplink>(i, carrierConf, waveformConf, false);
314  break;
315  }
317  // UT has only per slot non-random access carriers
318  rxc = CreateObject<SatPhyRxCarrierPerSlot>(i, carrierConf, waveformConf, false);
319  break;
320  }
322  isRandomAccessCarrier = superFrameConf->IsRandomAccessCarrier(i);
323 
324  // Satellite is the receiver in either user or feeder uplink
325  rxc = CreateObject<SatPhyRxCarrierUplink>(i,
326  carrierConf,
327  waveformConf,
328  isRandomAccessCarrier);
329  break;
330  }
332  isRandomAccessCarrier = superFrameConf->IsRandomAccessCarrier(i);
333 
334  // DA carrier
335  if (!isRandomAccessCarrier)
336  {
337  rxc = CreateObject<SatPhyRxCarrierPerSlot>(i, carrierConf, waveformConf, false);
338  }
339  // RA slotted aloha
340  else if (raModel == SatEnums::RA_MODEL_SLOTTED_ALOHA)
341  {
342  rxc = CreateObject<SatPhyRxCarrierPerSlot>(i, carrierConf, waveformConf, true);
343  DynamicCast<SatPhyRxCarrierPerSlot>(rxc)->SetRandomAccessAllocationChannelId(
344  superFrameConf->GetRaChannel(i));
345  }
346  // Note, that random access model of DVB-RCS2 specification may be configured
347  // to be either slotted ALOHA and CRDSA (wit no of unique payloads attribute).
348  // Here we make a short-cut such that the RCS2_SPECIFICATION random access
349  // always uses the CRDSA frame type receiver.
350  else if (raModel == SatEnums::RA_MODEL_CRDSA ||
352  {
353  rxc = CreateObject<SatPhyRxCarrierPerFrame>(i, carrierConf, waveformConf, true);
354  DynamicCast<SatPhyRxCarrierPerSlot>(rxc)->SetRandomAccessAllocationChannelId(
355  superFrameConf->GetRaChannel(i));
356  }
357  else if (raModel == SatEnums::RA_MODEL_MARSALA)
358  {
359  rxc = CreateObject<SatPhyRxCarrierMarsala>(i, carrierConf, waveformConf, true);
360  DynamicCast<SatPhyRxCarrierPerSlot>(rxc)->SetRandomAccessAllocationChannelId(
361  superFrameConf->GetRaChannel(i));
362  }
363  else if (raModel == SatEnums::RA_MODEL_ESSA)
364  {
365  rxc =
366  CreateObject<SatPhyRxCarrierPerWindow>(i, carrierConf, waveformConf, true);
367  DynamicCast<SatPhyRxCarrierPerSlot>(rxc)->SetRandomAccessAllocationChannelId(
368  superFrameConf->GetRaChannel(i));
369  }
370  break;
371  }
373  default: {
374  NS_FATAL_ERROR("SatPhyRx::ConfigurePhyRxCarriers - Invalid channel type!");
375  }
376  }
377  }
378  else if (regenerationMode == SatEnums::REGENERATION_PHY ||
379  regenerationMode == SatEnums::REGENERATION_LINK ||
380  regenerationMode == SatEnums::REGENERATION_NETWORK)
381  {
382  switch (carrierConf->GetChannelType())
383  {
385  // Satellite is the receiver in feeder uplink
386  rxc = CreateObject<SatPhyRxCarrierPerSlot>(i, carrierConf, waveformConf, false);
387  break;
388  }
390  // UT has only per slot non-random access carriers
391  rxc = CreateObject<SatPhyRxCarrierPerSlot>(i, carrierConf, waveformConf, false);
392  break;
393  }
395  isRandomAccessCarrier = superFrameConf->IsRandomAccessCarrier(i);
396 
397  // DA carrier
398  if (!isRandomAccessCarrier)
399  {
400  rxc = CreateObject<SatPhyRxCarrierPerSlot>(i, carrierConf, waveformConf, false);
401  }
402  // RA slotted aloha
403  else if (raModel == SatEnums::RA_MODEL_SLOTTED_ALOHA)
404  {
405  rxc = CreateObject<SatPhyRxCarrierPerSlot>(i, carrierConf, waveformConf, true);
406  DynamicCast<SatPhyRxCarrierPerSlot>(rxc)->SetRandomAccessAllocationChannelId(
407  superFrameConf->GetRaChannel(i));
408  }
409  // Note, that random access model of DVB-RCS2 specification may be configured
410  // to be either slotted ALOHA and CRDSA (wit no of unique payloads attribute).
411  // Here we make a short-cut such that the RCS2_SPECIFICATION random access
412  // always uses the CRDSA frame type receiver.
413  else if (raModel == SatEnums::RA_MODEL_CRDSA ||
415  {
416  rxc = CreateObject<SatPhyRxCarrierPerFrame>(i, carrierConf, waveformConf, true);
417  DynamicCast<SatPhyRxCarrierPerSlot>(rxc)->SetRandomAccessAllocationChannelId(
418  superFrameConf->GetRaChannel(i));
419  }
420  else if (raModel == SatEnums::RA_MODEL_MARSALA)
421  {
422  rxc = CreateObject<SatPhyRxCarrierMarsala>(i, carrierConf, waveformConf, true);
423  DynamicCast<SatPhyRxCarrierPerSlot>(rxc)->SetRandomAccessAllocationChannelId(
424  superFrameConf->GetRaChannel(i));
425  }
426  else if (raModel == SatEnums::RA_MODEL_ESSA)
427  {
428  rxc =
429  CreateObject<SatPhyRxCarrierPerWindow>(i, carrierConf, waveformConf, true);
430  DynamicCast<SatPhyRxCarrierPerSlot>(rxc)->SetRandomAccessAllocationChannelId(
431  superFrameConf->GetRaChannel(i));
432  }
433  break;
434  }
436  rxc = CreateObject<SatPhyRxCarrierPerSlot>(i, carrierConf, waveformConf, false);
437  break;
438  }
440  default: {
441  NS_FATAL_ERROR("SatPhyRx::ConfigurePhyRxCarriers - Invalid channel type!");
442  }
443  }
444  }
445  else
446  {
447  NS_FATAL_ERROR("SatPhyRx::ConfigurePhyRxCarriers - Unknown RX mode!");
448  }
449 
450  NS_LOG_INFO(this << " added carrier " << rxc << " on channel "
451  << carrierConf->GetChannelType() << " being random access "
452  << superFrameConf->IsRandomAccessCarrier(i));
453  m_rxCarriers.push_back(rxc);
454  }
455 }
456 
457 void
458 SatPhyRx::SetSatId(uint32_t satId)
459 {
460  NS_LOG_FUNCTION(this << satId);
461  NS_ASSERT(satId >= 0);
462  NS_ASSERT(!m_rxCarriers.empty());
463 
464  m_satId = satId;
465 
466  for (std::vector<Ptr<SatPhyRxCarrier>>::iterator it = m_rxCarriers.begin();
467  it != m_rxCarriers.end();
468  ++it)
469  {
470  (*it)->SetSatId(satId);
471  }
472 }
473 
474 uint32_t
476 {
477  NS_LOG_FUNCTION(this);
478 
479  return m_satId;
480 }
481 
482 void
483 SatPhyRx::SetBeamId(uint32_t beamId)
484 {
485  NS_LOG_FUNCTION(this << beamId);
486  NS_ASSERT(beamId >= 0);
487  NS_ASSERT(!m_rxCarriers.empty());
488 
489  m_beamId = beamId;
490 
491  for (std::vector<Ptr<SatPhyRxCarrier>>::iterator it = m_rxCarriers.begin();
492  it != m_rxCarriers.end();
493  ++it)
494  {
495  (*it)->SetBeamId(beamId);
496  }
497 }
498 
499 uint32_t
501 {
502  NS_LOG_FUNCTION(this);
503 
504  return m_beamId;
505 }
506 
507 double
508 SatPhyRx::GetRxTemperatureK(Ptr<SatSignalParameters> rxParams)
509 {
510  NS_LOG_FUNCTION(this << rxParams);
511 
512  uint32_t cId = rxParams->m_carrierId;
513 
514  if (cId >= m_rxCarriers.size())
515  {
516  NS_FATAL_ERROR("SatPhyRx::GetRxTemperatureK - unvalid carrier id: " << cId);
517  }
518 
519  return m_rxCarriers[cId]->GetRxTemperatureK();
520 }
521 
522 void
523 SatPhyRx::StartRx(Ptr<SatSignalParameters> rxParams)
524 {
525  NS_LOG_FUNCTION(this << rxParams);
526 
527  uint32_t cId = rxParams->m_carrierId;
528 
529  if (cId >= m_rxCarriers.size())
530  {
531  NS_FATAL_ERROR("SatPhyRx::StartRx - unvalid carrier id: " << cId);
532  }
533 
534  m_rxCarriers[cId]->StartRx(rxParams);
535 }
536 
537 } // namespace ns3
ChannelType_t
Types of channel.
RandomAccessModel_t
The defined random access models.
RegenerationMode_t
The regeneration mode used in satellites.
void ConfigurePhyRxCarriers(Ptr< SatPhyRxCarrierConf > carrierConf, Ptr< SatSuperframeConf > superFrameConf)
uint32_t GetSatId() const
Get satellite id of this receiver.
Ptr< SatAntennaGainPattern > m_antennaGainPattern
virtual void DoDispose()
Dispose of this class instance.
SatPhyRx()
Default constructor.
void SetFadingContainer(Ptr< SatBaseFading > fadingContainer)
Set fading container.
void SetAntennaLoss_Db(double loss_Db)
Set the Antenna loss in Db.
void SetAntennaGainPattern(Ptr< SatAntennaGainPattern > agp, Ptr< SatMobilityModel > mobility)
void SetMaxAntennaGain_Db(double gain_Db)
Set the maximum Antenna gain in Db.
void SetDevice(Ptr< NetDevice > d)
Callback< void, uint32_t, uint32_t, Address, Address, double, bool > CnoCallback
virtual ~SatPhyRx()
Destructor for SatPhyRx.
double GetFadingValue(Address macAddress, SatEnums::ChannelType_t channelType)
Get fading value.
double GetRxTemperatureK(Ptr< SatSignalParameters > rxParams)
Method for querying the temperature of the chosen carrier.
void BeginEndScheduling()
Begin frame/window end scheduling for processes utilizing frame length as interval.
double m_maxAntennaGain
Configured maximum antenna gain in linear.
void SetSatId(uint32_t satId)
Set the satellite id for all the transmissions from this SatPhyTx.
void SetMobility(Ptr< MobilityModel > m)
Mac48Address m_macAddress
Mac48Address GetAddress() const
Get MAC address of this PHY/MAC.
void SetAverageNormalizedOfferedLoadCallback(SatPhyRx::AverageNormalizedOfferedLoadCallback cb)
Set average normalized offered load callback.
void SetCnoCallback(SatPhyRx::CnoCallback cb)
Set C/N0 receiver.
std::vector< Ptr< SatPhyRxCarrier > > m_rxCarriers
void SetDefaultFadingValue(double fadingValue)
Function for setting the default fading value.
double GetAntennaGain(Ptr< MobilityModel > mobility)
Get antenna gain based on position or in case that antenna pattern is not configured,...
Ptr< NetDevice > m_device
double m_defaultFadingValue
Default fading value.
Ptr< MobilityModel > m_mobility
Callback< void, Ptr< SatSignalParameters >, bool > ReceiveCallback
void SetReceiveCallback(SatPhyRx::ReceiveCallback cb)
Set the upper layer receive callback.
virtual void StartRx(Ptr< SatSignalParameters > rxParams)
Start packet reception from the SatChannel.
double GetLosses()
Get configures RX losses, currently only antenna loss used.
Ptr< MobilityModel > GetMobility()
void SetBeamId(uint32_t beamId)
Set the beam id for all the transmissions from this SatPhyTx.
Ptr< SatBaseFading > m_fadingContainer
Fading container for fading model.
void SetNodeInfo(const Ptr< SatNodeInfo > nodeInfo)
Set the node info class.
double m_antennaLoss
Configured antenna loss in linear.
Callback< void, uint32_t, uint32_t, uint32_t, uint8_t, double > AverageNormalizedOfferedLoadCallback
Ptr< SatMobilityModel > m_satMobility
uint32_t GetBeamId() const
Get beam id of this receiver.
Ptr< NetDevice > GetDevice()
static TypeId GetTypeId(void)
inherited from Object
static T DbWToW(T dbw)
Converts Decibel Watts to Watts.
static T DbToLinear(T db)
Converts decibels to linear.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.