OLD | NEW |
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2005,2006,2007 INRIA | 3 * Copyright (c) 2005,2006,2007 INRIA |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 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· | 6 * it under the terms of the GNU General Public License version 2 as· |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 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 | 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 | 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 * | 17 * |
18 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> | 18 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
19 */ | 19 */ |
20 #include "wifi-mode.h" | 20 #include "wifi-mode.h" |
| 21 #include "ns3/simulator.h" |
21 #include "ns3/assert.h" | 22 #include "ns3/assert.h" |
| 23 #include "ns3/log.h" |
22 | 24 |
23 namespace ns3 { | 25 namespace ns3 { |
24 | 26 |
25 bool operator == (const WifiMode &a, const WifiMode &b) | 27 bool operator == (const WifiMode &a, const WifiMode &b) |
26 { | 28 { |
27 return a.GetUid () == b.GetUid (); | 29 return a.GetUid () == b.GetUid (); |
28 } | 30 } |
29 std::ostream & operator << (std::ostream & os, const WifiMode &mode) | 31 std::ostream & operator << (std::ostream & os, const WifiMode &mode) |
30 { | 32 { |
31 os << mode.GetUniqueName (); | 33 os << mode.GetUniqueName (); |
32 return os; | 34 return os; |
33 } | 35 } |
34 std::istream & operator >> (std::istream &is, WifiMode &mode) | 36 std::istream & operator >> (std::istream &is, WifiMode &mode) |
35 { | 37 { |
36 std::string str; | 38 std::string str; |
37 is >> str; | 39 is >> str; |
38 if (!WifiModeFactory::GetFactory ()->Search (str, &mode)) | 40 mode = WifiModeFactory::GetFactory ()->Search (str); |
39 { | |
40 is.setstate (std::ios_base::badbit); | |
41 } | |
42 return is; | 41 return is; |
43 } | 42 } |
44 | 43 |
45 uint32_t· | 44 uint32_t· |
46 WifiMode::GetBandwidth (void) const | 45 WifiMode::GetBandwidth (void) const |
47 { | 46 { |
48 struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->G
et (m_uid); | 47 struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->G
et (m_uid); |
49 return item->bandwidth; | 48 return item->bandwidth; |
50 } | 49 } |
51 uint32_t· | 50 uint32_t· |
52 WifiMode::GetPhyRate (void) const | 51 WifiMode::GetPhyRate (void) const |
53 { | 52 { |
54 struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->G
et (m_uid); | 53 struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->G
et (m_uid); |
55 return item->phyRate; | 54 return item->phyRate; |
56 } | 55 } |
57 uint32_t· | 56 uint32_t· |
58 WifiMode::GetDataRate (void) const | 57 WifiMode::GetDataRate (void) const |
59 { | 58 { |
60 struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->G
et (m_uid); | 59 struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->G
et (m_uid); |
61 return item->dataRate; | 60 return item->dataRate; |
62 } | 61 } |
63 bool· | 62 enum WifiCodeRate· |
64 WifiMode::IsModulationBpsk (void) const | 63 WifiMode::GetCodeRate (void) const |
65 { | 64 { |
66 struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->G
et (m_uid); | 65 struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->G
et (m_uid); |
67 return item->modulation == WifiMode::BPSK; | 66 return item->codingRate; |
68 } | |
69 bool· | |
70 WifiMode::IsModulationQam (void) const | |
71 { | |
72 struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->G
et (m_uid); | |
73 return item->modulation == WifiMode::QAM; | |
74 } | |
75 enum WifiMode::ModulationType· | |
76 WifiMode::GetModulationType (void) const | |
77 { | |
78 struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->G
et (m_uid); | |
79 return item->modulation; | |
80 } | 67 } |
81 uint8_t· | 68 uint8_t· |
82 WifiMode::GetConstellationSize (void) const | 69 WifiMode::GetConstellationSize (void) const |
83 { | 70 { |
84 struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->G
et (m_uid); | 71 struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->G
et (m_uid); |
85 return item->constellationSize; | 72 return item->constellationSize; |
86 } | 73 } |
87 std::string· | 74 std::string· |
88 WifiMode::GetUniqueName (void) const | 75 WifiMode::GetUniqueName (void) const |
89 { | 76 { |
90 // needed for ostream printing of the invalid mode | 77 // needed for ostream printing of the invalid mode |
91 struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->G
et (m_uid); | 78 struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->G
et (m_uid); |
92 return item->uniqueUid; | 79 return item->uniqueUid; |
93 } | 80 } |
94 bool | 81 bool |
95 WifiMode::IsMandatory (void) const | 82 WifiMode::IsMandatory (void) const |
96 { | 83 { |
97 struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->G
et (m_uid); | 84 struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->G
et (m_uid); |
98 return item->isMandatory; | 85 return item->isMandatory; |
99 } | 86 } |
100 uint32_t· | 87 uint32_t· |
101 WifiMode::GetUid (void) const | 88 WifiMode::GetUid (void) const |
102 { | 89 { |
103 return m_uid; | 90 return m_uid; |
104 } | 91 } |
105 enum WifiPhyStandard | 92 enum WifiModulationClass |
106 WifiMode::GetStandard () const | 93 WifiMode::GetModulationClass () const |
107 { | 94 { |
108 struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->G
et (m_uid); | 95 struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->G
et (m_uid); |
109 return item->standard; | 96 return item->modClass; |
110 } | 97 } |
111 WifiMode::WifiMode () | 98 WifiMode::WifiMode () |
112 : m_uid (0) | 99 : m_uid (0) |
113 {} | 100 {} |
114 WifiMode::WifiMode (uint32_t uid) | 101 WifiMode::WifiMode (uint32_t uid) |
115 : m_uid (uid) | 102 : m_uid (uid) |
116 {} | 103 {} |
117 WifiMode::WifiMode (std::string name) | 104 WifiMode::WifiMode (std::string name) |
118 { | 105 { |
119 if (!WifiModeFactory::GetFactory ()->Search (name, this)) | 106 *this = WifiModeFactory::GetFactory ()->Search (name); |
120 { | |
121 NS_FATAL_ERROR ("Invalid requested wifi mode: " << name); | |
122 } | |
123 } | 107 } |
124 | 108 |
125 ATTRIBUTE_HELPER_CPP (WifiMode); | 109 ATTRIBUTE_HELPER_CPP (WifiMode); |
126 | 110 |
127 WifiModeFactory::WifiModeFactory () | 111 WifiModeFactory::WifiModeFactory () |
128 {} | 112 {} |
129 | 113 |
| 114 |
130 WifiMode· | 115 WifiMode· |
131 WifiModeFactory::CreateBpsk (std::string uniqueName, | 116 WifiModeFactory::CreateWifiMode (std::string uniqueName, |
132 » » » bool isMandatory, | 117 enum WifiModulationClass modClass, |
133 » » » uint32_t bandwidth, | 118 bool isMandatory, |
134 » » » uint32_t dataRate, | 119 uint32_t bandwidth, |
135 » » » uint32_t phyRate, | 120 uint32_t dataRate, |
136 enum WifiPhyStandard standard) | 121 enum WifiCodeRate codingRate, |
| 122 uint8_t constellationSize) |
137 { | 123 { |
138 WifiModeFactory *factory = GetFactory (); | 124 WifiModeFactory *factory = GetFactory (); |
139 uint32_t uid = factory->AllocateUid (uniqueName); | 125 uint32_t uid = factory->AllocateUid (uniqueName); |
140 WifiModeItem *item = factory->Get (uid); | 126 WifiModeItem *item = factory->Get (uid); |
141 item->uniqueUid = uniqueName; | 127 item->uniqueUid = uniqueName; |
| 128 item->modClass = modClass; |
| 129 // The modulation class for this WifiMode must be valid. |
| 130 NS_ASSERT (modClass != WIFI_MOD_CLASS_UNKNOWN); |
| 131 |
142 item->bandwidth = bandwidth; | 132 item->bandwidth = bandwidth; |
143 item->dataRate = dataRate; | 133 item->dataRate = dataRate; |
144 item->phyRate = phyRate; | 134 |
145 item->modulation = WifiMode::BPSK; | 135 item->codingRate = codingRate; |
146 item->constellationSize = 2; | 136 |
| 137 switch (codingRate) { |
| 138 case WIFI_CODE_RATE_3_4: |
| 139 item->phyRate = dataRate * 4 / 3; |
| 140 break; |
| 141 case WIFI_CODE_RATE_2_3: |
| 142 item->phyRate = dataRate * 3 / 2; |
| 143 break; |
| 144 case WIFI_CODE_RATE_1_2: |
| 145 item->phyRate = dataRate * 2 / 1; |
| 146 break; |
| 147 case WIFI_CODE_RATE_UNDEFINED: |
| 148 default: |
| 149 item->phyRate = dataRate; |
| 150 break; |
| 151 } |
| 152 |
| 153 // Check for compatibility between modulation class and coding |
| 154 // rate. If modulation class is DSSS then coding rate must be |
| 155 // undefined, and vice versa. I could have done this with an |
| 156 // assertion, but it seems better to always give the error (i.e., |
| 157 // not only in non-optimised builds) and the cycles that extra test |
| 158 // here costs are only suffered at simulation setup. |
| 159 if ((codingRate == WIFI_CODE_RATE_UNDEFINED) != (modClass == WIFI_MOD_CLASS_DS
SS)) |
| 160 { |
| 161 NS_FATAL_ERROR ("Error in creation of WifiMode named " << uniqueName << st
d::endl |
| 162 << "Code rate must be WIFI_CODE_RATE_UNDEFINED iff Modulat
ion Class is WIFI_MOD_CLASS_DSSS"); |
| 163 } |
| 164 |
| 165 item->constellationSize = constellationSize; |
147 item->isMandatory = isMandatory; | 166 item->isMandatory = isMandatory; |
148 item->standard = standard; | 167 |
149 return WifiMode (uid); | 168 return WifiMode (uid); |
150 } | 169 } |
151 | 170 |
152 WifiMode· | 171 WifiMode |
153 WifiModeFactory::CreateQpsk (std::string uniqueName, | 172 WifiModeFactory::Search (std::string name) |
154 » » » bool isMandatory, | |
155 » » » uint32_t bandwidth, | |
156 » » » uint32_t dataRate, | |
157 » » » uint32_t phyRate, | |
158 enum WifiPhyStandard standard) | |
159 { | 173 { |
160 WifiModeFactory *factory = GetFactory (); | 174 WifiModeItemList::const_iterator i; |
161 uint32_t uid = factory->AllocateUid (uniqueName); | |
162 WifiModeItem *item = factory->Get (uid); | |
163 item->uniqueUid = uniqueName; | |
164 item->bandwidth = bandwidth; | |
165 item->dataRate = dataRate; | |
166 item->phyRate = phyRate; | |
167 item->modulation = WifiMode::QPSK; | |
168 item->constellationSize = 4; | |
169 item->isMandatory = isMandatory; | |
170 item->standard = standard; | |
171 return WifiMode (uid); | |
172 } | |
173 | |
174 WifiMode· | |
175 WifiModeFactory::CreateQam (std::string uniqueName, | |
176 bool isMandatory, | |
177 » » » uint32_t bandwidth, | |
178 » » » uint32_t dataRate, | |
179 » » » uint32_t phyRate, | |
180 » » » uint8_t constellationSize, | |
181 enum WifiPhyStandard standard) | |
182 { | |
183 WifiModeFactory *factory = GetFactory (); | |
184 uint32_t uid = factory->AllocateUid (uniqueName); | |
185 WifiModeItem *item = factory->Get (uid); | |
186 item->uniqueUid = uniqueName; | |
187 item->bandwidth = bandwidth; | |
188 item->dataRate = dataRate; | |
189 item->phyRate = phyRate; | |
190 item->modulation = WifiMode::QAM; | |
191 item->constellationSize = constellationSize; | |
192 item->isMandatory = isMandatory; | |
193 item->standard = standard; | |
194 return WifiMode (uid); | |
195 } | |
196 WifiMode· | |
197 WifiModeFactory::CreateDbpsk (std::string uniqueName, | |
198 » » » bool isMandatory, | |
199 » » » uint32_t bandwidth, | |
200 » » » uint32_t dataRate, | |
201 » » » uint32_t phyRate, | |
202 enum WifiPhyStandard standard) | |
203 { | |
204 WifiModeFactory *factory = GetFactory (); | |
205 uint32_t uid = factory->AllocateUid (uniqueName); | |
206 WifiModeItem *item = factory->Get (uid); | |
207 item->uniqueUid = uniqueName; | |
208 item->bandwidth = bandwidth; | |
209 item->dataRate = dataRate; | |
210 item->phyRate = phyRate; | |
211 item->modulation = WifiMode::DBPSK; | |
212 item->constellationSize = 2; | |
213 item->isMandatory = isMandatory; | |
214 item->standard = standard; | |
215 return WifiMode (uid); | |
216 } | |
217 WifiMode· | |
218 WifiModeFactory::CreateDqpsk (std::string uniqueName, | |
219 » » » bool isMandatory, | |
220 » » » uint32_t bandwidth, | |
221 » » » uint32_t dataRate, | |
222 » » » uint32_t phyRate, | |
223 enum WifiPhyStandard standard) | |
224 { | |
225 WifiModeFactory *factory = GetFactory (); | |
226 uint32_t uid = factory->AllocateUid (uniqueName); | |
227 WifiModeItem *item = factory->Get (uid); | |
228 item->uniqueUid = uniqueName; | |
229 item->bandwidth = bandwidth; | |
230 item->dataRate = dataRate; | |
231 item->phyRate = phyRate; | |
232 item->modulation = WifiMode::DQPSK; | |
233 item->constellationSize = 4; | |
234 item->isMandatory = isMandatory; | |
235 item->standard = standard; | |
236 return WifiMode (uid); | |
237 } | |
238 bool· | |
239 WifiModeFactory::Search (std::string name, WifiMode *mode) | |
240 { | |
241 uint32_t j = 0; | 175 uint32_t j = 0; |
242 for (WifiModeItemList::const_iterator i = m_itemList.begin (); | 176 for (i = m_itemList.begin (); i != m_itemList.end (); i++) |
243 i != m_itemList.end (); i++) | |
244 { | 177 { |
245 if (i->uniqueUid == name) | 178 if (i->uniqueUid == name) |
246 { | 179 { |
247 *mode = WifiMode (j); | 180 return WifiMode (j); |
248 » return true; | |
249 } | 181 } |
250 j++; | 182 j++; |
251 } | 183 } |
252 *mode = WifiMode (0); | 184 |
253 return false; | 185 // If we get here then a matching WifiMode was not found above. This |
| 186 // is a fatal problem, but we try to be helpful by displaying the |
| 187 // list of WifiModes that are supported. |
| 188 NS_LOG_UNCOND ("Could not find match for WifiMode named \"" |
| 189 << name << "\". Valid options are:"); |
| 190 for (i = m_itemList.begin (); i != m_itemList.end (); i++) |
| 191 { |
| 192 NS_LOG_UNCOND (" " << i->uniqueUid); |
| 193 } |
| 194 // Empty fatal error to die. We've already unconditionally logged |
| 195 // the helpful information. |
| 196 NS_FATAL_ERROR (""); |
| 197 |
| 198 // This next line is unreachable because of the fatal error |
| 199 // immediately above, and that is fortunate, because we have no idea |
| 200 // what is in WifiMode (0), but we do know it is not what our caller |
| 201 // has requested by name. It's here only because it's the safest |
| 202 // thing that'll give valid code. |
| 203 return WifiMode (0); |
254 } | 204 } |
255 | 205 |
256 uint32_t | 206 uint32_t |
257 WifiModeFactory::AllocateUid (std::string uniqueUid) | 207 WifiModeFactory::AllocateUid (std::string uniqueUid) |
258 { | 208 { |
259 uint32_t j = 0; | 209 uint32_t j = 0; |
260 for (WifiModeItemList::const_iterator i = m_itemList.begin (); | 210 for (WifiModeItemList::const_iterator i = m_itemList.begin (); |
261 i != m_itemList.end (); i++) | 211 i != m_itemList.end (); i++) |
262 { | 212 { |
263 if (i->uniqueUid == uniqueUid) | 213 if (i->uniqueUid == uniqueUid) |
(...skipping 20 matching lines...) Expand all Loading... |
284 static bool isFirstTime = true; | 234 static bool isFirstTime = true; |
285 static WifiModeFactory factory; | 235 static WifiModeFactory factory; |
286 if (isFirstTime) | 236 if (isFirstTime) |
287 { | 237 { |
288 uint32_t uid = factory.AllocateUid ("Invalid-WifiMode"); | 238 uint32_t uid = factory.AllocateUid ("Invalid-WifiMode"); |
289 WifiModeItem *item = factory.Get (uid); | 239 WifiModeItem *item = factory.Get (uid); |
290 item->uniqueUid = "Invalid-WifiMode"; | 240 item->uniqueUid = "Invalid-WifiMode"; |
291 item->bandwidth = 0; | 241 item->bandwidth = 0; |
292 item->dataRate = 0; | 242 item->dataRate = 0; |
293 item->phyRate = 0; | 243 item->phyRate = 0; |
294 item->modulation = WifiMode::UNKNOWN; | 244 item->modClass = WIFI_MOD_CLASS_UNKNOWN; |
295 item->constellationSize = 0; | 245 item->constellationSize = 0; |
| 246 item->codingRate = WIFI_CODE_RATE_UNDEFINED; |
296 item->isMandatory = false; | 247 item->isMandatory = false; |
297 item->standard = WIFI_PHY_UNKNOWN; | |
298 isFirstTime = false; | 248 isFirstTime = false; |
299 } | 249 } |
300 return &factory; | 250 return &factory; |
301 } | 251 } |
302 | 252 |
303 } // namespace ns3 | 253 } // namespace ns3 |
OLD | NEW |