A Discrete-Event Network Simulator
API
dot11s-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) 2009 IITP RAS
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 * Author: Kirill Andreev <andreev@iitp.ru>
19 */
20
21#include "ns3/assert.h"
22#include "ns3/address-utils.h"
23#include "dot11s-mac-header.h"
24#include "ns3/packet.h"
25
26namespace ns3 {
27namespace dot11s {
28/***********************************************************
29 * Here Mesh Mac Header functionality is defined.
30 ***********************************************************/
31TypeId
33{
34 static TypeId tid = TypeId ("ns3::dot11s::MeshHeader")
35 .SetParent<Header> ()
36 .SetGroupName ("Mesh")
37 .AddConstructor<MeshHeader> ();
38 return tid;
39}
41 m_meshFlags (0), m_meshTtl (0), m_meshSeqno (0), m_addr4 (Mac48Address ()), m_addr5 (Mac48Address ()),
42 m_addr6 (Mac48Address ())
43{
44}
46{
47}
50{
51 return GetTypeId ();
52}
53void
55{
57}
58void
60{
62}
63void
65{
67}
70{
71 return m_addr4;
72}
75{
76 return m_addr5;
77}
80{
81 return m_addr6;
82}
83void
85{
86 m_meshSeqno = seqno;
87}
90{
91 return m_meshSeqno;
92}
93void
95{
96 m_meshTtl = TTL;
97}
98uint8_t
100{
101 return m_meshTtl;
102}
103void
105{
106 NS_ASSERT (value <= 3);
107 m_meshFlags |= 0x03 & value;
108}
109uint8_t
111{
112 return (0x03 & m_meshFlags);
113}
116{
117 return 6 + GetAddressExt () * 6;
118}
119void
121{
124 i.WriteU8 (m_meshTtl);
126 uint8_t addresses_to_add = GetAddressExt ();
127 //Writing Address extensions:
128 if ((addresses_to_add == 1) || (addresses_to_add == 3))
129 {
130 WriteTo (i, m_addr4);
131 }
132 if (addresses_to_add > 1)
133 {
134 WriteTo (i, m_addr5);
135 }
136 if (addresses_to_add > 1)
137 {
138 WriteTo (i, m_addr6);
139 }
140}
143{
145 uint8_t addresses_to_read = 0;
146 m_meshFlags = i.ReadU8 ();
147 m_meshTtl = i.ReadU8 ();
149 addresses_to_read = m_meshFlags & 0x03;
150 if ((addresses_to_read == 1) || (addresses_to_read == 3))
151 {
152 ReadFrom (i, m_addr4);
153 }
154 if (addresses_to_read > 1)
155 {
156 ReadFrom (i, m_addr5);
157 }
158 if (addresses_to_read > 1)
159 {
160 ReadFrom (i, m_addr6);
161 }
162 return i.GetDistanceFrom (start);
163}
164void
165MeshHeader::Print (std::ostream &os) const
166{
167 os << "flags=" << (uint16_t) m_meshFlags << ", ttl=" << (uint16_t) m_meshTtl
168 << ", seqno=" << m_meshSeqno << ", addr4=" << m_addr4
169 << ", addr5=" << m_addr5 << ", addr6=" << m_addr6;
170}
171bool
172operator== (const MeshHeader & a, const MeshHeader & b)
173{
174 return ((a.m_meshFlags == b.m_meshFlags) && (a.m_meshTtl == b.m_meshTtl)
175 && (a.m_meshSeqno == b.m_meshSeqno) && (a.m_addr4 == b.m_addr4) && (a.m_addr5 == b.m_addr5)
176 && (a.m_addr6 == b.m_addr6));
177}
178} // namespace dot11s
179} // namespace ns3
iterator in a Buffer instance
Definition: buffer.h:99
uint32_t ReadLsbtohU32(void)
Definition: buffer.cc:1077
void WriteU8(uint8_t data)
Definition: buffer.h:869
void WriteHtolsbU32(uint32_t data)
Definition: buffer.cc:918
uint8_t ReadU8(void)
Definition: buffer.h:1021
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:788
Protocol header serialization and deserialization.
Definition: header.h:43
an EUI-48 address
Definition: mac48-address.h:44
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
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.
virtual TypeId GetInstanceTypeId() const
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.
static TypeId GetTypeId()
Get the type ID.
Mac48Address GetAddr5() const
Get extended address 5.
Mac48Address GetAddr4() const
Get extended address 4.
uint8_t m_meshFlags
mesh flags
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.
virtual uint32_t GetSerializedSize() const
virtual void Serialize(Buffer::Iterator start) const
void SetAddr5(Mac48Address address)
Set extended address 5.
void SetAddr4(Mac48Address address)
Set extended address 4.
virtual uint32_t Deserialize(Buffer::Iterator start)
uint8_t GetMeshTtl() const
Get mesh TTL function subfield value.
Mac48Address m_addr5
MAC address 5.
virtual void Print(std::ostream &os) const
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:67
address
Definition: first.py:44
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.
def start()
Definition: core.py:1853