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  return m_meshId[i] == o.m_meshId[i];
71 }
72 
73 bool
75 {
76  return m_meshId[0] == 0;
77 }
78 
79 char*
81 {
82  return (char*)m_meshId;
83 }
84 
85 uint16_t
87 {
88  uint8_t size = 0;
89  while (m_meshId[size] != 0 && size < 32)
90  {
91  size++;
92  }
93  NS_ASSERT(size <= 32);
94  return size;
95 }
96 
97 void
99 {
100  uint8_t size = 0;
101  while (m_meshId[size] != 0 && size < 32)
102  {
103  i.WriteU8(m_meshId[size]);
104  size++;
105  }
106 }
107 
108 uint16_t
110 {
112  NS_ASSERT(length <= 32);
113  i.Read(m_meshId, length);
114  m_meshId[length] = 0;
115  return i.GetDistanceFrom(start);
116 }
117 
118 void
119 IeMeshId::Print(std::ostream& os) const
120 {
121  os << "MeshId=(meshId=" << PeekString() << ")";
122 }
123 
124 bool
125 operator==(const IeMeshId& a, const IeMeshId& b)
126 {
127  bool result(true);
128  uint8_t size = 0;
129 
130  while (size < 32)
131  {
132  result = result && (a.m_meshId[size] == b.m_meshId[size]);
133  if (a.m_meshId[size] == 0)
134  {
135  return result;
136  }
137  size++;
138  }
139  return result;
140 }
141 
142 std::ostream&
143 operator<<(std::ostream& os, const IeMeshId& a)
144 {
145  a.Print(os);
146  return os;
147 }
148 
149 std::istream&
150 operator>>(std::istream& is, IeMeshId& a)
151 {
152  std::string str;
153  is >> str;
154  a = IeMeshId(str);
155  return is;
156 }
157 
158 } // namespace dot11s
159 } // 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:1125
uint32_t GetDistanceFrom(const Iterator &o) const
Definition: buffer.cc:780
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:86
bool IsBroadcast() const
Return true if broadcast (if first octet of Mesh ID is zero)
Definition: ie-dot11s-id.cc:74
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)
Definition: ie-dot11s-id.cc:98
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:80
#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