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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Kirill Andreev <andreev@iitp.ru>
7 */
8
9#include "dot11s-mac-header.h"
10
11#include "ns3/address-utils.h"
12#include "ns3/assert.h"
13#include "ns3/packet.h"
14
15namespace ns3
16{
17namespace dot11s
18{
19/***********************************************************
20 * Here Mesh Mac Header functionality is defined.
21 ***********************************************************/
22TypeId
24{
25 static TypeId tid = TypeId("ns3::dot11s::MeshHeader")
27 .SetGroupName("Mesh")
28 .AddConstructor<MeshHeader>();
29 return tid;
30}
31
33 : m_meshFlags(0),
34 m_meshTtl(0),
35 m_meshSeqno(0),
36 m_addr4(Mac48Address()),
37 m_addr5(Mac48Address()),
38 m_addr6(Mac48Address())
39{
40}
41
45
48{
49 return GetTypeId();
50}
51
52void
54{
55 m_addr4 = address;
56}
57
58void
60{
61 m_addr5 = address;
62}
63
64void
66{
67 m_addr6 = address;
68}
69
72{
73 return m_addr4;
74}
75
78{
79 return m_addr5;
80}
81
84{
85 return m_addr6;
86}
87
88void
93
96{
97 return m_meshSeqno;
98}
99
100void
102{
103 m_meshTtl = TTL;
104}
105
106uint8_t
108{
109 return m_meshTtl;
110}
111
112void
114{
115 NS_ASSERT(value <= 3);
116 m_meshFlags |= 0x03 & value;
117}
118
119uint8_t
121{
122 return (0x03 & m_meshFlags);
123}
124
127{
128 return 6 + GetAddressExt() * 6;
129}
130
131void
133{
134 Buffer::Iterator i = start;
138 uint8_t addresses_to_add = GetAddressExt();
139 // Writing Address extensions:
140 if ((addresses_to_add == 1) || (addresses_to_add == 3))
141 {
142 WriteTo(i, m_addr4);
143 }
144 if (addresses_to_add > 1)
145 {
146 WriteTo(i, m_addr5);
147 }
148 if (addresses_to_add > 1)
149 {
150 WriteTo(i, m_addr6);
151 }
152}
153
156{
157 Buffer::Iterator i = start;
158 uint8_t addresses_to_read = 0;
159 m_meshFlags = i.ReadU8();
160 m_meshTtl = i.ReadU8();
162 addresses_to_read = m_meshFlags & 0x03;
163 if ((addresses_to_read == 1) || (addresses_to_read == 3))
164 {
165 ReadFrom(i, m_addr4);
166 }
167 if (addresses_to_read > 1)
168 {
169 ReadFrom(i, m_addr5);
170 }
171 if (addresses_to_read > 1)
172 {
173 ReadFrom(i, m_addr6);
174 }
175 return i.GetDistanceFrom(start);
176}
177
178void
179MeshHeader::Print(std::ostream& os) const
180{
181 os << "flags=" << (uint16_t)m_meshFlags << ", ttl=" << (uint16_t)m_meshTtl
182 << ", seqno=" << m_meshSeqno << ", addr4=" << m_addr4 << ", addr5=" << m_addr5
183 << ", addr6=" << m_addr6;
184}
185
186bool
188{
189 return ((a.m_meshFlags == b.m_meshFlags) && (a.m_meshTtl == b.m_meshTtl) &&
190 (a.m_meshSeqno == b.m_meshSeqno) && (a.m_addr4 == b.m_addr4) &&
191 (a.m_addr5 == b.m_addr5) && (a.m_addr6 == b.m_addr6));
192}
193} // namespace dot11s
194} // namespace ns3
iterator in a Buffer instance
Definition buffer.h:89
void WriteU8(uint8_t data)
Definition buffer.h:870
void WriteHtolsbU32(uint32_t data)
Definition buffer.cc:899
uint32_t GetDistanceFrom(const Iterator &o) const
Definition buffer.cc:769
uint32_t ReadLsbtohU32()
Definition buffer.cc:1065
Protocol header serialization and deserialization.
Definition header.h:33
an EUI-48 address
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
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:55
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.