A Discrete-Event Network Simulator
API
wifi-mac-header.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2006, 2009 INRIA
4  * Copyright (c) 2009 MIRKO BANCHI
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20  * Mirko Banchi <mk.banchi@gmail.com>
21  */
22 
23 #include "ns3/nstime.h"
24 #include "ns3/address-utils.h"
25 #include "wifi-mac-header.h"
26 
27 namespace ns3 {
28 
29 NS_OBJECT_ENSURE_REGISTERED (WifiMacHeader);
30 
32 enum
33 {
34  TYPE_MGT = 0,
35  TYPE_CTL = 1,
36  TYPE_DATA = 2
37 };
38 
40 enum
41 {
42  //Reserved: 0 - 1
44  //Reserved: 3
56 };
57 
59  : m_ctrlMoreFrag (0),
60  m_ctrlRetry (0),
61  m_ctrlMoreData (0),
62  m_ctrlWep (0),
63  m_ctrlOrder (0),
64  m_duration (0),
65  m_seqFrag (0),
66  m_seqSeq (0),
67  m_qosEosp (0),
68  m_qosAckPolicy (0), // Normal Ack
69  m_amsduPresent (0)
70 {
71 }
72 
74  : WifiMacHeader ()
75 {
76  SetType (type);
77 }
78 
80 {
81 }
82 
83 void
85 {
86  m_ctrlFromDs = 1;
87 }
88 
89 void
91 {
92  m_ctrlFromDs = 0;
93 }
94 
95 void
97 {
98  m_ctrlToDs = 1;
99 }
100 
101 void
103 {
104  m_ctrlToDs = 0;
105 }
106 
107 void
109 {
110  m_addr1 = address;
111 }
112 
113 void
115 {
116  m_addr2 = address;
117 }
118 
119 void
121 {
122  m_addr3 = address;
123 }
124 
125 void
127 {
128  m_addr4 = address;
129 }
130 
131 void
132 WifiMacHeader::SetType (WifiMacType type, bool resetToDsFromDs)
133 {
134  switch (type)
135  {
139  break;
143  break;
147  break;
151  break;
152  case WIFI_MAC_CTL_RTS:
155  break;
156  case WIFI_MAC_CTL_CTS:
159  break;
160  case WIFI_MAC_CTL_ACK:
163  break;
164  case WIFI_MAC_CTL_END:
167  break;
171  break;
174  m_ctrlSubtype = 0;
175  break;
178  m_ctrlSubtype = 1;
179  break;
182  m_ctrlSubtype = 2;
183  break;
186  m_ctrlSubtype = 3;
187  break;
190  m_ctrlSubtype = 4;
191  break;
194  m_ctrlSubtype = 5;
195  break;
196  case WIFI_MAC_MGT_BEACON:
198  m_ctrlSubtype = 8;
199  break;
202  m_ctrlSubtype = 10;
203  break;
206  m_ctrlSubtype = 11;
207  break;
210  m_ctrlSubtype = 12;
211  break;
212  case WIFI_MAC_MGT_ACTION:
214  m_ctrlSubtype = 13;
215  break;
218  m_ctrlSubtype = 14;
219  break;
222  m_ctrlSubtype = 15;
223  break;
224  case WIFI_MAC_DATA:
226  m_ctrlSubtype = 0;
227  break;
228  case WIFI_MAC_DATA_CFACK:
230  m_ctrlSubtype = 1;
231  break;
234  m_ctrlSubtype = 2;
235  break;
238  m_ctrlSubtype = 3;
239  break;
240  case WIFI_MAC_DATA_NULL:
242  m_ctrlSubtype = 4;
243  break;
246  m_ctrlSubtype = 5;
247  break;
250  m_ctrlSubtype = 6;
251  break;
254  m_ctrlSubtype = 7;
255  break;
256  case WIFI_MAC_QOSDATA:
258  m_ctrlSubtype = 8;
259  break;
262  m_ctrlSubtype = 9;
263  break;
266  m_ctrlSubtype = 10;
267  break;
270  m_ctrlSubtype = 11;
271  break;
274  m_ctrlSubtype = 12;
275  break;
278  m_ctrlSubtype = 14;
279  break;
282  m_ctrlSubtype = 15;
283  break;
284  }
285  if (resetToDsFromDs)
286  {
287  m_ctrlToDs = 0;
288  m_ctrlFromDs = 0;
289  }
290 }
291 
292 void
293 WifiMacHeader::SetRawDuration (uint16_t duration)
294 {
295  NS_ASSERT (duration <= 32768);
296  m_duration = duration;
297 }
298 
299 void
301 {
302  int64_t duration_us = static_cast<int64_t> (ceil (static_cast<double> (duration.GetNanoSeconds ()) / 1000));
303  NS_ASSERT (duration_us >= 0 && duration_us <= 0x7fff);
304  m_duration = static_cast<uint16_t> (duration_us);
305 }
306 
307 void WifiMacHeader::SetId (uint16_t id)
308 {
309  m_duration = id;
310 }
311 
313 {
314  m_seqSeq = seq;
315 }
316 
318 {
319  m_seqFrag = frag;
320 }
321 
323 {
324  m_ctrlMoreFrag = 0;
325 }
326 
328 {
329  m_ctrlMoreFrag = 1;
330 }
331 
333 {
334  m_ctrlOrder = 1;
335 }
336 
338 {
339  m_ctrlOrder = 0;
340 }
341 
343 {
344  m_ctrlRetry = 1;
345 }
346 
348 {
349  m_ctrlRetry = 0;
350 }
351 
352 void WifiMacHeader::SetQosTid (uint8_t tid)
353 {
354  m_qosTid = tid;
355 }
356 
358 {
359  m_qosEosp = 1;
360 }
361 
363 {
364  m_qosEosp = 0;
365 }
366 
368 {
369  switch (policy)
370  {
371  case NORMAL_ACK:
372  m_qosAckPolicy = 0;
373  break;
374  case NO_ACK:
375  m_qosAckPolicy = 1;
376  break;
377  case NO_EXPLICIT_ACK:
378  m_qosAckPolicy = 2;
379  break;
380  case BLOCK_ACK:
381  m_qosAckPolicy = 3;
382  break;
383  }
384 }
385 
387 {
388  m_amsduPresent = 1;
389 }
390 
392 {
393  m_amsduPresent = 0;
394 }
395 
397 {
398  m_qosStuff = txop;
399 }
400 
401 void
403 {
404  m_qosEosp = 1;
405  m_qosStuff = size;
406 }
407 
409 {
410  //Mark bit 0 of this variable instead of bit 8, since m_qosStuff is
411  //shifted by one byte when serialized
412  m_qosStuff = m_qosStuff | 0x01; //bit 8 of QoS Control Field
413 }
414 
416 {
417  //Clear bit 0 of this variable instead of bit 8, since m_qosStuff is
418  //shifted by one byte when serialized
419  m_qosStuff = m_qosStuff & 0xfe; //bit 8 of QoS Control Field
420 }
421 
422 
425 {
426  return m_addr1;
427 }
428 
431 {
432  return m_addr2;
433 }
434 
437 {
438  return m_addr3;
439 }
440 
443 {
444  return m_addr4;
445 }
446 
449 {
450  switch (m_ctrlType)
451  {
452  case TYPE_MGT:
453  switch (m_ctrlSubtype)
454  {
455  case 0:
457  case 1:
459  case 2:
461  case 3:
463  case 4:
465  case 5:
467  case 8:
468  return WIFI_MAC_MGT_BEACON;
469  case 10:
471  case 11:
473  case 12:
475  case 13:
476  return WIFI_MAC_MGT_ACTION;
477  case 14:
479  case 15:
481  }
482  break;
483  case TYPE_CTL:
484  switch (m_ctrlSubtype)
485  {
486  case SUBTYPE_CTL_TRIGGER:
487  return WIFI_MAC_CTL_TRIGGER;
488  case SUBTYPE_CTL_BACKREQ:
489  return WIFI_MAC_CTL_BACKREQ;
491  return WIFI_MAC_CTL_BACKRESP;
492  case SUBTYPE_CTL_RTS:
493  return WIFI_MAC_CTL_RTS;
494  case SUBTYPE_CTL_CTS:
495  return WIFI_MAC_CTL_CTS;
496  case SUBTYPE_CTL_ACK:
497  return WIFI_MAC_CTL_ACK;
498  case SUBTYPE_CTL_END:
499  return WIFI_MAC_CTL_END;
500  case SUBTYPE_CTL_END_ACK:
501  return WIFI_MAC_CTL_END_ACK;
502  }
503  break;
504  case TYPE_DATA:
505  switch (m_ctrlSubtype)
506  {
507  case 0:
508  return WIFI_MAC_DATA;
509  case 1:
510  return WIFI_MAC_DATA_CFACK;
511  case 2:
512  return WIFI_MAC_DATA_CFPOLL;
513  case 3:
515  case 4:
516  return WIFI_MAC_DATA_NULL;
517  case 5:
519  case 6:
521  case 7:
523  case 8:
524  return WIFI_MAC_QOSDATA;
525  case 9:
526  return WIFI_MAC_QOSDATA_CFACK;
527  case 10:
529  case 11:
531  case 12:
532  return WIFI_MAC_QOSDATA_NULL;
533  case 14:
535  case 15:
537  }
538  break;
539  }
540  // NOTREACHED
541  NS_ASSERT (false);
542  return (WifiMacType) - 1;
543 }
544 
545 bool
547 {
548  return m_ctrlFromDs == 1;
549 }
550 
551 bool
553 {
554  return m_ctrlToDs == 1;
555 }
556 
557 bool
559 {
560  return (m_ctrlType == TYPE_DATA);
561 
562 }
563 
564 bool
566 {
567  return (m_ctrlType == TYPE_DATA && (m_ctrlSubtype & 0x08));
568 }
569 
570 bool
572 {
573  return (m_ctrlType == TYPE_CTL);
574 }
575 
576 bool
578 {
579  return (m_ctrlType == TYPE_MGT);
580 }
581 
582 bool
584 {
585  switch (GetType ())
586  {
595  return true;
596  default:
597  return false;
598  }
599 }
600 
601 bool
603 {
604  switch (GetType ())
605  {
606  case WIFI_MAC_CTL_END:
608  return true;
609  default:
610  return false;
611  }
612 }
613 
614 bool
616 {
617  switch (GetType ())
618  {
619  case WIFI_MAC_DATA_CFACK:
624  return true;
625  default:
626  return false;
627  break;
628  }
629 }
630 
631 bool
633 {
634  switch (GetType ())
635  {
636  case WIFI_MAC_DATA:
637  case WIFI_MAC_DATA_CFACK:
640  case WIFI_MAC_QOSDATA:
644  return true;
645  default:
646  return false;
647  }
648 }
649 
650 bool
652 {
653  return (GetType () == WIFI_MAC_CTL_RTS);
654 }
655 
656 bool
658 {
659  return (GetType () == WIFI_MAC_CTL_CTS);
660 }
661 
662 bool
664 {
665  return (GetType () == WIFI_MAC_CTL_ACK);
666 }
667 
668 bool
670 {
672 }
673 
674 bool
676 {
678 }
679 
680 bool
682 {
684 }
685 
686 bool
688 {
690 }
691 
692 bool
694 {
695  return (GetType () == WIFI_MAC_MGT_PROBE_REQUEST);
696 }
697 
698 bool
700 {
701  return (GetType () == WIFI_MAC_MGT_PROBE_RESPONSE);
702 }
703 
704 bool
706 {
707  return (GetType () == WIFI_MAC_MGT_BEACON);
708 }
709 
710 bool
712 {
713  return (GetType () == WIFI_MAC_MGT_DISASSOCIATION);
714 }
715 
716 bool
718 {
719  return (GetType () == WIFI_MAC_MGT_AUTHENTICATION);
720 }
721 
722 bool
724 {
725  return (GetType () == WIFI_MAC_MGT_DEAUTHENTICATION);
726 }
727 
728 bool
730 {
731  return (GetType () == WIFI_MAC_MGT_ACTION);
732 }
733 
734 bool
736 {
737  return (GetType () == WIFI_MAC_MGT_MULTIHOP_ACTION);
738 }
739 
740 bool
742 {
743  return (GetType () == WIFI_MAC_CTL_BACKREQ);
744 }
745 
746 bool
748 {
749  return (GetType () == WIFI_MAC_CTL_BACKRESP);
750 }
751 
752 bool
754 {
755  return (GetType () == WIFI_MAC_CTL_TRIGGER);
756 }
757 
758 uint16_t
760 {
761  return m_duration;
762 }
763 
764 Time
766 {
767  return MicroSeconds (m_duration);
768 }
769 
770 uint16_t
772 {
773  return (m_seqSeq << 4) | m_seqFrag;
774 }
775 
776 uint16_t
778 {
779  return m_seqSeq;
780 }
781 
782 uint8_t
784 {
785  return m_seqFrag;
786 }
787 
788 bool
790 {
791  return (m_ctrlRetry == 1);
792 }
793 
794 bool
796 {
797  return (m_ctrlMoreFrag == 1);
798 }
799 
800 bool
802 {
803  NS_ASSERT (IsQosData ());
804  return (m_qosAckPolicy == 3);
805 }
806 
807 bool
809 {
810  NS_ASSERT (IsQosData ());
811  return (m_qosAckPolicy == 1);
812 }
813 
814 bool
816 {
817  NS_ASSERT (IsQosData ());
818  return (m_qosAckPolicy == 0);
819 }
820 
821 bool
823 {
824  NS_ASSERT (IsQosData ());
825  return (m_qosEosp == 1);
826 }
827 
830 {
831  NS_ASSERT (IsQosData ());
832  QosAckPolicy policy;
833 
834  switch (m_qosAckPolicy)
835  {
836  case 0:
837  policy = NORMAL_ACK;
838  break;
839  case 1:
840  policy = NO_ACK;
841  break;
842  case 2:
843  policy = NO_EXPLICIT_ACK;
844  break;
845  case 3:
846  policy = BLOCK_ACK;
847  break;
848  default:
849  NS_ABORT_MSG ("Unknown QoS Ack policy");
850  }
851  return policy;
852 }
853 
854 bool
856 {
857  NS_ASSERT (IsQosData ());
858  return (m_amsduPresent == 1);
859 }
860 
861 uint8_t
863 {
864  NS_ASSERT (IsQosData ());
865  return m_qosTid;
866 }
867 
868 uint8_t
870 {
871  NS_ASSERT (m_qosEosp == 1);
872  return m_qosStuff;
873 }
874 
875 uint16_t
877 {
878  uint16_t val = 0;
879  val |= (m_ctrlType << 2) & (0x3 << 2);
880  val |= (m_ctrlSubtype << 4) & (0xf << 4);
881  val |= (m_ctrlToDs << 8) & (0x1 << 8);
882  val |= (m_ctrlFromDs << 9) & (0x1 << 9);
883  val |= (m_ctrlMoreFrag << 10) & (0x1 << 10);
884  val |= (m_ctrlRetry << 11) & (0x1 << 11);
885  val |= (m_ctrlMoreData << 13) & (0x1 << 13);
886  val |= (m_ctrlWep << 14) & (0x1 << 14);
887  val |= (m_ctrlOrder << 15) & (0x1 << 15);
888  return val;
889 }
890 
891 uint16_t
893 {
894  uint16_t val = 0;
895  val |= m_qosTid;
896  val |= m_qosEosp << 4;
897  val |= m_qosAckPolicy << 5;
898  val |= m_amsduPresent << 7;
899  val |= m_qosStuff << 8;
900  return val;
901 }
902 
903 void
905 {
906  m_ctrlType = (ctrl >> 2) & 0x03;
907  m_ctrlSubtype = (ctrl >> 4) & 0x0f;
908  m_ctrlToDs = (ctrl >> 8) & 0x01;
909  m_ctrlFromDs = (ctrl >> 9) & 0x01;
910  m_ctrlMoreFrag = (ctrl >> 10) & 0x01;
911  m_ctrlRetry = (ctrl >> 11) & 0x01;
912  m_ctrlMoreData = (ctrl >> 13) & 0x01;
913  m_ctrlWep = (ctrl >> 14) & 0x01;
914  m_ctrlOrder = (ctrl >> 15) & 0x01;
915 }
916 void
918 {
919  m_seqFrag = seq & 0x0f;
920  m_seqSeq = (seq >> 4) & 0x0fff;
921 }
922 void
924 {
925  m_qosTid = qos & 0x000f;
926  m_qosEosp = (qos >> 4) & 0x0001;
927  m_qosAckPolicy = (qos >> 5) & 0x0003;
928  m_amsduPresent = (qos >> 7) & 0x0001;
929  m_qosStuff = (qos >> 8) & 0x00ff;
930 }
931 
932 uint32_t
934 {
935  uint32_t size = 0;
936  switch (m_ctrlType)
937  {
938  case TYPE_MGT:
939  size = 2 + 2 + 6 + 6 + 6 + 2;
940  break;
941  case TYPE_CTL:
942  switch (m_ctrlSubtype)
943  {
944  case SUBTYPE_CTL_RTS:
945  case SUBTYPE_CTL_BACKREQ:
947  case SUBTYPE_CTL_TRIGGER:
948  case SUBTYPE_CTL_END:
949  case SUBTYPE_CTL_END_ACK:
950  size = 2 + 2 + 6 + 6;
951  break;
952  case SUBTYPE_CTL_CTS:
953  case SUBTYPE_CTL_ACK:
954  size = 2 + 2 + 6;
955  break;
957  size = 2 + 2 + 6 + 2 + 4;
958  break;
959  }
960  break;
961  case TYPE_DATA:
962  size = 2 + 2 + 6 + 6 + 6 + 2;
963  if (m_ctrlToDs && m_ctrlFromDs)
964  {
965  size += 6;
966  }
967  if (m_ctrlSubtype & 0x08)
968  {
969  size += 2;
970  }
971  break;
972  }
973  return size;
974 }
975 
976 const char *
978 {
979 #define FOO(x) \
980 case WIFI_MAC_ ## x: \
981  return # x; \
982  break;
983 
984  switch (GetType ())
985  {
986  FOO (CTL_RTS);
987  FOO (CTL_CTS);
988  FOO (CTL_ACK);
989  FOO (CTL_BACKREQ);
990  FOO (CTL_BACKRESP);
991  FOO (CTL_END);
992  FOO (CTL_END_ACK);
993  FOO (CTL_TRIGGER);
994 
995  FOO (MGT_BEACON);
996  FOO (MGT_ASSOCIATION_REQUEST);
997  FOO (MGT_ASSOCIATION_RESPONSE);
998  FOO (MGT_DISASSOCIATION);
999  FOO (MGT_REASSOCIATION_REQUEST);
1000  FOO (MGT_REASSOCIATION_RESPONSE);
1001  FOO (MGT_PROBE_REQUEST);
1002  FOO (MGT_PROBE_RESPONSE);
1003  FOO (MGT_AUTHENTICATION);
1004  FOO (MGT_DEAUTHENTICATION);
1005  FOO (MGT_ACTION);
1006  FOO (MGT_ACTION_NO_ACK);
1007  FOO (MGT_MULTIHOP_ACTION);
1008 
1009  FOO (DATA);
1010  FOO (DATA_CFACK);
1011  FOO (DATA_CFPOLL);
1012  FOO (DATA_CFACK_CFPOLL);
1013  FOO (DATA_NULL);
1014  FOO (DATA_NULL_CFACK);
1015  FOO (DATA_NULL_CFPOLL);
1016  FOO (DATA_NULL_CFACK_CFPOLL);
1017  FOO (QOSDATA);
1018  FOO (QOSDATA_CFACK);
1019  FOO (QOSDATA_CFPOLL);
1020  FOO (QOSDATA_CFACK_CFPOLL);
1021  FOO (QOSDATA_NULL);
1022  FOO (QOSDATA_NULL_CFPOLL);
1023  FOO (QOSDATA_NULL_CFACK_CFPOLL);
1024  default:
1025  return "ERROR";
1026  }
1027 #undef FOO
1028 #ifndef _WIN32
1029  // needed to make gcc 4.0.1 ppc darwin happy.
1030  return "BIG_ERROR";
1031 #endif
1032 }
1033 
1034 TypeId
1036 {
1037  static TypeId tid = TypeId ("ns3::WifiMacHeader")
1038  .SetParent<Header> ()
1039  .SetGroupName ("Wifi")
1040  .AddConstructor<WifiMacHeader> ()
1041  ;
1042  return tid;
1043 }
1044 
1045 TypeId
1047 {
1048  return GetTypeId ();
1049 }
1050 
1051 void
1052 WifiMacHeader::PrintFrameControl (std::ostream &os) const
1053 {
1054  os << "ToDS=" << std::hex << (int) m_ctrlToDs << ", FromDS=" << std::hex << (int) m_ctrlFromDs
1055  << ", MoreFrag=" << std::hex << (int) m_ctrlMoreFrag << ", Retry=" << std::hex << (int) m_ctrlRetry
1056  << ", MoreData=" << std::hex << (int) m_ctrlMoreData << std::dec
1057  ;
1058 }
1059 
1060 void
1061 WifiMacHeader::Print (std::ostream &os) const
1062 {
1063  os << GetTypeString () << " ";
1064  switch (GetType ())
1065  {
1066  case WIFI_MAC_CTL_RTS:
1067  case WIFI_MAC_CTL_TRIGGER:
1068  os << "Duration/ID=" << m_duration << "us"
1069  << ", RA=" << m_addr1 << ", TA=" << m_addr2;
1070  break;
1071  case WIFI_MAC_CTL_CTS:
1072  case WIFI_MAC_CTL_ACK:
1073  os << "Duration/ID=" << m_duration << "us"
1074  << ", RA=" << m_addr1;
1075  break;
1076  case WIFI_MAC_MGT_BEACON:
1086  PrintFrameControl (os);
1087  os << " Duration/ID=" << m_duration << "us"
1088  << ", DA=" << m_addr1 << ", SA=" << m_addr2
1089  << ", BSSID=" << m_addr3 << ", FragNumber=" << std::hex << (int) m_seqFrag << std::dec
1090  << ", SeqNumber=" << m_seqSeq;
1091  break;
1092  case WIFI_MAC_MGT_ACTION:
1094  PrintFrameControl (os);
1095  os << " Duration/ID=" << m_duration << "us"
1096  << ", DA=" << m_addr1 << ", SA=" << m_addr2 << ", BSSID=" << m_addr3
1097  << ", FragNumber=" << std::hex << (int) m_seqFrag << std::dec << ", SeqNumber=" << m_seqSeq;
1098  break;
1100  os << " Duration/ID=" << m_duration << "us"
1101  << ", RA=" << m_addr1 << ", TA=" << m_addr2 << ", DA=" << m_addr3
1102  << ", FragNumber=" << std::hex << (int) m_seqFrag << std::dec << ", SeqNumber=" << m_seqSeq;
1103  break;
1104  case WIFI_MAC_DATA:
1105  PrintFrameControl (os);
1106  os << " Duration/ID=" << m_duration << "us";
1107  if (!m_ctrlToDs && !m_ctrlFromDs)
1108  {
1109  os << ", DA=" << m_addr1 << ", SA=" << m_addr2 << ", BSSID=" << m_addr3;
1110  }
1111  else if (!m_ctrlToDs && m_ctrlFromDs)
1112  {
1113  os << ", DA=" << m_addr1 << ", SA=" << m_addr3 << ", BSSID=" << m_addr2;
1114  }
1115  else if (m_ctrlToDs && !m_ctrlFromDs)
1116  {
1117  os << ", DA=" << m_addr3 << ", SA=" << m_addr2 << ", BSSID=" << m_addr1;
1118  }
1119  else if (m_ctrlToDs && m_ctrlFromDs)
1120  {
1121  os << ", DA=" << m_addr3 << ", SA=" << m_addr4 << ", RA=" << m_addr1 << ", TA=" << m_addr2;
1122  }
1123  else
1124  {
1125  NS_FATAL_ERROR ("Impossible ToDs and FromDs flags combination");
1126  }
1127  os << ", FragNumber=" << std::hex << (int) m_seqFrag << std::dec
1128  << ", SeqNumber=" << m_seqSeq;
1129  break;
1130  case WIFI_MAC_CTL_BACKREQ:
1131  case WIFI_MAC_CTL_BACKRESP:
1133  case WIFI_MAC_CTL_END:
1134  case WIFI_MAC_CTL_END_ACK:
1135  case WIFI_MAC_DATA_CFACK:
1136  case WIFI_MAC_DATA_CFPOLL:
1138  case WIFI_MAC_DATA_NULL:
1142  case WIFI_MAC_QOSDATA:
1146  case WIFI_MAC_QOSDATA_NULL:
1149  default:
1150  break;
1151  }
1152 }
1153 
1154 uint32_t
1156 {
1157  return GetSize ();
1158 }
1159 
1160 void
1162 {
1165  WriteTo (i, m_addr1);
1166  switch (m_ctrlType)
1167  {
1168  case TYPE_MGT:
1169  WriteTo (i, m_addr2);
1170  WriteTo (i, m_addr3);
1172  break;
1173  case TYPE_CTL:
1174  switch (m_ctrlSubtype)
1175  {
1176  case SUBTYPE_CTL_RTS:
1177  case SUBTYPE_CTL_TRIGGER:
1178  case SUBTYPE_CTL_BACKREQ:
1179  case SUBTYPE_CTL_BACKRESP:
1180  case SUBTYPE_CTL_END:
1181  case SUBTYPE_CTL_END_ACK:
1182  WriteTo (i, m_addr2);
1183  break;
1184  case SUBTYPE_CTL_CTS:
1185  case SUBTYPE_CTL_ACK:
1186  break;
1187  default:
1188  //NOTREACHED
1189  NS_ASSERT (false);
1190  break;
1191  }
1192  break;
1193  case TYPE_DATA:
1194  {
1195  WriteTo (i, m_addr2);
1196  WriteTo (i, m_addr3);
1198  if (m_ctrlToDs && m_ctrlFromDs)
1199  {
1200  WriteTo (i, m_addr4);
1201  }
1202  if (m_ctrlSubtype & 0x08)
1203  {
1205  }
1206  } break;
1207  default:
1208  //NOTREACHED
1209  NS_ASSERT (false);
1210  break;
1211  }
1212 }
1213 
1214 uint32_t
1216 {
1217  Buffer::Iterator i = start;
1218  uint16_t frame_control = i.ReadLsbtohU16 ();
1219  SetFrameControl (frame_control);
1220  m_duration = i.ReadLsbtohU16 ();
1221  ReadFrom (i, m_addr1);
1222  switch (m_ctrlType)
1223  {
1224  case TYPE_MGT:
1225  ReadFrom (i, m_addr2);
1226  ReadFrom (i, m_addr3);
1228  break;
1229  case TYPE_CTL:
1230  switch (m_ctrlSubtype)
1231  {
1232  case SUBTYPE_CTL_RTS:
1233  case SUBTYPE_CTL_TRIGGER:
1234  case SUBTYPE_CTL_BACKREQ:
1235  case SUBTYPE_CTL_BACKRESP:
1236  case SUBTYPE_CTL_END:
1237  case SUBTYPE_CTL_END_ACK:
1238  ReadFrom (i, m_addr2);
1239  break;
1240  case SUBTYPE_CTL_CTS:
1241  case SUBTYPE_CTL_ACK:
1242  break;
1243  }
1244  break;
1245  case TYPE_DATA:
1246  ReadFrom (i, m_addr2);
1247  ReadFrom (i, m_addr3);
1249  if (m_ctrlToDs && m_ctrlFromDs)
1250  {
1251  ReadFrom (i, m_addr4);
1252  }
1253  if (m_ctrlSubtype & 0x08)
1254  {
1256  }
1257  break;
1258  }
1259  return i.GetDistanceFrom (start);
1260 }
1261 
1262 } //namespace ns3
iterator in a Buffer instance
Definition: buffer.h:99
void WriteHtolsbU16(uint16_t data)
Definition: buffer.cc:911
uint16_t ReadLsbtohU16(void)
Definition: buffer.cc:1066
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:788
Protocol header serialization and deserialization.
Definition: header.h:43
virtual uint32_t Deserialize(Buffer::Iterator start)=0
Deserialize the object from a buffer iterator.
an EUI-48 address
Definition: mac48-address.h:44
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
int64_t GetNanoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:391
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
Implements the IEEE 802.11 MAC header.
void SetDsNotFrom(void)
Un-set the From DS bit in the Frame Control field.
Mac48Address GetAddr3(void) const
Return the address in the Address 3 field.
bool IsCtl(void) const
Return true if the Type is Control.
uint8_t m_qosEosp
QoS EOSP.
uint8_t m_ctrlRetry
control retry
uint8_t GetQosTid(void) const
Return the Traffic ID of a QoS header.
bool IsTrigger(void) const
Return true if the header is a Trigger header.
bool IsQosAck(void) const
Return if the QoS Ack policy is Normal Ack.
uint8_t m_qosTid
QoS TID.
void SetQosAckPolicy(QosAckPolicy policy)
Set the QoS Ack policy in the QoS control field.
bool IsAck(void) const
Return true if the header is an Ack header.
bool IsBlockAck(void) const
Return true if the header is a BlockAck header.
Mac48Address GetAddr4(void) const
Return the address in the Address 4 field.
void SetRawDuration(uint16_t duration)
Set the Duration/ID field with the given raw uint16_t value.
Time GetDuration(void) const
Return the duration from the Duration/ID field (Time object).
bool HasData(void) const
Return true if the header type is DATA and is not DATA_NULL.
bool IsRts(void) const
Return true if the header is a RTS header.
void SetQosAmsdu(void)
Set that A-MSDU is present.
void SetFrameControl(uint16_t control)
Set the Frame Control field with the given raw value.
void SetNoRetry(void)
Un-set the Retry bit in the Frame Control field.
bool IsAuthentication(void) const
Return true if the header is an Authentication header.
Mac48Address m_addr1
address 1
uint16_t m_seqSeq
sequence sequence
bool IsQosData(void) const
Return true if the Type is DATA and Subtype is one of the possible values for QoS Data.
void SetNoMoreFragments(void)
Un-set the More Fragment bit in the Frame Control Field.
bool IsFromDs(void) const
uint16_t GetSequenceNumber(void) const
Return the sequence number of the header.
void SetQosTxopLimit(uint8_t txop)
Set TXOP limit in the QoS control field.
bool IsCts(void) const
Return true if the header is a CTS header.
static TypeId GetTypeId(void)
Get the type ID.
void SetQosControl(uint16_t qos)
Set the QoS Control field with the given raw value.
uint8_t m_ctrlSubtype
control subtype
void SetSequenceNumber(uint16_t seq)
Set the sequence number of the header.
uint32_t GetSize(void) const
Return the size of the WifiMacHeader in octets.
uint8_t m_amsduPresent
A-MSDU present.
void SetDsTo(void)
Set the To DS bit in the Frame Control field.
uint8_t GetQosQueueSize(void) const
Get the Queue Size subfield in the QoS control field.
bool IsReassocResp(void) const
Return true if the header is a Reassociation Response header.
Mac48Address GetAddr2(void) const
Return the address in the Address 2 field.
uint16_t GetRawDuration(void) const
Return the raw duration from the Duration/ID field.
bool IsAssocReq(void) const
Return true if the header is an Association Request header.
Mac48Address m_addr4
address 4
Mac48Address m_addr2
address 2
void SetAddr1(Mac48Address address)
Fill the Address 1 field with the given address.
bool IsQosNoAck(void) const
Return if the QoS Ack policy is No Ack.
bool IsCfEnd(void) const
Return true if the header is a CF-End header.
void SetSequenceControl(uint16_t seq)
Set the Sequence Control field with the given raw value.
bool IsProbeResp(void) const
Return true if the header is a Probe Response header.
void SetQosQueueSize(uint8_t size)
Set the Queue Size subfield in the QoS control field.
void SetType(WifiMacType type, bool resetToDsFromDs=true)
Set Type/Subtype values with the correct values depending on the given type.
uint16_t GetQosControl(void) const
Return the raw QoS Control field.
void SetAddr4(Mac48Address address)
Fill the Address 4 field with the given address.
uint8_t m_ctrlOrder
control order (set to 1 for QoS Data and Management frames to signify that HT/VHT/HE control field is...
bool IsRetry(void) const
Return if the Retry bit is set.
uint8_t m_ctrlFromDs
control from DS
uint16_t GetFrameControl(void) const
Return the raw Frame Control field.
uint16_t m_duration
duration
const char * GetTypeString(void) const
Return a string corresponds to the header type.
uint8_t m_ctrlWep
control WEP
bool IsReassocReq(void) const
Return true if the header is a Reassociation Request header.
void SetQosTid(uint8_t tid)
Set the TID for the QoS header.
QosAckPolicy GetQosAckPolicy(void) const
Return the QoS Ack policy in the QoS control field.
void SetRetry(void)
Set the Retry bit in the Frame Control field.
bool IsMultihopAction(void) const
Check if the header is a Multihop action header.
void SetDuration(Time duration)
Set the Duration/ID field with the given duration (Time object).
TypeId GetInstanceTypeId(void) const override
Get the most derived TypeId for this Object.
bool IsCfPoll(void) const
Return true if the Type/Subtype is one of the possible CF-Poll headers.
bool IsDisassociation(void) const
Return true if the header is a Disassociation header.
void SetQosNoEosp()
Un-set the end of service period (EOSP) bit in the QoS control field.
uint8_t m_seqFrag
sequence fragment
bool IsDeauthentication(void) const
Return true if the header is a Deauthentication header.
bool IsAction(void) const
Return true if the header is an Action header.
uint8_t m_ctrlMoreData
control more data
void SetDsNotTo(void)
Un-set the To DS bit in the Frame Control field.
bool IsBlockAckReq(void) const
Return true if the header is a BlockAckRequest header.
bool IsProbeReq(void) const
Return true if the header is a Probe Request header.
void Print(std::ostream &os) const override
bool IsMgt(void) const
Return true if the Type is Management.
Mac48Address GetAddr1(void) const
Return the address in the Address 1 field.
bool IsAssocResp(void) const
Return true if the header is an Association Response header.
void SetQosNoMeshControlPresent()
Clear the Mesh Control Present flag for the QoS header.
uint32_t GetSerializedSize(void) const override
void SetNoOrder(void)
Unset order bit in the frame control field.
uint8_t m_qosStuff
QoS stuff.
void SetQosNoAmsdu(void)
Set that A-MSDU is not present.
void PrintFrameControl(std::ostream &os) const
Print the Frame Control field to the output stream.
uint8_t m_ctrlType
control type
void SetAddr2(Mac48Address address)
Fill the Address 2 field with the given address.
bool IsData(void) const
Return true if the Type is DATA.
void SetId(uint16_t id)
Set the Duration/ID field with the given ID.
void SetMoreFragments(void)
Set the More Fragment bit in the Frame Control field.
bool IsQosEosp(void) const
Return if the end of service period (EOSP) is set.
void SetDsFrom(void)
Set the From DS bit in the Frame Control field.
WifiMacType GetType(void) const
Return the type (enum WifiMacType)
void SetQosEosp()
Set the end of service period (EOSP) bit in the QoS control field.
void Serialize(Buffer::Iterator start) const override
bool IsMoreFragments(void) const
Return if the More Fragment bit is set.
void SetAddr3(Mac48Address address)
Fill the Address 3 field with the given address.
void SetFragmentNumber(uint8_t frag)
Set the fragment number of the header.
void SetQosMeshControlPresent()
Set the Mesh Control Present flag for the QoS header.
uint16_t GetSequenceControl(void) const
Return the raw Sequence Control field.
uint8_t GetFragmentNumber(void) const
Return the fragment number of the header.
bool IsToDs(void) const
Mac48Address m_addr3
address 3
uint8_t m_ctrlMoreFrag
control more fragments
void SetOrder(void)
Set order bit in the frame control field.
QosAckPolicy
Ack policy for QoS frames.
bool IsQosAmsdu(void) const
Check if the A-MSDU present bit is set in the QoS control field.
uint8_t m_ctrlToDs
control to DS
bool IsCfAck(void) const
Return true if the header is a CF-Ack header.
uint8_t m_qosAckPolicy
QoS Ack policy.
bool IsQosBlockAck(void) const
Return if the QoS Ack policy is Block Ack.
bool IsBeacon(void) const
Return true if the header is a Beacon header.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:67
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition: abort.h:50
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1260
address
Definition: first.py:44
Every class exported by the ns3 library is enclosed in the ns3 namespace.
@ SUBTYPE_CTL_END
@ SUBTYPE_CTL_BACKREQ
@ SUBTYPE_CTL_NDPANNOUNCE
@ SUBTYPE_CTL_END_ACK
@ SUBTYPE_CTL_CTLWRAPPER
@ SUBTYPE_CTL_TRIGGER
@ SUBTYPE_CTL_CTS
@ SUBTYPE_CTL_BACKRESP
@ SUBTYPE_CTL_RTS
@ SUBTYPE_CTL_BEAMFORMINGRPOLL
@ SUBTYPE_CTL_CTLFRAMEEXT
@ SUBTYPE_CTL_ACK
@ DATA
Definition: ul-job.h:39
WifiMacType
Combination of valid MAC header type/subtype.
@ WIFI_MAC_QOSDATA_NULL_CFACK_CFPOLL
@ WIFI_MAC_CTL_TRIGGER
@ WIFI_MAC_MGT_PROBE_REQUEST
@ WIFI_MAC_CTL_END_ACK
@ WIFI_MAC_DATA_CFACK
@ WIFI_MAC_CTL_BACKREQ
@ WIFI_MAC_DATA_NULL
@ WIFI_MAC_CTL_RTS
@ WIFI_MAC_CTL_CTS
@ WIFI_MAC_MGT_AUTHENTICATION
@ WIFI_MAC_MGT_MULTIHOP_ACTION
@ WIFI_MAC_CTL_CTLWRAPPER
@ WIFI_MAC_QOSDATA_CFACK_CFPOLL
@ WIFI_MAC_MGT_BEACON
@ WIFI_MAC_MGT_ACTION
@ WIFI_MAC_MGT_ASSOCIATION_RESPONSE
@ WIFI_MAC_CTL_ACK
@ WIFI_MAC_MGT_DISASSOCIATION
@ WIFI_MAC_QOSDATA_NULL_CFPOLL
@ WIFI_MAC_MGT_ASSOCIATION_REQUEST
@ WIFI_MAC_DATA_NULL_CFACK_CFPOLL
@ WIFI_MAC_MGT_REASSOCIATION_REQUEST
@ WIFI_MAC_QOSDATA_CFACK
@ WIFI_MAC_CTL_BACKRESP
@ WIFI_MAC_DATA_CFACK_CFPOLL
@ WIFI_MAC_DATA_CFPOLL
@ WIFI_MAC_CTL_END
@ WIFI_MAC_DATA_NULL_CFACK
@ WIFI_MAC_MGT_ACTION_NO_ACK
@ WIFI_MAC_MGT_DEAUTHENTICATION
@ WIFI_MAC_QOSDATA_NULL
@ WIFI_MAC_DATA_NULL_CFPOLL
@ WIFI_MAC_MGT_PROBE_RESPONSE
@ WIFI_MAC_QOSDATA_CFPOLL
@ WIFI_MAC_DATA
@ WIFI_MAC_MGT_REASSOCIATION_RESPONSE
@ WIFI_MAC_QOSDATA
void WriteTo(Buffer::Iterator &i, Ipv4Address ad)
Write an Ipv4Address to a Buffer.
void ReadFrom(Buffer::Iterator &i, Ipv4Address &ad)
Read an Ipv4Address from a Buffer.
def start()
Definition: core.py:1853
#define FOO(x)