00001 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2005,2006,2007 INRIA 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation; 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> 00019 */ 00020 #ifndef WIFI_MODE_H 00021 #define WIFI_MODE_H 00022 00023 #include <stdint.h> 00024 #include <string> 00025 #include <vector> 00026 #include <ostream> 00027 #include "ns3/attribute-helper.h" 00028 00029 namespace ns3 { 00030 00031 /** 00032 * \brief represent a single transmission mode 00033 * 00034 * A WifiMode is implemented by a single integer which is used 00035 * to lookup in a global array the characteristics of the 00036 * associated transmission mode. It is thus extremely cheap to 00037 * keep a WifiMode variable around. 00038 */ 00039 class WifiMode 00040 { 00041 public: 00042 enum ModulationType { 00043 BPSK, 00044 QAM 00045 }; 00046 00047 /** 00048 * \returns the number of Hz used by this signal 00049 */ 00050 uint32_t GetBandwidth (void) const; 00051 /** 00052 * \returns the physical bit rate of this signal. 00053 * 00054 * If a transmission mode uses 1/2 FEC, and if its 00055 * data rate is 3Mbs, the phy rate is 6Mbs 00056 */ 00057 uint32_t GetPhyRate (void) const; 00058 /** 00059 * \returns the data bit rate of this signal. 00060 */ 00061 uint32_t GetDataRate (void) const; 00062 /** 00063 * \returns true if this mode uses a bpsk modulation, false 00064 * otherwise. 00065 */ 00066 bool IsModulationBpsk (void) const; 00067 /** 00068 * \returns true if this mode uses a qam modulation, false 00069 * otherwise. 00070 */ 00071 bool IsModulationQam (void) const; 00072 /** 00073 * \returns the type of modulation used by this mode. 00074 */ 00075 enum ModulationType GetModulationType (void) const; 00076 /** 00077 * \returns the size of the modulation constellation. 00078 */ 00079 uint8_t GetConstellationSize (void) const; 00080 00081 /** 00082 * \returns a human-readable representation of this WifiMode 00083 * instance. 00084 */ 00085 std::string GetUniqueName (void) const; 00086 00087 /** 00088 * \returns true if this mode is a mandatory mode, false 00089 * otherwise. 00090 */ 00091 bool IsMandatory (void) const; 00092 00093 /** 00094 * \returns the uid associated to this wireless mode. 00095 * 00096 * Each specific wireless mode should have a different uid. 00097 * For example, the 802.11b 1Mbs and the 802.11b 2Mbs modes 00098 * should have different uids. 00099 */ 00100 uint32_t GetUid (void) const; 00101 00102 /** 00103 * Create an invalid WifiMode. Calling any method on the 00104 * instance created will trigger an assert. This is useful 00105 * to separate the declaration of a WifiMode variable from 00106 * its initialization. 00107 */ 00108 WifiMode (); 00109 WifiMode (std::string name); 00110 private: 00111 friend class WifiModeFactory; 00112 WifiMode (uint32_t uid); 00113 uint32_t m_uid; 00114 }; 00115 00116 bool operator == (const WifiMode &a, const WifiMode &b); 00117 std::ostream & operator << (std::ostream & os, const WifiMode &mode); 00118 std::istream & operator >> (std::istream &is, WifiMode &mode); 00119 00120 /** 00121 * \class ns3::WifiModeValue 00122 * \brief hold objects of type ns3::WifiMode 00123 */ 00124 00125 ATTRIBUTE_HELPER_HEADER (WifiMode); 00126 00127 /** 00128 * \brief create WifiMode class instances and keep track of them. 00129 * 00130 * This factory ensures that each WifiMode created has a unique name 00131 * and assigns to each of them a unique integer. 00132 */ 00133 class WifiModeFactory 00134 { 00135 public: 00136 /** 00137 * \param uniqueName the name of the associated WifiMode. This name 00138 * must be unique accross _all_ instances. 00139 * \param isMandatory true if this WifiMode is mandatory, false otherwise. 00140 * \param bandwidth the bandwidth (Hz) of the signal generated when the 00141 * associated WifiMode is used. 00142 * \param dataRate the rate (bits/second) at which the user data is transmitted 00143 * \param phyRate the rate (bits/second) at which the encoded user data is transmitted 00144 * The phyRate includes FEC so, is typically higher than the dataRate. 00145 * 00146 * Create a BPSK WifiMode. 00147 */ 00148 static WifiMode CreateBpsk (std::string uniqueName, 00149 bool isMandatory, 00150 uint32_t bandwidth, 00151 uint32_t dataRate, 00152 uint32_t phyRate); 00153 /** 00154 * \param uniqueName the name of the associated WifiMode. This name 00155 * must be unique accross _all_ instances. 00156 * \param isMandatory true if this WifiMode is mandatory, false otherwise. 00157 * \param bandwidth the bandwidth (Hz) of the signal generated when the 00158 * associated WifiMode is used. 00159 * \param dataRate the rate (bits/second) at which the user data is transmitted 00160 * \param phyRate the rate (bits/second) at which the encoded user data is transmitted 00161 * The phyRate includes FEC so, is typically higher than the dataRate. 00162 * \param constellationSize the number of elements included in the QAM constellation. 00163 * 00164 * Create a QAM WifiMode. 00165 */ 00166 static WifiMode CreateQam (std::string uniqueName, 00167 bool isMandatory, 00168 uint32_t bandwidth, 00169 uint32_t dataRate, 00170 uint32_t phyRate, 00171 uint8_t constellationSize); 00172 00173 private: 00174 friend class WifiMode; 00175 friend std::istream & operator >> (std::istream &is, WifiMode &mode); 00176 static WifiModeFactory *GetFactory (); 00177 WifiModeFactory (); 00178 00179 /** 00180 * This is the data associated to a unique WifiMode. 00181 * The integer stored in a WifiMode is in fact an index 00182 * in an array of WifiModeItem objects. 00183 */ 00184 struct WifiModeItem { 00185 std::string uniqueUid; 00186 uint32_t bandwidth; 00187 uint32_t dataRate; 00188 uint32_t phyRate; 00189 enum WifiMode::ModulationType modulation; 00190 uint8_t constellationSize; 00191 bool isMandatory; 00192 }; 00193 00194 bool Search (std::string name, WifiMode *mode); 00195 uint32_t AllocateUid (std::string uniqueName); 00196 WifiModeItem *Get (uint32_t uid); 00197 00198 typedef std::vector<struct WifiModeItem> WifiModeItemList; 00199 WifiModeItemList m_itemList; 00200 }; 00201 00202 } // namespace ns3 00203 00204 #endif /* WIFI_MODE_H */