1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 /* 3 * Copyright (c) 2009 University of Washington 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: Leonard Tracy <lentracy@gmail.com> 19 */ 20 21 #ifndef UAN_TX_MODE_H 22 #define UAN_TX_MODE_H 23 24 #include "ns3/object.h" 25 #include <map> 26 27 namespace ns3 { 28 29 class UanTxModeFactory; 30 class UanTxMode; 31 32 /** 33 * \ingroup uan 34 * 35 * Abstraction of packet modulation information. 36 * 37 * This contains a lightweight globally unique id for the mode. 38 * Mode details are held in the UanTxModeFactory. Attributes 39 * are set in by the UanTxModeFactory constructor. 40 */ 41 class UanTxMode 42 { 43 public: 44 UanTxMode (); //!< Constructor. 45 ~UanTxMode (); //!< Destructor. 46 47 /** 48 * Modulation type. 49 */ 50 typedef enum { 51 PSK, //!< Phase shift keying. 52 QAM, //!< Quadrature amplitude modulation. 53 FSK, //!< Frequency shift keying. 54 OTHER //!< Unspecified/undefined. 55 } ModulationType; 56 /** 57 * Get the modulation type of the mode. 58 * 59 * \return The modulation type. 60 */ 61 ModulationType GetModType (void) const; 62 /** 63 * Get the data rate of the transmit mode. 64 * 65 * \return Data rate of the TX mode, in bits per second. 66 */ 67 uint32_t GetDataRateBps (void) const; 68 /** 69 * Get the physical signaling rate. 70 * 71 * \return PHY rate in symbols per second. 72 */ 73 uint32_t GetPhyRateSps (void) const; 74 /** 75 * Get the transmission center frequency. 76 * 77 * \return Center frequency, in Hz. 78 */ 79 uint32_t GetCenterFreqHz (void) const; 80 /** 81 * Get the transmission signal bandwidth. 82 * 83 * \return Bandwidth in Hz. 84 */ 85 uint32_t GetBandwidthHz (void) const; 86 /** 87 * Get the number of constellation points in the modulation scheme. 88 * 89 * \return Number of constellation points. 90 */ 91 uint32_t GetConstellationSize (void) const; 92 /** 93 * Get the mode name. 94 * 95 * \return Name 96 */ 97 std::string GetName (void) const; 98 /** 99 * Get a unique id for the mode. 100 * 101 * \return Unique ID. 102 */ 103 uint32_t GetUid (void) const; 104 105 private: 106 friend class UanTxModeFactory; 107 friend std::ostream &operator<< (std::ostream & os, const UanTxMode &mode); 108 friend std::istream &operator>> (std::istream & is, UanTxMode &mode); 109 110 111 uint32_t m_uid; //!< Mode id 112 113 }; // class UanTxMode 114 115 116 /** 117 * Writes tx mode entry to stream os. 118 * 119 * \param os The output stream. 120 * \param mode The mode. 121 * \return The stream. 122 */ 123 std::ostream & operator << (std::ostream & os, const UanTxMode &mode); 124 /** 125 * Reads tx mode entry from stream is 126 * 127 * \param is The input stream. 128 * \param mode The mode. 129 * \return The stream. 130 */ 131 std::istream & operator >> (std::istream & is, UanTxMode &mode); 132 133 /** 134 * \ingroup uan 135 * 136 * Global database of UanTxMode objects, retrievable by id or name. 137 */ 138 class UanTxModeFactory 139 { 140 public: 141 UanTxModeFactory (); //!< Constructor. 142 ~UanTxModeFactory (); //!< Destructor. 143 144 /** 145 * 146 * \param type Modulation type. 147 * \param dataRateBps Data rate in BPS. 148 * \param phyRateSps Symbol rate in symbols per second. 149 * \param cfHz Center frequency in Hz. 150 * \param bwHz Bandwidth in Hz. 151 * \param constSize Modulation constellation size (2 for BPSK, 4 for QPSK). 152 * \param name Unique string name for this transmission mode. 153 * 154 * \return the transmit mode object 155 */ 156 static UanTxMode CreateMode (UanTxMode::ModulationType type, 157 uint32_t dataRateBps, 158 uint32_t phyRateSps, 159 uint32_t cfHz, 160 uint32_t bwHz, 161 uint32_t constSize, 162 std::string name); 163 164 /** 165 * Get a mode by name. 166 * 167 * \param name String name of mode. 168 * \return Mode with given name. 169 */ 170 static UanTxMode GetMode (std::string name); 171 /** 172 * Get a mode by id. 173 * 174 * \param uid Unique ID of mode. 175 * \return The mode with given uid. 176 */ 177 static UanTxMode GetMode (uint32_t uid); 178 179 private: 180 friend class UanTxMode; 181 uint32_t m_nextUid; //!< next id number 182 183 /** 184 * \ingroup uan 185 * Container for the UanTxMode properties. 186 */ 187 struct UanTxModeItem 188 { 189 UanTxMode::ModulationType m_type; //!< Modulation type. 190 uint32_t m_cfHz; //!< Center frequency in Hz. 191 uint32_t m_bwHz; //!< Bandwidth in Hz. 192 uint32_t m_dataRateBps; //!< Data rate in BPS. 193 uint32_t m_phyRateSps; //!< Symbol rate in symbols per second. 194 uint32_t m_constSize; //!< Modulation constellation size (2 for BPSK, 4 for QPSK). 195 uint32_t m_uid; //!< Unique id. 196 std::string m_name; //!< Unique string name for this transmission mode. 197 }; 198 199 /** 200 * Container for modes 201 * 202 * \internal 203 * Accessed internally by uid and name, so a multimap might be more 204 * appropriate. If name accesses are predominant, perhaps a map 205 * indexed by name, with a find for uid. If accesses by uid dominate 206 * then vector (since uid's are sequential), and find by name. 207 */ 208 std::map<uint32_t, UanTxModeItem> m_modes; 209 210 /** 211 * Check if the mode \pname{name} already exists. 212 * 213 * \param name The mode name to test. 214 * \return True if \pname{name} exists. 215 */ 216 bool NameUsed (std::string name); 217 218 /** 219 * Construct and get the static global factory instance. 220 * 221 * \return The global instance. 222 */ 223 static UanTxModeFactory &GetFactory (void); 224 225 /** 226 * Get a mode by id. 227 * 228 * \param uid The unique id to find. 229 * \return The corresponding mode. 230 */ 231 UanTxModeItem &GetModeItem (uint32_t uid); 232 233 /** 234 * Get a mode by name. 235 * \param name The mode name to find. 236 * \return The corresponding mode. 237 */ 238 UanTxModeItem &GetModeItem (std::string name); 239 240 /** 241 * Create a public UanTxMode from an internal UanTxModeItem. 242 * 243 * \param item The UanTxModeItem to reference. 244 * \return A public UanTxMode. 245 */ 246 UanTxMode MakeModeFromItem (const UanTxModeItem &item); 247 248 }; // class UanTxModeFactory 249 250 /** 251 * \ingroup uan 252 * 253 * Container for UanTxModes. 254 * 255 * \see attribute_UanModesList 256 */ 257 class UanModesList 258 { 259 public: 260 UanModesList (); //!< Constructor 261 virtual ~UanModesList (); //!< Destructor 262 263 /** 264 * Add mode to this list. 265 * \param mode The mode to add. 266 */ 267 void AppendMode (UanTxMode mode); 268 /** 269 * Delete the mode at given index. 270 * \param num Index of mode to delete. 271 */ 272 void DeleteMode (uint32_t num); 273 /** 274 * Retrieve a mode by index. 275 * 276 * \param index Mode index. 277 * \return Mode at given index. 278 */ 279 UanTxMode operator[] (uint32_t index) const; 280 /** 281 * Get the number of modes in this list. 282 * 283 * \return Number of modes. 284 */ 285 uint32_t GetNModes (void) const; 286 287 288 private: 289 /** The vector of modes in this list. */ 290 std::vector<UanTxMode> m_modes; 291 292 friend std::ostream &operator << (std::ostream &os, const UanModesList &ml); 293 friend std::istream &operator >> (std::istream &is, UanModesList &ml); 294 295 }; // class UanModesList 296 297 /** 298 * Write UanModesList to stream os 299 * 300 * \param os The output stream. 301 * \param ml The mode list. 302 * \return The stream. 303 */ 304 std::ostream &operator << (std::ostream &os, const UanModesList &ml); 305 /** 306 * Read UanModesList from stream is. 307 * 308 * \param is The input stream. 309 * \param ml The mode list to fill. 310 * \return The stream. 311 */ 312 std::istream &operator >> (std::istream &is, UanModesList &ml); 313 314 ATTRIBUTE_HELPER_HEADER (UanModesList); 315 316 } // namespace ns3 317 318 #endif /* UAN_TX_MODE_H */ 319