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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Kirill Andreev <andreev@iitp.ru>
7 */
8
10
11#include "ns3/packet.h"
12
13namespace ns3
14{
15namespace dot11s
16{
17/*******************************************
18 * IeBeaconTimingUnit
19 *******************************************/
21 : m_aid(0),
22 m_lastBeacon(0),
23 m_beaconInterval(0)
24{
25}
26
27void
29{
30 m_aid = aid;
31}
32
33void
35{
36 m_lastBeacon = lastBeacon;
37}
38
39void
41{
42 m_beaconInterval = beaconInterval;
43}
44
45uint8_t
47{
48 return m_aid;
49}
50
51uint16_t
56
57uint16_t
62
63/*******************************************
64 * IeBeaconTiming
65 *******************************************/
71
73 : m_numOfUnits(0)
74{
75}
76
82
83void
84IeBeaconTiming::AddNeighboursTimingElementUnit(uint16_t aid, Time last_beacon, Time beacon_interval)
85{
86 if (m_numOfUnits == 50)
87 {
88 return;
89 }
90 // First we lookup if this element already exists
91 for (auto i = m_neighbours.begin(); i != m_neighbours.end(); i++)
92 {
93 if (((*i)->GetAid() == AidToU8(aid)) &&
94 ((*i)->GetLastBeacon() == TimestampToU16(last_beacon)) &&
95 ((*i)->GetBeaconInterval() == BeaconIntervalToU16(beacon_interval)))
96 {
97 return;
98 }
99 }
101 new_element->SetAid(AidToU8(aid));
102 new_element->SetLastBeacon(TimestampToU16(last_beacon));
103 new_element->SetBeaconInterval(BeaconIntervalToU16(beacon_interval));
104 m_neighbours.push_back(new_element);
105 m_numOfUnits++;
106}
107
108void
109IeBeaconTiming::DelNeighboursTimingElementUnit(uint16_t aid, Time last_beacon, Time beacon_interval)
110{
111 for (auto i = m_neighbours.begin(); i != m_neighbours.end(); i++)
112 {
113 if (((*i)->GetAid() == AidToU8(aid)) &&
114 ((*i)->GetLastBeacon() == TimestampToU16(last_beacon)) &&
115 ((*i)->GetBeaconInterval() == BeaconIntervalToU16(beacon_interval)))
116 {
117 m_neighbours.erase(i);
118 m_numOfUnits--;
119 break;
120 }
121 }
122}
123
124void
126{
127 for (auto j = m_neighbours.begin(); j != m_neighbours.end(); j++)
128 {
129 (*j) = nullptr;
130 }
131 m_neighbours.clear();
132}
133
134uint16_t
136{
137 return (5 * m_numOfUnits);
138}
139
140void
141IeBeaconTiming::Print(std::ostream& os) const
142{
143 os << "BeaconTiming=(Number of units=" << (uint16_t)m_numOfUnits;
144 for (auto j = m_neighbours.begin(); j != m_neighbours.end(); j++)
145 {
146 os << "(AID=" << (uint16_t)(*j)->GetAid() << ", Last beacon at=" << (*j)->GetLastBeacon()
147 << ", with beacon interval=" << (*j)->GetBeaconInterval() << ")";
148 }
149 os << ")";
150}
151
152void
154{
155 for (auto j = m_neighbours.begin(); j != m_neighbours.end(); j++)
156 {
157 i.WriteU8((*j)->GetAid());
158 i.WriteHtolsbU16((*j)->GetLastBeacon());
159 i.WriteHtolsbU16((*j)->GetBeaconInterval());
160 }
161}
162
163uint16_t
165{
166 Buffer::Iterator i = start;
167 m_numOfUnits = length / 5;
168 for (int j = 0; j < m_numOfUnits; j++)
169 {
171 new_element->SetAid(i.ReadU8());
172 new_element->SetLastBeacon(i.ReadLsbtohU16());
173 new_element->SetBeaconInterval(i.ReadLsbtohU16());
174 m_neighbours.push_back(new_element);
175 }
176 return i.GetDistanceFrom(start);
177}
178
179uint16_t
181{
182 return ((uint16_t)((t.GetMicroSeconds() >> 8) & 0xffff));
183}
184
185uint16_t
187{
188 return ((uint16_t)(t.GetMicroSeconds() >> 10) & 0xffff);
189}
190
191uint8_t
193{
194 return (uint8_t)(x & 0xff);
195}
196
197bool
199{
200 return ((a.GetAid() == b.GetAid()) && (a.GetLastBeacon() == b.GetLastBeacon()) &&
202}
203
204bool
206{
207 try
208 {
209 const auto& aa = dynamic_cast<const IeBeaconTiming&>(a);
210
211 if (m_numOfUnits != aa.m_numOfUnits)
212 {
213 return false;
214 }
215 for (unsigned int i = 0; i < m_neighbours.size(); i++)
216 {
217 if (!(*PeekPointer(m_neighbours[i]) == *PeekPointer(aa.m_neighbours[i])))
218 {
219 return false;
220 }
221 }
222 return true;
223 }
224 catch (std::bad_cast&)
225 {
226 return false;
227 }
228}
229
230std::ostream&
231operator<<(std::ostream& os, const IeBeaconTiming& a)
232{
233 a.Print(os);
234 return os;
235}
236} // namespace dot11s
237} // namespace ns3
iterator in a Buffer instance
Definition buffer.h:89
void WriteHtolsbU16(uint16_t data)
Definition buffer.cc:891
void WriteU8(uint8_t data)
Definition buffer.h:870
uint16_t ReadLsbtohU16()
Definition buffer.cc:1053
uint32_t GetDistanceFrom(const Iterator &o) const
Definition buffer.cc:769
Smart pointer class similar to boost::intrusive_ptr.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
int64_t GetMicroSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:402
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:
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
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:443
uint8_t WifiInformationElementId
This type is used to represent an Information Element ID.
#define IE_BEACON_TIMING