20#include "ns3/double.h"
23#include "ns3/simulator.h"
24#include "ns3/string.h"
25#include "ns3/trace-source-accessor.h"
26#include "ns3/traced-callback.h"
67 NS_LOG_WARN(
"Calculating SINR for unsupported modulation type");
70 double intKp = -
DbToKp(rxPowerDb);
71 auto it = arrivalList.begin();
72 for (; it != arrivalList.end(); it++)
75 if (std::abs((
double)it->GetTxMode().GetCenterFreqHz() - (
double)mode.
GetCenterFreqHz()) <
76 (
double)(it->GetTxMode().GetBandwidthHz() / 2 + mode.
GetBandwidthHz() / 2) - 0.5)
84 it->GetPacket()->PeekHeader(ch2);
92 <<
": PktRxMode: " << mode.
GetName()
93 <<
" Int mode: " << it->GetTxMode().GetName() <<
" Separation: "
94 << std::abs((
double)it->GetTxMode().GetCenterFreqHz() -
96 <<
" Combined bandwidths: "
97 << (
double)(it->GetTxMode().GetBandwidthHz() / 2 +
102 intKp +=
DbToKp(it->GetRxPowerDb());
109 <<
" dB. Number of interferers = " << arrivalList.size()
110 <<
" Interference + noise power = " << totalIntDb
111 <<
" dB. SINR = " << rxPowerDb - totalIntDb <<
" dB.");
112 return rxPowerDb - totalIntDb;
164 "Aggregate energy of incoming signals to move to CCA Busy state dB of Phy1.",
171 "Aggregate energy of incoming signals to move to CCA Busy state dB of Phy2.",
178 "Transmission output power in dB of Phy1.",
184 "Transmission output power in dB of Phy2.",
189 "SupportedModesPhy1",
190 "List of modes supported by Phy1.",
195 "SupportedModesPhy2",
196 "List of modes supported by Phy2.",
202 "Functor to calculate PER based on SINR and TxMode for Phy1.",
208 "Functor to calculate PER based on SINR and TxMode for Phy2.",
214 "Functor to calculate SINR based on pkt arrivals and modes for Phy1.",
220 "Functor to calculate SINR based on pkt arrivals and modes for Phy2.",
224 .AddTraceSource(
"RxOk",
225 "A packet was received successfully.",
227 "ns3::UanPhy::TracedCallback")
228 .AddTraceSource(
"RxError",
229 "A packet was received unsuccessfuly.",
231 "ns3::UanPhy::TracedCallback")
232 .AddTraceSource(
"Tx",
233 "Packet transmission beginning.",
235 "ns3::UanPhy::TracedCallback")
267 m_phy1->SendPacket(pkt, modeNum);
272 << modeNum -
m_phy1->GetNModes());
281 m_phy1->RegisterListener(listener);
282 m_phy2->RegisterListener(listener);
297 m_phy1->SetReceiveOkCallback(cb);
298 m_phy2->SetReceiveOkCallback(cb);
304 m_phy1->SetReceiveErrorCallback(cb);
305 m_phy2->SetReceiveErrorCallback(cb);
311 m_phy1->SetTxPowerDb(txpwr);
312 m_phy2->SetTxPowerDb(txpwr);
318 m_phy1->SetTxPowerDb(txpwr);
324 m_phy2->SetTxPowerDb(txpwr);
330 m_phy1->SetRxThresholdDb(thresh);
331 m_phy2->SetRxThresholdDb(thresh);
337 m_phy1->SetCcaThresholdDb(thresh);
338 m_phy2->SetCcaThresholdDb(thresh);
344 m_phy1->SetCcaThresholdDb(thresh);
350 m_phy2->SetCcaThresholdDb(thresh);
356 NS_LOG_WARN(
"Warning: Dual Phy only returns TxPowerDb of Phy 1");
357 return m_phy1->GetTxPowerDb();
363 return m_phy1->GetTxPowerDb();
369 return m_phy2->GetTxPowerDb();
375 return m_phy1->GetRxThresholdDb();
381 NS_LOG_WARN(
"Dual Phy only returns CCAThreshold of Phy 1");
382 return m_phy1->GetCcaThresholdDb();
388 return m_phy1->GetCcaThresholdDb();
394 return m_phy2->GetCcaThresholdDb();
400 return m_phy1->IsStateIdle();
406 return m_phy2->IsStateIdle();
412 return m_phy1->IsStateRx();
418 return m_phy2->IsStateRx();
424 return m_phy1->IsStateTx();
430 return m_phy1->GetPacketRx();
436 return m_phy2->GetPacketRx();
442 return m_phy2->IsStateTx();
448 return m_phy1->IsStateSleep() &&
m_phy2->IsStateSleep();
478 return m_phy1->IsStateCcaBusy() ||
m_phy2->IsStateCcaBusy();
484 return m_phy1->GetChannel();
490 return m_phy1->GetDevice();
497 m_phy2->SetChannel(channel);
503 m_phy1->SetDevice(device);
504 m_phy2->SetDevice(device);
524 m_phy1->NotifyIntChange();
525 m_phy2->NotifyIntChange();
531 m_phy1->SetTransducer(trans);
532 m_phy2->SetTransducer(trans);
538 NS_LOG_WARN(
"DualPhy Returning transducer of Phy1");
539 return m_phy1->GetTransducer();
553 return m_phy1->GetMode(n);
565 m_phy1->GetAttribute(
"SupportedModes", modeValue);
566 return modeValue.
Get();
573 m_phy2->GetAttribute(
"SupportedModes", modeValue);
574 return modeValue.
Get();
593 m_phy1->GetAttribute(
"PerModel", perValue);
601 m_phy2->GetAttribute(
"PerModel", perValue);
621 m_phy1->GetAttribute(
"SinrModel", sinrValue);
629 m_phy2->GetAttribute(
"SinrModel", sinrValue);
664 "GetPacketRx not valid for UanPhyDual. Must specify GetPhy1PacketRx or GetPhy2PacketRx");
This class can be used to hold variables of floating point type such as 'double' or 'float'.
virtual void DoDispose()
Destructor implementation.
AttributeValue implementation for Pointer.
Smart pointer class similar to boost::intrusive_ptr.
Hold variables of type string.
Simulation virtual time values and global simulation resolution.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Container for UanTxModes.
void SetChannel(Ptr< UanChannel > channel)
Attach a channel.
The power delay profile returned by propagation models.
Default SINR model for UanPhyDual.
UanPhyCalcSinrDual()
Constructor.
~UanPhyCalcSinrDual() override
Destructor.
static TypeId GetTypeId()
Register this type.
double CalcSinrDb(Ptr< Packet > pkt, Time arrTime, double rxPowerDb, double ambNoiseDb, UanTxMode mode, UanPdp pdp, const UanTransducer::ArrivalList &arrivalList) const override
Calculate the SINR value for a packet.
Class used for calculating SINR of packet in UanPhy.
double DbToKp(double db) const
Convert dB re 1 uPa to kilopascals.
double KpToDb(double kp) const
Convert kilopascals to dB re 1 uPa.
RxOkCallback m_recOkCb
Callback when packet received without errors.
Ptr< UanPhy > m_phy1
First Phy layer.
UanModesList GetModesPhy2() const
Get the list of available modes.
double GetCcaThresholdPhy1() const
Get the CCA threshold signal strength required to detect channel busy.
void RxOkFromSubPhy(Ptr< Packet > pkt, double sinr, UanTxMode mode)
Handle callback and logger for packets received without error.
bool IsStateRx() override
Ptr< UanChannel > GetChannel() const override
Get the attached channel.
~UanPhyDual() override
Dummy destructor.
void EnergyDepletionHandler() override
Handle the energy depletion event.
Ptr< Packet > GetPhy2PacketRx() const
Get the packet currently being received.
void NotifyIntChange() override
Called when there has been a change in the amount of interference this node is experiencing from othe...
Ptr< UanPhyCalcSinr > GetSinrModelPhy2() const
Get the SINR calculator.
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
void SetPerModelPhy1(Ptr< UanPhyPer > per)
Set the error probability model.
Ptr< UanPhy > m_phy2
Second Phy layer.
void SetTxPowerDbPhy1(double txpwr)
Set the transmit power.
void SetModesPhy2(UanModesList modes)
Set the available modes.
bool IsStateCcaBusy() override
UanModesList GetModesPhy1() const
Get the list of available modes.
bool IsStateBusy() override
Ptr< Packet > GetPacketRx() const override
Get the packet currently being received.
void Clear() override
Clear all pointer references.
void SetCcaThresholdDb(double thresh) override
Set the threshold for detecting channel busy.
bool IsStateIdle() override
uint32_t GetNModes() override
Get the number of transmission modes supported by this Phy.
UanTxMode GetMode(uint32_t n) override
Get a specific transmission mode.
double GetCcaThresholdDb() override
Get the CCA threshold signal strength required to detect channel busy.
void SetTransducer(Ptr< UanTransducer > trans) override
Attach a transducer to this Phy.
bool IsStateTx() override
double GetCcaThresholdPhy2() const
Get the CCA threshold signal strength required to detect channel busy.
void SetRxThresholdDb(double thresh) override
Set the minimum SINR threshold to receive a packet without errors.
void SetPerModelPhy2(Ptr< UanPhyPer > per)
Set the error probability model.
void SetChannel(Ptr< UanChannel > channel) override
Attach to a channel.
static TypeId GetTypeId()
Register this type.
void RegisterListener(UanPhyListener *listener) override
Register a UanPhyListener to be notified of common UanPhy events.
double GetRxThresholdDb() override
Get the minimum received signal strength required to receive a packet without errors.
bool IsStateSleep() override
void SetSinrModelPhy2(Ptr< UanPhyCalcSinr > calcSinr)
Set the SINR calculator.
ns3::TracedCallback< Ptr< const Packet >, double, UanTxMode > m_rxErrLogger
A packet was received unsuccessfuly.
void SetModesPhy1(UanModesList modes)
Set the available modes.
Ptr< UanPhyPer > GetPerModelPhy2() const
Get the error probability model.
double GetTxPowerDb() override
Get the current transmit power, in dB.
ns3::TracedCallback< Ptr< const Packet >, double, UanTxMode > m_rxOkLogger
A packet was received successfully.
void NotifyTransStartTx(Ptr< Packet > packet, double txPowerDb, UanTxMode txMode) override
Called when a transmission is beginning on the attached transducer.
Ptr< UanPhyPer > GetPerModelPhy1() const
Get the error probability model.
void SendPacket(Ptr< Packet > pkt, uint32_t modeNum) override
Send a packet using a specific transmission mode.
void SetMac(Ptr< UanMac > mac) override
Set the MAC forwarding messages to this Phy.
void SetDevice(Ptr< UanNetDevice > device) override
Set the device hosting this Phy.
double GetTxPowerDbPhy2() const
Get the current transmit power, in dB.
void DoDispose() override
Destructor implementation.
void RxErrFromSubPhy(Ptr< Packet > pkt, double sinr)
Handle callback and logger for packets received with error.
void SetTxPowerDb(double txpwr) override
Set the transmit power.
void EnergyRechargeHandler() override
Handle the energy recharge event.
RxErrCallback m_recErrCb
Callback when packet received with errors.
double GetTxPowerDbPhy1() const
Get the current transmit power, in dB.
void SetCcaThresholdPhy1(double thresh)
Set the threshold for detecting channel busy.
Ptr< UanTransducer > GetTransducer() override
Get the attached transducer.
void SetReceiveErrorCallback(RxErrCallback cb) override
Set the callback to be used when a packet is received with errors.
ns3::TracedCallback< Ptr< const Packet >, double, UanTxMode > m_txLogger
A packet was sent from this Phy.
void SetSinrModelPhy1(Ptr< UanPhyCalcSinr > calcSinr)
Set the SINR calculator.
void SetTxPowerDbPhy2(double txpwr)
Set the transmit power.
Ptr< Packet > GetPhy1PacketRx() const
Get the packet currently being received.
Ptr< UanNetDevice > GetDevice() const override
Get the device hosting this Phy.
void SetEnergyModelCallback(energy::DeviceEnergyModel::ChangeStateCallback callback) override
Set the DeviceEnergyModel callback for UanPhy device.
void SetCcaThresholdPhy2(double thresh)
Set the threshold for detecting channel busy.
void SetReceiveOkCallback(RxOkCallback cb) override
Set the callback to be used when a packet is received without error.
void StartRxPacket(Ptr< Packet > pkt, double rxPowerDb, UanTxMode txMode, UanPdp pdp) override
Packet arriving from channel: i.e.
Ptr< UanPhyCalcSinr > GetSinrModelPhy1() const
Get the SINR calculator.
static UanModesList GetDefaultModes()
Get the default transmission modes.
Base class for UAN Phy models.
Interface for PHY event listener.
std::list< UanPacketArrival > ArrivalList
List of arriving packets overlapping in time.
Abstraction of packet modulation information.
@ OTHER
Unspecified/undefined.
uint32_t GetBandwidthHz() const
Get the transmission signal bandwidth.
std::string GetName() const
Get the mode name.
ModulationType GetModType() const
Get the modulation type of the mode.
uint32_t GetCenterFreqHz() const
Get the transmission center frequency.
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< AttributeChecker > MakePointerChecker()
Create a PointerChecker for a type.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Time Now()
create an ns3::Time instance which contains the current simulation time.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeUanModesListChecker()
Ptr< const AttributeChecker > MakeDoubleChecker()
Ptr< const AttributeAccessor > MakeUanModesListAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)