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  acceptFrame = receivedMacHdr.GetShortDstAddr () == m_shortAddress
601  || receivedMacHdr.GetShortDstAddr () == Mac16Address ("ff:ff"); // check for broadcast addrs
602  }
603 
604  if (acceptFrame
605  && (receivedMacHdr.GetDstAddrMode () == 3))
606  {
607  acceptFrame = (receivedMacHdr.GetExtDstAddr () == m_selfExt);
608  }
609 
610  if (acceptFrame
611  && (receivedMacHdr.GetType () == LrWpanMacHeader::LRWPAN_MAC_BEACON))
612  {
613  if (m_macPanId == 0xffff)
614  {
615  // TODO: Accept only if the frame version field is valid
616  acceptFrame = true;
617  }
618  else
619  {
620  acceptFrame = receivedMacHdr.GetSrcPanId () == m_macPanId;
621  }
622  }
623 
624  if (acceptFrame
625  && ((receivedMacHdr.GetType () == LrWpanMacHeader::LRWPAN_MAC_DATA)
626  || (receivedMacHdr.GetType () == LrWpanMacHeader::LRWPAN_MAC_COMMAND))
627  && (receivedMacHdr.GetSrcAddrMode () > 1))
628  {
629  acceptFrame = receivedMacHdr.GetSrcPanId () == m_macPanId; // \todo need to check if PAN coord
630  }
631 
632  if (acceptFrame)
633  {
634  m_macRxTrace (originalPkt);
635  // \todo: What should we do if we receive a frame while waiting for an ACK?
636  // Especially if this frame has the ACK request bit set, should we reply with an ACK, possibly missing the pending ACK?
637 
638  // If the received frame is a frame with the ACK request bit set, we immediately send back an ACK.
639  // If we are currently waiting for a pending ACK, we assume the ACK was lost and trigger a retransmission after sending the ACK.
640  if ((receivedMacHdr.IsData () || receivedMacHdr.IsCommand ()) && receivedMacHdr.IsAckReq ()
641  && !(receivedMacHdr.GetDstAddrMode () == SHORT_ADDR && receivedMacHdr.GetShortDstAddr () == "ff:ff"))
642  {
643  // If this is a data or mac command frame, which is not a broadcast,
644  // with ack req set, generate and send an ack frame.
645  // If there is a CSMA medium access in progress we cancel the medium access
646  // for sending the ACK frame. A new transmission attempt will be started
647  // after the ACK was send.
649  {
652  }
653  else if (m_lrWpanMacState == MAC_CSMA)
654  {
655  // \todo: If we receive a packet while doing CSMA/CA, should we drop the packet because of channel busy,
656  // or should we restart CSMA/CA for the packet after sending the ACK?
657  // Currently we simply restart CSMA/CA after sending the ACK.
658  m_csmaCa->Cancel ();
659  }
660  // Cancel any pending MAC state change, ACKs have higher priority.
664  }
665 
666  if (receivedMacHdr.IsData () && !m_mcpsDataIndicationCallback.IsNull ())
667  {
668  // If it is a data frame, push it up the stack.
669  NS_LOG_DEBUG ("PdDataIndication(): Packet is for me; forwarding up");
670  m_mcpsDataIndicationCallback (params, p);
671  }
672  else if (receivedMacHdr.IsAcknowledgment () && m_txPkt && m_lrWpanMacState == MAC_ACK_PENDING)
673  {
674  LrWpanMacHeader macHdr;
675  m_txPkt->PeekHeader (macHdr);
676  if (receivedMacHdr.GetSeqNum () == macHdr.GetSeqNum ())
677  {
679  // If it is an ACK with the expected sequence number, finish the transmission
680  // and notify the upper layer.
683  {
684  TxQueueElement *txQElement = m_txQueue.front ();
685  McpsDataConfirmParams confirmParams;
686  confirmParams.m_msduHandle = txQElement->txQMsduHandle;
687  confirmParams.m_status = IEEE_802_15_4_SUCCESS;
688  m_mcpsDataConfirmCallback (confirmParams);
689  }
693  }
694  else
695  {
696  // 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)
698  if (!PrepareRetransmission ())
699  {
702  }
703  else
704  {
707  }
708  }
709  }
710  }
711  else
712  {
713  m_macRxDropTrace (originalPkt);
714  }
715  }
716  }
717 }
718 
719 void
720 LrWpanMac::SendAck (uint8_t seqno)
721 {
722  NS_LOG_FUNCTION (this << static_cast<uint32_t> (seqno));
723 
725 
726  // Generate a corresponding ACK Frame.
728  LrWpanMacTrailer macTrailer;
729  Ptr<Packet> ackPacket = Create<Packet> (0);
730  ackPacket->AddHeader (macHdr);
731  // Calculate FCS if the global attribute ChecksumEnable is set.
732  if (Node::ChecksumEnabled ())
733  {
734  macTrailer.EnableFcs (true);
735  macTrailer.SetFcs (ackPacket);
736  }
737  ackPacket->AddTrailer (macTrailer);
738 
739  // Enqueue the ACK packet for further processing
740  // when the transmitter is activated.
741  m_txPkt = ackPacket;
742 
743  // Switch transceiver to TX mode. Proceed sending the Ack on confirm.
745  m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_TX_ON);
746 }
747 
748 void
750 {
751  TxQueueElement *txQElement = m_txQueue.front ();
752  Ptr<const Packet> p = txQElement->txQPkt;
753  m_numCsmacaRetry += m_csmaCa->GetNB () + 1;
754 
755  Ptr<Packet> pkt = p->Copy ();
756  LrWpanMacHeader hdr;
757  pkt->RemoveHeader (hdr);
758  if (hdr.GetShortDstAddr () != Mac16Address ("ff:ff"))
759  {
761  }
762 
763  txQElement->txQPkt = 0;
764  delete txQElement;
765  m_txQueue.pop_front ();
766  m_txPkt = 0;
767  m_retransmission = 0;
768  m_numCsmacaRetry = 0;
770 }
771 
772 void
774 {
775  NS_LOG_FUNCTION (this);
776 
777  // TODO: If we are a PAN coordinator and this was an indirect transmission,
778  // we will not initiate a retransmission. Instead we wait for the data
779  // being extracted after a new data request command.
780  if (!PrepareRetransmission ())
781  {
783  }
784  else
785  {
787  }
788 }
789 
790 bool
792 {
793  NS_LOG_FUNCTION (this);
794 
796  {
797  // Maximum number of retransmissions has been reached.
798  // remove the copy of the packet that was just sent
799  TxQueueElement *txQElement = m_txQueue.front ();
800  m_macTxDropTrace (txQElement->txQPkt);
802  {
803  McpsDataConfirmParams confirmParams;
804  confirmParams.m_msduHandle = txQElement->txQMsduHandle;
805  confirmParams.m_status = IEEE_802_15_4_NO_ACK;
806  m_mcpsDataConfirmCallback (confirmParams);
807  }
809  return false;
810  }
811  else
812  {
814  m_numCsmacaRetry += m_csmaCa->GetNB () + 1;
815  // Start next CCA process for this packet.
816  return true;
817  }
818 }
819 
820 void
822 {
824 
825  NS_LOG_FUNCTION (this << status << m_txQueue.size ());
826 
827  LrWpanMacHeader macHdr;
828  m_txPkt->PeekHeader (macHdr);
829  if (status == IEEE_802_15_4_PHY_SUCCESS)
830  {
831  if (!macHdr.IsAcknowledgment ())
832  {
833  // We have just send a regular data packet, check if we have to wait
834  // for an ACK.
835  if (macHdr.IsAckReq ())
836  {
837  // wait for the ack or the next retransmission timeout
838  // start retransmission timer
839  Time waitTime = MicroSeconds (GetMacAckWaitDuration () * 1000 * 1000 / m_phy->GetDataOrSymbolRate (false));
844  return;
845  }
846  else
847  {
849  // remove the copy of the packet that was just sent
851  {
852  McpsDataConfirmParams confirmParams;
853  NS_ASSERT_MSG (m_txQueue.size () > 0, "TxQsize = 0");
854  TxQueueElement *txQElement = m_txQueue.front ();
855  confirmParams.m_msduHandle = txQElement->txQMsduHandle;
856  confirmParams.m_status = IEEE_802_15_4_SUCCESS;
857  m_mcpsDataConfirmCallback (confirmParams);
858  }
860  }
861  }
862  else
863  {
864  // We have send an ACK. Clear the packet buffer.
865  m_txPkt = 0;
866  }
867  }
868  else if (status == IEEE_802_15_4_PHY_UNSPECIFIED)
869  {
870 
871  if (!macHdr.IsAcknowledgment ())
872  {
873  NS_ASSERT_MSG (m_txQueue.size () > 0, "TxQsize = 0");
874  TxQueueElement *txQElement = m_txQueue.front ();
875  m_macTxDropTrace (txQElement->txQPkt);
877  {
878  McpsDataConfirmParams confirmParams;
879  confirmParams.m_msduHandle = txQElement->txQMsduHandle;
880  confirmParams.m_status = IEEE_802_15_4_FRAME_TOO_LONG;
881  m_mcpsDataConfirmCallback (confirmParams);
882  }
884  }
885  else
886  {
887  NS_LOG_ERROR ("Unable to send ACK");
888  }
889  }
890  else
891  {
892  // Something went really wrong. The PHY is not in the correct state for
893  // data transmission.
894  NS_FATAL_ERROR ("Transmission attempt failed with PHY status " << status);
895  }
896 
899 }
900 
901 void
903 {
904  NS_LOG_FUNCTION (this << status);
905  // Direct this call through the csmaCa object
906  m_csmaCa->PlmeCcaConfirm (status);
907 }
908 
909 void
910 LrWpanMac::PlmeEdConfirm (LrWpanPhyEnumeration status, uint8_t energyLevel)
911 {
912  NS_LOG_FUNCTION (this << status << energyLevel);
913 
914 }
915 
916 void
919  LrWpanPhyPibAttributes* attribute)
920 {
921  NS_LOG_FUNCTION (this << status << id << attribute);
922 }
923 
924 void
926 {
927  NS_LOG_FUNCTION (this << status);
928 
930  {
931  NS_ASSERT (m_txPkt);
932 
933  // Start sending if we are in state SENDING and the PHY transmitter was enabled.
937  m_phy->PdDataRequest (m_txPkt->GetSize (), m_txPkt);
938  }
939  else if (m_lrWpanMacState == MAC_CSMA && (status == IEEE_802_15_4_PHY_RX_ON || status == IEEE_802_15_4_PHY_SUCCESS))
940  {
941  // Start the CSMA algorithm as soon as the receiver is enabled.
942  m_csmaCa->Start ();
943  }
944  else if (m_lrWpanMacState == MAC_IDLE)
945  {
947  // Do nothing special when going idle.
948  }
949  else if (m_lrWpanMacState == MAC_ACK_PENDING)
950  {
952  }
953  else
954  {
955  // TODO: What to do when we receive an error?
956  // If we want to transmit a packet, but switching the transceiver on results
957  // in an error, we have to recover somehow (and start sending again).
958  NS_FATAL_ERROR ("Error changing transceiver state");
959  }
960 }
961 
962 void
965 {
966  NS_LOG_FUNCTION (this << status << id);
967 }
968 
969 void
971 {
972  NS_LOG_FUNCTION (this << "mac state = " << macState);
973 
974  McpsDataConfirmParams confirmParams;
975 
976  if (macState == MAC_IDLE)
977  {
979 
980  if (m_macRxOnWhenIdle)
981  {
982  m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_RX_ON);
983  }
984  else
985  {
986  m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_TRX_OFF);
987  }
988 
989  CheckQueue ();
990  }
991  else if (macState == MAC_ACK_PENDING)
992  {
994  m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_RX_ON);
995  }
996  else if (macState == MAC_CSMA)
997  {
999 
1001  m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_RX_ON);
1002  }
1003  else if (m_lrWpanMacState == MAC_CSMA && macState == CHANNEL_IDLE)
1004  {
1005  // Channel is idle, set transmitter to TX_ON
1007  m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_TX_ON);
1008  }
1009  else if (m_lrWpanMacState == MAC_CSMA && macState == CHANNEL_ACCESS_FAILURE)
1010  {
1011  NS_ASSERT (m_txPkt);
1012 
1013  // cannot find a clear channel, drop the current packet.
1014  NS_LOG_DEBUG ( this << " cannot find clear channel");
1015  confirmParams.m_msduHandle = m_txQueue.front ()->txQMsduHandle;
1019  {
1020  m_mcpsDataConfirmCallback (confirmParams);
1021  }
1022  // remove the copy of the packet that was just sent
1024 
1026  }
1027 }
1028 
1031 {
1032  return m_associationStatus;
1033 }
1034 
1035 void
1037 {
1038  m_associationStatus = status;
1039 }
1040 
1041 uint16_t
1043 {
1044  return m_macPanId;
1045 }
1046 
1047 void
1048 LrWpanMac::SetPanId (uint16_t panId)
1049 {
1050  m_macPanId = panId;
1051 }
1052 
1053 void
1055 {
1056  NS_LOG_LOGIC (this << " change lrwpan mac state from "
1057  << m_lrWpanMacState << " to "
1058  << newState);
1059  m_macStateLogger (m_lrWpanMacState, newState);
1060  m_lrWpanMacState = newState;
1061 }
1062 
1063 uint64_t
1065 {
1066  return m_csmaCa->GetUnitBackoffPeriod () + m_phy->aTurnaroundTime + m_phy->GetPhySHRDuration ()
1067  + ceil (6 * m_phy->GetPhySymbolsPerOctet ());
1068 }
1069 
1070 uint8_t
1072 {
1073  return m_macMaxFrameRetries;
1074 }
1075 
1076 void
1078 {
1079  m_macMaxFrameRetries = retries;
1080 }
1081 
1082 } // 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:917
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:831
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:749
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:202
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
#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:86
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:970
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:910
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:1381
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:791
void PlmeCcaConfirm(LrWpanPhyEnumeration status)
IEEE 802.15.4-2006 section 6.2.2.2 PLME-CCA.confirm status.
Definition: lr-wpan-mac.cc:902
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:821
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:1570
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:270
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:1030
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:254
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:925
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:720
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:773
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:963
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