A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wimax-mac-header.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007,2008, 2009 INRIA, UDcast
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Jahanzeb Farooq <jahanzeb.farooq@sophia.inria.fr>
7 * Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
8 * <amine.ismail@udcast.com>
9 */
10
11#include "wimax-mac-header.h"
12
13#include "crc8.h"
14
15namespace ns3
16{
17
18NS_OBJECT_ENSURE_REGISTERED(MacHeaderType);
19
21 : m_type(0)
22{
23}
24
26 : m_type(type)
27{
28}
29
33
34void
36{
37 m_type = type;
38}
39
40uint8_t
42{
43 return m_type;
44}
45
46std::string
48{
49 return "MAC Header Type";
50}
51
54{
55 static TypeId tid = TypeId("ns3::MacHeaderType")
57 .SetGroupName("Wimax")
58 .AddConstructor<MacHeaderType>();
59 return tid;
60}
61
64{
65 return GetTypeId();
66}
67
68void
69MacHeaderType::Print(std::ostream& os) const
70{
71 os << " header type = " << (uint32_t)m_type;
72}
73
76{
77 return 0;
78}
79
80void
84
87{
88 return 0;
89}
90
91// ----------------------------------------------------------------------------------------------------------
92
94
96 : m_ht(0),
97 m_ec(0),
98 m_type(0),
99 m_ci(0),
100 m_eks(0),
101 m_len(0),
102 m_cid(Cid())
103{
104 m_esf = 0;
105 m_hcs = 0;
106 m_rsv1 = 0;
107 c_hcs = 0;
108}
109
113
114void
116{
117 m_ht = ht;
118}
119
120void
122{
123 m_ec = ec;
124}
125
126void
128{
129 m_type = type;
130}
131
132void
134{
135 m_ci = ci;
136}
137
138void
140{
141 m_eks = eks;
142}
143
144void
146{
147 m_len = len;
148}
149
150void
152{
153 m_cid = cid;
154}
155
156void
158{
159 m_hcs = hcs;
160}
161
162uint8_t
164{
165 return m_ht;
166}
167
168uint8_t
170{
171 return m_ec;
172}
173
174uint8_t
176{
177 return m_type;
178}
179
180uint8_t
182{
183 return m_ci;
184}
185
186uint8_t
188{
189 return m_eks;
190}
191
192uint16_t
194{
195 return m_len;
196}
197
198Cid
200{
201 return m_cid;
202}
203
204uint8_t
206{
207 return m_hcs;
208}
209
210std::string
212{
213 return "Generic Mac Header";
214}
215
216TypeId
218{
219 static TypeId tid = TypeId("ns3::GenericMacHeader")
220 .SetParent<Header>()
221 .SetGroupName("Wimax")
222 .AddConstructor<GenericMacHeader>();
223 return tid;
224}
225
226TypeId
228{
229 return GetTypeId();
230}
231
232void
233GenericMacHeader::Print(std::ostream& os) const
234{
235 os << " ec (encryption control) = " << (uint32_t)m_ec << ", type = " << (uint32_t)m_type
236 << ", ci (crc indicator) = " << (uint32_t)m_ci
237 << ", eks (encryption key sequence) = " << (uint32_t)m_eks << ", len (length) = " << m_len
238 << ", cid = " << m_cid << ", hcs (header check sequence) = " << (uint32_t)m_hcs;
239}
240
243{
244 return 6;
245}
246
247void
249{
250 /*
251 * AI:Serialize function according to the
252 * IEEE 8002.16e.
253 * Please send bug and comments to
254 * amine.ismail@udcast.com
255 * amine.ismail@sophia.inria.fr
256 */
257
258 Buffer::Iterator i = start;
259
260 uint8_t headerBuffer[6];
261 memset(headerBuffer, 0, 6);
262
263 headerBuffer[0] = ((m_ht << 7) & 0x80) | ((m_ec << 6) & 0x40) | (m_type & 0x3F);
264 headerBuffer[1] = ((m_esf << 7) & 0x80) | ((m_ci << 6) & 0x40) | ((m_eks << 4) & 0x30) |
265 ((m_rsv1 << 3) & 0x08) | (((uint8_t)(m_len >> 8)) & 0x07);
266 headerBuffer[2] = (uint8_t)(m_len);
267 headerBuffer[3] = (uint8_t)(m_cid.GetIdentifier() >> 8);
268 headerBuffer[4] = (uint8_t)(m_cid.GetIdentifier());
269 uint8_t crc = CRC8Calculate(headerBuffer, 5);
270 headerBuffer[5] = crc;
271 for (int j = 0; j < 6; j++)
272 {
273 i.WriteU8(headerBuffer[j]);
274 }
275}
276
279{
280 /*
281 * AI:Deserialize function according to the
282 * IEEE 8002.16e.
283 * Please send bug and comments to
284 * amine.ismail@udcast.com
285 * amine.ismail@sophia.inria.fr
286 */
287
288 Buffer::Iterator i = start;
289
290 uint8_t headerBuffer[6];
291 for (int j = 0; j < 6; j++)
292 {
293 headerBuffer[j] = i.ReadU8();
294 }
295 m_ht = (headerBuffer[0] >> 7) & 0x01;
296 m_ec = (headerBuffer[0] >> 6) & 0x01;
297 m_type = (headerBuffer[0]) & 0x3F;
298 m_esf = (headerBuffer[1] >> 7) & 0x01;
299 m_ci = (headerBuffer[1] >> 6) & 0x01;
300 m_eks = (headerBuffer[1] >> 4) & 0x03;
301 m_rsv1 = (headerBuffer[1] >> 3) & 0x01;
302 uint16_t lenmsb = (headerBuffer[1] & 0x07);
303 uint16_t lenlsb = headerBuffer[2];
304 m_len = ((lenmsb << 8) & 0x0700) | (lenlsb & 0x00FF);
305 uint16_t cidmsb = headerBuffer[3];
306 uint16_t cidlsb = headerBuffer[4];
307 uint16_t cid = ((cidmsb << 8) & 0xFF00) | (cidlsb & 0x00FF);
308 m_cid = Cid(cid);
309 m_hcs = headerBuffer[5];
310 c_hcs = CRC8Calculate(headerBuffer, 5);
311 return i.GetDistanceFrom(start);
312}
313
314bool
316{
317 return m_hcs == c_hcs;
318}
319
320// ----------------------------------------------------------------------------------------------------------
321
323
325 : m_ht(1),
326 m_ec(0),
327 m_type(0),
328 m_br(0),
329 m_cid(Cid()),
330 m_hcs(0)
331{
332}
333
337
338void
340{
341 m_ht = ht;
342}
343
344void
346{
347 m_ec = ec;
348}
349
350void
352{
353 m_type = type;
354}
355
356void
361
362void
364{
365 m_cid = cid;
366}
367
368void
370{
371 m_hcs = hcs;
372}
373
374uint8_t
376{
377 return m_ht;
378}
379
380uint8_t
382{
383 return m_ec;
384}
385
386uint8_t
388{
389 return m_type;
390}
391
394{
395 return m_br;
396}
397
398Cid
400{
401 return m_cid;
402}
403
404uint8_t
406{
407 return m_hcs;
408}
409
410std::string
412{
413 return "Bandwidth Request Header";
414}
415
416TypeId
418{
419 static TypeId tid = TypeId("ns3::BandwidthRequestHeader")
420 .SetParent<Header>()
421 .SetGroupName("Wimax")
422 .AddConstructor<BandwidthRequestHeader>();
423 return tid;
424}
425
426TypeId
431
432void
433BandwidthRequestHeader::Print(std::ostream& os) const
434{
435 os << " ec (encryption control) = " << (uint32_t)m_ec << ", type = " << (uint32_t)m_type
436 << ", br (bandwidth request) = " << m_br << ", cid = ";
438 os << ", hcs (header check sequence) = " << (uint32_t)m_hcs;
439}
440
443{
444 /*
445 * The size of the BandwidthRequest mac header is always 6 bytes
446 */
447 return 6;
448}
449
450void
452{
453 /*
454 * AI:Serialize function according to the
455 * IEEE 8002.16e.
456 * please send bug and comments to
457 * amine.ismail@udcast.com
458 * amine.ismail@sophia.inria.fr
459 */
460
461 Buffer::Iterator i = start;
462 uint8_t headerBuffer[6];
463 uint8_t br_msb1 = (((uint32_t)m_br) >> 16) & 0x00000007;
464 uint8_t br_msb2 = (((uint32_t)m_br) >> 8) & 0x000000FF;
465 uint8_t br_lsb = m_br & 0x000000FF;
466 headerBuffer[0] =
467 ((m_ht << 7) & 0x80) | ((m_ec << 6) & 0x40) | ((m_type << 3) & 0x38) | br_msb1;
468 headerBuffer[1] = br_msb2;
469 headerBuffer[2] = br_lsb;
470 headerBuffer[3] = (uint8_t)((m_cid.GetIdentifier() >> 8) & 0x00FF);
471 headerBuffer[4] = (uint8_t)(m_cid.GetIdentifier() & 0x00FF);
472 headerBuffer[5] = CRC8Calculate(headerBuffer, 5);
473
474 for (int j = 0; j < 6; j++)
475 {
476 i.WriteU8(headerBuffer[j]);
477 }
478}
479
482{
483 /*
484 * AI:Deserialize function according to the
485 * IEEE 8002.16e.
486 * Please send bug and comments to
487 * amine.ismail@udcast.com
488 * amine.ismail@sophia.inria.fr
489 */
490
491 Buffer::Iterator i = start;
492
493 uint8_t headerBuffer[6];
494 for (int j = 0; j < 6; j++)
495 {
496 headerBuffer[j] = i.ReadU8();
497 }
498
499 m_ht = (headerBuffer[0] >> 7) & 0x01;
500 m_ec = (headerBuffer[0] >> 6) & 0x01;
501 m_type = (headerBuffer[0] >> 3) & 0x07;
502 uint32_t br_msb1 = headerBuffer[0] & 0x00000007;
503 uint32_t br_msb2 = headerBuffer[1] & 0x000000FF;
504 uint32_t br_lsb = headerBuffer[2] & 0x000000FF;
505 m_br = ((uint32_t)br_msb1 << 14) | ((uint32_t)br_msb2 << 8) | br_lsb;
506 uint16_t cidmsb = headerBuffer[3];
507 uint16_t cidlsb = headerBuffer[4];
508 uint16_t cid = ((cidmsb << 8) & 0xFF00) | (cidlsb & 0x00FF);
509 m_cid = Cid(cid);
510 m_hcs = headerBuffer[5];
511 c_hcs = CRC8Calculate(headerBuffer, 5);
512
513 return i.GetDistanceFrom(start);
514}
515
516bool
518{
519 return m_hcs == c_hcs;
520}
521
522// ----------------------------------------------------------------------------------------------------------
523
525
527 : m_si(0),
528 m_pm(0),
529 m_pbr(0)
530{
531}
532
536
537void
539{
540 m_si = si;
541}
542
543void
545{
546 m_pm = pm;
547}
548
549void
551{
552 m_pbr = pbr;
553}
554
555uint8_t
557{
558 return m_si;
559}
560
561uint8_t
563{
564 return m_pm;
565}
566
567uint16_t
569{
570 return m_pbr;
571}
572
573std::string
575{
576 return "Grant Management Subheader";
577}
578
579TypeId
581{
582 static TypeId tid = TypeId("ns3::GrantManagementSubheader")
583 .SetParent<Header>()
584 .SetGroupName("Wimax")
585 .AddConstructor<GrantManagementSubheader>();
586 return tid;
587}
588
589TypeId
594
595void
596GrantManagementSubheader::Print(std::ostream& os) const
597{
598 os << " si (slip indicator) = " << (uint32_t)m_si << ", pm (poll me) = " << (uint32_t)m_pm
599 << ", pbr (piggyback request) = " << m_pbr;
600}
601
604{
605 return 1 + 1 + 2;
606}
607
608void
610{
611 Buffer::Iterator i = start;
612 i.WriteU8(m_si);
613 i.WriteU8(m_pm);
614 i.WriteU16(m_pbr);
615}
616
619{
620 Buffer::Iterator i = start;
621 m_si = i.ReadU8();
622 m_pm = i.ReadU8();
623 m_pbr = i.ReadU16();
624
625 return i.GetDistanceFrom(start);
626}
627
628// ----------------------------------------------------------------------------------------------------------
629
631
633 : m_fc(0),
634 m_fsn(0)
635{
636}
637
641
642void
644{
645 m_fc = fc;
646}
647
648void
650{
651 m_fsn = fsn;
652}
653
654uint8_t
656{
657 return m_fc;
658}
659
660uint8_t
662{
663 return m_fsn;
664}
665
666std::string
668{
669 return "Fragmentation Subheader";
670}
671
672TypeId
674{
675 static TypeId tid = TypeId("ns3::FragmentationSubheader")
676 .SetParent<Header>()
677 .SetGroupName("Wimax")
678 .AddConstructor<FragmentationSubheader>();
679 return tid;
680}
681
682TypeId
687
688void
689FragmentationSubheader::Print(std::ostream& os) const
690{
691 os << " fc (fragment control) = " << (uint32_t)m_fc
692 << ", fsn (fragmentation sequence number) = " << (uint32_t)m_fsn << "\n";
693}
694
697{
698 return 2;
699}
700
701void
708
711{
712 Buffer::Iterator i = start;
713 m_fc = i.ReadU8();
714 m_fsn = i.ReadU8();
715
716 return i.GetDistanceFrom(start);
717}
718
719} // 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.
uint8_t GetHt() const
Get HT field.
uint32_t GetSerializedSize() const override
void SetBr(uint32_t br)
Set BR field.
uint32_t GetBr() const
Get BR field.
void SetEc(uint8_t ec)
Set EC field.
void SetType(uint8_t type)
Set type field.
uint8_t GetHcs() const
Get HCS field.
bool check_hcs() const
Check HCS.
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.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
uint8_t GetEc() const
Get EC field.
void SetHcs(uint8_t hcs)
Set HCS field.
Cid GetCid() const
Get CID field.
void SetHt(uint8_t ht)
Set HT field.
void SetCid(Cid cid)
Set CID field.
uint32_t m_br
Bandwidth Request.
void Serialize(Buffer::Iterator start) const override
void Print(std::ostream &os) const override
std::string GetName() const
Get name field.
uint8_t GetType() const
Get type field.
Cid m_cid
Connection identifier.
uint32_t Deserialize(Buffer::Iterator start) override
static TypeId GetTypeId()
Get the type ID.
iterator in a Buffer instance
Definition buffer.h:89
void WriteU8(uint8_t data)
Definition buffer.h:870
void WriteU16(uint16_t data)
Definition buffer.cc:848
uint32_t GetDistanceFrom(const Iterator &o) const
Definition buffer.cc:769
uint16_t ReadU16()
Definition buffer.h:1024
Cid class.
Definition cid.h:26
uint16_t GetIdentifier() const
Definition cid.cc:34
This class implements the fragmentation sub-header as described by IEEE Standard for Local and metrop...
uint8_t m_fsn
Fragment Sequence Number.
void Print(std::ostream &os) const override
std::string GetName() const
Get name field.
uint32_t GetSerializedSize() const override
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
uint8_t GetFsn() const
Get FSN field.
void SetFsn(uint8_t fsn)
Set FSN field.
uint8_t GetFc() const
Get FC field.
void SetFc(uint8_t fc)
Set FC field.
static TypeId GetTypeId()
Get the type ID.
void Serialize(Buffer::Iterator start) const override
uint8_t m_fc
Fragment Control.
uint32_t Deserialize(Buffer::Iterator start) override
This class implements the Generic mac Header as described by IEEE Standard for Local and metropolitan...
uint8_t GetEks() const
Get EKS field.
uint8_t GetType() const
Get type field.
void SetHcs(uint8_t hcs)
Set HCS field.
uint8_t m_hcs
Header Check Sequence.
void SetEc(uint8_t ec)
Set EC field.
bool check_hcs() const
Check HCS.
uint8_t GetCi() const
Get CI field.
uint8_t m_ht
Header type.
uint8_t GetHt() const
Get HT field.
uint32_t Deserialize(Buffer::Iterator start) override
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
void SetType(uint8_t type)
Set type field.
uint32_t GetSerializedSize() const override
void SetHt(uint8_t ht)
Set HT field.
void Serialize(Buffer::Iterator start) const override
uint8_t m_ec
Encryption Control.
uint8_t GetHcs() const
Get HCS field.
uint8_t GetEc() const
Get EC field.
void SetEks(uint8_t eks)
Set EKS field.
uint8_t m_ci
CRC Indicator.
std::string GetName() const
Get name field.
void SetLen(uint16_t len)
Set length field.
static TypeId GetTypeId()
Get the type ID.
uint16_t GetLen() const
Get length 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
uint8_t m_eks
Encryption Key Sequence.
void Print(std::ostream &os) const override
Cid GetCid() const
Get CID field.
This class implements the grant management sub-header as described by IEEE Standard for Local and met...
std::string GetName() const
Get name field.
uint8_t GetPm() const
Get PM field.
uint8_t GetSi() const
Get SI field.
uint16_t m_pbr
PiggyBack Request.
void Serialize(Buffer::Iterator start) const override
void SetSi(uint8_t si)
Set SI field.
void SetPm(uint8_t pm)
Set PM field.
uint16_t GetPbr() const
Get PBR field.
uint32_t GetSerializedSize() const override
uint32_t Deserialize(Buffer::Iterator start) override
uint8_t m_si
Slip Indicator.
void Print(std::ostream &os) const override
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
void SetPbr(uint16_t pbr)
Set PRR field.
static TypeId GetTypeId()
Get the type ID.
uint8_t m_pm
Poll-Me bit (byte in this case)
Protocol header serialization and deserialization.
Definition header.h:33
This class Represents the HT (Header Type) field of generic MAC and bandwidth request headers.
void Serialize(Buffer::Iterator start) const override
void SetType(uint8_t type)
Set type field.
uint8_t m_type
MAC header type.
uint32_t GetSerializedSize() const override
uint8_t GetType() const
Get type field.
void Print(std::ostream &os) const override
std::string GetName() const
Get name field.
static TypeId GetTypeId()
Get the type ID.
uint32_t Deserialize(Buffer::Iterator start) override
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
MacHeaderType()
Constructor.
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
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:40