A Discrete-Event Network Simulator
API
lr-wpan-mac.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 * Authors:
19 * Gary Pei <guangyu.pei@boeing.com>
20 * kwong yin <kwong-sang.yin@boeing.com>
21 * Tom Henderson <thomas.r.henderson@boeing.com>
22 * Sascha Alexander Jopen <jopen@cs.uni-bonn.de>
23 * Erwan Livolant <erwan.livolant@inria.fr>
24 * Alberto Gallegos Ramonet <ramonet@fc.ritsumei.ac.jp>
25 */
26#include "lr-wpan-mac.h"
27#include "lr-wpan-csmaca.h"
28#include "lr-wpan-mac-header.h"
30#include "lr-wpan-mac-trailer.h"
31#include <ns3/simulator.h>
32#include <ns3/log.h>
33#include <ns3/uinteger.h>
34#include <ns3/node.h>
35#include <ns3/packet.h>
36#include <ns3/random-variable-stream.h>
37#include <ns3/double.h>
38
39#undef NS_LOG_APPEND_CONTEXT
40#define NS_LOG_APPEND_CONTEXT \
41 std::clog << "[address " << m_shortAddress << "] ";
42
43namespace ns3 {
44
45NS_LOG_COMPONENT_DEFINE ("LrWpanMac");
46
48
49//IEEE 802.15.4-2011 Table 51
53const uint32_t LrWpanMac::aBaseSuperframeDuration = aBaseSlotDuration * aNumSuperframeSlots;
56
57TypeId
59{
60 static TypeId tid = TypeId ("ns3::LrWpanMac")
61 .SetParent<Object> ()
62 .SetGroupName ("LrWpan")
63 .AddConstructor<LrWpanMac> ()
64 .AddAttribute ("PanId", "16-bit identifier of the associated PAN",
67 MakeUintegerChecker<uint16_t> ())
68 .AddTraceSource ("MacTxEnqueue",
69 "Trace source indicating a packet has been "
70 "enqueued in the transaction queue",
72 "ns3::Packet::TracedCallback")
73 .AddTraceSource ("MacTxDequeue",
74 "Trace source indicating a packet has was "
75 "dequeued from the transaction queue",
77 "ns3::Packet::TracedCallback")
78 .AddTraceSource ("MacTx",
79 "Trace source indicating a packet has "
80 "arrived for transmission by this device",
82 "ns3::Packet::TracedCallback")
83 .AddTraceSource ("MacTxOk",
84 "Trace source indicating a packet has been "
85 "successfully sent",
87 "ns3::Packet::TracedCallback")
88 .AddTraceSource ("MacTxDrop",
89 "Trace source indicating a packet has been "
90 "dropped during transmission",
92 "ns3::Packet::TracedCallback")
93 .AddTraceSource ("MacPromiscRx",
94 "A packet has been received by this device, "
95 "has been passed up from the physical layer "
96 "and is being forwarded up the local protocol stack. "
97 "This is a promiscuous trace,",
99 "ns3::Packet::TracedCallback")
100 .AddTraceSource ("MacRx",
101 "A packet has been received by this device, "
102 "has been passed up from the physical layer "
103 "and is being forwarded up the local protocol stack. "
104 "This is a non-promiscuous trace,",
106 "ns3::Packet::TracedCallback")
107 .AddTraceSource ("MacRxDrop",
108 "Trace source indicating a packet was received, "
109 "but dropped before being forwarded up the stack",
111 "ns3::Packet::TracedCallback")
112 .AddTraceSource ("Sniffer",
113 "Trace source simulating a non-promiscuous "
114 "packet sniffer attached to the device",
116 "ns3::Packet::TracedCallback")
117 .AddTraceSource ("PromiscSniffer",
118 "Trace source simulating a promiscuous "
119 "packet sniffer attached to the device",
121 "ns3::Packet::TracedCallback")
122 .AddTraceSource ("MacStateValue",
123 "The state of LrWpan Mac",
125 "ns3::TracedValueCallback::LrWpanMacState")
126 .AddTraceSource ("MacIncSuperframeStatus",
127 "The period status of the incoming superframe",
129 "ns3::TracedValueCallback::SuperframeState")
130 .AddTraceSource ("MacOutSuperframeStatus",
131 "The period status of the outgoing superframe",
133 "ns3::TracedValueCallback::SuperframeState")
134 .AddTraceSource ("MacState",
135 "The state of LrWpan Mac",
137 "ns3::LrWpanMac::StateTracedCallback")
138 .AddTraceSource ("MacSentPkt",
139 "Trace source reporting some information about "
140 "the sent packet",
142 "ns3::LrWpanMac::SentTracedCallback")
143 .AddTraceSource ("IfsEnd",
144 "Trace source reporting the end of an "
145 "Interframe space (IFS) ",
147 "ns3::Packet::TracedCallback")
148 ;
149 return tid;
150}
151
153{
154
155 // First set the state to a known value, call ChangeMacState to fire trace source.
157
159
162
163 m_macRxOnWhenIdle = true;
164 m_macPanId = 0xffff;
168 m_macPromiscuousMode = false;
172 m_txPkt = 0;
173 m_ifs = 0;
174
175 m_macLIFSPeriod = 40;
176 m_macSIFSPeriod = 12;
177
178 m_macBeaconOrder = 15;
180 m_macTransactionPersistanceTime = 500; //0x01F5
181 m_macAutoRequest = true;
182
185 m_beaconTrackingOn = false;
187
188
189 Ptr<UniformRandomVariable> uniformVar = CreateObject<UniformRandomVariable> ();
190 uniformVar->SetAttribute ("Min", DoubleValue (0.0));
191 uniformVar->SetAttribute ("Max", DoubleValue (255.0));
192 m_macDsn = SequenceNumber8 (uniformVar->GetValue ());
193 m_macBsn = SequenceNumber8 (uniformVar->GetValue ());
194 m_shortAddress = Mac16Address ("00:00");
195}
196
198{}
199
200void
202{
204 {
205 m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_RX_ON);
206 }
207 else
208 {
209 m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_TRX_OFF);
210 }
211
213}
214
215void
217{
218 if (m_csmaCa != 0)
219 {
220 m_csmaCa->Dispose ();
221 m_csmaCa = 0;
222 }
223 m_txPkt = 0;
224 for (uint32_t i = 0; i < m_txQueue.size (); i++)
225 {
226 m_txQueue[i]->txQPkt = 0;
227 delete m_txQueue[i];
228 }
229 m_txQueue.clear ();
230 m_phy = 0;
231 m_mcpsDataIndicationCallback = MakeNullCallback< void, McpsDataIndicationParams, Ptr<Packet> > ();
232 m_mcpsDataConfirmCallback = MakeNullCallback< void, McpsDataConfirmParams > ();
233
235
237}
238
239bool
241{
242 return m_macRxOnWhenIdle;
243}
244
245void
246LrWpanMac::SetRxOnWhenIdle (bool rxOnWhenIdle)
247{
248 NS_LOG_FUNCTION (this << rxOnWhenIdle);
249 m_macRxOnWhenIdle = rxOnWhenIdle;
250
252 {
254 {
255 m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_RX_ON);
256 }
257 else
258 {
259 m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_TRX_OFF);
260 }
261 }
262}
263
264void
266{
267 //NS_LOG_FUNCTION (this << address);
269}
270
271void
273{
274 //NS_LOG_FUNCTION (this << address);
276}
277
278
281{
282 NS_LOG_FUNCTION (this);
283 return m_shortAddress;
284}
285
288{
289 NS_LOG_FUNCTION (this);
290 return m_selfExt;
291}
292void
294{
295 NS_LOG_FUNCTION (this << p);
296
297 McpsDataConfirmParams confirmParams;
298 confirmParams.m_msduHandle = params.m_msduHandle;
299
300 // TODO: We need a drop trace for the case that the packet is too large or the request parameters are maleformed.
301 // The current tx drop trace is not suitable, because packets dropped using this trace carry the mac header
302 // and footer, while packets being dropped here do not have them.
303
305 m_macDsn++;
306
308 {
309 // Note, this is just testing maximum theoretical frame size per the spec
310 // The frame could still be too large once headers are put on
311 // in which case the phy will reject it instead
312 NS_LOG_ERROR (this << " packet too big: " << p->GetSize ());
315 {
316 m_mcpsDataConfirmCallback (confirmParams);
317 }
318 return;
319 }
320
321 if ((params.m_srcAddrMode == NO_PANID_ADDR)
322 && (params.m_dstAddrMode == NO_PANID_ADDR))
323 {
324 NS_LOG_ERROR (this << " Can not send packet with no Address field" );
327 {
328 m_mcpsDataConfirmCallback (confirmParams);
329 }
330 return;
331 }
332 switch (params.m_srcAddrMode)
333 {
334 case NO_PANID_ADDR:
335 macHdr.SetSrcAddrMode (params.m_srcAddrMode);
336 macHdr.SetNoPanIdComp ();
337 break;
339 NS_ABORT_MSG ("Can not set source address type to ADDR_MODE_RESERVED. Aborting.");
340 break;
341 case SHORT_ADDR:
342 macHdr.SetSrcAddrMode (params.m_srcAddrMode);
344 break;
345 case EXT_ADDR:
346 macHdr.SetSrcAddrMode (params.m_srcAddrMode);
348 break;
349 default:
350 NS_LOG_ERROR (this << " Can not send packet with incorrect Source Address mode = " << params.m_srcAddrMode);
353 {
354 m_mcpsDataConfirmCallback (confirmParams);
355 }
356 return;
357 }
358 switch (params.m_dstAddrMode)
359 {
360 case NO_PANID_ADDR:
361 macHdr.SetDstAddrMode (params.m_dstAddrMode);
362 macHdr.SetNoPanIdComp ();
363 break;
365 NS_ABORT_MSG ("Can not set destination address type to ADDR_MODE_RESERVED. Aborting.");
366 break;
367 case SHORT_ADDR:
368 macHdr.SetDstAddrMode (params.m_dstAddrMode);
369 macHdr.SetDstAddrFields (params.m_dstPanId, params.m_dstAddr);
370 break;
371 case EXT_ADDR:
372 macHdr.SetDstAddrMode (params.m_dstAddrMode);
373 macHdr.SetDstAddrFields (params.m_dstPanId, params.m_dstExtAddr);
374 break;
375 default:
376 NS_LOG_ERROR (this << " Can not send packet with incorrect Destination Address mode = " << params.m_dstAddrMode);
379 {
380 m_mcpsDataConfirmCallback (confirmParams);
381 }
382 return;
383 }
384
385 macHdr.SetSecDisable ();
386 //extract the first 3 bits in TxOptions
387 int b0 = params.m_txOptions & TX_OPTION_ACK;
388 int b1 = params.m_txOptions & TX_OPTION_GTS;
389 int b2 = params.m_txOptions & TX_OPTION_INDIRECT;
390
391 if (b0 == TX_OPTION_ACK)
392 {
393 // Set AckReq bit only if the destination is not the broadcast address.
394 if (macHdr.GetDstAddrMode () == SHORT_ADDR)
395 {
396 // short address and ACK requested.
397 Mac16Address shortAddr = macHdr.GetShortDstAddr ();
398 if (shortAddr.IsBroadcast () || shortAddr.IsMulticast ())
399 {
400 NS_LOG_LOGIC ("LrWpanMac::McpsDataRequest: requested an ACK on broadcast or multicast destination (" << shortAddr << ") - forcefully removing it.");
401 macHdr.SetNoAckReq ();
402 params.m_txOptions &= ~uint8_t (TX_OPTION_ACK);
403 }
404 else
405 {
406 macHdr.SetAckReq ();
407 }
408 }
409 else
410 {
411 // other address (not short) and ACK requested
412 macHdr.SetAckReq ();
413 }
414 }
415 else
416 {
417 macHdr.SetNoAckReq ();
418 }
419
420
421 if (b1 == TX_OPTION_GTS)
422 {
423 //TODO:GTS Transmission
424 }
425 else if (b2 == TX_OPTION_INDIRECT)
426 {
427 // Indirect Tx
428 // A COORDINATOR will save the packet in the pending queue and await for data
429 // requests from its associated devices. The devices are aware of pending data,
430 // from the pending bit information extracted from the received beacon.
431 // A DEVICE must be tracking beacons (MLME-SYNC.request is running) before attempting
432 // request data from the coordinator.
433
434
435 //TODO: Check if the current device is coordinator or PAN coordinator
436 p->AddHeader (macHdr);
437
438 LrWpanMacTrailer macTrailer;
439 // Calculate FCS if the global attribute ChecksumEnable is set.
441 {
442 macTrailer.EnableFcs (true);
443 macTrailer.SetFcs (p);
444 }
445 p->AddTrailer (macTrailer);
446
447 if (m_txQueue.size () == m_txQueue.max_size ())
448 {
451 {
452 m_mcpsDataConfirmCallback (confirmParams);
453 }
454 }
455 else
456 {
457 IndTxQueueElement *indTxQElement = new IndTxQueueElement;
458 uint64_t unitPeriodSymbols;
459 Time expireTime;
460
461 if (m_macBeaconOrder == 15)
462 {
463 unitPeriodSymbols = aBaseSuperframeDuration;
464 }
465 else
466 {
467 unitPeriodSymbols = ((uint64_t) 1 << m_macBeaconOrder) * aBaseSuperframeDuration;
468 }
469
470 //TODO: check possible incorrect expire time here.
471
473 * MicroSeconds (unitPeriodSymbols * 1000 * 1000 / m_phy->GetDataOrSymbolRate (false));
474 indTxQElement->expireTime = expireTime;
475 indTxQElement->txQMsduHandle = params.m_msduHandle;
476 indTxQElement->txQPkt = p;
477
478 m_indTxQueue.push_back (indTxQElement);
479
480 std::cout << "Indirect Transmission Pushed | Elements in the queue: " << m_indTxQueue.size ()
481 << " " << "Element to expire in: " << expireTime.GetSeconds () << "secs\n";
482 }
483 }
484 else
485 {
486 // Direct Tx
487 // From this point the packet will be pushed to a Tx queue and immediately
488 // use a slotted (beacon-enabled) or unslotted (nonbeacon-enabled) version of CSMA/CA
489 // before sending the packet, depending on whether it has previously
490 // received a valid beacon or not.
491
492 p->AddHeader (macHdr);
493
494 LrWpanMacTrailer macTrailer;
495 // Calculate FCS if the global attribute ChecksumEnable is set.
497 {
498 macTrailer.EnableFcs (true);
499 macTrailer.SetFcs (p);
500 }
501 p->AddTrailer (macTrailer);
502
504
505 TxQueueElement *txQElement = new TxQueueElement;
506 txQElement->txQMsduHandle = params.m_msduHandle;
507 txQElement->txQPkt = p;
508 m_txQueue.push_back (txQElement);
509 CheckQueue ();
510 }
511
512}
513
514
515void
517{
518 NS_LOG_FUNCTION (this);
520
521 MlmeStartConfirmParams confirmParams;
522
523
524 if (GetShortAddress () == Mac16Address ("ff:ff"))
525 {
526 NS_LOG_ERROR (this << " Invalid MAC short address" );
527 confirmParams.m_status = MLMESTART_NO_SHORT_ADDRESS;
529 {
530 m_mlmeStartConfirmCallback (confirmParams);
531 }
532 return;
533 }
534
535
536 if ( (params.m_logCh > 26)
537 || (params.m_bcnOrd > 15)
538 || (params.m_sfrmOrd > params.m_bcnOrd))
539 {
540 NS_LOG_ERROR (this << " One or more parameters are invalid" );
543 {
544 m_mlmeStartConfirmCallback (confirmParams);
545 }
546 return;
547 }
548
549
550 if (params.m_coorRealgn) //Coordinator Realignment
551 {
552 // TODO:: Send realignment request command frame in CSMA/CA
553 return;
554 }
555 else
556 {
557 if (params.m_panCoor)
558 {
559 m_panCoor = true;
560 m_macPanId = params.m_PanId;
561
562 // Setting Channel and Page in the LrWpanPhy
564 pibAttr.phyCurrentChannel = params.m_logCh;
565 pibAttr.phyCurrentPage = params.m_logChPage;
566 m_phy->PlmeSetAttributeRequest (LrWpanPibAttributeIdentifier::phyCurrentChannel,&pibAttr);
567 m_phy->PlmeSetAttributeRequest (LrWpanPibAttributeIdentifier::phyCurrentPage,&pibAttr);
568 }
569
570 NS_ASSERT (params.m_PanId != 0xffff);
571
572
573 m_macBeaconOrder = params.m_bcnOrd;
574 if (m_macBeaconOrder == 15)
575 {
576 //Non-beacon enabled PAN
579 m_csmaCa->SetUnSlottedCsmaCa ();
580
581 confirmParams.m_status = MLMESTART_SUCCESS;
583 {
584 m_mlmeStartConfirmCallback (confirmParams);
585 }
586 }
587 else
588 {
590 m_csmaCa->SetBatteryLifeExtension (params.m_battLifeExt);
591
592 m_csmaCa->SetSlottedCsmaCa ();
593
594 //TODO: Calculate the real Final CAP slot (requires GTS implementation)
595 // FinalCapSlot = Superframe duration slots - CFP slots.
596 // In the current implementation the value of the final cap slot is equal to
597 // the total number of possible slots in the superframe (15).
598 m_fnlCapSlot = 15;
599
602
603 //TODO: change the beacon sending according to the startTime parameter (if not PAN coordinator)
604
606 }
607 }
608}
609
610
611void
613{
614 NS_LOG_FUNCTION (this);
615 NS_ASSERT (params.m_logCh <= 26 && m_macPanId != 0xffff);
616
617 uint64_t symbolRate = (uint64_t) m_phy->GetDataOrSymbolRate (false); //symbols per second
618 //change phy current logical channel
620 pibAttr.phyCurrentChannel = params.m_logCh;
621 m_phy->PlmeSetAttributeRequest (LrWpanPibAttributeIdentifier::phyCurrentChannel,&pibAttr);
622
623 //Enable Phy receiver
624 m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_RX_ON);
625
626 uint64_t searchSymbols;
627 Time searchBeaconTime;
628
630 {
632 }
633
634 if (params.m_trackBcn)
635 {
637 //search for a beacon for a time = incomingSuperframe symbols + 960 symbols
638 searchSymbols = ((uint64_t) 1 << m_incomingBeaconOrder) + 1 * aBaseSuperframeDuration;
639 searchBeaconTime = Seconds ((double) searchSymbols / symbolRate);
640 m_beaconTrackingOn = true;
642 }
643 else
644 {
645 m_beaconTrackingOn = false;
646 }
647
648}
649
650
651void
653{
654 NS_LOG_FUNCTION (this);
655
657 m_macBsn++;
658
660
661 Ptr<Packet> beaconPacket = Create <Packet> ();
662}
663
664
665void
667{
668 NS_LOG_FUNCTION (this);
670
672 m_macBsn++;
673 BeaconPayloadHeader macPayload;
674 Ptr<Packet> beaconPacket = Create <Packet> ();
675 LrWpanMacTrailer macTrailer;
676
678 macHdr.SetDstAddrFields (GetPanId (),Mac16Address ("ff:ff"));
679
680 //see IEEE 802.15.4-2011 Section 5.1.2.4
681 if (GetShortAddress () == Mac16Address ("ff:fe"))
682 {
685 }
686 else
687 {
690 }
691
692 macHdr.SetSecDisable ();
693 macHdr.SetNoAckReq ();
694
696 macPayload.SetGtsFields (GetGtsFields ());
698
699 beaconPacket->AddHeader (macPayload);
700 beaconPacket->AddHeader (macHdr);
701
702 // Calculate FCS if the global attribute ChecksumEnable is set.
704 {
705 macTrailer.EnableFcs (true);
706 macTrailer.SetFcs (beaconPacket);
707 }
708
709 beaconPacket->AddTrailer (macTrailer);
710
711 //Set the Beacon packet to be transmitted
712 m_txPkt = beaconPacket;
713
715
716 NS_LOG_DEBUG ("Outgoing superframe Active Portion (Beacon + CAP + CFP): " << m_superframeDuration << " symbols");
717
719 m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_TX_ON);
720}
721
722
723void
725{
726 uint32_t activeSlot;
727 uint64_t capDuration;
728 Time endCapTime;
729 uint64_t symbolRate;
730
731 symbolRate = (uint64_t) m_phy->GetDataOrSymbolRate (false); //symbols per second
732
733 if (superframeType == OUTGOING)
734 {
736 activeSlot = m_superframeDuration / 16;
737 capDuration = activeSlot * (m_fnlCapSlot + 1);
738 endCapTime = Seconds ((double) capDuration / symbolRate);
739 // Obtain the end of the CAP by adjust the time it took to send the beacon
740 endCapTime -= (Simulator::Now () - m_macBeaconTxTime);
741
742 NS_LOG_DEBUG ("Outgoing superframe CAP duration " << (endCapTime.GetSeconds () * symbolRate) << " symbols (" << endCapTime.As (Time::S) << ")");
743 NS_LOG_DEBUG ("Active Slots duration " << activeSlot << " symbols");
744
745 m_capEvent = Simulator::Schedule (endCapTime,
747
748 }
749 else
750 {
752 activeSlot = m_incomingSuperframeDuration / 16;
753 capDuration = activeSlot * (m_incomingFnlCapSlot + 1);
754 endCapTime = Seconds ((double) capDuration / symbolRate);
755 // Obtain the end of the CAP by adjust the time it took to receive the beacon
756 endCapTime -= (Simulator::Now () - m_macBeaconRxTime);
757
758 NS_LOG_DEBUG ("Incoming superframe CAP duration " << (endCapTime.GetSeconds () * symbolRate) << " symbols (" << endCapTime.As (Time::S) << ")");
759 NS_LOG_DEBUG ("Active Slots duration " << activeSlot << " symbols");
760
761 m_capEvent = Simulator::Schedule (endCapTime,
763 }
764
765 CheckQueue ();
766
767}
768
769
770void
772{
773 uint32_t activeSlot;
774 uint64_t cfpDuration;
775 Time endCfpTime;
776 uint64_t symbolRate;
777
778 symbolRate = (uint64_t) m_phy->GetDataOrSymbolRate (false); //symbols per second
779
780 if (superframeType == INCOMING)
781 {
782 activeSlot = m_incomingSuperframeDuration / 16;
783 cfpDuration = activeSlot * (15 - m_incomingFnlCapSlot);
784 endCfpTime = Seconds ((double) cfpDuration / symbolRate);
785 if (cfpDuration > 0)
786 {
788 }
789
790 NS_LOG_DEBUG ("Incoming superframe CFP duration " << cfpDuration << " symbols (" << endCfpTime.As (Time::S) << ")");
791
794 }
795 else
796 {
797 activeSlot = m_superframeDuration / 16;
798 cfpDuration = activeSlot * (15 - m_fnlCapSlot);
799 endCfpTime = Seconds ((double) cfpDuration / symbolRate);
800
801 if (cfpDuration > 0)
802 {
804 }
805
806 NS_LOG_DEBUG ("Outgoing superframe CFP duration " << cfpDuration << " symbols (" << endCfpTime.As (Time::S) << ")");
807
808 m_cfpEvent = Simulator::Schedule (endCfpTime,
810
811 }
812 //TODO: Start transmit or receive GTS here.
813}
814
815
816void
818{
819 uint64_t inactiveDuration;
820 Time endInactiveTime;
821 uint64_t symbolRate;
822
823 symbolRate = (uint64_t) m_phy->GetDataOrSymbolRate (false); //symbols per second
824
825 if (superframeType == INCOMING)
826 {
828 endInactiveTime = Seconds ((double) inactiveDuration / symbolRate);
829
830 if (inactiveDuration > 0)
831 {
833 }
834
835 NS_LOG_DEBUG ("Incoming superframe Inactive Portion duration " << inactiveDuration << " symbols (" << endInactiveTime.As (Time::S) << ")");
836 m_beaconEvent = Simulator::Schedule (endInactiveTime, &LrWpanMac::AwaitBeacon, this);
837 }
838 else
839 {
840 inactiveDuration = m_beaconInterval - m_superframeDuration;
841 endInactiveTime = Seconds ((double) inactiveDuration / symbolRate);
842
843 if (inactiveDuration > 0)
844 {
846 }
847
848 NS_LOG_DEBUG ("Outgoing superframe Inactive Portion duration " << inactiveDuration << " symbols (" << endInactiveTime.As (Time::S) << ")");
850 }
851}
852
853void
855{
857
858 //TODO: If the device waits more than the expected time to receive the beacon (wait = 46 symbols for default beacon size)
859 // it should continue with the start of the incoming CAP even if it did not receive the beacon.
860 // At the moment, the start of the incoming CAP is only triggered if the beacon is received.
861 // See MLME-SyncLoss for details.
862
863
864}
865
866void
868{
869 uint64_t symbolRate = (uint64_t) m_phy->GetDataOrSymbolRate (false); //symbols per second
870
872 {
873 MlmeSyncLossIndicationParams syncLossParams;
874 //syncLossParams.m_logCh =
875 syncLossParams.m_lossReason = MLMESYNCLOSS_BEACON_LOST;
876 syncLossParams.m_panId = m_macPanId;
877 m_mlmeSyncLossIndicationCallback (syncLossParams);
878
879 m_beaconTrackingOn = false;
881 }
882 else
883 {
885
886 //Search for one more beacon
887 uint64_t searchSymbols;
888 Time searchBeaconTime;
889 searchSymbols = ((uint64_t) 1 << m_incomingBeaconOrder) + 1 * aBaseSuperframeDuration;
890 searchBeaconTime = Seconds ((double) searchSymbols / symbolRate);
892
893 }
894}
895
896
897void
899{
900 NS_LOG_FUNCTION (this);
901 // Pull a packet from the queue and start sending if we are not already sending.
902 if (m_lrWpanMacState == MAC_IDLE && !m_txQueue.empty () && !m_setMacState.IsRunning ())
903 {
904 //TODO: this should check if the node is a coordinator and using the outcoming superframe not just the PAN coordinator
905 if (m_csmaCa->IsUnSlottedCsmaCa () || (m_outSuperframeStatus == CAP && m_panCoor) || m_incSuperframeStatus == CAP)
906 {
907 // check MAC is not in a IFS
908 if (!m_ifsEvent.IsRunning ())
909 {
910 TxQueueElement *txQElement = m_txQueue.front ();
911 m_txPkt = txQElement->txQPkt;
913 }
914 }
915 }
916}
917
918
921{
922 SuperframeField sfrmSpec;
923
926 sfrmSpec.SetFinalCapSlot (m_fnlCapSlot);
927
928 if (m_csmaCa->GetBatteryLifeExtension ())
929 {
930 sfrmSpec.SetBattLifeExt (true);
931 }
932
933 if (m_panCoor)
934 {
935 sfrmSpec.SetPanCoor (true);
936 }
937 //TODO: It is possible to do association using Beacons,
938 // however, the current implementation only support manual association.
939 // The association permit should be set here.
940
941 return sfrmSpec;
942}
943
946{
947 GtsFields gtsFields;
948
949 // TODO: Logic to populate the GTS Fields from local information here
950
951 return gtsFields;
952}
953
956{
957 PendingAddrFields pndAddrFields;
958
959 // TODO: Logic to populate the Pending Address Fields from local information here
960 return pndAddrFields;
961}
962
963
964void
966{
967 m_csmaCa = csmaCa;
968}
969
970void
972{
973 m_phy = phy;
974}
975
978{
979 return m_phy;
980}
981
982void
984{
986}
987
988void
990{
992}
993
994void
996{
998}
999
1000void
1002{
1004}
1005
1006void
1008{
1010}
1011
1012void
1014{
1016}
1017
1018void
1020{
1022 NS_LOG_FUNCTION (this << psduLength << p << (uint16_t)lqi);
1023
1024 bool acceptFrame;
1025
1026 // from sec 7.5.6.2 Reception and rejection, Std802.15.4-2006
1027 // level 1 filtering, test FCS field and reject if frame fails
1028 // level 2 filtering if promiscuous mode pass frame to higher layer otherwise perform level 3 filtering
1029 // level 3 filtering accept frame
1030 // if Frame type and version is not reserved, and
1031 // if there is a dstPanId then dstPanId=m_macPanId or broadcastPanI, and
1032 // if there is a shortDstAddr then shortDstAddr =shortMacAddr or broadcastAddr, and
1033 // if beacon frame then srcPanId = m_macPanId
1034 // if only srcAddr field in Data or Command frame,accept frame if srcPanId=m_macPanId
1035
1036 Ptr<Packet> originalPkt = p->Copy (); // because we will strip headers
1037 uint64_t symbolRate = (uint64_t) m_phy->GetDataOrSymbolRate (false); //symbols per second
1038 m_promiscSnifferTrace (originalPkt);
1039
1040 m_macPromiscRxTrace (originalPkt);
1041 // XXX no rejection tracing (to macRxDropTrace) being performed below
1042
1043 LrWpanMacTrailer receivedMacTrailer;
1044 p->RemoveTrailer (receivedMacTrailer);
1045 if (Node::ChecksumEnabled ())
1046 {
1047 receivedMacTrailer.EnableFcs (true);
1048 }
1049
1050 // level 1 filtering
1051 if (!receivedMacTrailer.CheckFcs (p))
1052 {
1053 m_macRxDropTrace (originalPkt);
1054 }
1055 else
1056 {
1057 LrWpanMacHeader receivedMacHdr;
1058 p->RemoveHeader (receivedMacHdr);
1059
1061 params.m_dsn = receivedMacHdr.GetSeqNum ();
1062 params.m_mpduLinkQuality = lqi;
1063 params.m_srcPanId = receivedMacHdr.GetSrcPanId ();
1064 params.m_srcAddrMode = receivedMacHdr.GetSrcAddrMode ();
1065 switch (params.m_srcAddrMode)
1066 {
1067 case SHORT_ADDR:
1068 params.m_srcAddr = receivedMacHdr.GetShortSrcAddr ();
1069 break;
1070 case EXT_ADDR:
1071 params.m_srcExtAddr = receivedMacHdr.GetExtSrcAddr ();
1072 break;
1073 default:
1074 break;
1075 }
1076 params.m_dstPanId = receivedMacHdr.GetDstPanId ();
1077 params.m_dstAddrMode = receivedMacHdr.GetDstAddrMode ();
1078 switch (params.m_dstAddrMode)
1079 {
1080 case SHORT_ADDR:
1081 params.m_dstAddr = receivedMacHdr.GetShortDstAddr ();
1082 break;
1083 case EXT_ADDR:
1084 params.m_dstExtAddr = receivedMacHdr.GetExtDstAddr ();
1085 break;
1086 default:
1087 break;
1088 }
1089
1091 {
1092 //level 2 filtering
1093 if (receivedMacHdr.GetDstAddrMode () == SHORT_ADDR)
1094 {
1095 NS_LOG_DEBUG ("Packet from " << params.m_srcAddr);
1096 NS_LOG_DEBUG ("Packet to " << params.m_dstAddr);
1097 }
1098 else if (receivedMacHdr.GetDstAddrMode () == EXT_ADDR)
1099 {
1100 NS_LOG_DEBUG ("Packet from " << params.m_srcExtAddr);
1101 NS_LOG_DEBUG ("Packet to " << params.m_dstExtAddr);
1102 }
1103
1104 //TODO: Fix here, this should trigger different Indication Callbacks
1105 //depending the type of frame received (data,command, beacon)
1107 {
1108 NS_LOG_DEBUG ("promiscuous mode, forwarding up");
1109 m_mcpsDataIndicationCallback (params, p);
1110 }
1111 else
1112 {
1113 NS_LOG_ERROR (this << " Data Indication Callback not initialized");
1114 }
1115 }
1116 else
1117 {
1118 //level 3 frame filtering
1119 acceptFrame = (receivedMacHdr.GetType () != LrWpanMacHeader::LRWPAN_MAC_RESERVED);
1120
1121 if (acceptFrame)
1122 {
1123 acceptFrame = (receivedMacHdr.GetFrameVer () <= 1);
1124 }
1125
1126 if (acceptFrame
1127 && (receivedMacHdr.GetDstAddrMode () > 1))
1128 {
1129 acceptFrame = receivedMacHdr.GetDstPanId () == m_macPanId
1130 || receivedMacHdr.GetDstPanId () == 0xffff;
1131 }
1132
1133 if (acceptFrame
1134 && (receivedMacHdr.GetDstAddrMode () == SHORT_ADDR))
1135 {
1136 if (receivedMacHdr.GetShortDstAddr () == m_shortAddress)
1137 {
1138 // unicast, for me
1139 acceptFrame = true;
1140 }
1141 else if (receivedMacHdr.GetShortDstAddr ().IsBroadcast () || receivedMacHdr.GetShortDstAddr ().IsMulticast ())
1142 {
1143 // broadcast or multicast
1144 if (receivedMacHdr.IsAckReq ())
1145 {
1146 // discard broadcast/multicast with the ACK bit set
1147 acceptFrame = false;
1148 }
1149 else
1150 {
1151 acceptFrame = true;
1152 }
1153 }
1154 else
1155 {
1156 acceptFrame = false;
1157 }
1158 }
1159
1160 if (acceptFrame
1161 && (receivedMacHdr.GetDstAddrMode () == EXT_ADDR))
1162 {
1163 acceptFrame = (receivedMacHdr.GetExtDstAddr () == m_selfExt);
1164 }
1165
1166 if (acceptFrame
1167 && (receivedMacHdr.GetType () == LrWpanMacHeader::LRWPAN_MAC_BEACON))
1168 {
1169 if (m_macPanId == 0xffff)
1170 {
1171 // TODO: Accept only if the frame version field is valid
1172 acceptFrame = true;
1173 }
1174 else
1175 {
1176 acceptFrame = receivedMacHdr.GetSrcPanId () == m_macPanId;
1177 }
1178 }
1179
1180 if (acceptFrame
1181 && ((receivedMacHdr.GetType () == LrWpanMacHeader::LRWPAN_MAC_DATA)
1182 || (receivedMacHdr.GetType () == LrWpanMacHeader::LRWPAN_MAC_COMMAND))
1183 && (receivedMacHdr.GetSrcAddrMode () > 1))
1184 {
1185 acceptFrame = receivedMacHdr.GetSrcPanId () == m_macPanId; // TODO: need to check if PAN coord
1186 }
1187
1188 if (acceptFrame)
1189 {
1190 m_macRxTrace (originalPkt);
1191 // \todo: What should we do if we receive a frame while waiting for an ACK?
1192 // Especially if this frame has the ACK request bit set, should we reply with an ACK, possibly missing the pending ACK?
1193
1194 // If the received frame is a frame with the ACK request bit set, we immediately send back an ACK.
1195 // If we are currently waiting for a pending ACK, we assume the ACK was lost and trigger a retransmission after sending the ACK.
1196 if ((receivedMacHdr.IsData () || receivedMacHdr.IsCommand ()) && receivedMacHdr.IsAckReq ()
1197 && !(receivedMacHdr.GetDstAddrMode () == SHORT_ADDR && (receivedMacHdr.GetShortDstAddr ().IsBroadcast () || receivedMacHdr.GetShortDstAddr ().IsMulticast ())))
1198 {
1199 // If this is a data or mac command frame, which is not a broadcast or multicast,
1200 // with ack req set, generate and send an ack frame.
1201 // If there is a CSMA medium access in progress we cancel the medium access
1202 // for sending the ACK frame. A new transmission attempt will be started
1203 // after the ACK was send.
1205 {
1208 }
1209 else if (m_lrWpanMacState == MAC_CSMA)
1210 {
1211 // \todo: If we receive a packet while doing CSMA/CA, should we drop the packet because of channel busy,
1212 // or should we restart CSMA/CA for the packet after sending the ACK?
1213 // Currently we simply restart CSMA/CA after sending the ACK.
1214 m_csmaCa->Cancel ();
1215 }
1216 // Cancel any pending MAC state change, ACKs have higher priority.
1219
1221 }
1222
1223
1224 if (receivedMacHdr.GetDstAddrMode () == SHORT_ADDR)
1225 {
1226 NS_LOG_DEBUG ("Packet from " << params.m_srcAddr);
1227 NS_LOG_DEBUG ("Packet to " << params.m_dstAddr);
1228 }
1229 else if (receivedMacHdr.GetDstAddrMode () == EXT_ADDR)
1230 {
1231 NS_LOG_DEBUG ("Packet from " << params.m_srcExtAddr);
1232 NS_LOG_DEBUG ("Packet to " << params.m_dstExtAddr);
1233 }
1234
1235
1236 if (receivedMacHdr.IsBeacon ())
1237 {
1238
1239
1240 // The received beacon size in symbols
1241 // Beacon = 5 bytes Sync Header (SHR) + 1 byte PHY header (PHR) + PSDU (default 17 bytes)
1242 m_rxBeaconSymbols = m_phy->GetPhySHRDuration () + 1 * m_phy->GetPhySymbolsPerOctet () +
1243 (originalPkt->GetSize () * m_phy->GetPhySymbolsPerOctet ());
1244
1245 // The start of Rx beacon time and start of the Incoming superframe Active Period
1246 m_macBeaconRxTime = Simulator::Now () - Seconds (double(m_rxBeaconSymbols) / symbolRate);
1247
1248 NS_LOG_DEBUG ("Beacon Received; forwarding up (m_macBeaconRxTime: " << m_macBeaconRxTime.As (Time::S) << ")");
1249
1250
1251 //TODO: Handle mlme-scan.request here
1252
1253 // Device not associated.
1254 if (m_macPanId == 0xffff)
1255 {
1256 //TODO: mlme-associate.request here.
1257 NS_LOG_ERROR (this << "The current device is not associated to any coordinator");
1258 return;
1259 }
1260
1261
1262 if (m_macPanId != receivedMacHdr.GetDstPanId ())
1263 {
1264 return;
1265 }
1266
1267 BeaconPayloadHeader receivedMacPayload;
1268 p->RemoveHeader (receivedMacPayload);
1269
1270 SuperframeField incomingSuperframe;
1271 incomingSuperframe = receivedMacPayload.GetSuperframeSpecField ();
1272
1273 m_incomingBeaconOrder = incomingSuperframe.GetBeaconOrder ();
1274 m_incomingSuperframeOrder = incomingSuperframe.GetFrameOrder ();
1275 m_incomingFnlCapSlot = incomingSuperframe.GetFinalCapSlot ();
1276
1279
1280 if (incomingSuperframe.IsBattLifeExt ())
1281 {
1282 m_csmaCa->SetBatteryLifeExtension (true);
1283 }
1284 else
1285 {
1286 m_csmaCa->SetBatteryLifeExtension (false);
1287 }
1288
1289 if (m_incomingBeaconOrder < 15 && !m_csmaCa->IsSlottedCsmaCa ())
1290 {
1291 m_csmaCa->SetSlottedCsmaCa ();
1292 }
1293
1294 //TODO: get Incoming frame GTS Fields here
1295
1296 NS_LOG_DEBUG ("Incoming superframe Active Portion (Beacon + CAP + CFP): " << m_incomingSuperframeDuration << " symbols");
1297
1298 //Begin CAP on the current device using info from the Incoming superframe
1300
1301
1302 // Send a Beacon notification only if we are not
1303 // automatically sending data command requests or the beacon contains
1304 // a beacon payload in its MAC payload.
1305 // see IEEE 802.15.4-2011 Section 6.2.4.1
1306 if ((m_macAutoRequest == false) || p->GetSize () > 0)
1307 {
1308 //TODO: Add the rest of the MlmeBeaconNotifyIndication params
1310 {
1312 beaconParams.m_bsn = receivedMacHdr.GetSeqNum ();
1313 m_mlmeBeaconNotifyIndicationCallback (beaconParams,originalPkt);
1314 }
1315 }
1316
1317 if (m_macAutoRequest)
1318 {
1319 // check if MLME-SYNC.request was previously issued and running
1320 // Sync. is necessary to handle pending messages (indirect transmissions)
1322 {
1324 m_numLostBeacons = 0;
1325
1327 {
1328 //if tracking option is on keep tracking the next beacon
1329 uint64_t searchSymbols;
1330 Time searchBeaconTime;
1331
1332 searchSymbols = ((uint64_t) 1 << m_incomingBeaconOrder) + 1 * aBaseSuperframeDuration;
1333 searchBeaconTime = Seconds ((double) searchSymbols / symbolRate);
1335 }
1336
1337 PendingAddrFields pndAddrFields;
1338 pndAddrFields = receivedMacPayload.GetPndAddrFields ();
1339
1340 //TODO: Ignore pending request if the address is in the GTS list.
1341 // If the address is not in the GTS list, then check if the address
1342 // is in the short address pending list or in the extended address
1343 // pending list.
1344
1345 }
1346 }
1347 }
1348 else if (receivedMacHdr.IsData () && !m_mcpsDataIndicationCallback.IsNull ())
1349 {
1350 // If it is a data frame, push it up the stack.
1351 NS_LOG_DEBUG ("Data Packet is for me; forwarding up");
1352 m_mcpsDataIndicationCallback (params, p);
1353 }
1354 else if (receivedMacHdr.IsAcknowledgment () && m_txPkt && m_lrWpanMacState == MAC_ACK_PENDING)
1355 {
1356 LrWpanMacHeader macHdr;
1357 Time ifsWaitTime = Seconds ((double) GetIfsSize () / symbolRate);
1358 m_txPkt->PeekHeader (macHdr);
1359 if (receivedMacHdr.GetSeqNum () == macHdr.GetSeqNum ())
1360 {
1362 // If it is an ACK with the expected sequence number, finish the transmission
1363 // and notify the upper layer.
1366 {
1367 TxQueueElement *txQElement = m_txQueue.front ();
1368 McpsDataConfirmParams confirmParams;
1369 confirmParams.m_msduHandle = txQElement->txQMsduHandle;
1370 confirmParams.m_status = IEEE_802_15_4_SUCCESS;
1371 m_mcpsDataConfirmCallback (confirmParams);
1372 }
1376 // Ack was succesfully received, wait for the Interframe Space (IFS) and then proceed
1377 m_ifsEvent = Simulator::Schedule (ifsWaitTime, &LrWpanMac::IfsWaitTimeout, this, ifsWaitTime);
1378 }
1379 else
1380 {
1381 // If it is an ACK with an unexpected sequence number, mark the current transmission as failed and start a retransmit. (cf 7.5.6.4.3)
1383 if (!PrepareRetransmission ())
1384 {
1387 }
1388 else
1389 {
1392 }
1393 }
1394 }
1395 }
1396 else
1397 {
1398 m_macRxDropTrace (originalPkt);
1399 }
1400 }
1401 }
1402}
1403
1404
1405
1406void
1407LrWpanMac::SendAck (uint8_t seqno)
1408{
1409 NS_LOG_FUNCTION (this << static_cast<uint32_t> (seqno));
1410
1412
1413 // Generate a corresponding ACK Frame.
1415 LrWpanMacTrailer macTrailer;
1416 Ptr<Packet> ackPacket = Create<Packet> (0);
1417 ackPacket->AddHeader (macHdr);
1418 // Calculate FCS if the global attribute ChecksumEnable is set.
1419 if (Node::ChecksumEnabled ())
1420 {
1421 macTrailer.EnableFcs (true);
1422 macTrailer.SetFcs (ackPacket);
1423 }
1424 ackPacket->AddTrailer (macTrailer);
1425
1426 // Enqueue the ACK packet for further processing
1427 // when the transmitter is activated.
1428 m_txPkt = ackPacket;
1429
1430 // Switch transceiver to TX mode. Proceed sending the Ack on confirm.
1432 m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_TX_ON);
1433
1434}
1435
1436void
1438{
1439 TxQueueElement *txQElement = m_txQueue.front ();
1440 Ptr<const Packet> p = txQElement->txQPkt;
1441 m_numCsmacaRetry += m_csmaCa->GetNB () + 1;
1442
1443 Ptr<Packet> pkt = p->Copy ();
1444 LrWpanMacHeader hdr;
1445 pkt->RemoveHeader (hdr);
1446 if (!hdr.GetShortDstAddr ().IsBroadcast () && !hdr.GetShortDstAddr ().IsMulticast ())
1447 {
1449 }
1450
1451 txQElement->txQPkt = 0;
1452 delete txQElement;
1453 m_txQueue.pop_front ();
1454 m_txPkt = 0;
1455 m_retransmission = 0;
1456 m_numCsmacaRetry = 0;
1458}
1459
1460void
1462{
1463 NS_LOG_FUNCTION (this);
1464
1465 // TODO: If we are a PAN coordinator and this was an indirect transmission,
1466 // we will not initiate a retransmission. Instead we wait for the data
1467 // being extracted after a new data request command.
1468 if (!PrepareRetransmission ())
1469 {
1471 }
1472 else
1473 {
1475 }
1476}
1477
1478void
1480{
1481 uint64_t symbolRate = (uint64_t) m_phy->GetDataOrSymbolRate (false);
1482 Time lifsTime = Seconds ((double) m_macLIFSPeriod / symbolRate);
1483 Time sifsTime = Seconds ((double) m_macSIFSPeriod / symbolRate);
1484
1485 if (ifsTime == lifsTime)
1486 {
1487 NS_LOG_DEBUG ("LIFS of " << m_macLIFSPeriod << " symbols (" << ifsTime.As (Time::S) << ") completed ");
1488 }
1489 else if (ifsTime == sifsTime)
1490 {
1491 NS_LOG_DEBUG ("SIFS of " << m_macSIFSPeriod << " symbols (" << ifsTime.As (Time::S) << ") completed ");
1492 }
1493 else
1494 {
1495 NS_LOG_DEBUG ("Unknown IFS size (" << ifsTime.As (Time::S) << ") completed ");
1496 }
1497
1498 m_macIfsEndTrace (ifsTime);
1499 CheckQueue ();
1500}
1501
1502
1503bool
1505{
1506 NS_LOG_FUNCTION (this);
1507
1509 {
1510 // Maximum number of retransmissions has been reached.
1511 // remove the copy of the packet that was just sent
1512 TxQueueElement *txQElement = m_txQueue.front ();
1513 m_macTxDropTrace (txQElement->txQPkt);
1515 {
1516 McpsDataConfirmParams confirmParams;
1517 confirmParams.m_msduHandle = txQElement->txQMsduHandle;
1518 confirmParams.m_status = IEEE_802_15_4_NO_ACK;
1519 m_mcpsDataConfirmCallback (confirmParams);
1520 }
1522 return false;
1523 }
1524 else
1525 {
1527 m_numCsmacaRetry += m_csmaCa->GetNB () + 1;
1528 // Start next CCA process for this packet.
1529 return true;
1530 }
1531}
1532
1533void
1535{
1537 NS_LOG_FUNCTION (this << status << m_txQueue.size ());
1538
1539 LrWpanMacHeader macHdr;
1540 Time ifsWaitTime;
1541 uint64_t symbolRate;
1542
1543 symbolRate = (uint64_t) m_phy->GetDataOrSymbolRate (false); //symbols per second
1544
1545 m_txPkt->PeekHeader (macHdr);
1546
1547 if (status == IEEE_802_15_4_PHY_SUCCESS)
1548 {
1549 if (!macHdr.IsAcknowledgment ())
1550 {
1551 if (macHdr.IsBeacon ())
1552 {
1553 ifsWaitTime = Seconds ((double) GetIfsSize () / symbolRate);
1554
1555 // The Tx Beacon in symbols
1556 // Beacon = 5 bytes Sync Header (SHR) + 1 byte PHY header (PHR) + PSDU (default 17 bytes)
1557 uint64_t beaconSymbols = m_phy->GetPhySHRDuration () + 1 * m_phy->GetPhySymbolsPerOctet () +
1558 (m_txPkt->GetSize () * m_phy->GetPhySymbolsPerOctet ());
1559
1560 // The beacon Tx time and start of the Outgoing superframe Active Period
1561 m_macBeaconTxTime = Simulator::Now () - Seconds (double(beaconSymbols) / symbolRate);
1562
1563
1564 m_txPkt = 0;
1566 NS_LOG_DEBUG ("Beacon Sent (m_macBeaconTxTime: " << m_macBeaconTxTime.As (Time::S) << ")");
1567
1568 MlmeStartConfirmParams mlmeConfirmParams;
1569 mlmeConfirmParams.m_status = MLMESTART_SUCCESS;
1571 {
1572 m_mlmeStartConfirmCallback (mlmeConfirmParams);
1573 }
1574 }
1575 else if (macHdr.IsAckReq ()) // We have sent a regular data packet, check if we have to wait for an ACK.
1576 {
1577 // wait for the ack or the next retransmission timeout
1578 // start retransmission timer
1579 Time waitTime = Seconds ((double) GetMacAckWaitDuration () / symbolRate);
1584 return;
1585 }
1586 else
1587 {
1589 // remove the copy of the packet that was just sent
1591 {
1592 McpsDataConfirmParams confirmParams;
1593 NS_ASSERT_MSG (m_txQueue.size () > 0, "TxQsize = 0");
1594 TxQueueElement *txQElement = m_txQueue.front ();
1595 confirmParams.m_msduHandle = txQElement->txQMsduHandle;
1596 confirmParams.m_status = IEEE_802_15_4_SUCCESS;
1597 m_mcpsDataConfirmCallback (confirmParams);
1598 }
1599 ifsWaitTime = Seconds ((double) GetIfsSize () / symbolRate);
1601 }
1602 }
1603 else
1604 {
1605 // We have send an ACK. Clear the packet buffer.
1606 m_txPkt = 0;
1607 }
1608 }
1609 else if (status == IEEE_802_15_4_PHY_UNSPECIFIED)
1610 {
1611
1612 if (!macHdr.IsAcknowledgment ())
1613 {
1614 NS_ASSERT_MSG (m_txQueue.size () > 0, "TxQsize = 0");
1615 TxQueueElement *txQElement = m_txQueue.front ();
1616 m_macTxDropTrace (txQElement->txQPkt);
1618 {
1619 McpsDataConfirmParams confirmParams;
1620 confirmParams.m_msduHandle = txQElement->txQMsduHandle;
1621 confirmParams.m_status = IEEE_802_15_4_FRAME_TOO_LONG;
1622 m_mcpsDataConfirmCallback (confirmParams);
1623 }
1625 }
1626 else
1627 {
1628 NS_LOG_ERROR ("Unable to send ACK");
1629 }
1630 }
1631 else
1632 {
1633 // Something went really wrong. The PHY is not in the correct state for
1634 // data transmission.
1635 NS_FATAL_ERROR ("Transmission attempt failed with PHY status " << status);
1636 }
1637
1638
1639 if (!ifsWaitTime.IsZero ())
1640 {
1641 m_ifsEvent = Simulator::Schedule (ifsWaitTime, &LrWpanMac::IfsWaitTimeout, this, ifsWaitTime);
1642 }
1643
1646
1647
1648}
1649
1650void
1652{
1653 NS_LOG_FUNCTION (this << status);
1654 // Direct this call through the csmaCa object
1655 m_csmaCa->PlmeCcaConfirm (status);
1656}
1657
1658void
1660{
1661 NS_LOG_FUNCTION (this << status << energyLevel);
1662
1663}
1664
1665void
1668 LrWpanPhyPibAttributes* attribute)
1669{
1670 NS_LOG_FUNCTION (this << status << id << attribute);
1671}
1672
1673void
1675{
1676 NS_LOG_FUNCTION (this << status);
1677
1679 {
1681
1682 // Start sending if we are in state SENDING and the PHY transmitter was enabled.
1686 m_phy->PdDataRequest (m_txPkt->GetSize (), m_txPkt);
1687 }
1688 else if (m_lrWpanMacState == MAC_CSMA && (status == IEEE_802_15_4_PHY_RX_ON || status == IEEE_802_15_4_PHY_SUCCESS))
1689 {
1690 // Start the CSMA algorithm as soon as the receiver is enabled.
1691 m_csmaCa->Start ();
1692 }
1693 else if (m_lrWpanMacState == MAC_IDLE)
1694 {
1696
1697 if (status == IEEE_802_15_4_PHY_RX_ON || status == IEEE_802_15_4_PHY_SUCCESS)
1698 {
1699 // Check if there is not messages to transmit when going idle
1700 CheckQueue ();
1701 }
1702
1703 }
1705 {
1707 }
1708 else
1709 {
1710 // TODO: What to do when we receive an error?
1711 // If we want to transmit a packet, but switching the transceiver on results
1712 // in an error, we have to recover somehow (and start sending again).
1713 NS_FATAL_ERROR ("Error changing transceiver state");
1714 }
1715}
1716
1717void
1720{
1721 NS_LOG_FUNCTION (this << status << id);
1722}
1723
1724void
1726{
1727 NS_LOG_FUNCTION (this << "mac state = " << macState);
1728
1729 McpsDataConfirmParams confirmParams;
1730
1731 if (macState == MAC_IDLE)
1732 {
1734
1736 {
1737 m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_RX_ON);
1738 }
1739 else
1740 {
1741 m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_TRX_OFF);
1742 }
1743
1744
1745 }
1746 else if (macState == MAC_ACK_PENDING)
1747 {
1749 m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_RX_ON);
1750 }
1751 else if (macState == MAC_CSMA)
1752 {
1754
1756 m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_RX_ON);
1757 }
1758 else if (m_lrWpanMacState == MAC_CSMA && macState == CHANNEL_IDLE)
1759 {
1760 // Channel is idle, set transmitter to TX_ON
1762 m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_TX_ON);
1763 }
1764 else if (m_lrWpanMacState == MAC_CSMA && macState == CHANNEL_ACCESS_FAILURE)
1765 {
1767
1768 // cannot find a clear channel, drop the current packet.
1769 NS_LOG_DEBUG ( this << " cannot find clear channel");
1770 confirmParams.m_msduHandle = m_txQueue.front ()->txQMsduHandle;
1774 {
1775 m_mcpsDataConfirmCallback (confirmParams);
1776 }
1777 // remove the copy of the packet that was just sent
1780 }
1781 else if (m_lrWpanMacState == MAC_CSMA && macState == MAC_CSMA_DEFERRED)
1782 {
1784 m_txPkt = 0;
1785 NS_LOG_DEBUG ("****** PACKET DEFERRED to the next superframe *****");
1786 }
1787}
1788
1791{
1792 return m_associationStatus;
1793}
1794
1795void
1797{
1798 m_associationStatus = status;
1799}
1800
1801uint16_t
1803{
1804 return m_macPanId;
1805}
1806
1807void
1808LrWpanMac::SetPanId (uint16_t panId)
1809{
1810 m_macPanId = panId;
1811}
1812
1813void
1815{
1816 NS_LOG_LOGIC (this << " change lrwpan mac state from "
1817 << m_lrWpanMacState << " to "
1818 << newState);
1820 m_lrWpanMacState = newState;
1821}
1822
1823uint64_t
1825{
1826 return m_csmaCa->GetUnitBackoffPeriod () + m_phy->aTurnaroundTime + m_phy->GetPhySHRDuration ()
1827 + ceil (6 * m_phy->GetPhySymbolsPerOctet ());
1828}
1829
1830uint8_t
1832{
1833 return m_macMaxFrameRetries;
1834}
1835
1836void
1838{
1839 NS_LOG_DEBUG ("Transmit Queue Size: " << m_txQueue.size ());
1840}
1841
1842void
1844{
1845 m_macMaxFrameRetries = retries;
1846}
1847
1848bool
1850{
1852 LrWpanMacHeader macHdr;
1853 m_txPkt->PeekHeader (macHdr);
1854
1857 {
1858 return true;
1859 }
1860 else
1861 {
1862 std::cout << "ERROR: Packet not for the coordinator!\n";
1863 return false;
1864
1865 }
1866
1867}
1868
1871{
1873
1875 {
1876 return m_macSIFSPeriod;
1877 }
1878 else
1879 {
1880 return m_macLIFSPeriod;
1881 }
1882}
1883
1884void
1886{
1888}
1889
1890void
1892{
1894}
1895
1896
1897uint64_t
1899{
1901 // Sync Header (SHR) + 8 bits PHY header (PHR) + PSDU
1902 return (m_phy->GetPhySHRDuration () + 1 * m_phy->GetPhySymbolsPerOctet () +
1903 (m_txPkt->GetSize () * m_phy->GetPhySymbolsPerOctet ()));
1904}
1905
1906bool
1908{
1910 LrWpanMacHeader macHdr;
1911 m_txPkt->PeekHeader (macHdr);
1912
1913 return macHdr.IsAckReq ();
1914}
1915
1916} // namespace ns3
1917
Implements the header for the MAC payload beacon frame according to the IEEE 802.15....
SuperframeField GetSuperframeSpecField(void) const
Get the superframe specification field from the beacon payload header.
void SetSuperframeSpecField(SuperframeField sfrmField)
Set the superframe specification field to the beacon payload header.
void SetGtsFields(GtsFields gtsFields)
Set the superframe Guaranteed Time Slot (GTS) fields to the beacon payload header.
PendingAddrFields GetPndAddrFields(void) const
Get the pending address fields from the beacon payload header.
void SetPndAddrFields(PendingAddrFields pndAddrFields)
Set the superframe Pending Address fields to the beacon payload header.
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:1386
Implements the header for the MAC payload command frame according to the IEEE 802....
@ DATA_REQ
Data Request (RFD true: Tx)
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 GTS information fields.
Represent the Mac Header with the Frame Control and Sequence Number fields.
void SetNoAckReq(void)
Set the Frame Control field "Ack. Request" bit to false.
@ LRWPAN_MAC_BEACON
LRWPAN_MAC_BEACON.
@ LRWPAN_MAC_COMMAND
LRWPAN_MAC_COMMAND.
@ LRWPAN_MAC_DATA
LRWPAN_MAC_DATA.
@ LRWPAN_MAC_ACKNOWLEDGMENT
LRWPAN_MAC_ACKNOWLEDGMENT.
@ LRWPAN_MAC_RESERVED
LRWPAN_MAC_RESERVED.
Mac64Address GetExtSrcAddr(void) const
Get the Source Extended address.
void SetAckReq(void)
Set the Frame Control field "Ack. Request" bit to true.
uint8_t GetSrcAddrMode(void) const
Get the Source Addressing Mode of Frame control field.
bool IsBeacon(void) const
Returns true if the header is a beacon.
void SetSrcAddrMode(uint8_t addrMode)
Set the Source address mode.
void SetSrcAddrFields(uint16_t panId, Mac16Address addr)
Set Source address fields.
Mac64Address GetExtDstAddr(void) const
Get the Destination Extended address.
uint8_t GetSeqNum(void) const
Get the frame Sequence number.
uint16_t GetDstPanId(void) const
Get the Destination PAN ID.
enum LrWpanMacType GetType(void) const
Get the header type.
void SetDstAddrFields(uint16_t panId, Mac16Address addr)
Set Destination address fields.
void SetDstAddrMode(uint8_t addrMode)
Set the Destination address mode.
Mac16Address GetShortSrcAddr(void) const
Get the Source Short address.
bool IsData(void) const
Returns true if the header is a data.
uint8_t GetFrameVer(void) const
Get the Frame Version of Frame control field.
Mac16Address GetShortDstAddr(void) const
Get the Destination Short address.
bool IsCommand(void) const
Returns true if the header is a command.
void SetNoPanIdComp(void)
Set the Frame Control field "PAN ID Compression" bit to false.
bool IsAckReq(void) const
Check if Ack.
void SetSecDisable(void)
Set the Frame Control field "Security Enabled" bit to false.
bool IsAcknowledgment(void) const
Returns true if the header is an ack.
uint16_t GetSrcPanId(void) const
Get the Source PAN ID.
uint8_t GetDstAddrMode(void) const
Get the Dest.
Class that implements the LR-WPAN MAC state machine.
Definition: lr-wpan-mac.h:449
uint32_t m_incomingBeaconInterval
Indication of the interval a node should receive a superframe expressed in symbols.
Definition: lr-wpan-mac.h:881
uint32_t GetIfsSize()
Get the size of the Interframe Space according to MPDU size (m_txPkt).
Ptr< LrWpanCsmaCa > m_csmaCa
The CSMA/CA implementation used by this MAC.
Definition: lr-wpan-mac.h:1229
virtual void DoDispose(void)
Destructor implementation.
Definition: lr-wpan-mac.cc:216
McpsDataConfirmCallback m_mcpsDataConfirmCallback
This callback is used to report data transmission request status to the upper layers.
Definition: lr-wpan-mac.h:1262
static const uint32_t aBaseSlotDuration
Length of a superframe slot in symbols.
Definition: lr-wpan-mac.h:468
Time m_macBeaconRxTime
The time that the device received its last bit of the beacon frame.
Definition: lr-wpan-mac.h:742
Ptr< LrWpanPhy > GetPhy(void)
Get the underlying PHY of the MAC.
Definition: lr-wpan-mac.cc:977
Mac16Address GetShortAddress(void) const
Get the short address of this MAC.
Definition: lr-wpan-mac.cc:280
void PlmeCcaConfirm(LrWpanPhyEnumeration status)
IEEE 802.15.4-2006 section 6.2.2.2 PLME-CCA.confirm status.
bool m_macRxOnWhenIdle
Indication of whether the MAC sublayer is to enable its receiver during idle periods.
Definition: lr-wpan-mac.h:840
TracedCallback< Ptr< const Packet > > m_macTxOkTrace
The trace source fired when packets where successfully transmitted, that is an acknowledgment was rec...
Definition: lr-wpan-mac.h:1142
void SetMlmeBeaconNotifyIndicationCallback(MlmeBeaconNotifyIndicationCallback c)
Set the callback for the indication of an incoming beacon packet.
uint64_t m_rxBeaconSymbols
The total size of the received beacon in symbols.
Definition: lr-wpan-mac.h:786
void SetRxOnWhenIdle(bool rxOnWhenIdle)
Set if the receiver should be enabled when the MAC is idle.
Definition: lr-wpan-mac.cc:246
bool m_panCoor
Indication of whether the current device is the PAN coordinator.
Definition: lr-wpan-mac.h:866
void BeaconSearchTimeout(void)
Called if the device is unable to locate a beacon in the time set by MLME-SYNC.request.
Definition: lr-wpan-mac.cc:867
void PlmeSetTRXStateConfirm(LrWpanPhyEnumeration status)
IEEE 802.15.4-2006 section 6.2.2.8 PLME-SET-TRX-STATE.confirm Set PHY state.
uint8_t m_numCsmacaRetry
The number of CSMA/CA retries used for sending the current packet.
Definition: lr-wpan-mac.h:1310
void MlmeSyncRequest(MlmeSyncRequestParams params)
IEEE 802.15.4-2011, section 6.2.13.1 MLME-SYNC.request Request to synchronize with the coordinator by...
Definition: lr-wpan-mac.cc:612
void SendOneBeacon(void)
Called to send a single beacon frame.
Definition: lr-wpan-mac.cc:666
MlmeStartConfirmCallback m_mlmeStartConfirmCallback
This callback is used to report the start of a new PAN or the begin of a new superframe configuration...
Definition: lr-wpan-mac.h:1251
uint64_t GetMacAckWaitDuration(void) const
Get the macAckWaitDuration attribute value.
uint8_t m_deviceCapability
Indication of current device capability (FFD or RFD)
Definition: lr-wpan-mac.h:890
uint8_t GetMacMaxFrameRetries(void) const
Get the macMaxFrameRetries attribute value.
virtual ~LrWpanMac(void)
Definition: lr-wpan-mac.cc:197
EventId m_trackingEvent
Scheduler event to track the incoming beacons.
Definition: lr-wpan-mac.h:1347
void CheckQueue(void)
Check the transmission queue.
Definition: lr-wpan-mac.cc:898
void SetMlmePollConfirmCallback(MlmePollConfirmCallback c)
Set the callback for the confirmation of a data transmission request.
void RemoveFirstTxQElement()
Remove the tip of the transmission queue, including clean up related to the last packet transmission.
void PlmeEdConfirm(LrWpanPhyEnumeration status, uint8_t energyLevel)
IEEE 802.15.4-2006 section 6.2.2.4 PLME-ED.confirm status and energy level.
TracedCallback< Ptr< const Packet > > m_macRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
Definition: lr-wpan-mac.h:1165
bool GetRxOnWhenIdle(void)
Check if the receiver will be enabled when the MAC is idle.
Definition: lr-wpan-mac.cc:240
TracedCallback< Ptr< const Packet > > m_promiscSnifferTrace
A trace source that emulates a promiscuous mode protocol sniffer connected to the device.
Definition: lr-wpan-mac.h:1212
void SetExtendedAddress(Mac64Address address)
Set the extended address of this MAC.
Definition: lr-wpan-mac.cc:272
void MlmeStartRequest(MlmeStartRequestParams params)
IEEE 802.15.4-2006, section 7.1.14.1 MLME-START.request Request to allow a PAN coordinator to initiat...
Definition: lr-wpan-mac.cc:516
uint16_t GetPanId(void) const
Get the PAN id used by this MAC.
uint32_t m_macLIFSPeriod
The minimum time forming a Long InterFrame Spacing (LIFS) period.
Definition: lr-wpan-mac.h:845
void StartInactivePeriod(SuperframeType superframeType)
Start the Inactive Period in a beacon-enabled mode.
Definition: lr-wpan-mac.cc:817
TracedCallback< Ptr< const Packet > > m_macTxDropTrace
The trace source fired when packets are dropped due to missing ACKs or because of transmission failur...
Definition: lr-wpan-mac.h:1149
void SetMcpsDataIndicationCallback(McpsDataIndicationCallback c)
Set the callback for the indication of an incoming data packet.
Definition: lr-wpan-mac.cc:983
virtual void DoInitialize(void)
Initialize() implementation.
Definition: lr-wpan-mac.cc:201
void SetMlmeStartConfirmCallback(MlmeStartConfirmCallback c)
Set the callback for the confirmation of a data transmission request.
Definition: lr-wpan-mac.cc:995
EventId m_cfpEvent
Scheduler event for the end of the outgoing superframe CFP.
Definition: lr-wpan-mac.h:1335
static const uint32_t aMinMPDUOverhead
The minimum number of octets added by the MAC sublayer to the PSDU.
Definition: lr-wpan-mac.h:462
void PrintTransmitQueueSize(void)
Print the number of elements in the packet transmit queue.
uint8_t m_macMaxFrameRetries
The maximum number of retries allowed after a transmission failure.
Definition: lr-wpan-mac.h:834
Mac64Address m_macCoordExtendedAddress
The extended address of the coordinator through which the device is associated.
Definition: lr-wpan-mac.h:756
MlmeSyncLossIndicationCallback m_mlmeSyncLossIndicationCallback
This callback is used to indicate the loss of synchronization with a coordinator.
Definition: lr-wpan-mac.h:1239
static TypeId GetTypeId(void)
Get the type ID.
Definition: lr-wpan-mac.cc:58
MlmePollConfirmCallback m_mlmePollConfirmCallback
This callback is used to report the status after a device send data command request to the coordinato...
Definition: lr-wpan-mac.h:1245
SequenceNumber8 m_macBsn
Sequence number added to transmitted beacon frame, 00-ff.
Definition: lr-wpan-mac.h:829
LrWpanAssociationStatus m_associationStatus
The current association status of the MAC layer.
Definition: lr-wpan-mac.h:1278
void SetLrWpanMacState(LrWpanMacState macState)
CSMA-CA algorithm calls back the MAC after executing channel assessment.
Mac16Address m_shortAddress
The short address used by this MAC.
Definition: lr-wpan-mac.h:1288
uint8_t m_macSuperframeOrder
Used by a PAN coordinator or coordinator.
Definition: lr-wpan-mac.h:775
void SetCsmaCa(Ptr< LrWpanCsmaCa > csmaCa)
Set the CSMA/CA implementation to be used by the MAC.
Definition: lr-wpan-mac.cc:965
void PdDataIndication(uint32_t psduLength, Ptr< Packet > p, uint8_t lqi)
IEEE 802.15.4-2006 section 6.2.1.3 PD-DATA.indication Indicates the transfer of an MPDU from PHY to M...
Time m_macBeaconTxTime
The time that the device transmitted its last beacon frame.
Definition: lr-wpan-mac.h:735
SuperframeField GetSuperframeField(void)
Constructs a Superframe specification field from the local information, the superframe Specification ...
Definition: lr-wpan-mac.cc:920
MlmeBeaconNotifyIndicationCallback m_mlmeBeaconNotifyIndicationCallback
This callback is used to notify incoming beacon packets to the upper layers.
Definition: lr-wpan-mac.h:1234
TracedCallback< LrWpanMacState, LrWpanMacState > m_macStateLogger
A trace source that fires when the LrWpanMac changes states.
Definition: lr-wpan-mac.h:1221
EventId m_setMacState
Scheduler event for a deferred MAC state change.
Definition: lr-wpan-mac.h:1319
void StartCFP(SuperframeType superframeType)
Called to begin the Contention Free Period (CFP) in a beacon-enabled mode.
Definition: lr-wpan-mac.cc:771
void SetMcpsDataConfirmCallback(McpsDataConfirmCallback c)
Set the callback for the confirmation of a data transmission request.
Definition: lr-wpan-mac.cc:989
uint16_t m_macTransactionPersistanceTime
The maximum time (in superframe periods) that a transaction is stored by a coordinator and indicated ...
Definition: lr-wpan-mac.h:781
void SetAssociationStatus(LrWpanAssociationStatus status)
Set the current association status.
void SetPanId(uint16_t panId)
Set the PAN id used by this MAC.
TracedCallback< Ptr< const Packet > > m_snifferTrace
A trace source that emulates a non-promiscuous protocol sniffer connected to the device.
Definition: lr-wpan-mac.h:1192
uint8_t m_incomingBeaconOrder
The beaconOrder value of the INCOMING frame.
Definition: lr-wpan-mac.h:796
SequenceNumber8 m_macDsn
Sequence number added to transmitted data or MAC command frame, 00-ff.
Definition: lr-wpan-mac.h:824
void SetMlmeSyncLossIndicationCallback(MlmeSyncLossIndicationCallback c)
Set the callback for the loss of synchronization with a coordinator.
uint32_t m_ifs
The value of the necessary InterFrame Space after the transmission of a packet.
Definition: lr-wpan-mac.h:862
std::deque< TxQueueElement * > m_txQueue
The transmit queue used by the MAC.
Definition: lr-wpan-mac.h:1297
std::deque< IndTxQueueElement * > m_indTxQueue
The indirect transmit queue used by the MAC pending messages.
Definition: lr-wpan-mac.h:1301
void ChangeMacState(LrWpanMacState newState)
Change the current MAC state to the given new state.
void PlmeGetAttributeConfirm(LrWpanPhyEnumeration status, LrWpanPibAttributeIdentifier id, LrWpanPhyPibAttributes *attribute)
IEEE 802.15.4-2006 section 6.2.2.6 PLME-GET.confirm Get attributes per definition from Table 23 in se...
uint8_t m_macBeaconOrder
Used by a PAN coordinator or coordinator.
Definition: lr-wpan-mac.h:768
TracedCallback< Time > m_macIfsEndTrace
The trace source is fired at the end of any Interframe Space (IFS).
Definition: lr-wpan-mac.h:1103
TracedValue< SuperframeStatus > m_outSuperframeStatus
The current period of the outgoing superframe.
Definition: lr-wpan-mac.h:1274
GtsFields GetGtsFields(void)
Constructs the Guaranteed Time Slots (GTS) Fields from local information.
Definition: lr-wpan-mac.cc:945
void PlmeSetAttributeConfirm(LrWpanPhyEnumeration status, LrWpanPibAttributeIdentifier id)
IEEE 802.15.4-2006 section 6.2.2.10 PLME-SET.confirm Set attributes per definition from Table 23 in s...
static const uint32_t aBaseSuperframeDuration
Length of a superframe in symbols.
Definition: lr-wpan-mac.h:479
EventId m_ackWaitTimeout
Scheduler event for the ACK timeout of the currently transmitted data packet.
Definition: lr-wpan-mac.h:1315
bool m_macPromiscuousMode
Indicates if MAC sublayer is in receive all mode.
Definition: lr-wpan-mac.h:813
uint8_t m_fnlCapSlot
Indication of the Slot where the CAP portion of the OUTGOING Superframe ends.
Definition: lr-wpan-mac.h:790
uint32_t m_macSIFSPeriod
The minimum time forming a Short InterFrame Spacing (SIFS) period.
Definition: lr-wpan-mac.h:850
void IfsWaitTimeout(Time ifsTime)
After a successful transmission of a frame (beacon, data) or an ack frame reception,...
bool PrepareRetransmission(void)
Check for remaining retransmissions for the packet currently being sent.
static const uint32_t aMaxLostBeacons
The number of consecutive lost beacons that will cause the MAC sublayer of a receiving device to decl...
Definition: lr-wpan-mac.h:486
uint32_t m_beaconInterval
Indication of the Interval used by the coordinator to transmit beacon frames expressed in symbols.
Definition: lr-wpan-mac.h:871
TracedValue< LrWpanMacState > m_lrWpanMacState
The current state of the MAC layer.
Definition: lr-wpan-mac.h:1266
TracedCallback< Ptr< const Packet > > m_macTxEnqueueTrace
The trace source fired when packets come into the "top" of the device at the L3/L2 transition,...
Definition: lr-wpan-mac.h:1121
EventId m_capEvent
Scheduler event for the end of the outgoing superframe CAP.
Definition: lr-wpan-mac.h:1331
Mac64Address GetExtendedAddress(void) const
Get the extended address of this MAC.
Definition: lr-wpan-mac.cc:287
TracedCallback< Ptr< const Packet > > m_macTxTrace
The trace source fired when packets are being sent down to L1.
Definition: lr-wpan-mac.h:1134
uint16_t m_macPanId
16 bits id of PAN on which this device is operating.
Definition: lr-wpan-mac.h:819
TracedCallback< Ptr< const Packet > > m_macRxDropTrace
The trace source fired for packets successfully received by the device but dropped before being forwa...
Definition: lr-wpan-mac.h:1173
bool m_macAutoRequest
Indication of whether a device automatically sends data request command if its address is listed in t...
Definition: lr-wpan-mac.h:858
uint8_t m_incomingSuperframeOrder
Used by all devices that have a parent.
Definition: lr-wpan-mac.h:803
TracedCallback< Ptr< const Packet >, uint8_t, uint8_t > m_sentPktTrace
The trace source fired when packets are considered as successfully sent or the transmission has been ...
Definition: lr-wpan-mac.h:1114
TracedCallback< Ptr< const Packet > > m_macTxDequeueTrace
The trace source fired when packets are dequeued from the L3/l2 transmission queue.
Definition: lr-wpan-mac.h:1128
void PdDataConfirm(LrWpanPhyEnumeration status)
IEEE 802.15.4-2006 section 6.2.1.2 Confirm the end of transmission of an MPDU to MAC.
uint8_t m_numLostBeacons
The number of consecutive loss beacons in a beacon tracking operation.
Definition: lr-wpan-mac.h:898
Ptr< Packet > m_txPkt
The packet which is currently being sent by the MAC layer.
Definition: lr-wpan-mac.h:1282
void McpsDataRequest(McpsDataRequestParams params, Ptr< Packet > p)
IEEE 802.15.4-2006, section 7.1.1.1 MCPS-DATA.request Request to transfer a MSDU.
Definition: lr-wpan-mac.cc:293
void SetPhy(Ptr< LrWpanPhy > phy)
Set the underlying PHY for the MAC.
Definition: lr-wpan-mac.cc:971
LrWpanAssociationStatus GetAssociationStatus(void) const
Get the current association status.
void AwaitBeacon(void)
Called after the end of an INCOMING superframe to start the moment a device waits for a new incoming ...
Definition: lr-wpan-mac.cc:854
Mac64Address m_selfExt
The extended address used by this MAC.
Definition: lr-wpan-mac.h:1293
EventId m_incCapEvent
Scheduler event for the end of the incoming superframe CAP.
Definition: lr-wpan-mac.h:1339
McpsDataIndicationCallback m_mcpsDataIndicationCallback
This callback is used to notify incoming packets to the upper layers.
Definition: lr-wpan-mac.h:1256
bool m_beaconTrackingOn
Indication of whether the current device is tracking incoming beacons.
Definition: lr-wpan-mac.h:894
uint32_t m_superframeDuration
Indication of the superframe duration in symbols.
Definition: lr-wpan-mac.h:876
Mac16Address m_macCoordShortAddress
The short address of the coordinator through which the device is associated.
Definition: lr-wpan-mac.h:750
void AckWaitTimeout(void)
Handle an ACK timeout with a packet retransmission, if there are retransmission left,...
Ptr< LrWpanPhy > m_phy
The PHY associated with this MAC.
Definition: lr-wpan-mac.h:1225
static const uint32_t aMaxSIFSFrameSize
The maximum size of an MPDU, in octets, that can be followed by a Short InterFrame Spacing (SIFS) per...
Definition: lr-wpan-mac.h:492
LrWpanMac(void)
Default constructor.
Definition: lr-wpan-mac.cc:152
bool isTxAckReq(void)
Check if the packet to transmit requires acknowledgment.
static const uint32_t aNumSuperframeSlots
Number of a superframe slots per superframe.
Definition: lr-wpan-mac.h:473
uint64_t GetTxPacketSymbols(void)
Obtain the number of symbols in the packet which is currently being sent by the MAC layer.
void StartCAP(SuperframeType superframeType)
Called to begin the Contention Access Period (CAP) in a beacon-enabled mode.
Definition: lr-wpan-mac.cc:724
TracedCallback< Ptr< const Packet > > m_macPromiscRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
Definition: lr-wpan-mac.h:1157
void MlmePollRequest(MlmePollRequestParams params)
IEEE 802.15.4-2011, section 6.2.14.2 MLME-POLL.request Prompts the device to request data from the co...
Definition: lr-wpan-mac.cc:652
EventId m_ifsEvent
Scheduler event for Interframe spacing wait time.
Definition: lr-wpan-mac.h:1323
EventId m_beaconEvent
Scheduler event for generation of one beacon.
Definition: lr-wpan-mac.h:1327
uint32_t m_incomingSuperframeDuration
Indication of the superframe duration in symbols (e.g.
Definition: lr-wpan-mac.h:886
void SetShortAddress(Mac16Address address)
Set the short address of this MAC.
Definition: lr-wpan-mac.cc:265
void SetMacMaxFrameRetries(uint8_t retries)
Set the macMaxFrameRetries attribute value.
uint8_t m_retransmission
The number of already used retransmission for the currently transmitted packet.
Definition: lr-wpan-mac.h:1306
PendingAddrFields GetPendingAddrFields(void)
Constructs Pending Address Fields from the local information, the Pending Address Fields are part of ...
Definition: lr-wpan-mac.cc:955
bool isCoordDest(void)
Check if the packet destination is its coordinator.
EventId m_incCfpEvent
Scheduler event for the end of the incoming superframe CFP.
Definition: lr-wpan-mac.h:1343
void SendAck(uint8_t seqno)
Send an acknowledgment packet for the given sequence number.
uint8_t m_incomingFnlCapSlot
Indication of the Slot where the CAP portion of the INCOMING Superframe ends.
Definition: lr-wpan-mac.h:807
TracedValue< SuperframeStatus > m_incSuperframeStatus
The current period of the incoming superframe.
Definition: lr-wpan-mac.h:1270
void SetAssociatedCoor(Mac16Address mac)
Check if the packet destination is its coordinator.
Represent the Mac Trailer with the Frame Check Sequence field.
void SetFcs(Ptr< const Packet > p)
Calculate and set the FCS value based on the given packet.
bool CheckFcs(Ptr< const Packet > p)
Check the FCS of a given packet against the FCS value stored in the trailer.
void EnableFcs(bool enable)
Enable or disable FCS calculation for this trailer.
static const uint32_t aMaxPhyPacketSize
The maximum packet size accepted by the PHY.
Definition: lr-wpan-phy.h:262
This class can contain 16 bit addresses.
Definition: mac16-address.h:42
bool IsBroadcast(void) const
Checks if the address is a broadcast address according to 802.15.4 scheme (i.e., 0xFFFF).
bool IsMulticast(void) const
Checks if the address is a multicast address according to RFC 4944 Section 9 (i.e....
an EUI-64 address
Definition: mac64-address.h:44
static Mac64Address Allocate(void)
Allocate a new Mac64Address.
static bool ChecksumEnabled(void)
Definition: node.cc:278
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:256
A base class which provides memory management and object aggregation.
Definition: object.h:88
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
virtual void DoInitialize(void)
Initialize() implementation.
Definition: object.cc:353
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:280
uint32_t RemoveTrailer(Trailer &trailer)
Remove a deserialized trailer from the internal buffer.
Definition: packet.cc:318
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Definition: packet.cc:290
void AddTrailer(const Trailer &trailer)
Add trailer to this packet.
Definition: packet.cc:307
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:121
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:856
Represent the Pending Address Specification field.
NUMERIC_TYPE GetValue() const
Extracts the numeric value of the sequence number.
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:556
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
Definition: simulator.h:587
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
Represent the Superframe Specification information field.
bool IsBattLifeExt(void) const
Check if the Battery Life Extension bit is enabled.
void SetBattLifeExt(bool battLifeExt)
Set the Superframe Specification Battery Life Extension (BLE).
uint8_t GetFinalCapSlot(void) const
Get the the Final CAP Slot.
void SetFinalCapSlot(uint8_t capSlot)
Set the superframe specification Final CAP slot field.
void SetSuperframeOrder(uint8_t frmOrder)
Set the superframe specification Superframe Order field.
void SetPanCoor(bool panCoor)
Set the Superframe Specification PAN coordinator field.
void SetBeaconOrder(uint8_t bcnOrder)
Set the superframe specification Beacon Order field.
uint8_t GetBeaconOrder(void) const
Get the Superframe Specification Beacon Order field.
uint8_t GetFrameOrder(void) const
Get the Superframe Specification Frame Order field.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:379
@ S
second
Definition: nstime.h:114
bool IsZero(void) const
Exactly equivalent to t == 0.
Definition: nstime.h:300
TimeWithUnit As(const enum Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:432
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
Hold an unsigned integer type.
Definition: uinteger.h:44
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
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition: uinteger.h:45
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition: abort.h:50
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:257
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:289
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
LrWpanMacState
MAC states.
Definition: lr-wpan-mac.h:70
LrWpanPhyEnumeration
IEEE802.15.4-2006 PHY Emumerations Table 18 in section 6.2.3.
Definition: lr-wpan-phy.h:106
LrWpanAssociationStatus
table 83 of 802.15.4
Definition: lr-wpan-mac.h:151
SuperframeType
Superframe type.
Definition: lr-wpan-mac.h:102
LrWpanPibAttributeIdentifier
IEEE802.15.4-2006 PHY PIB Attribute Identifiers Table 23 in section 6.4.2.
Definition: lr-wpan-phy.h:141
@ CHANNEL_ACCESS_FAILURE
CHANNEL_ACCESS_FAILURE.
Definition: lr-wpan-mac.h:75
@ MAC_IDLE
MAC_IDLE.
Definition: lr-wpan-mac.h:71
@ MAC_CSMA_DEFERRED
MAC_CSMA_DEFERRED.
Definition: lr-wpan-mac.h:80
@ MAC_CSMA
MAC_CSMA.
Definition: lr-wpan-mac.h:72
@ CHANNEL_IDLE
CHANNEL_IDLE.
Definition: lr-wpan-mac.h:76
@ MAC_SENDING
MAC_SENDING.
Definition: lr-wpan-mac.h:73
@ MAC_ACK_PENDING
MAC_ACK_PENDING.
Definition: lr-wpan-mac.h:74
@ FFD
Full Functional Device (FFD)
@ IEEE_802_15_4_TRANSACTION_OVERFLOW
Definition: lr-wpan-mac.h:167
@ IEEE_802_15_4_NO_ACK
Definition: lr-wpan-mac.h:172
@ IEEE_802_15_4_CHANNEL_ACCESS_FAILURE
Definition: lr-wpan-mac.h:169
@ IEEE_802_15_4_INVALID_ADDRESS
Definition: lr-wpan-mac.h:170
@ IEEE_802_15_4_SUCCESS
Definition: lr-wpan-mac.h:166
@ IEEE_802_15_4_FRAME_TOO_LONG
Definition: lr-wpan-mac.h:174
@ CFP
Contention Free Period.
Definition: lr-wpan-mac.h:92
@ INACTIVE
Inactive Period or unslotted CSMA-CA.
Definition: lr-wpan-mac.h:93
@ CAP
Contention Access Period.
Definition: lr-wpan-mac.h:91
@ BEACON
The Beacon transmission or reception Period.
Definition: lr-wpan-mac.h:90
@ IEEE_802_15_4_PHY_SUCCESS
Definition: lr-wpan-phy.h:114
@ IEEE_802_15_4_PHY_UNSPECIFIED
Definition: lr-wpan-phy.h:119
@ IEEE_802_15_4_PHY_TRX_OFF
Definition: lr-wpan-phy.h:115
@ IEEE_802_15_4_PHY_RX_ON
Definition: lr-wpan-phy.h:113
@ IEEE_802_15_4_PHY_TX_ON
Definition: lr-wpan-phy.h:116
@ TX_OPTION_ACK
TX_OPTION_ACK.
Definition: lr-wpan-mac.h:59
@ TX_OPTION_INDIRECT
TX_OPTION_INDIRECT.
Definition: lr-wpan-mac.h:61
@ TX_OPTION_GTS
TX_OPTION_GTS.
Definition: lr-wpan-mac.h:60
@ ASSOCIATED
Definition: lr-wpan-mac.h:152
@ MLMESTART_INVALID_PARAMETER
Definition: lr-wpan-mac.h:191
@ MLMESTART_SUCCESS
Definition: lr-wpan-mac.h:187
@ MLMESTART_NO_SHORT_ADDRESS
Definition: lr-wpan-mac.h:188
@ SHORT_ADDR
Definition: lr-wpan-mac.h:141
@ NO_PANID_ADDR
Definition: lr-wpan-mac.h:139
@ EXT_ADDR
Definition: lr-wpan-mac.h:142
@ ADDR_MODE_RESERVED
Definition: lr-wpan-mac.h:140
@ INCOMING
Incoming Superframe.
Definition: lr-wpan-mac.h:104
@ OUTGOING
Outgoing Superframe.
Definition: lr-wpan-mac.h:103
@ phyCurrentChannel
Definition: lr-wpan-phy.h:142
@ phyCurrentPage
Definition: lr-wpan-phy.h:146
@ MLMESYNCLOSS_BEACON_LOST
Definition: lr-wpan-mac.h:208
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
SequenceNumber< uint8_t, int8_t > SequenceNumber8
8 bit Sequence number.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1260
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
address
Definition: first.py:44
Every class exported by the ns3 library is enclosed in the ns3 namespace.
mac
Definition: third.py:96
phy
Definition: third.py:93
Helper structure for managing indirect transmission queue elements.
Definition: lr-wpan-mac.h:996
Time expireTime
The expiration time of the packet in the indirect transmission queue.
Definition: lr-wpan-mac.h:999
uint8_t txQMsduHandle
MSDU Handle.
Definition: lr-wpan-mac.h:997
Ptr< Packet > txQPkt
Queued packet.
Definition: lr-wpan-mac.h:998
Helper structure for managing transmission queue elements.
Definition: lr-wpan-mac.h:987
Ptr< Packet > txQPkt
Queued packet.
Definition: lr-wpan-mac.h:989
uint8_t txQMsduHandle
MSDU Handle.
Definition: lr-wpan-mac.h:988
IEEE802.15.4-2006 PHY PIB Attributes Table 23 in section 6.4.2.
Definition: lr-wpan-phy.h:158
uint8_t phyCurrentChannel
The RF channel to use.
Definition: lr-wpan-phy.h:159
uint32_t phyCurrentPage
Current channel page.
Definition: lr-wpan-phy.h:163
MCPS-DATA.confirm params.
Definition: lr-wpan-mac.h:261
LrWpanMcpsDataConfirmStatus m_status
The status of the last MSDU transmission.
Definition: lr-wpan-mac.h:263
uint8_t m_msduHandle
MSDU handle.
Definition: lr-wpan-mac.h:262
MCPS-DATA.indication params.
Definition: lr-wpan-mac.h:271
Mac16Address m_dstAddr
Destination address.
Definition: lr-wpan-mac.h:278
uint8_t m_dstAddrMode
Destination address mode.
Definition: lr-wpan-mac.h:276
uint16_t m_dstPanId
Destination PAN identifier.
Definition: lr-wpan-mac.h:277
uint8_t m_dsn
The DSN of the received data frame.
Definition: lr-wpan-mac.h:281
uint8_t m_mpduLinkQuality
LQI value measured during reception of the MPDU.
Definition: lr-wpan-mac.h:280
uint16_t m_srcPanId
Source PAN identifier.
Definition: lr-wpan-mac.h:273
Mac64Address m_dstExtAddr
Destination extended address.
Definition: lr-wpan-mac.h:279
uint8_t m_srcAddrMode
Source address mode.
Definition: lr-wpan-mac.h:272
Mac64Address m_srcExtAddr
Source extended address.
Definition: lr-wpan-mac.h:275
Mac16Address m_srcAddr
Source address.
Definition: lr-wpan-mac.h:274
MCPS-DATA.request params.
Definition: lr-wpan-mac.h:237
LrWpanAddressMode m_srcAddrMode
Source address mode.
Definition: lr-wpan-mac.h:246
Mac64Address m_dstExtAddr
Destination extended address.
Definition: lr-wpan-mac.h:250
LrWpanAddressMode m_dstAddrMode
Destination address mode.
Definition: lr-wpan-mac.h:247
uint16_t m_dstPanId
Destination PAN identifier.
Definition: lr-wpan-mac.h:248
Mac16Address m_dstAddr
Destination address.
Definition: lr-wpan-mac.h:249
uint8_t m_msduHandle
MSDU handle.
Definition: lr-wpan-mac.h:251
uint8_t m_txOptions
Tx Options (bitfield)
Definition: lr-wpan-mac.h:252
MLME-BEACON-NOTIFY.indication params.
Definition: lr-wpan-mac.h:360
uint8_t m_bsn
The beacon sequence number.
Definition: lr-wpan-mac.h:361
MLME-POLL.request params.
Definition: lr-wpan-mac.h:331
MLME-START.confirm params.
Definition: lr-wpan-mac.h:351
LrWpanMlmeStartConfirmStatus m_status
The status of a MLME-start.request.
Definition: lr-wpan-mac.h:352
MLME-START.request params.
Definition: lr-wpan-mac.h:289
uint32_t m_logChPage
Logical channel page on which to start using the new superframe configuration.
Definition: lr-wpan-mac.h:303
uint8_t m_logCh
Logical channel on which to start using the new superframe configuration.
Definition: lr-wpan-mac.h:302
bool m_panCoor
On true this device will become coordinator.
Definition: lr-wpan-mac.h:307
bool m_coorRealgn
True if a realignment request command is to be transmitted prior changing the superframe.
Definition: lr-wpan-mac.h:309
uint8_t m_bcnOrd
Beacon Order, Used to calculate the beacon interval, a value of 15 indicates no periodic beacons will...
Definition: lr-wpan-mac.h:305
uint16_t m_PanId
Pan Identifier used by the device.
Definition: lr-wpan-mac.h:301
uint8_t m_sfrmOrd
Superframe Order, indicates the length of the CAP in time slots.
Definition: lr-wpan-mac.h:306
bool m_battLifeExt
Flag indicating whether or not the Battery life extension (BLE) features are used.
Definition: lr-wpan-mac.h:308
MLME-SYNC-LOSS.indication params.
Definition: lr-wpan-mac.h:375
uint16_t m_panId
The PAN identifier with which the device lost synchronization or to which it was realigned.
Definition: lr-wpan-mac.h:377
LrWpanSyncLossReason m_lossReason
The reason for the lost of synchronization.
Definition: lr-wpan-mac.h:376
MLME-SYNC.request params.
Definition: lr-wpan-mac.h:317
bool m_trackBcn
True if the mlme sync with the next beacon and attempts to track future beacons.
Definition: lr-wpan-mac.h:323
uint8_t m_logCh
The channel number on which to attempt coordinator synchronization.
Definition: lr-wpan-mac.h:322