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 
26 namespace ns3 {
27 namespace dot11s {
28 /***********************************************************
29  * Here Mesh Mac Header functionality is defined.
30  ***********************************************************/
31 TypeId
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 }
48 TypeId
50 {
51  return GetTypeId ();
52 }
53 void
55 {
56  m_addr4 = address;
57 }
58 void
60 {
61  m_addr5 = address;
62 }
63 void
65 {
66  m_addr6 = address;
67 }
70 {
71  return m_addr4;
72 }
75 {
76  return m_addr5;
77 }
80 {
81  return m_addr6;
82 }
83 void
84 MeshHeader::SetMeshSeqno (uint32_t seqno)
85 {
86  m_meshSeqno = seqno;
87 }
88 uint32_t
90 {
91  return m_meshSeqno;
92 }
93 void
95 {
96  m_meshTtl = TTL;
97 }
98 uint8_t
100 {
101  return m_meshTtl;
102 }
103 void
104 MeshHeader::SetAddressExt (uint8_t num_of_addresses)
105 {
106  NS_ASSERT (num_of_addresses <= 3);
107  m_meshFlags |= 0x03 & num_of_addresses;
108 }
109 uint8_t
111 {
112  return (0x03 & m_meshFlags);
113 }
114 uint32_t
116 {
117  return 6 + GetAddressExt () * 6;
118 }
119 void
121 {
123  i.WriteU8 (m_meshFlags);
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 }
141 uint32_t
143 {
145  uint8_t addresses_to_read = 0;
146  m_meshFlags = i.ReadU8 ();
147  m_meshTtl = i.ReadU8 ();
148  m_meshSeqno = i.ReadLsbtohU32 ();
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 }
164 void
165 MeshHeader::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 }
171 bool
172 operator== (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
Protocol header serialization and deserialization.
Definition: header.h:42
uint8_t GetMeshTtl() const
void ReadFrom(Buffer::Iterator &i, Ipv4Address &ad)
Read an Ipv4Address from a Buffer.
def start()
Definition: core.py:1482
#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
void WriteTo(Buffer::Iterator &i, Ipv4Address ad)
Write an Ipv4Address to a Buffer.
virtual uint32_t Deserialize(Buffer::Iterator start)
void SetMeshSeqno(uint32_t seqno)
virtual void Print(std::ostream &os) const
bool operator==(const MeshHeader &a, const MeshHeader &b)
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:783
void SetAddressExt(uint8_t num_of_addresses)
iterator in a Buffer instance
Definition: buffer.h:98
void SetMeshTtl(uint8_t TTL)
virtual void Serialize(Buffer::Iterator start) const
virtual TypeId GetInstanceTypeId() const
Get the most derived TypeId for this Object.
Mac48Address GetAddr5() const
Mac48Address GetAddr4() const
void SetAddr6(Mac48Address address)
uint8_t GetAddressExt() const
void SetAddr4(Mac48Address address)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetAddr5(Mac48Address address)
an EUI-48 address
Definition: mac48-address.h:43
void WriteU8(uint8_t data)
Definition: buffer.h:868
virtual uint32_t GetSerializedSize() const
uint8_t ReadU8(void)
Definition: buffer.h:1020
Mesh Control field, see IEEE 802.11s draft 3.0 section 7.1.3.5b.
uint32_t GetMeshSeqno() const
tuple address
Definition: first.py:37
Mac48Address GetAddr6() const
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:904
uint32_t ReadLsbtohU32(void)
Definition: buffer.cc:1076
void WriteHtolsbU32(uint32_t data)
Definition: buffer.cc:917