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")
77  .SetParent<Object> ()
78  .SetGroupName ("LrWpan")
79  .AddConstructor<LrWpanPhy> ()
80  .AddTraceSource ("TrxState",
81  "The state of the transceiver",
83  "ns3::LrWpanPhy::StateTracedCallback")
84  .AddTraceSource ("PhyTxBegin",
85  "Trace source indicating a packet has "
86  "begun transmitting over the channel medium",
88  "ns3::Packet::TracedCallback")
89  .AddTraceSource ("PhyTxEnd",
90  "Trace source indicating a packet has been "
91  "completely transmitted over the channel.",
93  "ns3::Packet::TracedCallback")
94  .AddTraceSource ("PhyTxDrop",
95  "Trace source indicating a packet has been "
96  "dropped by the device during transmission",
98  "ns3::Packet::TracedCallback")
99  .AddTraceSource ("PhyRxBegin",
100  "Trace source indicating a packet has begun "
101  "being received from the channel medium by the device",
103  "ns3::Packet::TracedCallback")
104  .AddTraceSource ("PhyRxEnd",
105  "Trace source indicating a packet has been "
106  "completely received from the channel medium "
107  "by the device",
109  "ns3::LrWpanPhy::RxEndTracedCallback")
110  .AddTraceSource ("PhyRxDrop",
111  "Trace source indicating a packet has been "
112  "dropped by the device during reception",
114  "ns3::Packet::TracedCallback")
115  ;
116  return tid;
117 }
118 
120  : m_edRequest (),
121  m_setTRXState ()
122 {
125 
126  // default PHY PIB attributes
130  for (uint32_t i = 0; i < 32; i++)
131  {
133  }
135 
136  SetMyPhyOption ();
137 
138  m_edPower.averagePower = 0.0;
139  m_edPower.lastUpdate = Seconds (0.0);
141 
142  // default -110 dBm in W for 2.4 GHz
143  m_rxSensitivity = pow (10.0, -106.58 / 10.0) / 1000.0;
144  LrWpanSpectrumValueHelper psdHelper;
148  m_signal = Create<LrWpanInterferenceHelper> (m_noise->GetSpectrumModel ());
149  m_rxLastUpdate = Seconds (0);
150  Ptr<Packet> none_packet = 0;
151  Ptr<LrWpanSpectrumSignalParameters> none_params = 0;
152  m_currentRxPacket = std::make_pair (none_params, true);
153  m_currentTxPacket = std::make_pair (none_packet, true);
154  m_errorModel = 0;
155 
156  m_random = CreateObject<UniformRandomVariable> ();
157  m_random->SetAttribute ("Min", DoubleValue (0.0));
158  m_random->SetAttribute ("Max", DoubleValue (1.0));
159 
160 
162 }
163 
165 {
166 }
167 
168 void
170 {
171  NS_LOG_FUNCTION (this);
172 
173  // Cancel pending transceiver state change, if one is in progress.
177 
178  m_mobility = 0;
179  m_device = 0;
180  m_channel = 0;
181  m_txPsd = 0;
182  m_noise = 0;
183  m_signal = 0;
184  m_errorModel = 0;
185  m_pdDataIndicationCallback = MakeNullCallback< void, uint32_t, Ptr<Packet>, uint8_t > ();
186  m_pdDataConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration > ();
187  m_plmeCcaConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration > ();
188  m_plmeEdConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration,uint8_t > ();
189  m_plmeGetAttributeConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration, LrWpanPibAttributeIdentifier, LrWpanPhyPibAttributes* > ();
190  m_plmeSetTRXStateConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration > ();
191  m_plmeSetAttributeConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration, LrWpanPibAttributeIdentifier > ();
192 
194 }
195 
198 {
199  NS_LOG_FUNCTION (this);
200  return m_device;
201 }
202 
203 
206 {
207  NS_LOG_FUNCTION (this);
208  return m_mobility;
209 }
210 
211 
212 void
214 {
215  NS_LOG_FUNCTION (this << d);
216  m_device = d;
217 }
218 
219 
220 void
222 {
223  NS_LOG_FUNCTION (this << m);
224  m_mobility = m;
225 }
226 
227 
228 void
230 {
231  NS_LOG_FUNCTION (this << c);
232  m_channel = c;
233 }
234 
235 
238 {
239  NS_LOG_FUNCTION (this);
240  return m_channel;
241 }
242 
243 
246 {
247  NS_LOG_FUNCTION (this);
248  if (m_txPsd)
249  {
250  return m_txPsd->GetSpectrumModel ();
251  }
252  else
253  {
254  return 0;
255  }
256 }
257 
260 {
261  NS_LOG_FUNCTION (this);
262  return m_antenna;
263 }
264 
265 void
267 {
268  NS_LOG_FUNCTION (this << a);
269  m_antenna = a;
270 }
271 
272 void
274 {
275  NS_LOG_FUNCTION (this << spectrumRxParams);
276  LrWpanSpectrumValueHelper psdHelper;
277 
278  if (!m_edRequest.IsExpired ())
279  {
280  // Update the average receive power during ED.
281  Time now = Simulator::Now ();
283  m_edPower.lastUpdate = now;
284  }
285 
286  Ptr<LrWpanSpectrumSignalParameters> lrWpanRxParams = DynamicCast<LrWpanSpectrumSignalParameters> (spectrumRxParams);
287 
288  if (lrWpanRxParams == 0)
289  {
291  m_signal->AddSignal (spectrumRxParams->psd);
292 
293  // Update peak power if CCA is in progress.
294  if (!m_ccaRequest.IsExpired ())
295  {
297  if (m_ccaPeakPower < power)
298  {
299  m_ccaPeakPower = power;
300  }
301  }
302 
303  Simulator::Schedule (spectrumRxParams->duration, &LrWpanPhy::EndRx, this, spectrumRxParams);
304  return;
305  }
306 
307  Ptr<Packet> p = (lrWpanRxParams->packetBurst->GetPackets ()).front ();
308  NS_ASSERT (p != 0);
309 
310  // Prevent PHY from receiving another packet while switching the transceiver state.
312  {
313  // The specification doesn't seem to refer to BUSY_RX, but vendor
314  // data sheets suggest that this is a substate of the RX_ON state
315  // that is entered after preamble detection when the digital receiver
316  // is enabled. Here, for now, we use BUSY_RX to mark the period between
317  // StartRx() and EndRx() states.
318 
319  // We are going to BUSY_RX state when receiving the first bit of an SHR,
320  // as opposed to real receivers, which should go to this state only after
321  // successfully receiving the SHR.
322 
323  // If synchronizing to the packet is possible, change to BUSY_RX state,
324  // otherwise drop the packet and stay in RX state. The actual synchronization
325  // is not modeled.
326 
327  // Add any incoming packet to the current interference before checking the
328  // SINR.
329  NS_LOG_DEBUG (this << " receiving packet with power: " << 10 * log10(LrWpanSpectrumValueHelper::TotalAvgPower (lrWpanRxParams->psd, m_phyPIBAttributes.phyCurrentChannel)) + 30 << "dBm");
330  m_signal->AddSignal (lrWpanRxParams->psd);
331  Ptr<SpectrumValue> interferenceAndNoise = m_signal->GetSignalPsd ();
332  *interferenceAndNoise -= *lrWpanRxParams->psd;
333  *interferenceAndNoise += *m_noise;
335 
336  // Std. 802.15.4-2006, appendix E, Figure E.2
337  // At SNR < -5 the BER is less than 10e-1.
338  // It's useless to even *try* to decode the packet.
339  if (10 * log10 (sinr) > -5)
340  {
342  m_currentRxPacket = std::make_pair (lrWpanRxParams, false);
343  m_phyRxBeginTrace (p);
344 
346  }
347  else
348  {
349  m_phyRxDropTrace (p);
350  }
351  }
353  {
354  // Drop the new packet.
355  NS_LOG_DEBUG (this << " packet collision");
356  m_phyRxDropTrace (p);
357 
358  // Check if we correctly received the old packet up to now.
360 
361  // Add the incoming packet to the current interference after we have
362  // checked for successfull reception of the current packet for the time
363  // before the additional interference.
364  m_signal->AddSignal (lrWpanRxParams->psd);
365  }
366  else
367  {
368  // Simply drop the packet.
369  NS_LOG_DEBUG (this << " transceiver not in RX state");
370  m_phyRxDropTrace (p);
371 
372  // Add the signal power to the interference, anyway.
373  m_signal->AddSignal (lrWpanRxParams->psd);
374  }
375 
376  // Update peak power if CCA is in progress.
377  if (!m_ccaRequest.IsExpired ())
378  {
380  if (m_ccaPeakPower < power)
381  {
382  m_ccaPeakPower = power;
383  }
384  }
385 
386  // Always call EndRx to update the interference.
387  // \todo: Do we need to keep track of these events to unschedule them when disposing off the PHY?
388 
389  Simulator::Schedule (spectrumRxParams->duration, &LrWpanPhy::EndRx, this, spectrumRxParams);
390 }
391 
392 void
394 {
395  // Calculate whether packet was lost.
396  LrWpanSpectrumValueHelper psdHelper;
398 
399  // We are currently receiving a packet.
401  {
402  // NS_ASSERT (currentRxParams && !m_currentRxPacket.second);
403 
404  Ptr<Packet> currentPacket = currentRxParams->packetBurst->GetPackets ().front ();
405  if (m_errorModel != 0)
406  {
407  // How many bits did we receive since the last calculation?
408  double t = (Simulator::Now () - m_rxLastUpdate).ToDouble (Time::MS);
409  uint32_t chunkSize = ceil (t * (GetDataOrSymbolRate (true) / 1000));
410  Ptr<SpectrumValue> interferenceAndNoise = m_signal->GetSignalPsd ();
411  *interferenceAndNoise -= *currentRxParams->psd;
412  *interferenceAndNoise += *m_noise;
414  double per = 1.0 - m_errorModel->GetChunkSuccessRate (sinr, chunkSize);
415 
416  // The LQI is the total packet success rate scaled to 0-255.
417  // If not already set, initialize to 255.
418  LrWpanLqiTag tag (std::numeric_limits<uint8_t>::max ());
419  currentPacket->PeekPacketTag (tag);
420  uint8_t lqi = tag.Get ();
421  tag.Set (lqi - (per * lqi));
422  currentPacket->ReplacePacketTag (tag);
423 
424  if (m_random->GetValue () < per)
425  {
426  // The packet was destroyed, drop the packet after reception.
427  m_currentRxPacket.second = true;
428  }
429  }
430  else
431  {
432  NS_LOG_WARN ("Missing ErrorModel");
433  }
434  }
436 }
437 
438 void
440 {
441  NS_LOG_FUNCTION (this);
442 
443  Ptr<LrWpanSpectrumSignalParameters> params = DynamicCast<LrWpanSpectrumSignalParameters> (par);
444 
445  if (!m_edRequest.IsExpired ())
446  {
447  // Update the average receive power during ED.
448  Time now = Simulator::Now ();
450  m_edPower.lastUpdate = now;
451  }
452 
454  if (currentRxParams == params)
455  {
457  }
458 
459  // Update the interference.
460  m_signal->RemoveSignal (par->psd);
461 
462  if (params == 0)
463  {
464  NS_LOG_LOGIC ("Node: " << m_device->GetAddress() << " Removing interferent: " << *(par->psd));
465  return;
466  }
467 
468  // If this is the end of the currently received packet, check if reception was successful.
469  if (currentRxParams == params)
470  {
471  Ptr<Packet> currentPacket = currentRxParams->packetBurst->GetPackets ().front ();
472  NS_ASSERT (currentPacket != 0);
473 
474  // If there is no error model attached to the PHY, we always report the maximum LQI value.
475  LrWpanLqiTag tag (std::numeric_limits<uint8_t>::max ());
476  currentPacket->PeekPacketTag (tag);
477  m_phyRxEndTrace (currentPacket, tag.Get ());
478 
479  if (!m_currentRxPacket.second)
480  {
481  // The packet was successfully received, push it up the stack.
483  {
484  m_pdDataIndicationCallback (currentPacket->GetSize (), currentPacket, tag.Get ());
485  }
486  }
487  else
488  {
489  // The packet was destroyed, drop it.
490  m_phyRxDropTrace (currentPacket);
491  }
493  m_currentRxPacket = std::make_pair (none, true);
494 
495  // We may be waiting to apply a pending state change.
497  {
498  // Only change the state immediately, if the transceiver is not already
499  // switching the state.
500  if (!m_setTRXState.IsRunning ())
501  {
502  NS_LOG_LOGIC ("Apply pending state change to " << m_trxStatePending);
506  {
508  }
509  }
510  }
511  else
512  {
514  }
515  }
516 }
517 
518 void
519 LrWpanPhy::PdDataRequest (const uint32_t psduLength, Ptr<Packet> p)
520 {
521  NS_LOG_FUNCTION (this << psduLength << p);
522 
523  if (psduLength > aMaxPhyPacketSize)
524  {
526  {
528  }
529  NS_LOG_DEBUG ("Drop packet because psduLength too long: " << psduLength);
530  return;
531  }
532 
533  // Prevent PHY from sending a packet while switching the transceiver state.
534  if (!m_setTRXState.IsRunning ())
535  {
537  {
538  //send down
540 
541  // Remove a possible LQI tag from a previous transmission of the packet.
542  LrWpanLqiTag lqiTag;
543  p->RemovePacketTag (lqiTag);
544 
545  Ptr<LrWpanSpectrumSignalParameters> txParams = Create<LrWpanSpectrumSignalParameters> ();
546  txParams->duration = CalculateTxTime (p);
547  txParams->txPhy = GetObject<SpectrumPhy> ();
548  txParams->psd = m_txPsd;
549  txParams->txAntenna = m_antenna;
550  Ptr<PacketBurst> pb = CreateObject<PacketBurst> ();
551  pb->AddPacket (p);
552  txParams->packetBurst = pb;
553  m_channel->StartTx (txParams);
554  m_pdDataRequest = Simulator::Schedule (txParams->duration, &LrWpanPhy::EndTx, this);
556  m_phyTxBeginTrace (p);
557  m_currentTxPacket.first = p;
558  m_currentTxPacket.second = false;
559  return;
560  }
561  else if ((m_trxState == IEEE_802_15_4_PHY_RX_ON)
564  {
566  {
568  }
569  // Drop packet, hit PhyTxDrop trace
570  m_phyTxDropTrace (p);
571  return;
572  }
573  else
574  {
575  NS_FATAL_ERROR ("This should be unreachable, or else state " << m_trxState << " should be added as a case");
576  }
577  }
578  else
579  {
580  // TODO: This error code is not covered by the standard.
581  // What is the correct behavior in this case?
583  {
585  }
586  // Drop packet, hit PhyTxDrop trace
587  m_phyTxDropTrace (p);
588  return;
589  }
590 }
591 
592 void
594 {
595  NS_LOG_FUNCTION (this);
596 
598  {
599  m_ccaPeakPower = 0.0;
600  Time ccaTime = Seconds (8.0 / GetDataOrSymbolRate (false));
602  }
603  else
604  {
606  {
608  {
610  }
611  else
612  {
614  }
615  }
616  }
617 }
618 
619 void
621 {
622  NS_LOG_FUNCTION (this);
624  {
625  // Average over the powers of all signals received until EndEd()
630  }
631  else
632  {
635  {
636  result = IEEE_802_15_4_PHY_TX_ON;
637  }
638 
640  {
641  m_plmeEdConfirmCallback (result, 0);
642  }
643  }
644 }
645 
646 void
648 {
649  NS_LOG_FUNCTION (this << id);
650  LrWpanPhyEnumeration status;
651 
652  switch (id)
653  {
654  case phyCurrentChannel:
656  case phyTransmitPower:
657  case phyCCAMode:
658  case phyCurrentPage:
659  case phyMaxFrameDuration:
660  case phySHRDuration:
661  case phySymbolsPerOctet:
662  {
663  status = IEEE_802_15_4_PHY_SUCCESS;
664  break;
665  }
666  default:
667  {
669  break;
670  }
671  }
673  {
674  LrWpanPhyPibAttributes retValue;
675  memcpy (&retValue, &m_phyPIBAttributes, sizeof(LrWpanPhyPibAttributes));
676  m_plmeGetAttributeConfirmCallback (status,id,&retValue);
677  }
678 }
679 
680 // Section 6.2.2.7.3
681 void
683 {
684  NS_LOG_FUNCTION (this << state);
685 
686  // Check valid states (Table 14)
688  && (state != IEEE_802_15_4_PHY_TRX_OFF)
689  && (state != IEEE_802_15_4_PHY_FORCE_TRX_OFF)
690  && (state != IEEE_802_15_4_PHY_TX_ON) );
691 
692  NS_LOG_LOGIC ("Trying to set m_trxState from " << m_trxState << " to " << state);
693  // this method always overrides previous state setting attempts
694  if (!m_setTRXState.IsExpired ())
695  {
696  if (m_trxStatePending == state)
697  {
698  // Simply wait for the ongoing state switch.
699  return;
700  }
701  else
702  {
703  NS_LOG_DEBUG ("Cancel m_setTRXState");
704  // Keep the transceiver state as the old state before the switching attempt.
706  }
707  }
709  {
711  }
712 
713  if (state == m_trxState)
714  {
716  {
718  }
719  return;
720  }
721 
722  if ( ((state == IEEE_802_15_4_PHY_RX_ON)
723  || (state == IEEE_802_15_4_PHY_TRX_OFF))
725  {
726  NS_LOG_DEBUG ("Phy is busy; setting state pending to " << state);
727  m_trxStatePending = state;
728  return; // Send PlmeSetTRXStateConfirm later
729  }
730 
731  // specification talks about being in RX_ON and having received
732  // a valid SFD. Here, we are not modelling at that level of
733  // granularity, so we just test for BUSY_RX state (any part of
734  // a packet being actively received)
735  if (state == IEEE_802_15_4_PHY_TRX_OFF)
736  {
737  CancelEd (state);
738 
740  && (m_currentRxPacket.first) && (!m_currentRxPacket.second))
741  {
742  NS_LOG_DEBUG ("Receiver has valid SFD; defer state change");
743  m_trxStatePending = state;
744  return; // Send PlmeSetTRXStateConfirm later
745  }
747  {
750  {
752  }
753  return;
754  }
755  }
756 
757  if (state == IEEE_802_15_4_PHY_TX_ON)
758  {
759  CancelEd (state);
760 
761  NS_LOG_DEBUG ("turn on PHY_TX_ON");
763  {
764  if (m_currentRxPacket.first)
765  {
766  //terminate reception if needed
767  //incomplete reception -- force packet discard
768  NS_LOG_DEBUG ("force TX_ON, terminate reception");
769  m_currentRxPacket.second = true;
770  }
771 
772  // If CCA is in progress, cancel CCA and return BUSY.
773  if (!m_ccaRequest.IsExpired ())
774  {
775  m_ccaRequest.Cancel ();
777  {
779  }
780  }
781 
783 
784  // Delay for turnaround time
785  // TODO: Does it also take aTurnaroundTime to switch the transceiver state,
786  // even when the receiver is not busy? (6.9.2)
787  Time setTime = Seconds ( (double) aTurnaroundTime / GetDataOrSymbolRate (false));
789  return;
790  }
792  {
793  // We do NOT change the transceiver state here. We only report that
794  // the transceiver is already in TX_ON state.
796  {
798  }
799  return;
800  }
802  {
805  {
807  }
808  return;
809  }
810  }
811 
812  if (state == IEEE_802_15_4_PHY_FORCE_TRX_OFF)
813  {
815  {
816  NS_LOG_DEBUG ("force TRX_OFF, was already off");
817  }
818  else
819  {
820  NS_LOG_DEBUG ("force TRX_OFF, SUCCESS");
821  if (m_currentRxPacket.first)
822  { //terminate reception if needed
823  //incomplete reception -- force packet discard
824  NS_LOG_DEBUG ("force TRX_OFF, terminate reception");
825  m_currentRxPacket.second = true;
826  }
828  {
829  NS_LOG_DEBUG ("force TRX_OFF, terminate transmission");
830  m_currentTxPacket.second = true;
831  }
833  // Clear any other state
835  }
837  {
839  }
840  return;
841  }
842 
843  if (state == IEEE_802_15_4_PHY_RX_ON)
844  {
846  {
847  // Turnaround delay
848  // TODO: Does it really take aTurnaroundTime to switch the transceiver state,
849  // even when the transmitter is not busy? (6.9.1)
851 
852  Time setTime = Seconds ( (double) aTurnaroundTime / GetDataOrSymbolRate (false));
854  return;
855  }
857  {
859  {
861  }
862  return;
863  }
864  }
865 
866  NS_FATAL_ERROR ("Unexpected transition from state " << m_trxState << " to state " << state);
867 }
868 
869 bool
871 {
872  NS_LOG_FUNCTION (this << channel);
873  bool retValue = false;
874 
875  for (uint32_t i = 0; i < 32; i++)
876  {
877  if ((m_phyPIBAttributes.phyChannelsSupported[i] & (1 << channel)) != 0)
878  {
879  retValue = true;
880  break;
881  }
882  }
883 
884  return retValue;
885 }
886 
887 void
889  LrWpanPhyPibAttributes* attribute)
890 {
891  NS_LOG_FUNCTION (this << id << attribute);
892  NS_ASSERT (attribute);
894 
895  switch (id)
896  {
897  case phyCurrentChannel:
898  {
899  if (!ChannelSupported (attribute->phyCurrentChannel))
900  {
902  }
904  {
905  // Cancel a pending transceiver state change.
906  // Switch off the transceiver.
907  // TODO: Is switching off the transceiver the right choice?
910  {
914  {
916  }
917  }
918 
919  // Any packet in transmission or reception will be corrupted.
920  if (m_currentRxPacket.first)
921  {
922  m_currentRxPacket.second = true;
923  }
924  if (PhyIsBusy ())
925  {
926  m_currentTxPacket.second = true;
928  m_currentTxPacket.first = 0;
930  {
932  }
933  }
935  LrWpanSpectrumValueHelper psdHelper;
937  }
938  break;
939  }
941  { // only the first element is considered in the array
942  if ((attribute->phyChannelsSupported[0] & 0xf8000000) != 0)
943  { //5 MSBs reserved
945  }
946  else
947  {
949  }
950  break;
951  }
952  case phyTransmitPower:
953  {
954  if (attribute->phyTransmitPower > 0xbf)
955  {
957  }
958  else
959  {
961  LrWpanSpectrumValueHelper psdHelper;
963  }
964  break;
965  }
966  case phyCCAMode:
967  {
968  if ((attribute->phyCCAMode < 1) || (attribute->phyCCAMode > 3))
969  {
971  }
972  else
973  {
975  }
976  break;
977  }
978  default:
979  {
981  break;
982  }
983  }
984 
986  {
988  }
989 }
990 
991 void
993 {
994  NS_LOG_FUNCTION (this);
996 }
997 
998 void
1000 {
1001  NS_LOG_FUNCTION (this);
1003 }
1004 
1005 void
1007 {
1008  NS_LOG_FUNCTION (this);
1010 }
1011 
1012 void
1014 {
1015  NS_LOG_FUNCTION (this);
1017 }
1018 
1019 void
1021 {
1022  NS_LOG_FUNCTION (this);
1024 }
1025 
1026 void
1028 {
1029  NS_LOG_FUNCTION (this);
1031 }
1032 
1033 void
1035 {
1036  NS_LOG_FUNCTION (this);
1038 }
1039 
1040 void
1042 {
1043  NS_LOG_LOGIC (this << " state: " << m_trxState << " -> " << newState);
1044  m_trxStateLogger (Simulator::Now (), m_trxState, newState);
1045  m_trxState = newState;
1046 }
1047 
1048 bool
1050 {
1051  NS_LOG_FUNCTION (this << m_trxState);
1055 }
1056 
1057 void
1059 {
1060  NS_LOG_FUNCTION (this);
1062 
1063  if (!m_edRequest.IsExpired ())
1064  {
1065  m_edRequest.Cancel ();
1067  {
1068  m_plmeEdConfirmCallback (state, 0);
1069  }
1070  }
1071 }
1072 
1073 void
1075 {
1076  NS_LOG_FUNCTION (this);
1077 
1079 
1080  uint8_t energyLevel;
1081 
1082  // Per IEEE802.15.4-2006 sec 6.9.7
1083  double ratio = m_edPower.averagePower / m_rxSensitivity;
1084  ratio = 10.0 * log10 (ratio);
1085  if (ratio <= 10.0)
1086  { // less than 10 dB
1087  energyLevel = 0;
1088  }
1089  else if (ratio >= 40.0)
1090  { // less than 40 dB
1091  energyLevel = 255;
1092  }
1093  else
1094  {
1095  // in-between with linear increase per sec 6.9.7
1096  energyLevel = static_cast<uint8_t> (((ratio - 10.0) / 30.0) * 255.0);
1097  }
1098 
1100  {
1102  }
1103 }
1104 
1105 void
1107 {
1108  NS_LOG_FUNCTION (this);
1110 
1111  // Update peak power.
1113  if (m_ccaPeakPower < power)
1114  {
1115  m_ccaPeakPower = power;
1116  }
1117 
1118  if (PhyIsBusy ())
1119  {
1120  sensedChannelState = IEEE_802_15_4_PHY_BUSY;
1121  }
1122  else if (m_phyPIBAttributes.phyCCAMode == 1)
1123  { //sec 6.9.9 ED detection
1124  // -- ED threshold at most 10 dB above receiver sensitivity.
1125  if (10 * log10 (m_ccaPeakPower / m_rxSensitivity) >= 10.0)
1126  {
1127  sensedChannelState = IEEE_802_15_4_PHY_BUSY;
1128  }
1129  else
1130  {
1131  sensedChannelState = IEEE_802_15_4_PHY_IDLE;
1132  }
1133  }
1134  else if (m_phyPIBAttributes.phyCCAMode == 2)
1135  {
1136  //sec 6.9.9 carrier sense only
1138  {
1139  // We currently do not model PPDU reception in detail. Instead we model
1140  // packet reception starting with the first bit of the preamble.
1141  // Therefore, this code will never be reached, as PhyIsBusy() would
1142  // already lead to a channel busy condition.
1143  // TODO: Change this, if we also model preamble and SFD detection.
1144  sensedChannelState = IEEE_802_15_4_PHY_BUSY;
1145  }
1146  else
1147  {
1148  sensedChannelState = IEEE_802_15_4_PHY_IDLE;
1149  }
1150  }
1151  else if (m_phyPIBAttributes.phyCCAMode == 3)
1152  { //sect 6.9.9 both
1153  if ((10 * log10 (m_ccaPeakPower / m_rxSensitivity) >= 10.0)
1155  {
1156  // Again, this code will never be reached, if we are already receiving
1157  // a packet, as PhyIsBusy() would already lead to a channel busy condition.
1158  // TODO: Change this, if we also model preamble and SFD detection.
1159  sensedChannelState = IEEE_802_15_4_PHY_BUSY;
1160  }
1161  else
1162  {
1163  sensedChannelState = IEEE_802_15_4_PHY_IDLE;
1164  }
1165  }
1166  else
1167  {
1168  NS_ASSERT_MSG (false, "Invalid CCA mode");
1169  }
1170 
1171  NS_LOG_LOGIC (this << "channel sensed state: " << sensedChannelState);
1172 
1174  {
1175  m_plmeCcaConfirmCallback (sensedChannelState);
1176  }
1177 }
1178 
1179 void
1181 {
1182  NS_LOG_FUNCTION (this);
1183 
1187 
1189  {
1191  }
1192 }
1193 
1194 void
1196 {
1197  NS_LOG_FUNCTION (this);
1198 
1200 
1201  if (m_currentTxPacket.second == false)
1202  {
1203  NS_LOG_DEBUG ("Packet successfully transmitted");
1206  {
1208  }
1209  }
1210  else
1211  {
1212  NS_LOG_DEBUG ("Packet transmission aborted");
1215  {
1216  // See if this is ever entered in another state
1219  }
1220  }
1221  m_currentTxPacket.first = 0;
1222  m_currentTxPacket.second = false;
1223 
1224 
1225  // We may be waiting to apply a pending state change.
1227  {
1228  // Only change the state immediately, if the transceiver is not already
1229  // switching the state.
1230  if (!m_setTRXState.IsRunning ())
1231  {
1232  NS_LOG_LOGIC ("Apply pending state change to " << m_trxStatePending);
1236  {
1238  }
1239  }
1240  }
1241  else
1242  {
1244  {
1246  }
1247  }
1248 }
1249 
1250 Time
1252 {
1253  NS_LOG_FUNCTION (this << packet);
1254 
1255  bool isData = true;
1256  Time txTime = GetPpduHeaderTxTime ();
1257 
1258  txTime += Seconds (packet->GetSize () * 8.0 / GetDataOrSymbolRate (isData));
1259 
1260  return txTime;
1261 }
1262 
1263 double
1265 {
1266  NS_LOG_FUNCTION (this << isData);
1267 
1268  double rate = 0.0;
1269 
1271 
1272  if (isData)
1273  {
1275  }
1276  else
1277  {
1279  }
1280 
1281  return (rate * 1000.0);
1282 }
1283 
1284 Time
1286 {
1287  NS_LOG_FUNCTION (this);
1288 
1289  bool isData = false;
1290  double totalPpduHdrSymbols;
1291 
1293 
1294  totalPpduHdrSymbols = ppduHeaderSymbolNumbers[m_phyOption].shrPreamble
1297 
1298  return Seconds (totalPpduHdrSymbols / GetDataOrSymbolRate (isData));
1299 }
1300 
1301 // IEEE802.15.4-2006 Table 2 in section 6.1.2
1302 void
1304 {
1305  NS_LOG_FUNCTION (this);
1306 
1308 
1310  {
1312  { // 868 MHz BPSK
1314  }
1315  else if (m_phyPIBAttributes.phyCurrentChannel <= 10)
1316  { // 915 MHz BPSK
1318  }
1319  else if (m_phyPIBAttributes.phyCurrentChannel <= 26)
1320  { // 2.4 GHz MHz O-QPSK
1322  }
1323  }
1324  else if (m_phyPIBAttributes.phyCurrentPage == 1)
1325  {
1327  { // 868 MHz ASK
1329  }
1330  else if (m_phyPIBAttributes.phyCurrentChannel <= 10)
1331  { // 915 MHz ASK
1333  }
1334  }
1335  else if (m_phyPIBAttributes.phyCurrentPage == 2)
1336  {
1338  { // 868 MHz O-QPSK
1340  }
1341  else if (m_phyPIBAttributes.phyCurrentChannel <= 10)
1342  { // 915 MHz O-QPSK
1344  }
1345  }
1346 }
1347 
1350 {
1351  NS_LOG_FUNCTION (this);
1352  return m_phyOption;
1353 }
1354 
1355 void
1357 {
1358  NS_LOG_FUNCTION (this << txPsd);
1359  NS_ASSERT (txPsd);
1360  m_txPsd = txPsd;
1361  NS_LOG_INFO ("\t computed tx_psd: " << *txPsd << "\t stored tx_psd: " << *m_txPsd);
1362 }
1363 
1364 void
1366 {
1367  NS_LOG_FUNCTION (this << noisePsd);
1368  NS_LOG_INFO ("\t computed noise_psd: " << *noisePsd );
1369  NS_ASSERT (noisePsd);
1370  m_noise = noisePsd;
1371 }
1372 
1375 {
1376  NS_LOG_FUNCTION (this);
1377  return m_noise;
1378 }
1379 
1380 void
1382 {
1383  NS_LOG_FUNCTION (this << e);
1384  NS_ASSERT (e);
1385  m_errorModel = e;
1386 }
1387 
1390 {
1391  NS_LOG_FUNCTION (this);
1392  return m_errorModel;
1393 }
1394 
1395 uint64_t
1397 {
1398  NS_LOG_FUNCTION (this);
1400 
1403 }
1404 
1405 double
1407 {
1408  NS_LOG_FUNCTION (this);
1410 
1412 }
1413 
1414 int64_t
1416 {
1417  NS_LOG_FUNCTION (this);
1418  m_random->SetStream (stream);
1419  return 1;
1420 }
1421 
1422 } // 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 this RNG stream.
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:633
Make LrWpanPhy a SpectrumPhy so we can enable the eventual modeling of device interference.
Definition: lr-wpan-phy.h:233
static const uint32_t aTurnaroundTime
The turnaround time for switching the transceiver from RX to TX or vice versa.
Definition: lr-wpan-phy.h:255
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
void SetPdDataConfirmCallback(PdDataConfirmCallback c)
set the callback for the end of a TX, as part of the interconnections betweenthe PHY and the MAC...
Definition: lr-wpan-phy.cc:999
LrWpanPhyOption GetMyPhyOption(void)
Get the currently configured PHY option.
Ptr< UniformRandomVariable > m_random
Uniform random variable stream.
Definition: lr-wpan-phy.h:831
PdDataConfirmCallback m_pdDataConfirmCallback
This callback is used to report packet transmission status to the MAC layer.
Definition: lr-wpan-phy.h:728
LrWpanPibAttributeIdentifier
IEEE802.15.4-2006 PHY PIB Attribute Identifiers Table 23 in section 6.4.2.
Definition: lr-wpan-phy.h:126
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:992
uint32_t phyCurrentPage
Current channel page.
Definition: lr-wpan-phy.h:149
void SetPlmeCcaConfirmCallback(PlmeCcaConfirmCallback c)
set the callback for the end of a CCA, as part of the interconnections betweenthe PHY and the MAC...
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:1078
#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:740
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
void SetDevice(Ptr< NetDevice > d)
set the associated NetDevice instance
Definition: lr-wpan-phy.cc:213
void SetPlmeEdConfirmCallback(PlmeEdConfirmCallback c)
set the callback for the end of an ED, as part of the interconnections betweenthe PHY and the MAC...
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:766
LrWpanEdPower m_edPower
Helper value for tracking the average power during ED.
Definition: lr-wpan-phy.h:768
Time measurementLength
Total measuremement period.
Definition: lr-wpan-phy.h:53
LrWpanPhyEnumeration m_trxState
The current transceiver state.
Definition: lr-wpan-phy.h:709
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:339
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:244
#define NS_FATAL_ERROR(msg)
Fatal error handling.
Definition: fatal-error.h:100
void ChangeTrxState(LrWpanPhyEnumeration newState)
Change the PHY state to the given new state, firing the state change trace.
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:65
bool PhyIsBusy(void) const
Check if the PHY is busy, which is the case if the PHY is currently sending or receiving a frame...
PacketAndStatus m_currentTxPacket
Statusinformation of the currently transmitted packet.
Definition: lr-wpan-phy.h:806
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:641
uint8_t phyCCAMode
CCA mode.
Definition: lr-wpan-phy.h:148
PlmeGetAttributeConfirmCallback m_plmeGetAttributeConfirmCallback
This callback is used to report requested attribute values back to the MAC.
Definition: lr-wpan-phy.h:746
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:688
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
Definition: simulator.h:819
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:656
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:143
static const LrWpanPhyPpduHeaderSymbolNumber ppduHeaderSymbolNumbers[7]
The preamble, SFD, and PHR lengths in symbols for the different PHY options.
Definition: lr-wpan-phy.h:495
double m_rxSensitivity
The receiver sensitivity.
Definition: lr-wpan-phy.h:778
millisecond
Definition: nstime.h:115
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:663
PlmeSetTRXStateConfirmCallback m_plmeSetTRXStateConfirmCallback
This callback is used to report transceiver state change status to the MAC.
Definition: lr-wpan-phy.h:752
Ptr< NetDevice > GetDevice(void)
get the associated NetDevice instance
Definition: lr-wpan-phy.cc:197
uint8_t Get(void) const
Get the LQI value.
static const uint32_t aMaxPhyPacketSize
The maximum packet size accepted by the PHY.
Definition: lr-wpan-phy.h:248
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:678
void SetChannel(Ptr< SpectrumChannel > c)
Set the channel attached to this device.
Definition: lr-wpan-phy.cc:229
Time lastUpdate
Last update time.
Definition: lr-wpan-phy.h:52
static const LrWpanPhyDataAndSymbolRates dataSymbolRates[7]
The data and symbol rates for the different PHY options.
Definition: lr-wpan-phy.h:490
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
Definition: packet.cc:858
uint32_t phyChannelsSupported[32]
BitField representing the available channels supported by a channel page.
Definition: lr-wpan-phy.h:146
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:715
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:773
Ptr< LrWpanErrorModel > GetErrorModel(void) const
get the error model in use
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:785
void SetMyPhyOption(void)
Configure the PHY option according to the current channel and channel page.
virtual Ptr< const SpectrumModel > GetRxSpectrumModel(void) const
Definition: lr-wpan-phy.cc:245
Ptr< AntennaModel > m_antenna
The antenna used by the transceiver.
Definition: lr-wpan-phy.h:683
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:790
uint8_t phyTransmitPower
Transmit power.
Definition: lr-wpan-phy.h:147
Ptr< const SpectrumModel > GetSpectrumModel() const
void SetAntenna(Ptr< AntennaModel > a)
Set the attached antenna.
Definition: lr-wpan-phy.cc:266
Ptr< const SpectrumValue > m_noise
The spectral density for for the noise.
Definition: lr-wpan-phy.h:693
EventId m_setTRXState
Scheduler event of a currently running deferred transceiver state switch.
Definition: lr-wpan-phy.h:821
bool ReplacePacketTag(Tag &tag)
Replace the value of a packet tag.
Definition: packet.cc:850
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:76
Ptr< NetDevice > m_device
The configured net device.
Definition: lr-wpan-phy.h:673
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:647
LrWpanPhy(void)
Default constructor.
Definition: lr-wpan-phy.cc:119
Ptr< SpectrumChannel > GetChannel(void)
Get the currently attached channel.
Definition: lr-wpan-phy.cc:237
Ptr< MobilityModel > GetMobility(void)
get the associated MobilityModel instance
Definition: lr-wpan-phy.cc:205
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:252
EventId m_edRequest
Scheduler event of a currently running ED request.
Definition: lr-wpan-phy.h:816
std::pair< Ptr< LrWpanSpectrumSignalParameters >, bool > m_currentRxPacket
Statusinformation of the currently received packet.
Definition: lr-wpan-phy.h:798
Ptr< MobilityModel > m_mobility
The mobility model used by the PHY.
Definition: lr-wpan-phy.h:668
LrWpanPhyOption m_phyOption
The currently configured PHY type.
Definition: lr-wpan-phy.h:763
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:682
bool ChannelSupported(uint8_t channel)
Check if the given channel is supported by the PHY.
Definition: lr-wpan-phy.cc:870
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:221
PdDataIndicationCallback m_pdDataIndicationCallback
This callback is used to notify incoming packets to the MAC layer.
Definition: lr-wpan-phy.h:722
double GetValue(double min, double max)
Returns a random double from the uniform distribution with the specified range.
double symbolRate
symbol rate
Definition: lr-wpan-phy.h:65
double averagePower
Average measured power.
Definition: lr-wpan-phy.h:51
int64_t GetTimeStep(void) const
Definition: nstime.h:364
PlmeSetAttributeConfirmCallback m_plmeSetAttributeConfirmCallback
This callback is used to report attribute set results back to the MAC.
Definition: lr-wpan-phy.h:758
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:625
Ptr< AntennaModel > GetRxAntenna(void)
get the AntennaModel used by the NetDevice for reception
Definition: lr-wpan-phy.cc:259
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:617
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:223
void EndTx(void)
Finish the transmission of a frame.
EventId m_ccaRequest
Scheduler event of a currently running CCA request.
Definition: lr-wpan-phy.h:811
void CheckInterference(void)
Check if the interference destroys a frame currently received.
Definition: lr-wpan-phy.cc:393
#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:90
double GetPhySymbolsPerOctet(void) const
Get the number of symbols per octet, depending on the currently selected channel. ...
virtual ~LrWpanPhy(void)
Definition: lr-wpan-phy.cc:164
#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:826
PlmeCcaConfirmCallback m_plmeCcaConfirmCallback
This callback is used to report CCA status to the MAC or CSMA/CA.
Definition: lr-wpan-phy.h:734
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...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:228
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:703
virtual void StartRx(Ptr< SpectrumSignalParameters > params)
Notify the SpectrumPhy instance of an incoming waveform.
Definition: lr-wpan-phy.cc:273
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
Definition: packet.cc:843
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:236
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:866
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:649
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:888
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:519
double phr
Number of symbols for the PHR.
Definition: lr-wpan-phy.h:78
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:145
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:104
A base class which provides memory management and object aggregation.
Definition: object.h:87
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:593
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:620
void CancelEd(LrWpanPhyEnumeration state)
Cancel an ongoing ED procedure.
virtual void DoDispose(void)
Destructor implementation.
Definition: lr-wpan-phy.cc:169
LrWpanPhyOption
This Phy option will be used to index various Tables in IEEE802.15.4-2006.
Definition: lr-wpan-phy.h:86
uint64_t GetPhySHRDuration(void) const
Get the duration of the SHR (preamble and SFD) in symbols, depending on the currently selected channe...
double shrSfd
Number of symbols for the SHR SFD.
Definition: lr-wpan-phy.h:77
This class can be used to hold variables of floating point type such as 'double' or 'float'...
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:190
bool IsExpired(void) const
This method is syntactic sugar for the ns3::Simulator::IsExpired method.
Definition: event-id.cc:59
Ptr< LrWpanErrorModel > m_errorModel
The error model describing the bit and packet error rates.
Definition: lr-wpan-phy.h:698
a unique identifier for an interface.
Definition: type-id.h:57
TypeId SetParent(TypeId tid)
Definition: type-id.cc:638
void EndRx(Ptr< SpectrumSignalParameters > params)
Finish the reception of a frame.
Definition: lr-wpan-phy.cc:439