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  ;
30 
32  : m_type (0)
33 {
34 }
35 
37  : m_type (type)
38 {
39 }
40 
42 {
43 }
44 
45 void
46 MacHeaderType::SetType (uint8_t type)
47 {
48  m_type = type;
49 }
50 
51 uint8_t
53 {
54  return m_type;
55 }
56 
57 std::string
59 {
60  return "MAC Header Type";
61 }
62 
63 TypeId
65 {
66  static TypeId tid = TypeId ("ns3::MacHeaderType").SetParent<Header> ().AddConstructor<MacHeaderType> ();
67  return tid;
68 }
69 
71 {
72  return GetTypeId ();
73 }
74 
75 void MacHeaderType::Print (std::ostream &os) const
76 {
77  os << " header type = " << (uint32_t) m_type;
78 }
79 
80 uint32_t MacHeaderType::GetSerializedSize (void) const
81 {
82  return 0;
83 }
84 
86 {
87 }
88 
90 {
91  return 0;
92 }
93 
94 // ----------------------------------------------------------------------------------------------------------
95 
97  ;
98 
100  : m_ht (0),
101  m_ec (0),
102  m_type (0),
103  m_ci (0),
104  m_eks (0),
105  m_len (0),
106  m_cid (Cid ())
107 {
108  m_esf = 0;
109  m_hcs = 0;
110  m_rsv1 = 0;
111  c_hcs = 0;
112 }
113 
115 {
116 }
117 
118 void GenericMacHeader::SetHt (uint8_t ht)
119 {
120  m_ht = ht;
121 }
122 
123 void GenericMacHeader::SetEc (uint8_t ec)
124 {
125  m_ec = ec;
126 }
127 
128 void GenericMacHeader::SetType (uint8_t type)
129 {
130  m_type = type;
131 }
132 
133 void GenericMacHeader::SetCi (uint8_t ci)
134 {
135  m_ci = ci;
136 }
137 
138 void GenericMacHeader::SetEks (uint8_t eks)
139 {
140  m_eks = eks;
141 }
142 
143 void GenericMacHeader::SetLen (uint16_t len)
144 {
145  m_len = len;
146 }
147 
149 {
150  m_cid = cid;
151 }
152 
153 void GenericMacHeader::SetHcs (uint8_t hcs)
154 {
155  m_hcs = hcs;
156 }
157 
158 uint8_t GenericMacHeader::GetHt (void) const
159 {
160  return m_ht;
161 }
162 
163 uint8_t GenericMacHeader::GetEc (void) const
164 {
165  return m_ec;
166 }
167 
168 uint8_t GenericMacHeader::GetType (void) const
169 {
170  return m_type;
171 }
172 
173 uint8_t GenericMacHeader::GetCi (void) const
174 {
175  return m_ci;
176 }
177 
178 uint8_t GenericMacHeader::GetEks (void) const
179 {
180  return m_eks;
181 }
182 
183 uint16_t GenericMacHeader::GetLen (void) const
184 {
185  return m_len;
186 }
187 
189 {
190  return m_cid;
191 }
192 
193 uint8_t GenericMacHeader::GetHcs (void) const
194 {
195  return m_hcs;
196 }
197 
198 std::string GenericMacHeader::GetName (void) const
199 {
200  return "Generic Mac Header";
201 }
202 
204 {
205  static TypeId tid = TypeId ("ns3::GenericMacHeader").SetParent<Header> ().AddConstructor<GenericMacHeader> ();
206  return tid;
207 }
208 
210 {
211  return GetTypeId ();
212 }
213 
214 void GenericMacHeader::Print (std::ostream &os) const
215 {
216  os << " ec (encryption control) = " << (uint32_t) m_ec << ", type = " << (uint32_t) m_type
217  << ", ci (crc indicator) = " << (uint32_t) m_ci << ", eks (encryption key sequence) = " << (uint32_t) m_eks
218  << ", len (length) = " << m_len << ", cid = " << m_cid << ", hcs (header check sequence) = " << (uint32_t) m_hcs;
219 }
220 
222 {
223  return 6;
224 }
225 
227 {
228 
229  /*
230  * AI:Serialize function according to the
231  * IEEE 8002.16e.
232  * Please send bug and comments to
233  * amine.ismail@udcast.com
234  * amine.ismail@sophia.inria.fr
235  */
236 
238 
239  uint8_t headerBuffer[6];
240  memset (headerBuffer, 0, 6);
241 
242  headerBuffer[0] = ((m_ht << 7) & 0x80) | ((m_ec << 6) & 0x40) | (m_type & 0x3F);
243  headerBuffer[1] = ((m_esf << 7) & 0x80) | ((m_ci << 6) & 0x40) | ((m_eks << 4) & 0x30) | ((m_rsv1 << 3) & 0x08)
244  | (((uint8_t)(m_len >> 8)) & 0x07);
245  headerBuffer[2] = (uint8_t)(m_len);
246  headerBuffer[3] = (uint8_t)(m_cid.GetIdentifier () >> 8);
247  headerBuffer[4] = (uint8_t)(m_cid.GetIdentifier ());
248  uint8_t crc = CRC8Calculate (headerBuffer, 5);
249  headerBuffer[5] = crc;
250  for (int j = 0; j < 6; j++)
251  {
252  i.WriteU8 (headerBuffer[j]);
253  }
254 
255 }
256 
258 {
259 
260  /*
261  * AI:Deserialize function according to the
262  * IEEE 8002.16e.
263  * Please send bug and comments to
264  * amine.ismail@udcast.com
265  * amine.ismail@sophia.inria.fr
266  */
267 
269 
270  uint8_t headerBuffer[6];
271  for (int j = 0; j < 6; j++)
272  {
273  headerBuffer[j] = i.ReadU8 ();
274  }
275  m_ht = (headerBuffer[0] >> 7) & 0x01;
276  m_ec = (headerBuffer[0] >> 6) & 0x01;
277  m_type = (headerBuffer[0]) & 0x3F;
278  m_esf = (headerBuffer[1] >> 7) & 0x01;
279  m_ci = (headerBuffer[1] >> 6) & 0x01;
280  m_eks = (headerBuffer[1] >> 4) & 0x03;
281  m_rsv1 = (headerBuffer[1] >> 3) & 0x01;
282  uint16_t lenmsb = (headerBuffer[1] & 0x07);
283  uint16_t lenlsb = headerBuffer[2];
284  m_len = ((lenmsb << 8) & 0x0700) | (lenlsb & 0x00FF);
285  uint16_t cidmsb = headerBuffer[3];
286  uint16_t cidlsb = headerBuffer[4];
287  uint16_t cid = ((cidmsb << 8) & 0xFF00) | (cidlsb & 0x00FF);
288  m_cid = Cid (cid);
289  m_hcs = headerBuffer[5];
290  c_hcs = CRC8Calculate (headerBuffer, 5);
291  return i.GetDistanceFrom (start);
292 }
293 
295 {
296  return (m_hcs == c_hcs);
297 }
298 
299 // ----------------------------------------------------------------------------------------------------------
300 
302  ;
303 
305  : m_ht (1),
306  m_ec (0),
307  m_type (0),
308  m_br (0),
309  m_cid (Cid ()),
310  m_hcs (0)
311 {
312 }
313 
315 {
316 }
317 
319 {
320  m_ht = ht;
321 }
322 
324 {
325  m_ec = ec;
326 }
327 
329 {
330  m_type = type;
331 }
332 
334 {
335  m_br = br;
336 }
337 
339 {
340  m_cid = cid;
341 }
342 
344 {
345  m_hcs = hcs;
346 }
347 
348 uint8_t BandwidthRequestHeader::GetHt (void) const
349 {
350  return m_ht;
351 }
352 
353 uint8_t BandwidthRequestHeader::GetEc (void) const
354 {
355  return m_ec;
356 }
357 
359 {
360  return m_type;
361 }
362 
363 uint32_t BandwidthRequestHeader::GetBr (void) const
364 {
365  return m_br;
366 }
367 
369 {
370  return m_cid;
371 }
372 
373 uint8_t BandwidthRequestHeader::GetHcs (void) const
374 {
375  return m_hcs;
376 }
377 
378 std::string BandwidthRequestHeader::GetName (void) const
379 {
380  return "Bandwidth Request Header";
381 }
382 
384 {
385  static TypeId tid = TypeId ("ns3::BandwidthRequestHeader").SetParent<Header> ().AddConstructor<
387  return tid;
388 }
389 
391 {
392  return GetTypeId ();
393 }
394 
395 void BandwidthRequestHeader::Print (std::ostream &os) const
396 {
397  os << " ec (encryption control) = " << (uint32_t) m_ec << ", type = " << (uint32_t) m_type
398  << ", br (bandwidth request) = " << m_br << ", cid = ";
399  m_cid.GetIdentifier ();
400  os << ", hcs (header check sequence) = " << (uint32_t) m_hcs;
401 }
402 
404 {
405  /*
406  * The size of the BandwidthRequest mac header is always 6 bytes
407  */
408  return 6;
409 }
410 
412 {
413 
414  /*
415  * AI:Serialize function according to the
416  * IEEE 8002.16e.
417  * please send bug and comments to
418  * amine.ismail@udcast.com
419  * amine.ismail@sophia.inria.fr
420  */
421 
423  uint8_t headerBuffer[6];
424  uint8_t br_msb1 = (((uint32_t) m_br) >> 16) & 0x00000007;
425  uint8_t br_msb2 = (((uint32_t) m_br) >> 8) & 0x000000FF;
426  uint8_t br_lsb = m_br & 0x000000FF;
427  headerBuffer[0] = ((m_ht << 7) & 0x80) | ((m_ec << 6) & 0x40) | ((m_type << 3) & 0x38) | br_msb1;
428  headerBuffer[1] = br_msb2;
429  headerBuffer[2] = br_lsb;
430  headerBuffer[3] = (uint8_t)((m_cid.GetIdentifier () >> 8) & 0x00FF);
431  headerBuffer[4] = (uint8_t)(m_cid.GetIdentifier () & 0x00FF);
432  headerBuffer[5] = CRC8Calculate (headerBuffer, 5);
433 
434  for (int j = 0; j < 6; j++)
435  {
436  i.WriteU8 (headerBuffer[j]);
437  }
438 }
439 
441 {
442 
443  /*
444  * AI:Deserialize function according to the
445  * IEEE 8002.16e.
446  * Please send bug and comments to
447  * amine.ismail@udcast.com
448  * amine.ismail@sophia.inria.fr
449  */
450 
452 
453  uint8_t headerBuffer[6];
454  for (int j = 0; j < 6; j++)
455  {
456  headerBuffer[j] = i.ReadU8 ();
457  }
458 
459  m_ht = (headerBuffer[0] >> 7) & 0x01;
460  m_ec = (headerBuffer[0] >> 6) & 0x01;
461  m_type = (headerBuffer[0] >> 3) & 0x07;
462  uint32_t br_msb1 = headerBuffer[0] & 0x00000007;
463  uint32_t br_msb2 = headerBuffer[1] & 0x000000FF;
464  uint32_t br_lsb = headerBuffer[2] & 0x000000FF;
465  m_br = ((uint32_t) br_msb1 << 14) | ((uint32_t) br_msb2 << 8) | br_lsb;
466  uint16_t cidmsb = headerBuffer[3];
467  uint16_t cidlsb = headerBuffer[4];
468  uint16_t cid = ((cidmsb << 8) & 0xFF00) | (cidlsb & 0x00FF);
469  m_cid = Cid (cid);
470  m_hcs = headerBuffer[5];
471  c_hcs = CRC8Calculate (headerBuffer, 5);
472 
473  return i.GetDistanceFrom (start);
474 
475 }
476 
478 {
479  return (m_hcs == c_hcs);
480 }
481 
482 // ----------------------------------------------------------------------------------------------------------
483 
485  ;
486 
488  : m_si (0),
489  m_pm (0),
490  m_pbr (0)
491 {
492 }
493 
495 {
496 }
497 
499 {
500  m_si = si;
501 }
502 
504 {
505  m_pm = pm;
506 }
507 
509 {
510  m_pbr = pbr;
511 }
512 
514 {
515  return m_si;
516 }
517 
519 {
520  return m_pm;
521 }
522 
523 uint16_t GrantManagementSubheader::GetPbr (void) const
524 {
525  return m_pbr;
526 }
527 
528 std::string GrantManagementSubheader::GetName (void) const
529 {
530  return "Grant Management Subheader";
531 }
532 
534 {
535  static TypeId tid = TypeId ("ns3::GrantManagementSubheader").SetParent<Header> ().AddConstructor<
537  return tid;
538 }
539 
541 {
542  return GetTypeId ();
543 }
544 
545 void GrantManagementSubheader::Print (std::ostream &os) const
546 {
547  os << " si (slip indicator) = " << (uint32_t) m_si << ", pm (poll me) = " << (uint32_t) m_pm
548  << ", pbr (piggyback request) = " << m_pbr;
549 }
550 
552 {
553  return 1 + 1 + 2;
554 }
555 
557 {
559  i.WriteU8 (m_si);
560  i.WriteU8 (m_pm);
561  i.WriteU16 (m_pbr);
562 }
563 
565 {
567  m_si = i.ReadU8 ();
568  m_pm = i.ReadU8 ();
569  m_pbr = i.ReadU16 ();
570 
571  return i.GetDistanceFrom (start);
572 }
573 
574 // ----------------------------------------------------------------------------------------------------------
575 
577  ;
578 
580  : m_fc (0),
581  m_fsn (0)
582 {
583 }
584 
586 {
587 }
588 
589 void
591 {
592  m_fc = fc;
593 }
594 
595 void
597 {
598  m_fsn = fsn;
599 }
600 
601 uint8_t
603 {
604  return m_fc;
605 }
606 
607 uint8_t
609 {
610  return m_fsn;
611 }
612 
613 
614 std::string
616 {
617  return "Fragmentation Subheader";
618 }
619 
620 TypeId
622 {
623  static TypeId tid = TypeId ("ns3::FragmentationSubheader").SetParent<
624  Header> ().AddConstructor<FragmentationSubheader> ();
625  return tid;
626 }
627 
628 TypeId
630 {
631  return GetTypeId ();
632 }
633 
634 void
635 FragmentationSubheader::Print (std::ostream &os) const
636 {
637  os << " fc (fragment control) = " << (uint32_t) m_fc << ", fsn (fragmentation sequence number) = "
638  << (uint32_t) m_fsn << "\n";
639 }
640 
641 uint32_t
643 {
644  return 2;
645 }
646 
647 void
649 {
651  i.WriteU8 (m_fc);
652  i.WriteU8 (m_fsn);
653 }
654 
655 uint32_t
657 {
659  m_fc = i.ReadU8 ();
660  m_fsn = i.ReadU8 ();
661 
662  return i.GetDistanceFrom (start);
663 }
664 
665 } // namespace ns3
uint16_t ReadU16(void)
Definition: buffer.h:845
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
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)
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
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:807
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:895
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:690
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:819
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:611
uint32_t GetSerializedSize(void) const
void Print(std::ostream &os) const
void SetLen(uint16_t len)
virtual TypeId GetInstanceTypeId(void) const