28 #include "ns3/double.h"
29 #include "ns3/string.h"
32 #include "ns3/traced-callback.h"
33 #include "ns3/trace-source-accessor.h"
34 #include "ns3/simulator.h"
80 NS_LOG_WARN (
"Calculating SINR for unsupported modulation type");
83 double intKp = -
DbToKp (rxPowerDb);
84 UanTransducer::ArrivalList::const_iterator it = arrivalList.begin ();
85 for (; it != arrivalList.end (); it++)
88 if (std::abs ( (
double) it->GetTxMode ().GetCenterFreqHz () - (double) mode.
GetCenterFreqHz ())
89 < (
double)(it->GetTxMode ().GetBandwidthHz () / 2 + mode.
GetBandwidthHz () / 2) - 0.5)
96 it->GetPacket ()->PeekHeader (ch2);
103 << mode.
GetName () <<
" Int mode: " << it->GetTxMode ().GetName () <<
" Separation: "
104 << std::abs ( (
double) it->GetTxMode ().GetCenterFreqHz () - (double) mode.
GetCenterFreqHz ())
105 <<
" Combined bandwidths: " << (
double)(it->GetTxMode ().GetBandwidthHz () / 2 + mode.
GetBandwidthHz () / 2) - 0.5);
108 intKp +=
DbToKp (it->GetRxPowerDb ());
112 double totalIntDb =
KpToDb (intKp +
DbToKp (ambNoiseDb));
114 NS_LOG_DEBUG (
Simulator::Now ().GetSeconds () <<
" Calculating SINR: RxPower = " << rxPowerDb <<
" dB. Number of interferers = " << arrivalList.size () <<
" Interference + noise power = " << totalIntDb <<
" dB. SINR = " << rxPowerDb - totalIntDb <<
" dB.");
115 return rxPowerDb - totalIntDb;
122 m_phy1 = CreateObject<UanPhyGen> ();
123 m_phy2 = CreateObject<UanPhyGen> ();
126 m_phy2->SetReceiveOkCallback (
m_recOkCb);
163 .SetGroupName (
"Uan")
165 .AddAttribute (
"CcaThresholdPhy1",
166 "Aggregate energy of incoming signals to move to CCA Busy state dB of Phy1.",
169 MakeDoubleChecker<double> ())
170 .AddAttribute (
"CcaThresholdPhy2",
171 "Aggregate energy of incoming signals to move to CCA Busy state dB of Phy2.",
174 MakeDoubleChecker<double> ())
175 .AddAttribute (
"TxPowerPhy1",
176 "Transmission output power in dB of Phy1.",
179 MakeDoubleChecker<double> ())
180 .AddAttribute (
"TxPowerPhy2",
181 "Transmission output power in dB of Phy2.",
184 MakeDoubleChecker<double> ())
185 .AddAttribute (
"RxGainPhy1",
186 "Gain added to incoming signal at receiver of Phy1.",
189 MakeDoubleChecker<double> ())
190 .AddAttribute (
"RxGainPhy2",
191 "Gain added to incoming signal at receiver of Phy2.",
194 MakeDoubleChecker<double> ())
195 .AddAttribute (
"SupportedModesPhy1",
196 "List of modes supported by Phy1.",
200 .AddAttribute (
"SupportedModesPhy2",
201 "List of modes supported by Phy2.",
205 .AddAttribute (
"PerModelPhy1",
206 "Functor to calculate PER based on SINR and TxMode for Phy1.",
209 MakePointerChecker<UanPhyPer> ())
210 .AddAttribute (
"PerModelPhy2",
211 "Functor to calculate PER based on SINR and TxMode for Phy2.",
214 MakePointerChecker<UanPhyPer> ())
215 .AddAttribute (
"SinrModelPhy1",
216 "Functor to calculate SINR based on pkt arrivals and modes for Phy1.",
219 MakePointerChecker<UanPhyCalcSinr> ())
220 .AddAttribute (
"SinrModelPhy2",
221 "Functor to calculate SINR based on pkt arrivals and modes for Phy2.",
224 MakePointerChecker<UanPhyCalcSinr> ())
225 .AddTraceSource (
"RxOk",
226 "A packet was received successfully.",
228 "ns3::UanPhy::TracedCallback")
229 .AddTraceSource (
"RxError",
230 "A packet was received unsuccessfully.",
232 "ns3::UanPhy::TracedCallback")
233 .AddTraceSource (
"Tx",
234 "Packet transmission beginning.",
236 "ns3::UanPhy::TracedCallback")
268 m_phy1->SendPacket (pkt, modeNum);
275 m_phy2->SendPacket (pkt, modeNum -
m_phy1->GetNModes ());
281 m_phy1->RegisterListener (listener);
282 m_phy2->RegisterListener (listener);
294 m_phy1->SetReceiveOkCallback (cb);
295 m_phy2->SetReceiveOkCallback (cb);
301 m_phy1->SetReceiveErrorCallback (cb);
302 m_phy2->SetReceiveErrorCallback (cb);
308 m_phy1->SetRxGainDb (gain);
309 m_phy2->SetRxGainDb (gain);
314 m_phy1->SetRxGainDb (gain);
320 m_phy2->SetRxGainDb (gain);
326 m_phy1->SetTxPowerDb (txpwr);
327 m_phy2->SetTxPowerDb (txpwr);
333 m_phy1->SetTxPowerDb (txpwr);
338 m_phy2->SetTxPowerDb (txpwr);
344 NS_LOG_WARN (
"SetRxThresholdDb is deprecated and has no effect. Look at PER Functor attribute");
345 m_phy1->SetRxThresholdDb (thresh);
346 m_phy2->SetRxThresholdDb (thresh);
351 m_phy1->SetCcaThresholdDb (thresh);
352 m_phy2->SetCcaThresholdDb (thresh);
358 m_phy1->SetCcaThresholdDb (thresh);
363 m_phy2->SetCcaThresholdDb (thresh);
369 NS_LOG_WARN (
"Warning: UanPhyDual::GetRxGainDb returns RxGain of Phy 1");
370 return m_phy1->GetRxGainDb ();
375 return m_phy1->GetRxGainDb ();
380 return m_phy2->GetRxGainDb ();
386 NS_LOG_WARN (
"Warning: Dual Phy only returns TxPowerDb of Phy 1");
387 return m_phy1->GetTxPowerDb ();
393 return m_phy1->GetTxPowerDb ();
399 return m_phy2->GetTxPowerDb ();
405 return m_phy1->GetRxThresholdDb ();
411 NS_LOG_WARN (
"Dual Phy only returns CCAThreshold of Phy 1");
412 return m_phy1->GetCcaThresholdDb ();
417 return m_phy1->GetCcaThresholdDb ();
422 return m_phy2->GetCcaThresholdDb ();
428 return m_phy1->IsStateIdle ();
433 return m_phy2->IsStateIdle ();
439 return m_phy1->IsStateRx ();
445 return m_phy2->IsStateRx ();
451 return m_phy1->IsStateTx ();
457 return m_phy1->GetPacketRx ();
463 return m_phy2->GetPacketRx ();
469 return m_phy2->IsStateTx ();
474 return m_phy1->IsStateSleep () &&
m_phy2->IsStateSleep ();
479 return m_phy1->IsStateIdle () &&
m_phy2->IsStateIdle ();
499 return m_phy1->IsStateCcaBusy () ||
m_phy2->IsStateCcaBusy ();
504 return m_phy1->GetChannel ();
509 return m_phy1->GetDevice ();
514 m_phy1->SetChannel (channel);
515 m_phy2->SetChannel (channel);
520 m_phy1->SetDevice (device);
521 m_phy2->SetDevice (device);
537 m_phy1->NotifyIntChange ();
538 m_phy2->NotifyIntChange ();
544 m_phy1->SetTransducer (trans);
545 m_phy2->SetTransducer (trans);
550 NS_LOG_WARN (
"DualPhy Returning transducer of Phy1");
551 return m_phy1->GetTransducer ();
563 return m_phy1->GetMode (n);
576 m_phy1->GetAttribute (
"SupportedModes", modeValue);
577 return modeValue.
Get ();
584 m_phy2->GetAttribute (
"SupportedModes", modeValue);
585 return modeValue.
Get ();
604 m_phy1->GetAttribute (
"PerModel", perValue);
612 m_phy2->GetAttribute (
"PerModel", perValue);
632 m_phy1->GetAttribute (
"SinrModel", sinrValue);
640 m_phy2->GetAttribute (
"SinrModel", sinrValue);
674 NS_FATAL_ERROR (
"GetPacketRx not valid for UanPhyDual. Must specify GetPhy1PacketRx or GetPhy2PacketRx");
675 return Create<Packet> ();
Simulation virtual time values and global simulation resolution.
Ptr< const AttributeChecker > MakeUanModesListChecker(void)
UanModesList Get(void) const
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
virtual void DoDispose()
Destructor implementation.
std::string GetName(void) const
Get the mode name.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
virtual uint32_t GetNModes(void)
Get the number of transmission modes supported by this Phy.
RxOkCallback m_recOkCb
Callback when packet received without errors.
Hold variables of type string.
static TypeId GetTypeId(void)
Register this type.
virtual Ptr< UanTransducer > GetTransducer(void)
Get the attached transducer.
virtual void SetEnergyModelCallback(DeviceEnergyModel::ChangeStateCallback callback)
Set the DeviceEnergyModel callback for UanPhy device.
virtual ~UanPhyCalcSinrDual()
Destructor.
Ptr< UanPhy > m_phy1
First Phy layer.
Ptr< UanPhy > m_phy2
Second Phy layer.
Ptr< Packet > GetPacketRx(void) const
Get the packet currently being received.
virtual void SetMac(Ptr< UanMac > mac)
Set the MAC forwarding messages to this Phy.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
virtual bool IsStateSleep(void)
double GetCcaThresholdPhy2(void) const
Get the CCA threshold signal strength required to detect channel busy.
Container for UanTxModes.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
virtual void DoDispose(void)
Destructor implementation.
ModulationType GetModType(void) const
Get the modulation type of the mode.
virtual bool IsStateTx(void)
virtual void SetCcaThresholdDb(double thresh)
Set the threshold for detecting channel busy.
virtual void SetDevice(Ptr< UanNetDevice > device)
Set the device hosting this Phy.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
virtual Ptr< UanChannel > GetChannel(void) const
Get the attached channel.
virtual ~UanPhyDual()
Dummy destructor.
virtual void SetTxPowerDb(double txpwr)
Set the transmit power.
virtual bool IsStateBusy(void)
virtual double GetRxThresholdDb(void)
Get the minimum received signal strength required to receive a packet without errors.
void SetCcaThresholdPhy1(double thresh)
Set the threshold for detecting channel busy.
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
virtual bool IsStateIdle(void)
virtual double CalcSinrDb(Ptr< Packet > pkt, Time arrTime, double rxPowerDb, double ambNoiseDb, UanTxMode mode, UanPdp pdp, const UanTransducer::ArrivalList &arrivalList) const
Calculate the SINR value for a packet.
double GetRxGainDbPhy1(void) const
Get the receiver gain added to signal at receiver in dB.
virtual void NotifyTransStartTx(Ptr< Packet > packet, double txPowerDb, UanTxMode txMode)
Called when a transmission is beginning on the attched transducer.
double KpToDb(double kp) const
Convert kilopascals to dB re 1 uPa.
virtual void SendPacket(Ptr< Packet > pkt, uint32_t modeNum)
Send a packet using a specific transmission mode.
Ptr< Packet > GetPhy1PacketRx(void) const
Get the packet currently being received.
The power delay profile returned by propagation models.
Abstraction of packet modulation information.
ns3::TracedCallback< Ptr< const Packet >, double, UanTxMode > m_txLogger
A packet was sent from this Phy.
virtual void Clear(void)
Clear all pointer references.
std::list< UanPacketArrival > ArrivalList
List of arriving packets overlapping in time.
virtual void NotifyIntChange(void)
Called when there has been a change in the ammount of interference this node is experiencing from oth...
virtual void SetChannel(Ptr< UanChannel > channel)
Attach to a channel.
Ptr< UanPhyPer > GetPerModelPhy2(void) const
Get the error probability model.
UanModesList GetModesPhy1(void) const
Get the list of available modes.
void SetModesPhy1(UanModesList modes)
Set the available modes.
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Ptr< UanPhyCalcSinr > GetSinrModelPhy2(void) const
Get the SINR calculator.
UanModesList GetModesPhy2(void) const
Get the list of available modes.
virtual void EnergyRechargeHandler(void)
Handle the energy recharge event.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Hold objects of type Ptr.
virtual void SetRxGainDb(double gain)
Set the receiver gain.
RxErrCallback m_recErrCb
Callback when packet received with errors.
void SetPerModelPhy1(Ptr< UanPhyPer > per)
Set the error probability model.
uint32_t GetCenterFreqHz(void) const
Get the transmission center frequency.
Interface for PHY event listener.
virtual void StartRxPacket(Ptr< Packet > pkt, double rxPowerDb, UanTxMode txMode, UanPdp pdp)
Packet arriving from channel: i.e.
void RxOkFromSubPhy(Ptr< Packet > pkt, double sinr, UanTxMode mode)
Handle callback and logger for packets received without error.
void SetTxPowerDbPhy1(double txpwr)
Set the transmit power.
virtual bool IsStateRx(void)
void SetTxPowerDbPhy2(double txpwr)
Set the transmit power.
double DbToKp(double db) const
Convert dB re 1 uPa to kilopascals.
double GetCcaThresholdPhy1(void) const
Get the CCA threshold signal strength required to detect channel busy.
ns3::TracedCallback< Ptr< const Packet >, double, UanTxMode > m_rxErrLogger
A packet was received unsuccessfully.
static Time Now(void)
Return the current simulation virtual time.
void RxErrFromSubPhy(Ptr< Packet > pkt, double sinr)
Handle callback and logger for packets received with error.
Class used for calculating SINR of packet in UanPhy.
ns3::TracedCallback< Ptr< const Packet >, double, UanTxMode > m_rxOkLogger
A packet was received successfully.
void SetModesPhy2(UanModesList modes)
Set the available modes.
Base class for UAN Phy models.
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
void SetSinrModelPhy2(Ptr< UanPhyCalcSinr > calcSinr)
Set the SINR calculator.
virtual NS_DEPRECATED void SetRxThresholdDb(double thresh)
Set the minimum SINR threshold to receive a packet without errors.
void SetSinrModelPhy1(Ptr< UanPhyCalcSinr > calcSinr)
Set the SINR calculator.
virtual void SetReceiveOkCallback(RxOkCallback cb)
Set the callback to be used when a packet is received without error.
virtual void SetTransducer(Ptr< UanTransducer > trans)
Attach a transducer to this Phy.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
double GetTxPowerDbPhy1(void) const
Get the current transmit power, in dB.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
virtual void RegisterListener(UanPhyListener *listener)
Register a UanPhyListener to be notified of common UanPhy events.
static TypeId GetTypeId()
Register this type.
Ptr< UanPhyCalcSinr > GetSinrModelPhy1(void) const
Get the SINR calculator.
virtual void SetReceiveErrorCallback(RxErrCallback cb)
Set the callback to be used when a packet is received with errors.
double GetTxPowerDbPhy2(void) const
Get the current transmit power, in dB.
Ptr< const AttributeAccessor > MakeUanModesListAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
virtual double GetRxGainDb(void)
Get the receiver gain added to signal at receiver in dB.
virtual Ptr< UanNetDevice > GetDevice(void) const
Get the device hosting this Phy.
virtual bool IsStateCcaBusy(void)
uint32_t GetBandwidthHz(void) const
Get the transmission signal bandwidth.
UanPhyCalcSinrDual()
Constructor.
This class can be used to hold variables of floating point type such as 'double' or 'float'...
static UanModesList GetDefaultModes(void)
Get the default transmission modes.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Ptr< Packet > GetPhy2PacketRx(void) const
Get the packet currently being received.
double GetRxGainDbPhy2(void) const
Get the receiver gain added to signal at receiver in dB.
void SetPerModelPhy2(Ptr< UanPhyPer > per)
Set the error probability model.
virtual double GetCcaThresholdDb(void)
Get the CCA threshold signal strength required to detect channel busy.
void SetRxGainDbPhy2(double gain)
Set the receiver gain.
Default SINR model for UanPhyDual.
void SetRxGainDbPhy1(double gain)
Set the receiver gain.
void SetCcaThresholdPhy2(double thresh)
Set the threshold for detecting channel busy.
AttributeValue implementation for UanModesList.
Ptr< UanPhyPer > GetPerModelPhy1(void) const
Get the error probability model.
virtual UanTxMode GetMode(uint32_t n)
Get a specific transmission mode.
virtual void EnergyDepletionHandler(void)
Handle the energy depletion event.
virtual double GetTxPowerDb(void)
Get the current transmit power, in dB.