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>
51 NS_LOG_COMPONENT_DEFINE(
"SatChannel");
56 NS_OBJECT_ENSURE_REGISTERED(SatChannel);
62 m_carrierFreqConverter(),
66 m_rxPowerCalculationMode(
SatEnums::RX_PWR_CALCULATION),
74 m_enableRxPowerOutputTrace(false),
75 m_enableFadingOutputTrace(false),
76 m_enableExternalFadingInputTrace(false)
78 NS_LOG_FUNCTION(
this);
83 NS_LOG_FUNCTION(
this);
89 NS_LOG_FUNCTION(
this);
99 TypeId(
"ns3::SatChannel")
100 .SetParent<Channel>()
101 .AddConstructor<SatChannel>()
102 .AddAttribute(
"EnableRxPowerOutputTrace",
103 "Enable Rx power output trace.",
106 MakeBooleanChecker())
107 .AddAttribute(
"EnableFadingOutputTrace",
108 "Enable fading output trace.",
111 MakeBooleanChecker())
112 .AddAttribute(
"EnableExternalFadingInputTrace",
113 "Enable external fading input trace.",
116 MakeBooleanChecker())
117 .AddAttribute(
"RxPowerCalculationMode",
118 "Rx Power calculation mode",
120 MakeEnumAccessor<SatEnums::RxPowerCalculationMode_t>(
123 "RxPowerCalculation",
128 .AddAttribute(
"ForwardingMode",
129 "Channel forwarding mode.",
144 NS_LOG_FUNCTION(
this << phyRx);
152 NS_LOG_FUNCTION(
this << phyRx);
154 PhyRxContainer::iterator phyIter =
166 NS_LOG_FUNCTION(
this << txParams);
167 NS_ASSERT_MSG(txParams->m_phyTx,
"NULL phyTx");
179 for (PhyRxContainer::const_iterator rxPhyIterator =
m_phyRxContainer.begin();
184 if ((*rxPhyIterator)->GetBeamId() == txParams->m_beamId)
200 SatSignalParameters::PacketsInBurst_t::const_iterator it =
201 txParams->m_packetsInBurst.begin();
202 for (; it != txParams->m_packetsInBurst.end(); ++it)
205 bool mSuccess = (*it)->PeekPacketTag(macTag);
208 NS_FATAL_ERROR(
"MAC tag was not found from the packet!");
214 if (dest == (*rxPhyIterator)->GetAddress() || dest.IsBroadcast() ||
227 NS_FATAL_ERROR(
"Unsupported channel type!");
241 for (PhyRxContainer::const_iterator rxPhyIterator =
m_phyRxContainer.begin();
246 if ((*rxPhyIterator)->GetBeamId() == txParams->m_beamId)
260 for (PhyRxContainer::const_iterator rxPhyIterator =
m_phyRxContainer.begin();
269 NS_FATAL_ERROR(
"Unsupported SatChannel FwdMode!");
278 NS_LOG_FUNCTION(
this << txParams << receiver);
280 Time delay = Seconds(0);
282 Ptr<MobilityModel> senderMobility = txParams->m_phyTx->GetMobility();
283 Ptr<MobilityModel> receiverMobility = receiver->GetMobility();
285 NS_LOG_INFO(
"copying signal parameters " << txParams);
286 Ptr<SatSignalParameters> rxParams = txParams->Copy();
303 NS_FATAL_ERROR(
"SatChannel::ScheduleRx - propagation delay model not set!");
306 NS_LOG_INFO(
"Setting propagation delay: " << delay);
308 Ptr<NetDevice> netDev = receiver->GetDevice();
309 uint32_t dstNodeId = netDev->GetNode()->GetId();
310 Simulator::ScheduleWithContext(dstNodeId,
321 NS_LOG_FUNCTION(
this << rxParams << phyRx);
326 rxParams->m_carrierFreq_hz = frequency_hz;
348 NS_FATAL_ERROR(
"SatChannel::StartRx - Invalid Rx power calculation mode");
353 phyRx->StartRx(rxParams);
359 NS_LOG_FUNCTION(
this << rxParams << phyRx);
363 rxParams->m_carrierId,
366 NS_LOG_INFO(
"Carrier bw: " << carrierBandwidthHz
368 <<
", carrierId: " << rxParams->m_carrierId
371 std::vector<double> tempVector;
372 tempVector.push_back(Now().GetSeconds());
375 tempVector.push_back(rxParams->m_rxPower_W / carrierBandwidthHz);
381 Singleton<SatRxPowerOutputTraceContainer>::Get()->AddToContainer(
382 std::make_pair(phyRx->GetDevice()->GetAddress(),
m_channelType),
388 Singleton<SatRxPowerOutputTraceContainer>::Get()->AddToContainer(
394 NS_FATAL_ERROR(
"SatChannel::DoRxPowerOutputTrace - Invalid channel type");
403 NS_LOG_FUNCTION(
this << rxParams << phyRx);
407 rxParams->m_carrierId,
415 rxParams->m_rxPower_W =
417 Singleton<SatRxPowerInputTraceContainer>::Get()->GetRxPowerDensity(
418 std::make_pair(phyRx->GetDevice()->GetAddress(),
m_channelType));
425 rxParams->m_rxPower_W =
426 carrierBandwidthHz * Singleton<SatRxPowerInputTraceContainer>::Get()->GetRxPowerDensity(
431 NS_FATAL_ERROR(
"SatChannel::DoRxPowerInputTrace - Invalid channel type");
436 NS_LOG_INFO(
"Carrier bw: " << carrierBandwidthHz
438 <<
", carrierId: " << rxParams->m_carrierId
451 NS_LOG_FUNCTION(
this << rxParams << phyRx);
464 rxParams->m_carrierId,
466 double rxTemperatureK = phyRx->GetRxTemperatureK(rxParams);
468 double rxNoisePowerW =
476 cno = Singleton<SatRxCnoInputTraceContainer>::Get()->GetRxCno(
477 std::make_pair(phyRx->GetDevice()->GetAddress(),
m_channelType));
481 NS_LOG_INFO(
"Use calculation downlink \t" << cno <<
" " << carrierBandwidthHz <<
" "
482 << rxNoisePowerW <<
" "
483 << rxParams->m_rxPower_W);
486 rxParams->m_rxPower_W = rxNoisePowerW * cno / carrierBandwidthHz;
487 NS_LOG_INFO(
"Channel downlink \t" << cno <<
" " << carrierBandwidthHz <<
" "
488 << rxNoisePowerW <<
" "
489 << rxNoisePowerW * cno / carrierBandwidthHz);
495 cno = Singleton<SatRxCnoInputTraceContainer>::Get()->GetRxCno(
500 NS_LOG_INFO(
"Use calculation uplink \t" << cno <<
" " << carrierBandwidthHz <<
" "
501 << rxNoisePowerW <<
" "
502 << rxParams->m_rxPower_W);
505 rxParams->m_rxPower_W = rxNoisePowerW * cno / carrierBandwidthHz;
506 NS_LOG_INFO(
"Channel uplink \t" << cno <<
" " << carrierBandwidthHz <<
" "
507 << rxNoisePowerW <<
" "
508 << rxNoisePowerW * cno / carrierBandwidthHz);
512 NS_FATAL_ERROR(
"SatChannel::DoRxCnoInputTrace - Invalid channel type");
517 NS_LOG_INFO(
"Target C/N0: " << cno <<
", carrier bw: " << carrierBandwidthHz
519 <<
", carrierId: " << rxParams->m_carrierId <<
", channelType: "
534 NS_LOG_FUNCTION(
this << rxParams << phyRx << fadingValue);
536 std::vector<double> tempVector;
537 tempVector.push_back(Now().GetSeconds());
538 tempVector.push_back(fadingValue);
544 Singleton<SatFadingOutputTraceContainer>::Get()->AddToContainer(
545 std::make_pair(phyRx->GetDevice()->GetAddress(),
m_channelType),
551 Singleton<SatFadingOutputTraceContainer>::Get()->AddToContainer(
557 NS_FATAL_ERROR(
"SatChannel::DoFadingOutputTrace - Invalid channel type");
566 NS_LOG_FUNCTION(
this << rxParams << phyRx);
568 Ptr<MobilityModel> txMobility = rxParams->m_phyTx->GetMobility();
569 Ptr<MobilityModel> rxMobility = phyRx->GetMobility();
571 double txAntennaGain_W = 0.0;
572 double rxAntennaGain_W = 0.0;
573 double markovFading = 0.0;
574 double extFading = 1.0;
581 txAntennaGain_W = rxParams->m_phyTx->GetAntennaGain(rxMobility);
582 rxAntennaGain_W = phyRx->GetAntennaGain(rxMobility);
583 markovFading = phyRx->GetFadingValue(phyRx->GetDevice()->GetAddress(),
m_channelType);
588 txAntennaGain_W = rxParams->m_phyTx->GetAntennaGain(txMobility);
589 rxAntennaGain_W = phyRx->GetAntennaGain(txMobility);
594 NS_FATAL_ERROR(
"SatChannel::DoRxPowerCalculation - Invalid channel type");
621 double rxPower_W = (rxParams->m_txPower_W * txAntennaGain_W) /
622 m_freeSpaceLoss->GetFsl(txMobility, rxMobility, rxParams->m_carrierFreq_hz);
623 rxParams->m_rxPower_W =
624 rxPower_W * rxAntennaGain_W / phyRx->GetLosses() * markovFading / extFading;
630 NS_LOG_FUNCTION(
this << rxParams << phyRx);
633 Ptr<MobilityModel> mobility;
638 nodeId = Singleton<SatIdMapper>::Get()->GetGwIdWithMac(phyRx->GetDevice()->GetAddress());
639 mobility = phyRx->GetMobility();
643 nodeId = Singleton<SatIdMapper>::Get()->GetUtIdWithMac(phyRx->GetDevice()->GetAddress());
644 mobility = phyRx->GetMobility();
648 nodeId = Singleton<SatIdMapper>::Get()->GetUtIdWithMac(
GetSourceAddress(rxParams));
649 mobility = rxParams->m_phyTx->GetMobility();
653 nodeId = Singleton<SatIdMapper>::Get()->GetGwIdWithMac(
GetSourceAddress(rxParams));
654 mobility = rxParams->m_phyTx->GetMobility();
658 NS_FATAL_ERROR(
"SatChannel::GetExternalFadingTrace - Invalid channel type");
665 NS_FATAL_ERROR(
"SatChannel::GetExternalFadingTrace - Invalid node ID");
668 return (Singleton<SatFadingExternalInputTraceContainer>::Get()->GetFadingTrace((uint32_t)nodeId,
678 NS_LOG_FUNCTION(
this << rxParams);
682 SatSignalParameters::PacketsInBurst_t::const_iterator i = rxParams->m_packetsInBurst.begin();
686 NS_FATAL_ERROR(
"SatChannel::GetSourceAddress - Empty packet list");
689 (*i)->PeekPacketTag(tag);
697 NS_LOG_FUNCTION(
this << chType);
706 NS_LOG_FUNCTION(
this << freqId);
714 NS_LOG_FUNCTION(
this << &converter);
722 NS_LOG_FUNCTION(
this << &converter);
730 NS_LOG_FUNCTION(
this);
739 NS_LOG_FUNCTION(
this << delay);
744 Ptr<PropagationDelayModel>
747 NS_LOG_FUNCTION(
this);
756 NS_LOG_FUNCTION(
this << loss);
761 Ptr<SatFreeSpaceLoss>
764 NS_LOG_FUNCTION(
this);
772 NS_LOG_FUNCTION(
this);
779 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.