A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ie-dot11s-beacon-timing.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
21
22#include "ns3/packet.h"
23
24namespace ns3
25{
26namespace dot11s
27{
28/*******************************************
29 * IeBeaconTimingUnit
30 *******************************************/
32 : m_aid(0),
33 m_lastBeacon(0),
34 m_beaconInterval(0)
35{
36}
37
38void
40{
41 m_aid = aid;
42}
43
44void
46{
47 m_lastBeacon = lastBeacon;
48}
49
50void
52{
53 m_beaconInterval = beaconInterval;
54}
55
56uint8_t
58{
59 return m_aid;
60}
61
62uint16_t
64{
65 return m_lastBeacon;
66}
67
68uint16_t
70{
71 return m_beaconInterval;
72}
73
74/*******************************************
75 * IeBeaconTiming
76 *******************************************/
79{
80 return IE_BEACON_TIMING;
81}
82
84 : m_numOfUnits(0)
85{
86}
87
90{
91 return m_neighbours;
92}
93
94void
95IeBeaconTiming::AddNeighboursTimingElementUnit(uint16_t aid, Time last_beacon, Time beacon_interval)
96{
97 if (m_numOfUnits == 50)
98 {
99 return;
100 }
101 // First we lookup if this element already exists
102 for (NeighboursTimingUnitsList::const_iterator i = m_neighbours.begin();
103 i != m_neighbours.end();
104 i++)
105 {
106 if (((*i)->GetAid() == AidToU8(aid)) &&
107 ((*i)->GetLastBeacon() == TimestampToU16(last_beacon)) &&
108 ((*i)->GetBeaconInterval() == BeaconIntervalToU16(beacon_interval)))
109 {
110 return;
111 }
112 }
113 Ptr<IeBeaconTimingUnit> new_element = Create<IeBeaconTimingUnit>();
114 new_element->SetAid(AidToU8(aid));
115 new_element->SetLastBeacon(TimestampToU16(last_beacon));
116 new_element->SetBeaconInterval(BeaconIntervalToU16(beacon_interval));
117 m_neighbours.push_back(new_element);
118 m_numOfUnits++;
119}
120
121void
122IeBeaconTiming::DelNeighboursTimingElementUnit(uint16_t aid, Time last_beacon, Time beacon_interval)
123{
124 for (NeighboursTimingUnitsList::iterator i = m_neighbours.begin(); i != m_neighbours.end(); i++)
125 {
126 if (((*i)->GetAid() == AidToU8(aid)) &&
127 ((*i)->GetLastBeacon() == TimestampToU16(last_beacon)) &&
128 ((*i)->GetBeaconInterval() == BeaconIntervalToU16(beacon_interval)))
129 {
130 m_neighbours.erase(i);
131 m_numOfUnits--;
132 break;
133 }
134 }
135}
136
137void
139{
140 for (NeighboursTimingUnitsList::iterator j = m_neighbours.begin(); j != m_neighbours.end(); j++)
141 {
142 (*j) = nullptr;
143 }
144 m_neighbours.clear();
145}
146
147uint16_t
149{
150 return (5 * m_numOfUnits);
151}
152
153void
154IeBeaconTiming::Print(std::ostream& os) const
155{
156 os << "BeaconTiming=(Number of units=" << (uint16_t)m_numOfUnits;
157 for (NeighboursTimingUnitsList::const_iterator j = m_neighbours.begin();
158 j != m_neighbours.end();
159 j++)
160 {
161 os << "(AID=" << (uint16_t)(*j)->GetAid() << ", Last beacon at=" << (*j)->GetLastBeacon()
162 << ", with beacon interval=" << (*j)->GetBeaconInterval() << ")";
163 }
164 os << ")";
165}
166
167void
169{
170 for (NeighboursTimingUnitsList::const_iterator j = m_neighbours.begin();
171 j != m_neighbours.end();
172 j++)
173 {
174 i.WriteU8((*j)->GetAid());
175 i.WriteHtolsbU16((*j)->GetLastBeacon());
176 i.WriteHtolsbU16((*j)->GetBeaconInterval());
177 }
178}
179
180uint16_t
182{
183 Buffer::Iterator i = start;
184 m_numOfUnits = length / 5;
185 for (int j = 0; j < m_numOfUnits; j++)
186 {
187 Ptr<IeBeaconTimingUnit> new_element = Create<IeBeaconTimingUnit>();
188 new_element->SetAid(i.ReadU8());
189 new_element->SetLastBeacon(i.ReadLsbtohU16());
190 new_element->SetBeaconInterval(i.ReadLsbtohU16());
191 m_neighbours.push_back(new_element);
192 }
193 return i.GetDistanceFrom(start);
194};
195
196uint16_t
198{
199 return ((uint16_t)((t.GetMicroSeconds() >> 8) & 0xffff));
200};
201
202uint16_t
204{
205 return ((uint16_t)(t.GetMicroSeconds() >> 10) & 0xffff);
206}
207
208uint8_t
210{
211 return (uint8_t)(x & 0xff);
212}
213
214bool
216{
217 return ((a.GetAid() == b.GetAid()) && (a.GetLastBeacon() == b.GetLastBeacon()) &&
219}
220
221bool
223{
224 try
225 {
226 const IeBeaconTiming& aa = dynamic_cast<const IeBeaconTiming&>(a);
227
228 if (m_numOfUnits != aa.m_numOfUnits)
229 {
230 return false;
231 }
232 for (unsigned int i = 0; i < m_neighbours.size(); i++)
233 {
234 if (!(*PeekPointer(m_neighbours[i]) == *PeekPointer(aa.m_neighbours[i])))
235 {
236 return false;
237 }
238 }
239 return true;
240 }
241 catch (std::bad_cast&)
242 {
243 return false;
244 }
245}
246
247std::ostream&
248operator<<(std::ostream& os, const IeBeaconTiming& a)
249{
250 a.Print(os);
251 return os;
252}
253} // namespace dot11s
254} // namespace ns3
iterator in a Buffer instance
Definition: buffer.h:100
void WriteHtolsbU16(uint16_t data)
Definition: buffer.cc:908
uint8_t ReadU8()
Definition: buffer.h:1027
void WriteU8(uint8_t data)
Definition: buffer.h:881
uint16_t ReadLsbtohU16()
Definition: buffer.cc:1070
uint32_t GetDistanceFrom(const Iterator &o) const
Definition: buffer.cc:786
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
int64_t GetMicroSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:412
Information element, as defined in 802.11-2007 standard.
See 7.3.2.89 of 802.11s draft 2.07.
uint16_t GetInformationFieldSize() const override
Length of serialized information (i.e., the length of the body of the IE, not including the Element I...
void AddNeighboursTimingElementUnit(uint16_t aid, Time last_beacon, Time beacon_interval)
Add neighbors timing element unit.
static uint16_t BeaconIntervalToU16(Time x)
Beacon interval to U16 function.
void SerializeInformationField(Buffer::Iterator i) const override
Serialize information (i.e., the body of the IE, not including the Element ID and length octets)
bool operator==(const WifiInformationElement &a) const override
equality operator
uint16_t DeserializeInformationField(Buffer::Iterator i, uint16_t length) override
Deserialize information (i.e., the body of the IE, not including the Element ID and length octets)
void ClearTimingElement()
Clear timing element.
uint16_t m_numOfUnits
Timing element parameters:
NeighboursTimingUnitsList GetNeighboursTimingElementsList()
This methods are needed for beacon collision avoidance module:
static uint8_t AidToU8(uint16_t x)
Aid to U8 function.
WifiInformationElementId ElementId() const override
Get the wifi information element ID.
NeighboursTimingUnitsList m_neighbours
the neighbors
static uint16_t TimestampToU16(Time x)
Timestamp to U16 function.
void Print(std::ostream &os) const override
Generate human-readable form of IE.
void DelNeighboursTimingElementUnit(uint16_t aid, Time last_beacon, Time beacon_interval)
Delete neighbors timing element unit.
Information element describing one unit of beacon timing element.
uint16_t m_lastBeacon
Last time we received a beacon in accordance with a local TSF measured in 256 microseconds unit.
void SetBeaconInterval(uint16_t beaconInterval)
Set beacon interval value.
uint16_t m_beaconInterval
Beacon interval of remote mesh point.
uint16_t GetBeaconInterval() const
Get beacon interval.
void SetAid(uint8_t aid)
Set AID value.
void SetLastBeacon(uint16_t lastBeacon)
Set last beacon value.
uint16_t GetLastBeacon() const
Get last beacon value.
uint8_t GetAid() const
Get AID value.
uint8_t m_aid
Least significant octet of AID:
std::vector< Ptr< IeBeaconTimingUnit > > NeighboursTimingUnitsList
This type is a list of timing elements obtained from neighbours with their beacons:
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.
U * PeekPointer(const Ptr< U > &p)
Definition: ptr.h:488
uint8_t WifiInformationElementId
This type is used to represent an Information Element ID.
#define IE_BEACON_TIMING