31 #include "ns3/double.h"
34 #include "ns3/simulator.h"
35 #include "ns3/string.h"
36 #include "ns3/trace-source-accessor.h"
37 #include "ns3/traced-callback.h"
78 NS_LOG_WARN(
"Calculating SINR for unsupported modulation type");
81 double intKp = -
DbToKp(rxPowerDb);
82 auto it = arrivalList.begin();
83 for (; it != arrivalList.end(); it++)
86 if (std::abs((
double)it->GetTxMode().GetCenterFreqHz() - (
double)mode.
GetCenterFreqHz()) <
87 (
double)(it->GetTxMode().GetBandwidthHz() / 2 + mode.
GetBandwidthHz() / 2) - 0.5)
95 it->GetPacket()->PeekHeader(ch2);
103 <<
": PktRxMode: " << mode.
GetName()
104 <<
" Int mode: " << it->GetTxMode().GetName() <<
" Separation: "
105 << std::abs((
double)it->GetTxMode().GetCenterFreqHz() -
107 <<
" Combined bandwidths: "
108 << (
double)(it->GetTxMode().GetBandwidthHz() / 2 +
113 intKp +=
DbToKp(it->GetRxPowerDb());
120 <<
" dB. Number of interferers = " << arrivalList.size()
121 <<
" Interference + noise power = " << totalIntDb
122 <<
" dB. SINR = " << rxPowerDb - totalIntDb <<
" dB.");
123 return rxPowerDb - totalIntDb;
129 m_phy1 = CreateObject<UanPhyGen>();
130 m_phy2 = CreateObject<UanPhyGen>();
175 "Aggregate energy of incoming signals to move to CCA Busy state dB of Phy1.",
179 MakeDoubleChecker<double>())
182 "Aggregate energy of incoming signals to move to CCA Busy state dB of Phy2.",
186 MakeDoubleChecker<double>())
189 "Transmission output power in dB of Phy1.",
192 MakeDoubleChecker<double>())
195 "Transmission output power in dB of Phy2.",
198 MakeDoubleChecker<double>())
200 "SupportedModesPhy1",
201 "List of modes supported by Phy1.",
204 MakeUanModesListChecker())
206 "SupportedModesPhy2",
207 "List of modes supported by Phy2.",
210 MakeUanModesListChecker())
213 "Functor to calculate PER based on SINR and TxMode for Phy1.",
216 MakePointerChecker<UanPhyPer>())
219 "Functor to calculate PER based on SINR and TxMode for Phy2.",
222 MakePointerChecker<UanPhyPer>())
225 "Functor to calculate SINR based on pkt arrivals and modes for Phy1.",
228 MakePointerChecker<UanPhyCalcSinr>())
231 "Functor to calculate SINR based on pkt arrivals and modes for Phy2.",
234 MakePointerChecker<UanPhyCalcSinr>())
235 .AddTraceSource(
"RxOk",
236 "A packet was received successfully.",
238 "ns3::UanPhy::TracedCallback")
239 .AddTraceSource(
"RxError",
240 "A packet was received unsuccessfuly.",
242 "ns3::UanPhy::TracedCallback")
243 .AddTraceSource(
"Tx",
244 "Packet transmission beginning.",
246 "ns3::UanPhy::TracedCallback")
278 m_phy1->SendPacket(pkt, modeNum);
283 << modeNum -
m_phy1->GetNModes());
292 m_phy1->RegisterListener(listener);
293 m_phy2->RegisterListener(listener);
308 m_phy1->SetReceiveOkCallback(cb);
309 m_phy2->SetReceiveOkCallback(cb);
315 m_phy1->SetReceiveErrorCallback(cb);
316 m_phy2->SetReceiveErrorCallback(cb);
322 m_phy1->SetTxPowerDb(txpwr);
323 m_phy2->SetTxPowerDb(txpwr);
329 m_phy1->SetTxPowerDb(txpwr);
335 m_phy2->SetTxPowerDb(txpwr);
341 m_phy1->SetRxThresholdDb(thresh);
342 m_phy2->SetRxThresholdDb(thresh);
348 m_phy1->SetCcaThresholdDb(thresh);
349 m_phy2->SetCcaThresholdDb(thresh);
355 m_phy1->SetCcaThresholdDb(thresh);
361 m_phy2->SetCcaThresholdDb(thresh);
367 NS_LOG_WARN(
"Warning: Dual Phy only returns TxPowerDb of Phy 1");
368 return m_phy1->GetTxPowerDb();
374 return m_phy1->GetTxPowerDb();
380 return m_phy2->GetTxPowerDb();
386 return m_phy1->GetRxThresholdDb();
392 NS_LOG_WARN(
"Dual Phy only returns CCAThreshold of Phy 1");
393 return m_phy1->GetCcaThresholdDb();
399 return m_phy1->GetCcaThresholdDb();
405 return m_phy2->GetCcaThresholdDb();
411 return m_phy1->IsStateIdle();
417 return m_phy2->IsStateIdle();
423 return m_phy1->IsStateRx();
429 return m_phy2->IsStateRx();
435 return m_phy1->IsStateTx();
441 return m_phy1->GetPacketRx();
447 return m_phy2->GetPacketRx();
453 return m_phy2->IsStateTx();
459 return m_phy1->IsStateSleep() &&
m_phy2->IsStateSleep();
489 return m_phy1->IsStateCcaBusy() ||
m_phy2->IsStateCcaBusy();
495 return m_phy1->GetChannel();
501 return m_phy1->GetDevice();
514 m_phy1->SetDevice(device);
515 m_phy2->SetDevice(device);
535 m_phy1->NotifyIntChange();
536 m_phy2->NotifyIntChange();
542 m_phy1->SetTransducer(trans);
543 m_phy2->SetTransducer(trans);
549 NS_LOG_WARN(
"DualPhy Returning transducer of Phy1");
550 return m_phy1->GetTransducer();
564 return m_phy1->GetMode(n);
575 UanModesListValue modeValue;
576 m_phy1->GetAttribute(
"SupportedModes", modeValue);
577 return modeValue.Get();
583 UanModesListValue modeValue;
584 m_phy2->GetAttribute(
"SupportedModes", modeValue);
585 return modeValue.Get();
591 m_phy1->SetAttribute(
"SupportedModes", UanModesListValue(modes));
597 m_phy2->SetAttribute(
"SupportedModes", UanModesListValue(modes));
604 m_phy1->GetAttribute(
"PerModel", perValue);
612 m_phy2->GetAttribute(
"PerModel", perValue);
632 m_phy1->GetAttribute(
"SinrModel", sinrValue);
640 m_phy2->GetAttribute(
"SinrModel", sinrValue);
675 "GetPacketRx not valid for UanPhyDual. Must specify GetPhy1PacketRx or GetPhy2PacketRx");
676 return Create<Packet>();
This class can be used to hold variables of floating point type such as 'double' or 'float'.
virtual void DoDispose()
Destructor implementation.
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Hold objects of type Ptr<T>.
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.
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 SetEnergyModelCallback(DeviceEnergyModel::ChangeStateCallback callback) override
Set the DeviceEnergyModel callback for UanPhy device.
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 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.
#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.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
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 AttributeAccessor > MakePointerAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)