|
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
|
2 /* |
|
3 * Copyright (c) 2005,2006,2007 INRIA |
|
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
|
19 */ |
|
20 #ifndef WIFI_MODE_H |
|
21 #define WIFI_MODE_H |
|
22 |
|
23 #include <stdint.h> |
|
24 #include <string> |
|
25 #include <vector> |
|
26 #include <ostream> |
|
27 #include "ns3/attribute-helper.h" |
|
28 #include "ns3/wifi-phy-standard.h" |
|
29 |
|
30 namespace ns3 { |
|
31 |
|
32 /** |
|
33 * This enumeration defines the modulation classes per IEEE |
|
34 * 802.11-2007, Section 9.6.1, Table 9-2. |
|
35 */ |
|
36 enum WifiModulationClass { |
|
37 /** Modulation class unknown or unspecified. A WifiMode with this |
|
38 WifiModulationClass has not been properly initialised. */ |
|
39 WIFI_MOD_CLASS_UNKNOWN = 0, |
|
40 /** Infrared (IR) (Clause 16) */ |
|
41 WIFI_MOD_CLASS_IR, |
|
42 /** Frequency-hopping spread spectrum (FHSS) PHY (Clause 14) */ |
|
43 WIFI_MOD_CLASS_FHSS, |
|
44 /** DSSS PHY (Clause 15) and HR/DSSS PHY (Clause 18) */ |
|
45 WIFI_MOD_CLASS_DSSS, |
|
46 /** ERP-PBCC PHY (19.6) */ |
|
47 WIFI_MOD_CLASS_ERP_PBCC, |
|
48 /** DSSS-OFDM PHY (19.7) */ |
|
49 WIFI_MOD_CLASS_DSSS_OFDM, |
|
50 /** ERP-OFDM PHY (19.5) */ |
|
51 WIFI_MOD_CLASS_ERP_OFDM, |
|
52 /** OFDM PHY (Clause 17) */ |
|
53 WIFI_MOD_CLASS_OFDM, |
|
54 /** HT PHY (Clause 20) */ |
|
55 WIFI_MOD_CLASS_HT |
|
56 }; |
|
57 |
|
58 |
|
59 /** |
|
60 * This enumeration defines the various convolutional coding rates |
|
61 * used for the OFDM transmission modes in the IEEE 802.11 |
|
62 * standard. DSSS (for example) rates which do not have an explicit |
|
63 * coding stage in their generation should have this parameter set to |
|
64 * WIFI_CODE_RATE_UNDEFINED. |
|
65 */ |
|
66 enum WifiCodeRate { |
|
67 /** No explicit coding (e.g., DSSS rates) */ |
|
68 WIFI_CODE_RATE_UNDEFINED, |
|
69 /** Rate 3/4 */ |
|
70 WIFI_CODE_RATE_3_4, |
|
71 /** Rate 2/3 */ |
|
72 WIFI_CODE_RATE_2_3, |
|
73 /** Rate 1/2 */ |
|
74 WIFI_CODE_RATE_1_2 |
|
75 }; |
|
76 |
|
77 /** |
|
78 * \brief represent a single transmission mode |
|
79 * |
|
80 * A WifiMode is implemented by a single integer which is used |
|
81 * to lookup in a global array the characteristics of the |
|
82 * associated transmission mode. It is thus extremely cheap to |
|
83 * keep a WifiMode variable around. |
|
84 */ |
|
85 class WifiMode |
|
86 { |
|
87 public: |
|
88 /** |
|
89 * \returns the number of Hz used by this signal |
|
90 */ |
|
91 uint32_t GetBandwidth (void) const; |
|
92 /** |
|
93 * \returns the physical bit rate of this signal. |
|
94 * |
|
95 * If a transmission mode uses 1/2 FEC, and if its |
|
96 * data rate is 3Mbs, the phy rate is 6Mbs |
|
97 */ |
|
98 uint32_t GetPhyRate (void) const; |
|
99 /** |
|
100 * \returns the data bit rate of this signal. |
|
101 */ |
|
102 uint32_t GetDataRate (void) const; |
|
103 /** |
|
104 * \returns the coding rate of this transmission mode |
|
105 */ |
|
106 enum WifiCodeRate GetCodeRate (void) const; |
|
107 /** |
|
108 * \returns the size of the modulation constellation. |
|
109 */ |
|
110 uint8_t GetConstellationSize (void) const; |
|
111 |
|
112 /** |
|
113 * \returns a human-readable representation of this WifiMode |
|
114 * instance. |
|
115 */ |
|
116 std::string GetUniqueName (void) const; |
|
117 |
|
118 /** |
|
119 * \returns true if this mode is a mandatory mode, false |
|
120 * otherwise. |
|
121 */ |
|
122 bool IsMandatory (void) const; |
|
123 |
|
124 /** |
|
125 * \returns the uid associated to this wireless mode. |
|
126 * |
|
127 * Each specific wireless mode should have a different uid. |
|
128 * For example, the 802.11b 1Mbs and the 802.11b 2Mbs modes |
|
129 * should have different uids. |
|
130 */ |
|
131 uint32_t GetUid (void) const; |
|
132 |
|
133 /** |
|
134 * |
|
135 * \returns the Modulation Class (see IEEE 802.11-2007 Section |
|
136 * 9.6.1) to which this WifiMode belongs. |
|
137 */ |
|
138 enum WifiModulationClass GetModulationClass () const; |
|
139 |
|
140 /** |
|
141 * Create an invalid WifiMode. Calling any method on the |
|
142 * instance created will trigger an assert. This is useful |
|
143 * to separate the declaration of a WifiMode variable from |
|
144 * its initialization. |
|
145 */ |
|
146 WifiMode (); |
|
147 WifiMode (std::string name); |
|
148 private: |
|
149 friend class WifiModeFactory; |
|
150 WifiMode (uint32_t uid); |
|
151 uint32_t m_uid; |
|
152 }; |
|
153 |
|
154 bool operator == (const WifiMode &a, const WifiMode &b); |
|
155 std::ostream & operator << (std::ostream & os, const WifiMode &mode); |
|
156 std::istream & operator >> (std::istream &is, WifiMode &mode); |
|
157 |
|
158 /** |
|
159 * \class ns3::WifiModeValue |
|
160 * \brief hold objects of type ns3::WifiMode |
|
161 */ |
|
162 |
|
163 ATTRIBUTE_HELPER_HEADER (WifiMode); |
|
164 |
|
165 /** |
|
166 * In various parts of the code, folk are interested in maintaining a |
|
167 * list of transmission modes. The vector class provides a good basis |
|
168 * for this, but we here add some syntactic sugar by defining a |
|
169 * WifiModeList type, and a corresponding iterator. |
|
170 */ |
|
171 typedef std::vector<WifiMode> WifiModeList; |
|
172 typedef WifiModeList::const_iterator WifiModeListIterator; |
|
173 |
|
174 /** |
|
175 * \brief create WifiMode class instances and keep track of them. |
|
176 * |
|
177 * This factory ensures that each WifiMode created has a unique name |
|
178 * and assigns to each of them a unique integer. |
|
179 */ |
|
180 class WifiModeFactory |
|
181 { |
|
182 public: |
|
183 /** |
|
184 * \param uniqueName the name of the associated WifiMode. This name |
|
185 * must be unique accross _all_ instances. |
|
186 * \param modClass the class of modulation |
|
187 * \param isMandatory true if this WifiMode is mandatory, false otherwise. |
|
188 * \param bandwidth the bandwidth (Hz) of the signal generated when the |
|
189 * associated WifiMode is used. |
|
190 * \param dataRate the rate (bits/second) at which the user data is transmitted |
|
191 * \param codingRate if convolutional coding is used for this rate |
|
192 * then this parameter specifies the convolutional coding rate |
|
193 * used. If there is no explicit convolutional coding step (e.g., |
|
194 * for DSSS rates) then the caller should set this parameter to |
|
195 * WIFI_CODE_RATE_UNCODED. |
|
196 * \param constellationSize the order of the constellation used. |
|
197 * |
|
198 * Create a WifiMode. |
|
199 */ |
|
200 static WifiMode CreateWifiMode (std::string uniqueName, |
|
201 enum WifiModulationClass modClass, |
|
202 bool isMandatory, |
|
203 uint32_t bandwidth, |
|
204 uint32_t dataRate, |
|
205 enum WifiCodeRate codingRate, |
|
206 uint8_t constellationSize); |
|
207 |
|
208 private: |
|
209 friend class WifiMode; |
|
210 friend std::istream & operator >> (std::istream &is, WifiMode &mode); |
|
211 static WifiModeFactory *GetFactory (); |
|
212 WifiModeFactory (); |
|
213 |
|
214 /** |
|
215 * This is the data associated to a unique WifiMode. |
|
216 * The integer stored in a WifiMode is in fact an index |
|
217 * in an array of WifiModeItem objects. |
|
218 */ |
|
219 struct WifiModeItem { |
|
220 std::string uniqueUid; |
|
221 uint32_t bandwidth; |
|
222 uint32_t dataRate; |
|
223 uint32_t phyRate; |
|
224 enum WifiModulationClass modClass; |
|
225 uint8_t constellationSize; |
|
226 enum WifiCodeRate codingRate; |
|
227 bool isMandatory; |
|
228 }; |
|
229 |
|
230 WifiMode Search (std::string name); |
|
231 uint32_t AllocateUid (std::string uniqueName); |
|
232 WifiModeItem *Get (uint32_t uid); |
|
233 |
|
234 typedef std::vector<struct WifiModeItem> WifiModeItemList; |
|
235 WifiModeItemList m_itemList; |
|
236 }; |
|
237 |
|
238 } // namespace ns3 |
|
239 |
|
240 #endif /* WIFI_MODE_H */ |