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 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Jahanzeb Farooq <jahanzeb.farooq@sophia.inria.fr>
18 * Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
19 * <amine.ismail@udcast.com>
20 */
21
22#include "wimax-mac-header.h"
23
24#include "crc8.h"
25
26namespace ns3
27{
28
29NS_OBJECT_ENSURE_REGISTERED(MacHeaderType);
30
32 : m_type(0)
33{
34}
35
37 : m_type(type)
38{
39}
40
42{
43}
44
45void
47{
48 m_type = type;
49}
50
51uint8_t
53{
54 return m_type;
55}
56
57std::string
59{
60 return "MAC Header Type";
61}
62
65{
66 static TypeId tid = TypeId("ns3::MacHeaderType")
68 .SetGroupName("Wimax")
69 .AddConstructor<MacHeaderType>();
70 return tid;
71}
72
75{
76 return GetTypeId();
77}
78
79void
80MacHeaderType::Print(std::ostream& os) const
81{
82 os << " header type = " << (uint32_t)m_type;
83}
84
87{
88 return 0;
89}
90
91void
93{
94}
95
98{
99 return 0;
100}
101
102// ----------------------------------------------------------------------------------------------------------
103
105
107 : m_ht(0),
108 m_ec(0),
109 m_type(0),
110 m_ci(0),
111 m_eks(0),
112 m_len(0),
113 m_cid(Cid())
114{
115 m_esf = 0;
116 m_hcs = 0;
117 m_rsv1 = 0;
118 c_hcs = 0;
119}
120
122{
123}
124
125void
127{
128 m_ht = ht;
129}
130
131void
133{
134 m_ec = ec;
135}
136
137void
139{
140 m_type = type;
141}
142
143void
145{
146 m_ci = ci;
147}
148
149void
151{
152 m_eks = eks;
153}
154
155void
157{
158 m_len = len;
159}
160
161void
163{
164 m_cid = cid;
165}
166
167void
169{
170 m_hcs = hcs;
171}
172
173uint8_t
175{
176 return m_ht;
177}
178
179uint8_t
181{
182 return m_ec;
183}
184
185uint8_t
187{
188 return m_type;
189}
190
191uint8_t
193{
194 return m_ci;
195}
196
197uint8_t
199{
200 return m_eks;
201}
202
203uint16_t
205{
206 return m_len;
207}
208
209Cid
211{
212 return m_cid;
213}
214
215uint8_t
217{
218 return m_hcs;
219}
220
221std::string
223{
224 return "Generic Mac Header";
225}
226
227TypeId
229{
230 static TypeId tid = TypeId("ns3::GenericMacHeader")
231 .SetParent<Header>()
232 .SetGroupName("Wimax")
233 .AddConstructor<GenericMacHeader>();
234 return tid;
235}
236
237TypeId
239{
240 return GetTypeId();
241}
242
243void
244GenericMacHeader::Print(std::ostream& os) const
245{
246 os << " ec (encryption control) = " << (uint32_t)m_ec << ", type = " << (uint32_t)m_type
247 << ", ci (crc indicator) = " << (uint32_t)m_ci
248 << ", eks (encryption key sequence) = " << (uint32_t)m_eks << ", len (length) = " << m_len
249 << ", cid = " << m_cid << ", hcs (header check sequence) = " << (uint32_t)m_hcs;
250}
251
254{
255 return 6;
256}
257
258void
260{
261 /*
262 * AI:Serialize function according to the
263 * IEEE 8002.16e.
264 * Please send bug and comments to
265 * amine.ismail@udcast.com
266 * amine.ismail@sophia.inria.fr
267 */
268
269 Buffer::Iterator i = start;
270
271 uint8_t headerBuffer[6];
272 memset(headerBuffer, 0, 6);
273
274 headerBuffer[0] = ((m_ht << 7) & 0x80) | ((m_ec << 6) & 0x40) | (m_type & 0x3F);
275 headerBuffer[1] = ((m_esf << 7) & 0x80) | ((m_ci << 6) & 0x40) | ((m_eks << 4) & 0x30) |
276 ((m_rsv1 << 3) & 0x08) | (((uint8_t)(m_len >> 8)) & 0x07);
277 headerBuffer[2] = (uint8_t)(m_len);
278 headerBuffer[3] = (uint8_t)(m_cid.GetIdentifier() >> 8);
279 headerBuffer[4] = (uint8_t)(m_cid.GetIdentifier());
280 uint8_t crc = CRC8Calculate(headerBuffer, 5);
281 headerBuffer[5] = crc;
282 for (int j = 0; j < 6; j++)
283 {
284 i.WriteU8(headerBuffer[j]);
285 }
286}
287
290{
291 /*
292 * AI:Deserialize function according to the
293 * IEEE 8002.16e.
294 * Please send bug and comments to
295 * amine.ismail@udcast.com
296 * amine.ismail@sophia.inria.fr
297 */
298
299 Buffer::Iterator i = start;
300
301 uint8_t headerBuffer[6];
302 for (int j = 0; j < 6; j++)
303 {
304 headerBuffer[j] = i.ReadU8();
305 }
306 m_ht = (headerBuffer[0] >> 7) & 0x01;
307 m_ec = (headerBuffer[0] >> 6) & 0x01;
308 m_type = (headerBuffer[0]) & 0x3F;
309 m_esf = (headerBuffer[1] >> 7) & 0x01;
310 m_ci = (headerBuffer[1] >> 6) & 0x01;
311 m_eks = (headerBuffer[1] >> 4) & 0x03;
312 m_rsv1 = (headerBuffer[1] >> 3) & 0x01;
313 uint16_t lenmsb = (headerBuffer[1] & 0x07);
314 uint16_t lenlsb = headerBuffer[2];
315 m_len = ((lenmsb << 8) & 0x0700) | (lenlsb & 0x00FF);
316 uint16_t cidmsb = headerBuffer[3];
317 uint16_t cidlsb = headerBuffer[4];
318 uint16_t cid = ((cidmsb << 8) & 0xFF00) | (cidlsb & 0x00FF);
319 m_cid = Cid(cid);
320 m_hcs = headerBuffer[5];
321 c_hcs = CRC8Calculate(headerBuffer, 5);
322 return i.GetDistanceFrom(start);
323}
324
325bool
327{
328 return (m_hcs == c_hcs);
329}
330
331// ----------------------------------------------------------------------------------------------------------
332
334
336 : m_ht(1),
337 m_ec(0),
338 m_type(0),
339 m_br(0),
340 m_cid(Cid()),
341 m_hcs(0)
342{
343}
344
346{
347}
348
349void
351{
352 m_ht = ht;
353}
354
355void
357{
358 m_ec = ec;
359}
360
361void
363{
364 m_type = type;
365}
366
367void
369{
370 m_br = br;
371}
372
373void
375{
376 m_cid = cid;
377}
378
379void
381{
382 m_hcs = hcs;
383}
384
385uint8_t
387{
388 return m_ht;
389}
390
391uint8_t
393{
394 return m_ec;
395}
396
397uint8_t
399{
400 return m_type;
401}
402
405{
406 return m_br;
407}
408
409Cid
411{
412 return m_cid;
413}
414
415uint8_t
417{
418 return m_hcs;
419}
420
421std::string
423{
424 return "Bandwidth Request Header";
425}
426
427TypeId
429{
430 static TypeId tid = TypeId("ns3::BandwidthRequestHeader")
431 .SetParent<Header>()
432 .SetGroupName("Wimax")
433 .AddConstructor<BandwidthRequestHeader>();
434 return tid;
435}
436
437TypeId
439{
440 return GetTypeId();
441}
442
443void
444BandwidthRequestHeader::Print(std::ostream& os) const
445{
446 os << " ec (encryption control) = " << (uint32_t)m_ec << ", type = " << (uint32_t)m_type
447 << ", br (bandwidth request) = " << m_br << ", cid = ";
449 os << ", hcs (header check sequence) = " << (uint32_t)m_hcs;
450}
451
454{
455 /*
456 * The size of the BandwidthRequest mac header is always 6 bytes
457 */
458 return 6;
459}
460
461void
463{
464 /*
465 * AI:Serialize function according to the
466 * IEEE 8002.16e.
467 * please send bug and comments to
468 * amine.ismail@udcast.com
469 * amine.ismail@sophia.inria.fr
470 */
471
472 Buffer::Iterator i = start;
473 uint8_t headerBuffer[6];
474 uint8_t br_msb1 = (((uint32_t)m_br) >> 16) & 0x00000007;
475 uint8_t br_msb2 = (((uint32_t)m_br) >> 8) & 0x000000FF;
476 uint8_t br_lsb = m_br & 0x000000FF;
477 headerBuffer[0] =
478 ((m_ht << 7) & 0x80) | ((m_ec << 6) & 0x40) | ((m_type << 3) & 0x38) | br_msb1;
479 headerBuffer[1] = br_msb2;
480 headerBuffer[2] = br_lsb;
481 headerBuffer[3] = (uint8_t)((m_cid.GetIdentifier() >> 8) & 0x00FF);
482 headerBuffer[4] = (uint8_t)(m_cid.GetIdentifier() & 0x00FF);
483 headerBuffer[5] = CRC8Calculate(headerBuffer, 5);
484
485 for (int j = 0; j < 6; j++)
486 {
487 i.WriteU8(headerBuffer[j]);
488 }
489}
490
493{
494 /*
495 * AI:Deserialize function according to the
496 * IEEE 8002.16e.
497 * Please send bug and comments to
498 * amine.ismail@udcast.com
499 * amine.ismail@sophia.inria.fr
500 */
501
502 Buffer::Iterator i = start;
503
504 uint8_t headerBuffer[6];
505 for (int j = 0; j < 6; j++)
506 {
507 headerBuffer[j] = i.ReadU8();
508 }
509
510 m_ht = (headerBuffer[0] >> 7) & 0x01;
511 m_ec = (headerBuffer[0] >> 6) & 0x01;
512 m_type = (headerBuffer[0] >> 3) & 0x07;
513 uint32_t br_msb1 = headerBuffer[0] & 0x00000007;
514 uint32_t br_msb2 = headerBuffer[1] & 0x000000FF;
515 uint32_t br_lsb = headerBuffer[2] & 0x000000FF;
516 m_br = ((uint32_t)br_msb1 << 14) | ((uint32_t)br_msb2 << 8) | br_lsb;
517 uint16_t cidmsb = headerBuffer[3];
518 uint16_t cidlsb = headerBuffer[4];
519 uint16_t cid = ((cidmsb << 8) & 0xFF00) | (cidlsb & 0x00FF);
520 m_cid = Cid(cid);
521 m_hcs = headerBuffer[5];
522 c_hcs = CRC8Calculate(headerBuffer, 5);
523
524 return i.GetDistanceFrom(start);
525}
526
527bool
529{
530 return (m_hcs == c_hcs);
531}
532
533// ----------------------------------------------------------------------------------------------------------
534
536
538 : m_si(0),
539 m_pm(0),
540 m_pbr(0)
541{
542}
543
545{
546}
547
548void
550{
551 m_si = si;
552}
553
554void
556{
557 m_pm = pm;
558}
559
560void
562{
563 m_pbr = pbr;
564}
565
566uint8_t
568{
569 return m_si;
570}
571
572uint8_t
574{
575 return m_pm;
576}
577
578uint16_t
580{
581 return m_pbr;
582}
583
584std::string
586{
587 return "Grant Management Subheader";
588}
589
590TypeId
592{
593 static TypeId tid = TypeId("ns3::GrantManagementSubheader")
594 .SetParent<Header>()
595 .SetGroupName("Wimax")
596 .AddConstructor<GrantManagementSubheader>();
597 return tid;
598}
599
600TypeId
602{
603 return GetTypeId();
604}
605
606void
607GrantManagementSubheader::Print(std::ostream& os) const
608{
609 os << " si (slip indicator) = " << (uint32_t)m_si << ", pm (poll me) = " << (uint32_t)m_pm
610 << ", pbr (piggyback request) = " << m_pbr;
611}
612
615{
616 return 1 + 1 + 2;
617}
618
619void
621{
622 Buffer::Iterator i = start;
623 i.WriteU8(m_si);
624 i.WriteU8(m_pm);
625 i.WriteU16(m_pbr);
626}
627
630{
631 Buffer::Iterator i = start;
632 m_si = i.ReadU8();
633 m_pm = i.ReadU8();
634 m_pbr = i.ReadU16();
635
636 return i.GetDistanceFrom(start);
637}
638
639// ----------------------------------------------------------------------------------------------------------
640
642
644 : m_fc(0),
645 m_fsn(0)
646{
647}
648
650{
651}
652
653void
655{
656 m_fc = fc;
657}
658
659void
661{
662 m_fsn = fsn;
663}
664
665uint8_t
667{
668 return m_fc;
669}
670
671uint8_t
673{
674 return m_fsn;
675}
676
677std::string
679{
680 return "Fragmentation Subheader";
681}
682
683TypeId
685{
686 static TypeId tid = TypeId("ns3::FragmentationSubheader")
687 .SetParent<Header>()
688 .SetGroupName("Wimax")
689 .AddConstructor<FragmentationSubheader>();
690 return tid;
691}
692
693TypeId
695{
696 return GetTypeId();
697}
698
699void
700FragmentationSubheader::Print(std::ostream& os) const
701{
702 os << " fc (fragment control) = " << (uint32_t)m_fc
703 << ", fsn (fragmentation sequence number) = " << (uint32_t)m_fsn << "\n";
704}
705
708{
709 return 2;
710}
711
712void
714{
715 Buffer::Iterator i = start;
716 i.WriteU8(m_fc);
717 i.WriteU8(m_fsn);
718}
719
722{
723 Buffer::Iterator i = start;
724 m_fc = i.ReadU8();
725 m_fsn = i.ReadU8();
726
727 return i.GetDistanceFrom(start);
728}
729
730} // 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:100
uint8_t ReadU8()
Definition: buffer.h:1027
void WriteU8(uint8_t data)
Definition: buffer.h:881
void WriteU16(uint16_t data)
Definition: buffer.cc:865
uint32_t GetDistanceFrom(const Iterator &o) const
Definition: buffer.cc:786
uint16_t ReadU16()
Definition: buffer.h:1035
Cid class.
Definition: cid.h:37
uint16_t GetIdentifier() const
Definition: cid.cc:45
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:44
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:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:936
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
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:51