A Discrete-Event Network Simulator
API
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 */
22#include "ns3/address-utils.h"
23#include "ns3/uinteger.h"
24#include "ns3/log.h"
25namespace ns3 {
26
27NS_OBJECT_ENSURE_REGISTERED (WimaxMacToMacHeader);
28
30 : m_len (0)
31{
32}
33
35 : m_len (len)
36{
37}
38
40{
41}
42
43
44
47{
48 static TypeId tid =
49 TypeId ("ns3::WimaxMacToMacHeader")
50 .SetParent<Header> ()
51 .SetGroupName("Wimax")
52 .AddConstructor<WimaxMacToMacHeader> ()
53 ;
54 return tid;
55}
56
59{
60 return GetTypeId ();
61}
62
63uint8_t
65{
66 uint8_t sizeOfLen = 1;
67
68 if (m_len > 127)
69 {
70 sizeOfLen = 2;
71 uint64_t testValue = 0xFF;
72 while (m_len > testValue)
73 {
74 sizeOfLen++;
75 testValue *= 0xFF;
76 }
77 }
78 return sizeOfLen;
79}
80
83{
84 uint8_t sizeOfLen = GetSizeOfLen ();
85 if (sizeOfLen==1)
86 {
87 return 20;
88 }
89 else
90 {
91 return 20 + sizeOfLen -1;
92 }
93 //return 19+sizeOfLen;
94}
95
96void
98{
99 // The following header encoding was reverse-engineered by looking
100 // at existing live pcap traces which could be opened with wireshark
101 // i.e., we have no idea where this is coming from.
102 //
103 // 6 zeros for mac destination
104 // 6 zeros for mac source
105 // 2 bytes for length/type: 0x08f0
106 // 2 bytes for sequence number: 0x0001
107 // 2 bytes for number of tlvs: 0x0001
108 // 1 byte for type of first tlv: 0x09
109 // 1 byte to indicate the length of the length field of the tlv : 0x80 | 0x04
110 // n bytes to indicate the size of the packet (network order)
111 // n bytes for the packet data
112
113 uint8_t zero = 0;
114
115
116 for (int j = 0; j < 12; j++)
117 {
118 i.WriteU8 (zero);
119 }
120 i.WriteU16 (0xf008); // eth length/type
121 i.WriteU16 (0x0100); // sequence number
122 i.WriteU16 (0x0100); // number of tlvs
123 i.WriteU8 (0x09); // type of first tlv
124 uint8_t lenSize = GetSizeOfLen ();
125 if (lenSize == 1)
126 {
127 i.WriteU8 (m_len);
128 }
129 else
130 {
131 i.WriteU8 ((lenSize-1) | 0x80);
132 for (int j = 0; j < lenSize - 1; j++)
133 {
134 i.WriteU8 ((uint8_t)(m_len >> ((lenSize - 1 - 1 - j) * 8)));
135 }
136 }
137}
138
141{
142 // not needed here
143 return 20;
144}
145
146void
147WimaxMacToMacHeader::Print (std::ostream &os) const
148{
149}
150};
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
Protocol header serialization and deserialization.
Definition: header.h:43
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
this class implements the mac to mac header needed to dump a wimax pcap file The header format was re...
uint32_t Deserialize(Buffer::Iterator start)
uint32_t GetSerializedSize(void) const
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
virtual void Print(std::ostream &os) const
uint8_t GetSizeOfLen(void) const
Get size of length field.
void Serialize(Buffer::Iterator start) const
static TypeId GetTypeId(void)
Get the type ID.
static double zero
#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.
def start()
Definition: core.py:1853