|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
29 #include <ns3/abort.h>
30 #include <ns3/simulator.h>
31 #include <ns3/spectrum-value.h>
32 #include <ns3/antenna-model.h>
33 #include <ns3/mobility-model.h>
34 #include <ns3/spectrum-channel.h>
35 #include <ns3/packet.h>
36 #include <ns3/packet-burst.h>
37 #include <ns3/net-device.h>
38 #include <ns3/random-variable-stream.h>
39 #include <ns3/double.h>
53 const LrWpanPhyDataAndSymbolRates
64 const LrWpanPhyPpduHeaderSymbolNumber
78 .SetGroupName (
"LrWpan")
80 .AddTraceSource (
"TrxStateValue",
81 "The state of the transceiver",
83 "ns3::TracedValueCallback::LrWpanPhyEnumeration")
84 .AddTraceSource (
"TrxState",
85 "The state of the transceiver",
87 "ns3::LrWpanPhy::StateTracedCallback")
88 .AddTraceSource (
"PhyTxBegin",
89 "Trace source indicating a packet has "
90 "begun transmitting over the channel medium",
92 "ns3::Packet::TracedCallback")
93 .AddTraceSource (
"PhyTxEnd",
94 "Trace source indicating a packet has been "
95 "completely transmitted over the channel.",
97 "ns3::Packet::TracedCallback")
98 .AddTraceSource (
"PhyTxDrop",
99 "Trace source indicating a packet has been "
100 "dropped by the device during transmission",
102 "ns3::Packet::TracedCallback")
103 .AddTraceSource (
"PhyRxBegin",
104 "Trace source indicating a packet has begun "
105 "being received from the channel medium by the device",
107 "ns3::Packet::TracedCallback")
108 .AddTraceSource (
"PhyRxEnd",
109 "Trace source indicating a packet has been "
110 "completely received from the channel medium "
113 "ns3::Packet::SinrTracedCallback")
114 .AddTraceSource (
"PhyRxDrop",
115 "Trace source indicating a packet has been "
116 "dropped by the device during reception",
118 "ns3::Packet::TracedCallback")
134 for (uint32_t i = 0; i < 32; i++)
152 m_signal = Create<LrWpanInterferenceHelper> (
m_noise->GetSpectrumModel ());
160 m_random = CreateObject<UniformRandomVariable> ();
292 if (lrWpanRxParams == 0)
295 m_signal->AddSignal (spectrumRxParams->psd);
311 Ptr<Packet> p = (lrWpanRxParams->packetBurst->GetPackets ()).front ();
334 m_signal->AddSignal (lrWpanRxParams->psd);
336 *interferenceAndNoise -= *lrWpanRxParams->psd;
337 *interferenceAndNoise += *
m_noise;
343 if (10 * log10 (sinr) > -5)
368 m_signal->AddSignal (lrWpanRxParams->psd);
377 m_signal->AddSignal (lrWpanRxParams->psd);
408 Ptr<Packet> currentPacket = currentRxParams->packetBurst->GetPackets ().front ();
415 *interferenceAndNoise -= *currentRxParams->psd;
416 *interferenceAndNoise += *
m_noise;
418 double per = 1.0 -
m_errorModel->GetChunkSuccessRate (sinr, chunkSize);
424 uint8_t lqi = tag.
Get ();
425 tag.
Set (lqi - (per * lqi));
458 if (currentRxParams == params)
473 if (currentRxParams == params)
475 Ptr<Packet> currentPacket = currentRxParams->packetBurst->GetPackets ().front ();
533 NS_LOG_DEBUG (
"Drop packet because psduLength too long: " << psduLength);
555 txParams->txPhy = GetObject<SpectrumPhy> ();
560 txParams->packetBurst = pb;
731 NS_LOG_DEBUG (
"Phy is busy; setting state pending to " << state);
747 NS_LOG_DEBUG (
"Receiver has valid SFD; defer state change");
878 bool retValue =
false;
880 for (uint32_t i = 0; i < 32; i++)
962 NS_LOG_LOGIC (
"LrWpanPhy::PlmeSetAttributeRequest error - can not change read-only attribute bits.");
1088 uint8_t energyLevel;
1092 ratio = 10.0 * log10 (ratio);
1097 else if (ratio >= 40.0)
1104 energyLevel =
static_cast<uint8_t
> (((ratio - 10.0) / 30.0) * 255.0);
1179 NS_LOG_LOGIC (
this <<
"channel sensed state: " << sensedChannelState);
1289 return (rate * 1000.0);
1297 bool isData =
false;
1298 double totalPpduHdrSymbols;
1376 NS_LOG_INFO (
"\t computed noise_psd: " << *noisePsd );
1439 nominalTxPower -= 32;
1441 return nominalTxPower;
TracedValue< LrWpanPhyEnumeration > m_trxState
The current transceiver state.
a unique identifier for an interface.
static TypeId GetTypeId(void)
Get the type ID.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
bool ReplacePacketTag(Tag &tag)
Replace the value of a packet tag.
@ IEEE_802_15_4_2_4GHZ_OQPSK
Ptr< SpectrumValue > CreateTxPowerSpectralDensity(double txPower, uint32_t channel)
create spectrum value
uint8_t Get(void) const
Get the LQI value.
void EndCca(void)
Called at the end of the CCA.
IEEE802.15.4-2006 PHY PIB Attributes Table 23 in section 6.4.2.
@ IEEE_802_15_4_PHY_INVALID_PARAMETER
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
bool ChannelSupported(uint8_t channel)
Check if the given channel is supported by the PHY.
Ptr< MobilityModel > GetMobility(void) const
Get the associated MobilityModel instance.
void EndSetTRXState(void)
Called after applying a deferred transceiver state switch.
LrWpanEdPower m_edPower
Helper value for tracking the average power during ED.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
void SetDevice(Ptr< NetDevice > d)
Set the associated NetDevice instance.
virtual Address GetAddress(void) const =0
@ IEEE_802_15_4_915MHZ_BPSK
Time lastUpdate
Last update time.
static Time Now(void)
Return the current simulation virtual time.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< SpectrumValue > m_txPsd
The transmit power spectral density.
TracedCallback< Ptr< const Packet > > m_phyRxDropTrace
The trace source fired when the phy layer drops a packet it has received.
bool IsNull(void) const
Check for null implementation.
void PlmeSetAttributeRequest(LrWpanPibAttributeIdentifier id, LrWpanPhyPibAttributes *attribute)
IEEE 802.15.4-2006 section 6.2.2.9 PLME-SET.request Set attributes per definition from Table 23 in se...
void PlmeGetAttributeRequest(LrWpanPibAttributeIdentifier id)
IEEE 802.15.4-2006 section 6.2.2.5 PLME-GET.request Get attributes per definition from Table 23 in se...
This class defines all functions to create spectrum model for LrWpan.
uint32_t phyCurrentPage
Current channel page.
uint64_t GetPhySHRDuration(void) const
Get the duration of the SHR (preamble and SFD) in symbols, depending on the currently selected channe...
static double TotalAvgPower(Ptr< const SpectrumValue > psd, uint32_t channel)
total average power of the signal is the integral of the PSD using the limits of the given channel
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
PlmeCcaConfirmCallback m_plmeCcaConfirmCallback
This callback is used to report CCA status to the MAC or CSMA/CA.
void PlmeSetTRXStateRequest(LrWpanPhyEnumeration state)
IEEE 802.15.4-2006 section 6.2.2.7 PLME-SET-TRX-STATE.request Set PHY state.
virtual Ptr< const SpectrumModel > GetRxSpectrumModel(void) const
int8_t GetNominalTxPowerFromPib(uint8_t phyTransmitPower)
Calculates the nominal transmit power of the device in decibels relative to 1 mW according to the rep...
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Ptr< LrWpanErrorModel > m_errorModel
The error model describing the bit and packet error rates.
void SetChannel(Ptr< SpectrumChannel > c)
Set the channel attached to this device.
Ptr< const SpectrumModel > GetSpectrumModel() const
LrWpanPhyPibAttributes m_phyPIBAttributes
The current PHY PIB attributes.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
double m_ccaPeakPower
Helper value for the peak power value during CCA.
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
double symbolRate
symbol rate
double GetPhySymbolsPerOctet(void) const
Get the number of symbols per octet, depending on the currently selected channel.
Ptr< AntennaModel > m_antenna
The antenna used by the transceiver.
void SetTxPowerSpectralDensity(Ptr< SpectrumValue > txPsd)
Set the Power Spectral Density of outgoing signals in W/Hz.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
TracedCallback< Ptr< const Packet > > m_phyTxEndTrace
The trace source fired when a packet ends the transmission process on the medium.
void EndEd(void)
Called at the end of the ED procedure.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
@ IEEE_802_15_4_PHY_SUCCESS
void ChangeTrxState(LrWpanPhyEnumeration newState)
Change the PHY state to the given new state, firing the state change trace.
double GetDataOrSymbolRate(bool isData)
implement PLME SetAttribute confirm SAP bit rate is in kbit/s.
PlmeGetAttributeConfirmCallback m_plmeGetAttributeConfirmCallback
This callback is used to report requested attribute values back to the MAC.
@ IEEE_802_15_4_PHY_UNSUPPORTED_ATTRIBUTE
LrWpanPhy(void)
Default constructor.
uint8_t phyCCAMode
CCA mode.
double m_rxSensitivity
The receiver sensitivity.
int64_t GetTimeStep(void) const
Get the raw time value, in the current resolution unit.
LrWpanPibAttributeIdentifier
IEEE802.15.4-2006 PHY PIB Attribute Identifiers Table 23 in section 6.4.2.
PlmeSetTRXStateConfirmCallback m_plmeSetTRXStateConfirmCallback
This callback is used to report transceiver state change status to the MAC.
uint8_t phyTransmitPower
2 MSB: tolerance on the transmit power, 6 LSB: Tx power in dBm relative to 1mW (signed int in 2-compl...
static const uint32_t aTurnaroundTime
The turnaround time for switching the transceiver from RX to TX or vice versa.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
EventId m_ccaRequest
Scheduler event of a currently running CCA request.
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
static const LrWpanPhyDataAndSymbolRates dataSymbolRates[7]
The data and symbol rates for the different PHY options.
Ptr< SpectrumChannel > m_channel
The channel attached to this transceiver.
void SetPlmeGetAttributeConfirmCallback(PlmeGetAttributeConfirmCallback c)
set the callback for the end of an GetAttribute, as part of the interconnections betweenthe PHY and t...
@ IEEE_802_15_4_PHY_TRX_OFF
void SetPlmeSetAttributeConfirmCallback(PlmeSetAttributeConfirmCallback c)
set the callback for the end of an SetAttribute, as part of the interconnections betweenthe PHY and t...
void SetPlmeCcaConfirmCallback(PlmeCcaConfirmCallback c)
set the callback for the end of a CCA, as part of the interconnections betweenthe PHY and the MAC.
@ IEEE_802_15_4_868MHZ_ASK
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Introspection did not find any typical Config paths.
uint32_t phyChannelsSupported[32]
BitField representing the available channels supported by a channel page.
TracedCallback< Ptr< const Packet >, double > m_phyRxEndTrace
The trace source fired when a packet ends the reception process from the medium.
Abstract base class for Spectrum-aware PHY layers.
Ptr< AntennaModel > GetRxAntenna(void) const
Get the AntennaModel used by the NetDevice for reception.
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
PlmeSetAttributeConfirmCallback m_plmeSetAttributeConfirmCallback
This callback is used to report attribute set results back to the MAC.
LrWpanPhyEnumeration
IEEE802.15.4-2006 PHY Emumerations Table 18 in section 6.2.3.
@ IEEE_802_15_4_PHY_TX_ON
Time m_rxLastUpdate
Timestamp of the last calculation of the PER of a packet currently received.
Ptr< const SpectrumValue > GetNoisePowerSpectralDensity(void)
Get the noise power spectral density.
@ IEEE_802_15_4_PHY_RX_ON
Ptr< NetDevice > GetDevice(void) const
Get the associated NetDevice instance.
void SetPlmeSetTRXStateConfirmCallback(PlmeSetTRXStateConfirmCallback c)
set the callback for the end of an SetTRXState, as part of the interconnections betweenthe PHY and th...
Simulation virtual time values and global simulation resolution.
void EndTx(void)
Finish the transmission of a frame.
Time CalculateTxTime(Ptr< const Packet > packet)
Calculate the time required for sending the given packet, including preamble, SFD and PHR.
TracedCallback< Ptr< const Packet > > m_phyTxDropTrace
The trace source fired when the phy layer drops a packet as it tries to transmit it.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
TracedCallback< Time, LrWpanPhyEnumeration, LrWpanPhyEnumeration > m_trxStateLogger
The trace source fired when the phy layer changes the transceiver state.
@ IEEE_802_15_4_PHY_BUSY_TX
void PlmeCcaRequest(void)
IEEE 802.15.4-2006 section 6.2.2.1 PLME-CCA.request Perform a CCA per section 6.9....
void CancelEd(LrWpanPhyEnumeration state)
Cancel an ongoing ED procedure.
std::pair< Ptr< LrWpanSpectrumSignalParameters >, bool > m_currentRxPacket
Statusinformation of the currently received packet.
Ptr< LrWpanErrorModel > GetErrorModel(void) const
get the error model in use
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
LrWpanPhyOption
This Phy option will be used to index various Tables in IEEE802.15.4-2006.
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
void SetPlmeEdConfirmCallback(PlmeEdConfirmCallback c)
set the callback for the end of an ED, as part of the interconnections betweenthe PHY and the MAC.
LrWpanPhyEnumeration m_trxStatePending
The next pending state to applied after the current action of the PHY is completed.
virtual void StartRx(Ptr< SpectrumSignalParameters > params)
Notify the SpectrumPhy instance of an incoming waveform.
Ptr< SpectrumValue > CreateNoisePowerSpectralDensity(uint32_t channel)
create spectrum value for noise
PdDataIndicationCallback m_pdDataIndicationCallback
This callback is used to notify incoming packets to the MAC layer.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
TracedCallback< Ptr< const Packet > > m_phyRxBeginTrace
The trace source fired when a packet begins the reception process from the medium.
Time GetPpduHeaderTxTime(void)
Calculate the time required for sending the PPDU header, that is the preamble, SFD and PHR.
void SetMobility(Ptr< MobilityModel > m)
Set the mobility model associated with this device.
Ptr< LrWpanInterferenceHelper > m_signal
The accumulated signals currently received by the transceiver, including the signal of a possibly rec...
@ IEEE_802_15_4_915MHZ_ASK
Time Seconds(double value)
Construct a Time in the indicated unit.
TracedCallback< Ptr< const Packet > > m_phyTxBeginTrace
The trace source fired when a packet begins the transmission process on the medium.
void SetAntenna(Ptr< AntennaModel > a)
Set the attached antenna.
@ IEEE_802_15_4_868MHZ_OQPSK
Ptr< const SpectrumValue > m_noise
The spectral density for for the noise.
void SetPdDataConfirmCallback(PdDataConfirmCallback c)
set the callback for the end of a TX, as part of the interconnections betweenthe PHY and the MAC.
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
void PlmeEdRequest(void)
IEEE 802.15.4-2006 section 6.2.2.3 PLME-ED.request Perform an ED per section 6.9.7.
LrWpanPhyOption GetMyPhyOption(void)
Get the currently configured PHY option.
uint8_t phyCurrentChannel
The RF channel to use.
Time measurementLength
Total measurement period.
@ IEEE_802_15_4_INVALID_PHY_OPTION
Ptr< UniformRandomVariable > m_random
Uniform random variable stream.
static const uint32_t aMaxPhyPacketSize
The maximum packet size accepted by the PHY.
void SetPdDataIndicationCallback(PdDataIndicationCallback c)
set the callback for the end of a RX, as part of the interconnections betweenthe PHY and the MAC.
@ IEEE_802_15_4_PHY_FORCE_TRX_OFF
void CheckInterference(void)
Check if the interference destroys a frame currently received.
PdDataConfirmCallback m_pdDataConfirmCallback
This callback is used to report packet transmission status to the MAC layer.
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
EventId m_pdDataRequest
Scheduler event of a currently running data transmission request.
LrWpanPhyOption m_phyOption
The currently configured PHY type.
@ IEEE_802_15_4_PHY_BUSY_RX
PlmeEdConfirmCallback m_plmeEdConfirmCallback
This callback is used to report ED status to the MAC.
void SetNoisePowerSpectralDensity(Ptr< const SpectrumValue > noisePsd)
Set the noise power spectral density.
Ptr< MobilityModel > m_mobility
The mobility model used by the PHY.
bool PhyIsBusy(void) const
Check if the PHY is busy, which is the case if the PHY is currently sending or receiving a frame.
void SetErrorModel(Ptr< LrWpanErrorModel > e)
set the error model to use
void PdDataRequest(const uint32_t psduLength, Ptr< Packet > p)
IEEE 802.15.4-2006 section 6.2.1.1 PD-DATA.request Request to transfer MPDU from MAC (transmitting)
@ IEEE_802_15_4_PHY_UNSPECIFIED
@ IEEE_802_15_4_868MHZ_BPSK
void EndRx(Ptr< SpectrumSignalParameters > params)
Finish the reception of a frame.
void SetMyPhyOption(void)
Configure the PHY option according to the current channel and channel page.
EventId m_setTRXState
Scheduler event of a currently running deferred transceiver state switch.
PacketAndStatus m_currentTxPacket
Statusinformation of the currently transmitted packet.
void Set(uint8_t lqi)
Set the LQI to the given value.
static const LrWpanPhyPpduHeaderSymbolNumber ppduHeaderSymbolNumbers[7]
The preamble, SFD, and PHR lengths in symbols for the different PHY options.
virtual void DoDispose(void)
Destructor implementation.
double averagePower
Average measured power.
Ptr< NetDevice > m_device
The configured net device.
bool IsExpired(void) const
This method is syntactic sugar for the ns3::Simulator::IsExpired method.
@ IEEE_802_15_4_915MHZ_OQPSK
Ptr< SpectrumChannel > GetChannel(void)
Get the currently attached channel.
virtual void DoDispose(void)
Destructor implementation.
Make LrWpanPhy a SpectrumPhy so we can enable the eventual modeling of device interference.
EventId m_edRequest
Scheduler event of a currently running ED request.