A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
mgt-headers.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2006 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  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20  * Author: Mirko Banchi <mk.banchi@gmail.com>
21  */
22 #include "mgt-headers.h"
23 #include "ns3/simulator.h"
24 #include "ns3/assert.h"
25 
26 namespace ns3 {
27 
28 /***********************************************************
29  * Probe Request
30  ***********************************************************/
31 
32 NS_OBJECT_ENSURE_REGISTERED (MgtProbeRequestHeader);
33 
35 {
36 }
37 
38 void
40 {
41  m_ssid = ssid;
42 }
43 Ssid
45 {
46  return m_ssid;
47 }
48 void
50 {
51  m_rates = rates;
52 }
53 
56 {
57  return m_rates;
58 }
59 uint32_t
61 {
62  uint32_t size = 0;
63  size += m_ssid.GetSerializedSize ();
64  size += m_rates.GetSerializedSize ();
66  return size;
67 }
68 TypeId
70 {
71  static TypeId tid = TypeId ("ns3::MgtProbeRequestHeader")
72  .SetParent<Header> ()
73  .AddConstructor<MgtProbeRequestHeader> ()
74  ;
75  return tid;
76 }
77 TypeId
79 {
80  return GetTypeId ();
81 }
82 void
83 MgtProbeRequestHeader::Print (std::ostream &os) const
84 {
85  os << "ssid=" << m_ssid << ", "
86  << "rates=" << m_rates;
87 }
88 void
90 {
92  i = m_ssid.Serialize (i);
93  i = m_rates.Serialize (i);
94  i = m_rates.extended.Serialize (i);
95 }
96 uint32_t
98 {
100  i = m_ssid.Deserialize (i);
101  i = m_rates.Deserialize (i);
103  return i.GetDistanceFrom (start);
104 }
105 
106 
107 /***********************************************************
108  * Probe Response
109  ***********************************************************/
110 
112 
114 {
115 }
117 {
118 }
119 uint64_t
121 {
122  return m_timestamp;
123 }
124 Ssid
126 {
127  return m_ssid;
128 }
129 uint64_t
131 {
132  return m_beaconInterval;
133 }
136 {
137  return m_rates;
138 }
139 
140 void
142 {
143  m_ssid = ssid;
144 }
145 void
147 {
148  m_beaconInterval = us;
149 }
150 void
152 {
153  m_rates = rates;
154 }
155 TypeId
157 {
158  static TypeId tid = TypeId ("ns3::MgtProbeResponseHeader")
159  .SetParent<Header> ()
160  .AddConstructor<MgtProbeResponseHeader> ()
161  ;
162  return tid;
163 }
164 TypeId
166 {
167  return GetTypeId ();
168 }
169 uint32_t
171 {
172  uint32_t size = 0;
173  size += 8; // timestamp
174  size += 2; // beacon interval
175  size += m_capability.GetSerializedSize ();
176  size += m_ssid.GetSerializedSize ();
177  size += m_rates.GetSerializedSize ();
178  //size += 3; // ds parameter set
180  // xxx
181  return size;
182 }
183 void
184 MgtProbeResponseHeader::Print (std::ostream &os) const
185 {
186  os << "ssid=" << m_ssid << ", "
187  << "rates=" << m_rates;
188 }
189 void
191 {
192  // timestamp
193  // beacon interval
194  // capability information
195  // ssid
196  // supported rates
197  // fh parameter set
198  // ds parameter set
199  // cf parameter set
200  // ibss parameter set
201  //XXX
203  i.WriteHtolsbU64 (Simulator::Now ().GetMicroSeconds ());
204  i.WriteHtolsbU16 (m_beaconInterval / 1024);
205  i = m_capability.Serialize (i);
206  i = m_ssid.Serialize (i);
207  i = m_rates.Serialize (i);
208  //i.WriteU8 (0, 3); // ds parameter set.
209  i = m_rates.extended.Serialize (i);
210 }
211 uint32_t
213 {
215  m_timestamp = i.ReadLsbtohU64 ();
217  m_beaconInterval *= 1024;
218  i = m_capability.Deserialize (i);
219  i = m_ssid.Deserialize (i);
220  i = m_rates.Deserialize (i);
221  //i.Next (3); // ds parameter set
223  return i.GetDistanceFrom (start);
224 }
225 
226 /***********************************************************
227  * Assoc Request
228  ***********************************************************/
229 
231 
233  : m_listenInterval (0)
234 {
235 }
237 {
238 }
239 
240 void
242 {
243  m_ssid = ssid;
244 }
245 void
247 {
248  m_rates = rates;
249 }
250 void
252 {
253  m_listenInterval = interval;
254 }
255 Ssid
257 {
258  return m_ssid;
259 }
262 {
263  return m_rates;
264 }
265 uint16_t
267 {
268  return m_listenInterval;
269 }
270 
271 TypeId
273 {
274  static TypeId tid = TypeId ("ns3::MgtAssocRequestHeader")
275  .SetParent<Header> ()
276  .AddConstructor<MgtAssocRequestHeader> ()
277  ;
278  return tid;
279 }
280 TypeId
282 {
283  return GetTypeId ();
284 }
285 uint32_t
287 {
288  uint32_t size = 0;
289  size += m_capability.GetSerializedSize ();
290  size += 2;
291  size += m_ssid.GetSerializedSize ();
292  size += m_rates.GetSerializedSize ();
294  return size;
295 }
296 void
297 MgtAssocRequestHeader::Print (std::ostream &os) const
298 {
299  os << "ssid=" << m_ssid << ", "
300  << "rates=" << m_rates;
301 }
302 void
304 {
306  i = m_capability.Serialize (i);
308  i = m_ssid.Serialize (i);
309  i = m_rates.Serialize (i);
310  i = m_rates.extended.Serialize (i);
311 }
312 uint32_t
314 {
316  i = m_capability.Deserialize (i);
318  i = m_ssid.Deserialize (i);
319  i = m_rates.Deserialize (i);
321  return i.GetDistanceFrom (start);
322 }
323 
324 /***********************************************************
325  * Assoc Response
326  ***********************************************************/
327 
329 
331  : m_aid (0)
332 {
333 }
335 {
336 }
337 
340 {
341  return m_code;
342 }
345 {
346  return m_rates;
347 }
348 void
350 {
351  m_code = code;
352 }
353 void
355 {
356  m_rates = rates;
357 }
358 
359 TypeId
361 {
362  static TypeId tid = TypeId ("ns3::MgtAssocResponseHeader")
363  .SetParent<Header> ()
364  .AddConstructor<MgtAssocResponseHeader> ()
365  ;
366  return tid;
367 }
368 TypeId
370 {
371  return GetTypeId ();
372 }
373 uint32_t
375 {
376  uint32_t size = 0;
377  size += m_capability.GetSerializedSize ();
378  size += m_code.GetSerializedSize ();
379  size += 2; // aid
380  size += m_rates.GetSerializedSize ();
382  return size;
383 }
384 
385 void
386 MgtAssocResponseHeader::Print (std::ostream &os) const
387 {
388  os << "status code=" << m_code << ", "
389  << "rates=" << m_rates;
390 }
391 void
393 {
395  i = m_capability.Serialize (i);
396  i = m_code.Serialize (i);
397  i.WriteHtolsbU16 (m_aid);
398  i = m_rates.Serialize (i);
399  i = m_rates.extended.Serialize (i);
400 }
401 uint32_t
403 {
405  i = m_capability.Deserialize (i);
406  i = m_code.Deserialize (i);
407  m_aid = i.ReadLsbtohU16 ();
408  i = m_rates.Deserialize (i);
410  return i.GetDistanceFrom (start);
411 }
412 /**********************************************************
413  * ActionFrame
414  **********************************************************/
416 {
417 }
419 {
420 }
421 void
424 {
425  m_category = type;
426 
427  switch (type)
428  {
429  case BLOCK_ACK:
430  {
431  m_actionValue = action.blockAck;
432  break;
433  }
434  case MESH_PEERING_MGT:
435  {
436  m_actionValue = action.peerLink;
437  break;
438  }
439  case MESH_PATH_SELECTION:
440  {
441  m_actionValue = action.pathSelection;
442  break;
443  }
444  case MESH_LINK_METRIC:
445  case MESH_INTERWORKING:
448  break;
449  }
450 }
453 {
454  switch (m_category)
455  {
456  case BLOCK_ACK:
457  return BLOCK_ACK;
458  case MESH_PEERING_MGT:
459  return MESH_PEERING_MGT;
460  case MESH_LINK_METRIC:
461  return MESH_LINK_METRIC;
462  case MESH_PATH_SELECTION:
463  return MESH_PATH_SELECTION;
464  case MESH_INTERWORKING:
465  return MESH_INTERWORKING;
469  return MESH_PROXY_FORWARDING;
470  default:
471  NS_FATAL_ERROR ("Unknown action value");
472  return MESH_PEERING_MGT;
473  }
474 }
477 {
478  ActionValue retval;
479  retval.peerLink = PEER_LINK_OPEN; // Needs to be initialized to something to quiet valgrind in default cases
480  switch (m_category)
481  {
482  case BLOCK_ACK:
483  switch (m_actionValue)
484  {
487  return retval;
490  return retval;
491  case BLOCK_ACK_DELBA:
492  retval.blockAck = BLOCK_ACK_DELBA;
493  return retval;
494  }
495  case MESH_PEERING_MGT:
496  switch (m_actionValue)
497  {
498  case PEER_LINK_OPEN:
499  retval.peerLink = PEER_LINK_OPEN;
500  return retval;
501  case PEER_LINK_CONFIRM:
502  retval.peerLink = PEER_LINK_CONFIRM;
503  return retval;
504  case PEER_LINK_CLOSE:
505  retval.peerLink = PEER_LINK_CLOSE;
506  return retval;
507  default:
508  NS_FATAL_ERROR ("Unknown mesh peering management action code");
509  retval.peerLink = PEER_LINK_OPEN; /* quiet compiler */
510  return retval;
511  }
512  case MESH_PATH_SELECTION:
513  switch (m_actionValue)
514  {
515  case PATH_SELECTION:
516  retval.pathSelection = PATH_SELECTION;
517  return retval;
518  default:
519  NS_FATAL_ERROR ("Unknown mesh path selection action code");
520  retval.peerLink = PEER_LINK_OPEN; /* quiet compiler */
521  return retval;
522  }
523  case MESH_LINK_METRIC:
524  // not yet supported
525  case MESH_INTERWORKING:
526  // not yet supported
528  // not yet supported
529  default:
530  NS_FATAL_ERROR ("Unsupported mesh action");
531  retval.peerLink = PEER_LINK_OPEN; /* quiet compiler */
532  return retval;
533  }
534 }
535 TypeId
537 {
538  static TypeId tid = TypeId ("ns3::WifiActionHeader")
539  .SetParent<Header> ()
540  .AddConstructor<WifiActionHeader> ();
541  return tid;
542 }
543 TypeId
545 {
546  return GetTypeId ();
547 }
548 void
549 WifiActionHeader::Print (std::ostream &os) const
550 {
551 }
552 uint32_t
554 {
555  return 2;
556 }
557 void
559 {
560  start.WriteU8 (m_category);
561  start.WriteU8 (m_actionValue);
562 }
563 uint32_t
565 {
567  m_category = i.ReadU8 ();
568  m_actionValue = i.ReadU8 ();
569  return i.GetDistanceFrom (start);
570 }
571 
572 /***************************************************
573 * ADDBARequest
574 ****************************************************/
575 
577 
579  : m_dialogToken (1),
580  m_amsduSupport (1),
581  m_bufferSize (0)
582 {
583 }
584 
585 TypeId
587 {
588  static TypeId tid = TypeId ("ns3::MgtAddBaRequestHeader")
589  .SetParent<Header> ()
590  .AddConstructor<MgtAddBaRequestHeader> ();
591  return tid;
592 }
593 
594 TypeId
596 {
597  return GetTypeId ();
598 }
599 
600 void
601 MgtAddBaRequestHeader::Print (std::ostream &os) const
602 {
603 }
604 
605 uint32_t
607 {
608  uint32_t size = 0;
609  size += 1; //Dialog token
610  size += 2; //Block ack parameter set
611  size += 2; //Block ack timeout value
612  size += 2; //Starting sequence control
613  return size;
614 }
615 
616 void
618 {
624 }
625 
626 uint32_t
628 {
630  m_dialogToken = i.ReadU8 ();
634  return i.GetDistanceFrom (start);
635 }
636 
637 void
639 {
640  m_policy = 0;
641 }
642 
643 void
645 {
646  m_policy = 1;
647 }
648 
649 void
651 {
652  NS_ASSERT (tid < 16);
653  m_tid = tid;
654 }
655 
656 void
658 {
660 }
661 
662 void
664 {
665  m_bufferSize = size;
666 }
667 
668 void
670 {
671  m_startingSeq = seq;
672 }
673 
674 void
676 {
677  m_amsduSupport = supported;
678 }
679 
680 uint8_t
682 {
683  return m_tid;
684 }
685 
686 bool
688 {
689  return (m_policy == 1) ? true : false;
690 }
691 
692 uint16_t
694 {
695  return m_timeoutValue;
696 }
697 
698 uint16_t
700 {
701  return m_bufferSize;
702 }
703 
704 bool
706 {
707  return (m_amsduSupport == 1) ? true : false;
708 }
709 
710 uint16_t
712 {
713  return m_startingSeq;
714 }
715 
716 uint16_t
718 {
719  return (m_startingSeq << 4) & 0xfff0;
720 }
721 
722 void
724 {
725  m_startingSeq = (seqControl >> 4) & 0x0fff;
726 }
727 
728 uint16_t
730 {
731  uint16_t res = 0;
732  res |= m_amsduSupport;
733  res |= m_policy << 1;
734  res |= m_tid << 2;
735  res |= m_bufferSize << 6;
736  return res;
737 }
738 
739 void
741 {
742  m_amsduSupport = (params) & 0x01;
743  m_policy = (params >> 1) & 0x01;
744  m_tid = (params >> 2) & 0x0f;
745  m_bufferSize = (params >> 6) & 0x03ff;
746 }
747 
748 /***************************************************
749 * ADDBAResponse
750 ****************************************************/
751 
753 
755  : m_dialogToken (1),
756  m_amsduSupport (1),
757  m_bufferSize (0)
758 {
759 }
760 
761 TypeId
763 {
764  static TypeId tid = TypeId ("ns3::MgtAddBaResponseHeader")
765  .SetParent<Header> ()
766  .AddConstructor<MgtAddBaResponseHeader> ()
767  ;
768  return tid;
769 }
770 
771 TypeId
773 {
774  return GetTypeId ();
775 }
776 
777 void
778 MgtAddBaResponseHeader::Print (std::ostream &os) const
779 {
780  os << "status code=" << m_code;
781 }
782 
783 uint32_t
785 {
786  uint32_t size = 0;
787  size += 1; //Dialog token
788  size += m_code.GetSerializedSize (); //Status code
789  size += 2; //Block ack parameter set
790  size += 2; //Block ack timeout value
791  return size;
792 }
793 
794 void
796 {
799  i = m_code.Serialize (i);
802 }
803 
804 uint32_t
806 {
808  m_dialogToken = i.ReadU8 ();
809  i = m_code.Deserialize (i);
812  return i.GetDistanceFrom (start);
813 }
814 
815 void
817 {
818  m_policy = 0;
819 }
820 
821 void
823 {
824  m_policy = 1;
825 }
826 
827 void
829 {
830  NS_ASSERT (tid < 16);
831  m_tid = tid;
832 }
833 
834 void
836 {
838 }
839 
840 void
842 {
843  m_bufferSize = size;
844 }
845 
846 void
848 {
849  m_code = code;
850 }
851 
852 void
854 {
855  m_amsduSupport = supported;
856 }
857 
860 {
861  return m_code;
862 }
863 
864 uint8_t
866 {
867  return m_tid;
868 }
869 
870 bool
872 {
873  return (m_policy == 1) ? true : false;
874 }
875 
876 uint16_t
878 {
879  return m_timeoutValue;
880 }
881 
882 uint16_t
884 {
885  return m_bufferSize;
886 }
887 
888 bool
890 {
891  return (m_amsduSupport == 1) ? true : false;
892 }
893 
894 uint16_t
896 {
897  uint16_t res = 0;
898  res |= m_amsduSupport;
899  res |= m_policy << 1;
900  res |= m_tid << 2;
901  res |= m_bufferSize << 6;
902  return res;
903 }
904 
905 void
907 {
908  m_amsduSupport = (params) & 0x01;
909  m_policy = (params >> 1) & 0x01;
910  m_tid = (params >> 2) & 0x0f;
911  m_bufferSize = (params >> 6) & 0x03ff;
912 }
913 
914 /***************************************************
915 * DelBa
916 ****************************************************/
917 
919 
921  : m_reasonCode (1)
922 {
923 }
924 
925 TypeId
927 {
928  static TypeId tid = TypeId ("ns3::MgtDelBaHeader")
929  .SetParent<Header> ()
930  .AddConstructor<MgtDelBaHeader> ()
931  ;
932  return tid;
933 }
934 
935 TypeId
937 {
938  return GetTypeId ();
939 }
940 
941 void
942 MgtDelBaHeader::Print (std::ostream &os) const
943 {
944 }
945 
946 uint32_t
948 {
949  uint32_t size = 0;
950  size += 2; //DelBa parameter set
951  size += 2; //Reason code
952  return size;
953 }
954 
955 void
957 {
961 }
962 
963 uint32_t
965 {
969  return i.GetDistanceFrom (start);
970 }
971 
972 bool
974 {
975  return (m_initiator == 1) ? true : false;
976 }
977 
978 uint8_t
980 {
981  NS_ASSERT (m_tid < 16);
982  uint8_t tid = static_cast<uint8_t> (m_tid);
983  return tid;
984 }
985 
986 void
988 {
989  m_initiator = 1;
990 }
991 
992 void
994 {
995  m_initiator = 0;
996 }
997 
998 void
1000 {
1001  NS_ASSERT (tid < 16);
1002  m_tid = static_cast<uint16_t> (tid);
1003 }
1004 
1005 uint16_t
1007 {
1008  uint16_t res = 0;
1009  res |= m_initiator << 11;
1010  res |= m_tid << 12;
1011  return res;
1012 }
1013 
1014 void
1016 {
1017  m_initiator = (params >> 11) & 0x01;
1018  m_tid = (params >> 12) & 0x0f;
1019 }
1020 
1021 } // namespace ns3