A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  * Authors: Dean Armstrong <deanarm@gmail.com>
19  */
20 
21 #include "ns3/wifi-information-element.h"
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  i.WriteU8 (ElementId ());
47  return i;
48 }
49 
52 {
54  i = DeserializeIfPresent (i);
55  // This IE was not optional, so confirm that we did actually
56  // deserialise something.
57  NS_ASSERT (i.GetDistanceFrom (start) != 0);
58  return i;
59 }
60 
63 {
65  uint8_t elementId = i.ReadU8 ();
66 
67  // If the element here isn't the one we're after then we immediately
68  // return the iterator we were passed indicating that we haven't
69  // taken anything from the buffer.
70  if (elementId != ElementId ())
71  {
72  return start;
73  }
74 
75  uint8_t length = i.ReadU8 ();
76 
77  DeserializeInformationField (i, length);
78  i.Next (length);
79 
80  return i;
81 }
82 
83 
84 bool
86 {
87  return (ElementId () < a.ElementId ());
88 }
89 
90 bool
92 {
93  if (ElementId () != a.ElementId ())
94  {
95  return false;
96  }
97 
99  {
100  return false;
101  }
102 
103  uint32_t ieSize = GetInformationFieldSize ();
104 
105  Buffer myIe, hisIe;
106  myIe.AddAtEnd (ieSize);
107  hisIe.AddAtEnd (ieSize);
108 
110  a.SerializeInformationField (hisIe.Begin ());
111 
112  return (memcmp (myIe.PeekData (), hisIe.PeekData (), ieSize) == 0);
113 }
114 
115 }
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 uint8_t GetInformationFieldSize() const =0
Length of serialized information (i.e., the length of the body of the IE, not including the Element I...
automatically resized byte buffer
Definition: buffer.h:92
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:61
virtual WifiInformationElementId ElementId() const =0
Own unique Element ID.
Buffer::Iterator Deserialize(Buffer::Iterator i)
Deserialize entire IE, which must be present.
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:811
uint16_t GetSerializedSize() const
Get the size of the serialized IE including Element ID and length fields.
iterator in a Buffer instance
Definition: buffer.h:98
Information element, as defined in 802.11-2007 standardThe IEEE 802.11 standard includes the notion o...
uint8_t const * PeekData(void) const
Definition: buffer.cc:733
Buffer::Iterator DeserializeIfPresent(Buffer::Iterator i)
Deserialize entire IE if it is present.
void Next(void)
go forward by one byte
Definition: buffer.h:852
virtual bool operator<(WifiInformationElement const &a) const
Compare information elements using Element ID.
Buffer::Iterator Begin(void) const
Definition: buffer.h:1076
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 void Print(std::ostream &os) const
In addition, a subclass may optionally override the following...
bool AddAtEnd(uint32_t end)
Definition: buffer.cc:360
void WriteU8(uint8_t data)
Definition: buffer.h:876
uint8_t ReadU8(void)
Definition: buffer.h:1028
virtual bool operator==(WifiInformationElement const &a) const
Compare two IEs for equality by ID & Length, and then through memcmp of serialised version...
Buffer::Iterator Serialize(Buffer::Iterator i) const
Serialize entire IE including Element ID and length fields.