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"
23 namespace ns3 {
24 namespace dot11s {
25 /*******************************************
26  * IeBeaconTimingUnit
27  *******************************************/
29  m_aid (0), m_lastBeacon (0), m_beaconInterval (0)
30 {
31 }
32 void
34 {
35  m_aid = aid;
36 }
37 void
38 IeBeaconTimingUnit::SetLastBeacon (uint16_t lastBeacon)
39 {
40  m_lastBeacon = lastBeacon;
41 }
42 void
43 IeBeaconTimingUnit::SetBeaconInterval (uint16_t beaconInterval)
44 {
45  m_beaconInterval = beaconInterval;
46 }
47 uint8_t
49 {
50  return m_aid;
51 }
52 uint16_t
54 {
55  return m_lastBeacon;
56 }
57 uint16_t
59 {
60  return m_beaconInterval;
61 }
62 /*******************************************
63  * IeBeaconTiming
64  *******************************************/
67 {
68  return IE11S_BEACON_TIMING;
69 }
71  m_numOfUnits (0)
72 {
73 }
76 {
77  return m_neighbours;
78 }
79 void
80 IeBeaconTiming::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 }
102 void
103 IeBeaconTiming::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 }
116 void
118 {
119  for (NeighboursTimingUnitsList::iterator j = m_neighbours.begin (); j != m_neighbours.end (); j++)
120  {
121  (*j) = 0;
122  }
123  m_neighbours.clear ();
124 }
125 uint8_t
127 {
128  return (5 * m_numOfUnits );
129 }
130 void
131 IeBeaconTiming::Print (std::ostream& os) const
132 {
133  os << std::endl << "<information_element id=" << ElementId () << ">" << std::endl;
134  os << "Number of units: " << (uint16_t) m_numOfUnits << std::endl;
135  for (NeighboursTimingUnitsList::const_iterator j = m_neighbours.begin (); j != m_neighbours.end (); j++)
136  {
137  os << "AID=" << (uint16_t)(*j)->GetAid () << ", Last beacon was at " << (*j)->GetLastBeacon ()
138  << ", with beacon interval " << (*j)->GetBeaconInterval () << std::endl;
139  }
140  os << "</information_element>" << std::endl;
141 }
142 void
144 {
145  for (NeighboursTimingUnitsList::const_iterator j = m_neighbours.begin (); j != m_neighbours.end (); j++)
146  {
147  i.WriteU8 ((*j)->GetAid ());
148  i.WriteHtolsbU16 ((*j)->GetLastBeacon ());
149  i.WriteHtolsbU16 ((*j)->GetBeaconInterval ());
150  }
151 }
152 uint8_t
154 {
156  m_numOfUnits = length / 5;
157  for (int j = 0; j < m_numOfUnits; j++)
158  {
159  Ptr<IeBeaconTimingUnit> new_element = Create<IeBeaconTimingUnit> ();
160  new_element->SetAid (i.ReadU8 ());
161  new_element->SetLastBeacon (i.ReadLsbtohU16 ());
162  new_element->SetBeaconInterval (i.ReadLsbtohU16 ());
163  m_neighbours.push_back (new_element);
164  }
165  return i.GetDistanceFrom (start);
166 }
167 ;
168 uint16_t
170 {
171  return ((uint16_t)((t.GetMicroSeconds () >> 8) & 0xffff));
172 }
173 ;
174 
175 uint16_t
177 {
178  return ((uint16_t)(t.GetMicroSeconds () >> 10) & 0xffff);
179 }
180 uint8_t
182 {
183  return (uint8_t)(x & 0xff);
184 }
185 bool
187 {
188  return ((a.GetAid () == b.GetAid ()) && (a.GetLastBeacon () == b.GetLastBeacon ())
189  && (a.GetBeaconInterval () == b.GetBeaconInterval ()));
190 }
191 bool
193 {
194  try {
195  IeBeaconTiming const & aa = dynamic_cast<IeBeaconTiming const &>(a);
196 
197  if (m_numOfUnits != aa.m_numOfUnits)
198  {
199  return false;
200  }
201  for (unsigned int i = 0; i < m_neighbours.size (); i++)
202  {
203  if (!(*PeekPointer (m_neighbours[i]) == *PeekPointer (aa.m_neighbours[i])))
204  {
205  return false;
206  }
207  }
208  return true;
209  }
210  catch (std::bad_cast)
211  {
212  return false;
213  }
214 }
215 std::ostream &
216 operator << (std::ostream &os, const IeBeaconTiming &a)
217 {
218  a.Print (os);
219  return os;
220 }
221 } // namespace dot11s
222 } // namespace ns3
223 
uint8_t m_aid
Least significant octet of AID:
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:95
NeighboursTimingUnitsList m_neighbours
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) ...
def start()
Definition: core.py:1482
uint16_t m_lastBeacon
Last time we received a beacon in accordance with a local TSF measured in 256 microseconds unit...
U * PeekPointer(const Ptr< U > &p)
Definition: ptr.h:562
NeighboursTimingUnitsList GetNeighboursTimingElementsList()
This methods are needed for beacon collision avoidance module:
bool operator==(const MeshHeader &a, const MeshHeader &b)
std::vector< Ptr< IeBeaconTimingUnit > > NeighboursTimingUnitsList
This type is a list of timing elements obtained from neighbours with their beacons: ...
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:811
iterator in a Buffer instance
Definition: buffer.h:98
void SetBeaconInterval(uint16_t beaconInterval)
Information element, as defined in 802.11-2007 standardThe IEEE 802.11 standard includes the notion o...
int64_t GetMicroSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:335
static uint16_t BeaconIntervalToU16(Time x)
See 7.3.2.89 of 802.11s draft 2.07.
uint16_t m_numOfUnits
Timing element parameters:
#define IE11S_BEACON_TIMING
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...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void WriteHtolsbU16(uint16_t data)
Definition: buffer.cc:939
static uint16_t TimestampToU16(Time x)
Converters:
void WriteU8(uint8_t data)
Definition: buffer.h:876
uint16_t m_beaconInterval
Beacon interval of remote mesh point.
virtual WifiInformationElementId ElementId() const
Own unique Element ID.
uint8_t ReadU8(void)
Definition: buffer.h:1028
void DelNeighboursTimingElementUnit(uint16_t aid, Time last_beacon, Time beacon_interval)
uint16_t ReadLsbtohU16(void)
Definition: buffer.cc:1094
uint8_t WifiInformationElementId
This type is used to represent an Information Element ID.
void AddNeighboursTimingElementUnit(uint16_t aid, Time last_beacon, Time beacon_interval)
void SetLastBeacon(uint16_t lastBeacon)
std::ostream & operator<<(std::ostream &os, const IeBeaconTiming &a)
virtual void SerializeInformationField(Buffer::Iterator i) const
Serialize information (i.e., the body of the IE, not including the Element ID and length octets) ...
Describes one unit of beacon timing element.
static uint8_t AidToU8(uint16_t x)
bool operator==(WifiInformationElement const &a) const
Compare two IEs for equality by ID & Length, and then through memcmp of serialised version...