34 #include <ns3/boolean.h>
37 #include <ns3/mobility-model.h>
38 #include <ns3/net-device.h>
40 #include <ns3/object.h>
41 #include <ns3/packet.h>
42 #include <ns3/propagation-delay-model.h>
43 #include <ns3/simulator.h>
44 #include <ns3/singleton.h>
48 NS_LOG_COMPONENT_DEFINE(
"SatChannel");
53 NS_OBJECT_ENSURE_REGISTERED(SatChannel);
59 m_carrierFreqConverter(),
63 m_rxPowerCalculationMode(
SatEnums::RX_PWR_CALCULATION),
71 m_enableRxPowerOutputTrace(false),
72 m_enableFadingOutputTrace(false),
73 m_enableExternalFadingInputTrace(false)
75 NS_LOG_FUNCTION(
this);
80 NS_LOG_FUNCTION(
this);
86 NS_LOG_FUNCTION(
this);
96 TypeId(
"ns3::SatChannel")
98 .AddConstructor<SatChannel>()
99 .AddAttribute(
"EnableRxPowerOutputTrace",
100 "Enable Rx power output trace.",
103 MakeBooleanChecker())
104 .AddAttribute(
"EnableFadingOutputTrace",
105 "Enable fading output trace.",
108 MakeBooleanChecker())
109 .AddAttribute(
"EnableExternalFadingInputTrace",
110 "Enable external fading input trace.",
113 MakeBooleanChecker())
114 .AddAttribute(
"RxPowerCalculationMode",
115 "Rx Power calculation mode",
119 "RxPowerCalculation",
124 .AddAttribute(
"ForwardingMode",
125 "Channel forwarding mode.",
140 NS_LOG_FUNCTION(
this << phyRx);
147 NS_LOG_FUNCTION(
this << phyRx);
149 PhyRxContainer::iterator phyIter =
161 NS_LOG_FUNCTION(
this << txParams);
162 NS_ASSERT_MSG(txParams->m_phyTx,
"NULL phyTx");
174 for (PhyRxContainer::const_iterator rxPhyIterator =
m_phyRxContainer.begin();
179 if ((*rxPhyIterator)->GetBeamId() == txParams->m_beamId)
195 SatSignalParameters::PacketsInBurst_t::const_iterator it =
196 txParams->m_packetsInBurst.begin();
197 for (; it != txParams->m_packetsInBurst.end(); ++it)
200 bool mSuccess = (*it)->PeekPacketTag(macTag);
203 NS_FATAL_ERROR(
"MAC tag was not found from the packet!");
209 if (dest == (*rxPhyIterator)->GetAddress() || dest.IsBroadcast() ||
222 NS_FATAL_ERROR(
"Unsupported channel type!");
236 for (PhyRxContainer::const_iterator rxPhyIterator =
m_phyRxContainer.begin();
241 if ((*rxPhyIterator)->GetBeamId() == txParams->m_beamId)
255 for (PhyRxContainer::const_iterator rxPhyIterator =
m_phyRxContainer.begin();
264 NS_FATAL_ERROR(
"Unsupported SatChannel FwdMode!");
273 NS_LOG_FUNCTION(
this << txParams << receiver);
275 Time delay = Seconds(0);
277 Ptr<MobilityModel> senderMobility = txParams->m_phyTx->GetMobility();
278 Ptr<MobilityModel> receiverMobility = receiver->GetMobility();
280 NS_LOG_INFO(
"copying signal parameters " << txParams);
281 Ptr<SatSignalParameters> rxParams = txParams->Copy();
298 NS_FATAL_ERROR(
"SatChannel::ScheduleRx - propagation delay model not set!");
301 NS_LOG_INFO(
"Setting propagation delay: " << delay);
303 Ptr<NetDevice> netDev = receiver->GetDevice();
304 uint32_t dstNodeId = netDev->GetNode()->GetId();
305 Simulator::ScheduleWithContext(dstNodeId,
316 NS_LOG_FUNCTION(
this << rxParams << phyRx);
321 rxParams->m_carrierFreq_hz = frequency_hz;
343 NS_FATAL_ERROR(
"SatChannel::StartRx - Invalid Rx power calculation mode");
348 phyRx->StartRx(rxParams);
354 NS_LOG_FUNCTION(
this << rxParams << phyRx);
358 rxParams->m_carrierId,
361 NS_LOG_INFO(
"Carrier bw: " << carrierBandwidthHz
363 <<
", carrierId: " << rxParams->m_carrierId
366 std::vector<double> tempVector;
367 tempVector.push_back(Now().GetSeconds());
370 tempVector.push_back(rxParams->m_rxPower_W / carrierBandwidthHz);
376 Singleton<SatRxPowerOutputTraceContainer>::Get()->AddToContainer(
377 std::make_pair(phyRx->GetDevice()->GetAddress(),
m_channelType),
383 Singleton<SatRxPowerOutputTraceContainer>::Get()->AddToContainer(
389 NS_FATAL_ERROR(
"SatChannel::DoRxPowerOutputTrace - Invalid channel type");
398 NS_LOG_FUNCTION(
this << rxParams << phyRx);
402 rxParams->m_carrierId,
410 rxParams->m_rxPower_W =
412 Singleton<SatRxPowerInputTraceContainer>::Get()->GetRxPowerDensity(
413 std::make_pair(phyRx->GetDevice()->GetAddress(),
m_channelType));
420 rxParams->m_rxPower_W =
421 carrierBandwidthHz * Singleton<SatRxPowerInputTraceContainer>::Get()->GetRxPowerDensity(
426 NS_FATAL_ERROR(
"SatChannel::DoRxPowerInputTrace - Invalid channel type");
431 NS_LOG_INFO(
"Carrier bw: " << carrierBandwidthHz
433 <<
", carrierId: " << rxParams->m_carrierId
446 NS_LOG_FUNCTION(
this << rxParams << phyRx);
459 rxParams->m_carrierId,
461 double rxTemperatureK = phyRx->GetRxTemperatureK(rxParams);
463 double rxNoisePowerW =
471 cno = Singleton<SatRxCnoInputTraceContainer>::Get()->GetRxCno(
472 std::make_pair(phyRx->GetDevice()->GetAddress(),
m_channelType));
476 NS_LOG_INFO(
"Use calculation downlink \t" << cno <<
" " << carrierBandwidthHz <<
" "
477 << rxNoisePowerW <<
" "
478 << rxParams->m_rxPower_W);
481 rxParams->m_rxPower_W = rxNoisePowerW * cno / carrierBandwidthHz;
482 NS_LOG_INFO(
"Channel downlink \t" << cno <<
" " << carrierBandwidthHz <<
" "
483 << rxNoisePowerW <<
" "
484 << rxNoisePowerW * cno / carrierBandwidthHz);
490 cno = Singleton<SatRxCnoInputTraceContainer>::Get()->GetRxCno(
495 NS_LOG_INFO(
"Use calculation uplink \t" << cno <<
" " << carrierBandwidthHz <<
" "
496 << rxNoisePowerW <<
" "
497 << rxParams->m_rxPower_W);
500 rxParams->m_rxPower_W = rxNoisePowerW * cno / carrierBandwidthHz;
501 NS_LOG_INFO(
"Channel uplink \t" << cno <<
" " << carrierBandwidthHz <<
" "
502 << rxNoisePowerW <<
" "
503 << rxNoisePowerW * cno / carrierBandwidthHz);
507 NS_FATAL_ERROR(
"SatChannel::DoRxCnoInputTrace - Invalid channel type");
512 NS_LOG_INFO(
"Target C/N0: " << cno <<
", carrier bw: " << carrierBandwidthHz
514 <<
", carrierId: " << rxParams->m_carrierId <<
", channelType: "
529 NS_LOG_FUNCTION(
this << rxParams << phyRx << fadingValue);
531 std::vector<double> tempVector;
532 tempVector.push_back(Now().GetSeconds());
533 tempVector.push_back(fadingValue);
539 Singleton<SatFadingOutputTraceContainer>::Get()->AddToContainer(
540 std::make_pair(phyRx->GetDevice()->GetAddress(),
m_channelType),
546 Singleton<SatFadingOutputTraceContainer>::Get()->AddToContainer(
552 NS_FATAL_ERROR(
"SatChannel::DoFadingOutputTrace - Invalid channel type");
561 NS_LOG_FUNCTION(
this << rxParams << phyRx);
563 Ptr<MobilityModel> txMobility = rxParams->m_phyTx->GetMobility();
564 Ptr<MobilityModel> rxMobility = phyRx->GetMobility();
566 double txAntennaGain_W = 0.0;
567 double rxAntennaGain_W = 0.0;
568 double markovFading = 0.0;
569 double extFading = 1.0;
576 txAntennaGain_W = rxParams->m_phyTx->GetAntennaGain(rxMobility);
577 rxAntennaGain_W = phyRx->GetAntennaGain(rxMobility);
578 markovFading = phyRx->GetFadingValue(phyRx->GetDevice()->GetAddress(),
m_channelType);
583 txAntennaGain_W = rxParams->m_phyTx->GetAntennaGain(txMobility);
584 rxAntennaGain_W = phyRx->GetAntennaGain(txMobility);
589 NS_FATAL_ERROR(
"SatChannel::DoRxPowerCalculation - Invalid channel type");
616 double rxPower_W = (rxParams->m_txPower_W * txAntennaGain_W) /
617 m_freeSpaceLoss->GetFsl(txMobility, rxMobility, rxParams->m_carrierFreq_hz);
618 rxParams->m_rxPower_W =
619 rxPower_W * rxAntennaGain_W / phyRx->GetLosses() * markovFading / extFading;
625 NS_LOG_FUNCTION(
this << rxParams << phyRx);
628 Ptr<MobilityModel> mobility;
633 nodeId = Singleton<SatIdMapper>::Get()->GetGwIdWithMac(phyRx->GetDevice()->GetAddress());
634 mobility = phyRx->GetMobility();
638 nodeId = Singleton<SatIdMapper>::Get()->GetUtIdWithMac(phyRx->GetDevice()->GetAddress());
639 mobility = phyRx->GetMobility();
643 nodeId = Singleton<SatIdMapper>::Get()->GetUtIdWithMac(
GetSourceAddress(rxParams));
644 mobility = rxParams->m_phyTx->GetMobility();
648 nodeId = Singleton<SatIdMapper>::Get()->GetGwIdWithMac(
GetSourceAddress(rxParams));
649 mobility = rxParams->m_phyTx->GetMobility();
653 NS_FATAL_ERROR(
"SatChannel::GetExternalFadingTrace - Invalid channel type");
660 NS_FATAL_ERROR(
"SatChannel::GetExternalFadingTrace - Invalid node ID");
663 return (Singleton<SatFadingExternalInputTraceContainer>::Get()->GetFadingTrace((uint32_t)nodeId,
673 NS_LOG_FUNCTION(
this << rxParams);
677 SatSignalParameters::PacketsInBurst_t::const_iterator i = rxParams->m_packetsInBurst.begin();
681 NS_FATAL_ERROR(
"SatChannel::GetSourceAddress - Empty packet list");
684 (*i)->PeekPacketTag(tag);
692 NS_LOG_FUNCTION(
this << chType);
701 NS_LOG_FUNCTION(
this << freqId);
709 NS_LOG_FUNCTION(
this << &converter);
717 NS_LOG_FUNCTION(
this << &converter);
725 NS_LOG_FUNCTION(
this);
734 NS_LOG_FUNCTION(
this << delay);
739 Ptr<PropagationDelayModel>
742 NS_LOG_FUNCTION(
this);
751 NS_LOG_FUNCTION(
this << loss);
756 Ptr<SatFreeSpaceLoss>
759 NS_LOG_FUNCTION(
this);
767 NS_LOG_FUNCTION(
this);
774 NS_LOG_FUNCTION(
this << i);
Satellite channel implementation.
void DoRxPowerOutputTrace(Ptr< SatSignalParameters > rxParams, Ptr< SatPhyRx > phyRx)
Function for Rx power output trace.
void DoRxCnoInputTrace(Ptr< SatSignalParameters > rxParams, Ptr< SatPhyRx > phyRx)
Function for Rx power input trace from C/N0 values.
SatChannelFwdMode_e m_fwdMode
Forwarding mode of the SatChannel: SINGLE_RX = only the proper receiver of the packet shall receive t...
virtual Ptr< PropagationDelayModel > GetPropagationDelayModel()
Get the propagation delay model to be used in the SatChannel.
virtual void DoDispose()
Dispose SatChannel.
Callback< double, SatEnums::ChannelType_t, uint32_t, uint32_t > CarrierFreqConverter
Ptr< SatFreeSpaceLoss > m_freeSpaceLoss
Free space loss model to be used with this channel.
bool m_enableFadingOutputTrace
Defines whether fading output tracing is in use or not.
SatChannel()
Default constructor.
double GetExternalFadingTrace(Ptr< SatSignalParameters > rxParams, Ptr< SatPhyRx > phyRx)
Function for getting the external source fading value.
void DoRxPowerCalculation(Ptr< SatSignalParameters > rxParams, Ptr< SatPhyRx > phyRx)
Function for calculating the Rx power.
static TypeId GetTypeId(void)
Get the type ID.
virtual void SetFrequencyId(uint32_t freqId)
Set the frequency id of the channel.
void DoRxPowerInputTrace(Ptr< SatSignalParameters > rxParams, Ptr< SatPhyRx > phyRx)
Function for Rx power input trace.
SatTypedefs::CarrierBandwidthConverter_t m_carrierBandwidthConverter
Bandwidth converter callback.
virtual void SetChannelType(SatEnums::ChannelType_t chType)
Set the type of the channel.
bool m_enableRxPowerOutputTrace
Defines whether Rx power output tracing is in use or not.
uint32_t m_freqId
Frequency id of the channel.
virtual void SetPropagationDelayModel(Ptr< PropagationDelayModel > delay)
Set the propagation delay model to be used in the SatChannel.
virtual void RemoveRx(Ptr< SatPhyRx > phyRx)
This method is used to remove a SatPhyRx instance from a SatChannel instance, e.g.
Mac48Address GetSourceAddress(Ptr< SatSignalParameters > rxParams)
Function for getting the source MAC address from Rx parameters.
void DoFadingOutputTrace(Ptr< SatSignalParameters > rxParams, Ptr< SatPhyRx > phyRx, double fadingValue)
Function for fading output trace.
virtual Ptr< NetDevice > GetDevice(std::size_t i) const
Get a device for a certain receiver index.
virtual void SetBandwidthConverter(SatTypedefs::CarrierBandwidthConverter_t converter)
Set the bandwidth converter callback.
virtual SatEnums::ChannelType_t GetChannelType()
Get the type of the channel.
PhyRxContainer m_phyRxContainer
Container of SatPhyRx instances attached to the channel.
void ScheduleRx(Ptr< SatSignalParameters > txParams, Ptr< SatPhyRx > phyRx)
Used internally to schedule the StartRx method call after the propagation delay.
void StartRx(Ptr< SatSignalParameters > rxParams, Ptr< SatPhyRx > phyRx)
Used internally to start the packet reception of at the phyRx.
virtual void StartTx(Ptr< SatSignalParameters > params)
Used by attached SatPhyTx instances to transmit signals to the channel.
virtual ~SatChannel()
Destructor for SatChannel.
virtual void SetFreeSpaceLoss(Ptr< SatFreeSpaceLoss > delay)
Set the propagation delay model to be used in the SatChannel.
CarrierFreqConverter m_carrierFreqConverter
Frequency converter callback.
SatEnums::ChannelType_t m_channelType
Type of the channel.
virtual void AddRx(Ptr< SatPhyRx > phyRx)
This method is used to attach the receiver entity SatPhyRx instance to a SatChannel instance,...
Ptr< PropagationDelayModel > m_propagationDelay
Propagation delay model to be used with this channel.
virtual void SetFrequencyConverter(CarrierFreqConverter converter)
Set the frequency converter callback.
bool m_enableExternalFadingInputTrace
Defines whether external fading input tracing is in use or not.
virtual std::size_t GetNDevices(void) const
virtual Ptr< SatFreeSpaceLoss > GetFreeSpaceLoss() const
Get the propagation delay model used in the SatChannel.
SatEnums::RxPowerCalculationMode_t m_rxPowerCalculationMode
Defines the mode used for Rx power calculation.
SatEnums class is for simplifying the use of enumerators in the satellite module.
ChannelType_t
Types of channel.
static std::string GetChannelTypeName(ChannelType_t channelType)
This class implements a tag that carries the satellite MAC specific information, such as source and d...
Mac48Address GetSourceAddress(void) const
Get source MAC address.
Mac48Address GetDestAddress(void) const
Get destination MAC address.
Callback< double, SatEnums::ChannelType_t, uint32_t, SatEnums::CarrierBandwidthType_t > CarrierBandwidthConverter_t
Callback for carrier bandwidths.
static T LinearToDb(T linear)
Converts linear to decibels.
constexpr double BOLTZMANN_CONSTANT
Boltzmann Constant.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.