A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
wimax-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) 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  * Author: 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 "wimax-mac-header.h"
24 #include "crc8.h"
25 
26 namespace ns3 {
27 
28 NS_OBJECT_ENSURE_REGISTERED (MacHeaderType);
29 
31  : m_type (0)
32 {
33 }
34 
36  : m_type (type)
37 {
38 }
39 
41 {
42 }
43 
44 void
45 MacHeaderType::SetType (uint8_t type)
46 {
47  m_type = type;
48 }
49 
50 uint8_t
52 {
53  return m_type;
54 }
55 
56 std::string
58 {
59  return "MAC Header Type";
60 }
61 
62 TypeId
64 {
65  static TypeId tid = TypeId ("ns3::MacHeaderType").SetParent<Header> ().AddConstructor<MacHeaderType> ();
66  return tid;
67 }
68 
70 {
71  return GetTypeId ();
72 }
73 
74 void MacHeaderType::Print (std::ostream &os) const
75 {
76  os << " header type = " << (uint32_t) m_type;
77 }
78 
79 uint32_t MacHeaderType::GetSerializedSize (void) const
80 {
81  return 0;
82 }
83 
85 {
86 }
87 
89 {
90  return 0;
91 }
92 
93 // ----------------------------------------------------------------------------------------------------------
94 
96 
98  : m_ht (0),
99  m_ec (0),
100  m_type (0),
101  m_ci (0),
102  m_eks (0),
103  m_len (0),
104  m_cid (Cid ())
105 {
106  m_esf = 0;
107  m_hcs = 0;
108  m_rsv1 = 0;
109  c_hcs = 0;
110 }
111 
113 {
114 }
115 
116 void GenericMacHeader::SetHt (uint8_t ht)
117 {
118  m_ht = ht;
119 }
120 
121 void GenericMacHeader::SetEc (uint8_t ec)
122 {
123  m_ec = ec;
124 }
125 
126 void GenericMacHeader::SetType (uint8_t type)
127 {
128  m_type = type;
129 }
130 
131 void GenericMacHeader::SetCi (uint8_t ci)
132 {
133  m_ci = ci;
134 }
135 
136 void GenericMacHeader::SetEks (uint8_t eks)
137 {
138  m_eks = eks;
139 }
140 
141 void GenericMacHeader::SetLen (uint16_t len)
142 {
143  m_len = len;
144 }
145 
147 {
148  m_cid = cid;
149 }
150 
151 void GenericMacHeader::SetHcs (uint8_t hcs)
152 {
153  m_hcs = hcs;
154 }
155 
156 uint8_t GenericMacHeader::GetHt (void) const
157 {
158  return m_ht;
159 }
160 
161 uint8_t GenericMacHeader::GetEc (void) const
162 {
163  return m_ec;
164 }
165 
166 uint8_t GenericMacHeader::GetType (void) const
167 {
168  return m_type;
169 }
170 
171 uint8_t GenericMacHeader::GetCi (void) const
172 {
173  return m_ci;
174 }
175 
176 uint8_t GenericMacHeader::GetEks (void) const
177 {
178  return m_eks;
179 }
180 
181 uint16_t GenericMacHeader::GetLen (void) const
182 {
183  return m_len;
184 }
185 
187 {
188  return m_cid;
189 }
190 
191 uint8_t GenericMacHeader::GetHcs (void) const
192 {
193  return m_hcs;
194 }
195 
196 std::string GenericMacHeader::GetName (void) const
197 {
198  return "Generic Mac Header";
199 }
200 
202 {
203  static TypeId tid = TypeId ("ns3::GenericMacHeader").SetParent<Header> ().AddConstructor<GenericMacHeader> ();
204  return tid;
205 }
206 
208 {
209  return GetTypeId ();
210 }
211 
212 void GenericMacHeader::Print (std::ostream &os) const
213 {
214  os << " ec (encryption control) = " << (uint32_t) m_ec << ", type = " << (uint32_t) m_type
215  << ", ci (crc indicator) = " << (uint32_t) m_ci << ", eks (encryption key sequence) = " << (uint32_t) m_eks
216  << ", len (length) = " << m_len << ", cid = " << m_cid << ", hcs (header check sequence) = " << (uint32_t) m_hcs;
217 }
218 
220 {
221  return 6;
222 }
223 
225 {
226 
227  /*
228  * AI:Serialize function according to the
229  * IEEE 8002.16e.
230  * Please send bug and comments to
231  * amine.ismail@udcast.com
232  * amine.ismail@sophia.inria.fr
233  */
234 
236 
237  uint8_t headerBuffer[6];
238  memset (headerBuffer, 0, 6);
239 
240  headerBuffer[0] = ((m_ht << 7) & 0x80) | ((m_ec << 6) & 0x40) | (m_type & 0x3F);
241  headerBuffer[1] = ((m_esf << 7) & 0x80) | ((m_ci << 6) & 0x40) | ((m_eks << 4) & 0x30) | ((m_rsv1 << 3) & 0x08)
242  | (((uint8_t)(m_len >> 8)) & 0x07);
243  headerBuffer[2] = (uint8_t)(m_len);
244  headerBuffer[3] = (uint8_t)(m_cid.GetIdentifier () >> 8);
245  headerBuffer[4] = (uint8_t)(m_cid.GetIdentifier ());
246  uint8_t crc = CRC8Calculate (headerBuffer, 5);
247  headerBuffer[5] = crc;
248  for (int j = 0; j < 6; j++)
249  {
250  i.WriteU8 (headerBuffer[j]);
251  }
252 
253 }
254 
256 {
257 
258  /*
259  * AI:Deserialize function according to the
260  * IEEE 8002.16e.
261  * Please send bug and comments to
262  * amine.ismail@udcast.com
263  * amine.ismail@sophia.inria.fr
264  */
265 
267 
268  uint8_t headerBuffer[6];
269  for (int j = 0; j < 6; j++)
270  {
271  headerBuffer[j] = i.ReadU8 ();
272  }
273  m_ht = (headerBuffer[0] >> 7) & 0x01;
274  m_ec = (headerBuffer[0] >> 6) & 0x01;
275  m_type = (headerBuffer[0]) & 0x3F;
276  m_esf = (headerBuffer[1] >> 7) & 0x01;
277  m_ci = (headerBuffer[1] >> 6) & 0x01;
278  m_eks = (headerBuffer[1] >> 4) & 0x03;
279  m_rsv1 = (headerBuffer[1] >> 3) & 0x01;
280  uint16_t lenmsb = (headerBuffer[1] & 0x07);
281  uint16_t lenlsb = headerBuffer[2];
282  m_len = ((lenmsb << 8) & 0x0700) | (lenlsb & 0x00FF);
283  uint16_t cidmsb = headerBuffer[3];
284  uint16_t cidlsb = headerBuffer[4];
285  uint16_t cid = ((cidmsb << 8) & 0xFF00) | (cidlsb & 0x00FF);
286  m_cid = Cid (cid);
287  m_hcs = headerBuffer[5];
288  c_hcs = CRC8Calculate (headerBuffer, 5);
289  return i.GetDistanceFrom (start);
290 }
291 
293 {
294  return (m_hcs == c_hcs);
295 }
296 
297 // ----------------------------------------------------------------------------------------------------------
298 
300 
302  : m_ht (1),
303  m_ec (0),
304  m_type (0),
305  m_br (0),
306  m_cid (Cid ()),
307  m_hcs (0)
308 {
309 }
310 
312 {
313 }
314 
316 {
317  m_ht = ht;
318 }
319 
321 {
322  m_ec = ec;
323 }
324 
326 {
327  m_type = type;
328 }
329 
331 {
332  m_br = br;
333 }
334 
336 {
337  m_cid = cid;
338 }
339 
341 {
342  m_hcs = hcs;
343 }
344 
345 uint8_t BandwidthRequestHeader::GetHt (void) const
346 {
347  return m_ht;
348 }
349 
350 uint8_t BandwidthRequestHeader::GetEc (void) const
351 {
352  return m_ec;
353 }
354 
356 {
357  return m_type;
358 }
359 
360 uint32_t BandwidthRequestHeader::GetBr (void) const
361 {
362  return m_br;
363 }
364 
366 {
367  return m_cid;
368 }
369 
370 uint8_t BandwidthRequestHeader::GetHcs (void) const
371 {
372  return m_hcs;
373 }
374 
375 std::string BandwidthRequestHeader::GetName (void) const
376 {
377  return "Bandwidth Request Header";
378 }
379 
381 {
382  static TypeId tid = TypeId ("ns3::BandwidthRequestHeader").SetParent<Header> ().AddConstructor<
384  return tid;
385 }
386 
388 {
389  return GetTypeId ();
390 }
391 
392 void BandwidthRequestHeader::Print (std::ostream &os) const
393 {
394  os << " ec (encryption control) = " << (uint32_t) m_ec << ", type = " << (uint32_t) m_type
395  << ", br (bandwidth request) = " << m_br << ", cid = ";
396  m_cid.GetIdentifier ();
397  os << ", hcs (header check sequence) = " << (uint32_t) m_hcs;
398 }
399 
401 {
402  /*
403  * The size of the BandwidthRequest mac header is always 6 bytes
404  */
405  return 6;
406 }
407 
409 {
410 
411  /*
412  * AI:Serialize function according to the
413  * IEEE 8002.16e.
414  * please send bug and comments to
415  * amine.ismail@udcast.com
416  * amine.ismail@sophia.inria.fr
417  */
418 
420  uint8_t headerBuffer[6];
421  uint8_t br_msb1 = (((uint32_t) m_br) >> 16) & 0x00000007;
422  uint8_t br_msb2 = (((uint32_t) m_br) >> 8) & 0x000000FF;
423  uint8_t br_lsb = m_br & 0x000000FF;
424  headerBuffer[0] = ((m_ht << 7) & 0x80) | ((m_ec << 6) & 0x40) | ((m_type << 3) & 0x38) | br_msb1;
425  headerBuffer[1] = br_msb2;
426  headerBuffer[2] = br_lsb;
427  headerBuffer[3] = (uint8_t)((m_cid.GetIdentifier () >> 8) & 0x00FF);
428  headerBuffer[4] = (uint8_t)(m_cid.GetIdentifier () & 0x00FF);
429  headerBuffer[5] = CRC8Calculate (headerBuffer, 5);
430 
431  for (int j = 0; j < 6; j++)
432  {
433  i.WriteU8 (headerBuffer[j]);
434  }
435 }
436 
438 {
439 
440  /*
441  * AI:Deserialize function according to the
442  * IEEE 8002.16e.
443  * Please send bug and comments to
444  * amine.ismail@udcast.com
445  * amine.ismail@sophia.inria.fr
446  */
447 
449 
450  uint8_t headerBuffer[6];
451  for (int j = 0; j < 6; j++)
452  {
453  headerBuffer[j] = i.ReadU8 ();
454  }
455 
456  m_ht = (headerBuffer[0] >> 7) & 0x01;
457  m_ec = (headerBuffer[0] >> 6) & 0x01;
458  m_type = (headerBuffer[0] >> 3) & 0x07;
459  uint32_t br_msb1 = headerBuffer[0] & 0x00000007;
460  uint32_t br_msb2 = headerBuffer[1] & 0x000000FF;
461  uint32_t br_lsb = headerBuffer[2] & 0x000000FF;
462  m_br = ((uint32_t) br_msb1 << 14) | ((uint32_t) br_msb2 << 8) | br_lsb;
463  uint16_t cidmsb = headerBuffer[3];
464  uint16_t cidlsb = headerBuffer[4];
465  uint16_t cid = ((cidmsb << 8) & 0xFF00) | (cidlsb & 0x00FF);
466  m_cid = Cid (cid);
467  m_hcs = headerBuffer[5];
468  c_hcs = CRC8Calculate (headerBuffer, 5);
469 
470  return i.GetDistanceFrom (start);
471 
472 }
473 
475 {
476  return (m_hcs == c_hcs);
477 }
478 
479 // ----------------------------------------------------------------------------------------------------------
480 
482 
484  : m_si (0),
485  m_pm (0),
486  m_pbr (0)
487 {
488 }
489 
491 {
492 }
493 
495 {
496  m_si = si;
497 }
498 
500 {
501  m_pm = pm;
502 }
503 
505 {
506  m_pbr = pbr;
507 }
508 
510 {
511  return m_si;
512 }
513 
515 {
516  return m_pm;
517 }
518 
519 uint16_t GrantManagementSubheader::GetPbr (void) const
520 {
521  return m_pbr;
522 }
523 
524 std::string GrantManagementSubheader::GetName (void) const
525 {
526  return "Grant Management Subheader";
527 }
528 
530 {
531  static TypeId tid = TypeId ("ns3::GrantManagementSubheader").SetParent<Header> ().AddConstructor<
533  return tid;
534 }
535 
537 {
538  return GetTypeId ();
539 }
540 
541 void GrantManagementSubheader::Print (std::ostream &os) const
542 {
543  os << " si (slip indicator) = " << (uint32_t) m_si << ", pm (poll me) = " << (uint32_t) m_pm
544  << ", pbr (piggyback request) = " << m_pbr;
545 }
546 
548 {
549  return 1 + 1 + 2;
550 }
551 
553 {
555  i.WriteU8 (m_si);
556  i.WriteU8 (m_pm);
557  i.WriteU16 (m_pbr);
558 }
559 
561 {
563  m_si = i.ReadU8 ();
564  m_pm = i.ReadU8 ();
565  m_pbr = i.ReadU16 ();
566 
567  return i.GetDistanceFrom (start);
568 }
569 
570 // ----------------------------------------------------------------------------------------------------------
571 
573 
575  : m_fc (0),
576  m_fsn (0)
577 {
578 }
579 
581 {
582 }
583 
584 void
586 {
587  m_fc = fc;
588 }
589 
590 void
592 {
593  m_fsn = fsn;
594 }
595 
596 uint8_t
598 {
599  return m_fc;
600 }
601 
602 uint8_t
604 {
605  return m_fsn;
606 }
607 
608 
609 std::string
611 {
612  return "Fragmentation Subheader";
613 }
614 
615 TypeId
617 {
618  static TypeId tid = TypeId ("ns3::FragmentationSubheader").SetParent<
619  Header> ().AddConstructor<FragmentationSubheader> ();
620  return tid;
621 }
622 
623 TypeId
625 {
626  return GetTypeId ();
627 }
628 
629 void
630 FragmentationSubheader::Print (std::ostream &os) const
631 {
632  os << " fc (fragment control) = " << (uint32_t) m_fc << ", fsn (fragmentation sequence number) = "
633  << (uint32_t) m_fsn << "\n";
634 }
635 
636 uint32_t
638 {
639  return 2;
640 }
641 
642 void
644 {
646  i.WriteU8 (m_fc);
647  i.WriteU8 (m_fsn);
648 }
649 
650 uint32_t
652 {
654  m_fc = i.ReadU8 ();
655  m_fsn = i.ReadU8 ();
656 
657  return i.GetDistanceFrom (start);
658 }
659 
660 } // namespace ns3
uint16_t ReadU16(void)
Definition: buffer.h:1036
Protocol header serialization and deserialization.
Definition: header.h:42
void Print(std::ostream &os) const
uint8_t GetHcs(void) const
virtual TypeId GetInstanceTypeId(void) const
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
Definition: object-base.h:38
void Serialize(Buffer::Iterator start) const
GrantManagementSubheader(void)
this class implements the grant management sub-header as described by IEEE Standard for Local and met...
void SetType(uint8_t type)
std::string GetName(void) const
std::string GetName(void) const
static TypeId GetTypeId(void)
uint32_t Deserialize(Buffer::Iterator start)
uint32_t Deserialize(Buffer::Iterator start)
void SetHcs(uint8_t hcs)
uint8_t GetType(void) const
virtual TypeId GetInstanceTypeId(void) const
virtual TypeId GetInstanceTypeId(void) const
void SetEc(uint8_t ec)
virtual ~MacHeaderType(void)
this class implements the Generic mac Header as described by IEEE Standard for Local and metropolitan...
uint8_t GetEc(void) const
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:811
uint8_t GetType(void) const
iterator in a Buffer instance
Definition: buffer.h:98
static TypeId GetTypeId(void)
uint32_t GetSerializedSize(void) const
uint8_t GetFc(void) const
void Print(std::ostream &os) const
uint32_t Deserialize(Buffer::Iterator start)
uint32_t GetSerializedSize(void) const
uint32_t Deserialize(Buffer::Iterator start)
Cid GetCid(void) const
uint8_t GetFsn(void) const
uint8_t GetCi(void) const
void Print(std::ostream &os) const
void WriteU16(uint16_t data)
Definition: buffer.cc:899
uint8_t GetEc(void) const
Doxygen introspection did not find any typical Config paths.
uint8_t GetHt(void) const
uint16_t GetPbr(void) const
static TypeId GetTypeId(void)
void Serialize(Buffer::Iterator start) const
void SetType(uint8_t type)
std::string GetName(void) const
this class implements the bandwidth-request mac Header as described by IEEE Standard for Local and me...
Definition: cid.h:35
void Print(std::ostream &os) const
uint32_t GetSerializedSize(void) const
void SetEks(uint8_t eks)
void SetHt(uint8_t HT)
this class implements the fragmentation sub-header as described by IEEE Standard for Local and metrop...
uint8_t GetHcs(void) const
uint8_t GetEks(void) const
uint32_t GetBr(void) const
void WriteU8(uint8_t data)
Definition: buffer.h:876
std::string GetName(void) const
static TypeId GetTypeId(void)
uint8_t GetType(void) const
void SetCi(uint8_t ci)
uint8_t ReadU8(void)
Definition: buffer.h:1028
void Serialize(Buffer::Iterator start) const
uint16_t GetIdentifier(void) const
Definition: cid.cc:45
void Serialize(Buffer::Iterator start) const
uint8_t CRC8Calculate(const uint8_t *data, int length)
Definition: crc8.cc:56
void Serialize(Buffer::Iterator start) const
uint32_t GetSerializedSize(void) const
bool check_hcs(void) const
uint8_t GetHt(void) const
uint32_t Deserialize(Buffer::Iterator start)
uint16_t GetLen(void) const
virtual TypeId GetInstanceTypeId(void) const
a unique identifier for an interface.
Definition: type-id.h:49
std::string GetName(void) const
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
uint32_t GetSerializedSize(void) const
void Print(std::ostream &os) const
void SetLen(uint16_t len)
virtual TypeId GetInstanceTypeId(void) const