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