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
30
WimaxMacToMacHeader::WimaxMacToMacHeader
(
void
)
31
: m_len (0)
32
{
33
}
34
35
WimaxMacToMacHeader::WimaxMacToMacHeader
(uint32_t len)
36
: m_len (len)
37
{
38
}
39
40
WimaxMacToMacHeader::~WimaxMacToMacHeader
(
void
)
41
{
42
}
43
44
45
46
TypeId
47
WimaxMacToMacHeader::GetTypeId
(
void
)
48
{
49
static
TypeId
tid =
50
TypeId
(
"ns3::WimaxMacToMacHeader"
).
SetParent
<
Header
> ().AddConstructor<WimaxMacToMacHeader> ();
51
return
tid;
52
}
53
54
TypeId
55
WimaxMacToMacHeader::GetInstanceTypeId
(
void
)
const
56
{
57
return
GetTypeId
();
58
}
59
60
uint8_t
61
WimaxMacToMacHeader::GetSizeOfLen
(
void
)
const
62
{
63
uint8_t sizeOfLen = 1;
64
65
if
(
m_len
> 127)
66
{
67
sizeOfLen = 2;
68
uint64_t testValue = 0xFF;
69
while
(
m_len
> testValue)
70
{
71
sizeOfLen++;
72
testValue *= 0xFF;
73
}
74
}
75
return
sizeOfLen;
76
}
77
78
uint32_t
79
WimaxMacToMacHeader::GetSerializedSize
(
void
)
const
80
{
81
uint8_t sizeOfLen =
GetSizeOfLen
();
82
if
(sizeOfLen==1)
83
{
84
return
20;
85
}
86
else
87
{
88
return
20 + sizeOfLen -1;
89
}
90
//return 19+sizeOfLen;
91
}
92
93
void
94
WimaxMacToMacHeader::Serialize
(
Buffer::Iterator
i)
const
95
{
96
// The following header encoding was reverse-engineered by looking
97
// at existing live pcap traces which could be opened with wireshark
98
// i.e., we have no idea where this is coming from.
99
//
100
// 6 zeros for mac destination
101
// 6 zeros for mac source
102
// 2 bytes for length/type: 0x08f0
103
// 2 bytes for sequence number: 0x0001
104
// 2 bytes for number of tlvs: 0x0001
105
// 1 byte for type of first tlv: 0x09
106
// 1 byte to indicate the length of the length field of the tlv : 0x80 | 0x04
107
// n bytes to indicate the size of the packet (network order)
108
// n bytes for the packet data
109
110
uint8_t
zero
= 0;
111
112
113
for
(
int
j = 0; j < 12; j++)
114
{
115
i.
WriteU8
(zero);
116
}
117
i.
WriteU16
(0xf008);
// eth length/type
118
i.
WriteU16
(0x0100);
// sequence number
119
i.
WriteU16
(0x0100);
// number of tlvs
120
i.
WriteU8
(0x09);
// type of first tlv
121
uint8_t lenSize =
GetSizeOfLen
();
122
if
(lenSize == 1)
123
{
124
i.
WriteU8
(
m_len
);
125
}
126
else
127
{
128
i.
WriteU8
((lenSize-1) | 0x80);
129
for
(
int
j = 0; j < lenSize - 1; j++)
130
{
131
i.
WriteU8
((uint8_t)(
m_len
>> ((lenSize - 1 - 1 - j) * 8)));
132
}
133
}
134
}
135
136
uint32_t
137
WimaxMacToMacHeader::Deserialize
(
Buffer::Iterator
start
)
138
{
139
// not needed here
140
return
20;
141
}
142
143
void
144
WimaxMacToMacHeader::Print
(std::ostream &os)
const
145
{
146
}
147
};
ns3::Header
Protocol header serialization and deserialization.
Definition:
header.h:42
ns3::WimaxMacToMacHeader::WimaxMacToMacHeader
WimaxMacToMacHeader()
Definition:
wimax-mac-to-mac-header.cc:30
ns3::NS_OBJECT_ENSURE_REGISTERED
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
visualizer.core.start
def start
Definition:
core.py:1482
zero
static double zero
Definition:
data-calculator.cc:30
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition:
buffer.h:98
ns3::Buffer::Iterator::WriteU16
void WriteU16(uint16_t data)
Definition:
buffer.cc:895
ns3::WimaxMacToMacHeader::GetTypeId
static TypeId GetTypeId(void)
Definition:
wimax-mac-to-mac-header.cc:47
ns3::WimaxMacToMacHeader::m_len
uint32_t m_len
Definition:
wimax-mac-to-mac-header.h:50
ns3::WimaxMacToMacHeader::GetSerializedSize
uint32_t GetSerializedSize(void) const
Definition:
wimax-mac-to-mac-header.cc:79
wimax-mac-to-mac-header.h
ns3::WimaxMacToMacHeader::GetSizeOfLen
uint8_t GetSizeOfLen(void) const
Definition:
wimax-mac-to-mac-header.cc:61
ns3::WimaxMacToMacHeader::~WimaxMacToMacHeader
~WimaxMacToMacHeader()
Definition:
wimax-mac-to-mac-header.cc:40
ns3::Buffer::Iterator::WriteU8
void WriteU8(uint8_t data)
Definition:
buffer.h:690
ns3::WimaxMacToMacHeader::Serialize
void Serialize(Buffer::Iterator start) const
Definition:
wimax-mac-to-mac-header.cc:94
ns3::WimaxMacToMacHeader::Print
virtual void Print(std::ostream &os) const
Definition:
wimax-mac-to-mac-header.cc:144
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:49
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Definition:
type-id.cc:611
ns3::WimaxMacToMacHeader::GetInstanceTypeId
virtual TypeId GetInstanceTypeId(void) const
Definition:
wimax-mac-to-mac-header.cc:55
ns3::WimaxMacToMacHeader::Deserialize
uint32_t Deserialize(Buffer::Iterator start)
Definition:
wimax-mac-to-mac-header.cc:137
src
wimax
model
wimax-mac-to-mac-header.cc
Generated on Sat Apr 19 2014 14:07:13 for ns-3 by
1.8.6