A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
mac-messages.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007,2008,2009 INRIA, UDcast
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: Jahanzeb Farooq <jahanzeb.farooq@sophia.inria.fr>
19  * Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
20  * <amine.ismail@UDcast.com>
21  */
22 
23 #include "mac-messages.h"
24 #include "ns3/address-utils.h"
25 #include "ns3/uinteger.h"
26 #include "ns3/log.h"
27 #include "wimax-tlv.h"
28 
29 NS_LOG_COMPONENT_DEFINE ("MACMESSAGES");
30 namespace ns3 {
31 
32 NS_OBJECT_ENSURE_REGISTERED (ManagementMessageType);
33 
35  : m_type (~0)
36 {
37 }
38 
40  : m_type (type)
41 {
42 }
43 
45 {
46 }
47 
48 void
50 {
51  m_type = type;
52 }
53 
54 uint8_t
56 {
57  return m_type;
58 }
59 
60 std::string
62 {
63  return "Management Message Type";
64 }
65 
66 TypeId
68 {
69  static TypeId tid =
70  TypeId ("ns3::ManagementMessageType").SetParent<Header> ().AddConstructor<ManagementMessageType> ();
71  return tid;
72 }
73 
74 TypeId
76 {
77  return GetTypeId ();
78 }
79 
80 void
81 ManagementMessageType::Print (std::ostream &os) const
82 {
83  os << " management message type = " << (uint32_t) m_type;
84 }
85 
86 uint32_t
88 {
89  return 1;
90 }
91 
92 void
94 {
96  i.WriteU8 (m_type);
97 }
98 
99 uint32_t
101 {
103  m_type = i.ReadU8 ();
104  return i.GetDistanceFrom (start);
105 }
106 
107 // ----------------------------------------------------------------------------------------------------------
108 
110 
112  : m_reserved (0),
113  m_reqDlBurstProfile (0),
114  m_macAddress (Mac48Address ("00:00:00:00:00:00")),
115  m_rangingAnomalies (0)
116 {
117 }
118 
120 {
121 }
122 
123 void
124 RngReq::SetReqDlBurstProfile (uint8_t reqDlBurstProfile)
125 {
126  m_reqDlBurstProfile = reqDlBurstProfile;
127 }
128 
129 void
131 {
132  m_macAddress = macAddress;
133 }
134 
135 void
136 RngReq::SetRangingAnomalies (uint8_t rangingAnomalies)
137 {
138  m_rangingAnomalies = rangingAnomalies;
139 }
140 
141 uint8_t
143 {
144  return m_reqDlBurstProfile;
145 }
146 
149 {
150  return m_macAddress;
151 }
152 
153 uint8_t
155 {
156  return m_rangingAnomalies;
157 }
158 
159 std::string
160 RngReq::GetName (void) const
161 {
162  return "RNG-REQ";
163 }
164 
165 TypeId
167 {
168  static TypeId tid = TypeId ("ns3::RngReq").SetParent<Header> ().AddConstructor<RngReq> ();
169  return tid;
170 }
171 
172 TypeId
174 {
175  return GetTypeId ();
176 }
177 
178 void
179 RngReq::Print (std::ostream &os) const
180 {
181  os << " requested dl burst profile = " << (uint32_t) m_reqDlBurstProfile << ", mac address = " << m_macAddress
182  << ", ranging anomalies = " << (uint32_t) m_rangingAnomalies;
183 }
184 
185 void
186 RngReq::PrintDebug (void) const
187 {
188  NS_LOG_DEBUG (" requested dl burst profile = " << (uint32_t) m_reqDlBurstProfile << ", mac address = "
189  << m_macAddress << ", ranging anomalies = "
190  << (uint32_t) m_rangingAnomalies);
191 }
192 
193 uint32_t
195 {
196  return 1 + 1 + 6 + 1;
197 }
198 
199 void
201 {
203  i.WriteU8 (m_reserved);
205  WriteTo (i, m_macAddress);
207 }
208 
209 uint32_t
211 {
213  m_reserved = i.ReadU8 ();
215  ReadFrom (i, m_macAddress);
216  m_rangingAnomalies = i.ReadU8 ();
217 
218  return i.GetDistanceFrom (start);
219 }
220 
221 // ----------------------------------------------------------------------------------------------------------
222 
224 
226  : m_reserved (0),
227  m_timingAdjust (0),
228  m_powerLevelAdjust (0),
229  m_offsetFreqAdjust (0),
230  m_rangStatus (0),
231  m_dlFreqOverride (0),
232  m_ulChnlIdOverride (0),
233  m_dlOperBurstProfile (0),
234  m_macAddress (Mac48Address ("00:00:00:00:00:00")),
235  m_basicCid (),
236  m_primaryCid (),
237  m_aasBdcastPermission (0),
238  m_frameNumber (0),
239  m_initRangOppNumber (0),
240  m_rangSubchnl (0)
241 {
242 }
243 
245 {
246 }
247 
248 void
249 RngRsp::SetTimingAdjust (uint32_t timingAdjust)
250 {
251  m_timingAdjust = timingAdjust;
252 }
253 
254 void
255 RngRsp::SetPowerLevelAdjust (uint8_t powerLevelAdjust)
256 {
257  m_powerLevelAdjust = powerLevelAdjust;
258 }
259 
260 void
261 RngRsp::SetOffsetFreqAdjust (uint32_t offsetFreqAdjust)
262 {
263  m_offsetFreqAdjust = offsetFreqAdjust;
264 }
265 
266 void
267 RngRsp::SetRangStatus (uint8_t rangStatus)
268 {
269  m_rangStatus = rangStatus;
270 }
271 
272 void
273 RngRsp::SetDlFreqOverride (uint32_t dlFreqOverride)
274 {
275  m_dlFreqOverride = dlFreqOverride;
276 }
277 
278 void
279 RngRsp::SetUlChnlIdOverride (uint8_t ulChnlIdOverride)
280 {
281  m_ulChnlIdOverride = ulChnlIdOverride;
282 }
283 
284 void
285 RngRsp::SetDlOperBurstProfile (uint16_t dlOperBurstProfile)
286 {
287  m_dlOperBurstProfile = dlOperBurstProfile;
288 }
289 
290 void
292 {
293  m_macAddress = macAddress;
294 }
295 
296 void
298 {
299  m_basicCid = basicCid;
300 }
301 
302 void
304 {
305  m_primaryCid = primaryCid;
306 }
307 
308 void
309 RngRsp::SetAasBdcastPermission (uint8_t aasBdcastPermission)
310 {
311  m_aasBdcastPermission = aasBdcastPermission;
312 }
313 
314 void
315 RngRsp::SetFrameNumber (uint32_t frameNumber)
316 {
317  m_frameNumber = frameNumber;
318 }
319 
320 void
321 RngRsp::SetInitRangOppNumber (uint8_t initRangOppNumber)
322 {
323  m_initRangOppNumber = initRangOppNumber;
324 }
325 
326 void
327 RngRsp::SetRangSubchnl (uint8_t rangSubchnl)
328 {
329  m_rangSubchnl = rangSubchnl;
330 }
331 
332 uint32_t
334 {
335  return m_timingAdjust;
336 }
337 
338 uint8_t
340 {
341  return m_powerLevelAdjust;
342 }
343 
344 uint32_t
346 {
347  return m_offsetFreqAdjust;
348 }
349 
350 uint8_t
352 {
353  return m_rangStatus;
354 }
355 
356 uint32_t
358 {
359  return m_dlFreqOverride;
360 }
361 
362 uint8_t
364 {
365  return m_ulChnlIdOverride;
366 }
367 
368 uint16_t
370 {
371  return m_dlOperBurstProfile;
372 }
373 
376 {
377  return m_macAddress;
378 }
379 
380 Cid
382 {
383  return m_basicCid;
384 }
385 
386 Cid
388 {
389  return m_primaryCid;
390 }
391 
392 uint8_t
394 {
395  return m_aasBdcastPermission;
396 }
397 
398 uint32_t
400 {
401  return m_frameNumber;
402 }
403 
404 uint8_t
406 {
407  return m_initRangOppNumber;
408 }
409 
410 uint8_t
412 {
413  return m_rangSubchnl;
414 }
415 
416 std::string
417 RngRsp::GetName (void) const
418 {
419  return "RNG-RSP";
420 }
421 
422 TypeId
424 {
425  static TypeId tid = TypeId ("ns3::RngRsp").SetParent<Header> ().AddConstructor<RngRsp> ();
426  return tid;
427 }
428 
429 TypeId
431 {
432  return GetTypeId ();
433 }
434 
435 void
436 RngRsp::Print (std::ostream &os) const
437 {
438  os << " timing adjust = " << m_timingAdjust << ", power level adjust = " << (uint32_t) m_powerLevelAdjust
439  << ", offset freq adjust = " << m_offsetFreqAdjust << ", ranging status = " << (uint32_t) m_rangStatus
440  << ", dl freq override = " << m_dlFreqOverride << ", ul channel id override = " << (uint32_t) m_ulChnlIdOverride
441  << ", dl operational burst profile = " << (uint32_t) m_dlOperBurstProfile << ", mac address = " << m_macAddress
442  << ", basic cid = " << m_basicCid << ", primary management cid = " << m_primaryCid
443  << ", aas broadcast permission = " << (uint32_t) m_aasBdcastPermission << ", frame number = " << m_frameNumber
444  << ", initial ranging opportunity number = " << (uint32_t) m_initRangOppNumber << ", ranging subchannel = "
445  << (uint32_t) m_rangSubchnl;
446 }
447 
448 uint32_t
450 {
451  return 1 + 4 + 1 + 4 + 1 + 4 + 1 + 2 + 6 + 2 + 2 + 1 + 4 + 1 + 1;
452 }
453 
454 void
456 {
458  i.WriteU8 (m_reserved);
462  i.WriteU8 (m_rangStatus);
466  WriteTo (i, m_macAddress);
473 }
474 
475 uint32_t
477 {
479  m_reserved = i.ReadU8 ();
480  m_timingAdjust = i.ReadU32 ();
481  m_powerLevelAdjust = i.ReadU8 ();
483  m_rangStatus = i.ReadU8 ();
484  m_dlFreqOverride = i.ReadU32 ();
485  m_ulChnlIdOverride = i.ReadU8 ();
487  ReadFrom (i, m_macAddress); // length (6) shall also be written in packet instead of hard coded, see ARP example
488  m_basicCid = i.ReadU16 ();
489  m_primaryCid = i.ReadU16 ();
491  m_frameNumber = i.ReadU32 ();
493  m_rangSubchnl = i.ReadU8 ();
494 
495  return i.GetDistanceFrom (start);
496 }
497 
498 // ----------------------------------------------------------------------------------------------------------------------
499 
501 
503  : m_transactionId (0),
504  m_sfid (0),
505  m_cid (),
506  m_serviceFlow (ServiceFlow::SF_DIRECTION_DOWN)
507 {
508 }
509 
511 {
512  m_transactionId = 0;
513  m_serviceFlow = sf;
514 }
515 
517 {
518 }
519 
520 void
521 DsaReq::SetTransactionId (uint16_t transactionId)
522 {
523  m_transactionId = transactionId;
524 }
525 
526 uint16_t
528 {
529  return m_transactionId;
530 }
531 
532 void
533 DsaReq::SetSfid (uint32_t sfid)
534 {
535  m_sfid = sfid;
536 }
537 
538 uint32_t
539 DsaReq::GetSfid (void) const
540 {
541  return m_sfid;
542 }
543 
544 void
546 {
547  m_cid = cid;
548 }
549 
550 Cid
551 DsaReq::GetCid (void) const
552 {
553  return m_cid;
554 }
555 
556 
557 std::string
558 DsaReq::GetName (void) const
559 {
560  return "DSA-REQ";
561 }
562 
563 TypeId
565 {
566  static TypeId tid = TypeId ("ns3::DsaReq").SetParent<Header> ().AddConstructor<DsaReq> ();
567  return tid;
568 }
569 
570 TypeId
572 {
573  return GetTypeId ();
574 }
575 
576 void
577 DsaReq::Print (std::ostream &os) const
578 {
579  os << " transaction id = " << (uint32_t) m_transactionId << ", m_sfid = " << m_sfid << ", cid = " << m_cid;
580 }
581 
582 /*
583  * 0 7 15 23
584  * +-------------+-------------+-------------+
585  * |Mngt msg type| Transaction ID |
586  * +-------------+-------------+-------------+
587  * | Service Flow TLV |
588  * +~~~~~~~~~~~~~+~~~~~~~~~~~~~+~~~~~~~~~~~~~+
589  *
590  */
591 
592 uint32_t
594 {
595  Tlv t = m_serviceFlow.ToTlv ();
596  uint32_t size = 2 + t.GetSerializedSize ();
597  return size;
598 }
599 
600 void
602 {
605  Tlv t = m_serviceFlow.ToTlv ();
606  t.Serialize (i);
607 }
608 
609 uint32_t
611 {
613  m_transactionId = i.ReadU16 ();
614  Tlv tlv;
615  uint32_t size = tlv.Deserialize (i);
616  m_serviceFlow = ServiceFlow (tlv);
617  return size + 2;
618 }
619 
622 {
623  return m_serviceFlow;
624 }
625 
626 void
628 {
629  m_serviceFlow = sf;
630 }
631 
632 // ----------------------------------------------------------------------------------------------------------------------
633 
635 
637  : m_transactionId (0),
638  m_confirmationCode (0),
639  m_sfid (0),
640  m_cid ()
641 {
642 }
643 
645 {
646 }
647 
648 void
649 DsaRsp::SetTransactionId (uint16_t transactionId)
650 {
651  m_transactionId = transactionId;
652 }
653 
654 uint16_t
656 {
657  return m_transactionId;
658 }
659 
662 {
663  return m_serviceFlow;
664 }
665 
666 void
668 {
669  m_serviceFlow = sf;
670 }
671 
672 void
673 DsaRsp::SetConfirmationCode (uint16_t confirmationCode)
674 {
675  m_confirmationCode = confirmationCode;
676 }
677 
678 uint16_t
680 {
681  return m_confirmationCode;
682 }
683 
684 void
685 DsaRsp::SetSfid (uint32_t sfid)
686 {
687  m_sfid = sfid;
688 }
689 
690 uint32_t
691 DsaRsp::GetSfid (void) const
692 {
693  return m_sfid;
694 }
695 
696 void
698 {
699  m_cid = cid;
700 }
701 
702 Cid
703 DsaRsp::GetCid (void) const
704 {
705  return m_cid;
706 }
707 
708 std::string
709 DsaRsp::GetName (void) const
710 {
711  return "DSA-RSP";
712 }
713 
714 TypeId
716 {
717  static TypeId tid = TypeId ("ns3::DsaRsp").SetParent<Header> ().AddConstructor<DsaRsp> ();
718  return tid;
719 }
720 
721 TypeId
723 {
724  return GetTypeId ();
725 }
726 
727 void
728 DsaRsp::Print (std::ostream &os) const
729 {
730  os << " transaction id = " << (uint32_t) m_transactionId << ", confirmation code = " << (uint32_t) m_confirmationCode
731  << ", m_sfid = " << m_sfid << ", cid = " << m_cid;
732 }
733 
734 uint32_t
736 {
737  return 2 + 1 + m_serviceFlow.ToTlv ().GetSerializedSize ();
738 }
739 
740 /*
741  * 0 7 15 23
742  * +-------------+-------------+-------------+
743  * |Mngt msg type| Transaction ID |
744  * +-------------+-------------+-------------+
745  * | Conf Code | Service Flow TLV |
746  * +~~~~~~~~~~~~~+~~~~~~~~~~~~~+~~~~~~~~~~~~~+
747  *
748  */
749 void
751 {
753 
757 }
758 
759 uint32_t
761 {
763 
764  m_transactionId = i.ReadU16 ();
765  m_confirmationCode = i.ReadU8 ();
766  Tlv tlv;
767  uint32_t size = tlv.Deserialize (i);
768  m_serviceFlow = ServiceFlow (tlv);
769  return size + 3;
770 }
771 
772 // ----------------------------------------------------------------------------------------------------------
773 
775 
777  : m_transactionId (0),
778  m_confirmationCode (0)
779 {
780 }
781 
783 {
784 }
785 
786 void
787 DsaAck::SetTransactionId (uint16_t transactionId)
788 {
789  m_transactionId = transactionId;
790 }
791 
792 uint16_t
794 {
795  return m_transactionId;
796 }
797 
798 void
799 DsaAck::SetConfirmationCode (uint16_t confirmationCode)
800 {
801  m_confirmationCode = confirmationCode;
802 }
803 
804 uint16_t
806 {
807  return m_confirmationCode;
808 }
809 
810 std::string
811 DsaAck::GetName (void) const
812 {
813  return "DSA-ACK";
814 }
815 
816 TypeId
818 {
819  static TypeId tid = TypeId ("ns3::DsaAck").SetParent<Header> ().AddConstructor<DsaAck> ();
820  return tid;
821 }
822 
823 TypeId
825 {
826  return GetTypeId ();
827 }
828 
829 void
830 DsaAck::Print (std::ostream &os) const
831 {
832  os << " transaction id = " << (uint32_t) m_transactionId << ", confirmation code = " << (uint32_t) m_confirmationCode;
833 }
834 
835 uint32_t
837 {
838  return 2 + 1;
839 }
840 
841 void
843 {
847 }
848 
849 uint32_t
851 {
853  m_transactionId = i.ReadU16 ();
854  m_confirmationCode = i.ReadU8 ();
855 
856  return i.GetDistanceFrom (start);
857 }
858 
859 } // namespace ns3