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 
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 {
64  if (i.IsEnd ())
65  {
66  return i;
67  }
69  uint8_t elementId = i.ReadU8 ();
70 
71  //If the element here isn't the one we're after then we immediately
72  //return the iterator we were passed indicating that we haven't
73  //taken anything from the buffer.
74  if (elementId != ElementId ())
75  {
76  return start;
77  }
78 
79  uint8_t length = i.ReadU8 ();
80 
81  DeserializeInformationField (i, length);
82  i.Next (length);
83 
84  return i;
85 }
86 
87 bool
89 {
90  return (ElementId () < a.ElementId ());
91 }
92 
93 bool
95 {
96  if (ElementId () != a.ElementId ())
97  {
98  return false;
99  }
100 
102  {
103  return false;
104  }
105 
106  uint32_t ieSize = GetInformationFieldSize ();
107 
108  Buffer myIe, hisIe;
109  myIe.AddAtEnd (ieSize);
110  hisIe.AddAtEnd (ieSize);
111 
113  a.SerializeInformationField (hisIe.Begin ());
114 
115  return (memcmp (myIe.PeekData (), hisIe.PeekData (), ieSize) == 0);
116 }
117 
118 } //namespace ns3
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
def start()
Definition: core.py:1482
#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
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:783
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...
bool IsEnd(void) const
Definition: buffer.cc:799
uint8_t const * PeekData(void) const
Definition: buffer.cc:705
Buffer::Iterator DeserializeIfPresent(Buffer::Iterator i)
Deserialize entire IE if it is present.
void Next(void)
go forward by one byte
Definition: buffer.h:844
virtual bool operator<(WifiInformationElement const &a) const
Compare information elements using Element ID.
Buffer::Iterator Begin(void) const
Definition: buffer.h:1068
void AddAtEnd(uint32_t end)
Definition: buffer.cc:354
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) ...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual void Print(std::ostream &os) const
Generate human-readable form of IE.
void WriteU8(uint8_t data)
Definition: buffer.h:868
uint8_t ReadU8(void)
Definition: buffer.h:1020
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.