A Discrete-Event Network Simulator
API
 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  */
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 
31  : m_len (0)
32 {
33 }
34 
36  : m_len (len)
37 {
38 }
39 
41 {
42 }
43 
44 
45 
46 TypeId
48 {
49  static TypeId tid =
50  TypeId ("ns3::WimaxMacToMacHeader").SetParent<Header> ().AddConstructor<WimaxMacToMacHeader> ();
51  return tid;
52 }
53 
54 TypeId
56 {
57  return GetTypeId ();
58 }
59 
60 uint8_t
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
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
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
138 {
139  // not needed here
140  return 20;
141 }
142 
143 void
144 WimaxMacToMacHeader::Print (std::ostream &os) const
145 {
146 }
147 };
Protocol header serialization and deserialization.
Definition: header.h:42
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
static double zero
iterator in a Buffer instance
Definition: buffer.h:98
void WriteU16(uint16_t data)
Definition: buffer.cc:895
uint32_t GetSerializedSize(void) const
uint8_t GetSizeOfLen(void) const
void WriteU8(uint8_t data)
Definition: buffer.h:690
void Serialize(Buffer::Iterator start) const
virtual void Print(std::ostream &os) const
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611
virtual TypeId GetInstanceTypeId(void) const
uint32_t Deserialize(Buffer::Iterator start)