OLD | NEW |
(Empty) | |
| 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 |
| 21 #include "ie-dot11s-beacon-timing.h" |
| 22 #include "ns3/packet.h" |
| 23 namespace ns3 { |
| 24 namespace dot11s { |
| 25 /******************************************* |
| 26 * IeBeaconTimingUnit |
| 27 *******************************************/ |
| 28 IeBeaconTimingUnit::IeBeaconTimingUnit () : |
| 29 m_aid (0), m_lastBeacon (0), m_beaconInterval (0) |
| 30 { |
| 31 } |
| 32 void |
| 33 IeBeaconTimingUnit::SetAid (uint8_t aid) |
| 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 |
| 48 IeBeaconTimingUnit::GetAid () const |
| 49 { |
| 50 return m_aid; |
| 51 } |
| 52 uint16_t |
| 53 IeBeaconTimingUnit::GetLastBeacon () const |
| 54 { |
| 55 return m_lastBeacon; |
| 56 } |
| 57 uint16_t |
| 58 IeBeaconTimingUnit::GetBeaconInterval () const |
| 59 { |
| 60 return m_beaconInterval; |
| 61 } |
| 62 /******************************************* |
| 63 * IeBeaconTiming |
| 64 *******************************************/ |
| 65 WifiElementId |
| 66 IeBeaconTiming::ElementId () const |
| 67 { |
| 68 return IE11S_BEACON_TIMING; |
| 69 } |
| 70 IeBeaconTiming::IeBeaconTiming () : |
| 71 m_numOfUnits (0) |
| 72 { |
| 73 } |
| 74 IeBeaconTiming::NeighboursTimingUnitsList |
| 75 IeBeaconTiming::GetNeighboursTimingElementsList () |
| 76 { |
| 77 return m_neighbours; |
| 78 } |
| 79 void |
| 80 IeBeaconTiming::AddNeighboursTimingElementUnit (uint16_t aid, Time last_beacon,
//MicroSeconds! |
| 81 Time beacon_interval //MicroSeconds! |
| 82 ) |
| 83 { |
| 84 if (m_numOfUnits == 50) |
| 85 { |
| 86 return; |
| 87 } |
| 88 //First we lookup if this element already exists |
| 89 for (NeighboursTimingUnitsList::const_iterator i = m_neighbours.begin (); i !=
m_neighbours.end (); i++) |
| 90 { |
| 91 if (((*i)->GetAid () == AidToU8 (aid)) && ((*i)->GetLastBeacon () == Times
tampToU16 (last_beacon)) |
| 92 && ((*i)->GetBeaconInterval () == BeaconIntervalToU16 (beacon_interval
))) |
| 93 { |
| 94 return; |
| 95 } |
| 96 } |
| 97 Ptr<IeBeaconTimingUnit> new_element = Create<IeBeaconTimingUnit> (); |
| 98 new_element->SetAid (AidToU8 (aid)); |
| 99 new_element->SetLastBeacon (TimestampToU16 (last_beacon)); |
| 100 new_element->SetBeaconInterval (BeaconIntervalToU16 (beacon_interval)); |
| 101 m_neighbours.push_back (new_element); |
| 102 m_numOfUnits++; |
| 103 } |
| 104 void |
| 105 IeBeaconTiming::DelNeighboursTimingElementUnit (uint16_t aid, Time last_beacon,
Time beacon_interval) |
| 106 { |
| 107 for (NeighboursTimingUnitsList::iterator i = m_neighbours.begin (); i != m_nei
ghbours.end (); i++) |
| 108 { |
| 109 if (((*i)->GetAid () == AidToU8 (aid)) && ((*i)->GetLastBeacon () == Times
tampToU16 (last_beacon)) |
| 110 && ((*i)->GetBeaconInterval () == BeaconIntervalToU16 (beacon_interval
))) |
| 111 { |
| 112 m_neighbours.erase (i); |
| 113 m_numOfUnits--; |
| 114 break; |
| 115 } |
| 116 } |
| 117 } |
| 118 void |
| 119 IeBeaconTiming::ClearTimingElement () |
| 120 { |
| 121 uint16_t to_delete = 0; |
| 122 uint16_t i; |
| 123 for (NeighboursTimingUnitsList::iterator j = m_neighbours.begin (); j != m_nei
ghbours.end (); j++) |
| 124 { |
| 125 to_delete++; |
| 126 (*j) = 0; |
| 127 } |
| 128 for (i = 0; i < to_delete; i++) |
| 129 { |
| 130 m_neighbours.pop_back (); |
| 131 } |
| 132 m_neighbours.clear (); |
| 133 |
| 134 } |
| 135 uint8_t |
| 136 IeBeaconTiming::GetInformationSize () const |
| 137 { |
| 138 return (5 * m_numOfUnits ); |
| 139 } |
| 140 void |
| 141 IeBeaconTiming::Print (std::ostream& os) const |
| 142 { |
| 143 os << std::endl << "<information_element id=" << ElementId () << ">" << std::e
ndl; |
| 144 os << "Number of units: " << (uint16_t) m_numOfUnits << std::endl; |
| 145 for (NeighboursTimingUnitsList::const_iterator j = m_neighbours.begin (); j !=
m_neighbours.end (); j++) |
| 146 { |
| 147 os << "AID=" << (uint16_t) (*j)->GetAid () << ", Last beacon was at " << (
*j)->GetLastBeacon () |
| 148 << ", with beacon interval " << (*j)->GetBeaconInterval () << std::end
l; |
| 149 } |
| 150 os << "</information_element>" << std::endl; |
| 151 } |
| 152 void |
| 153 IeBeaconTiming::SerializeInformation (Buffer::Iterator i) const |
| 154 { |
| 155 for (NeighboursTimingUnitsList::const_iterator 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 uint8_t |
| 163 IeBeaconTiming::DeserializeInformation (Buffer::Iterator start, uint8_t length) |
| 164 { |
| 165 Buffer::Iterator i = start; |
| 166 m_numOfUnits = length / 5; |
| 167 for (int j = 0; j < m_numOfUnits; j++) |
| 168 { |
| 169 Ptr<IeBeaconTimingUnit> new_element = Create<IeBeaconTimingUnit> (); |
| 170 new_element->SetAid (i.ReadU8 ()); |
| 171 new_element->SetLastBeacon (i.ReadLsbtohU16 ()); |
| 172 new_element->SetBeaconInterval (i.ReadLsbtohU16 ()); |
| 173 m_neighbours.push_back (new_element); |
| 174 } |
| 175 return i.GetDistanceFrom (start); |
| 176 } |
| 177 ; |
| 178 uint16_t |
| 179 IeBeaconTiming::TimestampToU16 (Time t) |
| 180 { |
| 181 return ((uint16_t) ((t.GetMicroSeconds () >> 8) & 0xffff)); |
| 182 } |
| 183 ; |
| 184 |
| 185 uint16_t |
| 186 IeBeaconTiming::BeaconIntervalToU16 (Time t) |
| 187 { |
| 188 return ((uint16_t) (t.GetMicroSeconds () >> 10) & 0xffff); |
| 189 } |
| 190 uint8_t |
| 191 IeBeaconTiming::AidToU8 (uint16_t x) |
| 192 { |
| 193 return (uint8_t) (x & 0xff); |
| 194 } |
| 195 bool |
| 196 operator== (const IeBeaconTimingUnit & a, const IeBeaconTimingUnit & b) |
| 197 { |
| 198 return ((a.GetAid () == b.GetAid ()) && (a.GetLastBeacon () == b.GetLastBeacon
()) |
| 199 && (a.GetBeaconInterval () == b.GetBeaconInterval ())); |
| 200 } |
| 201 bool |
| 202 operator== (const IeBeaconTiming & a, const IeBeaconTiming& b) |
| 203 { |
| 204 if (a.m_numOfUnits != b.m_numOfUnits) |
| 205 { |
| 206 return false; |
| 207 } |
| 208 for (unsigned int i = 0; i < a.m_neighbours.size (); i++) |
| 209 { |
| 210 if (!(*PeekPointer (a.m_neighbours[i]) == *PeekPointer (b.m_neighbours[i])
)) |
| 211 { |
| 212 return false; |
| 213 } |
| 214 } |
| 215 return true; |
| 216 } |
| 217 std::ostream & |
| 218 operator << (std::ostream &os, const IeBeaconTiming &a) |
| 219 { |
| 220 a.Print (os); |
| 221 return os; |
| 222 } |
| 223 } // namespace dot11s |
| 224 } //namespace ns3 |
| 225 |
OLD | NEW |