A Discrete-Event Network Simulator
API
lr-wpan-phy.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 The Boeing Company
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author:
19  * Gary Pei <guangyu.pei@boeing.com>
20  * Sascha Alexander Jopen <jopen@cs.uni-bonn.de>
21  */
22 #include "lr-wpan-phy.h"
23 #include "lr-wpan-lqi-tag.h"
26 #include "lr-wpan-error-model.h"
27 #include "lr-wpan-net-device.h"
28 #include <ns3/log.h>
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>
40 
41 namespace ns3 {
42 
43 NS_LOG_COMPONENT_DEFINE ("LrWpanPhy");
44 
45 NS_OBJECT_ENSURE_REGISTERED (LrWpanPhy);
46 
47 // Table 22 in section 6.4.1 of ieee802.15.4
48 const uint32_t LrWpanPhy::aMaxPhyPacketSize = 127; // max PSDU in octets
49 const uint32_t LrWpanPhy::aTurnaroundTime = 12; // RX-to-TX or TX-to-RX in symbol periods
50 
51 // IEEE802.15.4-2006 Table 2 in section 6.1.2 (kb/s and ksymbol/s)
52 // The index follows LrWpanPhyOption
53 const LrWpanPhyDataAndSymbolRates
54 LrWpanPhy::dataSymbolRates[7] = { { 20.0, 20.0},
55  { 40.0, 40.0},
56  { 250.0, 12.5},
57  { 250.0, 50.0},
58  { 100.0, 25.0},
59  { 250.0, 62.5},
60  { 250.0, 62.5}};
61 // IEEE802.15.4-2006 Table 19 and Table 20 in section 6.3.
62 // The PHR is 1 octet and it follows phySymbolsPerOctet in Table 23
63 // The index follows LrWpanPhyOption
64 const LrWpanPhyPpduHeaderSymbolNumber
65 LrWpanPhy::ppduHeaderSymbolNumbers[7] = { { 32.0, 8.0, 8.0},
66  { 32.0, 8.0, 8.0},
67  { 2.0, 1.0, 0.4},
68  { 6.0, 1.0, 1.6},
69  { 8.0, 2.0, 2.0},
70  { 8.0, 2.0, 2.0},
71  { 8.0, 2.0, 2.0}};
72 
73 TypeId
75 {
76  static TypeId tid = TypeId ("ns3::LrWpanPhy")
78  .SetGroupName ("LrWpan")
79  .AddConstructor<LrWpanPhy> ()
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 "
111  "by the device",
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")
119  ;
120  return tid;
121 }
122 
124  : m_edRequest (),
125  m_setTRXState ()
126 {
129 
130  // default PHY PIB attributes
134  for (uint32_t i = 0; i < 32; i++)
135  {
137  }
139 
140  SetMyPhyOption ();
141 
142  m_edPower.averagePower = 0.0;
143  m_edPower.lastUpdate = Seconds (0.0);
145 
146  // default -110 dBm in W for 2.4 GHz
147  m_rxSensitivity = pow (10.0, -106.58 / 10.0) / 1000.0;
148  LrWpanSpectrumValueHelper psdHelper;
152  m_signal = Create<LrWpanInterferenceHelper> (m_noise->GetSpectrumModel ());
153  m_rxLastUpdate = Seconds (0);
154  Ptr<Packet> none_packet = 0;
155  Ptr<LrWpanSpectrumSignalParameters> none_params = 0;
156  m_currentRxPacket = std::make_pair (none_params, true);
157  m_currentTxPacket = std::make_pair (none_packet, true);
158  m_errorModel = 0;
159 
160  m_random = CreateObject<UniformRandomVariable> ();
161  m_random->SetAttribute ("Min", DoubleValue (0.0));
162  m_random->SetAttribute ("Max", DoubleValue (1.0));
163 
164 
166 }
167 
169 {
170 }
171 
172 void
174 {
175  NS_LOG_FUNCTION (this);
176 
177  // Cancel pending transceiver state change, if one is in progress.
181 
182  m_mobility = 0;
183  m_device = 0;
184  m_channel = 0;
185  m_txPsd = 0;
186  m_noise = 0;
187  m_signal = 0;
188  m_errorModel = 0;
189  m_pdDataIndicationCallback = MakeNullCallback< void, uint32_t, Ptr<Packet>, uint8_t > ();
190  m_pdDataConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration > ();
191  m_plmeCcaConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration > ();
192  m_plmeEdConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration,uint8_t > ();
193  m_plmeGetAttributeConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration, LrWpanPibAttributeIdentifier, LrWpanPhyPibAttributes* > ();
194  m_plmeSetTRXStateConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration > ();
195  m_plmeSetAttributeConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration, LrWpanPibAttributeIdentifier > ();
196 
198 }
199 
202 {
203  NS_LOG_FUNCTION (this);
204  return m_device;
205 }
206 
207 
210 {
211  NS_LOG_FUNCTION (this);
212  return m_mobility;
213 }
214 
215 
216 void
218 {
219  NS_LOG_FUNCTION (this << d);
220  m_device = d;
221 }
222 
223 
224 void
226 {
227  NS_LOG_FUNCTION (this << m);
228  m_mobility = m;
229 }
230 
231 
232 void
234 {
235  NS_LOG_FUNCTION (this << c);
236  m_channel = c;
237 }
238 
239 
242 {
243  NS_LOG_FUNCTION (this);
244  return m_channel;
245 }
246 
247 
250 {
251  NS_LOG_FUNCTION (this);
252  if (m_txPsd)
253  {
254  return m_txPsd->GetSpectrumModel ();
255  }
256  else
257  {
258  return 0;
259  }
260 }
261 
264 {
265  NS_LOG_FUNCTION (this);
266  return m_antenna;
267 }
268 
269 void
271 {
272  NS_LOG_FUNCTION (this << a);
273  m_antenna = a;
274 }
275 
276 void
278 {
279  NS_LOG_FUNCTION (this << spectrumRxParams);
280  LrWpanSpectrumValueHelper psdHelper;
281 
282  if (!m_edRequest.IsExpired ())
283  {
284  // Update the average receive power during ED.
285  Time now = Simulator::Now ();
287  m_edPower.lastUpdate = now;
288  }
289 
290  Ptr<LrWpanSpectrumSignalParameters> lrWpanRxParams = DynamicCast<LrWpanSpectrumSignalParameters> (spectrumRxParams);
291 
292  if (lrWpanRxParams == 0)
293  {
295  m_signal->AddSignal (spectrumRxParams->psd);
296 
297  // Update peak power if CCA is in progress.
298  if (!m_ccaRequest.IsExpired ())
299  {
301  if (m_ccaPeakPower < power)
302  {
303  m_ccaPeakPower = power;
304  }
305  }
306 
307  Simulator::Schedule (spectrumRxParams->duration, &LrWpanPhy::EndRx, this, spectrumRxParams);
308  return;
309  }
310 
311  Ptr<Packet> p = (lrWpanRxParams->packetBurst->GetPackets ()).front ();
312  NS_ASSERT (p != 0);
313 
314  // Prevent PHY from receiving another packet while switching the transceiver state.
316  {
317  // The specification doesn't seem to refer to BUSY_RX, but vendor
318  // data sheets suggest that this is a substate of the RX_ON state
319  // that is entered after preamble detection when the digital receiver
320  // is enabled. Here, for now, we use BUSY_RX to mark the period between
321  // StartRx() and EndRx() states.
322 
323  // We are going to BUSY_RX state when receiving the first bit of an SHR,
324  // as opposed to real receivers, which should go to this state only after
325  // successfully receiving the SHR.
326 
327  // If synchronizing to the packet is possible, change to BUSY_RX state,
328  // otherwise drop the packet and stay in RX state. The actual synchronization
329  // is not modeled.
330 
331  // Add any incoming packet to the current interference before checking the
332  // SINR.
333  NS_LOG_DEBUG (this << " receiving packet with power: " << 10 * log10(LrWpanSpectrumValueHelper::TotalAvgPower (lrWpanRxParams->psd, m_phyPIBAttributes.phyCurrentChannel)) + 30 << "dBm");
334  m_signal->AddSignal (lrWpanRxParams->psd);
335  Ptr<SpectrumValue> interferenceAndNoise = m_signal->GetSignalPsd ();
336  *interferenceAndNoise -= *lrWpanRxParams->psd;
337  *interferenceAndNoise += *m_noise;
339 
340  // Std. 802.15.4-2006, appendix E, Figure E.2
341  // At SNR < -5 the BER is less than 10e-1.
342  // It's useless to even *try* to decode the packet.
343  if (10 * log10 (sinr) > -5)
344  {
346  m_currentRxPacket = std::make_pair (lrWpanRxParams, false);
347  m_phyRxBeginTrace (p);
348 
350  }
351  else
352  {
353  m_phyRxDropTrace (p);
354  }
355  }
357  {
358  // Drop the new packet.
359  NS_LOG_DEBUG (this << " packet collision");
360  m_phyRxDropTrace (p);
361 
362  // Check if we correctly received the old packet up to now.
364 
365  // Add the incoming packet to the current interference after we have
366  // checked for successful reception of the current packet for the time
367  // before the additional interference.
368  m_signal->AddSignal (lrWpanRxParams->psd);
369  }
370  else
371  {
372  // Simply drop the packet.
373  NS_LOG_DEBUG (this << " transceiver not in RX state");
374  m_phyRxDropTrace (p);
375 
376  // Add the signal power to the interference, anyway.
377  m_signal->AddSignal (lrWpanRxParams->psd);
378  }
379 
380  // Update peak power if CCA is in progress.
381  if (!m_ccaRequest.IsExpired ())
382  {
384  if (m_ccaPeakPower < power)
385  {
386  m_ccaPeakPower = power;
387  }
388  }
389 
390  // Always call EndRx to update the interference.
391  // \todo: Do we need to keep track of these events to unschedule them when disposing off the PHY?
392 
393  Simulator::Schedule (spectrumRxParams->duration, &LrWpanPhy::EndRx, this, spectrumRxParams);
394 }
395 
396 void
398 {
399  // Calculate whether packet was lost.
400  LrWpanSpectrumValueHelper psdHelper;
402 
403  // We are currently receiving a packet.
405  {
406  // NS_ASSERT (currentRxParams && !m_currentRxPacket.second);
407 
408  Ptr<Packet> currentPacket = currentRxParams->packetBurst->GetPackets ().front ();
409  if (m_errorModel != 0)
410  {
411  // How many bits did we receive since the last calculation?
412  double t = (Simulator::Now () - m_rxLastUpdate).ToDouble (Time::MS);
413  uint32_t chunkSize = ceil (t * (GetDataOrSymbolRate (true) / 1000));
414  Ptr<SpectrumValue> interferenceAndNoise = m_signal->GetSignalPsd ();
415  *interferenceAndNoise -= *currentRxParams->psd;
416  *interferenceAndNoise += *m_noise;
418  double per = 1.0 - m_errorModel->GetChunkSuccessRate (sinr, chunkSize);
419 
420  // The LQI is the total packet success rate scaled to 0-255.
421  // If not already set, initialize to 255.
423  currentPacket->PeekPacketTag (tag);
424  uint8_t lqi = tag.Get ();
425  tag.Set (lqi - (per * lqi));
426  currentPacket->ReplacePacketTag (tag);
427 
428  if (m_random->GetValue () < per)
429  {
430  // The packet was destroyed, drop the packet after reception.
431  m_currentRxPacket.second = true;
432  }
433  }
434  else
435  {
436  NS_LOG_WARN ("Missing ErrorModel");
437  }
438  }
440 }
441 
442 void
444 {
445  NS_LOG_FUNCTION (this);
446 
447  Ptr<LrWpanSpectrumSignalParameters> params = DynamicCast<LrWpanSpectrumSignalParameters> (par);
448 
449  if (!m_edRequest.IsExpired ())
450  {
451  // Update the average receive power during ED.
452  Time now = Simulator::Now ();
454  m_edPower.lastUpdate = now;
455  }
456 
458  if (currentRxParams == params)
459  {
461  }
462 
463  // Update the interference.
464  m_signal->RemoveSignal (par->psd);
465 
466  if (params == 0)
467  {
468  NS_LOG_LOGIC ("Node: " << m_device->GetAddress() << " Removing interferent: " << *(par->psd));
469  return;
470  }
471 
472  // If this is the end of the currently received packet, check if reception was successful.
473  if (currentRxParams == params)
474  {
475  Ptr<Packet> currentPacket = currentRxParams->packetBurst->GetPackets ().front ();
476  NS_ASSERT (currentPacket != 0);
477 
478  // If there is no error model attached to the PHY, we always report the maximum LQI value.
480  currentPacket->PeekPacketTag (tag);
481  m_phyRxEndTrace (currentPacket, tag.Get ());
482 
483  if (!m_currentRxPacket.second)
484  {
485  // The packet was successfully received, push it up the stack.
487  {
488  m_pdDataIndicationCallback (currentPacket->GetSize (), currentPacket, tag.Get ());
489  }
490  }
491  else
492  {
493  // The packet was destroyed, drop it.
494  m_phyRxDropTrace (currentPacket);
495  }
497  m_currentRxPacket = std::make_pair (none, true);
498 
499  // We may be waiting to apply a pending state change.
501  {
502  // Only change the state immediately, if the transceiver is not already
503  // switching the state.
504  if (!m_setTRXState.IsRunning ())
505  {
506  NS_LOG_LOGIC ("Apply pending state change to " << m_trxStatePending);
510  {
512  }
513  }
514  }
515  else
516  {
518  }
519  }
520 }
521 
522 void
523 LrWpanPhy::PdDataRequest (const uint32_t psduLength, Ptr<Packet> p)
524 {
525  NS_LOG_FUNCTION (this << psduLength << p);
526 
527  if (psduLength > aMaxPhyPacketSize)
528  {
530  {
532  }
533  NS_LOG_DEBUG ("Drop packet because psduLength too long: " << psduLength);
534  return;
535  }
536 
537  // Prevent PHY from sending a packet while switching the transceiver state.
538  if (!m_setTRXState.IsRunning ())
539  {
541  {
542  //send down
544 
545  // Remove a possible LQI tag from a previous transmission of the packet.
546  LrWpanLqiTag lqiTag;
547  p->RemovePacketTag (lqiTag);
548 
549  m_phyTxBeginTrace (p);
550  m_currentTxPacket.first = p;
551  m_currentTxPacket.second = false;
552 
553  Ptr<LrWpanSpectrumSignalParameters> txParams = Create<LrWpanSpectrumSignalParameters> ();
554  txParams->duration = CalculateTxTime (p);
555  txParams->txPhy = GetObject<SpectrumPhy> ();
556  txParams->psd = m_txPsd;
557  txParams->txAntenna = m_antenna;
558  Ptr<PacketBurst> pb = CreateObject<PacketBurst> ();
559  pb->AddPacket (p);
560  txParams->packetBurst = pb;
561  m_channel->StartTx (txParams);
562  m_pdDataRequest = Simulator::Schedule (txParams->duration, &LrWpanPhy::EndTx, this);
564  return;
565  }
566  else if ((m_trxState == IEEE_802_15_4_PHY_RX_ON)
569  {
571  {
573  }
574  // Drop packet, hit PhyTxDrop trace
575  m_phyTxDropTrace (p);
576  return;
577  }
578  else
579  {
580  NS_FATAL_ERROR ("This should be unreachable, or else state " << m_trxState << " should be added as a case");
581  }
582  }
583  else
584  {
585  // TODO: This error code is not covered by the standard.
586  // What is the correct behavior in this case?
588  {
590  }
591  // Drop packet, hit PhyTxDrop trace
592  m_phyTxDropTrace (p);
593  return;
594  }
595 }
596 
597 void
599 {
600  NS_LOG_FUNCTION (this);
601 
603  {
604  m_ccaPeakPower = 0.0;
605  Time ccaTime = Seconds (8.0 / GetDataOrSymbolRate (false));
607  }
608  else
609  {
611  {
613  {
615  }
616  else
617  {
619  }
620  }
621  }
622 }
623 
624 void
626 {
627  NS_LOG_FUNCTION (this);
629  {
630  // Average over the powers of all signals received until EndEd()
635  }
636  else
637  {
640  {
641  result = IEEE_802_15_4_PHY_TX_ON;
642  }
643 
645  {
646  m_plmeEdConfirmCallback (result, 0);
647  }
648  }
649 }
650 
651 void
653 {
654  NS_LOG_FUNCTION (this << id);
655  LrWpanPhyEnumeration status;
656 
657  switch (id)
658  {
659  case phyCurrentChannel:
661  case phyTransmitPower:
662  case phyCCAMode:
663  case phyCurrentPage:
664  case phyMaxFrameDuration:
665  case phySHRDuration:
666  case phySymbolsPerOctet:
667  {
668  status = IEEE_802_15_4_PHY_SUCCESS;
669  break;
670  }
671  default:
672  {
674  break;
675  }
676  }
678  {
679  LrWpanPhyPibAttributes retValue;
680  memcpy (&retValue, &m_phyPIBAttributes, sizeof(LrWpanPhyPibAttributes));
681  m_plmeGetAttributeConfirmCallback (status,id,&retValue);
682  }
683 }
684 
685 // Section 6.2.2.7.3
686 void
688 {
689  NS_LOG_FUNCTION (this << state);
690 
691  // Check valid states (Table 14)
693  && (state != IEEE_802_15_4_PHY_TRX_OFF)
694  && (state != IEEE_802_15_4_PHY_FORCE_TRX_OFF)
695  && (state != IEEE_802_15_4_PHY_TX_ON) );
696 
697  NS_LOG_LOGIC ("Trying to set m_trxState from " << m_trxState << " to " << state);
698  // this method always overrides previous state setting attempts
699  if (!m_setTRXState.IsExpired ())
700  {
701  if (m_trxStatePending == state)
702  {
703  // Simply wait for the ongoing state switch.
704  return;
705  }
706  else
707  {
708  NS_LOG_DEBUG ("Cancel m_setTRXState");
709  // Keep the transceiver state as the old state before the switching attempt.
711  }
712  }
714  {
716  }
717 
718  if (state == m_trxState)
719  {
721  {
723  }
724  return;
725  }
726 
727  if ( ((state == IEEE_802_15_4_PHY_RX_ON)
728  || (state == IEEE_802_15_4_PHY_TRX_OFF))
730  {
731  NS_LOG_DEBUG ("Phy is busy; setting state pending to " << state);
732  m_trxStatePending = state;
733  return; // Send PlmeSetTRXStateConfirm later
734  }
735 
736  // specification talks about being in RX_ON and having received
737  // a valid SFD. Here, we are not modelling at that level of
738  // granularity, so we just test for BUSY_RX state (any part of
739  // a packet being actively received)
740  if (state == IEEE_802_15_4_PHY_TRX_OFF)
741  {
742  CancelEd (state);
743 
745  && (m_currentRxPacket.first) && (!m_currentRxPacket.second))
746  {
747  NS_LOG_DEBUG ("Receiver has valid SFD; defer state change");
748  m_trxStatePending = state;
749  return; // Send PlmeSetTRXStateConfirm later
750  }
752  {
755  {
757  }
758  return;
759  }
760  }
761 
762  if (state == IEEE_802_15_4_PHY_TX_ON)
763  {
764  CancelEd (state);
765 
766  NS_LOG_DEBUG ("turn on PHY_TX_ON");
768  {
769  if (m_currentRxPacket.first)
770  {
771  //terminate reception if needed
772  //incomplete reception -- force packet discard
773  NS_LOG_DEBUG ("force TX_ON, terminate reception");
774  m_currentRxPacket.second = true;
775  }
776 
777  // If CCA is in progress, cancel CCA and return BUSY.
778  if (!m_ccaRequest.IsExpired ())
779  {
780  m_ccaRequest.Cancel ();
782  {
784  }
785  }
786 
788 
789  // Delay for turnaround time
790  // TODO: Does it also take aTurnaroundTime to switch the transceiver state,
791  // even when the receiver is not busy? (6.9.2)
792  Time setTime = Seconds ( (double) aTurnaroundTime / GetDataOrSymbolRate (false));
794  return;
795  }
797  {
798  // We do NOT change the transceiver state here. We only report that
799  // the transceiver is already in TX_ON state.
801  {
803  }
804  return;
805  }
807  {
810  {
812  }
813  return;
814  }
815  }
816 
817  if (state == IEEE_802_15_4_PHY_FORCE_TRX_OFF)
818  {
820  {
821  NS_LOG_DEBUG ("force TRX_OFF, was already off");
822  }
823  else
824  {
825  NS_LOG_DEBUG ("force TRX_OFF, SUCCESS");
826  if (m_currentRxPacket.first)
827  { //terminate reception if needed
828  //incomplete reception -- force packet discard
829  NS_LOG_DEBUG ("force TRX_OFF, terminate reception");
830  m_currentRxPacket.second = true;
831  }
833  {
834  NS_LOG_DEBUG ("force TRX_OFF, terminate transmission");
835  m_currentTxPacket.second = true;
836  }
838  // Clear any other state
840  }
842  {
844  }
845  return;
846  }
847 
848  if (state == IEEE_802_15_4_PHY_RX_ON)
849  {
851  {
852  // Turnaround delay
853  // TODO: Does it really take aTurnaroundTime to switch the transceiver state,
854  // even when the transmitter is not busy? (6.9.1)
856 
857  Time setTime = Seconds ( (double) aTurnaroundTime / GetDataOrSymbolRate (false));
859  return;
860  }
862  {
864  {
866  }
867  return;
868  }
869  }
870 
871  NS_FATAL_ERROR ("Unexpected transition from state " << m_trxState << " to state " << state);
872 }
873 
874 bool
876 {
877  NS_LOG_FUNCTION (this << channel);
878  bool retValue = false;
879 
880  for (uint32_t i = 0; i < 32; i++)
881  {
882  if ((m_phyPIBAttributes.phyChannelsSupported[i] & (1 << channel)) != 0)
883  {
884  retValue = true;
885  break;
886  }
887  }
888 
889  return retValue;
890 }
891 
892 void
894  LrWpanPhyPibAttributes* attribute)
895 {
896  NS_LOG_FUNCTION (this << id << attribute);
897  NS_ASSERT (attribute);
899 
900  switch (id)
901  {
902  case phyCurrentChannel:
903  {
904  if (!ChannelSupported (attribute->phyCurrentChannel))
905  {
907  }
909  {
910  // Cancel a pending transceiver state change.
911  // Switch off the transceiver.
912  // TODO: Is switching off the transceiver the right choice?
915  {
919  {
921  }
922  }
923 
924  // Any packet in transmission or reception will be corrupted.
925  if (m_currentRxPacket.first)
926  {
927  m_currentRxPacket.second = true;
928  }
929  if (PhyIsBusy ())
930  {
931  m_currentTxPacket.second = true;
933  m_currentTxPacket.first = 0;
935  {
937  }
938  }
940  LrWpanSpectrumValueHelper psdHelper;
942  }
943  break;
944  }
946  { // only the first element is considered in the array
947  if ((attribute->phyChannelsSupported[0] & 0xf8000000) != 0)
948  { //5 MSBs reserved
950  }
951  else
952  {
954  }
955  break;
956  }
957  case phyTransmitPower:
958  {
959  if (attribute->phyTransmitPower > 0xbf)
960  {
962  }
963  else
964  {
966  LrWpanSpectrumValueHelper psdHelper;
968  }
969  break;
970  }
971  case phyCCAMode:
972  {
973  if ((attribute->phyCCAMode < 1) || (attribute->phyCCAMode > 3))
974  {
976  }
977  else
978  {
980  }
981  break;
982  }
983  default:
984  {
986  break;
987  }
988  }
989 
991  {
993  }
994 }
995 
996 void
998 {
999  NS_LOG_FUNCTION (this);
1001 }
1002 
1003 void
1005 {
1006  NS_LOG_FUNCTION (this);
1008 }
1009 
1010 void
1012 {
1013  NS_LOG_FUNCTION (this);
1015 }
1016 
1017 void
1019 {
1020  NS_LOG_FUNCTION (this);
1022 }
1023 
1024 void
1026 {
1027  NS_LOG_FUNCTION (this);
1029 }
1030 
1031 void
1033 {
1034  NS_LOG_FUNCTION (this);
1036 }
1037 
1038 void
1040 {
1041  NS_LOG_FUNCTION (this);
1043 }
1044 
1045 void
1047 {
1048  NS_LOG_LOGIC (this << " state: " << m_trxState << " -> " << newState);
1049  m_trxStateLogger (Simulator::Now (), m_trxState, newState);
1050  m_trxState = newState;
1051 }
1052 
1053 bool
1055 {
1056  NS_LOG_FUNCTION (this << m_trxState);
1060 }
1061 
1062 void
1064 {
1065  NS_LOG_FUNCTION (this);
1067 
1068  if (!m_edRequest.IsExpired ())
1069  {
1070  m_edRequest.Cancel ();
1072  {
1073  m_plmeEdConfirmCallback (state, 0);
1074  }
1075  }
1076 }
1077 
1078 void
1080 {
1081  NS_LOG_FUNCTION (this);
1082 
1084 
1085  uint8_t energyLevel;
1086 
1087  // Per IEEE802.15.4-2006 sec 6.9.7
1088  double ratio = m_edPower.averagePower / m_rxSensitivity;
1089  ratio = 10.0 * log10 (ratio);
1090  if (ratio <= 10.0)
1091  { // less than 10 dB
1092  energyLevel = 0;
1093  }
1094  else if (ratio >= 40.0)
1095  { // less than 40 dB
1096  energyLevel = 255;
1097  }
1098  else
1099  {
1100  // in-between with linear increase per sec 6.9.7
1101  energyLevel = static_cast<uint8_t> (((ratio - 10.0) / 30.0) * 255.0);
1102  }
1103 
1105  {
1107  }
1108 }
1109 
1110 void
1112 {
1113  NS_LOG_FUNCTION (this);
1115 
1116  // Update peak power.
1118  if (m_ccaPeakPower < power)
1119  {
1120  m_ccaPeakPower = power;
1121  }
1122 
1123  if (PhyIsBusy ())
1124  {
1125  sensedChannelState = IEEE_802_15_4_PHY_BUSY;
1126  }
1127  else if (m_phyPIBAttributes.phyCCAMode == 1)
1128  { //sec 6.9.9 ED detection
1129  // -- ED threshold at most 10 dB above receiver sensitivity.
1130  if (10 * log10 (m_ccaPeakPower / m_rxSensitivity) >= 10.0)
1131  {
1132  sensedChannelState = IEEE_802_15_4_PHY_BUSY;
1133  }
1134  else
1135  {
1136  sensedChannelState = IEEE_802_15_4_PHY_IDLE;
1137  }
1138  }
1139  else if (m_phyPIBAttributes.phyCCAMode == 2)
1140  {
1141  //sec 6.9.9 carrier sense only
1143  {
1144  // We currently do not model PPDU reception in detail. Instead we model
1145  // packet reception starting with the first bit of the preamble.
1146  // Therefore, this code will never be reached, as PhyIsBusy() would
1147  // already lead to a channel busy condition.
1148  // TODO: Change this, if we also model preamble and SFD detection.
1149  sensedChannelState = IEEE_802_15_4_PHY_BUSY;
1150  }
1151  else
1152  {
1153  sensedChannelState = IEEE_802_15_4_PHY_IDLE;
1154  }
1155  }
1156  else if (m_phyPIBAttributes.phyCCAMode == 3)
1157  { //sect 6.9.9 both
1158  if ((10 * log10 (m_ccaPeakPower / m_rxSensitivity) >= 10.0)
1160  {
1161  // Again, this code will never be reached, if we are already receiving
1162  // a packet, as PhyIsBusy() would already lead to a channel busy condition.
1163  // TODO: Change this, if we also model preamble and SFD detection.
1164  sensedChannelState = IEEE_802_15_4_PHY_BUSY;
1165  }
1166  else
1167  {
1168  sensedChannelState = IEEE_802_15_4_PHY_IDLE;
1169  }
1170  }
1171  else
1172  {
1173  NS_ASSERT_MSG (false, "Invalid CCA mode");
1174  }
1175 
1176  NS_LOG_LOGIC (this << "channel sensed state: " << sensedChannelState);
1177 
1179  {
1180  m_plmeCcaConfirmCallback (sensedChannelState);
1181  }
1182 }
1183 
1184 void
1186 {
1187  NS_LOG_FUNCTION (this);
1188 
1192 
1194  {
1196  }
1197 }
1198 
1199 void
1201 {
1202  NS_LOG_FUNCTION (this);
1203 
1205 
1206  if (m_currentTxPacket.second == false)
1207  {
1208  NS_LOG_DEBUG ("Packet successfully transmitted");
1211  {
1213  }
1214  }
1215  else
1216  {
1217  NS_LOG_DEBUG ("Packet transmission aborted");
1220  {
1221  // See if this is ever entered in another state
1224  }
1225  }
1226  m_currentTxPacket.first = 0;
1227  m_currentTxPacket.second = false;
1228 
1229 
1230  // We may be waiting to apply a pending state change.
1232  {
1233  // Only change the state immediately, if the transceiver is not already
1234  // switching the state.
1235  if (!m_setTRXState.IsRunning ())
1236  {
1237  NS_LOG_LOGIC ("Apply pending state change to " << m_trxStatePending);
1241  {
1243  }
1244  }
1245  }
1246  else
1247  {
1249  {
1251  }
1252  }
1253 }
1254 
1255 Time
1257 {
1258  NS_LOG_FUNCTION (this << packet);
1259 
1260  bool isData = true;
1261  Time txTime = GetPpduHeaderTxTime ();
1262 
1263  txTime += Seconds (packet->GetSize () * 8.0 / GetDataOrSymbolRate (isData));
1264 
1265  return txTime;
1266 }
1267 
1268 double
1270 {
1271  NS_LOG_FUNCTION (this << isData);
1272 
1273  double rate = 0.0;
1274 
1276 
1277  if (isData)
1278  {
1280  }
1281  else
1282  {
1284  }
1285 
1286  return (rate * 1000.0);
1287 }
1288 
1289 Time
1291 {
1292  NS_LOG_FUNCTION (this);
1293 
1294  bool isData = false;
1295  double totalPpduHdrSymbols;
1296 
1298 
1299  totalPpduHdrSymbols = ppduHeaderSymbolNumbers[m_phyOption].shrPreamble
1302 
1303  return Seconds (totalPpduHdrSymbols / GetDataOrSymbolRate (isData));
1304 }
1305 
1306 // IEEE802.15.4-2006 Table 2 in section 6.1.2
1307 void
1309 {
1310  NS_LOG_FUNCTION (this);
1311 
1313 
1315  {
1317  { // 868 MHz BPSK
1319  }
1320  else if (m_phyPIBAttributes.phyCurrentChannel <= 10)
1321  { // 915 MHz BPSK
1323  }
1324  else if (m_phyPIBAttributes.phyCurrentChannel <= 26)
1325  { // 2.4 GHz MHz O-QPSK
1327  }
1328  }
1329  else if (m_phyPIBAttributes.phyCurrentPage == 1)
1330  {
1332  { // 868 MHz ASK
1334  }
1335  else if (m_phyPIBAttributes.phyCurrentChannel <= 10)
1336  { // 915 MHz ASK
1338  }
1339  }
1340  else if (m_phyPIBAttributes.phyCurrentPage == 2)
1341  {
1343  { // 868 MHz O-QPSK
1345  }
1346  else if (m_phyPIBAttributes.phyCurrentChannel <= 10)
1347  { // 915 MHz O-QPSK
1349  }
1350  }
1351 }
1352 
1355 {
1356  NS_LOG_FUNCTION (this);
1357  return m_phyOption;
1358 }
1359 
1360 void
1362 {
1363  NS_LOG_FUNCTION (this << txPsd);
1364  NS_ASSERT (txPsd);
1365  m_txPsd = txPsd;
1366  NS_LOG_INFO ("\t computed tx_psd: " << *txPsd << "\t stored tx_psd: " << *m_txPsd);
1367 }
1368 
1369 void
1371 {
1372  NS_LOG_FUNCTION (this << noisePsd);
1373  NS_LOG_INFO ("\t computed noise_psd: " << *noisePsd );
1374  NS_ASSERT (noisePsd);
1375  m_noise = noisePsd;
1376 }
1377 
1380 {
1381  NS_LOG_FUNCTION (this);
1382  return m_noise;
1383 }
1384 
1385 void
1387 {
1388  NS_LOG_FUNCTION (this << e);
1389  NS_ASSERT (e);
1390  m_errorModel = e;
1391 }
1392 
1395 {
1396  NS_LOG_FUNCTION (this);
1397  return m_errorModel;
1398 }
1399 
1400 uint64_t
1402 {
1403  NS_LOG_FUNCTION (this);
1405 
1408 }
1409 
1410 double
1412 {
1413  NS_LOG_FUNCTION (this);
1415 
1417 }
1418 
1419 int64_t
1421 {
1422  NS_LOG_FUNCTION (this);
1423  m_random->SetStream (stream);
1424  return 1;
1425 }
1426 
1427 } // namespace ns3
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
void SetPlmeSetTRXStateConfirmCallback(PlmeSetTRXStateConfirmCallback c)
set the callback for the end of an SetTRXState, as part of the interconnections betweenthe PHY and th...
TracedCallback< Ptr< const Packet > > m_phyTxDropTrace
The trace source fired when the phy layer drops a packet as it tries to transmit it.
Definition: lr-wpan-phy.h:641
Abstract base class for Spectrum-aware PHY layers.
Definition: spectrum-phy.h:45
Make LrWpanPhy a SpectrumPhy so we can enable the eventual modeling of device interference.
Definition: lr-wpan-phy.h:247
static const uint32_t aTurnaroundTime
The turnaround time for switching the transceiver from RX to TX or vice versa.
Definition: lr-wpan-phy.h:269
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
void SetPdDataConfirmCallback(PdDataConfirmCallback c)
set the callback for the end of a TX, as part of the interconnections betweenthe PHY and the MAC...
LrWpanPhyOption GetMyPhyOption(void)
Get the currently configured PHY option.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:852
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
Ptr< UniformRandomVariable > m_random
Uniform random variable stream.
Definition: lr-wpan-phy.h:842
PdDataConfirmCallback m_pdDataConfirmCallback
This callback is used to report packet transmission status to the MAC layer.
Definition: lr-wpan-phy.h:739
LrWpanPibAttributeIdentifier
IEEE802.15.4-2006 PHY PIB Attribute Identifiers Table 23 in section 6.4.2.
Definition: lr-wpan-phy.h:140
TracedValue< LrWpanPhyEnumeration > m_trxState
The current transceiver state.
Definition: lr-wpan-phy.h:720
void SetPdDataIndicationCallback(PdDataIndicationCallback c)
set the callback for the end of a RX, as part of the interconnections betweenthe PHY and the MAC...
Definition: lr-wpan-phy.cc:997
uint32_t phyCurrentPage
Current channel page.
Definition: lr-wpan-phy.h:163
void SetPlmeCcaConfirmCallback(PlmeCcaConfirmCallback c)
set the callback for the end of a CCA, as part of the interconnections betweenthe PHY and the MAC...
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
PlmeEdConfirmCallback m_plmeEdConfirmCallback
This callback is used to report ED status to the MAC.
Definition: lr-wpan-phy.h:751
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:204
void SetDevice(Ptr< NetDevice > d)
Set the associated NetDevice instance.
Definition: lr-wpan-phy.cc:217
void SetPlmeEdConfirmCallback(PlmeEdConfirmCallback c)
set the callback for the end of an ED, as part of the interconnections betweenthe PHY and the MAC...
LrWpanEdPower m_edPower
Helper value for tracking the average power during ED.
Definition: lr-wpan-phy.h:779
Time measurementLength
Total measuremement period.
Definition: lr-wpan-phy.h:54
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:280
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
void ChangeTrxState(LrWpanPhyEnumeration newState)
Change the PHY state to the given new state, firing the state change trace.
PacketAndStatus m_currentTxPacket
Statusinformation of the currently transmitted packet.
Definition: lr-wpan-phy.h:817
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
TracedCallback< Ptr< const Packet > > m_phyRxBeginTrace
The trace source fired when a packet begins the reception process from the medium.
Definition: lr-wpan-phy.h:649
uint8_t phyCCAMode
CCA mode.
Definition: lr-wpan-phy.h:162
PlmeGetAttributeConfirmCallback m_plmeGetAttributeConfirmCallback
This callback is used to report requested attribute values back to the MAC.
Definition: lr-wpan-phy.h:757
void EndSetTRXState(void)
Called after applying a deferred transceiver state switch.
Ptr< SpectrumValue > m_txPsd
The transmit power spectral density.
Definition: lr-wpan-phy.h:699
TracedCallback< Ptr< const Packet > > m_phyRxDropTrace
The trace source fired when the phy layer drops a packet it has received.
Definition: lr-wpan-phy.h:664
Introspection did not find any typical Config paths.
IEEE802.15.4-2006 PHY PIB Attributes Table 23 in section 6.4.2.
Definition: lr-wpan-phy.h:157
static const LrWpanPhyPpduHeaderSymbolNumber ppduHeaderSymbolNumbers[7]
The preamble, SFD, and PHR lengths in symbols for the different PHY options.
Definition: lr-wpan-phy.h:502
double m_rxSensitivity
The receiver sensitivity.
Definition: lr-wpan-phy.h:789
double GetDataOrSymbolRate(bool isData)
implement PLME SetAttribute confirm SAP
TracedCallback< Time, LrWpanPhyEnumeration, LrWpanPhyEnumeration > m_trxStateLogger
The trace source fired when the phy layer changes the transceiver state.
Definition: lr-wpan-phy.h:674
PlmeSetTRXStateConfirmCallback m_plmeSetTRXStateConfirmCallback
This callback is used to report transceiver state change status to the MAC.
Definition: lr-wpan-phy.h:763
bool IsExpired(void) const
This method is syntactic sugar for the ns3::Simulator::IsExpired method.
Definition: event-id.cc:59
static const uint32_t aMaxPhyPacketSize
The maximum packet size accepted by the PHY.
Definition: lr-wpan-phy.h:262
channel
Definition: third.py:85
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
static TypeId GetTypeId(void)
Get the type ID.
Definition: lr-wpan-phy.cc:74
void SetPlmeSetAttributeConfirmCallback(PlmeSetAttributeConfirmCallback c)
set the callback for the end of an SetAttribute, as part of the interconnections betweenthe PHY and t...
Ptr< SpectrumChannel > m_channel
The channel attached to this transceiver.
Definition: lr-wpan-phy.h:689
void SetChannel(Ptr< SpectrumChannel > c)
Set the channel attached to this device.
Definition: lr-wpan-phy.cc:233
Time lastUpdate
Last update time.
Definition: lr-wpan-phy.h:53
static const LrWpanPhyDataAndSymbolRates dataSymbolRates[7]
The data and symbol rates for the different PHY options.
Definition: lr-wpan-phy.h:497
uint32_t phyChannelsSupported[32]
BitField representing the available channels supported by a channel page.
Definition: lr-wpan-phy.h:160
void SetPlmeGetAttributeConfirmCallback(PlmeGetAttributeConfirmCallback c)
set the callback for the end of an GetAttribute, as part of the interconnections betweenthe PHY and t...
LrWpanPhyEnumeration m_trxStatePending
The next pending state to applied after the current action of the PHY is completed.
Definition: lr-wpan-phy.h:726
void SetErrorModel(Ptr< LrWpanErrorModel > e)
set the error model to use
double m_ccaPeakPower
Helper value for the peak power value during CCA.
Definition: lr-wpan-phy.h:784
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1389
#define max(a, b)
Definition: 80211b.c:43
Time GetPpduHeaderTxTime(void)
Calculate the time required for sending the PPDU header, that is the preamble, SFD and PHR...
Ptr< const SpectrumValue > GetNoisePowerSpectralDensity(void)
Get the noise power spectral density.
Ptr< LrWpanInterferenceHelper > m_signal
The accumulated signals currently received by the transceiver, including the signal of a possibly rec...
Definition: lr-wpan-phy.h:796
void SetMyPhyOption(void)
Configure the PHY option according to the current channel and channel page.
Ptr< AntennaModel > m_antenna
The antenna used by the transceiver.
Definition: lr-wpan-phy.h:694
void SetTxPowerSpectralDensity(Ptr< SpectrumValue > txPsd)
Set the Power Spectral Density of outgoing signals in W/Hz.
Time m_rxLastUpdate
Timestamp of the last calculation of the PER of a packet currently received.
Definition: lr-wpan-phy.h:801
Ptr< NetDevice > GetDevice(void) const
Get the associated NetDevice instance.
Definition: lr-wpan-phy.cc:201
uint8_t phyTransmitPower
Transmit power.
Definition: lr-wpan-phy.h:161
void SetAntenna(Ptr< AntennaModel > a)
Set the attached antenna.
Definition: lr-wpan-phy.cc:270
Ptr< const SpectrumValue > m_noise
The spectral density for for the noise.
Definition: lr-wpan-phy.h:704
EventId m_setTRXState
Scheduler event of a currently running deferred transceiver state switch.
Definition: lr-wpan-phy.h:832
bool ReplacePacketTag(Tag &tag)
Replace the value of a packet tag.
Definition: packet.cc:877
This class defines all functions to create spectrum model for LrWpan.
double shrPreamble
Number of symbols for the SHR preamble.
Definition: lr-wpan-phy.h:77
Ptr< NetDevice > m_device
The configured net device.
Definition: lr-wpan-phy.h:684
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...
Definition: lr-wpan-phy.cc:652
LrWpanPhy(void)
Default constructor.
Definition: lr-wpan-phy.cc:123
Ptr< SpectrumChannel > GetChannel(void)
Get the currently attached channel.
Definition: lr-wpan-phy.cc:241
Ptr< MobilityModel > GetMobility(void)
Get the associated MobilityModel instance.
Definition: lr-wpan-phy.cc:209
EventId m_edRequest
Scheduler event of a currently running ED request.
Definition: lr-wpan-phy.h:827
std::pair< Ptr< LrWpanSpectrumSignalParameters >, bool > m_currentRxPacket
Statusinformation of the currently received packet.
Definition: lr-wpan-phy.h:809
Ptr< MobilityModel > m_mobility
The mobility model used by the PHY.
Definition: lr-wpan-phy.h:679
LrWpanPhyOption m_phyOption
The currently configured PHY type.
Definition: lr-wpan-phy.h:774
uint8_t Get(void) const
Get the LQI value.
void EndCca(void)
Called at the end of the CCA.
void PlmeSetTRXStateRequest(LrWpanPhyEnumeration state)
IEEE 802.15.4-2006 section 6.2.2.7 PLME-SET-TRX-STATE.request Set PHY state.
Definition: lr-wpan-phy.cc:687
bool ChannelSupported(uint8_t channel)
Check if the given channel is supported by the PHY.
Definition: lr-wpan-phy.cc:875
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetMobility(Ptr< MobilityModel > m)
Set the mobility model associated with this device.
Definition: lr-wpan-phy.cc:225
PdDataIndicationCallback m_pdDataIndicationCallback
This callback is used to notify incoming packets to the MAC layer.
Definition: lr-wpan-phy.h:733
double GetValue(double min, double max)
Get the next random value, as a double in the specified range .
double symbolRate
symbol rate
Definition: lr-wpan-phy.h:66
double averagePower
Average measured power.
Definition: lr-wpan-phy.h:52
double GetPhySymbolsPerOctet(void) const
Get the number of symbols per octet, depending on the currently selected channel. ...
PlmeSetAttributeConfirmCallback m_plmeSetAttributeConfirmCallback
This callback is used to report attribute set results back to the MAC.
Definition: lr-wpan-phy.h:769
TracedCallback< Ptr< const Packet > > m_phyTxEndTrace
The trace source fired when a packet ends the transmission process on the medium. ...
Definition: lr-wpan-phy.h:633
Ptr< const SpectrumModel > GetSpectrumModel() const
Ptr< AntennaModel > GetRxAntenna(void)
Get the AntennaModel used by the NetDevice for reception.
Definition: lr-wpan-phy.cc:263
TracedCallback< Ptr< const Packet > > m_phyTxBeginTrace
The trace source fired when a packet begins the transmission process on the medium.
Definition: lr-wpan-phy.h:625
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:193
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
void EndTx(void)
Finish the transmission of a frame.
uint64_t GetPhySHRDuration(void) const
Get the duration of the SHR (preamble and SFD) in symbols, depending on the currently selected channe...
EventId m_ccaRequest
Scheduler event of a currently running CCA request.
Definition: lr-wpan-phy.h:822
void CheckInterference(void)
Check if the interference destroys a frame currently received.
Definition: lr-wpan-phy.cc:397
virtual ~LrWpanPhy(void)
Definition: lr-wpan-phy.cc:168
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
Definition: abort.h:77
EventId m_pdDataRequest
Scheduler event of a currently running data transmission request.
Definition: lr-wpan-phy.h:837
PlmeCcaConfirmCallback m_plmeCcaConfirmCallback
This callback is used to report CCA status to the MAC or CSMA/CA.
Definition: lr-wpan-phy.h:745
Ptr< LrWpanErrorModel > GetErrorModel(void) const
get the error model in use
Ptr< SpectrumValue > CreateNoisePowerSpectralDensity(uint32_t channel)
create spectrum value for noise
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
bool PhyIsBusy(void) const
Check if the PHY is busy, which is the case if the PHY is currently sending or receiving a frame...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:264
void SetNoisePowerSpectralDensity(Ptr< const SpectrumValue > noisePsd)
Set the noise power spectral density.
LrWpanPhyPibAttributes m_phyPIBAttributes
The current PHY PIB attributes.
Definition: lr-wpan-phy.h:714
virtual void StartRx(Ptr< SpectrumSignalParameters > params)
Notify the SpectrumPhy instance of an incoming waveform.
Definition: lr-wpan-phy.cc:277
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
Definition: packet.cc:870
Ptr< SpectrumValue > CreateTxPowerSpectralDensity(double txPower, uint32_t channel)
create spectrum value
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:272
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1062
TracedCallback< Ptr< const Packet >, double > m_phyRxEndTrace
The trace source fired when a packet ends the reception process from the medium.
Definition: lr-wpan-phy.h:657
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:65
void EndEd(void)
Called at the end of the ED procedure.
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...
Definition: lr-wpan-phy.cc:893
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) ...
Definition: lr-wpan-phy.cc:523
double phr
Number of symbols for the PHR.
Definition: lr-wpan-phy.h:79
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:53
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 ...
uint8_t phyCurrentChannel
The RF channel to use.
Definition: lr-wpan-phy.h:159
void Set(uint8_t lqi)
Set the LQI to the given value.
LrWpanPhyEnumeration
IEEE802.15.4-2006 PHY Emumerations Table 18 in section 6.2.3.
Definition: lr-wpan-phy.h:105
Time CalculateTxTime(Ptr< const Packet > packet)
Calculate the time required for sending the given packet, including preamble, SFD and PHR...
void PlmeCcaRequest(void)
IEEE 802.15.4-2006 section 6.2.2.1 PLME-CCA.request Perform a CCA per section 6.9.9.
Definition: lr-wpan-phy.cc:598
void PlmeEdRequest(void)
IEEE 802.15.4-2006 section 6.2.2.3 PLME-ED.request Perform an ED per section 6.9.7.
Definition: lr-wpan-phy.cc:625
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
Definition: packet.cc:885
void CancelEd(LrWpanPhyEnumeration state)
Cancel an ongoing ED procedure.
virtual void DoDispose(void)
Destructor implementation.
Definition: lr-wpan-phy.cc:173
LrWpanPhyOption
This Phy option will be used to index various Tables in IEEE802.15.4-2006.
Definition: lr-wpan-phy.h:87
double shrSfd
Number of symbols for the SHR SFD.
Definition: lr-wpan-phy.h:78
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:1270
virtual Ptr< const SpectrumModel > GetRxSpectrumModel(void) const
Definition: lr-wpan-phy.cc:249
millisecond
Definition: nstime.h:115
This class can be used to hold variables of floating point type such as &#39;double&#39; or &#39;float&#39;...
Definition: double.h:41
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:185
Ptr< LrWpanErrorModel > m_errorModel
The error model describing the bit and packet error rates.
Definition: lr-wpan-phy.h:709
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
void EndRx(Ptr< SpectrumSignalParameters > params)
Finish the reception of a frame.
Definition: lr-wpan-phy.cc:443
int64_t GetTimeStep(void) const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:391