A Discrete-Event Network Simulator
API
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 namespace ns3 {
27 
28 NS_LOG_COMPONENT_DEFINE ("VendorSpecificAction");
29 
30 /*********** OrganizationIdentifier *******/
31 
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 
177 {
178  if (a.m_type != b.m_type)
179  {
180  return false;
181  }
182 
184  {
185  return memcmp (a.m_oi, b.m_oi, 3) == 0;
186  }
187 
189  {
190  return (memcmp (a.m_oi, b.m_oi, 4) == 0)
191  && ((a.m_oi[4] & 0xf0) == (b.m_oi[4] & 0xf0));
192  }
193 
194  return false;
195 }
196 
204 {
205  return !(a == b);
206 }
207 
215 {
216  return memcmp (a.m_oi, b.m_oi, std::min (a.m_type, b.m_type)) < 0;
217 }
218 
225 std::ostream& operator << (std::ostream& os, const OrganizationIdentifier& oi)
226 {
227  for (int i = 0; i < oi.m_type; i++)
228  {
229  os << "0x" << std::hex << static_cast<int> (oi.m_oi[i]) << " ";
230  }
231  os << std::endl;
232  return os;
233 }
234 
241 std::istream& operator >> (std::istream& is, const OrganizationIdentifier& oi)
242 {
243  return is;
244 }
245 
246 /*********** VendorSpecificActionHeader *******/
247 NS_OBJECT_ENSURE_REGISTERED (VendorSpecificActionHeader);
248 
250  : m_oi (),
251  m_category (CATEGORY_OF_VSA)
252 {
253  NS_LOG_FUNCTION (this);
254 }
255 
257 {
258  NS_LOG_FUNCTION (this);
259 }
260 
261 void
263 {
264  NS_LOG_FUNCTION (this << oi);
265  m_oi = oi;
266 }
267 
270 {
271  NS_LOG_FUNCTION (this);
272  return m_oi;
273 }
274 
275 TypeId
277 {
278  static TypeId tid = TypeId ("ns3::VendorSpecificActionHeader")
279  .SetParent<Header> ()
280  .SetGroupName ("Wave")
281  .AddConstructor<VendorSpecificActionHeader> ()
282  ;
283 
284  return tid;
285 }
286 
287 uint8_t
289 {
290  NS_LOG_FUNCTION (this);
291  return m_category;
292 }
293 
294 TypeId
296 {
297  NS_LOG_FUNCTION (this);
298  return GetTypeId ();
299 }
300 
301 void
302 VendorSpecificActionHeader::Print (std::ostream &os) const
303 {
304  NS_LOG_FUNCTION (this << &os);
305  os << "VendorSpecificActionHeader[ "
306  << "category = 0x" << std::hex << (int)m_category
307  << "organization identifier = " << m_oi
308  << std::dec;
309 }
310 
311 uint32_t
313 {
314  NS_LOG_FUNCTION (this);
315  return sizeof(m_category) + m_oi.GetSerializedSize ();
316 }
317 
318 void
320 {
321  NS_LOG_FUNCTION (this << &start);
322  start.WriteU8 (m_category);
323  m_oi.Serialize (start);
324 }
325 
326 uint32_t
328 {
329  NS_LOG_FUNCTION (this << &start);
330  m_category = start.ReadU8 ();
332  {
333  return 0;
334  }
336 
337  return GetSerializedSize ();
338 }
339 
340 /********* VendorSpecificContentManager ***********/
342 {
343  NS_LOG_FUNCTION (this);
344 }
345 
347 {
348  NS_LOG_FUNCTION (this);
349 }
350 
351 void
353 {
354  NS_LOG_FUNCTION (this << oi << &cb);
355  if (IsVscCallbackRegistered (oi))
356  {
357  NS_LOG_WARN ("there is already a VsaCallback registered for OrganizationIdentifier " << oi);
358  }
359  m_callbacks.insert (std::make_pair (oi, cb));
360 }
361 
362 void
364 {
365  NS_LOG_FUNCTION (this << oi);
366  m_callbacks.erase (oi);
367 }
368 
369 bool
371 {
372  NS_LOG_FUNCTION (this << oi);
373  if (m_callbacks.find (oi) == m_callbacks.end ())
374  {
375  OrganizationIdentifiers.push_back (oi);
376  return false;
377  }
378  return true;
379 }
380 
382 static VscCallback null_callback = MakeNullCallback<bool, Ptr<WifiMac>, const OrganizationIdentifier &,Ptr<const Packet>,const Address &> ();
383 
386 {
387  NS_LOG_FUNCTION (this << oi);
388  VscCallbacksI i;
389  i = m_callbacks.find (oi);
390  return (i == m_callbacks.end ()) ? null_callback : i->second;
391 }
392 
393 } // namespace ns3
Protocol header serialization and deserialization.
Definition: header.h:42
std::istream & operator>>(std::istream &is, Angles &a)
initialize a struct Angles from input
Definition: angles.cc:48
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Callback template class.
Definition: callback.h:1176
void RegisterVscCallback(OrganizationIdentifier oi, VscCallback cb)
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
virtual void Print(std::ostream &os) const
#define min(a, b)
Definition: 80211b.c:42
#define ATTRIBUTE_HELPER_CPP(type)
Define the attribute value, accessor and checkers for class type.
uint32_t Deserialize(Buffer::Iterator start)
Deserialize from buffer.
def start()
Definition: core.py:1844
#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
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
See IEEE 802.11-2007 chapter 7.3.1.11 and 7.4.5 also IEEE 802.11p-2010 chapter 7.4.5 Although WifiActionHeader has been defined in wifi mgt-header.h/.cc, it is not a good way to inherit from it or add vendor specific action support.
enum OrganizationIdentifierType GetType(void) const
void SetType(enum OrganizationIdentifierType type)
iterator in a Buffer instance
Definition: buffer.h:98
a polymophic address class
Definition: address.h:90
void DeregisterVscCallback(OrganizationIdentifier &oi)
bool operator<(const EventId &a, const EventId &b)
Definition: event-id.h:153
uint8_t m_oi[5]
organization identifier
VscCallbacks m_callbacks
VSC callbacks.
uint8_t GetCategory(void) const
the category field shall be CATEGORY_OF_VSA
void SetOrganizationIdentifier(OrganizationIdentifier oi)
the organization identifier is a public organizationally unique identifier assigned by the IEEE...
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:42
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:1471
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual void Serialize(Buffer::Iterator start) const
bool IsVscCallbackRegistered(OrganizationIdentifier &oi)
#define NS_FATAL_ERROR_NO_MSG()
Report a fatal error and terminate.
Definition: fatal-error.h:125
OrganizationIdentifier & operator=(const OrganizationIdentifier &oi)
assignment operator
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
uint32_t GetSerializedSize(void) const
Get serialized size.
static VscCallback null_callback
VSC callback function.
OrganizationIdentifier GetOrganizationIdentifier(void) const
static std::vector< OrganizationIdentifier > OrganizationIdentifiers
the OIs
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:262
virtual uint32_t GetSerializedSize(void) const
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.h:135
OrganizationIdentifierType
OrganizationIdentifierType enumeration.
static TypeId GetTypeId(void)
Get the type ID.
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
void Serialize(Buffer::Iterator start) const
Serialize to buffer.
a unique identifier for an interface.
Definition: type-id.h:58
enum OrganizationIdentifierType m_type
OI type.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
std::map< OrganizationIdentifier, VscCallback >::iterator VscCallbacksI
VSC callback iterator typedef.
virtual uint32_t Deserialize(Buffer::Iterator start)