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  */
25 #include "lr-wpan-mac.h"
26 #include "lr-wpan-csmaca.h"
27 #include "lr-wpan-mac-header.h"
28 #include "lr-wpan-mac-trailer.h"
29 #include <ns3/simulator.h>
30 #include <ns3/log.h>
31 #include <ns3/uinteger.h>
32 #include <ns3/node.h>
33 #include <ns3/packet.h>
34 #include <ns3/random-variable-stream.h>
35 #include <ns3/double.h>
36 
37 #undef NS_LOG_APPEND_CONTEXT
38 #define NS_LOG_APPEND_CONTEXT \
39  std::clog << "[address " << m_shortAddress << "] ";
40 
41 namespace ns3 {
42 
43 NS_LOG_COMPONENT_DEFINE ("LrWpanMac");
44 
45 NS_OBJECT_ENSURE_REGISTERED (LrWpanMac);
46 
47 const uint32_t LrWpanMac::aMinMPDUOverhead = 9; // Table 85
48 
49 TypeId
51 {
52  static TypeId tid = TypeId ("ns3::LrWpanMac")
53  .SetParent<Object> ()
54  .SetGroupName ("LrWpan")
55  .AddConstructor<LrWpanMac> ()
56  .AddAttribute ("PanId", "16-bit identifier of the associated PAN",
57  UintegerValue (),
59  MakeUintegerChecker<uint16_t> ())
60  .AddTraceSource ("MacTxEnqueue",
61  "Trace source indicating a packet has been "
62  "enqueued in the transaction queue",
64  "ns3::Packet::TracedCallback")
65  .AddTraceSource ("MacTxDequeue",
66  "Trace source indicating a packet has was "
67  "dequeued from the transaction queue",
69  "ns3::Packet::TracedCallback")
70  .AddTraceSource ("MacTx",
71  "Trace source indicating a packet has "
72  "arrived for transmission by this device",
74  "ns3::Packet::TracedCallback")
75  .AddTraceSource ("MacTxOk",
76  "Trace source indicating a packet has been "
77  "successfully sent",
79  "ns3::Packet::TracedCallback")
80  .AddTraceSource ("MacTxDrop",
81  "Trace source indicating a packet has been "
82  "dropped during transmission",
84  "ns3::Packet::TracedCallback")
85  .AddTraceSource ("MacPromiscRx",
86  "A packet has been received by this device, "
87  "has been passed up from the physical layer "
88  "and is being forwarded up the local protocol stack. "
89  "This is a promiscuous trace,",
91  "ns3::Packet::TracedCallback")
92  .AddTraceSource ("MacRx",
93  "A packet has been received by this device, "
94  "has been passed up from the physical layer "
95  "and is being forwarded up the local protocol stack. "
96  "This is a non-promiscuous trace,",
98  "ns3::Packet::TracedCallback")
99  .AddTraceSource ("MacRxDrop",
100  "Trace source indicating a packet was received, "
101  "but dropped before being forwarded up the stack",
103  "ns3::Packet::TracedCallback")
104  .AddTraceSource ("Sniffer",
105  "Trace source simulating a non-promiscuous "
106  "packet sniffer attached to the device",
108  "ns3::Packet::TracedCallback")
109  .AddTraceSource ("PromiscSniffer",
110  "Trace source simulating a promiscuous "
111  "packet sniffer attached to the device",
113  "ns3::Packet::TracedCallback")
114  .AddTraceSource ("MacStateValue",
115  "The state of LrWpan Mac",
117  "ns3::TracedValueCallback::LrWpanMacState")
118  .AddTraceSource ("MacState",
119  "The state of LrWpan Mac",
121  "ns3::LrWpanMac::StateTracedCallback")
122  .AddTraceSource ("MacSentPkt",
123  "Trace source reporting some information about "
124  "the sent packet",
126  "ns3::LrWpanMac::SentTracedCallback")
127  ;
128  return tid;
129 }
130 
132 {
133 
134  // First set the state to a known value, call ChangeMacState to fire trace source.
137 
138  m_macRxOnWhenIdle = true;
139  m_macPanId = 0;
142  m_macPromiscuousMode = false;
144  m_retransmission = 0;
145  m_numCsmacaRetry = 0;
146  m_txPkt = 0;
147 
148  Ptr<UniformRandomVariable> uniformVar = CreateObject<UniformRandomVariable> ();
149  uniformVar->SetAttribute ("Min", DoubleValue (0.0));
150  uniformVar->SetAttribute ("Max", DoubleValue (255.0));
151  m_macDsn = SequenceNumber8 (uniformVar->GetValue ());
152  m_shortAddress = Mac16Address ("00:00");
153 }
154 
156 {
157 }
158 
159 void
161 {
162  if (m_macRxOnWhenIdle)
163  {
164  m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_RX_ON);
165  }
166  else
167  {
168  m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_TRX_OFF);
169  }
170 
172 }
173 
174 void
176 {
177  if (m_csmaCa != 0)
178  {
179  m_csmaCa->Dispose ();
180  m_csmaCa = 0;
181  }
182  m_txPkt = 0;
183  for (uint32_t i = 0; i < m_txQueue.size (); i++)
184  {
185  m_txQueue[i]->txQPkt = 0;
186  delete m_txQueue[i];
187  }
188  m_txQueue.clear ();
189  m_phy = 0;
190  m_mcpsDataIndicationCallback = MakeNullCallback< void, McpsDataIndicationParams, Ptr<Packet> > ();
191  m_mcpsDataConfirmCallback = MakeNullCallback< void, McpsDataConfirmParams > ();
192 
194 }
195 
196 bool
198 {
199  return m_macRxOnWhenIdle;
200 }
201 
202 void
203 LrWpanMac::SetRxOnWhenIdle (bool rxOnWhenIdle)
204 {
205  NS_LOG_FUNCTION (this << rxOnWhenIdle);
206  m_macRxOnWhenIdle = rxOnWhenIdle;
207 
208  if (m_lrWpanMacState == MAC_IDLE)
209  {
210  if (m_macRxOnWhenIdle)
211  {
212  m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_RX_ON);
213  }
214  else
215  {
216  m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_TRX_OFF);
217  }
218  }
219 }
220 
221 void
223 {
224  //NS_LOG_FUNCTION (this << address);
226 }
227 
228 void
230 {
231  //NS_LOG_FUNCTION (this << address);
232  m_selfExt = address;
233 }
234 
235 
238 {
239  NS_LOG_FUNCTION (this);
240  return m_shortAddress;
241 }
242 
245 {
246  NS_LOG_FUNCTION (this);
247  return m_selfExt;
248 }
249 void
251 {
252  NS_LOG_FUNCTION (this << p);
253 
254  McpsDataConfirmParams confirmParams;
255  confirmParams.m_msduHandle = params.m_msduHandle;
256 
257  // TODO: We need a drop trace for the case that the packet is too large or the request parameters are maleformed.
258  // The current tx drop trace is not suitable, because packets dropped using this trace carry the mac header
259  // and footer, while packets being dropped here do not have them.
260 
262  m_macDsn++;
263 
265  {
266  // Note, this is just testing maximum theoretical frame size per the spec
267  // The frame could still be too large once headers are put on
268  // in which case the phy will reject it instead
269  NS_LOG_ERROR (this << " packet too big: " << p->GetSize ());
270  confirmParams.m_status = IEEE_802_15_4_FRAME_TOO_LONG;
272  {
273  m_mcpsDataConfirmCallback (confirmParams);
274  }
275  return;
276  }
277 
278  if ((params.m_srcAddrMode == NO_PANID_ADDR)
279  && (params.m_dstAddrMode == NO_PANID_ADDR))
280  {
281  NS_LOG_ERROR (this << " Can not send packet with no Address field" );
282  confirmParams.m_status = IEEE_802_15_4_INVALID_ADDRESS;
284  {
285  m_mcpsDataConfirmCallback (confirmParams);
286  }
287  return;
288  }
289  switch (params.m_srcAddrMode)
290  {
291  case NO_PANID_ADDR:
292  macHdr.SetSrcAddrMode (params.m_srcAddrMode);
293  macHdr.SetNoPanIdComp ();
294  break;
295  case ADDR_MODE_RESERVED:
296  NS_ABORT_MSG ("Can not set source address type to ADDR_MODE_RESERVED. Aborting.");
297  break;
298  case SHORT_ADDR:
299  macHdr.SetSrcAddrMode (params.m_srcAddrMode);
300  macHdr.SetSrcAddrFields (GetPanId (), GetShortAddress ());
301  break;
302  case EXT_ADDR:
303  macHdr.SetSrcAddrMode (params.m_srcAddrMode);
304  macHdr.SetSrcAddrFields (GetPanId (), GetExtendedAddress ());
305  break;
306  default:
307  NS_LOG_ERROR (this << " Can not send packet with incorrect Source Address mode = " << params.m_srcAddrMode);
308  confirmParams.m_status = IEEE_802_15_4_INVALID_ADDRESS;
310  {
311  m_mcpsDataConfirmCallback (confirmParams);
312  }
313  return;
314  }
315  switch (params.m_dstAddrMode)
316  {
317  case NO_PANID_ADDR:
318  macHdr.SetDstAddrMode (params.m_dstAddrMode);
319  macHdr.SetNoPanIdComp ();
320  break;
321  case ADDR_MODE_RESERVED:
322  NS_ABORT_MSG ("Can not set destination address type to ADDR_MODE_RESERVED. Aborting.");
323  break;
324  case SHORT_ADDR:
325  macHdr.SetDstAddrMode (params.m_dstAddrMode);
326  macHdr.SetDstAddrFields (params.m_dstPanId, params.m_dstAddr);
327  break;
328  case EXT_ADDR:
329  macHdr.SetDstAddrMode (params.m_dstAddrMode);
330  macHdr.SetDstAddrFields (params.m_dstPanId, params.m_dstExtAddr);
331  break;
332  default:
333  NS_LOG_ERROR (this << " Can not send packet with incorrect Destination Address mode = " << params.m_dstAddrMode);
334  confirmParams.m_status = IEEE_802_15_4_INVALID_ADDRESS;
336  {
337  m_mcpsDataConfirmCallback (confirmParams);
338  }
339  return;
340  }
341 
342  macHdr.SetSecDisable ();
343  //extract the last 3 bits in TxOptions and map to macHdr
344  int b0 = params.m_txOptions & TX_OPTION_ACK;
345  int b1 = params.m_txOptions & TX_OPTION_GTS;
346  int b2 = params.m_txOptions & TX_OPTION_INDIRECT;
347  if (b0 == TX_OPTION_ACK)
348  {
349  // Set AckReq bit only if the destination is not the broadcast address.
350  if (!(macHdr.GetDstAddrMode () == SHORT_ADDR && macHdr.GetShortDstAddr () == "ff:ff"))
351  {
352  macHdr.SetAckReq ();
353  }
354  }
355  else if (b0 == 0)
356  {
357  macHdr.SetNoAckReq ();
358  }
359  else
360  {
362  NS_LOG_ERROR (this << "Incorrect TxOptions bit 0 not 0/1");
364  {
365  m_mcpsDataConfirmCallback (confirmParams);
366  }
367  return;
368  }
369 
370  //if is Slotted CSMA means its beacon enabled
371  if (m_csmaCa->IsSlottedCsmaCa ())
372  {
373  if (b1 == TX_OPTION_GTS)
374  {
375  //TODO:GTS Transmission
376  }
377  else if (b1 == 0)
378  {
379  //TODO:CAP Transmission
380  }
381  else
382  {
383  NS_LOG_ERROR (this << "Incorrect TxOptions bit 1 not 0/1");
386  {
387  m_mcpsDataConfirmCallback (confirmParams);
388  }
389  return;
390  }
391  }
392  else
393  {
394  if (b1 != 0)
395  {
396  NS_LOG_ERROR (this << "for non-beacon-enables PAN, bit 1 should always be set to 0");
399  {
400  m_mcpsDataConfirmCallback (confirmParams);
401  }
402  return;
403  }
404  }
405 
406  if (b2 == TX_OPTION_INDIRECT)
407  {
408  //TODO :indirect tx
409  }
410  else if (b2 == 0)
411  {
412  //TODO :direct tx
413  }
414  else
415  {
416  NS_LOG_ERROR (this << "Incorrect TxOptions bit 2 not 0/1");
419  {
420  m_mcpsDataConfirmCallback (confirmParams);
421  }
422  return;
423  }
424 
425  p->AddHeader (macHdr);
426 
427  LrWpanMacTrailer macTrailer;
428  // Calculate FCS if the global attribute ChecksumEnable is set.
429  if (Node::ChecksumEnabled ())
430  {
431  macTrailer.EnableFcs (true);
432  macTrailer.SetFcs (p);
433  }
434  p->AddTrailer (macTrailer);
435 
437 
438  TxQueueElement *txQElement = new TxQueueElement;
439  txQElement->txQMsduHandle = params.m_msduHandle;
440  txQElement->txQPkt = p;
441  m_txQueue.push_back (txQElement);
442 
443  CheckQueue ();
444 }
445 
446 void
448 {
449  NS_LOG_FUNCTION (this);
450 
451  // Pull a packet from the queue and start sending, if we are not already sending.
452  if (m_lrWpanMacState == MAC_IDLE && !m_txQueue.empty () && m_txPkt == 0 && !m_setMacState.IsRunning ())
453  {
454  TxQueueElement *txQElement = m_txQueue.front ();
455  m_txPkt = txQElement->txQPkt;
457  }
458 }
459 
460 void
462 {
463  m_csmaCa = csmaCa;
464 }
465 
466 void
468 {
469  m_phy = phy;
470 }
471 
474 {
475  return m_phy;
476 }
477 
478 void
480 {
482 }
483 
484 void
486 {
488 }
489 
490 void
491 LrWpanMac::PdDataIndication (uint32_t psduLength, Ptr<Packet> p, uint8_t lqi)
492 {
494 
495  NS_LOG_FUNCTION (this << psduLength << p << (uint16_t)lqi);
496 
497  bool acceptFrame;
498 
499  // from sec 7.5.6.2 Reception and rejection, Std802.15.4-2006
500  // level 1 filtering, test FCS field and reject if frame fails
501  // level 2 filtering if promiscuous mode pass frame to higher layer otherwise perform level 3 filtering
502  // level 3 filtering accept frame
503  // if Frame type and version is not reserved, and
504  // if there is a dstPanId then dstPanId=m_macPanId or broadcastPanI, and
505  // if there is a shortDstAddr then shortDstAddr =shortMacAddr or broadcastAddr, and
506  // if beacon frame then srcPanId = m_macPanId
507  // if only srcAddr field in Data or Command frame,accept frame if srcPanId=m_macPanId
508 
509  Ptr<Packet> originalPkt = p->Copy (); // because we will strip headers
510 
511  m_promiscSnifferTrace (originalPkt);
512 
513  m_macPromiscRxTrace (originalPkt);
514  // XXX no rejection tracing (to macRxDropTrace) being performed below
515 
516  LrWpanMacTrailer receivedMacTrailer;
517  p->RemoveTrailer (receivedMacTrailer);
518  if (Node::ChecksumEnabled ())
519  {
520  receivedMacTrailer.EnableFcs (true);
521  }
522 
523  // level 1 filtering
524  if (!receivedMacTrailer.CheckFcs (p))
525  {
526  m_macRxDropTrace (originalPkt);
527  }
528  else
529  {
530  LrWpanMacHeader receivedMacHdr;
531  p->RemoveHeader (receivedMacHdr);
532 
534  params.m_dsn = receivedMacHdr.GetSeqNum ();
535  params.m_mpduLinkQuality = lqi;
536  params.m_srcPanId = receivedMacHdr.GetSrcPanId ();
537  params.m_srcAddrMode = receivedMacHdr.GetSrcAddrMode ();
538  switch (params.m_srcAddrMode)
539  {
540  case SHORT_ADDR:
541  params.m_srcAddr = receivedMacHdr.GetShortSrcAddr ();
542  NS_LOG_DEBUG ("Packet from " << params.m_srcAddr);
543  break;
544  case EXT_ADDR:
545  params.m_srcExtAddr = receivedMacHdr.GetExtSrcAddr ();
546  NS_LOG_DEBUG ("Packet from " << params.m_srcExtAddr);
547  break;
548  default:
549  break;
550  }
551  params.m_dstPanId = receivedMacHdr.GetDstPanId ();
552  params.m_dstAddrMode = receivedMacHdr.GetDstAddrMode ();
553  switch (params.m_dstAddrMode)
554  {
555  case SHORT_ADDR:
556  params.m_dstAddr = receivedMacHdr.GetShortDstAddr ();
557  NS_LOG_DEBUG ("Packet to " << params.m_dstAddr);
558  break;
559  case EXT_ADDR:
560  params.m_dstExtAddr = receivedMacHdr.GetExtDstAddr ();
561  NS_LOG_DEBUG ("Packet to " << params.m_dstExtAddr);
562  break;
563  default:
564  break;
565  }
566 
568  {
569  //level 2 filtering
571  {
572  NS_LOG_DEBUG ("promiscuous mode, forwarding up");
573  m_mcpsDataIndicationCallback (params, p);
574  }
575  else
576  {
577  NS_LOG_ERROR (this << " Data Indication Callback not initialised");
578  }
579  }
580  else
581  {
582  //level 3 frame filtering
583  acceptFrame = (receivedMacHdr.GetType () != LrWpanMacHeader::LRWPAN_MAC_RESERVED);
584 
585  if (acceptFrame)
586  {
587  acceptFrame = (receivedMacHdr.GetFrameVer () <= 1);
588  }
589 
590  if (acceptFrame
591  && (receivedMacHdr.GetDstAddrMode () > 1))
592  {
593  acceptFrame = receivedMacHdr.GetDstPanId () == m_macPanId
594  || receivedMacHdr.GetDstPanId () == 0xffff;
595  }
596 
597  if (acceptFrame
598  && (receivedMacHdr.GetDstAddrMode () == 2))
599  {
600  if (receivedMacHdr.GetShortDstAddr () == m_shortAddress)
601  {
602  // unicast, for me
603  acceptFrame = true;
604  }
605  else if (receivedMacHdr.GetShortDstAddr () == Mac16Address ("ff:ff"))
606  {
607  // broadcast
608  acceptFrame = true;
609  }
610  else
611  {
612  // multicast
613  uint8_t buf[2];
614  receivedMacHdr.GetShortDstAddr ().CopyTo (buf);
615  if (buf[0] & 0x80)
616  {
617  acceptFrame = true;
618  }
619  }
620  }
621 
622  if (acceptFrame
623  && (receivedMacHdr.GetDstAddrMode () == 3))
624  {
625  acceptFrame = (receivedMacHdr.GetExtDstAddr () == m_selfExt);
626  }
627 
628  if (acceptFrame
629  && (receivedMacHdr.GetType () == LrWpanMacHeader::LRWPAN_MAC_BEACON))
630  {
631  if (m_macPanId == 0xffff)
632  {
633  // TODO: Accept only if the frame version field is valid
634  acceptFrame = true;
635  }
636  else
637  {
638  acceptFrame = receivedMacHdr.GetSrcPanId () == m_macPanId;
639  }
640  }
641 
642  if (acceptFrame
643  && ((receivedMacHdr.GetType () == LrWpanMacHeader::LRWPAN_MAC_DATA)
644  || (receivedMacHdr.GetType () == LrWpanMacHeader::LRWPAN_MAC_COMMAND))
645  && (receivedMacHdr.GetSrcAddrMode () > 1))
646  {
647  acceptFrame = receivedMacHdr.GetSrcPanId () == m_macPanId; // \todo need to check if PAN coord
648  }
649 
650  if (acceptFrame)
651  {
652  m_macRxTrace (originalPkt);
653  // \todo: What should we do if we receive a frame while waiting for an ACK?
654  // Especially if this frame has the ACK request bit set, should we reply with an ACK, possibly missing the pending ACK?
655 
656  // If the received frame is a frame with the ACK request bit set, we immediately send back an ACK.
657  // If we are currently waiting for a pending ACK, we assume the ACK was lost and trigger a retransmission after sending the ACK.
658  if ((receivedMacHdr.IsData () || receivedMacHdr.IsCommand ()) && receivedMacHdr.IsAckReq ()
659  && !(receivedMacHdr.GetDstAddrMode () == SHORT_ADDR && receivedMacHdr.GetShortDstAddr () == "ff:ff"))
660  {
661  // If this is a data or mac command frame, which is not a broadcast,
662  // with ack req set, generate and send an ack frame.
663  // If there is a CSMA medium access in progress we cancel the medium access
664  // for sending the ACK frame. A new transmission attempt will be started
665  // after the ACK was send.
667  {
670  }
671  else if (m_lrWpanMacState == MAC_CSMA)
672  {
673  // \todo: If we receive a packet while doing CSMA/CA, should we drop the packet because of channel busy,
674  // or should we restart CSMA/CA for the packet after sending the ACK?
675  // Currently we simply restart CSMA/CA after sending the ACK.
676  m_csmaCa->Cancel ();
677  }
678  // Cancel any pending MAC state change, ACKs have higher priority.
682  }
683 
684  if (receivedMacHdr.IsData () && !m_mcpsDataIndicationCallback.IsNull ())
685  {
686  // If it is a data frame, push it up the stack.
687  NS_LOG_DEBUG ("PdDataIndication(): Packet is for me; forwarding up");
688  m_mcpsDataIndicationCallback (params, p);
689  }
690  else if (receivedMacHdr.IsAcknowledgment () && m_txPkt && m_lrWpanMacState == MAC_ACK_PENDING)
691  {
692  LrWpanMacHeader macHdr;
693  m_txPkt->PeekHeader (macHdr);
694  if (receivedMacHdr.GetSeqNum () == macHdr.GetSeqNum ())
695  {
697  // If it is an ACK with the expected sequence number, finish the transmission
698  // and notify the upper layer.
701  {
702  TxQueueElement *txQElement = m_txQueue.front ();
703  McpsDataConfirmParams confirmParams;
704  confirmParams.m_msduHandle = txQElement->txQMsduHandle;
705  confirmParams.m_status = IEEE_802_15_4_SUCCESS;
706  m_mcpsDataConfirmCallback (confirmParams);
707  }
711  }
712  else
713  {
714  // 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)
716  if (!PrepareRetransmission ())
717  {
720  }
721  else
722  {
725  }
726  }
727  }
728  }
729  else
730  {
731  m_macRxDropTrace (originalPkt);
732  }
733  }
734  }
735 }
736 
737 void
738 LrWpanMac::SendAck (uint8_t seqno)
739 {
740  NS_LOG_FUNCTION (this << static_cast<uint32_t> (seqno));
741 
743 
744  // Generate a corresponding ACK Frame.
746  LrWpanMacTrailer macTrailer;
747  Ptr<Packet> ackPacket = Create<Packet> (0);
748  ackPacket->AddHeader (macHdr);
749  // Calculate FCS if the global attribute ChecksumEnable is set.
750  if (Node::ChecksumEnabled ())
751  {
752  macTrailer.EnableFcs (true);
753  macTrailer.SetFcs (ackPacket);
754  }
755  ackPacket->AddTrailer (macTrailer);
756 
757  // Enqueue the ACK packet for further processing
758  // when the transmitter is activated.
759  m_txPkt = ackPacket;
760 
761  // Switch transceiver to TX mode. Proceed sending the Ack on confirm.
763  m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_TX_ON);
764 }
765 
766 void
768 {
769  TxQueueElement *txQElement = m_txQueue.front ();
770  Ptr<const Packet> p = txQElement->txQPkt;
771  m_numCsmacaRetry += m_csmaCa->GetNB () + 1;
772 
773  Ptr<Packet> pkt = p->Copy ();
774  LrWpanMacHeader hdr;
775  pkt->RemoveHeader (hdr);
776  if (hdr.GetShortDstAddr () != Mac16Address ("ff:ff"))
777  {
779  }
780 
781  txQElement->txQPkt = 0;
782  delete txQElement;
783  m_txQueue.pop_front ();
784  m_txPkt = 0;
785  m_retransmission = 0;
786  m_numCsmacaRetry = 0;
788 }
789 
790 void
792 {
793  NS_LOG_FUNCTION (this);
794 
795  // TODO: If we are a PAN coordinator and this was an indirect transmission,
796  // we will not initiate a retransmission. Instead we wait for the data
797  // being extracted after a new data request command.
798  if (!PrepareRetransmission ())
799  {
801  }
802  else
803  {
805  }
806 }
807 
808 bool
810 {
811  NS_LOG_FUNCTION (this);
812 
814  {
815  // Maximum number of retransmissions has been reached.
816  // remove the copy of the packet that was just sent
817  TxQueueElement *txQElement = m_txQueue.front ();
818  m_macTxDropTrace (txQElement->txQPkt);
820  {
821  McpsDataConfirmParams confirmParams;
822  confirmParams.m_msduHandle = txQElement->txQMsduHandle;
823  confirmParams.m_status = IEEE_802_15_4_NO_ACK;
824  m_mcpsDataConfirmCallback (confirmParams);
825  }
827  return false;
828  }
829  else
830  {
832  m_numCsmacaRetry += m_csmaCa->GetNB () + 1;
833  // Start next CCA process for this packet.
834  return true;
835  }
836 }
837 
838 void
840 {
842 
843  NS_LOG_FUNCTION (this << status << m_txQueue.size ());
844 
845  LrWpanMacHeader macHdr;
846  m_txPkt->PeekHeader (macHdr);
847  if (status == IEEE_802_15_4_PHY_SUCCESS)
848  {
849  if (!macHdr.IsAcknowledgment ())
850  {
851  // We have just send a regular data packet, check if we have to wait
852  // for an ACK.
853  if (macHdr.IsAckReq ())
854  {
855  // wait for the ack or the next retransmission timeout
856  // start retransmission timer
857  Time waitTime = MicroSeconds (GetMacAckWaitDuration () * 1000 * 1000 / m_phy->GetDataOrSymbolRate (false));
862  return;
863  }
864  else
865  {
867  // remove the copy of the packet that was just sent
869  {
870  McpsDataConfirmParams confirmParams;
871  NS_ASSERT_MSG (m_txQueue.size () > 0, "TxQsize = 0");
872  TxQueueElement *txQElement = m_txQueue.front ();
873  confirmParams.m_msduHandle = txQElement->txQMsduHandle;
874  confirmParams.m_status = IEEE_802_15_4_SUCCESS;
875  m_mcpsDataConfirmCallback (confirmParams);
876  }
878  }
879  }
880  else
881  {
882  // We have send an ACK. Clear the packet buffer.
883  m_txPkt = 0;
884  }
885  }
886  else if (status == IEEE_802_15_4_PHY_UNSPECIFIED)
887  {
888 
889  if (!macHdr.IsAcknowledgment ())
890  {
891  NS_ASSERT_MSG (m_txQueue.size () > 0, "TxQsize = 0");
892  TxQueueElement *txQElement = m_txQueue.front ();
893  m_macTxDropTrace (txQElement->txQPkt);
895  {
896  McpsDataConfirmParams confirmParams;
897  confirmParams.m_msduHandle = txQElement->txQMsduHandle;
898  confirmParams.m_status = IEEE_802_15_4_FRAME_TOO_LONG;
899  m_mcpsDataConfirmCallback (confirmParams);
900  }
902  }
903  else
904  {
905  NS_LOG_ERROR ("Unable to send ACK");
906  }
907  }
908  else
909  {
910  // Something went really wrong. The PHY is not in the correct state for
911  // data transmission.
912  NS_FATAL_ERROR ("Transmission attempt failed with PHY status " << status);
913  }
914 
917 }
918 
919 void
921 {
922  NS_LOG_FUNCTION (this << status);
923  // Direct this call through the csmaCa object
924  m_csmaCa->PlmeCcaConfirm (status);
925 }
926 
927 void
928 LrWpanMac::PlmeEdConfirm (LrWpanPhyEnumeration status, uint8_t energyLevel)
929 {
930  NS_LOG_FUNCTION (this << status << energyLevel);
931 
932 }
933 
934 void
937  LrWpanPhyPibAttributes* attribute)
938 {
939  NS_LOG_FUNCTION (this << status << id << attribute);
940 }
941 
942 void
944 {
945  NS_LOG_FUNCTION (this << status);
946 
948  {
949  NS_ASSERT (m_txPkt);
950 
951  // Start sending if we are in state SENDING and the PHY transmitter was enabled.
955  m_phy->PdDataRequest (m_txPkt->GetSize (), m_txPkt);
956  }
957  else if (m_lrWpanMacState == MAC_CSMA && (status == IEEE_802_15_4_PHY_RX_ON || status == IEEE_802_15_4_PHY_SUCCESS))
958  {
959  // Start the CSMA algorithm as soon as the receiver is enabled.
960  m_csmaCa->Start ();
961  }
962  else if (m_lrWpanMacState == MAC_IDLE)
963  {
965  // Do nothing special when going idle.
966  }
967  else if (m_lrWpanMacState == MAC_ACK_PENDING)
968  {
970  }
971  else
972  {
973  // TODO: What to do when we receive an error?
974  // If we want to transmit a packet, but switching the transceiver on results
975  // in an error, we have to recover somehow (and start sending again).
976  NS_FATAL_ERROR ("Error changing transceiver state");
977  }
978 }
979 
980 void
983 {
984  NS_LOG_FUNCTION (this << status << id);
985 }
986 
987 void
989 {
990  NS_LOG_FUNCTION (this << "mac state = " << macState);
991 
992  McpsDataConfirmParams confirmParams;
993 
994  if (macState == MAC_IDLE)
995  {
997 
998  if (m_macRxOnWhenIdle)
999  {
1000  m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_RX_ON);
1001  }
1002  else
1003  {
1004  m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_TRX_OFF);
1005  }
1006 
1007  CheckQueue ();
1008  }
1009  else if (macState == MAC_ACK_PENDING)
1010  {
1012  m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_RX_ON);
1013  }
1014  else if (macState == MAC_CSMA)
1015  {
1017 
1019  m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_RX_ON);
1020  }
1021  else if (m_lrWpanMacState == MAC_CSMA && macState == CHANNEL_IDLE)
1022  {
1023  // Channel is idle, set transmitter to TX_ON
1025  m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_TX_ON);
1026  }
1027  else if (m_lrWpanMacState == MAC_CSMA && macState == CHANNEL_ACCESS_FAILURE)
1028  {
1029  NS_ASSERT (m_txPkt);
1030 
1031  // cannot find a clear channel, drop the current packet.
1032  NS_LOG_DEBUG ( this << " cannot find clear channel");
1033  confirmParams.m_msduHandle = m_txQueue.front ()->txQMsduHandle;
1037  {
1038  m_mcpsDataConfirmCallback (confirmParams);
1039  }
1040  // remove the copy of the packet that was just sent
1042 
1044  }
1045 }
1046 
1049 {
1050  return m_associationStatus;
1051 }
1052 
1053 void
1055 {
1056  m_associationStatus = status;
1057 }
1058 
1059 uint16_t
1061 {
1062  return m_macPanId;
1063 }
1064 
1065 void
1066 LrWpanMac::SetPanId (uint16_t panId)
1067 {
1068  m_macPanId = panId;
1069 }
1070 
1071 void
1073 {
1074  NS_LOG_LOGIC (this << " change lrwpan mac state from "
1075  << m_lrWpanMacState << " to "
1076  << newState);
1077  m_macStateLogger (m_lrWpanMacState, newState);
1078  m_lrWpanMacState = newState;
1079 }
1080 
1081 uint64_t
1083 {
1084  return m_csmaCa->GetUnitBackoffPeriod () + m_phy->aTurnaroundTime + m_phy->GetPhySHRDuration ()
1085  + ceil (6 * m_phy->GetPhySymbolsPerOctet ());
1086 }
1087 
1088 uint8_t
1090 {
1091  return m_macMaxFrameRetries;
1092 }
1093 
1094 void
1096 {
1097  m_macMaxFrameRetries = retries;
1098 }
1099 
1100 } // namespace ns3
TracedValue< LrWpanMacState > m_lrWpanMacState
The current state of the MAC layer.
Definition: lr-wpan-mac.h:772
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:280
void EnableFcs(bool enable)
Enable or disable FCS calculation for this trailer.
uint16_t m_dstPanId
Destination PAN identifier.
Definition: lr-wpan-mac.h:159
TX_OPTION_INDIRECT.
Definition: lr-wpan-mac.h:59
virtual void DoInitialize(void)
Initialize() implementation.
Definition: object.cc:353
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
void CheckQueue(void)
Check the transmission queue.
Definition: lr-wpan-mac.cc:447
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
uint8_t GetSeqNum(void) const
Get the frame Sequence number.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition: abort.h:50
Class that implements the LR-WPAN Mac state machine.
Definition: lr-wpan-mac.h:222
Mac16Address GetShortDstAddr(void) const
Get the Destination Short address.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
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...
Definition: lr-wpan-mac.cc:935
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:852
Mac16Address GetShortSrcAddr(void) const
Get the Source Short address.
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
Mac16Address m_dstAddr
Destination address.
Definition: lr-wpan-mac.h:160
void RemoveFirstTxQElement()
Remove the tip of the transmission queue, including clean up related to the last packet transmission...
Definition: lr-wpan-mac.cc:767
Mac64Address m_srcExtAddr
Source extended address.
Definition: lr-wpan-mac.h:187
virtual ~LrWpanMac(void)
Definition: lr-wpan-mac.cc:155
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:659
LrWpanPibAttributeIdentifier
IEEE802.15.4-2006 PHY PIB Attribute Identifiers Table 23 in section 6.4.2.
Definition: lr-wpan-phy.h:140
static bool ChecksumEnabled(void)
Definition: node.cc:276
CHANNEL_IDLE.
Definition: lr-wpan-mac.h:74
bool IsData(void) const
Returns true if the header is a data.
McpsDataConfirmCallback m_mcpsDataConfirmCallback
This callback is used to report data transmission request status to the upper layers.
Definition: lr-wpan-mac.h:767
std::deque< TxQueueElement * > m_txQueue
The transmit queue used by the MAC.
Definition: lr-wpan-mac.h:800
Mac64Address GetExtendedAddress(void) const
Get the extended address of this MAC.
Definition: lr-wpan-mac.cc:244
Mac16Address m_dstAddr
Destination address.
Definition: lr-wpan-mac.h:190
uint8_t m_dstAddrMode
Destination address mode.
Definition: lr-wpan-mac.h:188
#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
Mac64Address m_dstExtAddr
Destination extended address.
Definition: lr-wpan-mac.h:191
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:204
LrWpanAssociationStatus m_associationStatus
The current association status of the MAC layer.
Definition: lr-wpan-mac.h:777
Mac64Address m_dstExtAddr
Destination extended address.
Definition: lr-wpan-mac.h:161
void CopyTo(uint8_t buffer[2]) const
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
virtual void DoDispose(void)
Destructor implementation.
Definition: lr-wpan-mac.cc:175
TracedCallback< LrWpanMacState, LrWpanMacState > m_macStateLogger
A trace source that fires when the LrWpanMac changes states.
Definition: lr-wpan-mac.h:744
void SetShortAddress(Mac16Address address)
Set the short address of this MAC.
Definition: lr-wpan-mac.cc:222
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
Represent the Mac Header with the Frame Control and Sequence Number fields.
bool IsCommand(void) const
Returns true if the header is a command.
uint16_t GetDstPanId(void) const
Get the Destination PAN ID.
IEEE802.15.4-2006 PHY PIB Attributes Table 23 in section 6.4.2.
Definition: lr-wpan-phy.h:157
McpsDataIndicationCallback m_mcpsDataIndicationCallback
This callback is used to notify incoming packets to the upper layers.
Definition: lr-wpan-mac.h:760
void SetMcpsDataConfirmCallback(McpsDataConfirmCallback c)
Set the callback for the confirmation of a data transmission request.
Definition: lr-wpan-mac.cc:485
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:250
uint8_t m_numCsmacaRetry
The number of CSMA/CA retries used for sending the current packet.
Definition: lr-wpan-mac.h:811
bool IsExpired(void) const
This method is syntactic sugar for the ns3::Simulator::IsExpired method.
Definition: event-id.cc:59
uint8_t m_msduHandle
MSDU handle.
Definition: lr-wpan-mac.h:162
uint8_t m_msduHandle
MSDU handle.
Definition: lr-wpan-mac.h:173
uint8_t GetFrameVer(void) const
Get the Frame Version of Frame control field.
static const uint32_t aMaxPhyPacketSize
The maximum packet size accepted by the PHY.
Definition: lr-wpan-phy.h:262
uint16_t m_dstPanId
Destination PAN identifier.
Definition: lr-wpan-mac.h:189
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
TracedCallback< Ptr< const Packet > > m_macTxTrace
The trace source fired when packets are being sent down to L1.
Definition: lr-wpan-mac.h:650
an EUI-64 address
Definition: mac64-address.h:43
phy
Definition: third.py:93
Ptr< Packet > m_txPkt
The packet which is currently being sent by the MAC layer.
Definition: lr-wpan-mac.h:782
bool GetRxOnWhenIdle(void)
Check if the receiver will be enabled when the MAC is idle.
Definition: lr-wpan-mac.cc:197
LrWpanAssociationStatus GetAssociationStatus(void) const
Get the current association status.
void SetLrWpanMacState(LrWpanMacState macState)
CSMA-CA algorithm calls back the MAC after executing channel assessment.
Definition: lr-wpan-mac.cc:988
void SetMacMaxFrameRetries(uint8_t retries)
Set the macMaxFrameRetries attribute value.
void PlmeEdConfirm(LrWpanPhyEnumeration status, uint8_t energyLevel)
IEEE 802.15.4-2006 section 6.2.2.4 PLME-ED.confirm status and energy level.
Definition: lr-wpan-mac.cc:928
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:734
TX_OPTION_ACK.
Definition: lr-wpan-mac.h:57
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:635
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:685
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1389
Ptr< Packet > txQPkt
Queued packet.
Definition: lr-wpan-mac.h:573
uint8_t GetDstAddrMode(void) const
Get the Dest.
bool PrepareRetransmission(void)
Check for remaining retransmissions for the packet currently being sent.
Definition: lr-wpan-mac.cc:809
void PlmeCcaConfirm(LrWpanPhyEnumeration status)
IEEE 802.15.4-2006 section 6.2.2.2 PLME-CCA.confirm status.
Definition: lr-wpan-mac.cc:920
Hold an unsigned integer type.
Definition: uinteger.h:44
EventId m_ackWaitTimeout
Scheduler event for the ACK timeout of the currently transmitted data packet.
Definition: lr-wpan-mac.h: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:667
uint16_t GetPanId(void) const
Get the PAN id used by this MAC.
EventId m_setMacState
Scheduler event for a deferred MAC state change.
Definition: lr-wpan-mac.h:822
Helper structure for managing transmission queue elements.
Definition: lr-wpan-mac.h:570
bool m_macRxOnWhenIdle
Indication of whether the MAC sublayer is to enable its receiver during idle periods.
Definition: lr-wpan-mac.h:516
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Definition: packet.cc:290
enum LrWpanMacType GetType(void) const
Get the header type.
MCPS-DATA.confirm params.
Definition: lr-wpan-mac.h:171
void PdDataConfirm(LrWpanPhyEnumeration status)
IEEE 802.15.4-2006 section 6.2.1.2 Confirm the end of transmission of an MPDU to MAC.
Definition: lr-wpan-mac.cc:839
uint8_t m_txOptions
Tx Options (bitfield)
Definition: lr-wpan-mac.h:163
uint8_t m_mpduLinkQuality
LQI value measured during reception of the MPDU.
Definition: lr-wpan-mac.h:192
void SetPhy(Ptr< LrWpanPhy > phy)
Set the underlying PHY for the MAC.
Definition: lr-wpan-mac.cc:467
void SetFcs(Ptr< const Packet > p)
Calculate and set the FCS value based on the given packet.
bool IsAcknowledgment(void) const
Returns true if the header is an ack.
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:627
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...
Definition: lr-wpan-mac.cc:491
uint8_t m_srcAddrMode
Source address mode.
Definition: lr-wpan-mac.h:184
Mac64Address GetExtSrcAddr(void) const
Get the Source Extended address.
LrWpanMcpsDataConfirmStatus m_status
The status of the last MSDU transmission.
Definition: lr-wpan-mac.h:174
LrWpanAddressMode m_srcAddrMode
Source address mode.
Definition: lr-wpan-mac.h:157
uint8_t m_retransmission
The number of already used retransmission for the currently transmitted packet.
Definition: lr-wpan-mac.h:806
Mac64Address m_selfExt
The extended address used by this MAC.
Definition: lr-wpan-mac.h:795
uint64_t GetMacAckWaitDuration(void) const
Get the macAckWaitDuration attribute value.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t GetSrcAddrMode(void) const
Get the Source Addressing Mode of Frame control field.
address
Definition: first.py:37
LrWpanAddressMode m_dstAddrMode
Destination address mode.
Definition: lr-wpan-mac.h:158
bool IsAckReq(void) const
Check if Ack.
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
double GetValue(double min, double max)
Get the next random value, as a double in the specified range .
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:694
TX_OPTION_GTS.
Definition: lr-wpan-mac.h:58
void SetRxOnWhenIdle(bool rxOnWhenIdle)
Set if the receiver should be enabled when the MAC is idle.
Definition: lr-wpan-mac.cc:203
uint32_t RemoveTrailer(Trailer &trailer)
Remove a deserialized trailer from the internal buffer.
Definition: packet.cc:318
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:676
bool m_macPromiscuousMode
Indicates if MAC sublayer is in receive all mode.
Definition: lr-wpan-mac.h:490
Mac16Address m_srcAddr
Source address.
Definition: lr-wpan-mac.h:186
static EventId ScheduleNow(MEM mem_ptr, OBJ obj)
Schedule an event to expire Now.
Definition: simulator.h:1578
This class can contain 16 bit addresses.
Definition: mac16-address.h:41
uint8_t m_dsn
The DSN of the received data frame.
Definition: lr-wpan-mac.h:193
LrWpanMac(void)
Default constructor.
Definition: lr-wpan-mac.cc:131
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
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:714
void SetExtendedAddress(Mac64Address address)
Set the extended address of this MAC.
Definition: lr-wpan-mac.cc:229
uint8_t m_macMaxFrameRetries
The maximum number of retries allowed after a transmission failure.
Definition: lr-wpan-mac.h:509
uint8_t txQMsduHandle
MSDU Handle.
Definition: lr-wpan-mac.h:572
uint16_t GetSrcPanId(void) const
Get the Source PAN ID.
static TypeId GetTypeId(void)
Get the type ID.
Definition: lr-wpan-mac.cc:50
Represent the Mac Trailer with the Frame Check Sequence field.
Ptr< LrWpanPhy > m_phy
The PHY associated with this MAC.
Definition: lr-wpan-mac.h:749
CHANNEL_ACCESS_FAILURE.
Definition: lr-wpan-mac.h:73
MAC_CSMA.
Definition: lr-wpan-mac.h:70
SequenceNumber8 m_macDsn
Sequence number added to transmitted data or MAC command frame, 00-ff.
Definition: lr-wpan-mac.h:503
MAC_ACK_PENDING.
Definition: lr-wpan-mac.h:72
static const uint32_t aMinMPDUOverhead
The minimum number of octets added by the MAC sublayer to the PSDU.
Definition: lr-wpan-mac.h:236
void ChangeMacState(LrWpanMacState newState)
Change the current MAC state to the given new state.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:272
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:65
Ptr< LrWpanCsmaCa > m_csmaCa
The CSMA/CA implementation used by this MAC.
Definition: lr-wpan-mac.h:754
LrWpanMacState
MAC states.
Definition: lr-wpan-mac.h:67
LrWpanAssociationStatus
table 83 of 802.15.4
Definition: lr-wpan-mac.h:110
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:53
uint8_t GetMacMaxFrameRetries(void) const
Get the macMaxFrameRetries attribute value.
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:643
uint16_t m_macPanId
16 bits id of PAN on which this device is operating.
Definition: lr-wpan-mac.h:497
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1078
SequenceNumber< uint8_t, int8_t > SequenceNumber8
8 bit Sequence number.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:256
void PlmeSetTRXStateConfirm(LrWpanPhyEnumeration status)
IEEE 802.15.4-2006 section 6.2.2.8 PLME-SET-TRX-STATE.confirm Set PHY state.
Definition: lr-wpan-mac.cc:943
LrWpanPhyEnumeration
IEEE802.15.4-2006 PHY Emumerations Table 18 in section 6.2.3.
Definition: lr-wpan-phy.h:105
void SendAck(uint8_t seqno)
Send an acknowledgment packet for the given sequence number.
Definition: lr-wpan-mac.cc:738
MCPS-DATA.request params.
Definition: lr-wpan-mac.h:146
bool CheckFcs(Ptr< const Packet > p)
Check the FCS of a given packet against the FCS value stored in the trailer.
A base class which provides memory management and object aggregation.
Definition: object.h:87
void AckWaitTimeout(void)
Handle an ACK timeout with a packet retransmission, if there are retransmission left, or a packet drop.
Definition: lr-wpan-mac.cc:791
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:1270
This class can be used to hold variables of floating point type such as &#39;double&#39; or &#39;float&#39;...
Definition: double.h:41
Ptr< LrWpanPhy > GetPhy(void)
Get the underlying PHY of the MAC.
Definition: lr-wpan-mac.cc:473
Mac16Address m_shortAddress
The short address used by this MAC.
Definition: lr-wpan-mac.h:789
NUMERIC_TYPE GetValue() const
Extracts the numeric value of the sequence number.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:185
Mac16Address GetShortAddress(void) const
Get the short address of this MAC.
Definition: lr-wpan-mac.cc:237
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: uinteger.h:45
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
void SetCsmaCa(Ptr< LrWpanCsmaCa > csmaCa)
Set the CSMA/CA implementation to be used by the MAC.
Definition: lr-wpan-mac.cc:461
void SetPanId(uint16_t panId)
Set the PAN id used by this MAC.
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...
Definition: lr-wpan-mac.cc:981
virtual void DoInitialize(void)
Initialize() implementation.
Definition: lr-wpan-mac.cc:160
static Mac64Address Allocate(void)
Allocate a new Mac64Address.
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
MAC_SENDING.
Definition: lr-wpan-mac.h:71
uint16_t m_srcPanId
Source PAN identifier.
Definition: lr-wpan-mac.h:185
MAC_IDLE.
Definition: lr-wpan-mac.h:69
void SetAssociationStatus(LrWpanAssociationStatus status)
Set the current association status.
MCPS-DATA.indication params.
Definition: lr-wpan-mac.h:182
Mac64Address GetExtDstAddr(void) const
Get the Destination Extended address.
void SetMcpsDataIndicationCallback(McpsDataIndicationCallback c)
Set the callback for the indication of an incoming data packet.
Definition: lr-wpan-mac.cc:479