Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
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 * Vishwesh Rege <vrege2012@gmail.com> | |
24 */ | |
Tommaso Pecorella
2015/07/22 15:46:37
see the comment on the .cc - just one author in th
vrege
2015/07/25 10:22:47
Done.
| |
25 #ifndef LR_WPAN_CONTIKIMAC_H | |
26 #define LR_WPAN_CONTIKIMAC_H | |
27 | |
28 #include "lr-wpan-mac.h" | |
29 | |
30 | |
31 namespace ns3 { | |
32 | |
33 /** | |
34 * \defgroup lr-wpan LR-WPAN models | |
35 * | |
36 * This section documents the API of the IEEE 802.15.4-related models. For a ge neric functional description, please refer to the ns-3 manual. | |
37 */ | |
38 | |
39 /** | |
40 * \ingroup lr-wpan | |
41 * \brief Neighbor description | |
42 */ | |
43 struct Neighbor | |
44 { | |
45 Mac16Address m_neighborAddress; | |
46 Time m_wakeupTime; | |
47 uint8_t failedTransmissions; | |
48 }; | |
49 | |
50 /** | |
51 * \ingroup lr-wpan | |
52 * | |
53 * Class that implements the LR-WPAN Mac state machine | |
54 */ | |
55 class LrWpanContikiMac : public LrWpanMac, public LrWpanPhyListener | |
56 { | |
57 public: | |
58 | |
59 /** | |
60 * Get the type ID. | |
61 * | |
62 * \return the object TypeId | |
63 */ | |
64 static TypeId GetTypeId (void); | |
65 | |
66 /** | |
67 * Default constructor. | |
68 */ | |
69 LrWpanContikiMac (void); | |
70 virtual ~LrWpanContikiMac (void); | |
71 | |
72 /** | |
73 * The minimum number of octets added by the MAC sublayer to the PSDU. | |
74 * See IEEE 802.15.4-2006, section 7.4.1, Table 85 | |
75 */ | |
76 static const uint32_t aMinMPDUOverhead; | |
77 | |
78 /** | |
79 * The maximum packet time (for ContikiMAC Fast Sleep). | |
80 * The 2400 MHz PHY has a maximum packet time of 4.256 ms, and the 915 MHz PHY has a maximum packet time of 26.6 ms | |
81 */ | |
82 static const double maxPacketTime; | |
83 | |
84 // ContikiMAC variables. | |
85 double m_sleepTime; //Time asleep / wake-up interval | |
86 double m_ccaInterval; //the interval between each CCA | |
87 double m_pktInterval; //the interval between each packet transmission | |
88 bool m_fastSleep; //enable the ContikiMAC fast sleep optimization | |
89 | |
90 /** | |
91 * The maximum number of retries for ContikiMAC RDC. | |
92 */ | |
93 uint8_t m_rdcMaxFrameRetries; | |
94 | |
95 virtual void NotifyRx (void); | |
96 virtual void NotifyRxStart (void); | |
97 virtual void NotifyTx (void); | |
98 virtual void NotifyTxStart (void); | |
99 virtual void NotifySleep (void); | |
100 virtual void NotifyTransition (int); | |
101 | |
102 // XXX these setters will become obsolete if we use the attribute system | |
103 /** | |
104 * Set the short address of this MAC. | |
105 * | |
106 * \param address the new address | |
107 */ | |
108 void SetShortAddress (Mac16Address address); | |
109 | |
110 /** | |
111 * Get the short address of this MAC. | |
112 * | |
113 * \return the short address | |
114 */ | |
115 Mac16Address GetShortAddress (void) const; | |
116 | |
117 /** | |
118 * Set the extended address of this MAC. | |
119 * | |
120 * \param address the new address | |
121 */ | |
122 void SetExtendedAddress (Mac64Address address); | |
123 | |
124 /** | |
125 * Get the extended address of this MAC. | |
126 * | |
127 * \return the extended address | |
128 */ | |
129 Mac64Address GetExtendedAddress (void) const; | |
130 | |
131 /** | |
132 * Set the PAN id used by this MAC. | |
133 * | |
134 * \param panId the new PAN id. | |
135 */ | |
136 void SetPanId (uint16_t panId); | |
137 | |
138 /** | |
139 * Get the PAN id used by this MAC. | |
140 * | |
141 * \return the PAN id. | |
142 */ | |
143 uint16_t GetPanId (void) const; | |
144 | |
145 /** | |
146 * IEEE 802.15.4-2006, section 7.1.1.1 | |
147 * MCPS-DATA.request | |
148 * Request to transfer a MSDU. | |
149 * | |
150 * \param params the request parameters | |
151 * \param p the packet to be transmitted | |
152 */ | |
153 void McpsDataRequest (McpsDataRequestParams params, Ptr<Packet> p); | |
154 | |
155 /** | |
156 * Set the CSMA/CA implementation to be used by the MAC. | |
157 * | |
158 * \param csmaCa the CSMA/CA implementation | |
159 */ | |
160 void SetCsmaCa (Ptr<LrWpanCsmaCa> csmaCa); | |
161 | |
162 /** | |
163 * Set the underlying PHY for the MAC. | |
164 * | |
165 * \param phy the PHY | |
166 */ | |
167 void SetPhy (Ptr<LrWpanPhy> phy); | |
168 | |
169 /** | |
170 * Get the underlying PHY of the MAC. | |
171 * | |
172 * \return the PHY | |
173 */ | |
174 Ptr<LrWpanPhy> GetPhy (void); | |
175 | |
176 /** | |
177 * Set the callback for the indication of an incoming data packet. | |
178 * The callback implements MCPS-DATA.indication SAP of IEEE 802.15.4-2006, | |
179 * section 7.1.1.3. | |
180 * | |
181 * \param c the callback | |
182 */ | |
183 void SetMcpsDataIndicationCallback (McpsDataIndicationCallback c); | |
184 | |
185 /** | |
186 * Set the callback for the confirmation of a data transmission request. | |
187 * The callback implements MCPS-DATA.confirm SAP of IEEE 802.15.4-2006, | |
188 * section 7.1.1.2. | |
189 * | |
190 * \param c the callback | |
191 */ | |
192 void SetMcpsDataConfirmCallback (McpsDataConfirmCallback c); | |
193 | |
194 // interfaces between MAC and PHY | |
195 /** | |
196 * IEEE 802.15.4-2006 section 6.2.1.3 | |
197 * PD-DATA.indication | |
198 * Indicates the transfer of an MPDU from PHY to MAC (receiving) | |
199 * @param psduLength number of bytes in the PSDU | |
200 * @param p the packet to be transmitted | |
201 * @param lqi Link quality (LQI) value measured during reception of the PPDU | |
202 */ | |
203 void PdDataIndication (uint32_t psduLength, Ptr<Packet> p, uint8_t lqi); | |
204 | |
205 /** | |
206 * IEEE 802.15.4-2006 section 6.2.1.2 | |
207 * Confirm the end of transmission of an MPDU to MAC | |
208 * @param status to report to MAC | |
209 * PHY PD-DATA.confirm status | |
210 */ | |
211 void PdDataConfirm (LrWpanPhyEnumeration status); | |
212 | |
213 /** | |
214 * IEEE 802.15.4-2006 section 6.2.2.2 | |
215 * PLME-CCA.confirm status | |
216 * @param status TRX_OFF, BUSY or IDLE | |
217 */ | |
218 void PlmeCcaConfirm (LrWpanPhyEnumeration status); | |
219 | |
220 /** | |
221 * IEEE 802.15.4-2006 section 6.2.2.4 | |
222 * PLME-ED.confirm status and energy level | |
223 * @param status SUCCESS, TRX_OFF or TX_ON | |
224 * @param energyLevel 0x00-0xff ED level for the channel | |
225 */ | |
226 void PlmeEdConfirm (LrWpanPhyEnumeration status, uint8_t energyLevel); | |
227 | |
228 /** | |
229 * IEEE 802.15.4-2006 section 6.2.2.6 | |
230 * PLME-GET.confirm | |
231 * Get attributes per definition from Table 23 in section 6.4.2 | |
232 * @param status SUCCESS or UNSUPPORTED_ATTRIBUTE | |
233 * @param id the attributed identifier | |
234 * @param attribute the attribute value | |
235 */ | |
236 void PlmeGetAttributeConfirm (LrWpanPhyEnumeration status, | |
237 LrWpanPibAttributeIdentifier id, | |
238 LrWpanPhyPibAttributes* attribute); | |
239 | |
240 /** | |
241 * IEEE 802.15.4-2006 section 6.2.2.8 | |
242 * PLME-SET-TRX-STATE.confirm | |
243 * Set PHY state | |
244 * @param status in RX_ON,TRX_OFF,FORCE_TRX_OFF,TX_ON | |
245 */ | |
246 void PlmeSetTRXStateConfirm (LrWpanPhyEnumeration status); | |
247 | |
248 /** | |
249 * IEEE 802.15.4-2006 section 6.2.2.10 | |
250 * PLME-SET.confirm | |
251 * Set attributes per definition from Table 23 in section 6.4.2 | |
252 * @param status SUCCESS, UNSUPPORTED_ATTRIBUTE, INVALID_PARAMETER, or READ_O NLY | |
253 * @param id the attributed identifier | |
254 */ | |
255 void PlmeSetAttributeConfirm (LrWpanPhyEnumeration status, | |
256 LrWpanPibAttributeIdentifier id); | |
257 | |
258 /** | |
259 * CSMA-CA algorithm calls back the MAC after executing channel assessment. | |
260 * | |
261 * \param macState indicate BUSY oder IDLE channel condition | |
262 */ | |
263 void SetLrWpanMacState (LrWpanMacState macState); | |
264 | |
265 /** | |
266 * Get the current association status. | |
267 * | |
268 * \return current association status | |
269 */ | |
270 LrWpanAssociationStatus GetAssociationStatus (void) const; | |
271 | |
272 /** | |
273 * Set the current association status. | |
274 * | |
275 * \param status new association status | |
276 */ | |
277 void SetAssociationStatus (LrWpanAssociationStatus status); | |
278 | |
279 /** | |
280 * Get the macAckWaitDuration attribute value. | |
281 * | |
282 * \return the maximum number symbols to wait for an acknowledgment frame | |
283 */ | |
284 uint64_t GetMacAckWaitDuration (void) const; | |
285 | |
286 /** | |
287 * Get the macMaxFrameRetries attribute value. | |
288 * | |
289 * \return the maximum number of retries | |
290 */ | |
291 uint8_t GetMacMaxFrameRetries (void) const; | |
292 | |
293 /** | |
294 * Set the macMaxFrameRetries attribute value. | |
295 * | |
296 * \param retries the maximum number of retries | |
297 */ | |
298 void SetMacMaxFrameRetries (uint8_t retries); | |
299 ·· | |
300 protected: | |
301 // Inherited from Object. | |
302 virtual void DoInitialize (void); | |
303 virtual void DoDispose (void); | |
304 | |
305 private: | |
306 | |
307 LrWpanPhy::State m_currentState; // current state the radio is in | |
308 | |
309 // list of active neighbors | |
310 typedef std::vector<Neighbor> Neighbors; | |
311 Neighbors m_nb; | |
312 | |
313 uint8_t m_ccaCount; // To keep count of two CCAs | |
314 bool m_broadcast; // Is Broadcast transmission | |
315 Time m_bcStart; // Start time of broadcast packet | |
316 | |
317 /** | |
318 * Helper structure for managing transmission queue elements. | |
319 */ | |
320 struct TxQueueElement | |
321 { | |
322 uint8_t txQMsduHandle; //!< MSDU Handle | |
323 Ptr<Packet> txQPkt; //!< Queued packet | |
324 }; | |
325 | |
326 /** | |
327 * Implements ContikiMAC sleep mechanism | |
328 * | |
329 */ | |
330 void Sleep (void); | |
331 | |
332 /** | |
333 * Implements ContikiMAC wakeup mechanism | |
334 * | |
335 */ | |
336 void WakeUp (void); | |
337 | |
338 /** | |
339 * Check phase-lock module if it has a recorded wake-up phase | |
340 * of the intended receiver. | |
341 * | |
342 * \param address The Address of the intended receiver | |
343 */ | |
344 bool CheckPlm (Mac16Address address); | |
345 | |
346 /** | |
347 * Notify the phase-lock module the transmission time of the last packet | |
348 * as an approximation of the wake-up phase of the receiver. | |
349 * | |
350 * \param address The Address of the receiver | |
351 */ | |
352 void NotifyPlm (Mac16Address address); | |
353 | |
354 /** | |
355 * Sets current state. | |
356 */ | |
357 void SetLrWpanRadioState (const LrWpanPhy::State); | |
358 | |
359 /** | |
360 * Send an acknowledgment packet for the given sequence number. | |
361 * | |
362 * \param seqno the sequence number for the ACK | |
363 */ | |
364 void SendAck (uint8_t seqno); | |
365 | |
366 /** | |
367 * Remove the tip of the transmission queue, including clean up related to the | |
368 * last packet transmission. | |
369 */ | |
370 void RemoveFirstTxQElement (); | |
371 | |
372 /** | |
373 * Change the current MAC state to the given new state. | |
374 * | |
375 * \param newState the new state | |
376 */ | |
377 void ChangeMacState (LrWpanMacState newState); | |
378 | |
379 /** | |
380 * Handle an ACK timeout with a packet retransmission, if there are | |
381 * retransmission left, or a packet drop. | |
382 */ | |
383 void AckWaitTimeout (void); | |
384 | |
385 /** | |
386 * Handle an RDC ACK timeout. | |
387 */ | |
388 void RdcAckTimeout (void); | |
389 | |
390 /** | |
391 * Check for remaining retransmissions for the packet currently being sent. | |
392 * Drop the packet, if there are no retransmissions left. | |
393 * | |
394 * \return true, if the packet should be retransmitted, false otherwise. | |
395 */ | |
396 bool PrepareRetransmission (void); | |
397 | |
398 /** | |
399 * Check the transmission queue. If there are packets in the transmission | |
400 * queue and the MAC is idle, pick the first one and initiate a packet | |
401 * transmission. | |
402 * | |
403 * \return true, if the Queue is empty, false otherwise. | |
404 */ | |
405 bool CheckQueue (void); | |
406 | |
407 /** | |
408 * The trace source fired when packets are considered as successfully sent | |
409 * or the transmission has been given up. | |
410 * Only non-broadcast packets are traced. | |
411 * | |
412 * The data should represent: | |
413 * packet, number of retries, total number of csma backoffs | |
414 * | |
415 * \see class CallBackTraceSource | |
416 */ | |
417 TracedCallback<Ptr<const Packet>, uint8_t, uint8_t > m_sentPktTrace; | |
418 | |
419 /** | |
420 * The trace source fired when packets come into the "top" of the device | |
421 * at the L3/L2 transition, when being queued for transmission. | |
422 * | |
423 * \see class CallBackTraceSource | |
424 */ | |
425 TracedCallback<Ptr<const Packet> > m_macTxEnqueueTrace; | |
426 | |
427 /** | |
428 * The trace source fired when packets are dequeued from the | |
429 * L3/l2 transmission queue. | |
430 * | |
431 * \see class CallBackTraceSource | |
432 */ | |
433 TracedCallback<Ptr<const Packet> > m_macTxDequeueTrace; | |
434 | |
435 /** | |
436 * The trace source fired when packets are being sent down to L1. | |
437 * | |
438 * \see class CallBackTraceSource | |
439 */ | |
440 TracedCallback<Ptr<const Packet> > m_macTxTrace; | |
441 | |
442 /** | |
443 * The trace source fired when packets where successfully transmitted, that is | |
444 * an acknowledgment was received, if requested, or the packet was | |
445 * successfully sent by L1, if no ACK was requested. | |
446 * | |
447 * \see class CallBackTraceSource | |
448 */ | |
449 TracedCallback<Ptr<const Packet> > m_macTxOkTrace; | |
450 | |
451 /** | |
452 * The trace source fired when packets are dropped due to missing ACKs or | |
453 * because of transmission failures in L1. | |
454 * | |
455 * \see class CallBackTraceSource | |
456 */ | |
457 TracedCallback<Ptr<const Packet> > m_macTxDropTrace; | |
458 | |
459 /** | |
460 * The trace source fired for packets successfully received by the device | |
461 * immediately before being forwarded up to higher layers (at the L2/L3 | |
462 * transition). This is a promiscuous trace. | |
463 * | |
464 * \see class CallBackTraceSource | |
465 */ | |
466 TracedCallback<Ptr<const Packet> > m_macPromiscRxTrace; | |
467 | |
468 /** | |
469 * The trace source fired for packets successfully received by the device | |
470 * immediately before being forwarded up to higher layers (at the L2/L3 | |
471 * transition). This is a non-promiscuous trace. | |
472 * | |
473 * \see class CallBackTraceSource | |
474 */ | |
475 TracedCallback<Ptr<const Packet> > m_macRxTrace; | |
476 | |
477 /** | |
478 * The trace source fired for packets successfully received by the device | |
479 * but dropped before being forwarded up to higher layers (at the L2/L3 | |
480 * transition). | |
481 * | |
482 * \see class CallBackTraceSource | |
483 */ | |
484 TracedCallback<Ptr<const Packet> > m_macRxDropTrace; | |
485 | |
486 /** | |
487 * A trace source that emulates a non-promiscuous protocol sniffer connected | |
488 * to the device. Unlike your average everyday sniffer, this trace source | |
489 * will not fire on PACKET_OTHERHOST events. | |
490 * | |
491 * On the transmit size, this trace hook will fire after a packet is dequeued | |
492 * from the device queue for transmission. In Linux, for example, this would | |
493 * correspond to the point just before a device hard_start_xmit where | |
494 * dev_queue_xmit_nit is called to dispatch the packet to the PF_PACKET | |
495 * ETH_P_ALL handlers. | |
496 * | |
497 * On the receive side, this trace hook will fire when a packet is received, | |
498 * just before the receive callback is executed. In Linux, for example, | |
499 * this would correspond to the point at which the packet is dispatched to | |
500 * packet sniffers in netif_receive_skb. | |
501 * | |
502 * \see class CallBackTraceSource | |
503 */ | |
504 TracedCallback<Ptr<const Packet> > m_snifferTrace; | |
505 | |
506 /** | |
507 * A trace source that emulates a promiscuous mode protocol sniffer connected | |
508 * to the device. This trace source fire on packets destined for any host | |
509 * just like your average everyday packet sniffer. | |
510 * | |
511 * On the transmit size, this trace hook will fire after a packet is dequeued | |
512 * from the device queue for transmission. In Linux, for example, this would | |
513 * correspond to the point just before a device hard_start_xmit where | |
514 * dev_queue_xmit_nit is called to dispatch the packet to the PF_PACKET | |
515 * ETH_P_ALL handlers. | |
516 * | |
517 * On the receive side, this trace hook will fire when a packet is received, | |
518 * just before the receive callback is executed. In Linux, for example, | |
519 * this would correspond to the point at which the packet is dispatched to | |
520 * packet sniffers in netif_receive_skb. | |
521 * | |
522 * \see class CallBackTraceSource | |
523 */ | |
524 TracedCallback<Ptr<const Packet> > m_promiscSnifferTrace; | |
525 | |
526 /** | |
527 * A trace source that fires when the LrWpanMac changes states. | |
528 * Parameters are the old mac state and the new mac state. | |
529 * | |
530 * \todo This should be a TracedValue | |
531 */ | |
532 TracedCallback<LrWpanMacState, LrWpanMacState> m_macStateLogger; | |
533 | |
534 /** | |
535 * The PHY associated with this MAC. | |
536 */ | |
537 Ptr<LrWpanPhy> m_phy; | |
538 | |
539 /** | |
540 * The CSMA/CA implementation used by this MAC. | |
541 */ | |
542 Ptr<LrWpanCsmaCa> m_csmaCa; | |
543 | |
544 /** | |
545 * This callback is used to notify incoming packets to the upper layers. | |
546 * See IEEE 802.15.4-2006, section 7.1.1.3. | |
547 */ | |
548 McpsDataIndicationCallback m_mcpsDataIndicationCallback; | |
549 | |
550 /** | |
551 * This callback is used to report data transmission request status to the | |
552 * upper layers. | |
553 * See IEEE 802.15.4-2006, section 7.1.1.2. | |
554 */ | |
555 McpsDataConfirmCallback m_mcpsDataConfirmCallback; | |
556 | |
557 /** | |
558 * The current state of the MAC layer. | |
559 */ | |
560 LrWpanMacState m_lrWpanMacState; | |
561 | |
562 /** | |
563 * The current association status of the MAC layer. | |
564 */ | |
565 LrWpanAssociationStatus m_associationStatus; | |
566 | |
567 /** | |
568 * The packet which is currently being sent by the MAC layer. | |
569 */ | |
570 Ptr<Packet> m_txPkt; // XXX need packet buffer instead of single packet | |
571 | |
572 /** | |
573 * The short address used by this MAC. Currently we do not have complete | |
574 * extended address support in the MAC, nor do we have the association | |
575 * primitives, so this address has to be configured manually. | |
576 */ | |
577 Mac16Address m_shortAddress; | |
578 | |
579 /** | |
580 * The extended address used by this MAC. Extended addresses are currently not | |
581 * really supported. | |
582 */ | |
583 Mac64Address m_selfExt; | |
584 | |
585 /** | |
586 * The transmit queue used by the MAC. | |
587 */ | |
588 std::deque<TxQueueElement*> m_txQueue; | |
589 | |
590 /** | |
591 * The number of already used retransmission for the currently transmitted | |
592 * packet. | |
593 */ | |
594 uint8_t m_retransmission; | |
595 | |
596 /** | |
597 * The number of already used retransmission for the currently transmitted | |
598 * packet. | |
599 */ | |
600 uint8_t m_rdcRetries; | |
601 | |
602 /** | |
603 * The number of CSMA/CA retries used for sending the current packet. | |
604 */ | |
605 uint8_t m_numCsmacaRetry; | |
606 | |
607 /** | |
608 * Scheduler event for the ACK timeout of the currently transmitted data | |
609 * packet. | |
610 */ | |
611 EventId m_ackWaitTimeout; | |
612 | |
613 /** | |
614 * Scheduler event for a deferred MAC state change. | |
615 */ | |
616 EventId m_setMacState; | |
617 | |
618 /** | |
619 * Scheduler event of a scheduled WakeUp. | |
620 */ | |
621 EventId m_wakeUp; | |
622 | |
623 /** | |
624 * Scheduler event of a scheduled Sleep. | |
625 */ | |
626 EventId m_sleep; | |
627 | |
628 /** | |
629 * Scheduler event of a repeated data packet. | |
630 */ | |
631 EventId m_repeatPkt; | |
632 | |
633 }; | |
634 | |
635 | |
636 } // namespace ns3 | |
637 | |
638 #endif /* LR_WPAN_CONTIKIMAC_H */ | |
OLD | NEW |