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/node.h>
35#include <ns3/spectrum-channel.h>
36#include <ns3/packet.h>
37#include <ns3/packet-burst.h>
38#include <ns3/net-device.h>
39#include <ns3/random-variable-stream.h>
40#include <ns3/double.h>
41
42namespace ns3 {
43
44NS_LOG_COMPONENT_DEFINE ("LrWpanPhy");
45
47
48// Table 22 in section 6.4.1 of ieee802.15.4
49const uint32_t LrWpanPhy::aMaxPhyPacketSize = 127; // max PSDU in octets
50const uint32_t LrWpanPhy::aTurnaroundTime = 12; // RX-to-TX or TX-to-RX in symbol periods
51
52// IEEE802.15.4-2006 Table 1 in section 6.1.1. and IEEE 802.15.4c-2009, IEEE 802.15.4d-2009
53// The index follows LrWpanPhyOption (kb/s and ksymbol/s)
54const LrWpanPhyDataAndSymbolRates
56 { 20.0, 20.0},
57 { 40.0, 40.0},
58 { 20.0, 20.0},
59 { 250.0, 12.5},
60 { 250.0, 50.0},
61 { 250.0, 62.5},
62 { 100.0, 25.0},
63 { 250.0, 62.5},
64 { 250.0, 62.5}};
65// IEEE802.15.4-2006,IEEE 802.15.4c-2009, IEEE 802.15.4d-2009 Table 19 and Table 20 in section 6.3.
66// The PHR is 1 octet and it follows phySymbolsPerOctet in Table 23
67// The index follows LrWpanPhyOption
68const LrWpanPhyPpduHeaderSymbolNumber
70 { 32.0, 8.0, 8.0},
71 { 32.0, 8.0, 8.0},
72 { 32.0, 8.0, 8.0},
73 { 2.0, 1.0, 0.4},
74 { 6.0, 1.0, 1.6},
75 { 8.0, 2.0, 2.0},
76 { 8.0, 2.0, 2.0},
77 { 8.0, 2.0, 2.0},
78 { 8.0, 2.0, 2.0}};
79
80TypeId
82{
83 static TypeId tid = TypeId ("ns3::LrWpanPhy")
85 .SetGroupName ("LrWpan")
86 .AddConstructor<LrWpanPhy> ()
87 .AddTraceSource ("TrxStateValue",
88 "The state of the transceiver",
90 "ns3::TracedValueCallback::LrWpanPhyEnumeration")
91 .AddTraceSource ("TrxState",
92 "The state of the transceiver",
94 "ns3::LrWpanPhy::StateTracedCallback")
95 .AddTraceSource ("PhyTxBegin",
96 "Trace source indicating a packet has "
97 "begun transmitting over the channel medium",
99 "ns3::Packet::TracedCallback")
100 .AddTraceSource ("PhyTxEnd",
101 "Trace source indicating a packet has been "
102 "completely transmitted over the channel.",
104 "ns3::Packet::TracedCallback")
105 .AddTraceSource ("PhyTxDrop",
106 "Trace source indicating a packet has been "
107 "dropped by the device during transmission",
109 "ns3::Packet::TracedCallback")
110 .AddTraceSource ("PhyRxBegin",
111 "Trace source indicating a packet has begun "
112 "being received from the channel medium by the device",
114 "ns3::Packet::TracedCallback")
115 .AddTraceSource ("PhyRxEnd",
116 "Trace source indicating a packet has been "
117 "completely received from the channel medium "
118 "by the device",
120 "ns3::Packet::SinrTracedCallback")
121 .AddTraceSource ("PhyRxDrop",
122 "Trace source indicating a packet has been "
123 "dropped by the device during reception",
125 "ns3::Packet::TracedCallback")
126 ;
127 return tid;
128}
129
131 : m_edRequest (),
132 m_setTRXState ()
133{
136
137 // default PHY PIB attributes
140
142
143 m_random = CreateObject<UniformRandomVariable> ();
144 m_random->SetAttribute ("Min", DoubleValue (0.0));
145 m_random->SetAttribute ("Max", DoubleValue (1.0));
146
147 m_isRxCanceled = false;
149}
150
152{}
153
154void
156{
157 NS_LOG_FUNCTION (this);
158
159 // This method ensures that the local mobility model pointer holds
160 // a pointer to the Node's aggregated mobility model (if one exists)
161 // in the case that the user has not directly called SetMobility()
162 // on this LrWpanPhy during simulation setup. If the mobility model
163 // needs to be added or changed during simulation runtime, users must
164 // call SetMobility() on this object.
165
166 if (!m_mobility)
167 {
168 NS_ABORT_MSG_UNLESS (m_device && m_device->GetNode (), "Either install a MobilityModel on this object or ensure that this object is part of a Node and NetDevice");
169 m_mobility = m_device->GetNode ()->GetObject<MobilityModel> ();
170 if (!m_mobility)
171 {
172 NS_LOG_WARN ("Mobility not found, propagation models might not work properly");
173 }
174 }
175}
176
177void
179{
180 NS_LOG_FUNCTION (this);
181
182 // Cancel pending transceiver state change, if one is in progress.
186
187 m_mobility = nullptr;
188 m_device = nullptr;
189 m_channel = nullptr;
190 m_antenna = nullptr;
191 m_txPsd = nullptr;
192 m_noise = nullptr;
193 m_signal = nullptr;
194 m_errorModel = nullptr;
195 m_currentRxPacket.first = nullptr;
196 m_currentTxPacket.first = nullptr;
197
202
203 m_random = nullptr;
204 m_pdDataIndicationCallback = MakeNullCallback< void, uint32_t, Ptr<Packet>, uint8_t > ();
205 m_pdDataConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration > ();
206 m_plmeCcaConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration > ();
207 m_plmeEdConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration,uint8_t > ();
208 m_plmeGetAttributeConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration, LrWpanPibAttributeIdentifier, LrWpanPhyPibAttributes* > ();
209 m_plmeSetTRXStateConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration > ();
210 m_plmeSetAttributeConfirmCallback = MakeNullCallback< void, LrWpanPhyEnumeration, LrWpanPibAttributeIdentifier > ();
211
213}
214
217{
218 NS_LOG_FUNCTION (this);
219 return m_device;
220}
221
222
225{
226 NS_LOG_FUNCTION (this);
227 return m_mobility;
228}
229
230
231void
233{
234 NS_LOG_FUNCTION (this << d);
235 m_device = d;
236}
237
238
239void
241{
242 NS_LOG_FUNCTION (this << m);
243 m_mobility = m;
244}
245
246
247void
249{
250 NS_LOG_FUNCTION (this << c);
251 m_channel = c;
252}
253
254
257{
258 NS_LOG_FUNCTION (this);
259 return m_channel;
260}
261
262
265{
266 NS_LOG_FUNCTION (this);
267 if (m_txPsd)
268 {
269 return m_txPsd->GetSpectrumModel ();
270 }
271 else
272 {
273 return 0;
274 }
275}
276
279{
280 NS_LOG_FUNCTION (this);
281 return m_antenna;
282}
283
284void
286{
287 NS_LOG_FUNCTION (this << a);
288 m_antenna = a;
289}
290
291void
293{
294 NS_LOG_FUNCTION (this << spectrumRxParams);
295
296 if (!m_edRequest.IsExpired ())
297 {
298 // Update the average receive power during ED.
299 Time now = Simulator::Now ();
301 m_edPower.lastUpdate = now;
302 }
303
304 Ptr<LrWpanSpectrumSignalParameters> lrWpanRxParams = DynamicCast<LrWpanSpectrumSignalParameters> (spectrumRxParams);
305
306 if (!lrWpanRxParams)
307 {
309 m_signal->AddSignal (spectrumRxParams->psd);
310
311 // Update peak power if CCA is in progress.
312 if (!m_ccaRequest.IsExpired ())
313 {
315 if (m_ccaPeakPower < power)
316 {
317 m_ccaPeakPower = power;
318 }
319 }
320
321 Simulator::Schedule (spectrumRxParams->duration, &LrWpanPhy::EndRx, this, spectrumRxParams);
322 return;
323 }
324
325 Ptr<Packet> p = (lrWpanRxParams->packetBurst->GetPackets ()).front ();
326 NS_ASSERT (p);
327
328 // Prevent PHY from receiving another packet while switching the transceiver state.
330 {
331 // The specification doesn't seem to refer to BUSY_RX, but vendor
332 // data sheets suggest that this is a substate of the RX_ON state
333 // that is entered after preamble detection when the digital receiver
334 // is enabled. Here, for now, we use BUSY_RX to mark the period between
335 // StartRx() and EndRx() states.
336
337 // We are going to BUSY_RX state when receiving the first bit of an SHR,
338 // as opposed to real receivers, which should go to this state only after
339 // successfully receiving the SHR.
340
341 // If synchronizing to the packet is possible, change to BUSY_RX state,
342 // otherwise drop the packet and stay in RX state. The actual synchronization
343 // is not modeled.
344
345 // Add any incoming packet to the current interference before checking the
346 // SINR.
347 NS_LOG_DEBUG (this << " receiving packet with power: " << 10 * log10 (LrWpanSpectrumValueHelper::TotalAvgPower (lrWpanRxParams->psd, m_phyPIBAttributes.phyCurrentChannel)) + 30 << "dBm");
348 m_signal->AddSignal (lrWpanRxParams->psd);
349 Ptr<SpectrumValue> interferenceAndNoise = m_signal->GetSignalPsd ();
350 *interferenceAndNoise -= *lrWpanRxParams->psd;
351 *interferenceAndNoise += *m_noise;
353
354 // Std. 802.15.4-2006, appendix E, Figure E.2
355 // At SNR < -5 the BER is less than 10e-1.
356 // It's useless to even *try* to decode the packet.
357 if (10 * log10 (sinr) > -5)
358 {
360 m_currentRxPacket = std::make_pair (lrWpanRxParams, false);
362
364 }
365 else
366 {
368 }
369 }
371 {
372 // Drop the new packet.
373 NS_LOG_DEBUG (this << " packet collision");
375
376 // Check if we correctly received the old packet up to now.
378
379 // Add the incoming packet to the current interference after we have
380 // checked for successful reception of the current packet for the time
381 // before the additional interference.
382 m_signal->AddSignal (lrWpanRxParams->psd);
383 }
384 else
385 {
386 // Simply drop the packet.
387 NS_LOG_DEBUG (this << " transceiver not in RX state");
389
390 // Add the signal power to the interference, anyway.
391 m_signal->AddSignal (lrWpanRxParams->psd);
392 }
393
394 // Update peak power if CCA is in progress.
395 if (!m_ccaRequest.IsExpired ())
396 {
398 if (m_ccaPeakPower < power)
399 {
400 m_ccaPeakPower = power;
401 }
402 }
403
404 // Always call EndRx to update the interference.
405 // We keep track of this event, and if necessary cancel this event when a TX of a packet.
406
407 Simulator::Schedule (spectrumRxParams->duration, &LrWpanPhy::EndRx, this, spectrumRxParams);
408}
409
410void
412{
413 // Calculate whether packet was lost.
416
417 // We are currently receiving a packet.
419 {
420 // NS_ASSERT (currentRxParams && !m_currentRxPacket.second);
421
422 Ptr<Packet> currentPacket = currentRxParams->packetBurst->GetPackets ().front ();
423 if (m_errorModel)
424 {
425 // How many bits did we receive since the last calculation?
426 double t = (Simulator::Now () - m_rxLastUpdate).ToDouble (Time::MS);
427 uint32_t chunkSize = ceil (t * (GetDataOrSymbolRate (true) / 1000));
428 Ptr<SpectrumValue> interferenceAndNoise = m_signal->GetSignalPsd ();
429 *interferenceAndNoise -= *currentRxParams->psd;
430 *interferenceAndNoise += *m_noise;
432 double per = 1.0 - m_errorModel->GetChunkSuccessRate (sinr, chunkSize);
433
434 // The LQI is the total packet success rate scaled to 0-255.
435 // If not already set, initialize to 255.
437 currentPacket->PeekPacketTag (tag);
438 uint8_t lqi = tag.Get ();
439 tag.Set (lqi - (per * lqi));
440 currentPacket->ReplacePacketTag (tag);
441
442 if (m_random->GetValue () < per)
443 {
444 // The packet was destroyed, drop the packet after reception.
445 m_currentRxPacket.second = true;
446 }
447 }
448 else
449 {
450 NS_LOG_WARN ("Missing ErrorModel");
451 }
452 }
454}
455
456void
458{
459 NS_LOG_FUNCTION (this);
460
461 Ptr<LrWpanSpectrumSignalParameters> params = DynamicCast<LrWpanSpectrumSignalParameters> (par);
462
463 if (!m_edRequest.IsExpired ())
464 {
465 // Update the average receive power during ED.
466 Time now = Simulator::Now ();
468 m_edPower.lastUpdate = now;
469 }
470
472 if (currentRxParams == params)
473 {
475 }
476
477 // Update the interference.
478 m_signal->RemoveSignal (par->psd);
479
480 if (!params)
481 {
482 NS_LOG_LOGIC ("Node: " << m_device->GetAddress () << " Removing interferent: " << *(par->psd));
483 return;
484 }
485
486 // If this is the end of the currently received packet, check if reception was successful.
487 if (currentRxParams == params)
488 {
489 Ptr<Packet> currentPacket = currentRxParams->packetBurst->GetPackets ().front ();
490 NS_ASSERT (currentPacket);
491
492 // If there is no error model attached to the PHY, we always report the maximum LQI value.
494 currentPacket->PeekPacketTag (tag);
495 m_phyRxEndTrace (currentPacket, tag.Get ());
496
497 if (!m_currentRxPacket.second)
498 {
499 // The packet was successfully received, push it up the stack.
501 {
502 m_pdDataIndicationCallback (currentPacket->GetSize (), currentPacket, tag.Get ());
503 }
504 }
505 else
506 {
507 // The packet was destroyed, drop it.
508 m_phyRxDropTrace (currentPacket);
509 }
511 m_currentRxPacket = std::make_pair (none, true);
512
513 if (!m_isRxCanceled)
514 {
515 // We may be waiting to apply a pending state change.
517 {
518 // Only change the state immediately, if the transceiver is not already
519 // switching the state.
520 if (!m_setTRXState.IsRunning ())
521 {
522 NS_LOG_LOGIC ("Apply pending state change to " << m_trxStatePending);
526 {
528 }
529 }
530 }
531 else
532 {
534 }
535 }
536 else
537 {
538 // A TX event was forced during the reception of the frame.
539 // There is no need to change the PHY state after handling the signal,
540 // because the Forced TX already changed the PHY state.
541 // Return flag to default state
542 m_isRxCanceled = false;
543 }
544 }
545}
546
547void
549{
550 NS_LOG_FUNCTION (this << psduLength << p);
551
552 if (psduLength > aMaxPhyPacketSize)
553 {
555 {
557 }
558 NS_LOG_DEBUG ("Drop packet because psduLength too long: " << psduLength);
559 return;
560 }
561
562 // Prevent PHY from sending a packet while switching the transceiver state.
563 if (!m_setTRXState.IsRunning ())
564 {
566 {
567 //send down
569
570 // Remove a possible LQI tag from a previous transmission of the packet.
571 LrWpanLqiTag lqiTag;
572 p->RemovePacketTag (lqiTag);
573
575 m_currentTxPacket.first = p;
576 m_currentTxPacket.second = false;
577
578 Ptr<LrWpanSpectrumSignalParameters> txParams = Create<LrWpanSpectrumSignalParameters> ();
579 txParams->duration = CalculateTxTime (p);
580 txParams->txPhy = GetObject<SpectrumPhy> ();
581 txParams->psd = m_txPsd;
582 txParams->txAntenna = m_antenna;
583 Ptr<PacketBurst> pb = CreateObject<PacketBurst> ();
584 pb->AddPacket (p);
585 txParams->packetBurst = pb;
586 m_channel->StartTx (txParams);
587 m_pdDataRequest = Simulator::Schedule (txParams->duration, &LrWpanPhy::EndTx, this);
589 return;
590 }
594 {
596 {
598 }
599 // Drop packet, hit PhyTxDrop trace
601 return;
602 }
603 else
604 {
605 NS_FATAL_ERROR ("This should be unreachable, or else state " << m_trxState << " should be added as a case");
606 }
607 }
608 else
609 {
610 // TODO: This error code is not covered by the standard.
611 // What is the correct behavior in this case?
613 {
615 }
616 // Drop packet, hit PhyTxDrop trace
618 return;
619 }
620}
621
622void
624{
625 NS_LOG_FUNCTION (this);
626
628 {
629 m_ccaPeakPower = 0.0;
630 Time ccaTime = Seconds (8.0 / GetDataOrSymbolRate (false));
632 }
633 else
634 {
636 {
638 {
640 }
641 else
642 {
644 }
645 }
646 }
647}
648
649void
651{
652 NS_LOG_FUNCTION (this);
654}
655
656void
658{
659 NS_LOG_FUNCTION (this);
661 {
662 // Average over the powers of all signals received until EndEd()
667 }
668 else
669 {
672 {
674 }
675
677 {
678 m_plmeEdConfirmCallback (result, 0);
679 }
680 }
681}
682
683void
685{
686 NS_LOG_FUNCTION (this << id);
688
689 switch (id)
690 {
693 case phyTransmitPower:
694 case phyCCAMode:
695 case phyCurrentPage:
697 case phySHRDuration:
699 {
701 break;
702 }
703 default:
704 {
706 break;
707 }
708 }
710 {
711 LrWpanPhyPibAttributes retValue;
712 memcpy (&retValue, &m_phyPIBAttributes, sizeof(LrWpanPhyPibAttributes));
713 m_plmeGetAttributeConfirmCallback (status,id,&retValue);
714 }
715}
716
717// Section 6.2.2.7.3
718void
720{
721 NS_LOG_FUNCTION (this << state);
722
723 // Check valid states (Table 14)
725 && (state != IEEE_802_15_4_PHY_TRX_OFF)
727 && (state != IEEE_802_15_4_PHY_TX_ON) );
728
729 NS_LOG_LOGIC ("Trying to set m_trxState from " << m_trxState << " to " << state);
730 // this method always overrides previous state setting attempts
731 if (!m_setTRXState.IsExpired ())
732 {
733 if (m_trxStatePending == state)
734 {
735 // Simply wait for the ongoing state switch.
736 return;
737 }
738 else
739 {
740 NS_LOG_DEBUG ("Cancel m_setTRXState");
741 // Keep the transceiver state as the old state before the switching attempt.
743 }
744 }
746 {
748 }
749
750 if (state == m_trxState)
751 {
753 {
755 }
756 return;
757 }
758
759 if ( ((state == IEEE_802_15_4_PHY_RX_ON)
760 || (state == IEEE_802_15_4_PHY_TRX_OFF))
762 {
763 NS_LOG_DEBUG ("Phy is busy; setting state pending to " << state);
764 m_trxStatePending = state;
765 return; // Send PlmeSetTRXStateConfirm later
766 }
767
768 // specification talks about being in RX_ON and having received
769 // a valid SFD. Here, we are not modelling at that level of
770 // granularity, so we just test for BUSY_RX state (any part of
771 // a packet being actively received)
772 if (state == IEEE_802_15_4_PHY_TRX_OFF)
773 {
774 CancelEd (state);
775
777 && (m_currentRxPacket.first) && (!m_currentRxPacket.second))
778 {
779 NS_LOG_DEBUG ("Receiver has valid SFD; defer state change");
780 m_trxStatePending = state;
781 return; // Send PlmeSetTRXStateConfirm later
782 }
784 {
787 {
789 }
790 return;
791 }
792 }
793
794 if (state == IEEE_802_15_4_PHY_TX_ON)
795 {
796 CancelEd (state);
797
798 NS_LOG_DEBUG ("turn on PHY_TX_ON");
800 {
801 if (m_currentRxPacket.first)
802 {
803 // TX_ON is being forced during a reception (For example, when a ACK or Beacon is issued)
804 // The current RX frame is marked as incomplete and the reception as canceled
805 // EndRx () will handle the rest accordingly
806 NS_LOG_DEBUG ("force TX_ON, terminate reception");
807 m_currentRxPacket.second = true;
808 m_isRxCanceled = true;
809 }
810
811 // If CCA is in progress, cancel CCA and return BUSY.
812 if (!m_ccaRequest.IsExpired ())
813 {
816 {
818 }
819 }
820
822
823 // Delay for turnaround time (BUSY_RX|RX_ON ---> TX_ON)
824 Time setTime = Seconds ( (double) aTurnaroundTime / GetDataOrSymbolRate (false));
826 return;
827 }
829 {
830 // We do NOT change the transceiver state here. We only report that
831 // the transceiver is already in TX_ON state.
833 {
835 }
836 return;
837 }
839 {
842 {
844 }
845 return;
846 }
847 }
848
850 {
852 {
853 NS_LOG_DEBUG ("force TRX_OFF, was already off");
854 }
855 else
856 {
857 NS_LOG_DEBUG ("force TRX_OFF, SUCCESS");
858 if (m_currentRxPacket.first)
859 {
860 // Terminate reception
861 // Mark the packet as incomplete and reception as canceled.
862 NS_LOG_DEBUG ("force TRX_OFF, terminate reception");
863 m_currentRxPacket.second = true;
864 m_isRxCanceled = true;
865 }
867 {
868 NS_LOG_DEBUG ("force TRX_OFF, terminate transmission");
869 m_currentTxPacket.second = true;
870 }
872 // Clear any other state
874 }
876 {
878 }
879 return;
880 }
881
882 if (state == IEEE_802_15_4_PHY_RX_ON)
883 {
885 {
886 // Turnaround delay
887 // TODO: Does it really take aTurnaroundTime to switch the transceiver state,
888 // even when the transmitter is not busy? (6.9.1)
890
891 Time setTime = Seconds ( (double) aTurnaroundTime / GetDataOrSymbolRate (false));
893 return;
894 }
896 {
898 {
900 }
901 return;
902 }
903 }
904
905 NS_FATAL_ERROR ("Unexpected transition from state " << m_trxState << " to state " << state);
906}
907
908bool
910{
911 NS_LOG_FUNCTION (this << channel);
912 bool retValue = false;
913
914 // Bits 0-26 (27 LSB)
916 {
917 return retValue = true;
918 }
919 else
920 {
921 return retValue;
922 }
923}
924
925bool
927{
928 NS_LOG_FUNCTION (this << +page);
929 bool retValue = false;
930
931 // TODO: Only O-QPSK 2.4GHz is supported in the LrWpanSpectrumModel
932 // we must limit the page until support for other modulation is added to the spectrum model.
933 //
934 NS_ABORT_MSG_UNLESS (page == 0," Only Page 0 (2.4Ghz O-QPSK supported).");
935
936
937 // IEEE 802.15.4-2006, Table 23 phyChannelsSupported Bits 27-31 (5 MSB)
938 uint8_t supportedPage = (m_phyPIBAttributes.phyChannelsSupported[page] >> 27) & (0x1F);
939
940 if (page == supportedPage)
941 {
942 retValue = true;
943 }
944
945 return retValue;
946
947}
948
949void
951 LrWpanPhyPibAttributes* attribute)
952{
953 NS_LOG_FUNCTION (this << id << attribute);
954 NS_ASSERT (attribute);
956
957 switch (id)
958 {
959 case phyCurrentPage:
960 {
961 if (!PageSupported (attribute->phyCurrentPage))
962 {
964 }
965 else if (m_phyPIBAttributes.phyCurrentPage != attribute->phyCurrentPage)
966 {
967
968 // Cancel a pending transceiver state change.
969 // Switch off the transceiver.
970 // TODO: Is switching off the transceiver the right choice?
973 {
977 {
979 }
980 }
981
982 // Any packet in transmission or reception will be corrupted.
983 if (m_currentRxPacket.first)
984 {
985 m_currentRxPacket.second = true;
986 }
987 if (PhyIsBusy ())
988 {
989 m_currentTxPacket.second = true;
991 m_currentTxPacket.first = 0;
993 {
995 }
996 }
997
998 // Changing the Page can change they current PHY in use
999 // Set the correct PHY according to the Page
1000 if (attribute->phyCurrentPage == 0)
1001 {
1003 {
1004 // 868 MHz BPSK
1006 NS_LOG_INFO ("Page 0, 868 MHz BPSK PHY SET");
1007 }
1009 {
1010 // 915 MHz BPSK
1012 NS_LOG_INFO ("Page " << (uint32_t) attribute->phyCurrentPage
1013 << ",915 MHz BPSK PHY SET");
1014 }
1016 {
1017 // 2.4 GHz MHz O-QPSK
1019 NS_LOG_INFO ("Page " << (uint32_t) attribute->phyCurrentPage
1020 << ", 2.4 Ghz O-QPSK PHY SET");
1021 }
1022 }
1023 else if (attribute->phyCurrentPage == 1)
1024 {
1026 {
1027 // 868 MHz ASK
1029 NS_LOG_INFO ("Page " << (uint32_t) attribute->phyCurrentPage
1030 << ", 868 MHz ASK PHY SET");
1031
1032 }
1034 {
1035 // 915 MHz ASK
1037 NS_LOG_INFO ("Page " << (uint32_t) attribute->phyCurrentPage
1038 << ", 915 MHz ASK PHY SET");
1039 }
1040 else
1041 {
1042 // No longer valid channel
1045 NS_LOG_INFO ("Channel no longer valid in new page "
1046 << (uint32_t) attribute->phyCurrentPage
1047 << ", setting new default channel "
1049 NS_LOG_INFO ("868 MHz ASK PHY SET");
1050 }
1051 }
1052 else if (attribute->phyCurrentPage == 2)
1053 {
1055 {
1056 // 868 MHz O-QPSK
1058 NS_LOG_INFO ("Page " << (uint32_t) attribute->phyCurrentPage
1059 << ", 868 MHz O-QPSK PHY SET");
1060 }
1062 {
1063 // 915 MHz O-QPSK
1065 NS_LOG_INFO ("Page " << (uint32_t) attribute->phyCurrentPage
1066 << ", 915 MHz O-QPSK PHY SET");
1067 }
1068 else
1069 {
1070 // No longer valid channel
1073 NS_LOG_INFO ("Channel no longer valid in new page "
1074 << (uint32_t) attribute->phyCurrentPage
1075 << ", setting new default channel "
1077 NS_LOG_INFO ("868 MHz O-QPSK PHY SET");
1078 }
1079 }
1080 else if (attribute->phyCurrentPage == 5)
1081 {
1083 {
1084 // 780 MHz O-QPSK
1086 NS_LOG_INFO ("Page " << (uint32_t) attribute->phyCurrentPage
1087 << ", 915 MHz O-QPSK PHY SET");
1088 }
1089 else
1090 {
1091 // No longer valid channel
1094 NS_LOG_INFO ("Channel no longer valid in new page "
1095 << (uint32_t) attribute->phyCurrentPage
1096 << ", setting new default channel "
1098 NS_LOG_INFO ("780 MHz O-QPSK PHY SET");
1099 }
1100 }
1101 else if (attribute->phyCurrentPage == 6)
1102 {
1104 {
1105 // 950 MHz BPSK
1107 NS_LOG_INFO ("Page " << (uint32_t) attribute->phyCurrentPage
1108 << ", 950 MHz BPSK PHY SET");
1109 }
1110 else
1111 {
1114 NS_LOG_INFO ("Channel no longer valid in new page "
1115 << (uint32_t) attribute->phyCurrentPage
1116 << ", setting new default channel "
1118 NS_LOG_INFO ("950 MHz BPSK PHY SET");
1119 }
1120 }
1121
1123
1124 LrWpanSpectrumValueHelper psdHelper;
1127 // if the page is changed we need to also update the Noise Power Spectral Density
1129 m_signal = Create<LrWpanInterferenceHelper> (m_noise->GetSpectrumModel ());
1130 }
1131 break;
1132 }
1133 case phyCurrentChannel:
1134 {
1135 if (!ChannelSupported (attribute->phyCurrentChannel))
1136 {
1138 }
1140 {
1141 // Cancel a pending transceiver state change.
1142 // Switch off the transceiver.
1143 // TODO: Is switching off the transceiver the right choice?
1146 {
1150 {
1152 }
1153 }
1154
1155 // Any packet in transmission or reception will be corrupted.
1156 if (m_currentRxPacket.first)
1157 {
1158 m_currentRxPacket.second = true;
1159 }
1160 if (PhyIsBusy ())
1161 {
1162 m_currentTxPacket.second = true;
1164 m_currentTxPacket.first = 0;
1166 {
1168 }
1169 }
1170
1172
1173 LrWpanSpectrumValueHelper psdHelper;
1176 // if the channel is changed we need to also update the Noise Power Spectral Density
1178 m_signal = Create<LrWpanInterferenceHelper> (m_noise->GetSpectrumModel ());
1179 }
1180 break;
1181 }
1183 { // only the first element is considered in the array
1184 if ((attribute->phyChannelsSupported[0] & 0xf8000000) != 0)
1185 { //5 MSBs reserved
1187 }
1188 else
1189 {
1191 }
1192 break;
1193 }
1194 case phyTransmitPower:
1195 {
1196 if (attribute->phyTransmitPower & 0xC0)
1197 {
1198 NS_LOG_LOGIC ("LrWpanPhy::PlmeSetAttributeRequest error - can not change read-only attribute bits.");
1200 }
1201 else
1202 {
1204 LrWpanSpectrumValueHelper psdHelper;
1207 }
1208 break;
1209 }
1210 case phyCCAMode:
1211 {
1212 if ((attribute->phyCCAMode < 1) || (attribute->phyCCAMode > 3))
1213 {
1215 }
1216 else
1217 {
1219 }
1220 break;
1221 }
1222 default:
1223 {
1225 break;
1226 }
1227 }
1228
1230 {
1232 }
1233}
1234
1235void
1237{
1238 NS_LOG_FUNCTION (this);
1240}
1241
1242void
1244{
1245 NS_LOG_FUNCTION (this);
1247}
1248
1249void
1251{
1252 NS_LOG_FUNCTION (this);
1254}
1255
1256void
1258{
1259 NS_LOG_FUNCTION (this);
1261}
1262
1263void
1265{
1266 NS_LOG_FUNCTION (this);
1268}
1269
1270void
1272{
1273 NS_LOG_FUNCTION (this);
1275}
1276
1277void
1279{
1280 NS_LOG_FUNCTION (this);
1282}
1283
1284void
1286{
1287 NS_LOG_LOGIC (this << " state: " << m_trxState << " -> " << newState);
1289 m_trxState = newState;
1290}
1291
1292bool
1294{
1295 NS_LOG_FUNCTION (this << m_trxState);
1299}
1300
1301void
1303{
1304 NS_LOG_FUNCTION (this);
1306
1307 if (!m_edRequest.IsExpired ())
1308 {
1311 {
1312 m_plmeEdConfirmCallback (state, 0);
1313 }
1314 }
1315}
1316
1317void
1319{
1320 NS_LOG_FUNCTION (this);
1321
1323
1324 uint8_t energyLevel;
1325
1326 // Per IEEE802.15.4-2006 sec 6.9.7
1327 double ratio = m_edPower.averagePower / m_rxSensitivity;
1328 ratio = 10.0 * log10 (ratio);
1329 if (ratio <= 10.0)
1330 { // less than 10 dB
1331 energyLevel = 0;
1332 }
1333 else if (ratio >= 40.0)
1334 { // less than 40 dB
1335 energyLevel = 255;
1336 }
1337 else
1338 {
1339 // in-between with linear increase per sec 6.9.7
1340 energyLevel = static_cast<uint8_t> (((ratio - 10.0) / 30.0) * 255.0);
1341 }
1342
1344 {
1346 }
1347}
1348
1349void
1351{
1352 NS_LOG_FUNCTION (this);
1354
1355 // Update peak power.
1357 if (m_ccaPeakPower < power)
1358 {
1359 m_ccaPeakPower = power;
1360 }
1361
1362 if (PhyIsBusy ())
1363 {
1364 sensedChannelState = IEEE_802_15_4_PHY_BUSY;
1365 }
1366 else if (m_phyPIBAttributes.phyCCAMode == 1)
1367 { //sec 6.9.9 ED detection
1368 // -- ED threshold at most 10 dB above receiver sensitivity.
1369 if (10 * log10 (m_ccaPeakPower / m_rxSensitivity) >= 10.0)
1370 {
1371 sensedChannelState = IEEE_802_15_4_PHY_BUSY;
1372 }
1373 else
1374 {
1375 sensedChannelState = IEEE_802_15_4_PHY_IDLE;
1376 }
1377 }
1378 else if (m_phyPIBAttributes.phyCCAMode == 2)
1379 {
1380 //sec 6.9.9 carrier sense only
1382 {
1383 // We currently do not model PPDU reception in detail. Instead we model
1384 // packet reception starting with the first bit of the preamble.
1385 // Therefore, this code will never be reached, as PhyIsBusy() would
1386 // already lead to a channel busy condition.
1387 // TODO: Change this, if we also model preamble and SFD detection.
1388 sensedChannelState = IEEE_802_15_4_PHY_BUSY;
1389 }
1390 else
1391 {
1392 sensedChannelState = IEEE_802_15_4_PHY_IDLE;
1393 }
1394 }
1395 else if (m_phyPIBAttributes.phyCCAMode == 3)
1396 { //sect 6.9.9 both
1397 if ((10 * log10 (m_ccaPeakPower / m_rxSensitivity) >= 10.0)
1399 {
1400 // Again, this code will never be reached, if we are already receiving
1401 // a packet, as PhyIsBusy() would already lead to a channel busy condition.
1402 // TODO: Change this, if we also model preamble and SFD detection.
1403 sensedChannelState = IEEE_802_15_4_PHY_BUSY;
1404 }
1405 else
1406 {
1407 sensedChannelState = IEEE_802_15_4_PHY_IDLE;
1408 }
1409 }
1410 else
1411 {
1412 NS_ASSERT_MSG (false, "Invalid CCA mode");
1413 }
1414
1415 NS_LOG_LOGIC (this << "channel sensed state: " << sensedChannelState);
1416
1418 {
1419 m_plmeCcaConfirmCallback (sensedChannelState);
1420 }
1421}
1422
1423void
1425{
1426 NS_LOG_FUNCTION (this);
1427
1431
1433 {
1435 }
1436}
1437
1438void
1440{
1441 NS_LOG_FUNCTION (this);
1442
1444
1445 if (m_currentTxPacket.second == false)
1446 {
1447 NS_LOG_DEBUG ("Packet successfully transmitted");
1450 {
1452 }
1453 }
1454 else
1455 {
1456 NS_LOG_DEBUG ("Packet transmission aborted");
1459 {
1460 // See if this is ever entered in another state
1463 }
1464 }
1465 m_currentTxPacket.first = 0;
1466 m_currentTxPacket.second = false;
1467
1468
1469 // We may be waiting to apply a pending state change.
1471 {
1472 // Only change the state immediately, if the transceiver is not already
1473 // switching the state.
1474 if (!m_setTRXState.IsRunning ())
1475 {
1476 NS_LOG_LOGIC ("Apply pending state change to " << m_trxStatePending);
1480 {
1482 }
1483 }
1484 }
1485 else
1486 {
1488 {
1490 }
1491 }
1492}
1493
1494Time
1496{
1497 NS_LOG_FUNCTION (this << packet);
1498
1499 bool isData = true;
1500 Time txTime = GetPpduHeaderTxTime ();
1501
1502 txTime += Seconds (packet->GetSize () * 8.0 / GetDataOrSymbolRate (isData));
1503
1504 return txTime;
1505}
1506
1507uint8_t
1509{
1511}
1512
1513uint8_t
1515{
1517}
1518
1519double
1521{
1522 NS_LOG_FUNCTION (this << isData);
1523
1524 double rate = 0.0;
1525
1527
1528 if (isData)
1529 {
1531 }
1532 else
1533 {
1535 }
1536
1537 return (rate * 1000.0);
1538}
1539
1540Time
1542{
1543 NS_LOG_FUNCTION (this);
1544
1545 bool isData = false;
1546 double totalPpduHdrSymbols;
1547
1549
1550 totalPpduHdrSymbols = ppduHeaderSymbolNumbers[m_phyOption].shrPreamble
1553
1554 return Seconds (totalPpduHdrSymbols / GetDataOrSymbolRate (isData));
1555}
1556
1557void
1559{
1560 NS_LOG_FUNCTION (this);
1561
1563
1564 // TODO: Only O-QPSK 2.4GHz is supported in the LrWpanSpectrumModel
1565 // we must limit the page until support for other modulations is added to the spectrum model.
1566 NS_ABORT_MSG_UNLESS (phyOption == IEEE_802_15_4_2_4GHZ_OQPSK," Only 2.4Ghz O-QPSK supported.");
1567
1568 // Set default Channel and Page
1569 // IEEE 802.15.4-2006 Table 2, section 6.1.1
1570 // IEEE 802.15.4c-2009 Table 2, section 6.1.2.2
1571 // IEEE 802.15.4d-2009 Table 2, section 6.1.2.2
1572 switch (phyOption)
1573 {
1575 // IEEE 802.15.4-2006 868 MHz BPSK (Page 0, Channel 0)
1578 break;
1580 // IEEE 802.15.4-2006 915 MHz BPSK (Page 0, Channels 1 to 10)
1583 break;
1585 // IEEE 802.15.4d-2009 950 MHz BPSK (Page 6, Channels 0 to 9)
1588 break;
1590 // IEEE 802.15.4-2006 868 MHz ASK (Page 1, Channel 0)
1593 break;
1595 // IEEE 802.15.4-2006 915 MHz ASK (Page 1, Channel 1 to 10)
1598 break;
1600 // IEEE 802.15.4c-2009 780 MHz O-QPSK (Page 5, Channel 0 to 3)
1603 break;
1605 // IEEE 802.15.4-2006 868 MHz O-QPSK (Page 2, Channel 0)
1608 break;
1610 // IEEE 802.15.4-2006 915 MHz O-QPSK (Page 2, Channels 1 to 10)
1613 break;
1615 // IEEE 802.15.4-2009 2.4 GHz O-QPSK (Page 0, Channels 11 to 26)
1618 break;
1620 // IEEE 802.15.4-2006 Use Non-Registered Page and channel
1623 break;
1624 }
1625
1626
1628
1629 m_phyOption = phyOption;
1630 // TODO: Fix/Update list when more modulations are supported.
1631 // IEEE 802.15.4-2006, Table 23
1632 // 5 MSB = Page number, 27 LSB = Supported Channels (1= supported, 0 Not supported)
1633 // Currently only page 0, channels 11-26 supported.
1634 m_phyPIBAttributes.phyChannelsSupported[0] = 0x7FFF800; // Page 0 should support, Channels 0 to 26 (0x07FFFFFF)
1635
1636 for (int i = 1; i <= 31; i++)
1637 {
1638 // Page 1 to 31, No support (Page set to 31, all channels 0)
1640 }
1641
1642
1643 m_edPower.averagePower = 0.0;
1646
1647
1648 // TODO: What is the RX sensibility that should be set for other frequencies?
1649 // default -110 dBm in W for 2.4 GHz
1650 m_rxSensitivity = pow (10.0, -106.58 / 10.0) / 1000.0;
1651 LrWpanSpectrumValueHelper psdHelper;
1655 m_signal = Create<LrWpanInterferenceHelper> (m_noise->GetSpectrumModel ());
1656 m_rxLastUpdate = Seconds (0);
1657 Ptr<Packet> none_packet = 0;
1659 m_currentRxPacket = std::make_pair (none_params, true);
1660 m_currentTxPacket = std::make_pair (none_packet, true);
1661 m_errorModel = 0;
1662
1663}
1664
1667{
1668 NS_LOG_FUNCTION (this);
1669 return m_phyOption;
1670}
1671
1672void
1674{
1675 NS_LOG_FUNCTION (this << txPsd);
1676 NS_ASSERT (txPsd);
1677 m_txPsd = txPsd;
1678 NS_LOG_INFO ("\t computed tx_psd: " << *txPsd << "\t stored tx_psd: " << *m_txPsd);
1679}
1680
1681void
1683{
1684 NS_LOG_FUNCTION (this << noisePsd);
1685 NS_LOG_INFO ("\t computed noise_psd: " << *noisePsd );
1686 NS_ASSERT (noisePsd);
1687 m_noise = noisePsd;
1688}
1689
1692{
1693 NS_LOG_FUNCTION (this);
1694 return m_noise;
1695}
1696
1697void
1699{
1700 NS_LOG_FUNCTION (this << e);
1701 NS_ASSERT (e);
1702 m_errorModel = e;
1703}
1704
1707{
1708 NS_LOG_FUNCTION (this);
1709 return m_errorModel;
1710}
1711
1712uint64_t
1714{
1715 NS_LOG_FUNCTION (this);
1717
1720}
1721
1722double
1724{
1725 NS_LOG_FUNCTION (this);
1727
1729}
1730
1731double
1733{
1735 return WToDbm (powerWatts);
1736}
1737
1738int8_t
1740{
1742
1743 // The nominal Tx power is stored in the PIB as a 6-bit
1744 // twos-complement, signed number.
1745
1746 // The 5 LSBs can be copied - as their representation
1747 // is the same for unsigned and signed integers.
1748 int8_t nominalTxPower = phyTransmitPower & 0x1F;
1749
1750 // Now check the 6th LSB (the "sign" bit).
1751 // It's a twos-complement format, so the "sign"
1752 // bit represents -2^5 = -32.
1753 if (phyTransmitPower & 0x20)
1754 {
1755 nominalTxPower -= 32;
1756 }
1757 return nominalTxPower;
1758}
1759
1760double
1762{
1763 return (10 * log10 (1000 * watt));
1764}
1765
1766double
1768{
1769 return (pow (10.0, dbm / 10.0) / 1000.0);
1770}
1771
1772int64_t
1774{
1775 NS_LOG_FUNCTION (this);
1776 m_random->SetStream (stream);
1777 return 1;
1778}
1779
1780} // namespace ns3
#define max(a, b)
Definition: 80211b.c:43
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:532
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:71
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:53
bool IsExpired(void) const
This method is syntactic sugar for the ns3::Simulator::IsExpired method.
Definition: event-id.cc:65
Represent the LQI (Link Quality Estination).
void Set(uint8_t lqi)
Set the LQI to the given value.
uint8_t Get(void) const
Get the LQI value.
Make LrWpanPhy a SpectrumPhy so we can enable the eventual modeling of device interference.
Definition: lr-wpan-phy.h:250
virtual void StartRx(Ptr< SpectrumSignalParameters > params)
Notify the SpectrumPhy instance of an incoming waveform.
Definition: lr-wpan-phy.cc:292
uint8_t GetCurrentPage(void) const
Get The current channel page number in use in this PHY from the PIB attributes.
Ptr< const SpectrumValue > m_noise
The spectral density for for the noise.
Definition: lr-wpan-phy.h:780
virtual void DoInitialize(void)
Initialize() implementation.
Definition: lr-wpan-phy.cc:155
void SetPdDataConfirmCallback(PdDataConfirmCallback c)
set the callback for the end of a TX, as part of the interconnections betweenthe PHY and the MAC.
void SetPhyOption(LrWpanPhyOption phyOption)
Set the modulation option used by this PHY.
EventId m_setTRXState
Scheduler event of a currently running deferred transceiver state switch.
Definition: lr-wpan-phy.h:914
static const uint32_t aMaxPhyPacketSize
The maximum packet size accepted by the PHY.
Definition: lr-wpan-phy.h:264
static TypeId GetTypeId(void)
Get the type ID.
Definition: lr-wpan-phy.cc:81
bool ChannelSupported(uint8_t channel)
Check if the given channel is supported by the PHY.
Definition: lr-wpan-phy.cc:909
Ptr< SpectrumValue > m_txPsd
The transmit power spectral density.
Definition: lr-wpan-phy.h:775
void ChangeTrxState(LrWpanPhyEnumeration newState)
Change the PHY state to the given new state, firing the state change trace.
PlmeSetAttributeConfirmCallback m_plmeSetAttributeConfirmCallback
This callback is used to report attribute set results back to the MAC.
Definition: lr-wpan-phy.h:845
void SetPlmeGetAttributeConfirmCallback(PlmeGetAttributeConfirmCallback c)
set the callback for the end of an GetAttribute, as part of the interconnections betweenthe PHY and t...
Time CalculateTxTime(Ptr< const Packet > packet)
Calculate the time required for sending the given packet, including preamble, SFD and PHR.
Ptr< AntennaModel > m_antenna
The antenna used by the transceiver.
Definition: lr-wpan-phy.h:770
double GetDataOrSymbolRate(bool isData)
implement PLME SetAttribute confirm SAP bit rate is in bit/s.
void SetPlmeSetTRXStateConfirmCallback(PlmeSetTRXStateConfirmCallback c)
set the callback for the end of an SetTRXState, as part of the interconnections betweenthe PHY and th...
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:719
void SetTxPowerSpectralDensity(Ptr< SpectrumValue > txPsd)
Set the Power Spectral Density of outgoing signals in W/Hz.
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:684
Ptr< UniformRandomVariable > m_random
Uniform random variable stream.
Definition: lr-wpan-phy.h:924
TracedValue< LrWpanPhyEnumeration > m_trxState
The current transceiver state.
Definition: lr-wpan-phy.h:796
void PlmeCcaRequest(void)
IEEE 802.15.4-2006 section 6.2.2.1 PLME-CCA.request Perform a CCA per section 6.9....
Definition: lr-wpan-phy.cc:623
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:657
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:675
void SetPlmeEdConfirmCallback(PlmeEdConfirmCallback c)
set the callback for the end of an ED, as part of the interconnections betweenthe PHY and the MAC.
void EndRx(Ptr< SpectrumSignalParameters > params)
Finish the reception of a frame.
Definition: lr-wpan-phy.cc:457
PlmeCcaConfirmCallback m_plmeCcaConfirmCallback
This callback is used to report CCA status to the MAC or CSMA/CA.
Definition: lr-wpan-phy.h:821
Ptr< NetDevice > m_device
The configured net device.
Definition: lr-wpan-phy.h:760
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:548
LrWpanPhyOption GetMyPhyOption(void)
Get the currently configured PHY option.
Ptr< SpectrumChannel > GetChannel(void)
Get the currently attached channel.
Definition: lr-wpan-phy.cc:256
uint8_t GetCurrentChannelNum(void) const
Get The current channel number in use in this PHY from the PIB attributes.
Ptr< LrWpanErrorModel > m_errorModel
The error model describing the bit and packet error rates.
Definition: lr-wpan-phy.h:785
bool PageSupported(uint8_t page)
Check if the given page is supported by the PHY.
Definition: lr-wpan-phy.cc:926
virtual ~LrWpanPhy(void)
Definition: lr-wpan-phy.cc:151
Ptr< LrWpanErrorModel > GetErrorModel(void) const
get the error model in use
PlmeEdConfirmCallback m_plmeEdConfirmCallback
This callback is used to report ED status to the MAC.
Definition: lr-wpan-phy.h:827
std::pair< Ptr< LrWpanSpectrumSignalParameters >, bool > m_currentRxPacket
Statusinformation of the currently received packet.
Definition: lr-wpan-phy.h:891
EventId m_ccaRequest
Scheduler event of a currently running CCA request.
Definition: lr-wpan-phy.h:904
virtual Ptr< const SpectrumModel > GetRxSpectrumModel(void) const
Definition: lr-wpan-phy.cc:264
uint64_t GetPhySHRDuration(void) const
Get the duration of the SHR (preamble and SFD) in symbols, depending on the currently selected channe...
LrWpanEdPower m_edPower
Helper value for tracking the average power during ED.
Definition: lr-wpan-phy.h:855
Ptr< const SpectrumValue > GetNoisePowerSpectralDensity(void)
Get the noise power spectral density.
PacketAndStatus m_currentTxPacket
Statusinformation of the currently transmitted packet.
Definition: lr-wpan-phy.h:899
static const LrWpanPhyDataAndSymbolRates dataSymbolRates[IEEE_802_15_4_INVALID_PHY_OPTION]
The data and symbol rates for the different PHY options.
Definition: lr-wpan-phy.h:536
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:699
Ptr< SpectrumChannel > m_channel
The channel attached to this transceiver.
Definition: lr-wpan-phy.h:765
PdDataConfirmCallback m_pdDataConfirmCallback
This callback is used to report packet transmission status to the MAC layer.
Definition: lr-wpan-phy.h:815
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:667
Ptr< MobilityModel > m_mobility
The mobility model used by the PHY.
Definition: lr-wpan-phy.h:755
double m_ccaPeakPower
Helper value for the peak power value during CCA.
Definition: lr-wpan-phy.h:860
LrWpanPhyOption m_phyOption
The currently configured PHY type.
Definition: lr-wpan-phy.h:850
EventId m_edRequest
Scheduler event of a currently running ED request.
Definition: lr-wpan-phy.h:909
LrWpanPhyPibAttributes m_phyPIBAttributes
The current PHY PIB attributes.
Definition: lr-wpan-phy.h:790
double m_rxSensitivity
The receiver sensitivity.
Definition: lr-wpan-phy.h:865
static const uint32_t aTurnaroundTime
The turnaround time for switching the transceiver from RX to TX or vice versa.
Definition: lr-wpan-phy.h:271
LrWpanPhyEnumeration m_trxStatePending
The next pending state to applied after the current action of the PHY is completed.
Definition: lr-wpan-phy.h:802
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
void CheckInterference(void)
Check if the interference destroys a frame currently received.
Definition: lr-wpan-phy.cc:411
Time GetPpduHeaderTxTime(void)
Calculate the time required for sending the PPDU header, that is the preamble, SFD and PHR.
Ptr< LrWpanInterferenceHelper > m_signal
The accumulated signals currently received by the transceiver, including the signal of a possibly rec...
Definition: lr-wpan-phy.h:878
LrWpanPhy(void)
Default constructor.
Definition: lr-wpan-phy.cc:130
int8_t GetNominalTxPowerFromPib(uint8_t phyTransmitPower)
Calculates the nominal transmit power of the device in decibels relative to 1 mW according to the rep...
PdDataIndicationCallback m_pdDataIndicationCallback
This callback is used to notify incoming packets to the MAC layer.
Definition: lr-wpan-phy.h:809
void SetMobility(Ptr< MobilityModel > m)
Set the mobility model associated with this device.
Definition: lr-wpan-phy.cc:240
void SetErrorModel(Ptr< LrWpanErrorModel > e)
set the error model to use
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:706
double WToDbm(double watt)
Transform watts (W) to decibels milliwatts (DBm).
void EndCca(void)
Called at the end of the CCA.
void EndSetTRXState(void)
Called after applying a deferred transceiver state switch.
PlmeSetTRXStateConfirmCallback m_plmeSetTRXStateConfirmCallback
This callback is used to report transceiver state change status to the MAC.
Definition: lr-wpan-phy.h:839
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:950
PlmeGetAttributeConfirmCallback m_plmeGetAttributeConfirmCallback
This callback is used to report requested attribute values back to the MAC.
Definition: lr-wpan-phy.h:833
bool PhyIsBusy(void) const
Check if the PHY is busy, which is the case if the PHY is currently sending or receiving a frame.
void SetPdDataIndicationCallback(PdDataIndicationCallback c)
set the callback for the end of a RX, as part of the interconnections betweenthe PHY and the MAC.
EventId m_pdDataRequest
Scheduler event of a currently running data transmission request.
Definition: lr-wpan-phy.h:919
static const LrWpanPhyPpduHeaderSymbolNumber ppduHeaderSymbolNumbers[IEEE_802_15_4_INVALID_PHY_OPTION]
The preamble, SFD, and PHR lengths in symbols for the different PHY options.
Definition: lr-wpan-phy.h:541
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:683
virtual void DoDispose(void)
Destructor implementation.
Definition: lr-wpan-phy.cc:178
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:691
void SetDevice(Ptr< NetDevice > d)
Set the associated NetDevice instance.
Definition: lr-wpan-phy.cc:232
bool m_isRxCanceled
Indicates if the reception of frame has been canceled.
Definition: lr-wpan-phy.h:870
void SetPlmeSetAttributeConfirmCallback(PlmeSetAttributeConfirmCallback c)
set the callback for the end of an SetAttribute, as part of the interconnections betweenthe PHY and t...
double DbmToW(double dbm)
Transforms decibels milliwatts (dBm) to watts (W).
Time m_rxLastUpdate
Timestamp of the last calculation of the PER of a packet currently received.
Definition: lr-wpan-phy.h:883
Ptr< MobilityModel > GetMobility(void) const
Get the associated MobilityModel instance.
Definition: lr-wpan-phy.cc:224
void SetChannel(Ptr< SpectrumChannel > c)
Set the channel attached to this device.
Definition: lr-wpan-phy.cc:248
Ptr< Object > GetAntenna(void) const
Get the AntennaModel used by this SpectrumPhy instance for transmission and/or reception.
Definition: lr-wpan-phy.cc:278
void CcaCancel(void)
Cancel an ongoing CCA request.
Definition: lr-wpan-phy.cc:650
TracedCallback< Time, LrWpanPhyEnumeration, LrWpanPhyEnumeration > m_trxStateLogger
The trace source fired when the phy layer changes the transceiver state.
Definition: lr-wpan-phy.h:716
void CancelEd(LrWpanPhyEnumeration state)
Cancel an ongoing ED procedure.
void EndEd(void)
Called at the end of the ED procedure.
void SetAntenna(Ptr< AntennaModel > a)
Set the attached antenna.
Definition: lr-wpan-phy.cc:285
double GetPhySymbolsPerOctet(void) const
Get the number of symbols per octet, depending on the currently selected channel.
void SetNoisePowerSpectralDensity(Ptr< const SpectrumValue > noisePsd)
Set the noise power spectral density.
void SetPlmeCcaConfirmCallback(PlmeCcaConfirmCallback c)
set the callback for the end of a CCA, as part of the interconnections betweenthe PHY and the MAC.
Ptr< NetDevice > GetDevice(void) const
Get the associated NetDevice instance.
Definition: lr-wpan-phy.cc:216
void EndTx(void)
Finish the transmission of a frame.
double GetCurrentSignalPsd(void)
Get the current accumulated sum of signals in the transceiver including signals considered as interfe...
This class defines all functions to create spectrum model for LrWpan.
Ptr< SpectrumValue > CreateNoisePowerSpectralDensity(uint32_t channel)
create spectrum value for noise
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
Ptr< SpectrumValue > CreateTxPowerSpectralDensity(double txPower, uint32_t channel)
create spectrum value
Keep track of the current position and velocity of an object.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:256
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
Definition: packet.cc:963
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
Definition: packet.cc:978
bool ReplacePacketTag(Tag &tag)
Replace the value of a packet tag.
Definition: packet.cc:970
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:856
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:555
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
Abstract base class for Spectrum-aware PHY layers.
Definition: spectrum-phy.h:47
Ptr< const SpectrumModel > GetSpectrumModel() const
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
int64_t GetTimeStep(void) const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:416
@ MS
millisecond
Definition: nstime.h:116
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
double GetValue(double min, double max)
Get the next random value, as a double in the specified range .
#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
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:88
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
Definition: abort.h:144
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
Definition: abort.h:77
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:206
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:274
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:290
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:266
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:282
LrWpanPhyOption
This Phy option will be used to index various Tables in IEEE802.15.4-2011.
Definition: lr-wpan-phy.h:88
LrWpanPhyEnumeration
IEEE802.15.4-2006 PHY Emumerations Table 18 in section 6.2.3.
Definition: lr-wpan-phy.h:108
LrWpanPibAttributeIdentifier
IEEE802.15.4-2006 PHY PIB Attribute Identifiers Table 23 in section 6.4.2.
Definition: lr-wpan-phy.h:143
@ IEEE_802_15_4_868MHZ_BPSK
Definition: lr-wpan-phy.h:89
@ IEEE_802_15_4_915MHZ_OQPSK
Definition: lr-wpan-phy.h:96
@ IEEE_802_15_4_868MHZ_ASK
Definition: lr-wpan-phy.h:92
@ IEEE_802_15_4_950MHZ_BPSK
Definition: lr-wpan-phy.h:91
@ IEEE_802_15_4_868MHZ_OQPSK
Definition: lr-wpan-phy.h:95
@ IEEE_802_15_4_780MHZ_OQPSK
Definition: lr-wpan-phy.h:94
@ IEEE_802_15_4_2_4GHZ_OQPSK
Definition: lr-wpan-phy.h:97
@ IEEE_802_15_4_915MHZ_ASK
Definition: lr-wpan-phy.h:93
@ IEEE_802_15_4_915MHZ_BPSK
Definition: lr-wpan-phy.h:90
@ IEEE_802_15_4_INVALID_PHY_OPTION
Definition: lr-wpan-phy.h:98
@ IEEE_802_15_4_PHY_BUSY_RX
Definition: lr-wpan-phy.h:110
@ IEEE_802_15_4_PHY_UNSUPPORTED_ATTRIBUTE
Definition: lr-wpan-phy.h:119
@ IEEE_802_15_4_PHY_BUSY
Definition: lr-wpan-phy.h:109
@ IEEE_802_15_4_PHY_SUCCESS
Definition: lr-wpan-phy.h:116
@ IEEE_802_15_4_PHY_UNSPECIFIED
Definition: lr-wpan-phy.h:121
@ IEEE_802_15_4_PHY_TRX_OFF
Definition: lr-wpan-phy.h:117
@ IEEE_802_15_4_PHY_FORCE_TRX_OFF
Definition: lr-wpan-phy.h:112
@ IEEE_802_15_4_PHY_BUSY_TX
Definition: lr-wpan-phy.h:111
@ IEEE_802_15_4_PHY_RX_ON
Definition: lr-wpan-phy.h:115
@ IEEE_802_15_4_PHY_TX_ON
Definition: lr-wpan-phy.h:118
@ IEEE_802_15_4_PHY_INVALID_PARAMETER
Definition: lr-wpan-phy.h:114
@ IEEE_802_15_4_PHY_IDLE
Definition: lr-wpan-phy.h:113
@ phyMaxFrameDuration
Definition: lr-wpan-phy.h:149
@ phyChannelsSupported
Definition: lr-wpan-phy.h:145
@ phyCurrentChannel
Definition: lr-wpan-phy.h:144
@ phyCurrentPage
Definition: lr-wpan-phy.h:148
@ phyCCAMode
Definition: lr-wpan-phy.h:147
@ phySymbolsPerOctet
Definition: lr-wpan-phy.h:151
@ phySHRDuration
Definition: lr-wpan-phy.h:150
@ phyTransmitPower
Definition: lr-wpan-phy.h:146
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1245
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
channel
Definition: third.py:83
double averagePower
Average measured power.
Definition: lr-wpan-phy.h:52
Time lastUpdate
Last update time.
Definition: lr-wpan-phy.h:53
Time measurementLength
Total measurement period.
Definition: lr-wpan-phy.h:54
double symbolRate
symbol rate
Definition: lr-wpan-phy.h:66
IEEE802.15.4-2006 PHY PIB Attributes Table 23 in section 6.4.2.
Definition: lr-wpan-phy.h:160
uint32_t phyChannelsSupported[32]
BitField representing the available channels supported by a channel page.
Definition: lr-wpan-phy.h:162
uint8_t phyTransmitPower
2 MSB: tolerance on the transmit power, 6 LSB: Tx power in dBm relative to 1mW (signed int in 2-compl...
Definition: lr-wpan-phy.h:163
uint8_t phyCCAMode
CCA mode.
Definition: lr-wpan-phy.h:164
uint8_t phyCurrentPage
Current channel page.
Definition: lr-wpan-phy.h:165
uint8_t phyCurrentChannel
The RF channel to use.
Definition: lr-wpan-phy.h:161
double shrSfd
Number of symbols for the SHR SFD.
Definition: lr-wpan-phy.h:78
double phr
Number of symbols for the PHR.
Definition: lr-wpan-phy.h:79
double shrPreamble
Number of symbols for the SHR preamble.
Definition: lr-wpan-phy.h:77
Time duration
The duration of the packet transmission.
Ptr< SpectrumValue > psd
The Power Spectral Density of the waveform, in linear units.