A Discrete-Event Network Simulator
API
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 
24 namespace ns3
25 {
26 namespace dot11s
27 {
28 /*******************************************
29  * IeBeaconTimingUnit
30  *******************************************/
32  : m_aid(0),
33  m_lastBeacon(0),
34  m_beaconInterval(0)
35 {
36 }
37 
38 void
40 {
41  m_aid = aid;
42 }
43 
44 void
46 {
47  m_lastBeacon = lastBeacon;
48 }
49 
50 void
51 IeBeaconTimingUnit::SetBeaconInterval(uint16_t beaconInterval)
52 {
53  m_beaconInterval = beaconInterval;
54 }
55 
56 uint8_t
58 {
59  return m_aid;
60 }
61 
62 uint16_t
64 {
65  return m_lastBeacon;
66 }
67 
68 uint16_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 
94 void
95 IeBeaconTiming::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 (auto i = m_neighbours.begin(); i != m_neighbours.end(); i++)
103  {
104  if (((*i)->GetAid() == AidToU8(aid)) &&
105  ((*i)->GetLastBeacon() == TimestampToU16(last_beacon)) &&
106  ((*i)->GetBeaconInterval() == BeaconIntervalToU16(beacon_interval)))
107  {
108  return;
109  }
110  }
111  Ptr<IeBeaconTimingUnit> new_element = Create<IeBeaconTimingUnit>();
112  new_element->SetAid(AidToU8(aid));
113  new_element->SetLastBeacon(TimestampToU16(last_beacon));
114  new_element->SetBeaconInterval(BeaconIntervalToU16(beacon_interval));
115  m_neighbours.push_back(new_element);
116  m_numOfUnits++;
117 }
118 
119 void
120 IeBeaconTiming::DelNeighboursTimingElementUnit(uint16_t aid, Time last_beacon, Time beacon_interval)
121 {
122  for (auto i = m_neighbours.begin(); i != m_neighbours.end(); i++)
123  {
124  if (((*i)->GetAid() == AidToU8(aid)) &&
125  ((*i)->GetLastBeacon() == TimestampToU16(last_beacon)) &&
126  ((*i)->GetBeaconInterval() == BeaconIntervalToU16(beacon_interval)))
127  {
128  m_neighbours.erase(i);
129  m_numOfUnits--;
130  break;
131  }
132  }
133 }
134 
135 void
137 {
138  for (auto j = m_neighbours.begin(); j != m_neighbours.end(); j++)
139  {
140  (*j) = nullptr;
141  }
142  m_neighbours.clear();
143 }
144 
145 uint16_t
147 {
148  return (5 * m_numOfUnits);
149 }
150 
151 void
152 IeBeaconTiming::Print(std::ostream& os) const
153 {
154  os << "BeaconTiming=(Number of units=" << (uint16_t)m_numOfUnits;
155  for (auto j = m_neighbours.begin(); j != m_neighbours.end(); j++)
156  {
157  os << "(AID=" << (uint16_t)(*j)->GetAid() << ", Last beacon at=" << (*j)->GetLastBeacon()
158  << ", with beacon interval=" << (*j)->GetBeaconInterval() << ")";
159  }
160  os << ")";
161 }
162 
163 void
165 {
166  for (auto j = m_neighbours.begin(); j != m_neighbours.end(); j++)
167  {
168  i.WriteU8((*j)->GetAid());
169  i.WriteHtolsbU16((*j)->GetLastBeacon());
170  i.WriteHtolsbU16((*j)->GetBeaconInterval());
171  }
172 }
173 
174 uint16_t
176 {
178  m_numOfUnits = length / 5;
179  for (int j = 0; j < m_numOfUnits; j++)
180  {
181  Ptr<IeBeaconTimingUnit> new_element = Create<IeBeaconTimingUnit>();
182  new_element->SetAid(i.ReadU8());
183  new_element->SetLastBeacon(i.ReadLsbtohU16());
184  new_element->SetBeaconInterval(i.ReadLsbtohU16());
185  m_neighbours.push_back(new_element);
186  }
187  return i.GetDistanceFrom(start);
188 }
189 
190 uint16_t
192 {
193  return ((uint16_t)((t.GetMicroSeconds() >> 8) & 0xffff));
194 }
195 
196 uint16_t
198 {
199  return ((uint16_t)(t.GetMicroSeconds() >> 10) & 0xffff);
200 }
201 
202 uint8_t
204 {
205  return (uint8_t)(x & 0xff);
206 }
207 
208 bool
210 {
211  return ((a.GetAid() == b.GetAid()) && (a.GetLastBeacon() == b.GetLastBeacon()) &&
212  (a.GetBeaconInterval() == b.GetBeaconInterval()));
213 }
214 
215 bool
217 {
218  try
219  {
220  const auto& aa = dynamic_cast<const IeBeaconTiming&>(a);
221 
222  if (m_numOfUnits != aa.m_numOfUnits)
223  {
224  return false;
225  }
226  for (unsigned int i = 0; i < m_neighbours.size(); i++)
227  {
228  if (!(*PeekPointer(m_neighbours[i]) == *PeekPointer(aa.m_neighbours[i])))
229  {
230  return false;
231  }
232  }
233  return true;
234  }
235  catch (std::bad_cast&)
236  {
237  return false;
238  }
239 }
240 
241 std::ostream&
242 operator<<(std::ostream& os, const IeBeaconTiming& a)
243 {
244  a.Print(os);
245  return os;
246 }
247 } // namespace dot11s
248 } // namespace ns3
iterator in a Buffer instance
Definition: buffer.h:100
void WriteHtolsbU16(uint16_t data)
Definition: buffer.cc:902
uint8_t ReadU8()
Definition: buffer.h:1027
void WriteU8(uint8_t data)
Definition: buffer.h:881
uint16_t ReadLsbtohU16()
Definition: buffer.cc:1064
uint32_t GetDistanceFrom(const Iterator &o) const
Definition: buffer.cc:780
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:413
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.
uint8_t WifiInformationElementId
This type is used to represent an Information Element ID.
U * PeekPointer(const Ptr< U > &p)
Definition: ptr.h:449
#define IE_BEACON_TIMING