A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wimax-mac-to-mac-header.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010 INRIA, UDcast
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
7 *
8 */
10
11#include "ns3/address-utils.h"
12#include "ns3/log.h"
13#include "ns3/uinteger.h"
14
15namespace ns3
16{
17
18NS_OBJECT_ENSURE_REGISTERED(WimaxMacToMacHeader);
19
24
29
33
36{
37 static TypeId tid = TypeId("ns3::WimaxMacToMacHeader")
39 .SetGroupName("Wimax")
40 .AddConstructor<WimaxMacToMacHeader>();
41 return tid;
42}
43
49
50uint8_t
52{
53 uint8_t sizeOfLen = 1;
54
55 if (m_len > 127)
56 {
57 sizeOfLen = 2;
58 uint64_t testValue = 0xFF;
59 while (m_len > testValue)
60 {
61 sizeOfLen++;
62 testValue *= 0xFF;
63 }
64 }
65 return sizeOfLen;
66}
67
70{
71 uint8_t sizeOfLen = GetSizeOfLen();
72 if (sizeOfLen == 1)
73 {
74 return 20;
75 }
76 else
77 {
78 return 20 + sizeOfLen - 1;
79 }
80 // return 19+sizeOfLen;
81}
82
83void
85{
86 // The following header encoding was reverse-engineered by looking
87 // at existing live pcap traces which could be opened with wireshark
88 // i.e., we have no idea where this is coming from.
89 //
90 // 6 zeros for mac destination
91 // 6 zeros for mac source
92 // 2 bytes for length/type: 0x08f0
93 // 2 bytes for sequence number: 0x0001
94 // 2 bytes for number of tlvs: 0x0001
95 // 1 byte for type of first tlv: 0x09
96 // 1 byte to indicate the length of the length field of the tlv : 0x80 | 0x04
97 // n bytes to indicate the size of the packet (network order)
98 // n bytes for the packet data
99
100 uint8_t zero = 0;
101
102 for (int j = 0; j < 12; j++)
103 {
104 i.WriteU8(zero);
105 }
106 i.WriteU16(0xf008); // eth length/type
107 i.WriteU16(0x0100); // sequence number
108 i.WriteU16(0x0100); // number of tlvs
109 i.WriteU8(0x09); // type of first tlv
110 uint8_t lenSize = GetSizeOfLen();
111 if (lenSize == 1)
112 {
113 i.WriteU8(m_len);
114 }
115 else
116 {
117 i.WriteU8((lenSize - 1) | 0x80);
118 for (int j = 0; j < lenSize - 1; j++)
119 {
120 i.WriteU8((uint8_t)(m_len >> ((lenSize - 1 - 1 - j) * 8)));
121 }
122 }
123}
124
127{
128 // not needed here
129 return 20;
130}
131
132void
133WimaxMacToMacHeader::Print(std::ostream& os) const
134{
135}
136}; // namespace ns3
iterator in a Buffer instance
Definition buffer.h:89
void WriteU8(uint8_t data)
Definition buffer.h:870
void WriteU16(uint16_t data)
Definition buffer.cc:848
Protocol header serialization and deserialization.
Definition header.h:33
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
this class implements the mac to mac header needed to dump a wimax pcap file The header format was re...
static TypeId GetTypeId()
Get the type ID.
uint8_t GetSizeOfLen() const
Get size of length field.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
void Serialize(Buffer::Iterator start) const override
uint32_t Deserialize(Buffer::Iterator start) override
void Print(std::ostream &os) const override
uint32_t GetSerializedSize() const override
static double zero
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Every class exported by the ns3 library is enclosed in the ns3 namespace.