A Discrete-Event Network Simulator
API
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
26namespace ns3 {
27
28NS_OBJECT_ENSURE_REGISTERED (MacHeaderType);
29
31 : m_type (0)
32{
33}
34
36 : m_type (type)
37{
38}
39
41{
42}
43
44void
46{
47 m_type = type;
48}
49
50uint8_t
52{
53 return m_type;
54}
55
56std::string
58{
59 return "MAC Header Type";
60}
61
64{
65 static TypeId tid = TypeId ("ns3::MacHeaderType")
66 .SetParent<Header> ()
67 .SetGroupName("Wimax")
68 .AddConstructor<MacHeaderType> ()
69 ;
70 return tid;
71}
72
74{
75 return GetTypeId ();
76}
77
78void MacHeaderType::Print (std::ostream &os) const
79{
80 os << " header type = " << (uint32_t) m_type;
81}
82
84{
85 return 0;
86}
87
89{
90}
91
93{
94 return 0;
95}
96
97// ----------------------------------------------------------------------------------------------------------
98
100
102 : m_ht (0),
103 m_ec (0),
104 m_type (0),
105 m_ci (0),
106 m_eks (0),
107 m_len (0),
108 m_cid (Cid ())
109{
110 m_esf = 0;
111 m_hcs = 0;
112 m_rsv1 = 0;
113 c_hcs = 0;
114}
115
117{
118}
119
120void GenericMacHeader::SetHt (uint8_t ht)
121{
122 m_ht = ht;
123}
124
125void GenericMacHeader::SetEc (uint8_t ec)
126{
127 m_ec = ec;
128}
129
130void GenericMacHeader::SetType (uint8_t type)
131{
132 m_type = type;
133}
134
135void GenericMacHeader::SetCi (uint8_t ci)
136{
137 m_ci = ci;
138}
139
140void GenericMacHeader::SetEks (uint8_t eks)
141{
142 m_eks = eks;
143}
144
145void GenericMacHeader::SetLen (uint16_t len)
146{
147 m_len = len;
148}
149
151{
152 m_cid = cid;
153}
154
155void GenericMacHeader::SetHcs (uint8_t hcs)
156{
157 m_hcs = hcs;
158}
159
160uint8_t GenericMacHeader::GetHt (void) const
161{
162 return m_ht;
163}
164
165uint8_t GenericMacHeader::GetEc (void) const
166{
167 return m_ec;
168}
169
170uint8_t GenericMacHeader::GetType (void) const
171{
172 return m_type;
173}
174
175uint8_t GenericMacHeader::GetCi (void) const
176{
177 return m_ci;
178}
179
180uint8_t GenericMacHeader::GetEks (void) const
181{
182 return m_eks;
183}
184
185uint16_t GenericMacHeader::GetLen (void) const
186{
187 return m_len;
188}
189
191{
192 return m_cid;
193}
194
195uint8_t GenericMacHeader::GetHcs (void) const
196{
197 return m_hcs;
198}
199
200std::string GenericMacHeader::GetName (void) const
201{
202 return "Generic Mac Header";
203}
204
206{
207 static TypeId tid = TypeId ("ns3::GenericMacHeader")
208 .SetParent<Header> ()
209 .SetGroupName("Wimax")
210 .AddConstructor<GenericMacHeader> ()
211 ;
212 return tid;
213}
214
216{
217 return GetTypeId ();
218}
219
220void GenericMacHeader::Print (std::ostream &os) const
221{
222 os << " ec (encryption control) = " << (uint32_t) m_ec << ", type = " << (uint32_t) m_type
223 << ", ci (crc indicator) = " << (uint32_t) m_ci << ", eks (encryption key sequence) = " << (uint32_t) m_eks
224 << ", len (length) = " << m_len << ", cid = " << m_cid << ", hcs (header check sequence) = " << (uint32_t) m_hcs;
225}
226
228{
229 return 6;
230}
231
233{
234
235 /*
236 * AI:Serialize function according to the
237 * IEEE 8002.16e.
238 * Please send bug and comments to
239 * amine.ismail@udcast.com
240 * amine.ismail@sophia.inria.fr
241 */
242
244
245 uint8_t headerBuffer[6];
246 memset (headerBuffer, 0, 6);
247
248 headerBuffer[0] = ((m_ht << 7) & 0x80) | ((m_ec << 6) & 0x40) | (m_type & 0x3F);
249 headerBuffer[1] = ((m_esf << 7) & 0x80) | ((m_ci << 6) & 0x40) | ((m_eks << 4) & 0x30) | ((m_rsv1 << 3) & 0x08)
250 | (((uint8_t)(m_len >> 8)) & 0x07);
251 headerBuffer[2] = (uint8_t)(m_len);
252 headerBuffer[3] = (uint8_t)(m_cid.GetIdentifier () >> 8);
253 headerBuffer[4] = (uint8_t)(m_cid.GetIdentifier ());
254 uint8_t crc = CRC8Calculate (headerBuffer, 5);
255 headerBuffer[5] = crc;
256 for (int j = 0; j < 6; j++)
257 {
258 i.WriteU8 (headerBuffer[j]);
259 }
260
261}
262
264{
265
266 /*
267 * AI:Deserialize function according to the
268 * IEEE 8002.16e.
269 * Please send bug and comments to
270 * amine.ismail@udcast.com
271 * amine.ismail@sophia.inria.fr
272 */
273
275
276 uint8_t headerBuffer[6];
277 for (int j = 0; j < 6; j++)
278 {
279 headerBuffer[j] = i.ReadU8 ();
280 }
281 m_ht = (headerBuffer[0] >> 7) & 0x01;
282 m_ec = (headerBuffer[0] >> 6) & 0x01;
283 m_type = (headerBuffer[0]) & 0x3F;
284 m_esf = (headerBuffer[1] >> 7) & 0x01;
285 m_ci = (headerBuffer[1] >> 6) & 0x01;
286 m_eks = (headerBuffer[1] >> 4) & 0x03;
287 m_rsv1 = (headerBuffer[1] >> 3) & 0x01;
288 uint16_t lenmsb = (headerBuffer[1] & 0x07);
289 uint16_t lenlsb = headerBuffer[2];
290 m_len = ((lenmsb << 8) & 0x0700) | (lenlsb & 0x00FF);
291 uint16_t cidmsb = headerBuffer[3];
292 uint16_t cidlsb = headerBuffer[4];
293 uint16_t cid = ((cidmsb << 8) & 0xFF00) | (cidlsb & 0x00FF);
294 m_cid = Cid (cid);
295 m_hcs = headerBuffer[5];
296 c_hcs = CRC8Calculate (headerBuffer, 5);
297 return i.GetDistanceFrom (start);
298}
299
301{
302 return (m_hcs == c_hcs);
303}
304
305// ----------------------------------------------------------------------------------------------------------
306
308
310 : m_ht (1),
311 m_ec (0),
312 m_type (0),
313 m_br (0),
314 m_cid (Cid ()),
315 m_hcs (0)
316{
317}
318
320{
321}
322
324{
325 m_ht = ht;
326}
327
329{
330 m_ec = ec;
331}
332
334{
335 m_type = type;
336}
337
339{
340 m_br = br;
341}
342
344{
345 m_cid = cid;
346}
347
349{
350 m_hcs = hcs;
351}
352
354{
355 return m_ht;
356}
357
359{
360 return m_ec;
361}
362
364{
365 return m_type;
366}
367
369{
370 return m_br;
371}
372
374{
375 return m_cid;
376}
377
379{
380 return m_hcs;
381}
382
383std::string BandwidthRequestHeader::GetName (void) const
384{
385 return "Bandwidth Request Header";
386}
387
389{
390 static TypeId tid = TypeId ("ns3::BandwidthRequestHeader")
391 .SetParent<Header> ()
392 .SetGroupName("Wimax")
393 .AddConstructor<BandwidthRequestHeader> ()
394 ;
395 return tid;
396}
397
399{
400 return GetTypeId ();
401}
402
403void BandwidthRequestHeader::Print (std::ostream &os) const
404{
405 os << " ec (encryption control) = " << (uint32_t) m_ec << ", type = " << (uint32_t) m_type
406 << ", br (bandwidth request) = " << m_br << ", cid = ";
408 os << ", hcs (header check sequence) = " << (uint32_t) m_hcs;
409}
410
412{
413 /*
414 * The size of the BandwidthRequest mac header is always 6 bytes
415 */
416 return 6;
417}
418
420{
421
422 /*
423 * AI:Serialize function according to the
424 * IEEE 8002.16e.
425 * please send bug and comments to
426 * amine.ismail@udcast.com
427 * amine.ismail@sophia.inria.fr
428 */
429
431 uint8_t headerBuffer[6];
432 uint8_t br_msb1 = (((uint32_t) m_br) >> 16) & 0x00000007;
433 uint8_t br_msb2 = (((uint32_t) m_br) >> 8) & 0x000000FF;
434 uint8_t br_lsb = m_br & 0x000000FF;
435 headerBuffer[0] = ((m_ht << 7) & 0x80) | ((m_ec << 6) & 0x40) | ((m_type << 3) & 0x38) | br_msb1;
436 headerBuffer[1] = br_msb2;
437 headerBuffer[2] = br_lsb;
438 headerBuffer[3] = (uint8_t)((m_cid.GetIdentifier () >> 8) & 0x00FF);
439 headerBuffer[4] = (uint8_t)(m_cid.GetIdentifier () & 0x00FF);
440 headerBuffer[5] = CRC8Calculate (headerBuffer, 5);
441
442 for (int j = 0; j < 6; j++)
443 {
444 i.WriteU8 (headerBuffer[j]);
445 }
446}
447
449{
450
451 /*
452 * AI:Deserialize function according to the
453 * IEEE 8002.16e.
454 * Please send bug and comments to
455 * amine.ismail@udcast.com
456 * amine.ismail@sophia.inria.fr
457 */
458
460
461 uint8_t headerBuffer[6];
462 for (int j = 0; j < 6; j++)
463 {
464 headerBuffer[j] = i.ReadU8 ();
465 }
466
467 m_ht = (headerBuffer[0] >> 7) & 0x01;
468 m_ec = (headerBuffer[0] >> 6) & 0x01;
469 m_type = (headerBuffer[0] >> 3) & 0x07;
470 uint32_t br_msb1 = headerBuffer[0] & 0x00000007;
471 uint32_t br_msb2 = headerBuffer[1] & 0x000000FF;
472 uint32_t br_lsb = headerBuffer[2] & 0x000000FF;
473 m_br = ((uint32_t) br_msb1 << 14) | ((uint32_t) br_msb2 << 8) | br_lsb;
474 uint16_t cidmsb = headerBuffer[3];
475 uint16_t cidlsb = headerBuffer[4];
476 uint16_t cid = ((cidmsb << 8) & 0xFF00) | (cidlsb & 0x00FF);
477 m_cid = Cid (cid);
478 m_hcs = headerBuffer[5];
479 c_hcs = CRC8Calculate (headerBuffer, 5);
480
481 return i.GetDistanceFrom (start);
482
483}
484
486{
487 return (m_hcs == c_hcs);
488}
489
490// ----------------------------------------------------------------------------------------------------------
491
493
495 : m_si (0),
496 m_pm (0),
497 m_pbr (0)
498{
499}
500
502{
503}
504
506{
507 m_si = si;
508}
509
511{
512 m_pm = pm;
513}
514
516{
517 m_pbr = pbr;
518}
519
521{
522 return m_si;
523}
524
526{
527 return m_pm;
528}
529
531{
532 return m_pbr;
533}
534
535std::string GrantManagementSubheader::GetName (void) const
536{
537 return "Grant Management Subheader";
538}
539
541{
542 static TypeId tid = TypeId ("ns3::GrantManagementSubheader")
543 .SetParent<Header> ()
544 .SetGroupName("Wimax")
545 .AddConstructor<GrantManagementSubheader> ()
546 ;
547 return tid;
548}
549
551{
552 return GetTypeId ();
553}
554
555void GrantManagementSubheader::Print (std::ostream &os) const
556{
557 os << " si (slip indicator) = " << (uint32_t) m_si << ", pm (poll me) = " << (uint32_t) m_pm
558 << ", pbr (piggyback request) = " << m_pbr;
559}
560
562{
563 return 1 + 1 + 2;
564}
565
567{
569 i.WriteU8 (m_si);
570 i.WriteU8 (m_pm);
571 i.WriteU16 (m_pbr);
572}
573
575{
577 m_si = i.ReadU8 ();
578 m_pm = i.ReadU8 ();
579 m_pbr = i.ReadU16 ();
580
581 return i.GetDistanceFrom (start);
582}
583
584// ----------------------------------------------------------------------------------------------------------
585
587
589 : m_fc (0),
590 m_fsn (0)
591{
592}
593
595{
596}
597
598void
600{
601 m_fc = fc;
602}
603
604void
606{
607 m_fsn = fsn;
608}
609
610uint8_t
612{
613 return m_fc;
614}
615
616uint8_t
618{
619 return m_fsn;
620}
621
622
623std::string
625{
626 return "Fragmentation Subheader";
627}
628
629TypeId
631{
632 static TypeId tid = TypeId ("ns3::FragmentationSubheader")
633 .SetParent<Header> ()
634 .SetGroupName("Wimax")
635 .AddConstructor<FragmentationSubheader> ()
636 ;
637 return tid;
638}
639
640TypeId
642{
643 return GetTypeId ();
644}
645
646void
647FragmentationSubheader::Print (std::ostream &os) const
648{
649 os << " fc (fragment control) = " << (uint32_t) m_fc << ", fsn (fragmentation sequence number) = "
650 << (uint32_t) m_fsn << "\n";
651}
652
655{
656 return 2;
657}
658
659void
661{
663 i.WriteU8 (m_fc);
664 i.WriteU8 (m_fsn);
665}
666
669{
671 m_fc = i.ReadU8 ();
672 m_fsn = i.ReadU8 ();
673
674 return i.GetDistanceFrom (start);
675}
676
677} // namespace ns3
This class implements the bandwidth-request mac Header as described by IEEE Standard for Local and me...
uint8_t m_ec
Encryption Control.
uint32_t GetSerializedSize(void) const
uint32_t Deserialize(Buffer::Iterator start)
void SetBr(uint32_t br)
Set BR field.
Cid GetCid(void) const
Get CID field.
void SetEc(uint8_t ec)
Set EC field.
void SetType(uint8_t type)
Set type field.
uint8_t c_hcs
calculated header check sequence; this is used to check if the received header is correct or not
uint8_t m_hcs
Header Check Sequence.
uint32_t GetBr(void) const
Get BR field.
void Serialize(Buffer::Iterator start) const
uint8_t GetHcs(void) const
Get HCS field.
void SetHcs(uint8_t hcs)
Set HCS field.
std::string GetName(void) const
Get name field.
void SetHt(uint8_t ht)
Set HT field.
void SetCid(Cid cid)
Set CID field.
uint8_t GetHt(void) const
Get HT field.
uint32_t m_br
Bandwidth Request.
uint8_t GetEc(void) const
Get EC field.
bool check_hcs(void) const
Check HCS.
uint8_t GetType(void) const
Get type field.
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
static TypeId GetTypeId(void)
Get the type ID.
void Print(std::ostream &os) const
Cid m_cid
Connection identifier.
iterator in a Buffer instance
Definition: buffer.h:99
void WriteU8(uint8_t data)
Definition: buffer.h:869
void WriteU16(uint16_t data)
Definition: buffer.cc:871
uint16_t ReadU16(void)
Definition: buffer.h:1029
uint8_t ReadU8(void)
Definition: buffer.h:1021
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:788
Cid class.
Definition: cid.h:38
uint16_t GetIdentifier(void) const
Definition: cid.cc:45
This class implements the fragmentation sub-header as described by IEEE Standard for Local and metrop...
static TypeId GetTypeId(void)
Get the type ID.
uint8_t m_fsn
Fragment Sequence Number.
std::string GetName(void) const
Get name field.
uint32_t Deserialize(Buffer::Iterator start)
void Serialize(Buffer::Iterator start) const
uint8_t GetFc(void) const
Get FC field.
void Print(std::ostream &os) const
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
void SetFsn(uint8_t fsn)
Set FSN field.
void SetFc(uint8_t fc)
Set FC field.
uint32_t GetSerializedSize(void) const
uint8_t GetFsn(void) const
Get FSN field.
uint8_t m_fc
Fragment Control.
This class implements the Generic mac Header as described by IEEE Standard for Local and metropolitan...
bool check_hcs(void) const
Check HCS.
uint8_t GetHt(void) const
Get HT field.
void SetHcs(uint8_t hcs)
Set HCS field.
uint8_t m_hcs
Header Check Sequence.
void SetEc(uint8_t ec)
Set EC field.
uint8_t m_ht
Header type.
uint8_t GetEks(void) const
Get EKS field.
void Serialize(Buffer::Iterator start) const
uint8_t GetType(void) const
Get type field.
uint8_t GetHcs(void) const
Get HCS field.
void SetType(uint8_t type)
Set type field.
uint16_t GetLen(void) const
Get length field.
uint32_t Deserialize(Buffer::Iterator start)
void SetHt(uint8_t ht)
Set HT field.
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
uint8_t m_ec
Encryption Control.
static TypeId GetTypeId(void)
Get the type ID.
uint8_t GetCi(void) const
Get CI field.
void SetEks(uint8_t eks)
Set EKS field.
uint8_t m_ci
CRC Indicator.
void Print(std::ostream &os) const
void SetLen(uint16_t len)
Set length field.
std::string GetName(void) const
Get name field.
uint8_t GetEc(void) const
Get EC field.
void SetCid(Cid cid)
Set CID field.
void SetCi(uint8_t ci)
Set CI field.
uint8_t c_hcs
calculated header check sequence; this is used to check if the received header is correct or not
uint32_t GetSerializedSize(void) const
uint8_t m_eks
Encryption Key Sequence.
Cid GetCid(void) const
Get CID field.
This class implements the grant management sub-header as described by IEEE Standard for Local and met...
uint16_t GetPbr(void) const
Get PBR field.
uint8_t GetPm(void) const
Get PM field.
uint16_t m_pbr
PiggyBack Request.
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
void SetSi(uint8_t si)
Set SI field.
void SetPm(uint8_t pm)
Set PM field.
void Serialize(Buffer::Iterator start) const
uint32_t Deserialize(Buffer::Iterator start)
uint32_t GetSerializedSize(void) const
static TypeId GetTypeId(void)
Get the type ID.
uint8_t GetSi(void) const
Get SI field.
uint8_t m_si
Slip Indicator.
void Print(std::ostream &os) const
std::string GetName(void) const
Get name field.
void SetPbr(uint16_t pbr)
Set PRR field.
uint8_t m_pm
Poll-Me bit (byte in this case)
Protocol header serialization and deserialization.
Definition: header.h:43
This class Represents the HT (Header Type) field of generic MAC and bandwidth request headers.
void SetType(uint8_t type)
Set type field.
uint8_t m_type
MAC header type.
void Print(std::ostream &os) const
MacHeaderType(void)
Constructor.
void Serialize(Buffer::Iterator start) const
uint8_t GetType(void) const
Get type field.
virtual ~MacHeaderType(void)
uint32_t Deserialize(Buffer::Iterator start)
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
std::string GetName(void) const
Get name field.
uint32_t GetSerializedSize(void) const
static TypeId GetTypeId(void)
Get the type ID.
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t CRC8Calculate(const uint8_t *data, int length)
Definition: crc8.cc:57
def start()
Definition: core.py:1853