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  .AddConstructor<LrWpanPhy> ()
79  .AddTraceSource ("TrxState",
80  "The state of the transceiver",
82  "ns3::LrWpanPhy::StateTracedCallback")
83  .AddTraceSource ("PhyTxBegin",
84  "Trace source indicating a packet has "
85  "begun transmitting over the channel medium",
87  "ns3::Packet::TracedCallback")
88  .AddTraceSource ("PhyTxEnd",
89  "Trace source indicating a packet has been "
90  "completely transmitted over the channel.",
92  "ns3::Packet::TracedCallback")
93  .AddTraceSource ("PhyTxDrop",
94  "Trace source indicating a packet has been "
95  "dropped by the device during transmission",
97  "ns3::Packet::TracedCallback")
98  .AddTraceSource ("PhyRxBegin",
99  "Trace source indicating a packet has begun "
100  "being received from the channel medium by the device",
102  "ns3::Packet::TracedCallback")
103  .AddTraceSource ("PhyRxEnd",
104  "Trace source indicating a packet has been "
105  "completely received from the channel medium "
106  "by the device",
108  "ns3::LrWpanPhy::RxEndTracedCallback")
109  .AddTraceSource ("PhyRxDrop",
110  "Trace source indicating a packet has been "
111  "dropped by the device during reception",
113  "ns3::Packet::TracedCallback")
114  ;
115  return tid;
116 }
117 
119  : m_edRequest (),
120  m_setTRXState ()
121 {
124 
125  // default PHY PIB attributes
129  for (uint32_t i = 0; i < 32; i++)
130  {
132  }
134 
135  SetMyPhyOption ();
136 
137  m_edPower.averagePower = 0.0;
138  m_edPower.lastUpdate = Seconds (0.0);
140 
141  // default -110 dBm in W for 2.4 GHz
142  m_rxSensitivity = pow (10.0, -106.58 / 10.0) / 1000.0;
143  LrWpanSpectrumValueHelper psdHelper;
147  m_signal = Create<LrWpanInterferenceHelper> (m_noise->GetSpectrumModel ());
148  m_rxLastUpdate = Seconds (0);
149  Ptr<Packet> none_packet = 0;
150  Ptr<LrWpanSpectrumSignalParameters> none_params = 0;
151  m_currentRxPacket = std::make_pair (none_params, true);
152  m_currentTxPacket = std::make_pair (none_packet, true);
153  m_errorModel = 0;
154 
155  m_random = CreateObject<UniformRandomVariable> ();
156  m_random->SetAttribute ("Min", DoubleValue (0.0));
157  m_random->SetAttribute ("Max", DoubleValue (1.0));
158 
159 
161 }
162 
164 {
165 }
166 
167 void
169 {
170  NS_LOG_FUNCTION (this);
171 
172  // Cancel pending transceiver state change, if one is in progress.
176 
177  m_mobility = 0;
178  m_device = 0;
179  m_channel = 0;
180  m_txPsd = 0;
181  m_noise = 0;
182  m_signal = 0;
183  m_errorModel = 0;
184  m_pdDataIndicationCallback = MakeNullCallback< void, uint32_t, Ptr<Packet>, uint8_t > ();
185  m_pdDataConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration > ();
186  m_plmeCcaConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration > ();
187  m_plmeEdConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration,uint8_t > ();
188  m_plmeGetAttributeConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration, LrWpanPibAttributeIdentifier, LrWpanPhyPibAttributes* > ();
189  m_plmeSetTRXStateConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration > ();
190  m_plmeSetAttributeConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration, LrWpanPibAttributeIdentifier > ();
191 
193 }
194 
197 {
198  NS_LOG_FUNCTION (this);
199  return m_device;
200 }
201 
202 
205 {
206  NS_LOG_FUNCTION (this);
207  return m_mobility;
208 }
209 
210 
211 void
213 {
214  NS_LOG_FUNCTION (this << d);
215  m_device = d;
216 }
217 
218 
219 void
221 {
222  NS_LOG_FUNCTION (this << m);
223  m_mobility = m;
224 }
225 
226 
227 void
229 {
230  NS_LOG_FUNCTION (this << c);
231  m_channel = c;
232 }
233 
234 
237 {
238  NS_LOG_FUNCTION (this);
239  return m_channel;
240 }
241 
242 
245 {
246  NS_LOG_FUNCTION (this);
247  if (m_txPsd)
248  {
249  return m_txPsd->GetSpectrumModel ();
250  }
251  else
252  {
253  return 0;
254  }
255 }
256 
259 {
260  NS_LOG_FUNCTION (this);
261  return m_antenna;
262 }
263 
264 void
266 {
267  NS_LOG_FUNCTION (this << a);
268  m_antenna = a;
269 }
270 
271 void
273 {
274  NS_LOG_FUNCTION (this << spectrumRxParams);
275  LrWpanSpectrumValueHelper psdHelper;
276 
277  if (!m_edRequest.IsExpired ())
278  {
279  // Update the average receive power during ED.
280  Time now = Simulator::Now ();
282  m_edPower.lastUpdate = now;
283  }
284 
285  Ptr<LrWpanSpectrumSignalParameters> lrWpanRxParams = DynamicCast<LrWpanSpectrumSignalParameters> (spectrumRxParams);
286 
287  if ( lrWpanRxParams == 0)
288  {
290  m_signal->AddSignal (spectrumRxParams->psd);
291 
292  // Update peak power if CCA is in progress.
293  if (!m_ccaRequest.IsExpired ())
294  {
296  if (m_ccaPeakPower < power)
297  {
298  m_ccaPeakPower = power;
299  }
300  }
301 
302  Simulator::Schedule (spectrumRxParams->duration, &LrWpanPhy::EndRx, this, spectrumRxParams);
303  return;
304  }
305 
306  Ptr<Packet> p = (lrWpanRxParams->packetBurst->GetPackets ()).front ();
307  NS_ASSERT (p != 0);
308 
309  // Prevent PHY from receiving another packet while switching the transceiver state.
311  {
312  // The specification doesn't seem to refer to BUSY_RX, but vendor
313  // data sheets suggest that this is a substate of the RX_ON state
314  // that is entered after preamble detection when the digital receiver
315  // is enabled. Here, for now, we use BUSY_RX to mark the period between
316  // StartRx() and EndRx() states.
317 
318  // We are going to BUSY_RX state when receiving the first bit of an SHR,
319  // as opposed to real receivers, which should go to this state only after
320  // successfully receiving the SHR.
321 
322  // If synchronizing to the packet is possible, change to BUSY_RX state,
323  // otherwise drop the packet and stay in RX state. The actual synchronization
324  // is not modeled.
325 
326  // Add any incoming packet to the current interference before checking the
327  // SINR.
328  NS_LOG_DEBUG (this << " receiving packet with power: " << 10 * log10(LrWpanSpectrumValueHelper::TotalAvgPower (lrWpanRxParams->psd, m_phyPIBAttributes.phyCurrentChannel)) + 30 << "dBm");
329  m_signal->AddSignal (lrWpanRxParams->psd);
330  Ptr<SpectrumValue> interferenceAndNoise = m_signal->GetSignalPsd ();
331  *interferenceAndNoise -= *lrWpanRxParams->psd;
332  *interferenceAndNoise += *m_noise;
334 
335  // Std. 802.15.4-2006, appendix E, Figure E.2
336  // At SNR < -5 the BER is less than 10e-1.
337  // It's useless to even *try* to decode the packet.
338  if (10 * log10 (sinr) > -5)
339  {
341  m_currentRxPacket = std::make_pair (lrWpanRxParams, false);
342  m_phyRxBeginTrace (p);
343 
345  }
346  else
347  {
348  m_phyRxDropTrace (p);
349  }
350  }
352  {
353  // Drop the new packet.
354  NS_LOG_DEBUG (this << " packet collision");
355  m_phyRxDropTrace (p);
356 
357  // Check if we correctly received the old packet up to now.
359 
360  // Add the incoming packet to the current interference after we have
361  // checked for successfull reception of the current packet for the time
362  // before the additional interference.
363  m_signal->AddSignal (lrWpanRxParams->psd);
364  }
365  else
366  {
367  // Simply drop the packet.
368  NS_LOG_DEBUG (this << " transceiver not in RX state");
369  m_phyRxDropTrace (p);
370 
371  // Add the signal power to the interference, anyway.
372  m_signal->AddSignal (lrWpanRxParams->psd);
373  }
374 
375  // Update peak power if CCA is in progress.
376  if (!m_ccaRequest.IsExpired ())
377  {
379  if (m_ccaPeakPower < power)
380  {
381  m_ccaPeakPower = power;
382  }
383  }
384 
385  // Always call EndRx to update the interference.
386  // \todo: Do we need to keep track of these events to unschedule them when disposing off the PHY?
387 
388  Simulator::Schedule (spectrumRxParams->duration, &LrWpanPhy::EndRx, this, spectrumRxParams);
389 }
390 
391 void
393 {
394  // Calculate whether packet was lost.
395  LrWpanSpectrumValueHelper psdHelper;
397 
398  // We are currently receiving a packet.
400  {
401  // NS_ASSERT (currentRxParams && !m_currentRxPacket.second);
402 
403  Ptr<Packet> currentPacket = currentRxParams->packetBurst->GetPackets ().front ();
404  if (m_errorModel != 0)
405  {
406  // How many bits did we receive since the last calculation?
407  double t = (Simulator::Now () - m_rxLastUpdate).ToDouble (Time::MS);
408  uint32_t chunkSize = ceil (t * (GetDataOrSymbolRate (true) / 1000));
409  Ptr<SpectrumValue> interferenceAndNoise = m_signal->GetSignalPsd ();
410  *interferenceAndNoise -= *currentRxParams->psd;
411  *interferenceAndNoise += *m_noise;
413  double per = 1.0 - m_errorModel->GetChunkSuccessRate (sinr, chunkSize);
414 
415  // The LQI is the total packet success rate scaled to 0-255.
416  // If not already set, initialize to 255.
417  LrWpanLqiTag tag (std::numeric_limits<uint8_t>::max ());
418  currentPacket->PeekPacketTag (tag);
419  uint8_t lqi = tag.Get ();
420  tag.Set (lqi - (per * lqi));
421  currentPacket->ReplacePacketTag (tag);
422 
423  if (m_random->GetValue () < per)
424  {
425  // The packet was destroyed, drop the packet after reception.
426  m_currentRxPacket.second = true;
427  }
428  }
429  else
430  {
431  NS_LOG_WARN ("Missing ErrorModel");
432  }
433  }
435 }
436 
437 void
439 {
440  NS_LOG_FUNCTION (this);
441 
442  Ptr<LrWpanSpectrumSignalParameters> params = DynamicCast<LrWpanSpectrumSignalParameters> (par);
443 
444  if (!m_edRequest.IsExpired ())
445  {
446  // Update the average receive power during ED.
447  Time now = Simulator::Now ();
449  m_edPower.lastUpdate = now;
450  }
451 
453 
454  // Update the interference.
455  m_signal->RemoveSignal (par->psd);
456 
457  if (params == 0)
458  {
459  NS_LOG_LOGIC ("Node: " << m_device->GetAddress() << " Removing interferent: " << *(par->psd));
460  return;
461  }
462 
463  // If this is the end of the currently received packet, check if reception was successful.
465  if (currentRxParams == params)
466  {
467  Ptr<Packet> currentPacket = currentRxParams->packetBurst->GetPackets ().front ();
468  NS_ASSERT (currentPacket != 0);
469 
470  // If there is no error model attached to the PHY, we always report the maximum LQI value.
471  LrWpanLqiTag tag (std::numeric_limits<uint8_t>::max ());
472  currentPacket->PeekPacketTag (tag);
473  m_phyRxEndTrace (currentPacket, tag.Get ());
474 
475  if (!m_currentRxPacket.second)
476  {
477  // The packet was successfully received, push it up the stack.
479  {
480  m_pdDataIndicationCallback (currentPacket->GetSize (), currentPacket, tag.Get ());
481  }
482  }
483  else
484  {
485  // The packet was destroyed, drop it.
486  m_phyRxDropTrace (currentPacket);
487  }
489  m_currentRxPacket = std::make_pair (none, true);
490 
491  // We may be waiting to apply a pending state change.
493  {
494  // Only change the state immediately, if the transceiver is not already
495  // switching the state.
496  if (!m_setTRXState.IsRunning ())
497  {
498  NS_LOG_LOGIC ("Apply pending state change to " << m_trxStatePending);
502  {
504  }
505  }
506  }
507  else
508  {
510  }
511  }
512 }
513 
514 void
515 LrWpanPhy::PdDataRequest (const uint32_t psduLength, Ptr<Packet> p)
516 {
517  NS_LOG_FUNCTION (this << psduLength << p);
518 
519  if (psduLength > aMaxPhyPacketSize)
520  {
522  {
524  }
525  NS_LOG_DEBUG ("Drop packet because psduLength too long: " << psduLength);
526  return;
527  }
528 
529  // Prevent PHY from sending a packet while switching the transceiver state.
530  if (!m_setTRXState.IsRunning ())
531  {
533  {
534  //send down
536 
537  // Remove a possible LQI tag from a previous transmission of the packet.
538  LrWpanLqiTag lqiTag;
539  p->RemovePacketTag (lqiTag);
540 
541  Ptr<LrWpanSpectrumSignalParameters> txParams = Create<LrWpanSpectrumSignalParameters> ();
542  txParams->duration = CalculateTxTime (p);
543  txParams->txPhy = GetObject<SpectrumPhy> ();
544  txParams->psd = m_txPsd;
545  txParams->txAntenna = m_antenna;
546  Ptr<PacketBurst> pb = CreateObject<PacketBurst> ();
547  pb->AddPacket (p);
548  txParams->packetBurst = pb;
549  m_channel->StartTx (txParams);
550  m_pdDataRequest = Simulator::Schedule (txParams->duration, &LrWpanPhy::EndTx, this);
552  m_phyTxBeginTrace (p);
553  m_currentTxPacket.first = p;
554  m_currentTxPacket.second = false;
555  return;
556  }
557  else if ((m_trxState == IEEE_802_15_4_PHY_RX_ON)
560  {
562  {
564  }
565  // Drop packet, hit PhyTxDrop trace
566  m_phyTxDropTrace (p);
567  return;
568  }
569  else
570  {
571  NS_FATAL_ERROR ("This should be unreachable, or else state " << m_trxState << " should be added as a case");
572  }
573  }
574  else
575  {
576  // TODO: This error code is not covered by the standard.
577  // What is the correct behavior in this case?
579  {
581  }
582  // Drop packet, hit PhyTxDrop trace
583  m_phyTxDropTrace (p);
584  return;
585  }
586 }
587 
588 void
590 {
591  NS_LOG_FUNCTION (this);
592 
594  {
595  m_ccaPeakPower = 0.0;
596  Time ccaTime = Seconds (8.0 / GetDataOrSymbolRate (false));
598  }
599  else
600  {
602  {
604  {
606  }
607  else
608  {
610  }
611  }
612  }
613 }
614 
615 void
617 {
618  NS_LOG_FUNCTION (this);
620  {
621  // Average over the powers of all signals received until EndEd()
626  }
627  else
628  {
631  {
632  result = IEEE_802_15_4_PHY_TX_ON;
633  }
634 
636  {
637  m_plmeEdConfirmCallback (result, 0);
638  }
639  }
640 }
641 
642 void
644 {
645  NS_LOG_FUNCTION (this << id);
646  LrWpanPhyEnumeration status;
647 
648  switch (id)
649  {
650  case phyCurrentChannel:
652  case phyTransmitPower:
653  case phyCCAMode:
654  case phyCurrentPage:
655  case phyMaxFrameDuration:
656  case phySHRDuration:
657  case phySymbolsPerOctet:
658  {
659  status = IEEE_802_15_4_PHY_SUCCESS;
660  break;
661  }
662  default:
663  {
665  break;
666  }
667  }
669  {
670  LrWpanPhyPibAttributes retValue;
671  memcpy (&retValue, &m_phyPIBAttributes, sizeof(LrWpanPhyPibAttributes));
672  m_plmeGetAttributeConfirmCallback (status,id,&retValue);
673  }
674 }
675 
676 // Section 6.2.2.7.3
677 void
679 {
680  NS_LOG_FUNCTION (this << state);
681 
682  // Check valid states (Table 14)
684  && (state != IEEE_802_15_4_PHY_TRX_OFF)
685  && (state != IEEE_802_15_4_PHY_FORCE_TRX_OFF)
686  && (state != IEEE_802_15_4_PHY_TX_ON) );
687 
688  NS_LOG_LOGIC ("Trying to set m_trxState from " << m_trxState << " to " << state);
689  // this method always overrides previous state setting attempts
690  if (!m_setTRXState.IsExpired ())
691  {
692  if (m_trxStatePending == state)
693  {
694  // Simply wait for the ongoing state switch.
695  return;
696  }
697  else
698  {
699  NS_LOG_DEBUG ("Cancel m_setTRXState");
700  // Keep the transceiver state as the old state before the switching attempt.
702  }
703  }
705  {
707  }
708 
709  if (state == m_trxState)
710  {
712  {
714  }
715  return;
716  }
717 
718  if ( ((state == IEEE_802_15_4_PHY_RX_ON)
719  || (state == IEEE_802_15_4_PHY_TRX_OFF))
721  {
722  NS_LOG_DEBUG ("Phy is busy; setting state pending to " << state);
723  m_trxStatePending = state;
724  return; // Send PlmeSetTRXStateConfirm later
725  }
726 
727  // specification talks about being in RX_ON and having received
728  // a valid SFD. Here, we are not modelling at that level of
729  // granularity, so we just test for BUSY_RX state (any part of
730  // a packet being actively received)
731  if (state == IEEE_802_15_4_PHY_TRX_OFF)
732  {
733  CancelEd (state);
734 
736  && (m_currentRxPacket.first) && (!m_currentRxPacket.second))
737  {
738  NS_LOG_DEBUG ("Receiver has valid SFD; defer state change");
739  m_trxStatePending = state;
740  return; // Send PlmeSetTRXStateConfirm later
741  }
743  {
746  {
748  }
749  return;
750  }
751  }
752 
753  if (state == IEEE_802_15_4_PHY_TX_ON)
754  {
755  CancelEd (state);
756 
757  NS_LOG_DEBUG ("turn on PHY_TX_ON");
759  {
760  if (m_currentRxPacket.first)
761  {
762  //terminate reception if needed
763  //incomplete reception -- force packet discard
764  NS_LOG_DEBUG ("force TX_ON, terminate reception");
765  m_currentRxPacket.second = true;
766  }
767 
768  // If CCA is in progress, cancel CCA and return BUSY.
769  if (!m_ccaRequest.IsExpired ())
770  {
771  m_ccaRequest.Cancel ();
773  {
775  }
776  }
777 
779 
780  // Delay for turnaround time
781  // TODO: Does it also take aTurnaroundTime to switch the transceiver state,
782  // even when the receiver is not busy? (6.9.2)
783  Time setTime = Seconds ( (double) aTurnaroundTime / GetDataOrSymbolRate (false));
785  return;
786  }
788  {
789  // We do NOT change the transceiver state here. We only report that
790  // the transceiver is already in TX_ON state.
792  {
794  }
795  return;
796  }
798  {
801  {
803  }
804  return;
805  }
806  }
807 
808  if (state == IEEE_802_15_4_PHY_FORCE_TRX_OFF)
809  {
811  {
812  NS_LOG_DEBUG ("force TRX_OFF, was already off");
813  }
814  else
815  {
816  NS_LOG_DEBUG ("force TRX_OFF, SUCCESS");
817  if (m_currentRxPacket.first)
818  { //terminate reception if needed
819  //incomplete reception -- force packet discard
820  NS_LOG_DEBUG ("force TRX_OFF, terminate reception");
821  m_currentRxPacket.second = true;
822  }
824  {
825  NS_LOG_DEBUG ("force TRX_OFF, terminate transmission");
826  m_currentTxPacket.second = true;
827  }
829  // Clear any other state
831  }
833  {
835  }
836  return;
837  }
838 
839  if (state == IEEE_802_15_4_PHY_RX_ON)
840  {
842  {
843  // Turnaround delay
844  // TODO: Does it really take aTurnaroundTime to switch the transceiver state,
845  // even when the transmitter is not busy? (6.9.1)
847 
848  Time setTime = Seconds ( (double) aTurnaroundTime / GetDataOrSymbolRate (false));
850  return;
851  }
853  {
855  {
857  }
858  return;
859  }
860  }
861 
862  NS_FATAL_ERROR ("Unexpected transition from state " << m_trxState << " to state " << state);
863 }
864 
865 bool
867 {
868  NS_LOG_FUNCTION (this << channel);
869  bool retValue = false;
870 
871  for (uint32_t i = 0; i < 32; i++)
872  {
873  if ((m_phyPIBAttributes.phyChannelsSupported[i] & (1 << channel)) != 0)
874  {
875  retValue = true;
876  break;
877  }
878  }
879 
880  return retValue;
881 }
882 
883 void
885  LrWpanPhyPibAttributes* attribute)
886 {
887  NS_LOG_FUNCTION (this << id << attribute);
888  NS_ASSERT (attribute);
890 
891  switch (id)
892  {
893  case phyCurrentChannel:
894  {
895  if (!ChannelSupported (attribute->phyCurrentChannel))
896  {
898  }
900  {
901  // Cancel a pending tranceiver state change.
902  // Switch off the transceiver.
903  // TODO: Is switching off the transceiver the right choice?
906  {
910  {
912  }
913  }
914 
915  // Any packet in transmission or reception will be corrupted.
916  if (m_currentRxPacket.first)
917  {
918  m_currentRxPacket.second = true;
919  }
920  if (PhyIsBusy ())
921  {
922  m_currentTxPacket.second = true;
924  m_currentTxPacket.first = 0;
926  {
928  }
929  }
931  }
932  break;
933  }
935  { // only the first element is considered in the array
936  if ((attribute->phyChannelsSupported[0] & 0xf8000000) != 0)
937  { //5 MSBs reserved
939  }
940  else
941  {
943  }
944  break;
945  }
946  case phyTransmitPower:
947  {
948  if (attribute->phyTransmitPower > 0xbf)
949  {
951  }
952  else
953  {
955  LrWpanSpectrumValueHelper psdHelper;
957  }
958  break;
959  }
960  case phyCCAMode:
961  {
962  if ((attribute->phyCCAMode < 1) || (attribute->phyCCAMode > 3))
963  {
965  }
966  else
967  {
969  }
970  break;
971  }
972  default:
973  {
975  break;
976  }
977  }
978 
980  {
982  }
983 }
984 
985 void
987 {
988  NS_LOG_FUNCTION (this);
990 }
991 
992 void
994 {
995  NS_LOG_FUNCTION (this);
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_LOGIC (this << " state: " << m_trxState << " -> " << newState);
1038  m_trxStateLogger (Simulator::Now (), m_trxState, newState);
1039  m_trxState = newState;
1040 }
1041 
1042 bool
1044 {
1045  NS_LOG_FUNCTION (this << m_trxState);
1049 }
1050 
1051 void
1053 {
1054  NS_LOG_FUNCTION (this);
1056 
1057  if (!m_edRequest.IsExpired ())
1058  {
1059  m_edRequest.Cancel ();
1061  {
1062  m_plmeEdConfirmCallback (state, 0);
1063  }
1064  }
1065 }
1066 
1067 void
1069 {
1070  NS_LOG_FUNCTION (this);
1071 
1073 
1074  uint8_t energyLevel;
1075 
1076  // Per IEEE802.15.4-2006 sec 6.9.7
1077  double ratio = m_edPower.averagePower / m_rxSensitivity;
1078  ratio = 10.0 * log10 (ratio);
1079  if (ratio <= 10.0)
1080  { // less than 10 dB
1081  energyLevel = 0;
1082  }
1083  else if (ratio >= 40.0)
1084  { // less than 40 dB
1085  energyLevel = 255;
1086  }
1087  else
1088  {
1089  // in-between with linear increase per sec 6.9.7
1090  energyLevel = static_cast<uint8_t> (((ratio - 10.0) / 30.0) * 255.0);
1091  }
1092 
1094  {
1096  }
1097 }
1098 
1099 void
1101 {
1102  NS_LOG_FUNCTION (this);
1104 
1105  // Update peak power.
1107  if (m_ccaPeakPower < power)
1108  {
1109  m_ccaPeakPower = power;
1110  }
1111 
1112  if (PhyIsBusy ())
1113  {
1114  sensedChannelState = IEEE_802_15_4_PHY_BUSY;
1115  }
1116  else if (m_phyPIBAttributes.phyCCAMode == 1)
1117  { //sec 6.9.9 ED detection
1118  // -- ED threshold at most 10 dB above receiver sensitivity.
1119  if (10 * log10 (m_ccaPeakPower / m_rxSensitivity) >= 10.0)
1120  {
1121  sensedChannelState = IEEE_802_15_4_PHY_BUSY;
1122  }
1123  else
1124  {
1125  sensedChannelState = IEEE_802_15_4_PHY_IDLE;
1126  }
1127  }
1128  else if (m_phyPIBAttributes.phyCCAMode == 2)
1129  {
1130  //sec 6.9.9 carrier sense only
1132  {
1133  // We currently do not model PPDU reception in detail. Instead we model
1134  // packet reception starting with the first bit of the preamble.
1135  // Therefore, this code will never be reached, as PhyIsBusy() would
1136  // already lead to a channel busy condition.
1137  // TODO: Change this, if we also model preamble and SFD detection.
1138  sensedChannelState = IEEE_802_15_4_PHY_BUSY;
1139  }
1140  else
1141  {
1142  sensedChannelState = IEEE_802_15_4_PHY_IDLE;
1143  }
1144  }
1145  else if (m_phyPIBAttributes.phyCCAMode == 3)
1146  { //sect 6.9.9 both
1147  if ((10 * log10 (m_ccaPeakPower / m_rxSensitivity) >= 10.0)
1149  {
1150  // Again, this code will never be reached, if we are already receiving
1151  // a packet, as PhyIsBusy() would already lead to a channel busy condition.
1152  // TODO: Change this, if we also model preamble and SFD detection.
1153  sensedChannelState = IEEE_802_15_4_PHY_BUSY;
1154  }
1155  else
1156  {
1157  sensedChannelState = IEEE_802_15_4_PHY_IDLE;
1158  }
1159  }
1160  else
1161  {
1162  NS_ASSERT_MSG (false, "Invalid CCA mode");
1163  }
1164 
1165  NS_LOG_LOGIC (this << "channel sensed state: " << sensedChannelState);
1166 
1168  {
1169  m_plmeCcaConfirmCallback (sensedChannelState);
1170  }
1171 }
1172 
1173 void
1175 {
1176  NS_LOG_FUNCTION (this);
1177 
1181 
1183  {
1185  }
1186 }
1187 
1188 void
1190 {
1191  NS_LOG_FUNCTION (this);
1192 
1194 
1195  if (m_currentTxPacket.second == false)
1196  {
1197  NS_LOG_DEBUG ("Packet successfully transmitted");
1200  {
1202  }
1203  }
1204  else
1205  {
1206  NS_LOG_DEBUG ("Packet transmission aborted");
1209  {
1210  // See if this is ever entered in another state
1213  }
1214  }
1215  m_currentTxPacket.first = 0;
1216  m_currentTxPacket.second = false;
1217 
1218 
1219  // We may be waiting to apply a pending state change.
1221  {
1222  // Only change the state immediately, if the transceiver is not already
1223  // switching the state.
1224  if (!m_setTRXState.IsRunning ())
1225  {
1226  NS_LOG_LOGIC ("Apply pending state change to " << m_trxStatePending);
1230  {
1232  }
1233  }
1234  }
1235  else
1236  {
1238  {
1240  }
1241  }
1242 }
1243 
1244 Time
1246 {
1247  NS_LOG_FUNCTION (this << packet);
1248 
1249  bool isData = true;
1250  Time txTime = GetPpduHeaderTxTime ();
1251 
1252  txTime += Seconds (packet->GetSize () * 8.0 / GetDataOrSymbolRate (isData));
1253 
1254  return txTime;
1255 }
1256 
1257 double
1259 {
1260  NS_LOG_FUNCTION (this << isData);
1261 
1262  double rate = 0.0;
1263 
1265 
1266  if (isData)
1267  {
1269  }
1270  else
1271  {
1273  }
1274 
1275  return (rate * 1000.0);
1276 }
1277 
1278 Time
1280 {
1281  NS_LOG_FUNCTION (this);
1282 
1283  bool isData = false;
1284  double totalPpduHdrSymbols;
1285 
1287 
1288  totalPpduHdrSymbols = ppduHeaderSymbolNumbers[m_phyOption].shrPreamble
1291 
1292  return Seconds (totalPpduHdrSymbols / GetDataOrSymbolRate (isData));
1293 }
1294 
1295 // IEEE802.15.4-2006 Table 2 in section 6.1.2
1296 void
1298 {
1299  NS_LOG_FUNCTION (this);
1300 
1302 
1304  {
1306  { // 868 MHz BPSK
1308  }
1309  else if (m_phyPIBAttributes.phyCurrentChannel <= 10)
1310  { // 915 MHz BPSK
1312  }
1313  else if (m_phyPIBAttributes.phyCurrentChannel <= 26)
1314  { // 2.4 GHz MHz O-QPSK
1316  }
1317  }
1318  else if (m_phyPIBAttributes.phyCurrentPage == 1)
1319  {
1321  { // 868 MHz ASK
1323  }
1324  else if (m_phyPIBAttributes.phyCurrentChannel <= 10)
1325  { // 915 MHz ASK
1327  }
1328  }
1329  else if (m_phyPIBAttributes.phyCurrentPage == 2)
1330  {
1332  { // 868 MHz O-QPSK
1334  }
1335  else if (m_phyPIBAttributes.phyCurrentChannel <= 10)
1336  { // 915 MHz O-QPSK
1338  }
1339  }
1340 }
1341 
1344 {
1345  NS_LOG_FUNCTION (this);
1346  return m_phyOption;
1347 }
1348 
1349 void
1351 {
1352  NS_LOG_FUNCTION (this << txPsd);
1353  NS_ASSERT (txPsd);
1354  m_txPsd = txPsd;
1355  NS_LOG_INFO ("\t computed tx_psd: " << *txPsd << "\t stored tx_psd: " << *m_txPsd);
1356 }
1357 
1358 void
1360 {
1361  NS_LOG_FUNCTION (this << noisePsd);
1362  NS_LOG_INFO ("\t computed noise_psd: " << *noisePsd );
1363  NS_ASSERT (noisePsd);
1364  m_noise = noisePsd;
1365 }
1366 
1369 {
1370  NS_LOG_FUNCTION (this);
1371  return m_noise;
1372 }
1373 
1374 void
1376 {
1377  NS_LOG_FUNCTION (this << e);
1378  NS_ASSERT (e);
1379  m_errorModel = e;
1380 }
1381 
1384 {
1385  NS_LOG_FUNCTION (this);
1386  return m_errorModel;
1387 }
1388 
1389 uint64_t
1391 {
1392  NS_LOG_FUNCTION (this);
1394 
1397 }
1398 
1399 double
1401 {
1402  NS_LOG_FUNCTION (this);
1404 
1406 }
1407 
1408 int64_t
1410 {
1411  NS_LOG_FUNCTION (this);
1412  m_random->SetStream (stream);
1413  return 1;
1414 }
1415 
1416 } // namespace ns3
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:95
#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
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:993
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:986
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:1072
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:61
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:212
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:338
#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:108
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:196
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:228
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:244
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:265
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:643
LrWpanPhy(void)
Default constructor.
Definition: lr-wpan-phy.cc:118
Ptr< SpectrumChannel > GetChannel(void)
Get the currently attached channel.
Definition: lr-wpan-phy.cc:236
Ptr< MobilityModel > GetMobility(void)
get the associated MobilityModel instance
Definition: lr-wpan-phy.cc:204
#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:678
bool ChannelSupported(uint8_t channel)
Check if the given channel is supported by the PHY.
Definition: lr-wpan-phy.cc:866
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:220
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:357
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:258
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:392
#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:84
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:163
#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:272
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:859
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:884
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:515
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:589
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:616
void CancelEd(LrWpanPhyEnumeration state)
Cancel an ongoing ED procedure.
virtual void DoDispose(void)
Destructor implementation.
Definition: lr-wpan-phy.cc:168
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:51
TypeId SetParent(TypeId tid)
Definition: type-id.cc:631
void EndRx(Ptr< SpectrumSignalParameters > params)
Finish the reception of a frame.
Definition: lr-wpan-phy.cc:438