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;
943  }
944  break;
945  }
947  { // only the first element is considered in the array
948  if ((attribute->phyChannelsSupported[0] & 0xf8000000) != 0)
949  { //5 MSBs reserved
951  }
952  else
953  {
955  }
956  break;
957  }
958  case phyTransmitPower:
959  {
960  if (attribute->phyTransmitPower & 0xC0)
961  {
962  NS_LOG_LOGIC ("LrWpanPhy::PlmeSetAttributeRequest error - can not change read-only attribute bits.");
964  }
965  else
966  {
968  LrWpanSpectrumValueHelper psdHelper;
971  }
972  break;
973  }
974  case phyCCAMode:
975  {
976  if ((attribute->phyCCAMode < 1) || (attribute->phyCCAMode > 3))
977  {
979  }
980  else
981  {
983  }
984  break;
985  }
986  default:
987  {
989  break;
990  }
991  }
992 
994  {
996  }
997 }
998 
999 void
1001 {
1002  NS_LOG_FUNCTION (this);
1004 }
1005 
1006 void
1008 {
1009  NS_LOG_FUNCTION (this);
1011 }
1012 
1013 void
1015 {
1016  NS_LOG_FUNCTION (this);
1018 }
1019 
1020 void
1022 {
1023  NS_LOG_FUNCTION (this);
1025 }
1026 
1027 void
1029 {
1030  NS_LOG_FUNCTION (this);
1032 }
1033 
1034 void
1036 {
1037  NS_LOG_FUNCTION (this);
1039 }
1040 
1041 void
1043 {
1044  NS_LOG_FUNCTION (this);
1046 }
1047 
1048 void
1050 {
1051  NS_LOG_LOGIC (this << " state: " << m_trxState << " -> " << newState);
1052  m_trxStateLogger (Simulator::Now (), m_trxState, newState);
1053  m_trxState = newState;
1054 }
1055 
1056 bool
1058 {
1059  NS_LOG_FUNCTION (this << m_trxState);
1063 }
1064 
1065 void
1067 {
1068  NS_LOG_FUNCTION (this);
1070 
1071  if (!m_edRequest.IsExpired ())
1072  {
1073  m_edRequest.Cancel ();
1075  {
1076  m_plmeEdConfirmCallback (state, 0);
1077  }
1078  }
1079 }
1080 
1081 void
1083 {
1084  NS_LOG_FUNCTION (this);
1085 
1087 
1088  uint8_t energyLevel;
1089 
1090  // Per IEEE802.15.4-2006 sec 6.9.7
1091  double ratio = m_edPower.averagePower / m_rxSensitivity;
1092  ratio = 10.0 * log10 (ratio);
1093  if (ratio <= 10.0)
1094  { // less than 10 dB
1095  energyLevel = 0;
1096  }
1097  else if (ratio >= 40.0)
1098  { // less than 40 dB
1099  energyLevel = 255;
1100  }
1101  else
1102  {
1103  // in-between with linear increase per sec 6.9.7
1104  energyLevel = static_cast<uint8_t> (((ratio - 10.0) / 30.0) * 255.0);
1105  }
1106 
1108  {
1110  }
1111 }
1112 
1113 void
1115 {
1116  NS_LOG_FUNCTION (this);
1118 
1119  // Update peak power.
1121  if (m_ccaPeakPower < power)
1122  {
1123  m_ccaPeakPower = power;
1124  }
1125 
1126  if (PhyIsBusy ())
1127  {
1128  sensedChannelState = IEEE_802_15_4_PHY_BUSY;
1129  }
1130  else if (m_phyPIBAttributes.phyCCAMode == 1)
1131  { //sec 6.9.9 ED detection
1132  // -- ED threshold at most 10 dB above receiver sensitivity.
1133  if (10 * log10 (m_ccaPeakPower / m_rxSensitivity) >= 10.0)
1134  {
1135  sensedChannelState = IEEE_802_15_4_PHY_BUSY;
1136  }
1137  else
1138  {
1139  sensedChannelState = IEEE_802_15_4_PHY_IDLE;
1140  }
1141  }
1142  else if (m_phyPIBAttributes.phyCCAMode == 2)
1143  {
1144  //sec 6.9.9 carrier sense only
1146  {
1147  // We currently do not model PPDU reception in detail. Instead we model
1148  // packet reception starting with the first bit of the preamble.
1149  // Therefore, this code will never be reached, as PhyIsBusy() would
1150  // already lead to a channel busy condition.
1151  // TODO: Change this, if we also model preamble and SFD detection.
1152  sensedChannelState = IEEE_802_15_4_PHY_BUSY;
1153  }
1154  else
1155  {
1156  sensedChannelState = IEEE_802_15_4_PHY_IDLE;
1157  }
1158  }
1159  else if (m_phyPIBAttributes.phyCCAMode == 3)
1160  { //sect 6.9.9 both
1161  if ((10 * log10 (m_ccaPeakPower / m_rxSensitivity) >= 10.0)
1163  {
1164  // Again, this code will never be reached, if we are already receiving
1165  // a packet, as PhyIsBusy() would already lead to a channel busy condition.
1166  // TODO: Change this, if we also model preamble and SFD detection.
1167  sensedChannelState = IEEE_802_15_4_PHY_BUSY;
1168  }
1169  else
1170  {
1171  sensedChannelState = IEEE_802_15_4_PHY_IDLE;
1172  }
1173  }
1174  else
1175  {
1176  NS_ASSERT_MSG (false, "Invalid CCA mode");
1177  }
1178 
1179  NS_LOG_LOGIC (this << "channel sensed state: " << sensedChannelState);
1180 
1182  {
1183  m_plmeCcaConfirmCallback (sensedChannelState);
1184  }
1185 }
1186 
1187 void
1189 {
1190  NS_LOG_FUNCTION (this);
1191 
1195 
1197  {
1199  }
1200 }
1201 
1202 void
1204 {
1205  NS_LOG_FUNCTION (this);
1206 
1208 
1209  if (m_currentTxPacket.second == false)
1210  {
1211  NS_LOG_DEBUG ("Packet successfully transmitted");
1214  {
1216  }
1217  }
1218  else
1219  {
1220  NS_LOG_DEBUG ("Packet transmission aborted");
1223  {
1224  // See if this is ever entered in another state
1227  }
1228  }
1229  m_currentTxPacket.first = 0;
1230  m_currentTxPacket.second = false;
1231 
1232 
1233  // We may be waiting to apply a pending state change.
1235  {
1236  // Only change the state immediately, if the transceiver is not already
1237  // switching the state.
1238  if (!m_setTRXState.IsRunning ())
1239  {
1240  NS_LOG_LOGIC ("Apply pending state change to " << m_trxStatePending);
1244  {
1246  }
1247  }
1248  }
1249  else
1250  {
1252  {
1254  }
1255  }
1256 }
1257 
1258 Time
1260 {
1261  NS_LOG_FUNCTION (this << packet);
1262 
1263  bool isData = true;
1264  Time txTime = GetPpduHeaderTxTime ();
1265 
1266  txTime += Seconds (packet->GetSize () * 8.0 / GetDataOrSymbolRate (isData));
1267 
1268  return txTime;
1269 }
1270 
1271 double
1273 {
1274  NS_LOG_FUNCTION (this << isData);
1275 
1276  double rate = 0.0;
1277 
1279 
1280  if (isData)
1281  {
1283  }
1284  else
1285  {
1287  }
1288 
1289  return (rate * 1000.0);
1290 }
1291 
1292 Time
1294 {
1295  NS_LOG_FUNCTION (this);
1296 
1297  bool isData = false;
1298  double totalPpduHdrSymbols;
1299 
1301 
1302  totalPpduHdrSymbols = ppduHeaderSymbolNumbers[m_phyOption].shrPreamble
1305 
1306  return Seconds (totalPpduHdrSymbols / GetDataOrSymbolRate (isData));
1307 }
1308 
1309 // IEEE802.15.4-2006 Table 2 in section 6.1.2
1310 void
1312 {
1313  NS_LOG_FUNCTION (this);
1314 
1316 
1318  {
1320  { // 868 MHz BPSK
1322  }
1323  else if (m_phyPIBAttributes.phyCurrentChannel <= 10)
1324  { // 915 MHz BPSK
1326  }
1327  else if (m_phyPIBAttributes.phyCurrentChannel <= 26)
1328  { // 2.4 GHz MHz O-QPSK
1330  }
1331  }
1332  else if (m_phyPIBAttributes.phyCurrentPage == 1)
1333  {
1335  { // 868 MHz ASK
1337  }
1338  else if (m_phyPIBAttributes.phyCurrentChannel <= 10)
1339  { // 915 MHz ASK
1341  }
1342  }
1343  else if (m_phyPIBAttributes.phyCurrentPage == 2)
1344  {
1346  { // 868 MHz O-QPSK
1348  }
1349  else if (m_phyPIBAttributes.phyCurrentChannel <= 10)
1350  { // 915 MHz O-QPSK
1352  }
1353  }
1354 }
1355 
1358 {
1359  NS_LOG_FUNCTION (this);
1360  return m_phyOption;
1361 }
1362 
1363 void
1365 {
1366  NS_LOG_FUNCTION (this << txPsd);
1367  NS_ASSERT (txPsd);
1368  m_txPsd = txPsd;
1369  NS_LOG_INFO ("\t computed tx_psd: " << *txPsd << "\t stored tx_psd: " << *m_txPsd);
1370 }
1371 
1372 void
1374 {
1375  NS_LOG_FUNCTION (this << noisePsd);
1376  NS_LOG_INFO ("\t computed noise_psd: " << *noisePsd );
1377  NS_ASSERT (noisePsd);
1378  m_noise = noisePsd;
1379 }
1380 
1383 {
1384  NS_LOG_FUNCTION (this);
1385  return m_noise;
1386 }
1387 
1388 void
1390 {
1391  NS_LOG_FUNCTION (this << e);
1392  NS_ASSERT (e);
1393  m_errorModel = e;
1394 }
1395 
1398 {
1399  NS_LOG_FUNCTION (this);
1400  return m_errorModel;
1401 }
1402 
1403 uint64_t
1405 {
1406  NS_LOG_FUNCTION (this);
1408 
1411 }
1412 
1413 double
1415 {
1416  NS_LOG_FUNCTION (this);
1418 
1420 }
1421 
1422 int8_t
1424 {
1425  NS_LOG_FUNCTION (this << +phyTransmitPower);
1426 
1427  // The nominal Tx power is stored in the PIB as a 6-bit
1428  // twos-complement, signed number.
1429 
1430  // The 5 LSBs can be copied - as their representation
1431  // is the same for unsigned and signed integers.
1432  int8_t nominalTxPower = phyTransmitPower & 0x1F;
1433 
1434  // Now check the 6th LSB (the "sign" bit).
1435  // It's a twos-complement format, so the "sign"
1436  // bit represents -2^5 = -32.
1437  if (phyTransmitPower & 0x20)
1438  {
1439  nominalTxPower -= 32;
1440  }
1441  return nominalTxPower;
1442 }
1443 
1444 
1445 int64_t
1447 {
1448  NS_LOG_FUNCTION (this);
1449  m_random->SetStream (stream);
1450  return 1;
1451 }
1452 
1453 } // namespace ns3
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:557
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
#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:643
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
Ptr< UniformRandomVariable > m_random
Uniform random variable stream.
Definition: lr-wpan-phy.h:862
PdDataConfirmCallback m_pdDataConfirmCallback
This callback is used to report packet transmission status to the MAC layer.
Definition: lr-wpan-phy.h:759
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:740
void SetPdDataIndicationCallback(PdDataIndicationCallback c)
set the callback for the end of a RX, as part of the interconnections betweenthe PHY and the MAC...
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:771
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
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:799
Time measurementLength
Total measurement period.
Definition: lr-wpan-phy.h:54
Ptr< MobilityModel > GetMobility(void) const
Get the associated MobilityModel instance.
Definition: lr-wpan-phy.cc:209
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
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:837
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:651
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:777
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:719
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:666
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:504
double m_rxSensitivity
The receiver sensitivity.
Definition: lr-wpan-phy.h:809
double GetDataOrSymbolRate(bool isData)
implement PLME SetAttribute confirm SAP bit rate is in kbit/s.
TracedCallback< Time, LrWpanPhyEnumeration, LrWpanPhyEnumeration > m_trxStateLogger
The trace source fired when the phy layer changes the transceiver state.
Definition: lr-wpan-phy.h:676
PlmeSetTRXStateConfirmCallback m_plmeSetTRXStateConfirmCallback
This callback is used to report transceiver state change status to the MAC.
Definition: lr-wpan-phy.h:783
bool IsExpired(void) const
This method is syntactic sugar for the ns3::Simulator::IsExpired method.
Definition: event-id.cc:65
static const uint32_t aMaxPhyPacketSize
The maximum packet size accepted by the PHY.
Definition: lr-wpan-phy.h:262
channel
Definition: third.py:92
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:709
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:499
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:746
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:804
#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:816
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:714
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:821
Ptr< NetDevice > GetDevice(void) const
Get the associated NetDevice instance.
Definition: lr-wpan-phy.cc:201
uint8_t phyTransmitPower
2 MSB: tolerance on the transmit power, 6 LSB: Tx power in dBm relative to 1mW (signed int in 2-compl...
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:724
EventId m_setTRXState
Scheduler event of a currently running deferred transceiver state switch.
Definition: lr-wpan-phy.h:852
bool ReplacePacketTag(Tag &tag)
Replace the value of a packet tag.
Definition: packet.cc:970
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:704
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
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:289
EventId m_edRequest
Scheduler event of a currently running ED request.
Definition: lr-wpan-phy.h:847
std::pair< Ptr< LrWpanSpectrumSignalParameters >, bool > m_currentRxPacket
Statusinformation of the currently received packet.
Definition: lr-wpan-phy.h:829
Ptr< MobilityModel > m_mobility
The mobility model used by the PHY.
Definition: lr-wpan-phy.h:699
LrWpanPhyOption m_phyOption
The currently configured PHY type.
Definition: lr-wpan-phy.h:794
int8_t GetNominalTxPowerFromPib(uint8_t phyTransmitPower)
Calculates the nominal transmit power of the device in decibels relative to 1 mW according to the rep...
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
Ptr< AntennaModel > GetRxAntenna(void) const
Get the AntennaModel used by the NetDevice for reception.
Definition: lr-wpan-phy.cc:263
PdDataIndicationCallback m_pdDataIndicationCallback
This callback is used to notify incoming packets to the MAC layer.
Definition: lr-wpan-phy.h:753
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:789
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:635
Ptr< const SpectrumModel > GetSpectrumModel() const
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:627
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
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:842
void CheckInterference(void)
Check if the interference destroys a frame currently received.
Definition: lr-wpan-phy.cc:397
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:88
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:857
PlmeCcaConfirmCallback m_plmeCcaConfirmCallback
This callback is used to report CCA status to the MAC or CSMA/CA.
Definition: lr-wpan-phy.h:765
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:265
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:734
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:963
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:273
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
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:659
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:71
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:978
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:1386
virtual Ptr< const SpectrumModel > GetRxSpectrumModel(void) const
Definition: lr-wpan-phy.cc:249
millisecond
Definition: nstime.h:116
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:729
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
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:416