src/devices/mesh/wifi-information-element-vector.h
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu Nov 12 13:01:01 2009 +0100 (2009-11-12)
changeset 5505 c0ac392289c3
parent 5184 a109c38131dd
child 5827 ed0b2d9301a1
permissions -rw-r--r--
replace RefCountBase with SimpleRefCount<> to avoid duplicate refcounting implementations.
     1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
     2 /*
     3  * Copyright (c) 2009 IITP RAS
     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: Kirill Andreev <andreev@iitp.ru>
    19  *          Pavel Boyko <boyko.iitp.ru>
    20  */
    21 
    22 #ifndef IE_VECTOR_H
    23 #define IE_VECTOR_H
    24 
    25 #include "ns3/header.h"
    26 #include "ns3/simple-ref-count.h"
    27 
    28 namespace ns3 {
    29 class Packet;
    30 /**
    31  * \ingroup mesh
    32  *
    33  * \brief Enum of all known information element id (aka tags).
    34  *
    35  * For now only 802.11s (mesh) related elements are supported here (so 11S prefix),
    36  * but this can change in future.
    37  *
    38  * Note that 802.11s element ids are not yet officially assigned, we use ones
    39  * compatible with open80211s (http://o11s.org/) implementation.
    40  */
    41 enum WifiElementId {
    42   /* begin of open80211s-compatible IDs */
    43   IE11S_MESH_CONFIGURATION              = 51,
    44   IE11S_MESH_ID                         = 52,
    45   /* end of open80211s-compatible IDs */
    46   IE11S_LINK_METRIC_REPORT              = 20,
    47   IE11S_CONGESTION_NOTIFICATION,
    48   /* begin of open80211s-compatible IDs */
    49   IE11S_PEERING_MANAGEMENT              = 55,
    50   /* end of open80211s-compatible IDs */
    51   IE11S_SUPP_MBSS_REG_CLASSES_CHANNELS  = 23,
    52   IE11S_MESH_CHANNEL_SWITCH_ANNOUNCEMENT,
    53   IE11S_MESH_TIM,
    54   IE11S_AWAKE_WINDOW,
    55   IE11S_BEACON_TIMING,
    56   IE11S_MCCAOP_SETUP_REQUEST,
    57   IE11S_MCCAOP_SETUP_REPLY,
    58   IE11S_MCCAOP_ADVERTISEMENT,
    59   IE11S_MCCAOP_RESERVATION_TEARDOWN,
    60   IE11S_PORTAL_ANNOUNCEMENT,
    61   IE11S_RANN                            = 67,
    62   /* begin of open80211s-compatible IDs */
    63   IE11S_PREQ                            = 68,
    64   IE11S_PREP                            = 69,
    65   IE11S_PERR                            = 70,
    66   /* end of open80211s-compatible IDs */
    67   IE11S_PROXY_UPDATE                    = 37,
    68   IE11S_PROXY_UPDATE_CONFIRMATION,
    69   IE11S_ABBREVIATED_HANDSHAKE,
    70   IE11S_MESH_PEERING_PROTOCOL_VERSION   = 74,
    71 };
    72 
    73 /**
    74  * \ingroup mesh
    75  *
    76  * \brief Information element, as defined in 802.11-2007 standard
    77  *
    78  * Elements are defined to have a common general format consisting of a 1 octet Element ID field, a 1 octet
    79  * length field, and a variable-length element-specific information field. Each element is assigned a unique
    80  * Element ID as defined in this standard. The Length field specifies the number of octets in the Information
    81  * field.
    82  */
    83 class WifiInformationElement : public SimpleRefCount<WifiInformationElement>
    84 {
    85 public:
    86   virtual ~WifiInformationElement ();
    87   ///\name Each subclass must implement
    88   //\{
    89   virtual void Print (std::ostream &os) const = 0;
    90   /// Own unique Element ID
    91   virtual WifiElementId ElementId () const = 0;
    92   /// Length of serialized information
    93   virtual uint8_t GetInformationSize () const = 0;
    94   /// Serialize information
    95   virtual void SerializeInformation (Buffer::Iterator start) const = 0;
    96   /// Deserialize information
    97   virtual uint8_t DeserializeInformation (Buffer::Iterator start, uint8_t length) = 0;
    98   //\}
    99 
   100   /// Compare information elements using Element ID
   101   friend bool operator< (WifiInformationElement const & a, WifiInformationElement const & b);
   102   /// 
   103   virtual bool operator== (WifiInformationElement const & a) { return false; }
   104 };
   105 
   106 /// Compare information elements using Element ID
   107 bool operator< (WifiInformationElement const & a, WifiInformationElement const & b);
   108 
   109 /**
   110  * \ingroup mesh
   111  *
   112  * \brief Information element vector
   113  *
   114  * Implements a vector of WifiInformationElement's
   115  */
   116 class WifiInformationElementVector : public Header
   117 {
   118 public:
   119   WifiInformationElementVector ();
   120   ~WifiInformationElementVector ();
   121   ///\name Inherited from Header
   122   //\{
   123   static TypeId GetTypeId ();
   124   TypeId GetInstanceTypeId () const;
   125   virtual uint32_t GetSerializedSize () const;
   126   virtual void Serialize (Buffer::Iterator start) const;
   127   /**
   128    * \attention When you use RemoveHeader, WifiInformationElementVector supposes, that
   129    * all buffer consists of information elements
   130    * @param start
   131    * @return
   132    */
   133   virtual uint32_t Deserialize (Buffer::Iterator start);
   134   virtual void Print (std::ostream &os) const;
   135   //\}
   136   /**
   137    * \brief Needed when you try to deserialize a lonely IE inside other header
   138    * \param start is the start of the buffer
   139    * \return deserialized bytes
   140    */
   141   virtual uint32_t DeserializeSingleIe (Buffer::Iterator start);
   142   ///Set maximum size to control overflow of the max packet length 
   143   void SetMaxSize (uint16_t size);
   144   typedef std::vector<Ptr<WifiInformationElement> >::iterator Iterator;
   145   Iterator Begin ();
   146   Iterator End ();
   147   bool AddInformationElement (Ptr<WifiInformationElement> element);
   148   Ptr<WifiInformationElement> FindFirst (enum WifiElementId id) const;
   149 private:
   150   typedef std::vector<Ptr<WifiInformationElement> > IE_VECTOR;
   151   uint32_t GetSize () const;
   152   IE_VECTOR m_elements;
   153   /// Size in bytes (actually, max packet length)
   154   uint16_t m_maxSize;
   155   friend bool operator== (const WifiInformationElementVector & a, const WifiInformationElementVector & b);
   156 };
   157 bool operator== (const WifiInformationElementVector & a, const WifiInformationElementVector & b);
   158 }
   159 #endif