A Discrete-Event Network Simulator
API
ie-dot11s-beacon-timing.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
22#include "ns3/packet.h"
23namespace ns3 {
24namespace dot11s {
25/*******************************************
26 * IeBeaconTimingUnit
27 *******************************************/
29 m_aid (0), m_lastBeacon (0), m_beaconInterval (0)
30{
31}
32void
34{
35 m_aid = aid;
36}
37void
39{
40 m_lastBeacon = lastBeacon;
41}
42void
44{
45 m_beaconInterval = beaconInterval;
46}
47uint8_t
49{
50 return m_aid;
51}
52uint16_t
54{
55 return m_lastBeacon;
56}
57uint16_t
59{
60 return m_beaconInterval;
61}
62/*******************************************
63 * IeBeaconTiming
64 *******************************************/
67{
68 return IE_BEACON_TIMING;
69}
71 m_numOfUnits (0)
72{
73}
76{
77 return m_neighbours;
78}
79void
80IeBeaconTiming::AddNeighboursTimingElementUnit (uint16_t aid, Time last_beacon, Time beacon_interval)
81{
82 if (m_numOfUnits == 50)
83 {
84 return;
85 }
86 //First we lookup if this element already exists
87 for (NeighboursTimingUnitsList::const_iterator i = m_neighbours.begin (); i != m_neighbours.end (); i++)
88 {
89 if (((*i)->GetAid () == AidToU8 (aid)) && ((*i)->GetLastBeacon () == TimestampToU16 (last_beacon))
90 && ((*i)->GetBeaconInterval () == BeaconIntervalToU16 (beacon_interval)))
91 {
92 return;
93 }
94 }
95 Ptr<IeBeaconTimingUnit> new_element = Create<IeBeaconTimingUnit> ();
96 new_element->SetAid (AidToU8 (aid));
97 new_element->SetLastBeacon (TimestampToU16 (last_beacon));
98 new_element->SetBeaconInterval (BeaconIntervalToU16 (beacon_interval));
99 m_neighbours.push_back (new_element);
100 m_numOfUnits++;
101}
102void
103IeBeaconTiming::DelNeighboursTimingElementUnit (uint16_t aid, Time last_beacon, Time beacon_interval)
104{
105 for (NeighboursTimingUnitsList::iterator i = m_neighbours.begin (); i != m_neighbours.end (); i++)
106 {
107 if (((*i)->GetAid () == AidToU8 (aid)) && ((*i)->GetLastBeacon () == TimestampToU16 (last_beacon))
108 && ((*i)->GetBeaconInterval () == BeaconIntervalToU16 (beacon_interval)))
109 {
110 m_neighbours.erase (i);
111 m_numOfUnits--;
112 break;
113 }
114 }
115}
116void
118{
119 for (NeighboursTimingUnitsList::iterator j = m_neighbours.begin (); j != m_neighbours.end (); j++)
120 {
121 (*j) = 0;
122 }
123 m_neighbours.clear ();
124}
125uint8_t
127{
128 return (5 * m_numOfUnits );
129}
130void
131IeBeaconTiming::Print (std::ostream& os) const
132{
133 os << "BeaconTiming=(Number of units=" << (uint16_t) m_numOfUnits;
134 for (NeighboursTimingUnitsList::const_iterator j = m_neighbours.begin (); j != m_neighbours.end (); j++)
135 {
136 os << "(AID=" << (uint16_t)(*j)->GetAid () << ", Last beacon at=" << (*j)->GetLastBeacon ()
137 << ", with beacon interval=" << (*j)->GetBeaconInterval () << ")";
138 }
139 os << ")";
140}
141void
143{
144 for (NeighboursTimingUnitsList::const_iterator j = m_neighbours.begin (); j != m_neighbours.end (); j++)
145 {
146 i.WriteU8 ((*j)->GetAid ());
147 i.WriteHtolsbU16 ((*j)->GetLastBeacon ());
148 i.WriteHtolsbU16 ((*j)->GetBeaconInterval ());
149 }
150}
151uint8_t
153{
155 m_numOfUnits = length / 5;
156 for (int j = 0; j < m_numOfUnits; j++)
157 {
158 Ptr<IeBeaconTimingUnit> new_element = Create<IeBeaconTimingUnit> ();
159 new_element->SetAid (i.ReadU8 ());
160 new_element->SetLastBeacon (i.ReadLsbtohU16 ());
161 new_element->SetBeaconInterval (i.ReadLsbtohU16 ());
162 m_neighbours.push_back (new_element);
163 }
164 return i.GetDistanceFrom (start);
165}
166;
167uint16_t
169{
170 return ((uint16_t)((t.GetMicroSeconds () >> 8) & 0xffff));
171}
172;
173
174uint16_t
176{
177 return ((uint16_t)(t.GetMicroSeconds () >> 10) & 0xffff);
178}
179uint8_t
181{
182 return (uint8_t)(x & 0xff);
183}
184bool
186{
187 return ((a.GetAid () == b.GetAid ()) && (a.GetLastBeacon () == b.GetLastBeacon ())
188 && (a.GetBeaconInterval () == b.GetBeaconInterval ()));
189}
190bool
192{
193 try {
194 IeBeaconTiming const & aa = dynamic_cast<IeBeaconTiming const &>(a);
195
196 if (m_numOfUnits != aa.m_numOfUnits)
197 {
198 return false;
199 }
200 for (unsigned int i = 0; i < m_neighbours.size (); i++)
201 {
202 if (!(*PeekPointer (m_neighbours[i]) == *PeekPointer (aa.m_neighbours[i])))
203 {
204 return false;
205 }
206 }
207 return true;
208 }
209 catch (std::bad_cast&)
210 {
211 return false;
212 }
213}
214std::ostream &
215operator << (std::ostream &os, const IeBeaconTiming &a)
216{
217 a.Print (os);
218 return os;
219}
220} // namespace dot11s
221} // namespace ns3
222
iterator in a Buffer instance
Definition: buffer.h:99
void WriteHtolsbU16(uint16_t data)
Definition: buffer.cc:911
void WriteU8(uint8_t data)
Definition: buffer.h:869
uint8_t ReadU8(void)
Definition: buffer.h:1021
uint16_t ReadLsbtohU16(void)
Definition: buffer.cc:1066
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:788
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
int64_t GetMicroSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:387
Information element, as defined in 802.11-2007 standard.
See 7.3.2.89 of 802.11s draft 2.07.
bool operator==(WifiInformationElement const &a) const
equality operator
virtual void Print(std::ostream &os) const
Generate human-readable form of IE.
virtual uint8_t GetInformationFieldSize() const
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.
virtual uint8_t DeserializeInformationField(Buffer::Iterator i, uint8_t length)
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:
virtual WifiInformationElementId ElementId() const
static uint8_t AidToU8(uint16_t x)
Aid to U8 function.
NeighboursTimingUnitsList m_neighbours
the neighbors
static uint16_t TimestampToU16(Time x)
Timestamp to U16 function.
virtual void SerializeInformationField(Buffer::Iterator i) const
Serialize information (i.e., the body of the IE, not including the Element ID and length octets)
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:415
uint8_t WifiInformationElementId
This type is used to represent an Information Element ID.
list x
Random number samples.
def start()
Definition: core.py:1853
#define IE_BEACON_TIMING