A Discrete-Event Network Simulator
API
lr-wpan-phy.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 The Boeing Company
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author:
18 * Gary Pei <guangyu.pei@boeing.com>
19 * Sascha Alexander Jopen <jopen@cs.uni-bonn.de>
20 */
21#include "lr-wpan-phy.h"
22
23#include "lr-wpan-error-model.h"
24#include "lr-wpan-lqi-tag.h"
25#include "lr-wpan-net-device.h"
28
29#include <ns3/abort.h>
30#include <ns3/antenna-model.h>
31#include <ns3/double.h>
32#include <ns3/error-model.h>
33#include <ns3/log.h>
34#include <ns3/mobility-model.h>
35#include <ns3/net-device.h>
36#include <ns3/node.h>
37#include <ns3/packet-burst.h>
38#include <ns3/packet.h>
39#include <ns3/pointer.h>
40#include <ns3/random-variable-stream.h>
41#include <ns3/simulator.h>
42#include <ns3/spectrum-channel.h>
43#include <ns3/spectrum-value.h>
44
45namespace ns3
46{
47
48NS_LOG_COMPONENT_DEFINE("LrWpanPhy");
49
51
52// Table 22 in section 6.4.1 of ieee802.15.4
53const uint32_t LrWpanPhy::aMaxPhyPacketSize = 127; // max PSDU in octets
54const uint32_t LrWpanPhy::aTurnaroundTime = 12; // RX-to-TX or TX-to-RX in symbol periods
55
56// IEEE802.15.4-2006 Table 1 in section 6.1.1. and IEEE 802.15.4c-2009, IEEE 802.15.4d-2009
57// The index follows LrWpanPhyOption (kb/s and ksymbol/s)
58const LrWpanPhyDataAndSymbolRates LrWpanPhy::dataSymbolRates[IEEE_802_15_4_INVALID_PHY_OPTION] = {
59 {20.0, 20.0},
60 {40.0, 40.0},
61 {20.0, 20.0},
62 {250.0, 12.5},
63 {250.0, 50.0},
64 {250.0, 62.5},
65 {100.0, 25.0},
66 {250.0, 62.5},
67 {250.0, 62.5}};
68// IEEE802.15.4-2006,IEEE 802.15.4c-2009, IEEE 802.15.4d-2009 Table 19 and Table 20 in section 6.3.
69// The PHR is 1 octet and it follows phySymbolsPerOctet in Table 23
70// The index follows LrWpanPhyOption
71const LrWpanPhyPpduHeaderSymbolNumber
73 {32.0, 8.0, 8.0},
74 {32.0, 8.0, 8.0},
75 {2.0, 1.0, 0.4},
76 {6.0, 1.0, 1.6},
77 {8.0, 2.0, 2.0},
78 {8.0, 2.0, 2.0},
79 {8.0, 2.0, 2.0},
80 {8.0, 2.0, 2.0}};
81
82TypeId
84{
85 static TypeId tid =
86 TypeId("ns3::LrWpanPhy")
88 .SetGroupName("LrWpan")
89 .AddConstructor<LrWpanPhy>()
90 .AddAttribute("PostReceptionErrorModel",
91 "An optional packet error model can be added to the receive "
92 "packet process after any propagation-based (SNR-based) error "
93 "models have been applied. Typically this is used to force "
94 "specific packet drops, for testing purposes.",
97 MakePointerChecker<ErrorModel>())
98 .AddTraceSource("TrxStateValue",
99 "The state of the transceiver",
101 "ns3::TracedValueCallback::LrWpanPhyEnumeration")
102 .AddTraceSource("TrxState",
103 "The state of the transceiver",
105 "ns3::LrWpanPhy::StateTracedCallback")
106 .AddTraceSource("PhyTxBegin",
107 "Trace source indicating a packet has "
108 "begun transmitting over the channel medium",
110 "ns3::Packet::TracedCallback")
111 .AddTraceSource("PhyTxEnd",
112 "Trace source indicating a packet has been "
113 "completely transmitted over the channel.",
115 "ns3::Packet::TracedCallback")
116 .AddTraceSource("PhyTxDrop",
117 "Trace source indicating a packet has been "
118 "dropped by the device during transmission",
120 "ns3::Packet::TracedCallback")
121 .AddTraceSource("PhyRxBegin",
122 "Trace source indicating a packet has begun "
123 "being received from the channel medium by the device",
125 "ns3::Packet::TracedCallback")
126 .AddTraceSource("PhyRxEnd",
127 "Trace source indicating a packet has been "
128 "completely received from the channel medium "
129 "by the device",
131 "ns3::Packet::SinrTracedCallback")
132 .AddTraceSource("PhyRxDrop",
133 "Trace source indicating a packet has been "
134 "dropped by the device during reception",
136 "ns3::Packet::TracedCallback");
137 return tid;
138}
139
141 : m_edRequest(),
142 m_setTRXState()
143{
146
147 // default PHY PIB attributes
150
152
153 m_random = CreateObject<UniformRandomVariable>();
154 m_random->SetAttribute("Min", DoubleValue(0.0));
155 m_random->SetAttribute("Max", DoubleValue(1.0));
156
157 m_isRxCanceled = false;
159}
160
162{
163}
164
165void
167{
168 NS_LOG_FUNCTION(this);
169
170 // This method ensures that the local mobility model pointer holds
171 // a pointer to the Node's aggregated mobility model (if one exists)
172 // in the case that the user has not directly called SetMobility()
173 // on this LrWpanPhy during simulation setup. If the mobility model
174 // needs to be added or changed during simulation runtime, users must
175 // call SetMobility() on this object.
176
177 if (!m_mobility)
178 {
180 "Either install a MobilityModel on this object or ensure that this "
181 "object is part of a Node and NetDevice");
182 m_mobility = m_device->GetNode()->GetObject<MobilityModel>();
183 if (!m_mobility)
184 {
185 NS_LOG_WARN("Mobility not found, propagation models might not work properly");
186 }
187 }
188}
189
190void
192{
193 NS_LOG_FUNCTION(this);
194
195 // Cancel pending transceiver state change, if one is in progress.
199
200 m_mobility = nullptr;
201 m_device = nullptr;
202 m_channel = nullptr;
203 m_antenna = nullptr;
204 m_txPsd = nullptr;
205 m_noise = nullptr;
206 m_signal = nullptr;
207 m_errorModel = nullptr;
208 m_currentRxPacket.first = nullptr;
209 m_currentTxPacket.first = nullptr;
211
216
217 m_random = nullptr;
218 m_pdDataIndicationCallback = MakeNullCallback<void, uint32_t, Ptr<Packet>, uint8_t>();
219 m_pdDataConfirmCallback = MakeNullCallback<void, LrWpanPhyEnumeration>();
220 m_plmeCcaConfirmCallback = MakeNullCallback<void, LrWpanPhyEnumeration>();
221 m_plmeEdConfirmCallback = MakeNullCallback<void, LrWpanPhyEnumeration, uint8_t>();
226 m_plmeSetTRXStateConfirmCallback = MakeNullCallback<void, LrWpanPhyEnumeration>();
228 MakeNullCallback<void, LrWpanPhyEnumeration, LrWpanPibAttributeIdentifier>();
229
231}
232
235{
236 NS_LOG_FUNCTION(this);
237 return m_device;
238}
239
242{
243 NS_LOG_FUNCTION(this);
244 return m_mobility;
245}
246
247void
249{
250 NS_LOG_FUNCTION(this << d);
251 m_device = d;
252}
253
254void
256{
257 NS_LOG_FUNCTION(this << m);
258 m_mobility = m;
259}
260
261void
263{
264 NS_LOG_FUNCTION(this << c);
265 m_channel = c;
266}
267
270{
271 NS_LOG_FUNCTION(this);
272 return m_channel;
273}
274
277{
278 NS_LOG_FUNCTION(this);
279 if (m_txPsd)
280 {
281 return m_txPsd->GetSpectrumModel();
282 }
283 else
284 {
285 return nullptr;
286 }
287}
288
291{
292 NS_LOG_FUNCTION(this);
293 return m_antenna;
294}
295
296void
298{
299 NS_LOG_FUNCTION(this << a);
300 m_antenna = a;
301}
302
303void
305{
306 NS_LOG_FUNCTION(this << spectrumRxParams);
307
308 if (!m_edRequest.IsExpired())
309 {
310 // Update the average receive power during ED.
311 Time now = Simulator::Now();
316 m_edPower.lastUpdate = now;
317 }
318
320 DynamicCast<LrWpanSpectrumSignalParameters>(spectrumRxParams);
321
322 if (!lrWpanRxParams)
323 {
325 m_signal->AddSignal(spectrumRxParams->psd);
326
327 // Update peak power if CCA is in progress.
328 if (!m_ccaRequest.IsExpired())
329 {
330 double power =
333 if (m_ccaPeakPower < power)
334 {
335 m_ccaPeakPower = power;
336 }
337 }
338
339 Simulator::Schedule(spectrumRxParams->duration, &LrWpanPhy::EndRx, this, spectrumRxParams);
340 return;
341 }
342
343 Ptr<Packet> p = (lrWpanRxParams->packetBurst->GetPackets()).front();
344 NS_ASSERT(p);
345
346 // Prevent PHY from receiving another packet while switching the transceiver state.
348 {
349 // The specification doesn't seem to refer to BUSY_RX, but vendor
350 // data sheets suggest that this is a substate of the RX_ON state
351 // that is entered after preamble detection when the digital receiver
352 // is enabled. Here, for now, we use BUSY_RX to mark the period between
353 // StartRx() and EndRx() states.
354
355 // We are going to BUSY_RX state when receiving the first bit of an SHR,
356 // as opposed to real receivers, which should go to this state only after
357 // successfully receiving the SHR.
358
359 // If synchronizing to the packet is possible, change to BUSY_RX state,
360 // otherwise drop the packet and stay in RX state. The actual synchronization
361 // is not modeled.
362
363 // Add any incoming packet to the current interference before checking the
364 // SINR.
365 NS_LOG_DEBUG(this << " receiving packet with power: "
367 lrWpanRxParams->psd,
369 30
370 << "dBm");
371 m_signal->AddSignal(lrWpanRxParams->psd);
372 Ptr<SpectrumValue> interferenceAndNoise = m_signal->GetSignalPsd();
373 *interferenceAndNoise -= *lrWpanRxParams->psd;
374 *interferenceAndNoise += *m_noise;
375 double sinr =
378 LrWpanSpectrumValueHelper::TotalAvgPower(interferenceAndNoise,
380
381 // Std. 802.15.4-2006, appendix E, Figure E.2
382 // At SNR < -5 the BER is less than 10e-1.
383 // It's useless to even *try* to decode the packet.
384 if (10 * log10(sinr) > -5)
385 {
387 m_currentRxPacket = std::make_pair(lrWpanRxParams, false);
389
391 }
392 else
393 {
395 }
396 }
398 {
399 // Drop the new packet.
400 NS_LOG_DEBUG(this << " packet collision");
402
403 // Check if we correctly received the old packet up to now.
405
406 // Add the incoming packet to the current interference after we have
407 // checked for successful reception of the current packet for the time
408 // before the additional interference.
409 m_signal->AddSignal(lrWpanRxParams->psd);
410 }
411 else
412 {
413 // Simply drop the packet.
414 NS_LOG_DEBUG(this << " transceiver not in RX state");
416
417 // Add the signal power to the interference, anyway.
418 m_signal->AddSignal(lrWpanRxParams->psd);
419 }
420
421 // Update peak power if CCA is in progress.
422 if (!m_ccaRequest.IsExpired())
423 {
424 double power =
427 if (m_ccaPeakPower < power)
428 {
429 m_ccaPeakPower = power;
430 }
431 }
432
433 // Always call EndRx to update the interference.
434 // We keep track of this event, and if necessary cancel this event when a TX of a packet.
435
436 Simulator::Schedule(spectrumRxParams->duration, &LrWpanPhy::EndRx, this, spectrumRxParams);
437}
438
439void
441{
442 // Calculate whether packet was lost.
445
446 // We are currently receiving a packet.
448 {
449 // NS_ASSERT (currentRxParams && !m_currentRxPacket.second);
450
451 Ptr<Packet> currentPacket = currentRxParams->packetBurst->GetPackets().front();
452 if (m_errorModel)
453 {
454 // How many bits did we receive since the last calculation?
455 double t = (Simulator::Now() - m_rxLastUpdate).ToDouble(Time::MS);
456 uint32_t chunkSize = ceil(t * (GetDataOrSymbolRate(true) / 1000));
457 Ptr<SpectrumValue> interferenceAndNoise = m_signal->GetSignalPsd();
458 *interferenceAndNoise -= *currentRxParams->psd;
459 *interferenceAndNoise += *m_noise;
460 double sinr =
461 LrWpanSpectrumValueHelper::TotalAvgPower(currentRxParams->psd,
463 LrWpanSpectrumValueHelper::TotalAvgPower(interferenceAndNoise,
465 double per = 1.0 - m_errorModel->GetChunkSuccessRate(sinr, chunkSize);
466
467 // The LQI is the total packet success rate scaled to 0-255.
468 // If not already set, initialize to 255.
470 currentPacket->PeekPacketTag(tag);
471 uint8_t lqi = tag.Get();
472 tag.Set(lqi - (per * lqi));
473 currentPacket->ReplacePacketTag(tag);
474
475 if (m_random->GetValue() < per)
476 {
477 // The packet was destroyed, drop the packet after reception.
478 m_currentRxPacket.second = true;
479 }
480 }
481 else
482 {
483 NS_LOG_WARN("Missing ErrorModel");
484 }
485 }
487}
488
489void
491{
492 NS_LOG_FUNCTION(this);
493
494 Ptr<LrWpanSpectrumSignalParameters> params = DynamicCast<LrWpanSpectrumSignalParameters>(par);
495
496 if (!m_edRequest.IsExpired())
497 {
498 // Update the average receive power during ED.
499 Time now = Simulator::Now();
504 m_edPower.lastUpdate = now;
505 }
506
508 if (currentRxParams == params)
509 {
511 }
512
513 // Update the interference.
514 m_signal->RemoveSignal(par->psd);
515
516 if (!params)
517 {
518 NS_LOG_LOGIC("Node: " << m_device->GetAddress()
519 << " Removing interferent: " << *(par->psd));
520 return;
521 }
522
523 // If this is the end of the currently received packet, check if reception was successful.
524 if (currentRxParams == params)
525 {
526 Ptr<Packet> currentPacket = currentRxParams->packetBurst->GetPackets().front();
527 NS_ASSERT(currentPacket);
528
530 m_postReceptionErrorModel->IsCorrupt(currentPacket->Copy()))
531 {
532 NS_LOG_DEBUG("Reception failed due to post-rx error model");
533 m_currentRxPacket.second = true;
534 }
535
536 // If there is no error model attached to the PHY, we always report the maximum LQI value.
538 currentPacket->PeekPacketTag(tag);
539 m_phyRxEndTrace(currentPacket, tag.Get());
540
541 if (!m_currentRxPacket.second)
542 {
543 // The packet was successfully received, push it up the stack.
545 {
546 m_pdDataIndicationCallback(currentPacket->GetSize(), currentPacket, tag.Get());
547 }
548 }
549 else
550 {
551 // The packet was destroyed, drop it.
552 m_phyRxDropTrace(currentPacket);
553 }
555 m_currentRxPacket = std::make_pair(none, true);
556
557 if (!m_isRxCanceled)
558 {
559 // We may be waiting to apply a pending state change.
561 {
562 // Only change the state immediately, if the transceiver is not already
563 // switching the state.
565 {
566 NS_LOG_LOGIC("Apply pending state change to " << m_trxStatePending);
570 {
572 }
573 }
574 }
575 else
576 {
578 }
579 }
580 else
581 {
582 // A TX event was forced during the reception of the frame.
583 // There is no need to change the PHY state after handling the signal,
584 // because the Forced TX already changed the PHY state.
585 // Return flag to default state
586 m_isRxCanceled = false;
587 }
588 }
589}
590
591void
593{
594 NS_LOG_FUNCTION(this << psduLength << p);
595
596 if (psduLength > aMaxPhyPacketSize)
597 {
599 {
601 }
602 NS_LOG_DEBUG("Drop packet because psduLength too long: " << psduLength);
603 return;
604 }
605
606 // Prevent PHY from sending a packet while switching the transceiver state.
608 {
610 {
611 // send down
613
614 // Remove a possible LQI tag from a previous transmission of the packet.
615 LrWpanLqiTag lqiTag;
616 p->RemovePacketTag(lqiTag);
617
619 m_currentTxPacket.first = p;
620 m_currentTxPacket.second = false;
621
622 Ptr<LrWpanSpectrumSignalParameters> txParams = Create<LrWpanSpectrumSignalParameters>();
623 txParams->duration = CalculateTxTime(p);
624 txParams->txPhy = GetObject<SpectrumPhy>();
625 txParams->psd = m_txPsd;
626 txParams->txAntenna = m_antenna;
627 Ptr<PacketBurst> pb = CreateObject<PacketBurst>();
628 pb->AddPacket(p);
629 txParams->packetBurst = pb;
630 m_channel->StartTx(txParams);
631 m_pdDataRequest = Simulator::Schedule(txParams->duration, &LrWpanPhy::EndTx, this);
633 return;
634 }
635 else if ((m_trxState == IEEE_802_15_4_PHY_RX_ON) ||
638 {
640 {
642 }
643 // Drop packet, hit PhyTxDrop trace
645 return;
646 }
647 else
648 {
649 NS_FATAL_ERROR("This should be unreachable, or else state "
650 << m_trxState << " should be added as a case");
651 }
652 }
653 else
654 {
655 // TODO: This error code is not covered by the standard.
656 // What is the correct behavior in this case?
658 {
660 }
661 // Drop packet, hit PhyTxDrop trace
663 return;
664 }
665}
666
667void
669{
670 NS_LOG_FUNCTION(this);
671
673 {
674 m_ccaPeakPower = 0.0;
675 Time ccaTime = Seconds(8.0 / GetDataOrSymbolRate(false));
677 }
678 else
679 {
681 {
683 {
685 }
686 else
687 {
689 }
690 }
691 }
692}
693
694void
696{
697 NS_LOG_FUNCTION(this);
699}
700
701void
703{
704 NS_LOG_FUNCTION(this);
706 {
707 // Average over the powers of all signals received until EndEd()
712 }
713 else
714 {
717 {
719 }
720
722 {
723 m_plmeEdConfirmCallback(result, 0);
724 }
725 }
726}
727
728void
730{
731 NS_LOG_FUNCTION(this << id);
733
734 switch (id)
735 {
738 case phyTransmitPower:
739 case phyCCAMode:
740 case phyCurrentPage:
742 case phySHRDuration:
743 case phySymbolsPerOctet: {
745 break;
746 }
747 default: {
749 break;
750 }
751 }
753 {
754 LrWpanPhyPibAttributes retValue;
755 memcpy(&retValue, &m_phyPIBAttributes, sizeof(LrWpanPhyPibAttributes));
756 m_plmeGetAttributeConfirmCallback(status, id, &retValue);
757 }
758}
759
760// Section 6.2.2.7.3
761void
763{
764 NS_LOG_FUNCTION(this << state);
765
766 // Check valid states (Table 14)
769
770 NS_LOG_LOGIC("Trying to set m_trxState from " << m_trxState << " to " << state);
771 // this method always overrides previous state setting attempts
773 {
774 if (m_trxStatePending == state)
775 {
776 // Simply wait for the ongoing state switch.
777 return;
778 }
779 else
780 {
781 NS_LOG_DEBUG("Cancel m_setTRXState");
782 // Keep the transceiver state as the old state before the switching attempt.
784 }
785 }
787 {
789 }
790
791 if (state == m_trxState)
792 {
794 {
796 }
797 return;
798 }
799
800 if (((state == IEEE_802_15_4_PHY_RX_ON) || (state == IEEE_802_15_4_PHY_TRX_OFF)) &&
802 {
803 NS_LOG_DEBUG("Phy is busy; setting state pending to " << state);
804 m_trxStatePending = state;
805 return; // Send PlmeSetTRXStateConfirm later
806 }
807
808 // specification talks about being in RX_ON and having received
809 // a valid SFD. Here, we are not modelling at that level of
810 // granularity, so we just test for BUSY_RX state (any part of
811 // a packet being actively received)
812 if (state == IEEE_802_15_4_PHY_TRX_OFF)
813 {
814 CancelEd(state);
815
817 (!m_currentRxPacket.second))
818 {
819 NS_LOG_DEBUG("Receiver has valid SFD; defer state change");
820 m_trxStatePending = state;
821 return; // Send PlmeSetTRXStateConfirm later
822 }
824 {
827 {
829 }
830 return;
831 }
832 }
833
834 if (state == IEEE_802_15_4_PHY_TX_ON)
835 {
836 CancelEd(state);
837
838 NS_LOG_DEBUG("turn on PHY_TX_ON");
840 {
841 if (m_currentRxPacket.first)
842 {
843 // TX_ON is being forced during a reception (For example, when a ACK or Beacon is
844 // issued) The current RX frame is marked as incomplete and the reception as
845 // canceled EndRx () will handle the rest accordingly
846 NS_LOG_DEBUG("force TX_ON, terminate reception");
847 m_currentRxPacket.second = true;
848 m_isRxCanceled = true;
849 }
850
851 // If CCA is in progress, cancel CCA and return BUSY.
852 if (!m_ccaRequest.IsExpired())
853 {
856 {
858 }
859 }
860
862
863 // Delay for turnaround time (BUSY_RX|RX_ON ---> TX_ON)
864 Time setTime = Seconds((double)aTurnaroundTime / GetDataOrSymbolRate(false));
866 return;
867 }
869 {
870 // We do NOT change the transceiver state here. We only report that
871 // the transceiver is already in TX_ON state.
873 {
875 }
876 return;
877 }
879 {
882 {
884 }
885 return;
886 }
887 }
888
890 {
892 {
893 NS_LOG_DEBUG("force TRX_OFF, was already off");
894 }
895 else
896 {
897 NS_LOG_DEBUG("force TRX_OFF, SUCCESS");
898 if (m_currentRxPacket.first)
899 {
900 // Terminate reception
901 // Mark the packet as incomplete and reception as canceled.
902 NS_LOG_DEBUG("force TRX_OFF, terminate reception");
903 m_currentRxPacket.second = true;
904 m_isRxCanceled = true;
905 }
907 {
908 NS_LOG_DEBUG("force TRX_OFF, terminate transmission");
909 m_currentTxPacket.second = true;
910 }
912 // Clear any other state
914 }
916 {
918 }
919 return;
920 }
921
922 if (state == IEEE_802_15_4_PHY_RX_ON)
923 {
925 {
926 // Turnaround delay
927 // TODO: Does it really take aTurnaroundTime to switch the transceiver state,
928 // even when the transmitter is not busy? (6.9.1)
930
931 Time setTime = Seconds((double)aTurnaroundTime / GetDataOrSymbolRate(false));
933 return;
934 }
936 {
938 {
940 }
941 return;
942 }
943 }
944
945 NS_FATAL_ERROR("Unexpected transition from state " << m_trxState << " to state " << state);
946}
947
948bool
950{
951 NS_LOG_FUNCTION(this << channel);
952 bool retValue = false;
953
954 // Bits 0-26 (27 LSB)
956 (1 << channel)) != 0)
957 {
958 return retValue = true;
959 }
960 else
961 {
962 return retValue;
963 }
964}
965
966bool
968{
969 NS_LOG_FUNCTION(this << +page);
970 bool retValue = false;
971
972 // TODO: Only O-QPSK 2.4GHz is supported in the LrWpanSpectrumModel
973 // we must limit the page until support for other modulation is added to the spectrum
974 // model.
975 //
976 NS_ABORT_MSG_UNLESS(page == 0, " Only Page 0 (2.4Ghz O-QPSK supported).");
977
978 // IEEE 802.15.4-2006, Table 23 phyChannelsSupported Bits 27-31 (5 MSB)
979 uint8_t supportedPage = (m_phyPIBAttributes.phyChannelsSupported[page] >> 27) & (0x1F);
980
981 if (page == supportedPage)
982 {
983 retValue = true;
984 }
985
986 return retValue;
987}
988
989void
991 LrWpanPhyPibAttributes* attribute)
992{
993 NS_LOG_FUNCTION(this << id << attribute);
994 NS_ASSERT(attribute);
996
997 switch (id)
998 {
999 case phyCurrentPage: {
1000 if (!PageSupported(attribute->phyCurrentPage))
1001 {
1003 }
1004 else if (m_phyPIBAttributes.phyCurrentPage != attribute->phyCurrentPage)
1005 {
1006 // Cancel a pending transceiver state change.
1007 // Switch off the transceiver.
1008 // TODO: Is switching off the transceiver the right choice?
1011 {
1015 {
1017 }
1018 }
1019
1020 // Any packet in transmission or reception will be corrupted.
1021 if (m_currentRxPacket.first)
1022 {
1023 m_currentRxPacket.second = true;
1024 }
1025 if (PhyIsBusy())
1026 {
1027 m_currentTxPacket.second = true;
1029 m_currentTxPacket.first = nullptr;
1031 {
1033 }
1034 }
1035
1036 // Changing the Page can change they current PHY in use
1037 // Set the correct PHY according to the Page
1038 if (attribute->phyCurrentPage == 0)
1039 {
1041 {
1042 // 868 MHz BPSK
1044 NS_LOG_INFO("Page 0, 868 MHz BPSK PHY SET");
1045 }
1047 {
1048 // 915 MHz BPSK
1050 NS_LOG_INFO("Page " << (uint32_t)attribute->phyCurrentPage
1051 << ",915 MHz BPSK PHY SET");
1052 }
1054 {
1055 // 2.4 GHz MHz O-QPSK
1057 NS_LOG_INFO("Page " << (uint32_t)attribute->phyCurrentPage
1058 << ", 2.4 Ghz O-QPSK PHY SET");
1059 }
1060 }
1061 else if (attribute->phyCurrentPage == 1)
1062 {
1064 {
1065 // 868 MHz ASK
1067 NS_LOG_INFO("Page " << (uint32_t)attribute->phyCurrentPage
1068 << ", 868 MHz ASK PHY SET");
1069 }
1071 {
1072 // 915 MHz ASK
1074 NS_LOG_INFO("Page " << (uint32_t)attribute->phyCurrentPage
1075 << ", 915 MHz ASK PHY SET");
1076 }
1077 else
1078 {
1079 // No longer valid channel
1082 NS_LOG_INFO("Channel no longer valid in new page "
1083 << (uint32_t)attribute->phyCurrentPage
1084 << ", setting new default channel "
1086 NS_LOG_INFO("868 MHz ASK PHY SET");
1087 }
1088 }
1089 else if (attribute->phyCurrentPage == 2)
1090 {
1092 {
1093 // 868 MHz O-QPSK
1095 NS_LOG_INFO("Page " << (uint32_t)attribute->phyCurrentPage
1096 << ", 868 MHz O-QPSK PHY SET");
1097 }
1099 {
1100 // 915 MHz O-QPSK
1102 NS_LOG_INFO("Page " << (uint32_t)attribute->phyCurrentPage
1103 << ", 915 MHz O-QPSK PHY SET");
1104 }
1105 else
1106 {
1107 // No longer valid channel
1110 NS_LOG_INFO("Channel no longer valid in new page "
1111 << (uint32_t)attribute->phyCurrentPage
1112 << ", setting new default channel "
1114 NS_LOG_INFO("868 MHz O-QPSK PHY SET");
1115 }
1116 }
1117 else if (attribute->phyCurrentPage == 5)
1118 {
1120 {
1121 // 780 MHz O-QPSK
1123 NS_LOG_INFO("Page " << (uint32_t)attribute->phyCurrentPage
1124 << ", 915 MHz O-QPSK PHY SET");
1125 }
1126 else
1127 {
1128 // No longer valid channel
1131 NS_LOG_INFO("Channel no longer valid in new page "
1132 << (uint32_t)attribute->phyCurrentPage
1133 << ", setting new default channel "
1135 NS_LOG_INFO("780 MHz O-QPSK PHY SET");
1136 }
1137 }
1138 else if (attribute->phyCurrentPage == 6)
1139 {
1141 {
1142 // 950 MHz BPSK
1144 NS_LOG_INFO("Page " << (uint32_t)attribute->phyCurrentPage
1145 << ", 950 MHz BPSK PHY SET");
1146 }
1147 else
1148 {
1151 NS_LOG_INFO("Channel no longer valid in new page "
1152 << (uint32_t)attribute->phyCurrentPage
1153 << ", setting new default channel "
1155 NS_LOG_INFO("950 MHz BPSK PHY SET");
1156 }
1157 }
1158
1160
1161 LrWpanSpectrumValueHelper psdHelper;
1165 // if the page is changed we need to also update the Noise Power Spectral Density
1166 m_noise =
1168 m_signal = Create<LrWpanInterferenceHelper>(m_noise->GetSpectrumModel());
1169 }
1170 break;
1171 }
1172 case phyCurrentChannel: {
1173 if (!ChannelSupported(attribute->phyCurrentChannel))
1174 {
1176 }
1178 {
1179 // Cancel a pending transceiver state change.
1180 // Switch off the transceiver.
1181 // TODO: Is switching off the transceiver the right choice?
1184 {
1188 {
1190 }
1191 }
1192
1193 // Any packet in transmission or reception will be corrupted.
1194 if (m_currentRxPacket.first)
1195 {
1196 m_currentRxPacket.second = true;
1197 }
1198 if (PhyIsBusy())
1199 {
1200 m_currentTxPacket.second = true;
1202 m_currentTxPacket.first = nullptr;
1204 {
1206 }
1207 }
1208
1210
1211 LrWpanSpectrumValueHelper psdHelper;
1215 // if the channel is changed we need to also update the Noise Power Spectral Density
1216 m_noise =
1218 m_signal = Create<LrWpanInterferenceHelper>(m_noise->GetSpectrumModel());
1219 }
1220 break;
1221 }
1222 case phyChannelsSupported: { // only the first element is considered in the array
1223 if ((attribute->phyChannelsSupported[0] & 0xf8000000) != 0)
1224 { // 5 MSBs reserved
1226 }
1227 else
1228 {
1230 }
1231 break;
1232 }
1233 case phyTransmitPower: {
1234 if (attribute->phyTransmitPower & 0xC0)
1235 {
1236 NS_LOG_LOGIC("LrWpanPhy::PlmeSetAttributeRequest error - can not change read-only "
1237 "attribute bits.");
1239 }
1240 else
1241 {
1243 LrWpanSpectrumValueHelper psdHelper;
1247 }
1248 break;
1249 }
1250 case phyCCAMode: {
1251 if ((attribute->phyCCAMode < 1) || (attribute->phyCCAMode > 3))
1252 {
1254 }
1255 else
1256 {
1258 }
1259 break;
1260 }
1261 default: {
1263 break;
1264 }
1265 }
1266
1268 {
1270 }
1271}
1272
1273void
1275{
1276 NS_LOG_FUNCTION(this);
1278}
1279
1280void
1282{
1283 NS_LOG_FUNCTION(this);
1285}
1286
1287void
1289{
1290 NS_LOG_FUNCTION(this);
1292}
1293
1294void
1296{
1297 NS_LOG_FUNCTION(this);
1299}
1300
1301void
1303{
1304 NS_LOG_FUNCTION(this);
1306}
1307
1308void
1310{
1311 NS_LOG_FUNCTION(this);
1313}
1314
1315void
1317{
1318 NS_LOG_FUNCTION(this);
1320}
1321
1322void
1324{
1325 NS_LOG_LOGIC(this << " state: " << m_trxState << " -> " << newState);
1327 m_trxState = newState;
1328}
1329
1330bool
1332{
1333 NS_LOG_FUNCTION(this << m_trxState);
1336}
1337
1338void
1340{
1341 NS_LOG_FUNCTION(this);
1343
1344 if (!m_edRequest.IsExpired())
1345 {
1348 {
1349 m_plmeEdConfirmCallback(state, 0);
1350 }
1351 }
1352}
1353
1354void
1356{
1357 NS_LOG_FUNCTION(this);
1358
1362 (Simulator::Now() - m_edPower.lastUpdate).GetTimeStep() /
1364
1365 uint8_t energyLevel;
1366
1367 // Per IEEE802.15.4-2006 sec 6.9.7
1368 double ratio = m_edPower.averagePower / m_rxSensitivity;
1369 ratio = 10.0 * log10(ratio);
1370 if (ratio <= 10.0)
1371 { // less than 10 dB
1372 energyLevel = 0;
1373 }
1374 else if (ratio >= 40.0)
1375 { // less than 40 dB
1376 energyLevel = 255;
1377 }
1378 else
1379 {
1380 // in-between with linear increase per sec 6.9.7
1381 energyLevel = static_cast<uint8_t>(((ratio - 10.0) / 30.0) * 255.0);
1382 }
1383
1385 {
1387 }
1388}
1389
1390void
1392{
1393 NS_LOG_FUNCTION(this);
1395
1396 // Update peak power.
1397 double power = LrWpanSpectrumValueHelper::TotalAvgPower(m_signal->GetSignalPsd(),
1399 if (m_ccaPeakPower < power)
1400 {
1401 m_ccaPeakPower = power;
1402 }
1403
1404 if (PhyIsBusy())
1405 {
1406 sensedChannelState = IEEE_802_15_4_PHY_BUSY;
1407 }
1408 else if (m_phyPIBAttributes.phyCCAMode == 1)
1409 { // sec 6.9.9 ED detection
1410 // -- ED threshold at most 10 dB above receiver sensitivity.
1411 if (10 * log10(m_ccaPeakPower / m_rxSensitivity) >= 10.0)
1412 {
1413 sensedChannelState = IEEE_802_15_4_PHY_BUSY;
1414 }
1415 else
1416 {
1417 sensedChannelState = IEEE_802_15_4_PHY_IDLE;
1418 }
1419 }
1420 else if (m_phyPIBAttributes.phyCCAMode == 2)
1421 {
1422 // sec 6.9.9 carrier sense only
1424 {
1425 // We currently do not model PPDU reception in detail. Instead we model
1426 // packet reception starting with the first bit of the preamble.
1427 // Therefore, this code will never be reached, as PhyIsBusy() would
1428 // already lead to a channel busy condition.
1429 // TODO: Change this, if we also model preamble and SFD detection.
1430 sensedChannelState = IEEE_802_15_4_PHY_BUSY;
1431 }
1432 else
1433 {
1434 sensedChannelState = IEEE_802_15_4_PHY_IDLE;
1435 }
1436 }
1437 else if (m_phyPIBAttributes.phyCCAMode == 3)
1438 { // sect 6.9.9 both
1439 if ((10 * log10(m_ccaPeakPower / m_rxSensitivity) >= 10.0) &&
1441 {
1442 // Again, this code will never be reached, if we are already receiving
1443 // a packet, as PhyIsBusy() would already lead to a channel busy condition.
1444 // TODO: Change this, if we also model preamble and SFD detection.
1445 sensedChannelState = IEEE_802_15_4_PHY_BUSY;
1446 }
1447 else
1448 {
1449 sensedChannelState = IEEE_802_15_4_PHY_IDLE;
1450 }
1451 }
1452 else
1453 {
1454 NS_ASSERT_MSG(false, "Invalid CCA mode");
1455 }
1456
1457 NS_LOG_LOGIC(this << "channel sensed state: " << sensedChannelState);
1458
1460 {
1461 m_plmeCcaConfirmCallback(sensedChannelState);
1462 }
1463}
1464
1465void
1467{
1468 NS_LOG_FUNCTION(this);
1469
1474
1476 {
1478 }
1479}
1480
1481void
1483{
1484 NS_LOG_FUNCTION(this);
1485
1488
1489 if (m_currentTxPacket.second == false)
1490 {
1491 NS_LOG_DEBUG("Packet successfully transmitted");
1494 {
1496 }
1497 }
1498 else
1499 {
1500 NS_LOG_DEBUG("Packet transmission aborted");
1503 {
1504 // See if this is ever entered in another state
1507 }
1508 }
1509 m_currentTxPacket.first = nullptr;
1510 m_currentTxPacket.second = false;
1511
1512 // We may be waiting to apply a pending state change.
1514 {
1515 // Only change the state immediately, if the transceiver is not already
1516 // switching the state.
1517 if (!m_setTRXState.IsRunning())
1518 {
1519 NS_LOG_LOGIC("Apply pending state change to " << m_trxStatePending);
1523 {
1525 }
1526 }
1527 }
1528 else
1529 {
1531 {
1533 }
1534 }
1535}
1536
1537Time
1539{
1540 NS_LOG_FUNCTION(this << packet);
1541
1542 bool isData = true;
1543 Time txTime = GetPpduHeaderTxTime();
1544
1545 txTime += Seconds(packet->GetSize() * 8.0 / GetDataOrSymbolRate(isData));
1546
1547 return txTime;
1548}
1549
1550uint8_t
1552{
1554}
1555
1556uint8_t
1558{
1560}
1561
1562double
1564{
1565 NS_LOG_FUNCTION(this << isData);
1566
1567 double rate = 0.0;
1568
1570
1571 if (isData)
1572 {
1574 }
1575 else
1576 {
1578 }
1579
1580 return (rate * 1000.0);
1581}
1582
1583Time
1585{
1586 NS_LOG_FUNCTION(this);
1587
1588 bool isData = false;
1589 double totalPpduHdrSymbols;
1590
1592
1593 totalPpduHdrSymbols = ppduHeaderSymbolNumbers[m_phyOption].shrPreamble +
1596
1597 return Seconds(totalPpduHdrSymbols / GetDataOrSymbolRate(isData));
1598}
1599
1600void
1602{
1603 NS_LOG_FUNCTION(this);
1604
1606
1607 // TODO: Only O-QPSK 2.4GHz is supported in the LrWpanSpectrumModel
1608 // we must limit the page until support for other modulations is added to the spectrum
1609 // model.
1610 NS_ABORT_MSG_UNLESS(phyOption == IEEE_802_15_4_2_4GHZ_OQPSK, " Only 2.4Ghz O-QPSK supported.");
1611
1612 // Set default Channel and Page
1613 // IEEE 802.15.4-2006 Table 2, section 6.1.1
1614 // IEEE 802.15.4c-2009 Table 2, section 6.1.2.2
1615 // IEEE 802.15.4d-2009 Table 2, section 6.1.2.2
1616 switch (phyOption)
1617 {
1619 // IEEE 802.15.4-2006 868 MHz BPSK (Page 0, Channel 0)
1622 break;
1624 // IEEE 802.15.4-2006 915 MHz BPSK (Page 0, Channels 1 to 10)
1627 break;
1629 // IEEE 802.15.4d-2009 950 MHz BPSK (Page 6, Channels 0 to 9)
1632 break;
1634 // IEEE 802.15.4-2006 868 MHz ASK (Page 1, Channel 0)
1637 break;
1639 // IEEE 802.15.4-2006 915 MHz ASK (Page 1, Channel 1 to 10)
1642 break;
1644 // IEEE 802.15.4c-2009 780 MHz O-QPSK (Page 5, Channel 0 to 3)
1647 break;
1649 // IEEE 802.15.4-2006 868 MHz O-QPSK (Page 2, Channel 0)
1652 break;
1654 // IEEE 802.15.4-2006 915 MHz O-QPSK (Page 2, Channels 1 to 10)
1657 break;
1659 // IEEE 802.15.4-2009 2.4 GHz O-QPSK (Page 0, Channels 11 to 26)
1662 break;
1664 // IEEE 802.15.4-2006 Use Non-Registered Page and channel
1667 break;
1668 }
1669
1671
1672 m_phyOption = phyOption;
1673 // TODO: Fix/Update list when more modulations are supported.
1674 // IEEE 802.15.4-2006, Table 23
1675 // 5 MSB = Page number, 27 LSB = Supported Channels (1= supported, 0 Not supported)
1676 // Currently only page 0, channels 11-26 supported.
1678 0x7FFF800; // Page 0 should support, Channels 0 to 26 (0x07FFFFFF)
1679
1680 for (int i = 1; i <= 31; i++)
1681 {
1682 // Page 1 to 31, No support (Page set to 31, all channels 0)
1684 }
1685
1686 m_edPower.averagePower = 0.0;
1689
1690 // TODO: What is the RX sensibility that should be set for other frequencies?
1691 // default -110 dBm in W for 2.4 GHz
1692 m_rxSensitivity = pow(10.0, -106.58 / 10.0) / 1000.0;
1693 LrWpanSpectrumValueHelper psdHelper;
1698 m_signal = Create<LrWpanInterferenceHelper>(m_noise->GetSpectrumModel());
1700 Ptr<Packet> none_packet = nullptr;
1701 Ptr<LrWpanSpectrumSignalParameters> none_params = nullptr;
1702 m_currentRxPacket = std::make_pair(none_params, true);
1703 m_currentTxPacket = std::make_pair(none_packet, true);
1704 m_errorModel = nullptr;
1705}
1706
1709{
1710 NS_LOG_FUNCTION(this);
1711 return m_phyOption;
1712}
1713
1714void
1716{
1717 NS_LOG_FUNCTION(this << txPsd);
1718 NS_ASSERT(txPsd);
1719 m_txPsd = txPsd;
1720 NS_LOG_INFO("\t computed tx_psd: " << *txPsd << "\t stored tx_psd: " << *m_txPsd);
1721}
1722
1723void
1725{
1726 NS_LOG_FUNCTION(this << noisePsd);
1727 NS_LOG_INFO("\t computed noise_psd: " << *noisePsd);
1728 NS_ASSERT(noisePsd);
1729 m_noise = noisePsd;
1730}
1731
1734{
1735 NS_LOG_FUNCTION(this);
1736 return m_noise;
1737}
1738
1739void
1741{
1742 NS_LOG_FUNCTION(this << e);
1743 NS_ASSERT(e);
1744 m_errorModel = e;
1745}
1746
1749{
1750 NS_LOG_FUNCTION(this);
1751 return m_errorModel;
1752}
1753
1754uint64_t
1756{
1757 NS_LOG_FUNCTION(this);
1759
1762}
1763
1764double
1766{
1767 NS_LOG_FUNCTION(this);
1769
1771}
1772
1773double
1775{
1776 double powerWatts =
1779 return WToDbm(powerWatts);
1780}
1781
1782int8_t
1784{
1786
1787 // The nominal Tx power is stored in the PIB as a 6-bit
1788 // twos-complement, signed number.
1789
1790 // The 5 LSBs can be copied - as their representation
1791 // is the same for unsigned and signed integers.
1792 int8_t nominalTxPower = phyTransmitPower & 0x1F;
1793
1794 // Now check the 6th LSB (the "sign" bit).
1795 // It's a twos-complement format, so the "sign"
1796 // bit represents -2^5 = -32.
1797 if (phyTransmitPower & 0x20)
1798 {
1799 nominalTxPower -= 32;
1800 }
1801 return nominalTxPower;
1802}
1803
1804double
1806{
1807 return (10 * log10(1000 * watt));
1808}
1809
1810double
1812{
1813 return (pow(10.0, dbm / 10.0) / 1000.0);
1814}
1815
1816int64_t
1818{
1819 NS_LOG_FUNCTION(this);
1820 m_random->SetStream(stream);
1821 return 1;
1822}
1823
1824void
1826{
1827 NS_LOG_FUNCTION(this << em);
1829}
1830
1831} // namespace ns3
#define max(a, b)
Definition: 80211b.c:43
bool IsNull() const
Check for null implementation.
Definition: callback.h:556
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:55
bool IsExpired() const
This method is syntactic sugar for the ns3::Simulator::IsExpired method.
Definition: event-id.cc:69
bool IsRunning() const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:76
Represent the LQI (Link Quality Estination).
uint8_t Get() const
Get the LQI value.
void Set(uint8_t lqi)
Set the LQI to the given value.
Make LrWpanPhy a SpectrumPhy so we can enable the eventual modeling of device interference.
Definition: lr-wpan-phy.h:251
double GetCurrentSignalPsd()
Get the current accumulated sum of signals in the transceiver including signals considered as interfe...
static TypeId GetTypeId()
Get the type ID.
Definition: lr-wpan-phy.cc:83
Ptr< const SpectrumValue > m_noise
The spectral density for for the noise.
Definition: lr-wpan-phy.h:797
void SetPdDataConfirmCallback(PdDataConfirmCallback c)
set the callback for the end of a TX, as part of the interconnections between the PHY and the MAC.
void SetPhyOption(LrWpanPhyOption phyOption)
Set the modulation option used by this PHY.
void EndTx()
Finish the transmission of a frame.
EventId m_setTRXState
Scheduler event of a currently running deferred transceiver state switch.
Definition: lr-wpan-phy.h:930
static const uint32_t aMaxPhyPacketSize
The maximum packet size accepted by the PHY.
Definition: lr-wpan-phy.h:264
Ptr< const SpectrumValue > GetNoisePowerSpectralDensity()
Get the noise power spectral density.
bool ChannelSupported(uint8_t channel)
Check if the given channel is supported by the PHY.
Definition: lr-wpan-phy.cc:949
Ptr< SpectrumValue > m_txPsd
The transmit power spectral density.
Definition: lr-wpan-phy.h:792
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:862
void SetPlmeGetAttributeConfirmCallback(PlmeGetAttributeConfirmCallback c)
set the callback for the end of an GetAttribute, as part of the interconnections between the PHY and ...
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:787
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 between the PHY and t...
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:762
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:729
Ptr< UniformRandomVariable > m_random
Uniform random variable stream.
Definition: lr-wpan-phy.h:940
TracedValue< LrWpanPhyEnumeration > m_trxState
The current transceiver state.
Definition: lr-wpan-phy.h:813
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:692
void SetPlmeEdConfirmCallback(PlmeEdConfirmCallback c)
set the callback for the end of an ED, as part of the interconnections between the PHY and the MAC.
LrWpanPhyOption GetMyPhyOption()
Get the currently configured PHY option.
void EndRx(Ptr< SpectrumSignalParameters > params)
Finish the reception of a frame.
Definition: lr-wpan-phy.cc:490
PlmeCcaConfirmCallback m_plmeCcaConfirmCallback
This callback is used to report CCA status to the MAC or CSMA/CA.
Definition: lr-wpan-phy.h:838
bool PhyIsBusy() const
Check if the PHY is busy, which is the case if the PHY is currently sending or receiving a frame.
Ptr< NetDevice > m_device
The configured net device.
Definition: lr-wpan-phy.h:777
uint64_t GetPhySHRDuration() const
Get the duration of the SHR (preamble and SFD) in symbols, depending on the currently selected channe...
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:592
Ptr< ErrorModel > m_postReceptionErrorModel
Error model for receive packet events.
Definition: lr-wpan-phy.h:942
Ptr< LrWpanErrorModel > m_errorModel
The error model describing the bit and packet error rates.
Definition: lr-wpan-phy.h:802
uint8_t GetCurrentPage() const
Get The current channel page number in use in this PHY from the PIB attributes.
bool PageSupported(uint8_t page)
Check if the given page is supported by the PHY.
Definition: lr-wpan-phy.cc:967
void DoInitialize() override
Initialize() implementation.
Definition: lr-wpan-phy.cc:166
void EndEd()
Called at the end of the ED procedure.
PlmeEdConfirmCallback m_plmeEdConfirmCallback
This callback is used to report ED status to the MAC.
Definition: lr-wpan-phy.h:844
std::pair< Ptr< LrWpanSpectrumSignalParameters >, bool > m_currentRxPacket
Statusinformation of the currently received packet.
Definition: lr-wpan-phy.h:907
EventId m_ccaRequest
Scheduler event of a currently running CCA request.
Definition: lr-wpan-phy.h:920
void CheckInterference()
Check if the interference destroys a frame currently received.
Definition: lr-wpan-phy.cc:440
void EndCca()
Called at the end of the CCA.
LrWpanEdPower m_edPower
Helper value for tracking the average power during ED.
Definition: lr-wpan-phy.h:872
Ptr< LrWpanErrorModel > GetErrorModel() const
get the error model in use
uint8_t GetCurrentChannelNum() const
Get The current channel number in use in this PHY from the PIB attributes.
PacketAndStatus m_currentTxPacket
Statusinformation of the currently transmitted packet.
Definition: lr-wpan-phy.h:915
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:716
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:551
void SetMobility(Ptr< MobilityModel > m) override
Set the mobility model associated with this device.
Definition: lr-wpan-phy.cc:255
Ptr< SpectrumChannel > m_channel
The channel attached to this transceiver.
Definition: lr-wpan-phy.h:782
PdDataConfirmCallback m_pdDataConfirmCallback
This callback is used to report packet transmission status to the MAC layer.
Definition: lr-wpan-phy.h:832
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:684
Ptr< MobilityModel > m_mobility
The mobility model used by the PHY.
Definition: lr-wpan-phy.h:772
double GetPhySymbolsPerOctet() const
Get the number of symbols per octet, depending on the currently selected channel.
double m_ccaPeakPower
Helper value for the peak power value during CCA.
Definition: lr-wpan-phy.h:877
LrWpanPhyOption m_phyOption
The currently configured PHY type.
Definition: lr-wpan-phy.h:867
EventId m_edRequest
Scheduler event of a currently running ED request.
Definition: lr-wpan-phy.h:925
LrWpanPhyPibAttributes m_phyPIBAttributes
The current PHY PIB attributes.
Definition: lr-wpan-phy.h:807
double m_rxSensitivity
The receiver sensitivity.
Definition: lr-wpan-phy.h:882
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:819
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
void EndSetTRXState()
Called after applying a deferred transceiver state switch.
Ptr< LrWpanInterferenceHelper > m_signal
The accumulated signals currently received by the transceiver, including the signal of a possibly rec...
Definition: lr-wpan-phy.h:894
int8_t GetNominalTxPowerFromPib(uint8_t phyTransmitPower)
Calculates the nominal transmit power of the device in decibels relative to 1 mW according to the rep...
Ptr< MobilityModel > GetMobility() const override
Get the associated MobilityModel instance.
Definition: lr-wpan-phy.cc:241
PdDataIndicationCallback m_pdDataIndicationCallback
This callback is used to notify incoming packets to the MAC layer.
Definition: lr-wpan-phy.h:826
Time GetPpduHeaderTxTime()
Calculate the time required for sending the PPDU header, that is the preamble, SFD and PHR.
void DoDispose() override
Destructor implementation.
Definition: lr-wpan-phy.cc:191
~LrWpanPhy() override
Definition: lr-wpan-phy.cc:161
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:723
double WToDbm(double watt)
Transform watts (W) to decibels milliwatts (DBm).
void SetChannel(Ptr< SpectrumChannel > c) override
Set the channel attached to this device.
Definition: lr-wpan-phy.cc:262
void CcaCancel()
Cancel an ongoing CCA request.
Definition: lr-wpan-phy.cc:695
PlmeSetTRXStateConfirmCallback m_plmeSetTRXStateConfirmCallback
This callback is used to report transceiver state change status to the MAC.
Definition: lr-wpan-phy.h:856
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:990
PlmeGetAttributeConfirmCallback m_plmeGetAttributeConfirmCallback
This callback is used to report requested attribute values back to the MAC.
Definition: lr-wpan-phy.h:850
void SetPdDataIndicationCallback(PdDataIndicationCallback c)
set the callback for the end of a RX, as part of the interconnections between the PHY and the MAC.
EventId m_pdDataRequest
Scheduler event of a currently running data transmission request.
Definition: lr-wpan-phy.h:935
Ptr< NetDevice > GetDevice() const override
Get the associated NetDevice instance.
Definition: lr-wpan-phy.cc:234
void PlmeEdRequest()
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:702
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:558
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:700
void SetPostReceptionErrorModel(const Ptr< ErrorModel > em)
Attach a receive ErrorModel to the LrWpanPhy.
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:708
bool m_isRxCanceled
Indicates if the reception of frame has been canceled.
Definition: lr-wpan-phy.h:887
void SetPlmeSetAttributeConfirmCallback(PlmeSetAttributeConfirmCallback c)
set the callback for the end of an SetAttribute, as part of the interconnections between the PHY and ...
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:899
Ptr< SpectrumChannel > GetChannel()
Get the currently attached channel.
Definition: lr-wpan-phy.cc:269
TracedCallback< Time, LrWpanPhyEnumeration, LrWpanPhyEnumeration > m_trxStateLogger
The trace source fired when the phy layer changes the transceiver state.
Definition: lr-wpan-phy.h:733
void StartRx(Ptr< SpectrumSignalParameters > params) override
Notify the SpectrumPhy instance of an incoming waveform.
Definition: lr-wpan-phy.cc:304
LrWpanPhy()
Default constructor.
Definition: lr-wpan-phy.cc:140
void PlmeCcaRequest()
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:668
void SetDevice(Ptr< NetDevice > d) override
Set the associated NetDevice instance.
Definition: lr-wpan-phy.cc:248
void CancelEd(LrWpanPhyEnumeration state)
Cancel an ongoing ED procedure.
void SetAntenna(Ptr< AntennaModel > a)
Set the attached antenna.
Definition: lr-wpan-phy.cc:297
void SetNoisePowerSpectralDensity(Ptr< const SpectrumValue > noisePsd)
Set the noise power spectral density.
Ptr< Object > GetAntenna() const override
Get the AntennaModel used by this SpectrumPhy instance for transmission and/or reception.
Definition: lr-wpan-phy.cc:290
void SetPlmeCcaConfirmCallback(PlmeCcaConfirmCallback c)
set the callback for the end of a CCA, as part of the interconnections between the PHY and the MAC.
Ptr< const SpectrumModel > GetRxSpectrumModel() const override
Definition: lr-wpan-phy.cc:276
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:258
virtual void DoDispose()
Destructor implementation.
Definition: object.cc:353
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
Definition: packet.cc:986
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:863
Ptr< Packet > Copy() const
performs a COW copy of the packet.
Definition: packet.cc:131
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
Definition: packet.cc:1002
bool ReplacePacketTag(Tag &tag)
Replace the value of a packet tag.
Definition: packet.cc:994
Hold objects of type Ptr<T>.
Definition: pointer.h:37
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(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:568
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:199
Abstract base class for Spectrum-aware PHY layers.
Definition: spectrum-phy.h:46
Ptr< const SpectrumModel > GetSpectrumModel() const
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
@ MS
millisecond
Definition: nstime.h:117
int64_t GetTimeStep() const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:444
a unique identifier for an interface.
Definition: type-id.h:60
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:935
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:66
#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:86
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Definition: pointer.h:230
Callback< R, Args... > MakeNullCallback()
Definition: callback.h:734
#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:160
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
Definition: abort.h:76
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:282
#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:261
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
LrWpanPhyOption
This Phy option will be used to index various Tables in IEEE802.15.4-2011.
Definition: lr-wpan-phy.h:89
LrWpanPhyEnumeration
IEEE802.15.4-2006 PHY Emumerations Table 18 in section 6.2.3.
Definition: lr-wpan-phy.h:109
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:90
@ IEEE_802_15_4_915MHZ_OQPSK
Definition: lr-wpan-phy.h:97
@ IEEE_802_15_4_868MHZ_ASK
Definition: lr-wpan-phy.h:93
@ IEEE_802_15_4_950MHZ_BPSK
Definition: lr-wpan-phy.h:92
@ IEEE_802_15_4_868MHZ_OQPSK
Definition: lr-wpan-phy.h:96
@ IEEE_802_15_4_780MHZ_OQPSK
Definition: lr-wpan-phy.h:95
@ IEEE_802_15_4_2_4GHZ_OQPSK
Definition: lr-wpan-phy.h:98
@ IEEE_802_15_4_915MHZ_ASK
Definition: lr-wpan-phy.h:94
@ IEEE_802_15_4_915MHZ_BPSK
Definition: lr-wpan-phy.h:91
@ IEEE_802_15_4_INVALID_PHY_OPTION
Definition: lr-wpan-phy.h:99
@ IEEE_802_15_4_PHY_BUSY_RX
Definition: lr-wpan-phy.h:111
@ IEEE_802_15_4_PHY_UNSUPPORTED_ATTRIBUTE
Definition: lr-wpan-phy.h:120
@ IEEE_802_15_4_PHY_BUSY
Definition: lr-wpan-phy.h:110
@ IEEE_802_15_4_PHY_SUCCESS
Definition: lr-wpan-phy.h:117
@ IEEE_802_15_4_PHY_UNSPECIFIED
Definition: lr-wpan-phy.h:122
@ IEEE_802_15_4_PHY_TRX_OFF
Definition: lr-wpan-phy.h:118
@ IEEE_802_15_4_PHY_FORCE_TRX_OFF
Definition: lr-wpan-phy.h:113
@ IEEE_802_15_4_PHY_BUSY_TX
Definition: lr-wpan-phy.h:112
@ IEEE_802_15_4_PHY_RX_ON
Definition: lr-wpan-phy.h:116
@ IEEE_802_15_4_PHY_TX_ON
Definition: lr-wpan-phy.h:119
@ IEEE_802_15_4_PHY_INVALID_PARAMETER
Definition: lr-wpan-phy.h:115
@ IEEE_802_15_4_PHY_IDLE
Definition: lr-wpan-phy.h:114
@ 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:1338
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:81
double averagePower
Average measured power.
Definition: lr-wpan-phy.h:53
Time lastUpdate
Last update time.
Definition: lr-wpan-phy.h:54
Time measurementLength
Total measurement period.
Definition: lr-wpan-phy.h:55
double symbolRate
symbol rate
Definition: lr-wpan-phy.h:67
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:164
uint8_t phyCCAMode
CCA mode.
Definition: lr-wpan-phy.h:166
uint8_t phyCurrentPage
Current channel page.
Definition: lr-wpan-phy.h:167
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:79
double phr
Number of symbols for the PHR.
Definition: lr-wpan-phy.h:80
double shrPreamble
Number of symbols for the SHR preamble.
Definition: lr-wpan-phy.h:78
Time duration
The duration of the packet transmission.
Ptr< SpectrumValue > psd
The Power Spectral Density of the waveform, in linear units.