1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2008,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  *          Aleksey Kovalenko <kovalenko@iitp.ru>
20  */
21 
22 
23 #ifndef MESH_CONFIGURATION_H
24 #define MESH_CONFIGURATION_H
25 
26 #include "ns3/mesh-information-element-vector.h"
27 
28 namespace ns3 {
29 namespace dot11s {
30 
31 //according to IEEE 802.11 - 2012
32 
33 //in 7.3.2.98.2 Active Path Selection Protocol Identifier - 802.11s-2011
34 enum dot11sPathSelectionProtocol
35 {
36   PROTOCOL_HWMP = 0x01,
37 };
38 
39 //in 7.3.2.98.3 Active Path Selection Metric Identifier - 802.11s-2011
40 enum dot11sPathSelectionMetric
41 {
42   METRIC_AIRTIME = 0x01,
43 };
44 
45 // in 7.3.2.98.4 Congestion Control Mode Identifier - 802.11s-2011
46 enum dot11sCongestionControlMode
47 {
48   CONGESTION_SIGNALING = 0x01,
49   CONGESTION_NULL      = 0x00,
50 };
51 
52 // in 7.3.2.98.5 Synchronization Method Identifier - 802.11s-2011
53 enum dot11sSynchronizationProtocolIdentifier
54 {
55   SYNC_NEIGHBOUR_OFFSET = 0x01,  //Neighbor offset synchronization method
56   SYNC_NULL             = 0x00,  //Reserved
57 };
58 
59 // in 7.3.2.98.6 Authentication Protocol Identifier - 802.11s-2011
60 enum dot11sAuthenticationProtocol
61 {
62   AUTH_NULL = 0x00,  //No authentication method is required to establish mesh peerings within the MBSS
63   AUTH_SAE  = 0x01,  //SAE defined in 8.2a
64   AUTH_IEEE = 0x02,  //IEEE 802.1X authentication
65 };
66 /**
67  * \ingroup dot11s
68  * A set of values indicating whether a mesh STA is a possible candidate
69  * for mesh peering establishment (Section 8.4.2.100.8 of IEEE 802.11-2012)
70  */
71 class Dot11sMeshCapability
72 {
73 public:
74   Dot11sMeshCapability ();
75   /**
76    * Size of the field in bytes when serialized
77    * \returns the serialized size in bytes
78    */
79   uint8_t GetSerializedSize () const;
80   /**
81    * Serialize to a buffer
82    * \param i the iterator of the buffer to serialize to
83    * \returns new value of the iterator
84    */
85   Buffer::Iterator Serialize (Buffer::Iterator i) const;
86   /**
87    * Deserialize from a buffer
88    * \param i the iterator from which to deserialize
89    * \returns new value of the iterator
90    */
91   Buffer::Iterator Deserialize (Buffer::Iterator i);
92   /**
93    * The Mesh Capability is expressed in terms of 8 single bit fields.
94    * This method returns the whole byte.
95    * \returns the Mesh Capability byte
96    */
97   uint8_t GetUint8 () const;
98   bool acceptPeerLinks; ///< accept peer links
99   bool MCCASupported; ///< MCCA supported
100   bool MCCAEnabled; ///< MCCA enabled
101   bool forwarding; ///< forwarding?
102   bool beaconTimingReport; ///< beacon timing report
103   bool TBTTAdjustment; ///< TBTT adjustment
104   bool powerSaveLevel; ///< power save level
105   /**
106    * This is a utility function to test if the bit at position n is true
107    * \param cap byte to test
108    * \param n bit number to mask
109    * \returns true if bit n is set in cap
110    */
111   bool Is (uint8_t cap, uint8_t n) const;
112   /**
113    * equality operator
114    *
115    * \param a lhs
116    * \param b rhs
117    * \returns true if equal
118    */
119   friend bool operator== (const Dot11sMeshCapability & a, const Dot11sMeshCapability & b);
120 };
121 
122 /**
123  * \ingroup dot11s
124  * \brief Describes Mesh Configuration Element
125  * see 7.3.2.86 of 802.11s draft 3.0
126  */
127 class IeConfiguration : public WifiInformationElement
128 {
129 public:
130   IeConfiguration ();
131   /**
132    * Set routing value
133    * \param routingId the routing ID
134    */
135   void SetRouting (dot11sPathSelectionProtocol routingId);
136   /**
137    * Set metric value
138    * \param metricId the path selection metric
139    */
140   void SetMetric (dot11sPathSelectionMetric metricId);
141   /**
142    * Is HWMP function
143    * \returns true if Active Path Selection Protocol Identifier field set
144    *          to HWMP
145    */
146   bool IsHWMP ();
147   /**
148    * Is airtime function
149    * \returns true if Active Path Selection Metric Identifier is set to
150    *          airtime link metric
151    */
152   bool IsAirtime ();
153   /**
154    * Set neighbor count
155    * \param neighbors the number of neighbors
156    */
157   void SetNeighborCount (uint8_t neighbors);
158   /**
159    * Get neighbor count
160    * \returns the the neighbor count
161    */
162   uint8_t GetNeighborCount ();
163   /**
164    * Mesh capability
165    * \returns the dot11s mesh capability
166    */
167   Dot11sMeshCapability const& MeshCapability ();
168 
169   // Inherited from WifiInformationElement
170   virtual WifiInformationElementId ElementId () const;
171   virtual uint8_t GetInformationFieldSize () const;
172   virtual void SerializeInformationField (Buffer::Iterator i) const;
173   virtual uint8_t DeserializeInformationField (Buffer::Iterator i, uint8_t length);
174   virtual void Print (std::ostream& os) const;
175 
176 private:
177   /** Active Path Selection Protocol ID */
178   dot11sPathSelectionProtocol m_APSPId;
179   /** Active Path Metric ID */
180   dot11sPathSelectionMetric   m_APSMId;
181   /** Congestion Control Mode ID */
182   dot11sCongestionControlMode m_CCMId;
183   /** Sync protocol ID */
184   dot11sSynchronizationProtocolIdentifier m_SPId;
185   /** Auth protocol ID */
186   dot11sAuthenticationProtocol m_APId;
187   /** Mesh capability */
188   Dot11sMeshCapability m_meshCap;
189   uint8_t m_neighbors; ///< neighbors
190   /**
191    * equality operator
192    *
193    * \param a lhs
194    * \param b rhs
195    * \returns true if equal
196    */
197   friend bool operator== (const IeConfiguration & a, const IeConfiguration & b);
198 };
199 bool operator== (const IeConfiguration & a, const IeConfiguration & b);
200 bool operator== (const Dot11sMeshCapability & a, const Dot11sMeshCapability & b);
201 std::ostream &operator << (std::ostream &os, const IeConfiguration &config);
202 } // namespace dot11s
203 } // namespace ns3
204 #endif
205