A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
vendor-specific-action.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013 Dalian University of Technology
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Junling Bu <linlinjavaer@gmail.com>
18  */
19 #include <iomanip>
20 #include <iostream>
21 #include <cstring>
22 #include "ns3/log.h"
23 #include "ns3/assert.h"
24 #include "vendor-specific-action.h"
25 
26 NS_LOG_COMPONENT_DEFINE ("VendorSpecificAction");
27 
28 namespace ns3 {
29 
30 /*********** OrganizationIdentifier *******/
31 
32 ATTRIBUTE_HELPER_CPP (OrganizationIdentifier);
33 
35  : m_type (Unknown)
36 {
37  NS_LOG_FUNCTION (this);
38  m_type = Unknown;
39  std::memset (m_oi, 0, 5);
40 }
41 
42 OrganizationIdentifier::OrganizationIdentifier (const uint8_t *str, uint32_t length)
43 {
44  NS_LOG_FUNCTION (this << str << length);
45  if (length == 3)
46  {
47  m_type = OUI24;
48  std::memcpy (m_oi, str, length);
49  }
50  else if (length == 5)
51  {
52  m_type = OUI36;
53  std::memcpy (m_oi, str, length);
54  }
55  else
56  {
57  m_type = Unknown;
58  NS_FATAL_ERROR ("cannot support organization identifier with length=" << length);
59  }
60 }
61 
64 {
65  this->m_type = oi.m_type;
66  std::memcpy (this->m_oi, oi.m_oi, 5);
67  return (*this);
68 }
69 
71 {
72  NS_LOG_FUNCTION (this);
73 }
74 
75 uint8_t
77 {
78  NS_LOG_FUNCTION (this);
79  NS_ASSERT (m_type == OUI36);
80  return (m_oi[4] & 0x0f);
81 }
82 
83 bool
85 {
86  NS_LOG_FUNCTION (this);
87  return m_type == Unknown;
88 }
89 
90 uint32_t
92 {
93  NS_LOG_FUNCTION (this);
94  switch (m_type)
95  {
96  case OUI24:
97  return 3;
98  case OUI36:
99  return 5;
100  case Unknown:
101  default:
103  return 0;
104  }
105 }
106 
107 void
109 {
110  NS_LOG_FUNCTION (this);
111  m_type = type;
112 }
113 
116 {
117  NS_LOG_FUNCTION (this);
118  return m_type;
119 }
120 
121 void
123 {
124  NS_LOG_FUNCTION (this << &start);
125  start.Write (m_oi, GetSerializedSize ());
126 }
127 
128 /* because OrganizationIdentifier field is not standard
129  * and the length of OrganizationIdentifier is variable
130  * so data parse here is troublesome
131  */
132 uint32_t
134 {
135  NS_LOG_FUNCTION (this << &start);
136  // first try to parse OUI24 with 3 bytes
137  start.Read (m_oi, 3);
138  for (std::vector<OrganizationIdentifier>::iterator i = OrganizationIdentifiers.begin (); i != OrganizationIdentifiers.end (); ++i)
139  {
140  if ((i->m_type == OUI24)
141  && (std::memcmp (i->m_oi, m_oi, 3) == 0 ))
142  {
143  m_type = OUI24;
144  return 3;
145  }
146  }
147 
148  // then try to parse OUI36 with 5 bytes
149  start.Read (m_oi + 3, 2);
150  for (std::vector<OrganizationIdentifier>::iterator i = OrganizationIdentifiers.begin (); i != OrganizationIdentifiers.end (); ++i)
151  {
152  if ((i->m_type == OUI36)
153  && (std::memcmp (i->m_oi, m_oi, 4) == 0 ))
154  {
155  // OUI36 first check 4 bytes, then check half of the 5th byte
156  if ((i->m_oi[4] & 0xf0) == (m_oi[4] & 0xf0))
157  {
158  m_type = OUI36;
159  return 5;
160  }
161  }
162  }
163 
164  // if we cannot deserialize the organization identifier field,
165  // we will fail
166  NS_FATAL_ERROR ("cannot deserialize the organization identifier field successfully");
167  return 0;
168 }
169 
171 {
172  if (a.m_type != b.m_type)
173  {
174  return false;
175  }
176 
178  {
179  return memcmp (a.m_oi, b.m_oi, 3) == 0;
180  }
181 
183  {
184  return (memcmp (a.m_oi, b.m_oi, 4) == 0)
185  && ((a.m_oi[4] & 0xf0) == (b.m_oi[4] & 0xf0));
186  }
187 
188  return false;
189 }
190 
192 {
193  return !(a == b);
194 }
195 
197 {
198  return memcmp (a.m_oi, b.m_oi, std::min (a.m_type, b.m_type)) < 0;
199 }
200 
201 std::ostream& operator << (std::ostream& os, const OrganizationIdentifier& oi)
202 {
203  for (int i = 0; i < oi.m_type; i++)
204  {
205  os << "0x" << std::hex << static_cast<int> (oi.m_oi[i]) << " ";
206  }
207  os << std::endl;
208  return os;
209 }
210 
211 std::istream& operator >> (std::istream& is, const OrganizationIdentifier& oi)
212 {
213  return is;
214 }
215 
216 /*********** VendorSpecificActionHeader *******/
217 NS_OBJECT_ENSURE_REGISTERED (VendorSpecificActionHeader);
218 
220  : m_oi (),
221  m_category (CATEGORY_OF_VSA)
222 {
223  NS_LOG_FUNCTION (this);
224 }
225 
227 {
228  NS_LOG_FUNCTION (this);
229 }
230 
231 void
233 {
234  NS_LOG_FUNCTION (this << oi);
235  m_oi = oi;
236 }
237 
240 {
241  NS_LOG_FUNCTION (this);
242  return m_oi;
243 }
244 
245 TypeId
247 {
248  static TypeId tid = TypeId ("ns3::VendorSpecificActionHeader")
249  .SetParent<Header> ()
250  .AddConstructor<VendorSpecificActionHeader> ()
251  ;
252 
253  return tid;
254 }
255 
256 uint8_t
258 {
259  NS_LOG_FUNCTION (this);
260  return m_category;
261 }
262 
263 TypeId
265 {
266  NS_LOG_FUNCTION (this);
267  return GetTypeId ();
268 }
269 
270 void
271 VendorSpecificActionHeader::Print (std::ostream &os) const
272 {
273  NS_LOG_FUNCTION (this << &os);
274  os << "VendorSpecificActionHeader[ "
275  << "category = 0x" << std::hex << (int)m_category
276  << "organization identifier = " << m_oi
277  << std::dec;
278 }
279 
280 uint32_t
282 {
283  NS_LOG_FUNCTION (this);
284  return sizeof(m_category) + m_oi.GetSerializedSize ();
285 }
286 
287 void
289 {
290  NS_LOG_FUNCTION (this << &start);
291  start.WriteU8 (m_category);
292  m_oi.Serialize (start);
293 }
294 
295 uint32_t
297 {
298  NS_LOG_FUNCTION (this << &start);
299  m_category = start.ReadU8 ();
301  {
302  return 0;
303  }
304  m_oi.Deserialize (start);
305 
306  return GetSerializedSize ();
307 }
308 
309 /********* VendorSpecificContentManager ***********/
311 {
312  NS_LOG_FUNCTION (this);
313 }
314 
316 {
317  NS_LOG_FUNCTION (this);
318 }
319 
320 void
322 {
323  NS_LOG_FUNCTION (this << oi << &cb);
324  m_callbacks.insert (std::make_pair (oi, cb));
325  OrganizationIdentifiers.push_back (oi);
326 }
327 
328 void
330 {
331  NS_LOG_FUNCTION (this << oi);
332  m_callbacks.erase (oi);
333 }
334 
335 static VscCallback null_callback = MakeNullCallback<bool, Ptr<WifiMac>, const OrganizationIdentifier &,Ptr<const Packet>,const Address &> ();
336 
339 {
340  NS_LOG_FUNCTION (this << oi);
341  VscCallbacksI i;
342  i = m_callbacks.find (oi);
343  return (i == m_callbacks.end ()) ? null_callback : i->second;
344 }
345 
346 } // namespace ns3
Protocol header serialization and deserialization.
Definition: header.h:42
void Serialize(Buffer::Iterator start) const
std::istream & operator>>(std::istream &is, Angles &a)
initialize a struct Angles from input
Definition: angles.cc:49
uint32_t GetSerializedSize(void) const
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
Callback template class.
Definition: callback.h:920
void RegisterVscCallback(OrganizationIdentifier oi, VscCallback cb)
virtual TypeId GetInstanceTypeId(void) const
#define NS_FATAL_ERROR_NO_MSG()
fatal error handling
Definition: fatal-error.h:44
virtual void Serialize(Buffer::Iterator start) const
uint32_t Deserialize(Buffer::Iterator start)
#define NS_ASSERT(condition)
Definition: assert.h:64
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
bool operator<(const Room &a, const Room &b)
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:72
void SetType(enum OrganizationIdentifierType type)
iterator in a Buffer instance
Definition: buffer.h:98
a polymophic address class
Definition: address.h:86
void DeregisterVscCallback(OrganizationIdentifier &oi)
enum OrganizationIdentifierType GetType() const
void SetOrganizationIdentifier(OrganizationIdentifier oi)
the organization identifier is a public organizationally unique identifier assigned by the IEEE...
NS_LOG_COMPONENT_DEFINE("VendorSpecificAction")
virtual uint32_t GetSerializedSize(void) const
virtual void Print(std::ostream &os) const
uint8_t GetCategory() const
the category field shall be CATEGORY_OF_VSA
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:43
bool operator!=(Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 > a, Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 > b)
Inequality test.
Definition: callback.h:1213
void Read(uint8_t *buffer, uint32_t size)
Definition: buffer.cc:1148
OrganizationIdentifier & operator=(const OrganizationIdentifier &oi)
VscCallback FindVscCallback(OrganizationIdentifier &oi)
static const uint8_t CATEGORY_OF_VSA
see IEEE 802.11-2007 chapter 7.3.1.11 Table 7-24—Category values
static VscCallback null_callback
void WriteU8(uint8_t data)
Definition: buffer.h:690
static std::vector< OrganizationIdentifier > OrganizationIdentifiers
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.cc:89
uint8_t ReadU8(void)
Definition: buffer.h:819
void Write(uint8_t const *buffer, uint32_t size)
Definition: buffer.cc:978
OrganizationIdentifier GetOrganizationIdentifier(void) const
uint8_t GetManagementId(void) const
ATTRIBUTE_HELPER_CPP(ObjectFactory)
a unique identifier for an interface.
Definition: type-id.h:49
enum OrganizationIdentifierType m_type
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611
std::map< OrganizationIdentifier, VscCallback >::iterator VscCallbacksI
virtual uint32_t Deserialize(Buffer::Iterator start)