A Discrete-Event Network Simulator
API
wifi-information-element.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2010 Dean Armstrong
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: Dean Armstrong <deanarm@gmail.com>
19  */
20 
22 
23 namespace ns3 {
24 
26 {
27 }
28 
29 void
30 WifiInformationElement::Print (std::ostream &os) const
31 {
32 }
33 
34 uint16_t
36 {
37  return (2 + GetInformationFieldSize ());
38 }
39 
42 {
43  return 0;
44 }
45 
48 {
49  i.WriteU8 (ElementId ());
51  if (ElementId () == IE_EXTENSION)
52  {
53  i.WriteU8 (ElementIdExt ());
55  i.Next (GetInformationFieldSize () - 1);
56  }
57  else
58  {
61  }
62  return i;
63 }
64 
67 {
69  i = DeserializeIfPresent (i);
70  //This IE was not optional, so confirm that we did actually
71  //deserialise something.
72  NS_ASSERT (i.GetDistanceFrom (start) != 0);
73  return i;
74 }
75 
78 {
79  if (i.IsEnd ())
80  {
81  return i;
82  }
84  uint8_t elementId = i.ReadU8 ();
85 
86  //If the element here isn't the one we're after then we immediately
87  //return the iterator we were passed indicating that we haven't
88  //taken anything from the buffer.
89  if (elementId != ElementId ())
90  {
91  return start;
92  }
93 
94  uint8_t length = i.ReadU8 ();
95  if (ElementId () == IE_EXTENSION)
96  {
97  uint8_t elementIdExt = i.ReadU8 ();
98  //If the element here isn't the one we're after then we immediately
99  //return the iterator we were passed indicating that we haven't
100  //taken anything from the buffer.
101  if (elementIdExt != ElementIdExt ())
102  {
103  return start;
104  }
105  DeserializeInformationField (i, length - 1);
106  i.Next (length - 1);
107  }
108  else
109  {
110  DeserializeInformationField (i, length);
111  i.Next (length);
112  }
113  return i;
114 }
115 
116 bool
118 {
119  if (ElementId () != a.ElementId ())
120  {
121  return false;
122  }
123 
125  {
126  return false;
127  }
128 
129  if (ElementIdExt () != a.ElementIdExt ())
130  {
131  return false;
132  }
133 
134  uint32_t ieSize = GetInformationFieldSize ();
135 
136  Buffer myIe, hisIe;
137  myIe.AddAtEnd (ieSize);
138  hisIe.AddAtEnd (ieSize);
139 
141  a.SerializeInformationField (hisIe.Begin ());
142 
143  return (memcmp (myIe.PeekData (), hisIe.PeekData (), ieSize) == 0);
144 }
145 
146 } //namespace ns3
iterator in a Buffer instance
Definition: buffer.h:99
bool IsEnd(void) const
Definition: buffer.cc:804
void WriteU8(uint8_t data)
Definition: buffer.h:869
void Next(void)
go forward by one byte
Definition: buffer.h:845
uint8_t ReadU8(void)
Definition: buffer.h:1021
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:788
automatically resized byte buffer
Definition: buffer.h:93
void AddAtEnd(uint32_t end)
Definition: buffer.cc:354
uint8_t const * PeekData(void) const
Definition: buffer.cc:710
Buffer::Iterator Begin(void) const
Definition: buffer.h:1069
Information element, as defined in 802.11-2007 standard.
virtual uint8_t GetInformationFieldSize() const =0
Length of serialized information (i.e., the length of the body of the IE, not including the Element I...
virtual WifiInformationElementId ElementId() const =0
virtual uint16_t GetSerializedSize() const
Get the size of the serialized IE including Element ID and length fields.
Buffer::Iterator Deserialize(Buffer::Iterator i)
Deserialize entire IE, which must be present.
virtual bool operator==(WifiInformationElement const &a) const
Compare two IEs for equality by ID & Length, and then through memcmp of serialised version.
virtual Buffer::Iterator Serialize(Buffer::Iterator i) const
Serialize entire IE including Element ID and length fields.
Buffer::Iterator DeserializeIfPresent(Buffer::Iterator i)
Deserialize entire IE if it is present.
virtual uint8_t DeserializeInformationField(Buffer::Iterator start, uint8_t length)=0
Deserialize information (i.e., the body of the IE, not including the Element ID and length octets)
virtual void Print(std::ostream &os) const
Generate human-readable form of IE.
virtual void SerializeInformationField(Buffer::Iterator start) const =0
Serialize information (i.e., the body of the IE, not including the Element ID and length octets)
virtual WifiInformationElementId ElementIdExt() const
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:67
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.
def start()
Definition: core.py:1853
#define IE_EXTENSION