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"
51NS_LOG_COMPONENT_DEFINE(
"SatChannel");
79 NS_LOG_FUNCTION(
this);
85 NS_LOG_FUNCTION(
this);
87 Channel::NotifyConstructionCompleted();
92 CreateObject<SatFadingExternalInputTraceContainer>();
98 NS_LOG_FUNCTION(
this);
104 NS_LOG_FUNCTION(
this);
107 Channel::DoDispose();
114 TypeId(
"ns3::SatChannel")
115 .SetParent<Channel>()
116 .AddConstructor<SatChannel>()
117 .AddAttribute(
"EnableRxPowerOutputTrace",
118 "Enable Rx power output trace.",
121 MakeBooleanChecker())
122 .AddAttribute(
"EnableFadingOutputTrace",
123 "Enable fading output trace.",
126 MakeBooleanChecker())
127 .AddAttribute(
"EnableExternalFadingInputTrace",
128 "Enable external fading input trace.",
131 MakeBooleanChecker())
132 .AddAttribute(
"RxPowerCalculationMode",
133 "Rx Power calculation mode",
135 MakeEnumAccessor<SatEnums::RxPowerCalculationMode_t>(
138 "RxPowerCalculation",
143 .AddAttribute(
"ForwardingMode",
144 "Channel forwarding mode.",
159 NS_LOG_FUNCTION(
this << phyRx);
167 NS_LOG_FUNCTION(
this << phyRx);
169 PhyRxContainer::iterator phyIter =
181 NS_LOG_FUNCTION(
this << txParams);
182 NS_ASSERT_MSG(txParams->m_phyTx,
"NULL phyTx");
194 for (PhyRxContainer::const_iterator rxPhyIterator =
m_phyRxContainer.begin();
199 if ((*rxPhyIterator)->GetBeamId() == txParams->m_beamId)
215 SatSignalParameters::PacketsInBurst_t::const_iterator it =
216 txParams->m_packetsInBurst.begin();
217 for (; it != txParams->m_packetsInBurst.end(); ++it)
220 bool mSuccess = (*it)->PeekPacketTag(macTag);
223 NS_FATAL_ERROR(
"MAC tag was not found from the packet!");
229 if (dest == (*rxPhyIterator)->GetAddress() || dest.IsBroadcast() ||
242 NS_FATAL_ERROR(
"Unsupported channel type!");
256 for (PhyRxContainer::const_iterator rxPhyIterator =
m_phyRxContainer.begin();
261 if ((*rxPhyIterator)->GetBeamId() == txParams->m_beamId)
275 for (PhyRxContainer::const_iterator rxPhyIterator =
m_phyRxContainer.begin();
284 NS_FATAL_ERROR(
"Unsupported SatChannel FwdMode!");
293 NS_LOG_FUNCTION(
this << txParams << receiver);
295 Time delay = Seconds(0);
297 Ptr<MobilityModel> senderMobility = txParams->m_phyTx->GetMobility();
298 Ptr<MobilityModel> receiverMobility = receiver->GetMobility();
300 NS_LOG_INFO(
"copying signal parameters " << txParams);
301 Ptr<SatSignalParameters> rxParams = txParams->Copy();
318 NS_FATAL_ERROR(
"SatChannel::ScheduleRx - propagation delay model not set!");
321 NS_LOG_INFO(
"Setting propagation delay: " << delay);
323 Ptr<NetDevice> netDev = receiver->GetDevice();
324 uint32_t dstNodeId = netDev->GetNode()->GetId();
325 Simulator::ScheduleWithContext(dstNodeId,
336 NS_LOG_FUNCTION(
this << rxParams << phyRx);
341 rxParams->m_carrierFreq_hz = frequency_hz;
363 NS_FATAL_ERROR(
"SatChannel::StartRx - Invalid Rx power calculation mode");
368 phyRx->StartRx(rxParams);
374 NS_LOG_FUNCTION(
this << rxParams << phyRx);
378 rxParams->m_carrierId,
381 NS_LOG_INFO(
"Carrier bw: " << carrierBandwidthHz
383 <<
", carrierId: " << rxParams->m_carrierId
386 std::vector<double> tempVector;
387 tempVector.push_back(Now().GetSeconds());
390 tempVector.push_back(rxParams->m_rxPower_W / carrierBandwidthHz);
396 Singleton<SatRxPowerOutputTraceContainer>::Get()->AddToContainer(
397 std::make_pair(phyRx->GetDevice()->GetAddress(),
m_channelType),
403 Singleton<SatRxPowerOutputTraceContainer>::Get()->AddToContainer(
409 NS_FATAL_ERROR(
"SatChannel::DoRxPowerOutputTrace - Invalid channel type");
418 NS_LOG_FUNCTION(
this << rxParams << phyRx);
422 rxParams->m_carrierId,
430 rxParams->m_rxPower_W =
432 Singleton<SatRxPowerInputTraceContainer>::Get()->GetRxPowerDensity(
433 std::make_pair(phyRx->GetDevice()->GetAddress(),
m_channelType));
440 rxParams->m_rxPower_W =
441 carrierBandwidthHz * Singleton<SatRxPowerInputTraceContainer>::Get()->GetRxPowerDensity(
446 NS_FATAL_ERROR(
"SatChannel::DoRxPowerInputTrace - Invalid channel type");
451 NS_LOG_INFO(
"Carrier bw: " << carrierBandwidthHz
453 <<
", carrierId: " << rxParams->m_carrierId
466 NS_LOG_FUNCTION(
this << rxParams << phyRx);
479 rxParams->m_carrierId,
481 double rxTemperatureK = phyRx->GetRxTemperatureK(rxParams);
483 double rxNoisePowerW =
491 cno = Singleton<SatRxCnoInputTraceContainer>::Get()->GetRxCno(
492 std::make_pair(phyRx->GetDevice()->GetAddress(),
m_channelType));
496 NS_LOG_INFO(
"Use calculation downlink \t" << cno <<
" " << carrierBandwidthHz <<
" "
497 << rxNoisePowerW <<
" "
498 << rxParams->m_rxPower_W);
501 rxParams->m_rxPower_W = rxNoisePowerW * cno / carrierBandwidthHz;
502 NS_LOG_INFO(
"Channel downlink \t" << cno <<
" " << carrierBandwidthHz <<
" "
503 << rxNoisePowerW <<
" "
504 << rxNoisePowerW * cno / carrierBandwidthHz);
510 cno = Singleton<SatRxCnoInputTraceContainer>::Get()->GetRxCno(
515 NS_LOG_INFO(
"Use calculation uplink \t" << cno <<
" " << carrierBandwidthHz <<
" "
516 << rxNoisePowerW <<
" "
517 << rxParams->m_rxPower_W);
520 rxParams->m_rxPower_W = rxNoisePowerW * cno / carrierBandwidthHz;
521 NS_LOG_INFO(
"Channel uplink \t" << cno <<
" " << carrierBandwidthHz <<
" "
522 << rxNoisePowerW <<
" "
523 << rxNoisePowerW * cno / carrierBandwidthHz);
527 NS_FATAL_ERROR(
"SatChannel::DoRxCnoInputTrace - Invalid channel type");
532 NS_LOG_INFO(
"Target C/N0: " << cno <<
", carrier bw: " << carrierBandwidthHz
534 <<
", carrierId: " << rxParams->m_carrierId <<
", channelType: "
549 NS_LOG_FUNCTION(
this << rxParams << phyRx << fadingValue);
551 std::vector<double> tempVector;
552 tempVector.push_back(Now().GetSeconds());
553 tempVector.push_back(fadingValue);
559 Singleton<SatFadingOutputTraceContainer>::Get()->AddToContainer(
560 std::make_pair(phyRx->GetDevice()->GetAddress(),
m_channelType),
566 Singleton<SatFadingOutputTraceContainer>::Get()->AddToContainer(
572 NS_FATAL_ERROR(
"SatChannel::DoFadingOutputTrace - Invalid channel type");
581 NS_LOG_FUNCTION(
this << rxParams << phyRx);
583 Ptr<MobilityModel> txMobility = rxParams->m_phyTx->GetMobility();
584 Ptr<MobilityModel> rxMobility = phyRx->GetMobility();
586 double txAntennaGain_W = 0.0;
587 double rxAntennaGain_W = 0.0;
588 double markovFading = 0.0;
589 double extFading = 1.0;
596 txAntennaGain_W = rxParams->m_phyTx->GetAntennaGain(rxMobility);
597 rxAntennaGain_W = phyRx->GetAntennaGain(rxMobility);
598 markovFading = phyRx->GetFadingValue(phyRx->GetDevice()->GetAddress(),
m_channelType);
603 txAntennaGain_W = rxParams->m_phyTx->GetAntennaGain(txMobility);
604 rxAntennaGain_W = phyRx->GetAntennaGain(txMobility);
609 NS_FATAL_ERROR(
"SatChannel::DoRxPowerCalculation - Invalid channel type");
636 double rxPower_W = (rxParams->m_txPower_W * txAntennaGain_W) /
637 m_freeSpaceLoss->GetFsl(txMobility, rxMobility, rxParams->m_carrierFreq_hz);
638 rxParams->m_rxPower_W =
639 rxPower_W * rxAntennaGain_W / phyRx->GetLosses() * markovFading / extFading;
645 NS_LOG_FUNCTION(
this << rxParams << phyRx);
648 Ptr<MobilityModel> mobility;
653 nodeId = Singleton<SatIdMapper>::Get()->GetGwIdWithMac(phyRx->GetDevice()->GetAddress());
654 mobility = phyRx->GetMobility();
658 nodeId = Singleton<SatIdMapper>::Get()->GetUtIdWithMac(phyRx->GetDevice()->GetAddress());
659 mobility = phyRx->GetMobility();
663 nodeId = Singleton<SatIdMapper>::Get()->GetUtIdWithMac(
GetSourceAddress(rxParams));
664 mobility = rxParams->m_phyTx->GetMobility();
668 nodeId = Singleton<SatIdMapper>::Get()->GetGwIdWithMac(
GetSourceAddress(rxParams));
669 mobility = rxParams->m_phyTx->GetMobility();
673 NS_FATAL_ERROR(
"SatChannel::GetExternalFadingTrace - Invalid channel type");
680 NS_FATAL_ERROR(
"SatChannel::GetExternalFadingTrace - Invalid node ID");
693 NS_LOG_FUNCTION(
this << rxParams);
697 SatSignalParameters::PacketsInBurst_t::const_iterator i = rxParams->m_packetsInBurst.begin();
701 NS_FATAL_ERROR(
"SatChannel::GetSourceAddress - Empty packet list");
704 (*i)->PeekPacketTag(tag);
712 NS_LOG_FUNCTION(
this << chType);
721 NS_LOG_FUNCTION(
this << freqId);
729 NS_LOG_FUNCTION(
this << &converter);
737 NS_LOG_FUNCTION(
this << &converter);
745 NS_LOG_FUNCTION(
this);
754 NS_LOG_FUNCTION(
this << delay);
759Ptr<PropagationDelayModel>
762 NS_LOG_FUNCTION(
this);
771 NS_LOG_FUNCTION(
this << loss);
779 NS_LOG_FUNCTION(
this);
787 NS_LOG_FUNCTION(
this);
794 NS_LOG_FUNCTION(
this << i);
Satellite channel implementation.
Ptr< SatFadingExternalInputTraceContainer > m_satFadingExternalInputTraceContainer
External fading input tracing container.
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.
virtual void NotifyConstructionCompleted() override
Notifier called once the ObjectBase is fully constructed.
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.