A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
dot11s-mac-header.cc
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
32 MeshHeader::GetTypeId ()
33 {
34  static TypeId tid = TypeId ("ns3::Dot11sMacHeader")
35  .SetParent<Header> ()
36  .AddConstructor<MeshHeader> ();
37  return tid;
38 }
39 MeshHeader::MeshHeader () :
40  m_meshFlags (0), m_meshTtl (0), m_meshSeqno (0), m_addr4 (Mac48Address ()), m_addr5 (Mac48Address ()),
41  m_addr6 (Mac48Address ())
42 {
43 }
44 MeshHeader::~MeshHeader ()
45 {
46 }
47 TypeId
49 {
50  return GetTypeId ();
51 }
52 void
53 MeshHeader::SetAddr4 (Mac48Address address)
54 {
55  m_addr4 = address;
56 }
57 void
58 MeshHeader::SetAddr5 (Mac48Address address)
59 {
60  m_addr5 = address;
61 }
62 void
63 MeshHeader::SetAddr6 (Mac48Address address)
64 {
65  m_addr6 = address;
66 }
67 Mac48Address
68 MeshHeader::GetAddr4 () const
69 {
70  return m_addr4;
71 }
72 Mac48Address
73 MeshHeader::GetAddr5 () const
74 {
75  return m_addr5;
76 }
77 Mac48Address
78 MeshHeader::GetAddr6 () const
79 {
80  return m_addr6;
81 }
82 void
83 MeshHeader::SetMeshSeqno (uint32_t seqno)
84 {
85  m_meshSeqno = seqno;
86 }
87 uint32_t
88 MeshHeader::GetMeshSeqno () const
89 {
90  return m_meshSeqno;
91 }
92 void
93 MeshHeader::SetMeshTtl (uint8_t TTL)
94 {
95  m_meshTtl = TTL;
96 }
97 uint8_t
98 MeshHeader::GetMeshTtl () const
99 {
100  return m_meshTtl;
101 }
102 void
103 MeshHeader::SetAddressExt (uint8_t num_of_addresses)
104 {
105  NS_ASSERT (num_of_addresses <= 3);
106  m_meshFlags |= 0x03 & num_of_addresses;
107 }
108 uint8_t
109 MeshHeader::GetAddressExt () const
110 {
111  return (0x03 & m_meshFlags);
112 }
113 uint32_t
115 {
116  return 6 + GetAddressExt () * 6;
117 }
118 void
120 {
121  Buffer::Iterator i = start;
122  i.WriteU8 (m_meshFlags);
123  i.WriteU8 (m_meshTtl);
124  i.WriteHtolsbU32 (m_meshSeqno);
125  uint8_t addresses_to_add = GetAddressExt ();
126  //Writing Address extensions:
127  if ((addresses_to_add == 1) || (addresses_to_add == 3))
128  {
129  WriteTo (i, m_addr4);
130  }
131  if (addresses_to_add > 1)
132  {
133  WriteTo (i, m_addr5);
134  }
135  if (addresses_to_add > 1)
136  {
137  WriteTo (i, m_addr6);
138  }
139 }
140 uint32_t
142 {
143  Buffer::Iterator i = start;
144  uint8_t addresses_to_read = 0;
145  m_meshFlags = i.ReadU8 ();
146  m_meshTtl = i.ReadU8 ();
147  m_meshSeqno = i.ReadLsbtohU32 ();
148  addresses_to_read = m_meshFlags & 0x03;
149  if ((addresses_to_read == 1) || (addresses_to_read == 3))
150  {
151  ReadFrom (i, m_addr4);
152  }
153  if (addresses_to_read > 1)
154  {
155  ReadFrom (i, m_addr5);
156  }
157  if (addresses_to_read > 1)
158  {
159  ReadFrom (i, m_addr6);
160  }
161  return i.GetDistanceFrom (start);
162 }
163 void
164 MeshHeader::Print (std::ostream &os) const
165 {
166  os << "flags = " << (uint16_t) m_meshFlags << std::endl << "ttl = " << (uint16_t) m_meshTtl
167  << std::endl << "seqno = " << m_meshSeqno << std::endl<< "addr4 = " << m_addr4 << std::endl
168  << "addr5 = " << m_addr5 << std::endl << "addr6 = " << m_addr6 << std::endl;
169 }
170 bool
171 operator== (const MeshHeader & a, const MeshHeader & b)
172 {
173  return ((a.m_meshFlags == b.m_meshFlags) && (a.m_meshTtl == b.m_meshTtl)
174  && (a.m_meshSeqno == b.m_meshSeqno) && (a.m_addr4 == b.m_addr4) && (a.m_addr5 == b.m_addr5)
175  && (a.m_addr6 == b.m_addr6));
176 }
177 } // namespace dot11s
178 } // namespace ns3
#define NS_ASSERT(condition)
Definition: assert.h:64
virtual uint32_t Deserialize(Buffer::Iterator start)
virtual void Print(std::ostream &os) const
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:807
iterator in a Buffer instance
Definition: buffer.h:98
virtual void Serialize(Buffer::Iterator start) const
virtual TypeId GetInstanceTypeId() const
an EUI-48 address
Definition: mac48-address.h:41
void WriteU8(uint8_t data)
Definition: buffer.h:690
virtual uint32_t GetSerializedSize() const
uint8_t ReadU8(void)
Definition: buffer.h:819
Mesh Control field, see IEEE 802.11s draft 3.0 section 7.1.3.5b.
uint32_t ReadLsbtohU32(void)
Definition: buffer.cc:1101
void WriteHtolsbU32(uint32_t data)
Definition: buffer.cc:942