A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
dot11s-mac-header.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 IITP RAS
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Kirill Andreev <andreev@iitp.ru>
18 */
19
20#include "dot11s-mac-header.h"
21
22#include "ns3/address-utils.h"
23#include "ns3/assert.h"
24#include "ns3/packet.h"
25
26namespace ns3
27{
28namespace dot11s
29{
30/***********************************************************
31 * Here Mesh Mac Header functionality is defined.
32 ***********************************************************/
33TypeId
35{
36 static TypeId tid = TypeId("ns3::dot11s::MeshHeader")
38 .SetGroupName("Mesh")
39 .AddConstructor<MeshHeader>();
40 return tid;
41}
42
44 : m_meshFlags(0),
45 m_meshTtl(0),
46 m_meshSeqno(0),
47 m_addr4(Mac48Address()),
48 m_addr5(Mac48Address()),
49 m_addr6(Mac48Address())
50{
51}
52
54{
55}
56
59{
60 return GetTypeId();
61}
62
63void
65{
66 m_addr4 = address;
67}
68
69void
71{
72 m_addr5 = address;
73}
74
75void
77{
78 m_addr6 = address;
79}
80
83{
84 return m_addr4;
85}
86
89{
90 return m_addr5;
91}
92
95{
96 return m_addr6;
97}
98
99void
101{
102 m_meshSeqno = seqno;
103}
104
107{
108 return m_meshSeqno;
109}
110
111void
113{
114 m_meshTtl = TTL;
115}
116
117uint8_t
119{
120 return m_meshTtl;
121}
122
123void
125{
126 NS_ASSERT(value <= 3);
127 m_meshFlags |= 0x03 & value;
128}
129
130uint8_t
132{
133 return (0x03 & m_meshFlags);
134}
135
138{
139 return 6 + GetAddressExt() * 6;
140}
141
142void
144{
145 Buffer::Iterator i = start;
149 uint8_t addresses_to_add = GetAddressExt();
150 // Writing Address extensions:
151 if ((addresses_to_add == 1) || (addresses_to_add == 3))
152 {
153 WriteTo(i, m_addr4);
154 }
155 if (addresses_to_add > 1)
156 {
157 WriteTo(i, m_addr5);
158 }
159 if (addresses_to_add > 1)
160 {
161 WriteTo(i, m_addr6);
162 }
163}
164
167{
168 Buffer::Iterator i = start;
169 uint8_t addresses_to_read = 0;
170 m_meshFlags = i.ReadU8();
171 m_meshTtl = i.ReadU8();
173 addresses_to_read = m_meshFlags & 0x03;
174 if ((addresses_to_read == 1) || (addresses_to_read == 3))
175 {
176 ReadFrom(i, m_addr4);
177 }
178 if (addresses_to_read > 1)
179 {
180 ReadFrom(i, m_addr5);
181 }
182 if (addresses_to_read > 1)
183 {
184 ReadFrom(i, m_addr6);
185 }
186 return i.GetDistanceFrom(start);
187}
188
189void
190MeshHeader::Print(std::ostream& os) const
191{
192 os << "flags=" << (uint16_t)m_meshFlags << ", ttl=" << (uint16_t)m_meshTtl
193 << ", seqno=" << m_meshSeqno << ", addr4=" << m_addr4 << ", addr5=" << m_addr5
194 << ", addr6=" << m_addr6;
195}
196
197bool
199{
200 return ((a.m_meshFlags == b.m_meshFlags) && (a.m_meshTtl == b.m_meshTtl) &&
201 (a.m_meshSeqno == b.m_meshSeqno) && (a.m_addr4 == b.m_addr4) &&
202 (a.m_addr5 == b.m_addr5) && (a.m_addr6 == b.m_addr6));
203}
204} // namespace dot11s
205} // namespace ns3
iterator in a Buffer instance
Definition: buffer.h:100
uint8_t ReadU8()
Definition: buffer.h:1027
void WriteU8(uint8_t data)
Definition: buffer.h:881
void WriteHtolsbU32(uint32_t data)
Definition: buffer.cc:910
uint32_t GetDistanceFrom(const Iterator &o) const
Definition: buffer.cc:780
uint32_t ReadLsbtohU32()
Definition: buffer.cc:1076
Protocol header serialization and deserialization.
Definition: header.h:44
an EUI-48 address
Definition: mac48-address.h:46
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
Mesh Control field, see Section 8.2.4.7.3 IEEE 802.11-2012.
void SetAddr6(Mac48Address address)
Set extended address 6.
void SetMeshSeqno(uint32_t seqno)
Set four-byte mesh sequence number.
void Serialize(Buffer::Iterator start) const override
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Mac48Address m_addr6
MAC address 6.
uint32_t GetMeshSeqno() const
Get the four-byte mesh sequence number.
void SetMeshTtl(uint8_t TTL)
Set mesh TTL subfield corresponding to the remaining number of hops the MSDU/MMPDU is forwarded.
Mac48Address m_addr4
MAC address 4.
uint32_t Deserialize(Buffer::Iterator start) override
static TypeId GetTypeId()
Get the type ID.
void Print(std::ostream &os) const override
Mac48Address GetAddr5() const
Get extended address 5.
Mac48Address GetAddr4() const
Get extended address 4.
uint8_t m_meshFlags
mesh flags
uint32_t GetSerializedSize() const override
Mac48Address GetAddr6() const
Get extended address 6.
uint8_t GetAddressExt() const
Get Address Extension Mode.
void SetAddressExt(uint8_t num_of_addresses)
Set Address Extension Mode.
void SetAddr5(Mac48Address address)
Set extended address 5.
void SetAddr4(Mac48Address address)
Set extended address 4.
uint8_t GetMeshTtl() const
Get mesh TTL function subfield value.
Mac48Address m_addr5
MAC address 5.
uint32_t m_meshSeqno
mesh sequence no
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
bool operator==(const MeshHeader &a, const MeshHeader &b)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void WriteTo(Buffer::Iterator &i, Ipv4Address ad)
Write an Ipv4Address to a Buffer.
void ReadFrom(Buffer::Iterator &i, Ipv4Address &ad)
Read an Ipv4Address from a Buffer.