A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ie-dot11s-id.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008,2009 IITP RAS
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Kirill Andreev <andreev@iitp.ru>
7 */
8
9#include "ie-dot11s-id.h"
10
11#include "ns3/assert.h"
12
13namespace ns3
14{
15namespace dot11s
16{
17
19{
20 for (uint8_t i = 0; i < 32; i++)
21 {
22 m_meshId[i] = 0;
23 }
24}
25
26IeMeshId::IeMeshId(std::string s)
27{
28 NS_ASSERT(s.size() < 32);
29 const char* meshid = s.c_str();
30 uint8_t len = 0;
31 while (*meshid != 0 && len < 32)
32 {
33 m_meshId[len] = *meshid;
34 meshid++;
35 len++;
36 }
37 NS_ASSERT(len <= 32);
38 while (len < 33)
39 {
40 m_meshId[len] = 0;
41 len++;
42 }
43}
44
47{
48 return IE_MESH_ID;
49}
50
51bool
53{
54 uint8_t i = 0;
55 while (i < 32 && m_meshId[i] == o.m_meshId[i] && m_meshId[i] != 0)
56 {
57 i++;
58 }
59 return m_meshId[i] == o.m_meshId[i];
60}
61
62bool
64{
65 return m_meshId[0] == 0;
66}
67
68char*
70{
71 return (char*)m_meshId;
72}
73
74uint16_t
76{
77 uint8_t size = 0;
78 while (m_meshId[size] != 0 && size < 32)
79 {
80 size++;
81 }
82 NS_ASSERT(size <= 32);
83 return size;
84}
85
86void
88{
89 uint8_t size = 0;
90 while (m_meshId[size] != 0 && size < 32)
91 {
92 i.WriteU8(m_meshId[size]);
93 size++;
94 }
95}
96
97uint16_t
99{
100 Buffer::Iterator i = start;
101 NS_ASSERT(length <= 32);
102 i.Read(m_meshId, length);
103 m_meshId[length] = 0;
104 return i.GetDistanceFrom(start);
105}
106
107void
108IeMeshId::Print(std::ostream& os) const
109{
110 os << "MeshId=(meshId=" << PeekString() << ")";
111}
112
113bool
114operator==(const IeMeshId& a, const IeMeshId& b)
115{
116 bool result(true);
117 uint8_t size = 0;
118
119 while (size < 32)
120 {
121 result = result && (a.m_meshId[size] == b.m_meshId[size]);
122 if (a.m_meshId[size] == 0)
123 {
124 return result;
125 }
126 size++;
127 }
128 return result;
129}
130
131std::ostream&
132operator<<(std::ostream& os, const IeMeshId& a)
133{
134 a.Print(os);
135 return os;
136}
137
138std::istream&
139operator>>(std::istream& is, IeMeshId& a)
140{
141 std::string str;
142 is >> str;
143 a = IeMeshId(str);
144 return is;
145}
146
147} // namespace dot11s
148} // namespace ns3
iterator in a Buffer instance
Definition buffer.h:89
void WriteU8(uint8_t data)
Definition buffer.h:870
void Read(uint8_t *buffer, uint32_t size)
Definition buffer.cc:1114
uint32_t GetDistanceFrom(const Iterator &o) const
Definition buffer.cc:769
a IEEE 802.11 Mesh ID element (Section 8.4.2.101 of IEEE 802.11-2012)
WifiInformationElementId ElementId() const override
Get the wifi information element ID.
uint16_t GetInformationFieldSize() const override
Length of serialized information (i.e., the length of the body of the IE, not including the Element I...
bool IsBroadcast() const
Return true if broadcast (if first octet of Mesh ID is zero)
void Print(std::ostream &os) const override
Generate human-readable form of IE.
bool IsEqual(const IeMeshId &o) const
Equality test.
uint8_t m_meshId[33]
mesh ID
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.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
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