A Discrete-Event Network Simulator
API
ie-dot11s-id.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008,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 "ie-dot11s-id.h"
21 
22 #include "ns3/assert.h"
23 
24 namespace ns3
25 {
26 namespace dot11s
27 {
28 
30 {
31  for (uint8_t i = 0; i < 32; i++)
32  {
33  m_meshId[i] = 0;
34  }
35 }
36 
37 IeMeshId::IeMeshId(std::string s)
38 {
39  NS_ASSERT(s.size() < 32);
40  const char* meshid = s.c_str();
41  uint8_t len = 0;
42  while (*meshid != 0 && len < 32)
43  {
44  m_meshId[len] = *meshid;
45  meshid++;
46  len++;
47  }
48  NS_ASSERT(len <= 32);
49  while (len < 33)
50  {
51  m_meshId[len] = 0;
52  len++;
53  }
54 }
55 
58 {
59  return IE_MESH_ID;
60 }
61 
62 bool
63 IeMeshId::IsEqual(const IeMeshId& o) const
64 {
65  uint8_t i = 0;
66  while (i < 32 && m_meshId[i] == o.m_meshId[i] && m_meshId[i] != 0)
67  {
68  i++;
69  }
70  if (m_meshId[i] != o.m_meshId[i])
71  {
72  return false;
73  }
74  return true;
75 }
76 
77 bool
79 {
80  if (m_meshId[0] == 0)
81  {
82  return true;
83  }
84  return false;
85 }
86 
87 char*
89 {
90  return (char*)m_meshId;
91 }
92 
93 uint16_t
95 {
96  uint8_t size = 0;
97  while (m_meshId[size] != 0 && size < 32)
98  {
99  size++;
100  }
101  NS_ASSERT(size <= 32);
102  return size;
103 }
104 
105 void
107 {
108  uint8_t size = 0;
109  while (m_meshId[size] != 0 && size < 32)
110  {
111  i.WriteU8(m_meshId[size]);
112  size++;
113  }
114 }
115 
116 uint16_t
118 {
120  NS_ASSERT(length <= 32);
121  i.Read(m_meshId, length);
122  m_meshId[length] = 0;
123  return i.GetDistanceFrom(start);
124 }
125 
126 void
127 IeMeshId::Print(std::ostream& os) const
128 {
129  os << "MeshId=(meshId=" << PeekString() << ")";
130 }
131 
132 bool
133 operator==(const IeMeshId& a, const IeMeshId& b)
134 {
135  bool result(true);
136  uint8_t size = 0;
137 
138  while (size < 32)
139  {
140  result = result && (a.m_meshId[size] == b.m_meshId[size]);
141  if (a.m_meshId[size] == 0)
142  {
143  return result;
144  }
145  size++;
146  }
147  return result;
148 }
149 
150 std::ostream&
151 operator<<(std::ostream& os, const IeMeshId& a)
152 {
153  a.Print(os);
154  return os;
155 }
156 
157 std::istream&
158 operator>>(std::istream& is, IeMeshId& a)
159 {
160  std::string str;
161  is >> str;
162  a = IeMeshId(str);
163  return is;
164 }
165 
166 } // namespace dot11s
167 } // namespace ns3
iterator in a Buffer instance
Definition: buffer.h:100
void WriteU8(uint8_t data)
Definition: buffer.h:881
void Read(uint8_t *buffer, uint32_t size)
Definition: buffer.cc:1128
uint32_t GetDistanceFrom(const Iterator &o) const
Definition: buffer.cc:783
a IEEE 802.11 Mesh ID element (Section 8.4.2.101 of IEEE 802.11-2012)
Definition: ie-dot11s-id.h:38
WifiInformationElementId ElementId() const override
Get the wifi information element ID.
Definition: ie-dot11s-id.cc:57
uint16_t GetInformationFieldSize() const override
Length of serialized information (i.e., the length of the body of the IE, not including the Element I...
Definition: ie-dot11s-id.cc:94
bool IsBroadcast() const
Return true if broadcast (if first octet of Mesh ID is zero)
Definition: ie-dot11s-id.cc:78
void Print(std::ostream &os) const override
Generate human-readable form of IE.
bool IsEqual(const IeMeshId &o) const
Equality test.
Definition: ie-dot11s-id.cc:63
uint8_t m_meshId[33]
mesh ID
Definition: ie-dot11s-id.h:75
void SerializeInformationField(Buffer::Iterator i) const override
Serialize information (i.e., the body of the IE, not including the Element ID and length octets)
uint16_t DeserializeInformationField(Buffer::Iterator start, uint16_t length) override
Deserialize information (i.e., the body of the IE, not including the Element ID and length octets)
char * PeekString() const
Peek the IeMeshId as a string value.
Definition: ie-dot11s-id.cc:88
#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
std::istream & operator>>(std::istream &is, IeMeshId &a)
bool operator==(const MeshHeader &a, const MeshHeader &b)
std::ostream & operator<<(std::ostream &os, const IeBeaconTiming &a)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t WifiInformationElementId
This type is used to represent an Information Element ID.
#define IE_MESH_ID