A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
wimax-mac-to-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) 2010 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
* Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
19
*
20
*/
21
#include "
wimax-mac-to-mac-header.h
"
22
#include "ns3/address-utils.h"
23
#include "ns3/uinteger.h"
24
#include "ns3/log.h"
25
namespace
ns3 {
26
27
NS_OBJECT_ENSURE_REGISTERED
(WimaxMacToMacHeader);
28
29
WimaxMacToMacHeader::WimaxMacToMacHeader
(
void
)
30
: m_len (0)
31
{
32
}
33
34
WimaxMacToMacHeader::WimaxMacToMacHeader
(uint32_t len)
35
: m_len (len)
36
{
37
}
38
39
WimaxMacToMacHeader::~WimaxMacToMacHeader
(
void
)
40
{
41
}
42
43
44
45
TypeId
46
WimaxMacToMacHeader::GetTypeId
(
void
)
47
{
48
static
TypeId
tid =
49
TypeId
(
"ns3::WimaxMacToMacHeader"
).
SetParent
<
Header
> ().AddConstructor<WimaxMacToMacHeader> ();
50
return
tid;
51
}
52
53
TypeId
54
WimaxMacToMacHeader::GetInstanceTypeId
(
void
)
const
55
{
56
return
GetTypeId
();
57
}
58
59
uint8_t
60
WimaxMacToMacHeader::GetSizeOfLen
(
void
)
const
61
{
62
uint8_t sizeOfLen = 1;
63
64
if
(
m_len
> 127)
65
{
66
sizeOfLen = 2;
67
uint64_t testValue = 0xFF;
68
while
(
m_len
> testValue)
69
{
70
sizeOfLen++;
71
testValue *= 0xFF;
72
}
73
}
74
return
sizeOfLen;
75
}
76
77
uint32_t
78
WimaxMacToMacHeader::GetSerializedSize
(
void
)
const
79
{
80
uint8_t sizeOfLen =
GetSizeOfLen
();
81
if
(sizeOfLen==1)
82
{
83
return
20;
84
}
85
else
86
{
87
return
20 + sizeOfLen -1;
88
}
89
//return 19+sizeOfLen;
90
}
91
92
void
93
WimaxMacToMacHeader::Serialize
(
Buffer::Iterator
i)
const
94
{
95
// The following header encoding was reverse-engineered by looking
96
// at existing live pcap traces which could be opened with wireshark
97
// i.e., we have no idea where this is coming from.
98
//
99
// 6 zeros for mac destination
100
// 6 zeros for mac source
101
// 2 bytes for length/type: 0x08f0
102
// 2 bytes for sequence number: 0x0001
103
// 2 bytes for number of tlvs: 0x0001
104
// 1 byte for type of first tlv: 0x09
105
// 1 byte to indicate the length of the length field of the tlv : 0x80 | 0x04
106
// n bytes to indicate the size of the packet (network order)
107
// n bytes for the packet data
108
109
uint8_t
zero
= 0;
110
111
112
for
(
int
j = 0; j < 12; j++)
113
{
114
i.
WriteU8
(zero);
115
}
116
i.
WriteU16
(0xf008);
// eth length/type
117
i.
WriteU16
(0x0100);
// sequence number
118
i.
WriteU16
(0x0100);
// number of tlvs
119
i.
WriteU8
(0x09);
// type of first tlv
120
uint8_t lenSize =
GetSizeOfLen
();
121
if
(lenSize == 1)
122
{
123
i.
WriteU8
(
m_len
);
124
}
125
else
126
{
127
i.
WriteU8
((lenSize-1) | 0x80);
128
for
(
int
j = 0; j < lenSize - 1; j++)
129
{
130
i.
WriteU8
((uint8_t)(
m_len
>> ((lenSize - 1 - 1 - j) * 8)));
131
}
132
}
133
}
134
135
uint32_t
136
WimaxMacToMacHeader::Deserialize
(
Buffer::Iterator
start
)
137
{
138
// not needed here
139
return
20;
140
}
141
142
void
143
WimaxMacToMacHeader::Print
(std::ostream &os)
const
144
{
145
}
146
};
src
wimax
model
wimax-mac-to-mac-header.cc
Generated on Tue Nov 13 2012 10:32:26 for ns-3 by
1.8.1.2