A Discrete-Event Network Simulator
API
ie-dot11s-id.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2008,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 "ie-dot11s-id.h"
22#include "ns3/assert.h"
23
24namespace ns3 {
25namespace dot11s {
26
28{
29 for (uint8_t i = 0; i < 32; i++)
30 {
31 m_meshId[i] = 0;
32 }
33}
34IeMeshId::IeMeshId (std::string s)
35{
36 NS_ASSERT (s.size () < 32);
37 const char *meshid = s.c_str ();
38 uint8_t len = 0;
39 while (*meshid != 0 && len < 32)
40 {
41 m_meshId[len] = *meshid;
42 meshid++;
43 len++;
44 }
45 NS_ASSERT (len <= 32);
46 while (len < 33)
47 {
48 m_meshId[len] = 0;
49 len++;
50 }
51}
54{
55 return IE_MESH_ID;
56}
57bool
59{
60 uint8_t i = 0;
61 while (i < 32 && m_meshId[i] == o.m_meshId[i] && m_meshId[i] != 0)
62 {
63 i++;
64 }
65 if (m_meshId[i] != o.m_meshId[i])
66 {
67 return false;
68 }
69 return true;
70}
71bool
73{
74 if (m_meshId[0] == 0)
75 {
76 return true;
77 }
78 return false;
79}
80char *
82{
83 return (char *) m_meshId;
84}
85uint8_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}
96void
98{
99 uint8_t size = 0;
100 while (m_meshId[size] != 0 && size < 32)
101 {
102 i.WriteU8 (m_meshId[size]);
103 size++;
104 }
105}
106uint8_t
108{
110 NS_ASSERT (length <= 32);
111 i.Read (m_meshId, length);
112 m_meshId[length] = 0;
113 return i.GetDistanceFrom (start);
114}
115void
116IeMeshId::Print (std::ostream& os) const
117{
118 os << "MeshId=(meshId=" << PeekString () << ")";
119}
120bool
121operator== (const IeMeshId & a, const IeMeshId & b)
122{
123 bool result (true);
124 uint8_t size = 0;
125
126 while (size < 32)
127 {
128 result = result && (a.m_meshId[size] == b.m_meshId[size]);
129 if (a.m_meshId[size] == 0)
130 {
131 return result;
132 }
133 size++;
134 }
135 return result;
136}
137std::ostream &
138operator << (std::ostream &os, const IeMeshId &a)
139{
140 a.Print (os);
141 return os;
142}
143
144std::istream &operator >> (std::istream &is, IeMeshId &a)
145{
146 std::string str;
147 is >> str;
148 a = IeMeshId (str.c_str ());
149 return is;
150}
151
152
153} // namespace dot11s
154} // namespace ns3
iterator in a Buffer instance
Definition: buffer.h:99
void WriteU8(uint8_t data)
Definition: buffer.h:869
void Read(uint8_t *buffer, uint32_t size)
Definition: buffer.cc:1124
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:788
a IEEE 802.11 Mesh ID element (Section 8.4.2.101 of IEEE 802.11-2012)
Definition: ie-dot11s-id.h:36
bool IsEqual(IeMeshId const &o) const
Equality test.
Definition: ie-dot11s-id.cc:58
char * PeekString(void) const
Peek the IeMeshId as a string value.
Definition: ie-dot11s-id.cc:81
virtual void SerializeInformationField(Buffer::Iterator i) const
Serialize information (i.e., the body of the IE, not including the Element ID and length octets)
Definition: ie-dot11s-id.cc:97
bool IsBroadcast(void) const
Return true if broadcast (if first octet of Mesh ID is zero)
Definition: ie-dot11s-id.cc:72
virtual WifiInformationElementId ElementId() const
Definition: ie-dot11s-id.cc:53
virtual uint8_t GetInformationFieldSize() const
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
uint8_t m_meshId[33]
mesh ID
Definition: ie-dot11s-id.h:73
virtual void Print(std::ostream &os) const
Generate human-readable form of IE.
virtual uint8_t DeserializeInformationField(Buffer::Iterator start, uint8_t length)
Deserialize information (i.e., the body of the IE, not including the Element ID and length octets)
#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
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.
def start()
Definition: core.py:1853
#define IE_MESH_ID