37#include "ns3/boolean.h"
38#include "ns3/double.h"
41#include "ns3/pointer.h"
42#include "ns3/simulator.h"
43#include "ns3/uinteger.h"
45NS_LOG_COMPONENT_DEFINE(
"SatPhy");
50NS_OBJECT_ENSURE_REGISTERED(
SatPhy);
70 NS_LOG_FUNCTION(
this);
71 NS_FATAL_ERROR(
"SatPhy default constructor is not allowed to use");
100 m_phyTx = CreateObject<SatPhyTx>();
101 m_phyRx = CreateObject<SatPhyRx>();
105 m_phyTx = CreateObject<SatLoraPhyTx>();
106 m_phyRx = CreateObject<SatPhyRx>();
110 m_phyTx = CreateObject<SatLoraPhyTx>();
111 m_phyRx = CreateObject<SatLoraPhyRx>();
115 m_phyTx = CreateObject<SatLoraPhyTx>();
116 m_phyRx = CreateObject<SatPhyRx>();
120 NS_FATAL_ERROR(
"Standard not implemented yet: " <<
m_params.m_standard);
127 NS_LOG_FUNCTION(
this);
129 Object::NotifyConstructionCompleted();
131 Ptr<MobilityModel> mobility =
m_params.m_device->GetNode()->GetObject<MobilityModel>();
139 m_phyTx->SetMobility(mobility);
140 m_phyRx->SetMobility(mobility);
147 TypeId(
"ns3::SatPhy")
149 .AddAttribute(
"ReceiveCb",
150 "The receive callback for this phy.",
153 MakeCallbackChecker())
154 .AddAttribute(
"CnoCb",
155 "The C/N0 info callback for this phy.",
158 MakeCallbackChecker())
159 .AddAttribute(
"AverageNormalizedOfferedLoadCallback",
160 "The average offered random access load callback for this phy.",
163 MakeCallbackChecker())
164 .AddAttribute(
"EnableStatisticsTags",
165 "If true, some tags will be added to each transmitted packet to assist "
166 "with statistics computation",
169 MakeBooleanChecker())
170 .AddTraceSource(
"PacketTrace",
171 "Packet event trace",
173 "ns3::SatTypedefs::PacketTraceCallback")
174 .AddTraceSource(
"Rx",
177 "ns3::SatTypedefs::PacketSourceAddressCallback")
178 .AddTraceSource(
"RxDelay",
179 "A packet is received with delay information",
181 "ns3::SatTypedefs::PacketDelayAddressCallback")
182 .AddTraceSource(
"RxLinkDelay",
183 "A packet is received with link delay information",
185 "ns3::SatTypedefs::PacketDelayAddressCallback")
186 .AddTraceSource(
"RxJitter",
187 "A packet is received with jitter information",
189 "ns3::SatTypedefs::PacketJitterAddressCallback")
190 .AddTraceSource(
"RxLinkJitter",
191 "A packet is received with link jitter information",
193 "ns3::SatTypedefs::PacketJitterAddressCallback")
194 .AddTraceSource(
"RxLinkModcod",
195 "A packet is received with link MODCOD information",
197 "ns3::SatTypedefs::PacketModcodAddressCallback");
204 NS_LOG_FUNCTION(
this);
205 Object::DoInitialize();
211 NS_LOG_FUNCTION(
this);
214 double eirpWoGainDbw =
234 m_phyRx->SetAverageNormalizedOfferedLoadCallback(
249 NS_LOG_FUNCTION(
this);
255 NS_LOG_FUNCTION(
this);
267 NS_LOG_FUNCTION(
this << sinr << otherInterference);
271 NS_FATAL_ERROR(
"Calculated own SINR is expected to be greater than zero!!!");
274 if (otherInterference <= 0)
276 NS_FATAL_ERROR(
"Interference is expected to be greater than zero!!!");
279 double finalSinr = 1 / ((1 / sinr) + (1 / otherInterference));
286 Ptr<SatMobilityModel> satelliteMobility)
288 NS_LOG_FUNCTION(
this);
289 m_phyTx->SetAntennaGainPattern(agp, satelliteMobility);
294 Ptr<SatMobilityModel> satelliteMobility)
296 NS_LOG_FUNCTION(
this);
297 m_phyRx->SetAntennaGainPattern(agp, satelliteMobility);
302 Ptr<SatSuperframeConf> superFrameConf)
304 NS_LOG_FUNCTION(
this);
305 m_phyRx->ConfigurePhyRxCarriers(carrierConf, superFrameConf);
311 NS_LOG_FUNCTION(
this);
313 m_phyRx->SetFadingContainer(fadingContainer);
319 NS_LOG_FUNCTION(
this);
321 m_phyTx->SetFadingContainer(fadingContainer);
327 NS_LOG_FUNCTION(
this << nodeInfo);
329 m_phyRx->SetNodeInfo(nodeInfo);
335 NS_LOG_FUNCTION(
this);
342 NS_LOG_FUNCTION(
this);
349 NS_LOG_FUNCTION(
this);
356 NS_LOG_FUNCTION(
this << phyTx);
363 NS_LOG_FUNCTION(
this << phyRx);
370 NS_LOG_FUNCTION(
this);
382 NS_LOG_FUNCTION(
this << carrierId << duration);
383 NS_LOG_INFO(
"Sending a packet with carrierId: " << carrierId <<
" duration: " << duration);
401 Ptr<SatSignalParameters> txParams = CreateObject<SatSignalParameters>();
402 txParams->m_duration = duration;
404 txParams->m_packetsInBurst = p;
407 txParams->m_carrierId = carrierId;
409 txParams->m_txInfo.modCod = txInfo.
modCod;
410 txParams->m_txInfo.sliceId = txInfo.
sliceId;
412 txParams->m_txInfo.frameType = txInfo.
frameType;
413 txParams->m_txInfo.waveformId = txInfo.
waveformId;
414 txParams->m_txInfo.packetType = txInfo.
packetType;
423 NS_LOG_FUNCTION(
this << txParams);
435 NS_LOG_FUNCTION(
this << satId);
444 NS_LOG_FUNCTION(
this << beamId);
446 bool connect =
m_beamId == 0 && beamId != 0;
447 bool disconnect =
m_beamId != 0 && beamId == 0;
453 return connect || disconnect;
461 for (PacketContainer_t::const_iterator it = packets.begin(); it != packets.end(); ++it)
464 if (!(*it)->PeekPacketTag(timeTag))
489 NS_LOG_FUNCTION(
this);
493 SatSignalParameters::PacketsInBurst_t::iterator it1;
494 for (it1 = packets.begin(); it1 != packets.end(); ++it1)
497 bool isTaggedWithAddress =
false;
498 ByteTagIterator it2 = (*it1)->GetByteTagIterator();
500 while (!isTaggedWithAddress && it2.HasNext())
502 ByteTagIterator::Item item = it2.Next();
506 NS_LOG_DEBUG(
this <<
" contains a SatAddressTag tag:" <<
" start="
507 << item.GetStart() <<
" end=" << item.GetEnd());
509 item.GetTag(addrTag);
511 isTaggedWithAddress =
true;
518 if ((*it1)->RemovePacketTag(linkTimeTag))
520 NS_LOG_DEBUG(
this <<
" contains a SatPhyLinkTimeTag tag");
532 if ((*it1)->RemovePacketTag(timeTag))
534 NS_LOG_DEBUG(
this <<
" contains a SatPhyTimeTag tag");
553 NS_LOG_FUNCTION(
this);
562 SatSignalParameters::PacketsInBurst_t::iterator it1;
563 for (it1 = rxParams->m_packetsInBurst.begin(); it1 != rxParams->m_packetsInBurst.end();
566 if (!(*it1)->PeekPacketTag(satAddressE2ETag))
568 NS_FATAL_ERROR(
"SatUplinkInfoTag not found");
576 SatSignalParameters::PacketsInBurst_t::iterator it1;
577 for (it1 = rxParams->m_packetsInBurst.begin(); it1 != rxParams->m_packetsInBurst.end();
580 if (!(*it1)->PeekPacketTag(satAddressE2ETag))
582 NS_FATAL_ERROR(
"SatUplinkInfoTag not found");
590 NS_FATAL_ERROR(
"Incorrect satellite RX link direction");
598 NS_LOG_FUNCTION(
this << rxParams << phyError);
617 NS_LOG_INFO(
this <<
" dropped " << rxParams->m_packetsInBurst.size()
618 <<
" packets because of PHY error.");
623 RxTraces(rxParams->m_packetsInBurst);
641 NS_LOG_FUNCTION(
this << beamId << source << cno << isSatelliteMac);
642 m_cnoCallback(satId, beamId, source, dest, cno, isSatelliteMac);
649 uint8_t allocationChannelId,
650 double averageNormalizedOfferedLoad)
652 NS_LOG_FUNCTION(
this << satId << beamId << carrierId << allocationChannelId
653 << averageNormalizedOfferedLoad);
658 averageNormalizedOfferedLoad);
664 NS_LOG_FUNCTION(
this << &cb);
This class implements a tag that carries the satellite MAC of GW and UT.
Mac48Address GetE2ESourceAddress(void) const
Get E2E source MAC address.
Mac48Address GetE2EDestAddress(void) const
Get E2E destination MAC address.
This class implements a tag that carries the MAC address of the sender of the packet.
static TypeId GetTypeId()
Inherited from ObjectBase base class.
Address GetSourceAddress() const
Get the source address.
SatLinkDir_t
Link direction used for packet tracing.
SatPacketEvent_t
Packet event used for packet tracing.
The SatPhy models the basic physical layer of the satellite system.
virtual void SetTxAntennaGainPattern(Ptr< SatAntennaGainPattern > agp, Ptr< SatMobilityModel > satelliteMobility)
Set the transmit antenna gain pattern.
double m_txMaxAntennaGainDb
Configured maximum transmitter antenna gain in dBi.
TracedCallback< Time, SatEnums::SatPacketEvent_t, SatEnums::SatNodeType_t, uint32_t, Mac48Address, SatEnums::SatLogLevel_t, SatEnums::SatLinkDir_t, std::string > m_packetTrace
Trace callback used for packet tracing:
void SetNodeInfo(const Ptr< SatNodeInfo > nodeInfo)
Set the node info class.
void SetTimeTag(SatPhy::PacketContainer_t packets)
Set SatPhyTimeTag of packets.
void ConfigureRxCarriers(Ptr< SatPhyRxCarrierConf > carrierConf, Ptr< SatSuperframeConf > superFrameConf)
Configure Rx carriers.
void Initialize()
Initialize phy.
virtual Ptr< SatPhyTx > GetPhyTx() const
Get the SatPhyTx pointer.
CreateParam_t m_params
Satellite physical layer construction parameters.
virtual void SetRxAntennaGainPattern(Ptr< SatAntennaGainPattern > agp, Ptr< SatMobilityModel > satelliteMobility)
Set the receive antenna gain pattern.
TracedCallback< const Time &, const Address & > m_rxDelayTrace
Traced callback for all received packets, including delay information and the address of the senders.
TracedCallback< const Time &, const Address & > m_rxJitterTrace
Traced callback for all received packets, including jitter information and the address of the senders...
void CnoInfo(uint32_t satId, uint32_t beamId, Address source, Address destination, double cno, bool isSatelliteMac)
Function for getting the C/NO information.
void SetSatId(uint32_t satId)
Set the satId this PHY is connected with.
TracedCallback< const Time &, const Address & > m_rxLinkDelayTrace
Traced callback for all received packets, including link delay information and the address of the sen...
Ptr< SatPhyRx > m_phyRx
Pointer to internal SatPhyRx instance.
virtual SatEnums::SatLinkDir_t GetSatLinkTxDir()
Get the link TX direction.
virtual SatEnums::SatLinkDir_t GetSatLinkRxDir()
Get the link RX direction.
uint32_t m_satId
Satellite ID.
void BeginEndScheduling()
Begin frame/window end scheduling for processes utilizing frame length as interval.
virtual void SendPduWithParams(Ptr< SatSignalParameters > rxParams)
Send Pdu to the PHY tx module (for satellite switch packet forwarding).
uint32_t m_beamId
Beam ID.
double m_rxAntennaLossDb
Configured receiver antenna loss in Dbs.
double m_defaultFadingValue
Default fading value.
virtual Ptr< SatPhyRx > GetPhyRx() const
Get the SatPhyRx pointer.
static TypeId GetTypeId(void)
Derived from Object.
double m_txMaxPowerDbw
Configured maximum transmitter power in DbWs.
void SetRxFadingContainer(Ptr< SatBaseFading > fadingContainer)
Set fading container.
void AverageNormalizedOfferedRandomAccessLoadInfo(uint32_t satId, uint32_t beamId, uint32_t carrierId, uint8_t allocationChannelId, double averageNormalizedOfferedLoad)
Function for getting the normalized offered load of the specific random access allocation channel.
Ptr< SatChannel > GetTxChannel()
Get the Tx satellite channel.
Ptr< SatNodeInfo > m_nodeInfo
Node info containing node related information, such as node type, node id and MAC address (of the Sat...
TracedCallback< uint32_t, const Address & > m_rxLinkModcodTrace
Traced callback for all received packets, including link MODCOD information and the address of the se...
double m_rxNoiseTemperatureDbk
Configured receiver noise temperature in dBK.
double m_rxMaxAntennaGainDb
Configured maximum receiver antenna gain in dBi.
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).
void SetChannelPairGetterCallback(SatPhy::ChannelPairGetterCallback cb)
Set the channel pair getter callback.
virtual void RxTraces(SatPhy::PacketContainer_t packets)
Invoke the Rx trace source for each received packet.
virtual void Receive(Ptr< SatSignalParameters > rxParams, bool phyError)
Receives packets from lower layer.
double m_txOutputLossDb
Configured transmitter output loss in Dbs.
virtual void NotifyConstructionCompleted() override
Notifier called once the ObjectBase is fully constructed.
SatPhy::ChannelPairGetterCallback m_retrieveChannelPair
Callback for retrieving SatChannel pairs by beam.
TracedCallback< Ptr< const Packet >, const Address & > m_rxTrace
Traced callback for all received packets, including the address of the senders.
SatPhy(void)
Default constructor.
SatPhy::AverageNormalizedOfferedLoadCallback m_avgNormalizedOfferedLoadCallback
Average normalized offered load callback.
double m_eirpWoGainW
Calculated EIRP without gain in W.
virtual void SetPhyTx(Ptr< SatPhyTx > phyTx)
Set the SatPhyTx module.
Time m_lastDelay
Last delay measurement.
double m_txPointingLossDb
Configured transmitter pointing loss in Dbs.
Ptr< SatPhyTx > m_phyTx
Pointer to internal SatPhyTx instance.
void ModcodTrace(Ptr< SatSignalParameters > rxParams)
Invoke the RxLinkModcod trace source for each received packet.
double m_txAntennaLossDb
Configured transmitter antenna loss in Dbs.
bool m_isStatisticsTagsEnabled
EnableStatisticsTags attribute.
virtual void DoDispose(void)
Dispose of SatPhy.
virtual ~SatPhy()
Destructor.
Time m_lastLinkDelay
Last delay measurement for link.
void SetTxFadingContainer(Ptr< SatBaseFading > fadingContainer)
Set fading container.
double CalculateSinr(double sinr, double otherInterference)
Calculate final SINR with PHY specific parameters and given calculated SINR.
SatSignalParameters::PacketsInBurst_t PacketContainer_t
Define PacketContainer in SatPhy.
double m_txOboLossDb
Configured transmitter OBO loss in Dbs.
virtual void SetPhyRx(Ptr< SatPhyRx > phyRx)
Set the SatPhyRx module.
SatPhy::CnoCallback m_cnoCallback
The C/N0 info callback.
Callback< SatChannelPair::ChannelPair_t, uint32_t, uint32_t > ChannelPairGetterCallback
Callback for retrieving a pair of SatChannel associated to a beam.
virtual void DoInitialize(void)
Initialization of SatPhy.
SatPhy::ReceiveCallback m_rxCallback
The upper layer package receive callback.
TracedCallback< const Time &, const Address & > m_rxLinkJitterTrace
Traced callback for all received packets, including link jitter information and the address of the se...
bool SetBeamId(uint32_t beamId)
Set the beamId this PHY is connected with.
Time tag used to identify the time when packet is enqueued at PHY on current link level.
Time GetSenderLinkTimestamp(void) const
Get sender time stamp of this tag.
Time tag used to identify the time when packet is enqueued at PHY on first link between GW and UT lev...
Time GetSenderTimestamp(void) const
Get sender time stamp of this tag.
static T DbWToW(T dbw)
Converts Decibel Watts to Watts.
static std::string GetPacketInfo(const Ptr< const Packet > p)
Get packet information in std::string for printing purposes.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
Creation parameters for base PHY object.
Struct for storing the packet specific Tx information.
SatEnums::PacketType_t packetType
uint32_t crdsaUniquePacketId
SatEnums::SatBbFrameType_t frameType
uint32_t fecBlockSizeInBytes
SatEnums::SatModcod_t modCod