View | Details | Raw Unified | Return to bug 2412
Collapse All | Expand All

(-)a/src/wifi/doc/source/wifi-user.rst (+335 lines)
 Lines 48-53    Link Here 
48
* Configure mobility: finally, mobility model is (usually) required before WifiNetDevice
48
* Configure mobility: finally, mobility model is (usually) required before WifiNetDevice
49
  can be used.
49
  can be used.
50
50
51
The following sample code illustrates a typical configuration using mostly
52
default values in the simulator, and infrastructure mode::
53
54
  NodeContainer wifiStaNode;
55
  wifiStaNode.Create (10);   // Create 10 station node objects
56
  NodeContainer wifiApNode;
57
  wifiApNode.Create (1);   // Create 1 access point node object
58
59
  // Create a channel helper and phy helper, and then create the channel
60
  YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
61
  YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
62
  phy.SetChannel (channel.Create ());
63
64
  // Create a WifiMacHelper, which is reused across STA and AP configurations
65
  WifiMacHelper mac;
66
67
  // Create a WifiHelper, which will use the above helpers to create
68
  // and install Wifi devices.  Configure a Wifi standard to use, which
69
  // will align various parameters in the Phy and Mac to standard defaults.
70
  WifiHelper wifi;
71
  wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
72
  // Declare NetDeviceContainers to hold the container returned by the helper
73
  NetDeviceContainer wifiStaDevices;
74
  NetDeviceContainer wifiApDevice;
75
76
  // Perform the installation
77
  mac.SetType ("ns3::StaWifiMac");
78
  wifiStaDevices = wifi.Install (phy, mac, wifiStaNodes);
79
  mac.SetType ("ns3::ApWifiMac");
80
  wifiApDevice = wifi.Install (phy, mac, wifiApNode);
81
82
At this point, the 11 nodes have Wi-Fi devices configured, attached to a 
83
common channel.  The rest of this section describes how additional 
84
configuration may be performed.
85
51
YansWifiChannelHelper
86
YansWifiChannelHelper
52
=====================
87
=====================
53
88
 Lines 153-158    Link Here 
153
  //Once install is done, we overwrite the channel width value
188
  //Once install is done, we overwrite the channel width value
154
  Config::Set ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/ChannelWidth", UintegerValue (160));
189
  Config::Set ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/ChannelWidth", UintegerValue (160));
155
190
191
Channel, frequency, and channel width configuration
192
===================================================
193
194
There are a few ``ns3::WifiPhy`` parameters that are related, and cannot
195
be set completely independently, concerning the frequency and channel width
196
that the device is tuned to.  These are:
197
198
* ``WifiPhyStandard``:  For example, 802.11b, 802.11n, etc.
199
* ``Frequency``
200
* ``ChannelWidth``
201
* ``ChannelNumber``
202
203
It is possible to set the above to incompatible combinations (e.g. channel
204
number 1 with 40 MHz channel width on frequency 4915 MHz).  In addition,
205
the latter three values above are attributes; it is possible to set them
206
in a number of ways:
207
208
* by setting global configuration default; e.g.
209
210
::
211
212
  Config::SetDefault ("ns3::WifiPhy::ChannelNumber", UintegerValue (3));
213
214
* by setting an attribute value in the helper; e.g.
215
216
::
217
218
  YansWifiPhyHelper wifiPhyHelper = YansWifiPhyHelper::Default ();
219
  wifiPhyHelper.Set ("ChannelNumber", UintegerValue (3));
220
221
222
* by setting the WifiHelper::SetStandard (enum WifiPhyStandard) method; and
223
224
* by performing post-installation configuration of the option, either
225
  via a Ptr to the WifiPhy object, or through the Config namespace; e.g.:
226
227
::
228
229
  Config::Set ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::WifiPhy/ChannelNumber", UintegerValue (3));
230
231
This section provides guidance on how to configure these settings in
232
a coherent manner, and what happens if non-standard values are chosen.
233
234
WifiHelper::SetStandard()
235
+++++++++++++++++++++++++
236
237
``WifiHelper::SetStandard ()`` is a method to set various parameters
238
in the Mac and Phy to standard values and some reasonable defaults.
239
For example, ``SetStandard (WIFI_PHY_STANDARD_80211a)`` will set the
240
WifiPhy to Channel 36 in the 5 GHz band, among other settings.
241
242
The following values for WifiPhyStandard are defined in 
243
``src/wifi/model/wifi-phy-standard.h``:
244
245
::
246
247
  /** OFDM PHY for the 5 GHz band (Clause 17) */
248
  WIFI_PHY_STANDARD_80211a,
249
  /** DSSS PHY (Clause 15) and HR/DSSS PHY (Clause 18) */
250
  WIFI_PHY_STANDARD_80211b,
251
  /** ERP-OFDM PHY (Clause 19, Section 19.5) */
252
  WIFI_PHY_STANDARD_80211g,
253
  /** OFDM PHY for the 5 GHz band (Clause 17 with 10 MHz channel bandwidth) */
254
  WIFI_PHY_STANDARD_80211_10MHZ,
255
  /** OFDM PHY for the 5 GHz band (Clause 17 with 5 MHz channel bandwidth) */
256
  WIFI_PHY_STANDARD_80211_5MHZ,
257
  /** This is intended to be the configuration used in this paper:
258
   *  Gavin Holland, Nitin Vaidya and Paramvir Bahl, "A Rate-Adaptive
259
   *  MAC Protocol for Multi-Hop Wireless Networks", in Proc. of
260
   *  ACM MOBICOM, 2001.
261
   */
262
  WIFI_PHY_STANDARD_holland,
263
  /** HT OFDM PHY for the 2.4 GHz band (clause 20) */
264
  WIFI_PHY_STANDARD_80211n_2_4GHZ,
265
  /** HT OFDM PHY for the 5 GHz band (clause 20) */
266
  WIFI_PHY_STANDARD_80211n_5GHZ,
267
  /** VHT OFDM PHY (clause 22) */
268
  WIFI_PHY_STANDARD_80211ac
269
270
In addition, a value WIFI_PHY_STANDARD_UNSPECIFIED is defined to indicate
271
that the user has not set a standard.
272
273
By default, the WifiPhy will be initialized to WIFI_PHY_STANDARD_UNSPECIFIED,
274
when it is created directly by ``CreateObject`` (i.e. not by WifiHelper).
275
However, the WifiHelper (the typical use case for WifiPhy creation) will 
276
configure the WIFI_PHY_STANDARD_80211a standard by default.  Other values 
277
for standards should be passed explicitly to the WifiHelper object.
278
279
If user has not already separately configured Frequency or ChannelNumber
280
when SetStandard is called, the user obtains default values, in addition
281
(e.g. channel 1 for 802.11b/g, or channel 36 for a/n), in addition to
282
an appropriate ChannelWidth value for the standard (typically, 20 MHz, but
283
80 MHz for 802.11ac).
284
285
WifiPhy attribute interactions
286
++++++++++++++++++++++++++++++
287
288
Users should keep in mind that the two attributes that matter most
289
within the model code are ``WifiPhy::Frequency`` and 
290
``WifiPhy::ChannelWidth``; these are the ones directly used to set
291
transmission parameters.  ``WifiPhy::ChannelNumber`` and 
292
``WifiHelper::SetStandard ()`` are convenience shorthands for setting
293
frequency and channel width.  The ``ns3::WifiPhy`` contains code to
294
keep these values aligned and to generate runtime errors in some cases
295
if users set these attributes to incompatible values.
296
297
The pair (WifiPhyStandard, ChannelNumber) is an alias for a pair of 
298
(Frequency/ChannelWidth) items.  Valid combinations are stored in 
299
a map within WifiPhy that is populated with well-known values but that
300
can be dynamically extended at runtime.  
301
302
WifiPhy::Frequency
303
++++++++++++++++++
304
305
The WifiPhy channel center frequency is set by the attribute ``Frequency``
306
in the class ``WifiPhy``.  It is expressed in units of MHz.  By default,
307
this attribute is set to the value 0 to indicate that no value is configured.
308
309
Note that this is a change in definition from ns-3.25 and earlier releases,
310
where this attribute referred to the start of the overall frequency band
311
on which the channel resides, not the specific channel center frequency.
312
313
WifiPhy::ChannelWidth
314
+++++++++++++++++++++
315
316
The WifiPhy channel width is set by the attribute ``ChannelWidth``
317
in the class ``WifiPhy``.  It is expressed in units of MHz.  By default,
318
this attribute is set to the value 20.  Allowable values are 5, 10, 20,
319
22, 40, 80, or 160 (MHz).
320
321
WifiPhy::ChannelNumber
322
++++++++++++++++++++++
323
324
Several channel numbers are defined and well-known in practice.  However,
325
valid channel numbers vary by geographical region around the world, and
326
there is some overlap between the different standards.
327
328
In |ns3|, the class ``WifiPhy`` contains an attribute ``ChannelNumber`` that
329
is, by default, set to the value 0.  The value 0 indicates that no
330
channel number has been set by the user.
331
332
In |ns3|, a ChannelNumber may be defined or unknown.  These terms
333
are not found in the code; they are just used to describe behavoir herein.
334
335
If a ChannelNumber is defined, it means that WifiPhy has stored a
336
map of ChannelNumber to the center frequency and channel width commonly
337
known for that channel in practice.  For example:
338
339
* Channel 1, when IEEE 802.11b is configured, corresponds to a channel
340
  width of 22 MHz and a center frequency of 2412 MHz.  
341
342
* Channel 36, when IEEE 802.11n is configured at 5GHz, corresponds to 
343
  a channel width of 20 MHz and a center frequency of 5180 MHz.  
344
345
The following channel numbers are well-defined for 2.4 GHz standards:
346
347
* channels 1-14 with ChannelWidth of 22 MHz for 802.11b
348
* channels 1-14 with ChannelWidth of 20 MHz for 802.11n-2.4GHz and 802.11g
349
350
The following channel numbers are well-defined for 5 GHz standards:
351
352
+------------------+-------------------------------------------+
353
| ``ChannelWidth`` | ``ChannelNumber``                         |
354
+------------------+-------------------------------------------+
355
| 20 MHz           | 36, 40, 44, 48, 52, 56, 60, 64, 100,      |
356
|                  | 104, 108, 112, 116, 120, 124,             |
357
|                  | 128, 132, 136, 140, 144,                  |
358
|                  | 149, 153, 161, 165, 169                   |
359
+------------------+-------------------------------------------+
360
| 40 MHz           | 38, 46, 54, 62, 102, 110, 118, 126,       |
361
|                  | 134, 142, 151, 159                        |
362
+------------------+-------------------------------------------+
363
| 80 MHz           | 42, 58, 106, 122, 138, 155                |
364
+------------------+-------------------------------------------+
365
| 160 MHz          | 50, 114                                   |
366
+------------------+-------------------------------------------+
367
| 10 MHz (802.11p) | 172, 174, 176, 178, 180, 182, 184         |
368
+------------------+-------------------------------------------+
369
370
The channel number may be set either before or after creation of the
371
WifiPhy object.  
372
373
If an unknown channel number (other than zero) is configured, the
374
simulator will exit with an error; for instance, such as:
375
376
::
377
378
  Ptr<WifiPhy> wifiPhy = ...;
379
  wifiPhy->SetAttribute ("ChannelNumber", UintegerValue (1321));
380
381
The known channel numbers are defined in the implementation file
382
``src/wifi/model/wifi-phy.cc``.  Of course, this file may be edited
383
by users to extend to additional channel numbers.  Below, we describe 
384
how new channel numbers may be defined dynamically at run-time.
385
386
If a known channel number is configured against an incorrect value
387
of the WifiPhyStandard, the simulator will exit with an error; for instance,
388
such as:
389
390
::
391
392
  WifiHelper wifi;
393
  wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
394
  ...
395
  Ptr<WifiPhy> wifiPhy = ...;
396
  wifiPhy->SetAttribute ("ChannelNumber", UintegerValue (14));
397
398
In the above, while channel number 14 is well-defined in practice for 802.11b
399
only, it is for 2.4 GHz band, not 5 GHz band.
400
401
Defining a new channel number
402
+++++++++++++++++++++++++++++
403
404
Users may define their own channel number so that they can later refer to
405
the channel by number.  
406
407
The method is ``WifiPhy::DefineChannelNumber ()`` and it takes the following
408
arguments:
409
410
* uint16_t channelNumber
411
* enum WifiPhyStandard standard
412
* uint32_t frequency
413
* uint32_t channelWidth
414
415
The pair of (channelNumber, standard) are used as an index to a map that
416
returns a Frequency and ChannelWidth.  By calling this method, one can
417
dynamically add members to the map.  For instance, let's suppose that you
418
previously configured WIFI_PHY_STANDARD_80211a, and wanted to deine a new
419
channel number '34' of width 20 MHz and at center frequency 5160 MHz.
420
421
If you try to simply configure ChannelNumber to the value 34, it will fail,
422
since 34 is undefined.  However, you can use DefineChannelNumber as follows:
423
424
::
425
426
  Ptr<WifiPhy> wifiPhy = ...;
427
  wifiPhy->DefineChannelNumber (34, WIFI_PHY_STANDARD_80211a, 5160, 20);
428
429
and then later you can refer to channel number 34 in your program, which
430
will configure a center operating frequency of 5160 MHz and a width of
431
20 MHz.
432
433
The steps can be repeated to explicitly configure the same channel for
434
multiple standards:
435
436
::
437
438
  wifiPhy->DefineChannelNumber (34, WIFI_PHY_STANDARD_80211a, 5160, 20);
439
  wifiPhy->DefineChannelNumber (34, WIFI_PHY_STANDARD_80211n_5GHZ, 5160, 20);
440
441
or for a wildcard, unspecified standard:
442
443
::
444
445
  wifiPhy->DefineChannelNumber (34, WIFI_PHY_STANDARD_UNSPECIFIED, 5160, 20);
446
447
Order of operation issues
448
+++++++++++++++++++++++++
449
450
Depending on the default values used and the order of operation in setting
451
the values for the standard, channel width, frequency, and channel number,
452
different configurations can be obtained.   Below are some common use cases.
453
454
* **(accepting the standard defaults):**  If a user has not already 
455
  separately configured frequency or channel number when 
456
  ``WifiHelper::SetStandard ()`` is called, the user gets default values 
457
  (e.g. channel 1 for 802.11b/g or channel 36 for a/n, with 20 MHz 
458
  channel widths)
459
460
* **(overwriting the standard channel):**  If the user has previously 
461
  configured (e.g. via SetDefault) either frequency or channel number when 
462
  SetStandard is called, and the frequency or channel number are appropriate 
463
  for the standard being configured, they are not overwritten
464
465
* **(changing the standard channel after Install):**  The user may also call
466
  ``WifiHelper::SetStandard ()`` after ``Install ()`` and either configure
467
  the frequency to something different, or configure the channel number
468
  to something different.  Note that if the channel number is undefined
469
  for the standard that was previously set, an error will occur.  
470
471
* **(changing to non-standard frequency):**  If the user configures a 
472
  frequency outside the standardized frequency range for the current 
473
  WifiPhyStandard, this is OK.  This allows users to experiment with 
474
  wifi on e.g. whitespace frequencies but still use SetStandard to set 
475
  all of the other configuration details.
476
477
* **(interaction between channel number and frequency):**  If the user 
478
  the user sets Frequency to a different value than the currently configured
479
  ChannelNumber (or if ChannelNumber is zero), then the ChannelNumber is 
480
  set to a new channel number if known, or to zero if unknown. 
481
482
  * *example:*  ChannelNumber previously set to 36, user sets Frequency to 5200, then ChannelNumber gets automatically set to 40
483
  * *example:*  ChannelNumber set to 36, user later sets Frequency to 5185, ChannelNumber gets reset to 0
484
485
In summary, ChannelNumber and Frequency follow each other.  ChannelNumber
486
sets both Frequency and ChannelWidth if the channel number has been defined
487
for the standard.  Setting ChannelWidth has no effect on Frequency or
488
ChannelNumber.  Setting Frequency will set ChannelNumber to either the
489
defined value for that Wi-Fi standard, or to the value 0 if undefined.
490
156
WifiMacHelper
491
WifiMacHelper
157
=============
492
=============
158
493
(-)8e25be6336a8 (+391 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2016 Tom Henderson
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: Tom Henderson <tomh@tomh.org>
19
 */
20
21
#include <string>
22
#include "ns3/core-module.h"
23
#include "ns3/config-store-module.h"
24
#include "ns3/network-module.h"
25
#include "ns3/wifi-module.h"
26
27
// This example shows (and tests) some possible configurations for
28
// the Wi-Fi physical layer, particularly the interaction between
29
// WifiHelper.SetStandard () and the physical layer channel number,
30
// center frequency, and channel width.
31
32
using namespace ns3;
33
34
NS_LOG_COMPONENT_DEFINE ("WifiPhyConfigurationExample");
35
36
37
Ptr<YansWifiPhy>
38
GetYansWifiPhyPtr (const NetDeviceContainer &nc)
39
{
40
  Ptr<WifiNetDevice> wnd = nc.Get (0)->GetObject<WifiNetDevice> ();
41
  Ptr<WifiPhy> wp = wnd->GetPhy ();
42
  return wp->GetObject<YansWifiPhy> ();
43
}
44
45
void
46
PrintAttributesIfEnabled (bool enabled)
47
{
48
  if (enabled)
49
    {
50
      ConfigStore outputConfig;
51
      outputConfig.ConfigureAttributes ();
52
    }
53
}
54
55
int main (int argc, char *argv[])
56
{
57
  uint32_t testCase = 0;
58
  bool printAttributes = false;
59
60
  CommandLine cmd;
61
  cmd.AddValue ("testCase", "Test case", testCase);
62
  cmd.AddValue ("printAttributes", "If true, print out attributes", printAttributes);
63
  cmd.Parse (argc, argv);
64
65
  NodeContainer wifiStaNode;
66
  wifiStaNode.Create (1);
67
  NodeContainer wifiApNode;
68
  wifiApNode.Create (1);
69
70
  YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
71
  YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
72
  phy.SetChannel (channel.Create ());
73
  WifiHelper wifi;
74
75
  // Configure and declare other generic components of this example
76
  Ssid ssid;
77
  ssid = Ssid ("wifi-phy-configuration");
78
  WifiMacHelper macSta;
79
  macSta.SetType ("ns3::StaWifiMac",
80
                  "Ssid", SsidValue (ssid),
81
                  "ActiveProbing", BooleanValue (false));
82
  WifiMacHelper macAp;
83
  macAp.SetType ("ns3::ApWifiMac",
84
                 "Ssid", SsidValue (ssid),
85
                 "BeaconInterval", TimeValue (MicroSeconds (102400)),
86
                 "BeaconGeneration", BooleanValue (true));
87
  NetDeviceContainer staDevice;
88
  NetDeviceContainer apDevice;
89
  Ptr<YansWifiPhy> phySta;
90
  Config::SetDefault ("ns3::ConfigStore::Filename", StringValue ("output-attributes-" + std::to_string (testCase) + ".txt"));
91
  Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue ("RawText"));
92
  Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Save"));
93
94
  switch (testCase)
95
  {
96
    case 0:
97
      // Default configuration, without WifiHelper::SetStandard or WifiHelper
98
      phySta = CreateObject<YansWifiPhy> ();
99
      // The default results in an invalid configuration of channel 0,
100
      // width 20, and frequency 0 MHz
101
      NS_ASSERT (phySta->GetChannelNumber () == 0);
102
      NS_ASSERT (phySta->GetChannelWidth () == 20);
103
      NS_ASSERT (phySta->GetFrequency () == 0);
104
      PrintAttributesIfEnabled (printAttributes);
105
      break;
106
107
    // The following cases test the setting of WifiPhyStandard alone;
108
    // i.e. without further channel number/width/frequency configuration
109
110
    case 1:
111
      // By default, WifiHelper will use WIFI_PHY_STANDARD_80211a
112
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
113
      apDevice = wifi.Install (phy, macAp, wifiApNode.Get(0));
114
      phySta = GetYansWifiPhyPtr (staDevice);
115
      // We expect channel 36, width 20, frequency 5180
116
      NS_ASSERT (phySta->GetChannelNumber () == 36);
117
      NS_ASSERT (phySta->GetChannelWidth () == 20);
118
      NS_ASSERT (phySta->GetFrequency () == 5180);
119
      PrintAttributesIfEnabled (printAttributes);
120
      break;
121
    case 2:
122
      wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
123
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
124
      apDevice = wifi.Install (phy, macAp, wifiApNode.Get(0));
125
      phySta = GetYansWifiPhyPtr (staDevice);
126
      // We expect channel 1, width 22, frequency 2412
127
      NS_ASSERT (phySta->GetChannelNumber () == 1);
128
      NS_ASSERT (phySta->GetChannelWidth () == 22);
129
      NS_ASSERT (phySta->GetFrequency () == 2412);
130
      PrintAttributesIfEnabled (printAttributes);
131
      break;
132
    case 3:
133
      wifi.SetStandard (WIFI_PHY_STANDARD_80211g);
134
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
135
      apDevice = wifi.Install (phy, macAp, wifiApNode.Get(0));
136
      phySta = GetYansWifiPhyPtr (staDevice);
137
      // We expect channel 1, width 20, frequency 2412
138
      NS_ASSERT (phySta->GetChannelNumber () == 1);
139
      NS_ASSERT (phySta->GetChannelWidth () == 20);
140
      NS_ASSERT (phySta->GetFrequency () == 2412);
141
      PrintAttributesIfEnabled (printAttributes);
142
      break;
143
    case 4:
144
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
145
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
146
      apDevice = wifi.Install (phy, macAp, wifiApNode.Get(0));
147
      phySta = GetYansWifiPhyPtr (staDevice);
148
      // We expect channel 36, width 20, frequency 5180
149
      NS_ASSERT (phySta->GetChannelNumber () == 36);
150
      NS_ASSERT (phySta->GetChannelWidth () == 20);
151
      NS_ASSERT (phySta->GetFrequency () == 5180);
152
      PrintAttributesIfEnabled (printAttributes);
153
      break;
154
    case 5:
155
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_2_4GHZ);
156
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
157
      apDevice = wifi.Install (phy, macAp, wifiApNode.Get(0));
158
      phySta = GetYansWifiPhyPtr (staDevice);
159
      // We expect channel 1, width 20, frequency 2412
160
      NS_ASSERT (phySta->GetChannelNumber () == 1);
161
      NS_ASSERT (phySta->GetChannelWidth () == 20);
162
      NS_ASSERT (phySta->GetFrequency () == 2412);
163
      PrintAttributesIfEnabled (printAttributes);
164
      break;
165
    case 6:
166
      wifi.SetStandard (WIFI_PHY_STANDARD_80211ac);
167
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
168
      apDevice = wifi.Install (phy, macAp, wifiApNode.Get(0));
169
      phySta = GetYansWifiPhyPtr (staDevice);
170
      // We expect channel 42, width 80, frequency 5210
171
      NS_ASSERT (phySta->GetChannelNumber () == 42);
172
      NS_ASSERT (phySta->GetChannelWidth () == 80);
173
      NS_ASSERT (phySta->GetFrequency () == 5210);
174
      PrintAttributesIfEnabled (printAttributes);
175
      break;
176
    case 7:
177
      wifi.SetStandard (WIFI_PHY_STANDARD_80211_10MHZ);
178
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
179
      apDevice = wifi.Install (phy, macAp, wifiApNode.Get(0));
180
      phySta = GetYansWifiPhyPtr (staDevice);
181
      // We expect channel 172, width 10, frequency 5860
182
      NS_ASSERT (phySta->GetChannelNumber () == 172);
183
      NS_ASSERT (phySta->GetChannelWidth () == 10);
184
      NS_ASSERT (phySta->GetFrequency () == 5860);
185
      PrintAttributesIfEnabled (printAttributes);
186
      break;
187
    case 8:
188
      wifi.SetStandard (WIFI_PHY_STANDARD_80211_5MHZ);
189
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
190
      apDevice = wifi.Install (phy, macAp, wifiApNode.Get(0));
191
      phySta = GetYansWifiPhyPtr (staDevice);
192
      // We expect channel 0, width 5, frequency 5860
193
      // Channel 0 because 5MHz channels are not officially defined
194
      NS_ASSERT (phySta->GetChannelNumber () == 0);
195
      NS_ASSERT (phySta->GetChannelWidth () == 5);
196
      NS_ASSERT (phySta->GetFrequency () == 5860);
197
      PrintAttributesIfEnabled (printAttributes);
198
      break;
199
    case 9:
200
      wifi.SetStandard (WIFI_PHY_STANDARD_holland);
201
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
202
      apDevice = wifi.Install (phy, macAp, wifiApNode.Get(0));
203
      phySta = GetYansWifiPhyPtr (staDevice);
204
      // We expect channel 36, width 20, frequency 5180
205
      NS_ASSERT (phySta->GetChannelNumber () == 36);
206
      NS_ASSERT (phySta->GetChannelWidth () == 20);
207
      NS_ASSERT (phySta->GetFrequency () == 5180);
208
      PrintAttributesIfEnabled (printAttributes);
209
      break;
210
    case 10:
211
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
212
      phy.Set ("ChannelNumber", UintegerValue(44));
213
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
214
      apDevice = wifi.Install (phy, macAp, wifiApNode.Get(0));
215
      phySta = GetYansWifiPhyPtr (staDevice);
216
      // We expect channel 44, width 20, frequency 5220
217
      NS_ASSERT (phySta->GetChannelNumber () == 44);
218
      NS_ASSERT (phySta->GetChannelWidth () == 20);
219
      NS_ASSERT (phySta->GetFrequency () == 5220);
220
      PrintAttributesIfEnabled (printAttributes);
221
      break;
222
223
    case 11:
224
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
225
      phy.Set ("ChannelNumber", UintegerValue(44));
226
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
227
      apDevice = wifi.Install (phy, macAp, wifiApNode.Get(0));
228
      phySta = GetYansWifiPhyPtr (staDevice);
229
      // Post-install reconfiguration to channel number 40
230
      Config::Set ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/ChannelNumber", UintegerValue(40));
231
      Config::Set ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/ChannelNumber", UintegerValue(40));
232
      // We expect channel 40, width 20, frequency 5200
233
      NS_ASSERT (phySta->GetChannelNumber () == 40);
234
      NS_ASSERT (phySta->GetChannelWidth () == 20);
235
      NS_ASSERT (phySta->GetFrequency () == 5200);
236
      PrintAttributesIfEnabled (printAttributes);
237
      break;
238
239
    case 12:
240
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
241
      phy.Set ("ChannelNumber", UintegerValue (44));
242
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
243
      apDevice = wifi.Install (phy, macAp, wifiApNode.Get(0));
244
      phySta = GetYansWifiPhyPtr (staDevice);
245
      // Post-install reconfiguration to channel width 40 MHz
246
      Config::Set ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/ChannelWidth", UintegerValue(40));
247
      Config::Set ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/ChannelWidth", UintegerValue(40));
248
      // Although channel 44 is configured originally for 20 MHz, we 
249
      // allow it to be used for 40 MHz here
250
      NS_ASSERT (phySta->GetChannelNumber () == 44);
251
      NS_ASSERT (phySta->GetChannelWidth () == 40);
252
      NS_ASSERT (phySta->GetFrequency () == 5220);
253
      PrintAttributesIfEnabled (printAttributes);
254
      break;
255
256
    case 13:
257
      Config::SetDefault ("ns3::WifiPhy::ChannelNumber", UintegerValue (44));
258
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
259
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
260
      apDevice = wifi.Install (phy, macAp, wifiApNode.Get(0));
261
      phySta = GetYansWifiPhyPtr (staDevice);
262
      // Post-install reconfiguration to channel width 40 MHz
263
      Config::Set ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/ChannelWidth", UintegerValue(40));
264
      Config::Set ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/ChannelWidth", UintegerValue(40));
265
      // Although channel 44 is configured originally for 20 MHz, we 
266
      // allow it to be used for 40 MHz here
267
      NS_ASSERT (phySta->GetChannelNumber () == 44);
268
      NS_ASSERT (phySta->GetChannelWidth () == 40);
269
      NS_ASSERT (phySta->GetFrequency () == 5220);
270
      PrintAttributesIfEnabled (printAttributes);
271
      break;
272
273
    case 14:
274
      // Test that setting Frequency to a non-standard value will zero the
275
      // channel number
276
      Config::SetDefault ("ns3::WifiPhy::Frequency", UintegerValue (5281));
277
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
278
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
279
      apDevice = wifi.Install (phy, macAp, wifiApNode.Get(0));
280
      phySta = GetYansWifiPhyPtr (staDevice);
281
      // We expect channel number to be zero since frequency doesn't match
282
      NS_ASSERT (phySta->GetChannelNumber () == 0);
283
      NS_ASSERT (phySta->GetChannelWidth () == 20);
284
      NS_ASSERT (phySta->GetFrequency () == 5281);
285
      PrintAttributesIfEnabled (printAttributes);
286
      break;
287
288
    case 15:
289
      // Test that setting Frequency to a standard value will set the
290
      // channel number correctly
291
      Config::SetDefault ("ns3::WifiPhy::Frequency", UintegerValue (5500));
292
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
293
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
294
      apDevice = wifi.Install (phy, macAp, wifiApNode.Get (0));
295
      phySta = GetYansWifiPhyPtr (staDevice);
296
      // We expect channel number to be 100 due to frequency 5500
297
      NS_ASSERT (phySta->GetChannelNumber () == 100);
298
      NS_ASSERT (phySta->GetChannelWidth () == 20);
299
      NS_ASSERT (phySta->GetFrequency () == 5500);
300
      PrintAttributesIfEnabled (printAttributes);
301
      break;
302
303
    case 16:
304
      // Define a new channel number
305
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
306
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
307
      apDevice = wifi.Install (phy, macAp, wifiApNode.Get (0));
308
      phySta = GetYansWifiPhyPtr (staDevice);
309
      // This case will error exit due to invalid channel number unless
310
      // we provide the DefineChannelNumber() below
311
      phySta->DefineChannelNumber (99, WIFI_PHY_STANDARD_80211n_5GHZ, 5185, 40);
312
      phySta->SetAttribute ("ChannelNumber", UintegerValue (99));
313
      PrintAttributesIfEnabled (printAttributes);
314
      break;
315
316
    case 17:
317
      // Test how channel number behaves when frequency is non-standard
318
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
319
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
320
      apDevice = wifi.Install (phy, macAp, wifiApNode.Get(0));
321
      phySta = GetYansWifiPhyPtr (staDevice);
322
      phySta->SetAttribute ("Frequency", UintegerValue (5181));
323
      // We expect channel number to be 0 due to unknown center frequency 5181
324
      NS_ASSERT (phySta->GetChannelNumber () == 0);
325
      NS_ASSERT (phySta->GetChannelWidth () == 20);
326
      NS_ASSERT (phySta->GetFrequency () == 5181);
327
      phySta->SetAttribute ("Frequency", UintegerValue (5180));
328
      // We expect channel number to be 36 due to known center frequency 5180
329
      NS_ASSERT (phySta->GetChannelNumber () == 36);
330
      NS_ASSERT (phySta->GetChannelWidth () == 20);
331
      NS_ASSERT (phySta->GetFrequency () == 5180);
332
      phySta->SetAttribute ("Frequency", UintegerValue (5179));
333
      // We expect channel number to be 0 due to unknown center frequency 5179
334
      NS_ASSERT (phySta->GetChannelNumber () == 0);
335
      NS_ASSERT (phySta->GetChannelWidth () == 20);
336
      NS_ASSERT (phySta->GetFrequency () == 5179);
337
      phySta->SetAttribute ("ChannelNumber", UintegerValue (36));
338
      NS_ASSERT (phySta->GetChannelNumber () == 36);
339
      NS_ASSERT (phySta->GetChannelWidth () == 20);
340
      NS_ASSERT (phySta->GetFrequency () == 5180);
341
      PrintAttributesIfEnabled (printAttributes);
342
      break;
343
344
    case 18:
345
      // Set both channel and frequency to consistent values
346
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
347
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
348
      apDevice = wifi.Install (phy, macAp, wifiApNode.Get(0));
349
      phySta = GetYansWifiPhyPtr (staDevice);
350
      phySta->SetAttribute ("Frequency", UintegerValue (5200));
351
      phySta->SetAttribute ("ChannelNumber", UintegerValue (40));
352
      NS_ASSERT (phySta->GetChannelNumber () == 40);
353
      NS_ASSERT (phySta->GetChannelWidth () == 20);
354
      NS_ASSERT (phySta->GetFrequency () == 5200);
355
      // Set both channel and frequency to inconsistent values
356
      phySta->SetAttribute ("Frequency", UintegerValue (5200));
357
      phySta->SetAttribute ("ChannelNumber", UintegerValue (36));
358
      // We expect channel number to be 36 
359
      NS_ASSERT (phySta->GetChannelNumber () == 36);
360
      NS_ASSERT (phySta->GetChannelWidth () == 20);
361
      NS_ASSERT (phySta->GetFrequency () == 5180);
362
      phySta->SetAttribute ("ChannelNumber", UintegerValue (36));
363
      phySta->SetAttribute ("Frequency", UintegerValue (5200));
364
      // We expect channel number to be 40 
365
      NS_ASSERT (phySta->GetChannelNumber () == 40);
366
      NS_ASSERT (phySta->GetChannelWidth () == 20);
367
      NS_ASSERT (phySta->GetFrequency () == 5200);
368
      phySta->SetAttribute ("Frequency", UintegerValue (5179));
369
      phySta->SetAttribute ("ChannelNumber", UintegerValue (36));
370
      // We expect channel number to be 36 
371
      NS_ASSERT (phySta->GetChannelNumber () == 36);
372
      NS_ASSERT (phySta->GetChannelWidth () == 20);
373
      NS_ASSERT (phySta->GetFrequency () == 5180);
374
      phySta->SetAttribute ("ChannelNumber", UintegerValue (36));
375
      phySta->SetAttribute ("Frequency", UintegerValue (5179));
376
      // We expect channel number to be 0 
377
      NS_ASSERT (phySta->GetChannelNumber () == 0);
378
      NS_ASSERT (phySta->GetChannelWidth () == 20);
379
      NS_ASSERT (phySta->GetFrequency () == 5179);
380
      PrintAttributesIfEnabled (printAttributes);
381
      break;
382
383
    default:
384
      std::cerr << "Invalid testcase number " << testCase << std::endl;
385
      exit (1);
386
      break;
387
  }
388
389
  // No need to Simulator::Run (); this is a configuration example
390
  Simulator::Destroy ();
391
}
(-)a/src/wifi/examples/wscript (+4 lines)
 Lines 19-21    Link Here 
19
    obj = bld.create_ns3_program('minstrel-ht-wifi-manager-example',
19
    obj = bld.create_ns3_program('minstrel-ht-wifi-manager-example',
20
        ['core', 'network', 'wifi', 'stats', 'mobility', 'propagation'])
20
        ['core', 'network', 'wifi', 'stats', 'mobility', 'propagation'])
21
    obj.source = 'minstrel-ht-wifi-manager-example.cc'
21
    obj.source = 'minstrel-ht-wifi-manager-example.cc'
22
23
    obj = bld.create_ns3_program('wifi-phy-configuration',
24
        ['core', 'network', 'config-store', 'wifi'])
25
    obj.source = 'wifi-phy-configuration.cc'
(-)a/src/wifi/model/wifi-phy-standard.h (-1 / +3 lines)
 Lines 50-56    Link Here 
50
  /** HT OFDM PHY for the 5 GHz band (clause 20) */
50
  /** HT OFDM PHY for the 5 GHz band (clause 20) */
51
  WIFI_PHY_STANDARD_80211n_5GHZ,
51
  WIFI_PHY_STANDARD_80211n_5GHZ,
52
  /** VHT OFDM PHY (clause 22) */
52
  /** VHT OFDM PHY (clause 22) */
53
  WIFI_PHY_STANDARD_80211ac
53
  WIFI_PHY_STANDARD_80211ac,
54
  /** Unspecified */
55
  WIFI_PHY_STANDARD_UNSPECIFIED
54
};
56
};
55
57
56
} //namespace ns3
58
} //namespace ns3
(-)a/src/wifi/model/wifi-phy.cc (+464 lines)
 Lines 31-36    Link Here 
31
#include "ns3/uinteger.h"
31
#include "ns3/uinteger.h"
32
#include "ns3/enum.h"
32
#include "ns3/enum.h"
33
#include "ns3/trace-source-accessor.h"
33
#include "ns3/trace-source-accessor.h"
34
#include "ns3/fatal-error.h"
34
#include <cmath>
35
#include <cmath>
35
36
36
namespace ns3 {
37
namespace ns3 {
 Lines 51-62    Link Here 
51
52
52
NS_OBJECT_ENSURE_REGISTERED (WifiPhy);
53
NS_OBJECT_ENSURE_REGISTERED (WifiPhy);
53
54
55
/**
56
 * This table maintains the mapping of valid ChannelNumber to
57
 * Frequency/ChannelWidth pairs.  If you want to make a channel applicable
58
 * to all standards, then you may use the WIFI_PHY_STANDARD_UNSPECIFIED
59
 * standard to represent this, as a wildcard.  If you want to limit the 
60
 * configuration of a particular channel/frequency/width to a particular 
61
 * standard(s), then you can specify one or more such bindings. 
62
 */
63
WifiPhy::ChannelToFrequencyWidthMap WifiPhy::m_channelToFrequencyWidth =
64
{
65
  // 802.11b uses width of 22, while OFDM modes use width of 20
66
  { std::make_pair (1, WIFI_PHY_STANDARD_80211b), std::make_pair (2412, 22) },
67
  { std::make_pair (1, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2412, 20) },
68
  { std::make_pair (2, WIFI_PHY_STANDARD_80211b), std::make_pair (2417, 22) },
69
  { std::make_pair (2, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2417, 20) },
70
  { std::make_pair (3, WIFI_PHY_STANDARD_80211b), std::make_pair (2422, 22) },
71
  { std::make_pair (3, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2422, 20) },
72
  { std::make_pair (4, WIFI_PHY_STANDARD_80211b), std::make_pair (2427, 22) },
73
  { std::make_pair (4, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2427, 20) },
74
  { std::make_pair (5, WIFI_PHY_STANDARD_80211b), std::make_pair (2432, 22) },
75
  { std::make_pair (5, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2432, 20) },
76
  { std::make_pair (6, WIFI_PHY_STANDARD_80211b), std::make_pair (2437, 22) },
77
  { std::make_pair (6, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2437, 20) },
78
  { std::make_pair (7, WIFI_PHY_STANDARD_80211b), std::make_pair (2442, 22) },
79
  { std::make_pair (7, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2442, 20) },
80
  { std::make_pair (8, WIFI_PHY_STANDARD_80211b), std::make_pair (2447, 22) },
81
  { std::make_pair (8, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2447, 20) },
82
  { std::make_pair (9, WIFI_PHY_STANDARD_80211b), std::make_pair (2452, 22) },
83
  { std::make_pair (9, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2452, 20) },
84
  { std::make_pair (10, WIFI_PHY_STANDARD_80211b), std::make_pair (2457, 22) },
85
  { std::make_pair (10, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2457, 20) },
86
  { std::make_pair (11, WIFI_PHY_STANDARD_80211b), std::make_pair (2462, 22) },
87
  { std::make_pair (11, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2462, 20) },
88
  { std::make_pair (12, WIFI_PHY_STANDARD_80211b), std::make_pair (2467, 22) },
89
  { std::make_pair (12, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2467, 20) },
90
  { std::make_pair (13, WIFI_PHY_STANDARD_80211b), std::make_pair (2472, 22) },
91
  { std::make_pair (13, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2472, 20) },
92
  // Only defined for 802.11b
93
  { std::make_pair (14, WIFI_PHY_STANDARD_80211b), std::make_pair (2484, 22) },
94
95
  // Now the 5GHz channels; UNSPECIFIED for 802.11a/n channels, but limited
96
  // to 802.11ac for the 80/160 MHz channels
97
  // 20 MHz channels
98
  { std::make_pair (36, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5180, 20) },
99
  { std::make_pair (40, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5200, 20) },
100
  { std::make_pair (44, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5220, 20) },
101
  { std::make_pair (48, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5240, 20) },
102
  { std::make_pair (52, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5260, 20) },
103
  { std::make_pair (56, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5280, 20) },
104
  { std::make_pair (60, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5300, 20) },
105
  { std::make_pair (64, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5320, 20) },
106
  { std::make_pair (100, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5500, 20) },
107
  { std::make_pair (104, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5520, 20) },
108
  { std::make_pair (108, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5540, 20) },
109
  { std::make_pair (112, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5560, 20) },
110
  { std::make_pair (116, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5580, 20) },
111
  { std::make_pair (120, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5600, 20) },
112
  { std::make_pair (124, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5620, 20) },
113
  { std::make_pair (128, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5640, 20) },
114
  { std::make_pair (132, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5660, 20) },
115
  { std::make_pair (136, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5680, 20) },
116
  { std::make_pair (140, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5700, 20) },
117
  { std::make_pair (144, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5720, 20) },
118
  { std::make_pair (149, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5745, 20) },
119
  { std::make_pair (153, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5765, 20) },
120
  { std::make_pair (157, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5785, 20) },
121
  { std::make_pair (161, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5805, 20) },
122
  { std::make_pair (165, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5825, 20) },
123
  // 40 MHz channels
124
  { std::make_pair (38, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5190, 40) },
125
  { std::make_pair (46, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5230, 40) },
126
  { std::make_pair (54, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5230, 40) },
127
  { std::make_pair (62, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5310, 40) },
128
  { std::make_pair (102, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5510, 40) },
129
  { std::make_pair (110, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5550, 40) },
130
  { std::make_pair (118, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5590, 40) },
131
  { std::make_pair (126, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5590, 40) },
132
  { std::make_pair (134, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5670, 40) },
133
  { std::make_pair (142, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5710, 40) },
134
  { std::make_pair (151, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5755, 40) },
135
  { std::make_pair (159, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5795, 40) },
136
  // 80 MHz channels
137
  { std::make_pair (42, WIFI_PHY_STANDARD_80211ac), std::make_pair (5210, 80) },
138
  { std::make_pair (58, WIFI_PHY_STANDARD_80211ac), std::make_pair (5290, 80) },
139
  { std::make_pair (106, WIFI_PHY_STANDARD_80211ac), std::make_pair (5530, 80) },
140
  { std::make_pair (122, WIFI_PHY_STANDARD_80211ac), std::make_pair (5610, 80) },
141
  { std::make_pair (138, WIFI_PHY_STANDARD_80211ac), std::make_pair (5690, 80) },
142
  { std::make_pair (155, WIFI_PHY_STANDARD_80211ac), std::make_pair (5775, 80) },
143
  // 160 MHz channels
144
  { std::make_pair (50, WIFI_PHY_STANDARD_80211ac), std::make_pair (5250, 160) },
145
  { std::make_pair (114, WIFI_PHY_STANDARD_80211ac), std::make_pair (5570, 160) },
146
147
  // 802.11p (10 MHz channels at the 5.855-5.925 band 
148
  { std::make_pair (172, WIFI_PHY_STANDARD_80211_10MHZ), std::make_pair (5860, 10) },
149
  { std::make_pair (174, WIFI_PHY_STANDARD_80211_10MHZ), std::make_pair (5870, 10) },
150
  { std::make_pair (176, WIFI_PHY_STANDARD_80211_10MHZ), std::make_pair (5880, 10) },
151
  { std::make_pair (178, WIFI_PHY_STANDARD_80211_10MHZ), std::make_pair (5890, 10) },
152
  { std::make_pair (180, WIFI_PHY_STANDARD_80211_10MHZ), std::make_pair (5900, 10) },
153
  { std::make_pair (182, WIFI_PHY_STANDARD_80211_10MHZ), std::make_pair (5910, 10) },
154
  { std::make_pair (184, WIFI_PHY_STANDARD_80211_10MHZ), std::make_pair (5920, 10) }
155
};
156
54
TypeId
157
TypeId
55
WifiPhy::GetTypeId (void)
158
WifiPhy::GetTypeId (void)
56
{
159
{
57
  static TypeId tid = TypeId ("ns3::WifiPhy")
160
  static TypeId tid = TypeId ("ns3::WifiPhy")
58
    .SetParent<Object> ()
161
    .SetParent<Object> ()
59
    .SetGroupName ("Wifi")
162
    .SetGroupName ("Wifi")
163
    .AddAttribute ("Frequency",
164
                   "The operating center frequency (MHz)",
165
                   UintegerValue (0),
166
                   MakeUintegerAccessor (&WifiPhy::GetFrequency,
167
                                         &WifiPhy::SetFrequency),
168
                   MakeUintegerChecker<uint32_t> ())
169
    .AddAttribute ("ChannelWidth",
170
                   "Whether 5MHz, 10MHz, 20MHz, 22MHz, 40MHz, 80 MHz or 160 MHz.",
171
                   UintegerValue (20),
172
                   MakeUintegerAccessor (&WifiPhy::GetChannelWidth,
173
                                         &WifiPhy::SetChannelWidth),
174
                   MakeUintegerChecker<uint32_t> ())
175
    .AddAttribute ("ChannelNumber",
176
                   "If set to non-zero defined value, will control Frequency and ChannelWidth assignment",
177
                   UintegerValue (0),
178
                   MakeUintegerAccessor (&WifiPhy::SetChannelNumber,
179
                                         &WifiPhy::GetChannelNumber),
180
                   MakeUintegerChecker<uint16_t> ())
60
    .AddTraceSource ("PhyTxBegin",
181
    .AddTraceSource ("PhyTxBegin",
61
                     "Trace source indicating a packet "
182
                     "Trace source indicating a packet "
62
                     "has begun transmitting over the channel medium",
183
                     "has begun transmitting over the channel medium",
 Lines 107-112    Link Here 
107
}
228
}
108
229
109
WifiPhy::WifiPhy ()
230
WifiPhy::WifiPhy ()
231
  : m_standard (WIFI_PHY_STANDARD_UNSPECIFIED),
232
    m_channelCenterFrequency (0),
233
    m_channelNumber (1)
110
{
234
{
111
  NS_LOG_FUNCTION (this);
235
  NS_LOG_FUNCTION (this);
112
  m_totalAmpduSize = 0;
236
  m_totalAmpduSize = 0;
 Lines 118-123    Link Here 
118
  NS_LOG_FUNCTION (this);
242
  NS_LOG_FUNCTION (this);
119
}
243
}
120
244
245
void
246
WifiPhy::ConfigureDefaultsForStandard (enum WifiPhyStandard standard)
247
{
248
  NS_LOG_FUNCTION (this << standard);
249
  switch (standard)
250
    {
251
    case WIFI_PHY_STANDARD_80211a:
252
      SetChannelWidth (20);
253
      SetFrequency (5180);
254
      // Channel number should be aligned by SetFrequency () to 36
255
      NS_ASSERT (GetChannelNumber () == 36);
256
      break;
257
    case WIFI_PHY_STANDARD_80211b:
258
      SetChannelWidth (22);
259
      SetFrequency (2412);
260
      // Channel number should be aligned by SetFrequency () to 1
261
      NS_ASSERT (GetChannelNumber () == 1);
262
      break;
263
    case WIFI_PHY_STANDARD_80211g:
264
      SetChannelWidth (20);
265
      SetFrequency (2412);
266
      // Channel number should be aligned by SetFrequency () to 1
267
      NS_ASSERT (GetChannelNumber () == 1);
268
      break;
269
    case WIFI_PHY_STANDARD_80211_10MHZ:
270
      SetChannelWidth (10);
271
      SetFrequency (5860);
272
      // Channel number should be aligned by SetFrequency () to 172
273
      NS_ASSERT (GetChannelNumber () == 172);
274
      break;
275
    case WIFI_PHY_STANDARD_80211_5MHZ:
276
      SetChannelWidth (5);
277
      SetFrequency (5860);
278
      // Channel number should be aligned by SetFrequency () to 0 
279
      NS_ASSERT (GetChannelNumber () == 0);
280
      break;
281
    case WIFI_PHY_STANDARD_holland:
282
      SetChannelWidth (20);
283
      SetFrequency (5180);
284
      // Channel number should be aligned by SetFrequency () to 36
285
      NS_ASSERT (GetChannelNumber () == 36);
286
      break;
287
    case WIFI_PHY_STANDARD_80211n_2_4GHZ:
288
      SetChannelWidth (20);
289
      SetFrequency (2412);
290
      // Channel number should be aligned by SetFrequency () to 1
291
      NS_ASSERT (GetChannelNumber () == 1);
292
      break;
293
    case WIFI_PHY_STANDARD_80211n_5GHZ:
294
      SetChannelWidth (20);
295
      SetFrequency (5180);
296
      // Channel number should be aligned by SetFrequency () to 36
297
      NS_ASSERT (GetChannelNumber () == 36);
298
      break;
299
    case WIFI_PHY_STANDARD_80211ac:
300
      SetChannelWidth (80);
301
      SetFrequency (5210);
302
      // Channel number should be aligned by SetFrequency () to 42
303
      NS_ASSERT (GetChannelNumber () == 42);
304
      break;
305
    case WIFI_PHY_STANDARD_UNSPECIFIED:
306
      NS_LOG_WARN ("Configuring unspecified standard; performing no action");
307
      break;
308
    default:
309
      NS_ASSERT (false);
310
      break;
311
    }
312
}
313
314
bool 
315
WifiPhy::DefineChannelNumber (uint16_t channelNumber, enum WifiPhyStandard standard, uint32_t frequency, uint32_t channelWidth)
316
{
317
  NS_LOG_FUNCTION (this << channelNumber << standard << frequency << channelWidth);
318
  ChannelNumberStandardPair p = std::make_pair (channelNumber, standard);
319
  ChannelToFrequencyWidthMap::const_iterator it;
320
  it = m_channelToFrequencyWidth.find (p);
321
  if (it != m_channelToFrequencyWidth.end ())
322
    {
323
      NS_LOG_DEBUG ("channel number/standard already defined; returning false");
324
      return false;
325
    }
326
  FrequencyWidthPair f = std::make_pair (frequency, channelWidth);
327
  m_channelToFrequencyWidth[p] = f;
328
  return true;
329
}
330
331
uint16_t 
332
WifiPhy::FindChannelNumberForFrequencyWidth (uint32_t frequency, uint32_t width) const
333
{
334
  NS_LOG_FUNCTION (this << frequency << width);
335
  bool found = false;
336
  FrequencyWidthPair f = std::make_pair (frequency, width);
337
  ChannelToFrequencyWidthMap::const_iterator it = m_channelToFrequencyWidth.begin ();
338
  while (it != m_channelToFrequencyWidth.end ())
339
    {
340
      if (it->second == f)
341
        {
342
           found = true;
343
           break;
344
        }
345
      ++it;
346
    }
347
  if (found)
348
    {
349
      NS_LOG_DEBUG ("Found, returning " << it->first.first);
350
      return (it->first.first);
351
    }
352
  else
353
    {
354
      NS_LOG_DEBUG ("Not found, returning 0");
355
      return 0;
356
    }
357
}
358
359
void
360
WifiPhy::ConfigureChannelForStandard (enum WifiPhyStandard standard)
361
{
362
  NS_LOG_FUNCTION (this << standard);
363
  // If the user has configured both Frequency and ChannelNumber, Frequency
364
  // takes precedence 
365
  if (GetFrequency () != 0)
366
    {
367
      // If Frequency is already set, then see whether a ChannelNumber can
368
      // be found that matches Frequency and ChannelWidth.  If so, configure 
369
      // the ChannelNumber to that channel number.  If not, set 
370
      // ChannelNumber to zero.
371
      NS_LOG_DEBUG ("Frequency set; checking whether a channel number corresponds");
372
      uint32_t channelNumberSearched = FindChannelNumberForFrequencyWidth (GetFrequency (), GetChannelWidth ());
373
      if (channelNumberSearched)
374
        {
375
          NS_LOG_DEBUG ("Channel number found; setting to " << channelNumberSearched);
376
          SetChannelNumber (channelNumberSearched);
377
        }
378
      else
379
        {
380
          NS_LOG_DEBUG ("Channel number not found; setting to zero");
381
          SetChannelNumber (0);
382
        }
383
    }
384
  else if (GetChannelNumber () != 0)
385
    {
386
      // If the channel number is known for this particular standard or for 
387
      // the unspecified standard, configure using the known values;
388
      // otherwise, this is a configuration error
389
      NS_LOG_DEBUG ("Configuring for channel number " << GetChannelNumber ());
390
      ChannelNumberStandardPair p = std::make_pair (GetChannelNumber (), standard);
391
      FrequencyWidthPair f;
392
      ChannelToFrequencyWidthMap::const_iterator it;
393
      it = m_channelToFrequencyWidth.find (p);
394
      if (it != m_channelToFrequencyWidth.end ())
395
        {
396
          f = m_channelToFrequencyWidth[p];
397
        }
398
      else
399
        {
400
          // the specific pair of number/standard is not known
401
          NS_LOG_DEBUG ("Falling back to check WIFI_PHY_STANDARD_UNSPECIFIED");
402
          ChannelNumberStandardPair p2 = std::make_pair (GetChannelNumber (), WIFI_PHY_STANDARD_UNSPECIFIED);
403
          it = m_channelToFrequencyWidth.find (p2);
404
        }
405
      if (it == m_channelToFrequencyWidth.end())
406
        {
407
          NS_FATAL_ERROR ("Error, ChannelNumber " << GetChannelNumber () << " is unknown for this standard");
408
        }
409
      else
410
        {
411
          NS_LOG_DEBUG ("Setting frequency to " << f.first << "; width to " << f.second);
412
          SetFrequency (f.first);
413
          SetChannelWidth (f.second);
414
        }
415
    }
416
}
417
418
void
419
WifiPhy::ConfigureStandard (enum WifiPhyStandard standard)
420
{
421
  NS_LOG_FUNCTION (this << standard);
422
  m_standard = standard;
423
  if (GetFrequency () == 0 && GetChannelNumber () == 0)
424
    {
425
      ConfigureDefaultsForStandard (standard);
426
    }
427
  else
428
    {
429
      // The user has configured either (or both) Frequency or ChannelNumber
430
      ConfigureChannelForStandard (standard);
431
    }
432
}
433
434
void
435
WifiPhy::SetFrequency (uint32_t frequency)
436
{
437
  NS_LOG_FUNCTION (this << frequency);
438
  // If the user has configured both Frequency and ChannelNumber, Frequency
439
  // takes precedence 
440
  if (GetFrequency () == frequency)
441
    {
442
      NS_LOG_DEBUG ("No frequency change requested");
443
      return;
444
    }
445
  if (frequency == 0)
446
    {
447
      DoFrequencySwitch (0);
448
      NS_LOG_DEBUG ("Setting frequency and channel number to zero");
449
      m_channelCenterFrequency = 0;
450
      m_channelNumber = 0;
451
      return;
452
    }
453
  // See if there corresponds a channel number to the requested frequency.
454
  uint16_t nch = FindChannelNumberForFrequencyWidth (frequency, GetChannelWidth ());
455
  if (nch != 0)
456
    {
457
      NS_LOG_DEBUG ("Setting frequency " << frequency << " corresponds to channel " << nch);
458
      if (DoFrequencySwitch (frequency))
459
        {
460
          NS_LOG_DEBUG ("Channel frequency switched to " << frequency << "; channel number to " << nch);
461
          m_channelCenterFrequency = frequency;
462
          m_channelNumber = nch;
463
        }
464
    else
465
        {
466
          NS_LOG_DEBUG ("Suppressing reassignment of frequency");
467
        }
468
    }
469
  else
470
    {
471
      NS_LOG_DEBUG ("Channel number is unknown for frequency " << frequency);
472
      if (DoFrequencySwitch (frequency))
473
        {
474
          NS_LOG_DEBUG ("Channel frequency switched to " << frequency << "; channel number to " << 0);
475
          m_channelCenterFrequency = frequency;
476
          m_channelNumber = 0;
477
        }
478
    else
479
        {
480
          NS_LOG_DEBUG ("Suppressing reassignment of frequency");
481
        }
482
    }
483
}
484
485
uint32_t
486
WifiPhy::GetFrequency (void) const
487
{
488
  return m_channelCenterFrequency;
489
}
490
491
void
492
WifiPhy::SetChannelWidth (uint32_t channelwidth)
493
{
494
  NS_ASSERT_MSG (channelwidth == 5 || channelwidth == 10 || channelwidth == 20 || channelwidth == 22 || channelwidth == 40 || channelwidth == 80 || channelwidth == 160, "wrong channel width value");
495
  m_channelWidth = channelwidth;
496
  AddSupportedChannelWidth (channelwidth);
497
}
498
499
uint32_t
500
WifiPhy::GetChannelWidth (void) const
501
{
502
  return m_channelWidth;
503
}
504
505
void
506
WifiPhy::AddSupportedChannelWidth (uint32_t width)
507
{
508
  NS_LOG_FUNCTION (this << width);
509
  for (std::vector<uint32_t>::size_type i = 0; i != m_supportedChannelWidthSet.size (); i++)
510
    {
511
      if (m_supportedChannelWidthSet[i] == width)
512
        {
513
          return;
514
        }
515
    }
516
  m_supportedChannelWidthSet.push_back (width);
517
}
518
519
std::vector<uint32_t> 
520
WifiPhy::GetSupportedChannelWidthSet (void) const
521
{
522
  return m_supportedChannelWidthSet;
523
}
524
525
void
526
WifiPhy::SetChannelNumber (uint16_t nch)
527
{
528
  NS_LOG_FUNCTION (this << nch);
529
  if (GetChannelNumber () == nch)
530
    {
531
      NS_LOG_DEBUG ("No channel change requested");
532
      return;
533
    }
534
  if (nch == 0)
535
    {
536
      DoChannelSwitch (nch);
537
      m_channelNumber = 0;
538
      return;
539
    }
540
541
  ChannelNumberStandardPair p = std::make_pair (nch, m_standard);
542
  FrequencyWidthPair f = m_channelToFrequencyWidth[p];
543
  if (f.first == 0 && m_standard != WIFI_PHY_STANDARD_UNSPECIFIED)
544
    {
545
      // the specific pair of number/standard is not known
546
      NS_LOG_DEBUG ("Falling back to check WIFI_PHY_STANDARD_UNSPECIFIED");
547
      ChannelNumberStandardPair p2 = std::make_pair (nch, WIFI_PHY_STANDARD_UNSPECIFIED);
548
      f = m_channelToFrequencyWidth[p2];
549
    }
550
  if (f.first == 0)
551
    {
552
      NS_FATAL_ERROR ("Error, ChannelNumber " << nch << " is unknown for this standard");
553
    }
554
  if (DoChannelSwitch (nch))
555
    {
556
      m_channelNumber = nch;
557
      NS_LOG_DEBUG ("Setting frequency to " << f.first << "; width to " << f.second);
558
      m_channelCenterFrequency = f.first;
559
      SetChannelWidth (f.second);
560
    }
561
  else
562
    {
563
      NS_LOG_DEBUG ("Suppressing reassignment of channel number");
564
    }
565
}
566
567
uint16_t
568
WifiPhy::GetChannelNumber (void) const
569
{
570
  return m_channelNumber;
571
}
572
573
bool
574
WifiPhy::DoChannelSwitch (uint16_t nch)
575
{
576
  return true;
577
}
578
579
bool
580
WifiPhy::DoFrequencySwitch (uint32_t frequency)
581
{
582
  return true;
583
}
584
121
WifiMode
585
WifiMode
122
WifiPhy::GetHtPlcpHeaderMode (WifiMode payloadMode)
586
WifiPhy::GetHtPlcpHeaderMode (WifiMode payloadMode)
123
{
587
{
(-)a/src/wifi/model/wifi-phy.h (-17 / +103 lines)
 Lines 23-28    Link Here 
23
#define WIFI_PHY_H
23
#define WIFI_PHY_H
24
24
25
#include <stdint.h>
25
#include <stdint.h>
26
#include <map>
26
#include "ns3/callback.h"
27
#include "ns3/callback.h"
27
#include "ns3/packet.h"
28
#include "ns3/packet.h"
28
#include "ns3/object.h"
29
#include "ns3/object.h"
 Lines 33-38    Link Here 
33
#include "wifi-phy-standard.h"
34
#include "wifi-phy-standard.h"
34
#include "ns3/traced-callback.h"
35
#include "ns3/traced-callback.h"
35
#include "wifi-tx-vector.h"
36
#include "wifi-tx-vector.h"
37
#include "wifi-phy-standard.h"
36
38
37
namespace ns3 {
39
namespace ns3 {
38
40
 Lines 556-571    Link Here 
556
   *
558
   *
557
   * where Starting channel frequency is standard-dependent, see SetStandard()
559
   * where Starting channel frequency is standard-dependent, see SetStandard()
558
   * as defined in (Section 18.3.8.4.2 "Channel numbering"; IEEE Std 802.11-2012).
560
   * as defined in (Section 18.3.8.4.2 "Channel numbering"; IEEE Std 802.11-2012).
561
   * This method may fail to take action if the Phy model determines that
562
   * the channel number cannot be switched for some reason (e.g. sleep state)
559
   *
563
   *
560
   * \param id the channel number
564
   * \param id the channel number
561
   */
565
   */
562
  virtual void SetChannelNumber (uint16_t id) = 0;
566
  virtual void SetChannelNumber (uint16_t id);
563
  /**
567
  /**
564
   * Return current channel number.
568
   * Return current channel number.
565
   *
569
   *
566
   * \return the current channel number
570
   * \return the current channel number
567
   */
571
   */
568
  virtual uint16_t GetChannelNumber (void) const = 0;
572
  virtual uint16_t GetChannelNumber (void) const;
569
  /**
573
  /**
570
   * \return the required time for channel switch operation of this WifiPhy
574
   * \return the required time for channel switch operation of this WifiPhy
571
   */
575
   */
 Lines 576-582    Link Here 
576
   *
580
   *
577
   * \param standard the Wi-Fi standard
581
   * \param standard the Wi-Fi standard
578
   */
582
   */
579
  virtual void ConfigureStandard (enum WifiPhyStandard standard) = 0;
583
  virtual void ConfigureStandard (enum WifiPhyStandard standard);
584
585
  /**
586
   * Add a channel definition to the WifiPhy.  The pair (channelNumber,
587
   * WifiPhyStandard) may then be used to lookup a pair (frequency, 
588
   * channelWidth).
589
   *
590
   * If the channel is not already defined for the standard, the method
591
   * should return true; otherwise false.
592
   *
593
   * \param channelNumber the channel number to define
594
   * \param standard the applicable WifiPhyStandard
595
   * \param frequency the frequency (MHz)
596
   * \param channelWidth the channel width (MHz)
597
   *
598
   * \return true if the channel definition succeeded
599
   */
600
  bool DefineChannelNumber (uint16_t channelNumber, enum WifiPhyStandard standard, uint32_t frequency, uint32_t channelWidth);
601
602
  /**
603
   * A pair of a ChannelNumber and WifiPhyStandard
604
   */
605
  typedef std::pair<uint16_t, enum WifiPhyStandard> ChannelNumberStandardPair;
606
  /**
607
   * A pair of a center Frequency and a ChannelWidth
608
   */
609
  typedef std::pair<uint32_t, uint32_t> FrequencyWidthPair;
580
610
581
  /**
611
  /**
582
   * Return the WifiChannel this WifiPhy is connected to.
612
   * Return the WifiChannel this WifiPhy is connected to.
 Lines 1210-1222    Link Here 
1210
  virtual int64_t AssignStreams (int64_t stream) = 0;
1240
  virtual int64_t AssignStreams (int64_t stream) = 0;
1211
1241
1212
  /**
1242
  /**
1213
   * \param freq the operating frequency on this node.
1243
   * \param freq the operating center frequency (MHz) on this node.
1214
   */
1244
   */
1215
  virtual void SetFrequency (uint32_t freq) = 0;
1245
  virtual void SetFrequency (uint32_t freq);
1216
  /**
1246
  /**
1217
   * \return the operating frequency on this node
1247
   * \return the operating center frequency (MHz) 
1218
   */
1248
   */
1219
  virtual uint32_t GetFrequency (void) const = 0;
1249
  virtual uint32_t GetFrequency (void) const;
1220
  /**
1250
  /**
1221
   * \param tx the number of transmitters on this node.
1251
   * \param tx the number of transmitters on this node.
1222
   */
1252
   */
 Lines 1276-1286    Link Here 
1276
  /**
1306
  /**
1277
   * \return the channel width
1307
   * \return the channel width
1278
   */
1308
   */
1279
  virtual uint32_t GetChannelWidth (void) const = 0;
1309
  virtual uint32_t GetChannelWidth (void) const;
1280
  /**
1310
  /**
1281
   * \param channelwidth channel width
1311
   * \param channelwidth channel width
1282
   */
1312
   */
1283
  virtual void SetChannelWidth (uint32_t channelwidth) = 0;
1313
  virtual void SetChannelWidth (uint32_t channelwidth);
1314
  /**
1315
   * \param channelwidth channel width (in MHz) to support
1316
   */
1317
  virtual void AddSupportedChannelWidth (uint32_t channelwidth);
1318
  /**
1319
   * \return a vector containing the supported channel widths, values in MHz
1320
   */
1321
  virtual std::vector<uint32_t> GetSupportedChannelWidthSet (void) const;
1284
  /**
1322
  /**
1285
   * \return the maximum number of supported Rx spatial streams
1323
   * \return the maximum number of supported Rx spatial streams
1286
   */
1324
   */
 Lines 1290-1303    Link Here 
1290
   */
1328
   */
1291
  virtual uint8_t GetSupportedTxSpatialStreams (void) const = 0;
1329
  virtual uint8_t GetSupportedTxSpatialStreams (void) const = 0;
1292
  /**
1330
  /**
1293
   * \param width channel width (in MHz) to support
1294
   */
1295
  virtual void AddSupportedChannelWidth (uint32_t width) = 0;
1296
  /**
1297
   * \return a vector containing the supported channel widths, values in MHz
1298
   */
1299
  virtual std::vector<uint32_t> GetSupportedChannelWidthSet (void) const = 0;
1300
  /**
1301
   * Convert from dBm to Watts.
1331
   * Convert from dBm to Watts.
1302
   *
1332
   *
1303
   * \param dbm the power in dBm
1333
   * \param dbm the power in dBm
 Lines 1332-1337    Link Here 
1332
1362
1333
private:
1363
private:
1334
  /**
1364
  /**
1365
   * The default implementation does nothing and returns true.  This method 
1366
   * is typically called internally by SetChannelNumber ().
1367
   *
1368
   * \brief Perform any actions necessary when user changes channel number
1369
   * \param id channel number to try to switch to
1370
   * \return true if WifiPhy can actually change the number; false if not
1371
   * \see SetChannelNumber
1372
   */
1373
  virtual bool DoChannelSwitch (uint16_t id);
1374
  /**
1375
   * The default implementation does nothing and returns true.  This method
1376
   * is typically called internally by SetFrequency ().
1377
   *
1378
   * \brief Perform any actions necessary when user changes frequency
1379
   * \param frequency frequency to try to switch to
1380
   * \return true if WifiPhy can actually change the frequency; false if not
1381
   * \see SetFrequency
1382
   */
1383
  virtual bool DoFrequencySwitch (uint32_t frequency);
1384
  /**
1385
   * Configure the PHY-level parameters for different Wi-Fi standard.
1386
   * This method is called when defaults for each standard must be 
1387
   * selected.
1388
   *
1389
   * \param standard the Wi-Fi standard
1390
   */
1391
  virtual void ConfigureDefaultsForStandard (enum WifiPhyStandard standard);
1392
  /**
1393
   * Configure the PHY-level parameters for different Wi-Fi standard.
1394
   * This method is called when the Frequency or ChannelNumber attributes
1395
   * are set by the user.  If the Frequency or ChannelNumber are valid for
1396
   * the standard, they are used instead.
1397
   *
1398
   * \param standard the Wi-Fi standard
1399
   */
1400
  virtual void ConfigureChannelForStandard (enum WifiPhyStandard standard);
1401
  /**
1402
   * Look for 
1403
   * \param frequency The center frequency to use
1404
   * \param width The channel width to use
1405
   * \return the channel number if found, zero if not
1406
   */
1407
  uint16_t FindChannelNumberForFrequencyWidth (uint32_t frequency, uint32_t width) const;
1408
1409
  /**
1335
   * The trace source fired when a packet begins the transmission process on
1410
   * The trace source fired when a packet begins the transmission process on
1336
   * the medium.
1411
   * the medium.
1337
   *
1412
   *
 Lines 1408-1413    Link Here 
1408
  TracedCallback<Ptr<const Packet>, uint16_t, uint16_t, uint32_t,
1483
  TracedCallback<Ptr<const Packet>, uint16_t, uint16_t, uint32_t,
1409
                 WifiPreamble, WifiTxVector, struct mpduInfo> m_phyMonitorSniffTxTrace;
1484
                 WifiPreamble, WifiTxVector, struct mpduInfo> m_phyMonitorSniffTxTrace;
1410
1485
1486
  enum WifiPhyStandard m_standard;     //!< WifiPhyStandard
1487
  uint32_t m_channelCenterFrequency;   //!< Center frequency in MHz
1488
  uint32_t m_channelWidth;             //!< Channel width
1489
1490
1491
  typedef std::map<ChannelNumberStandardPair,FrequencyWidthPair> ChannelToFrequencyWidthMap;
1492
  static ChannelToFrequencyWidthMap m_channelToFrequencyWidth;
1493
1494
  std::vector<uint32_t> m_supportedChannelWidthSet; //!< Supported channel width
1495
  uint16_t             m_channelNumber;  //!< Operating channel number
1496
1411
  double m_totalAmpduNumSymbols;   //!< Number of symbols previously transmitted for the MPDUs in an A-MPDU, used for the computation of the number of symbols needed for the last MPDU in the A-MPDU
1497
  double m_totalAmpduNumSymbols;   //!< Number of symbols previously transmitted for the MPDUs in an A-MPDU, used for the computation of the number of symbols needed for the last MPDU in the A-MPDU
1412
  uint32_t m_totalAmpduSize;       //!< Total size of the previously transmitted MPDUs in an A-MPDU, used for the computation of the number of symbols needed for the last MPDU in the A-MPDU
1498
  uint32_t m_totalAmpduSize;       //!< Total size of the previously transmitted MPDUs in an A-MPDU, used for the computation of the number of symbols needed for the last MPDU in the A-MPDU
1413
};
1499
};
(-)a/src/wifi/model/yans-wifi-phy.cc (-151 / +109 lines)
 Lines 119-136    Link Here 
119
                   TimeValue (MicroSeconds (250)),
119
                   TimeValue (MicroSeconds (250)),
120
                   MakeTimeAccessor (&YansWifiPhy::m_channelSwitchDelay),
120
                   MakeTimeAccessor (&YansWifiPhy::m_channelSwitchDelay),
121
                   MakeTimeChecker ())
121
                   MakeTimeChecker ())
122
    .AddAttribute ("ChannelNumber",
123
                   "Channel center frequency = Channel starting frequency + 5 MHz * nch.",
124
                   UintegerValue (1),
125
                   MakeUintegerAccessor (&YansWifiPhy::SetChannelNumber,
126
                                         &YansWifiPhy::GetChannelNumber),
127
                   MakeUintegerChecker<uint16_t> ())
128
    .AddAttribute ("Frequency",
129
                   "The operating frequency.",
130
                   UintegerValue (2407),
131
                   MakeUintegerAccessor (&YansWifiPhy::GetFrequency,
132
                                         &YansWifiPhy::SetFrequency),
133
                   MakeUintegerChecker<uint32_t> ())
134
    .AddAttribute ("TxAntennas",
122
    .AddAttribute ("TxAntennas",
135
                   "The number of supported Tx antennas.",
123
                   "The number of supported Tx antennas.",
136
                   UintegerValue (1),
124
                   UintegerValue (1),
 Lines 177-198    Link Here 
177
                   MakeBooleanAccessor (&YansWifiPhy::GetShortPlcpPreambleSupported,
165
                   MakeBooleanAccessor (&YansWifiPhy::GetShortPlcpPreambleSupported,
178
                                        &YansWifiPhy::SetShortPlcpPreambleSupported),
166
                                        &YansWifiPhy::SetShortPlcpPreambleSupported),
179
                   MakeBooleanChecker ())
167
                   MakeBooleanChecker ())
180
    .AddAttribute ("ChannelWidth",
181
                   "Whether 5MHz, 10MHz, 20MHz, 22MHz, 40MHz, 80 MHz or 160 MHz.",
182
                   UintegerValue (20),
183
                   MakeUintegerAccessor (&YansWifiPhy::GetChannelWidth,
184
                                         &YansWifiPhy::SetChannelWidth),
185
                   MakeUintegerChecker<uint32_t> ())
186
  ;
168
  ;
187
  return tid;
169
  return tid;
188
}
170
}
189
171
190
YansWifiPhy::YansWifiPhy ()
172
YansWifiPhy::YansWifiPhy ()
191
  : m_initialized (false),
173
  : m_initialized (false),
192
    m_channelNumber (1),
193
    m_endRxEvent (),
174
    m_endRxEvent (),
194
    m_endPlcpRxEvent (),
175
    m_endPlcpRxEvent (),
195
    m_channelStartingFrequency (0),
196
    m_mpdusNum (0),
176
    m_mpdusNum (0),
197
    m_plcpSuccess (false),
177
    m_plcpSuccess (false),
198
    m_txMpduReferenceNumber (0xffffffff),
178
    m_txMpduReferenceNumber (0xffffffff),
 Lines 227-236    Link Here 
227
  m_initialized = true;
207
  m_initialized = true;
228
}
208
}
229
209
210
bool
211
YansWifiPhy::DoChannelSwitch (uint16_t nch)
212
{
213
  if (!m_initialized)
214
    {
215
      //this is not channel switch, this is initialization
216
      NS_LOG_DEBUG ("start at channel " << nch);
217
      return true;
218
    }
219
220
  NS_ASSERT (!IsStateSwitching ());
221
  switch (m_state->GetState ())
222
    {
223
    case YansWifiPhy::RX:
224
      NS_LOG_DEBUG ("drop packet because of channel switching while reception");
225
      m_endPlcpRxEvent.Cancel ();
226
      m_endRxEvent.Cancel ();
227
      goto switchChannel;
228
      break;
229
    case YansWifiPhy::TX:
230
      NS_LOG_DEBUG ("channel switching postponed until end of current transmission");
231
      Simulator::Schedule (GetDelayUntilIdle (), &WifiPhy::SetChannelNumber, this, nch);
232
      break;
233
    case YansWifiPhy::CCA_BUSY:
234
    case YansWifiPhy::IDLE:
235
      goto switchChannel;
236
      break;
237
    case YansWifiPhy::SLEEP:
238
      NS_LOG_DEBUG ("channel switching ignored in sleep mode");
239
      break;
240
    default:
241
      NS_ASSERT (false);
242
      break;
243
    }
244
245
  return false;
246
247
switchChannel:
248
249
  NS_LOG_DEBUG ("switching channel " << GetChannelNumber () << " -> " << nch);
250
  m_state->SwitchToChannelSwitching (m_channelSwitchDelay);
251
  m_interference.EraseEvents ();
252
  /*
253
   * Needed here to be able to correctly sensed the medium for the first
254
   * time after the switching. The actual switching is not performed until
255
   * after m_channelSwitchDelay. Packets received during the switching
256
   * state are added to the event list and are employed later to figure
257
   * out the state of the medium after the switching.
258
   */
259
  return true;
260
}
261
262
bool
263
YansWifiPhy::DoFrequencySwitch (uint32_t frequency)
264
{
265
  if (!m_initialized)
266
    {
267
      //this is not channel switch, this is initialization
268
      NS_LOG_DEBUG ("start at frequency " << frequency);
269
      return true;
270
    }
271
272
  NS_ASSERT (!IsStateSwitching ());
273
  switch (m_state->GetState ())
274
    {
275
    case YansWifiPhy::RX:
276
      NS_LOG_DEBUG ("drop packet because of channel/frequency switching while reception");
277
      m_endPlcpRxEvent.Cancel ();
278
      m_endRxEvent.Cancel ();
279
      goto switchFrequency;
280
      break;
281
    case YansWifiPhy::TX:
282
      NS_LOG_DEBUG ("channel/frequency switching postponed until end of current transmission");
283
      Simulator::Schedule (GetDelayUntilIdle (), &WifiPhy::SetFrequency, this, frequency);
284
      break;
285
    case YansWifiPhy::CCA_BUSY:
286
    case YansWifiPhy::IDLE:
287
      goto switchFrequency;
288
      break;
289
    case YansWifiPhy::SLEEP:
290
      NS_LOG_DEBUG ("frequency switching ignored in sleep mode");
291
      break;
292
    default:
293
      NS_ASSERT (false);
294
      break;
295
    }
296
297
  return false;
298
299
switchFrequency:
300
301
  NS_LOG_DEBUG ("switching frequency " << GetFrequency () << " -> " << frequency);
302
  m_state->SwitchToChannelSwitching (m_channelSwitchDelay);
303
  m_interference.EraseEvents ();
304
  /*
305
   * Needed here to be able to correctly sensed the medium for the first
306
   * time after the switching. The actual switching is not performed until
307
   * after m_channelSwitchDelay. Packets received during the switching
308
   * state are added to the event list and are employed later to figure
309
   * out the state of the medium after the switching.
310
   */
311
  return true;
312
}
313
230
void
314
void
231
YansWifiPhy::ConfigureStandard (enum WifiPhyStandard standard)
315
YansWifiPhy::ConfigureStandard (enum WifiPhyStandard standard)
232
{
316
{
233
  NS_LOG_FUNCTION (this << standard);
317
  NS_LOG_FUNCTION (this << standard);
318
  WifiPhy::ConfigureStandard (standard); // set up base class
234
  switch (standard)
319
  switch (standard)
235
    {
320
    {
236
    case WIFI_PHY_STANDARD_80211a:
321
    case WIFI_PHY_STANDARD_80211a:
 Lines 252-262    Link Here 
252
      ConfigureHolland ();
337
      ConfigureHolland ();
253
      break;
338
      break;
254
    case WIFI_PHY_STANDARD_80211n_2_4GHZ:
339
    case WIFI_PHY_STANDARD_80211n_2_4GHZ:
255
      m_channelStartingFrequency = 2407;
256
      Configure80211n ();
340
      Configure80211n ();
257
      break;
341
      break;
258
    case WIFI_PHY_STANDARD_80211n_5GHZ:
342
    case WIFI_PHY_STANDARD_80211n_5GHZ:
259
      m_channelStartingFrequency = 5e3;
260
      Configure80211n ();
343
      Configure80211n ();
261
      break;
344
      break;
262
    case WIFI_PHY_STANDARD_80211ac:
345
    case WIFI_PHY_STANDARD_80211ac:
 Lines 428-504    Link Here 
428
  m_channel->Add (this);
511
  m_channel->Add (this);
429
}
512
}
430
513
431
void
432
YansWifiPhy::SetChannelNumber (uint16_t nch)
433
{
434
  if (!m_initialized)
435
    {
436
      //this is not channel switch, this is initialization
437
      NS_LOG_DEBUG ("start at channel " << nch);
438
      m_channelNumber = nch;
439
      return;
440
    }
441
442
  NS_ASSERT (!IsStateSwitching ());
443
  switch (m_state->GetState ())
444
    {
445
    case YansWifiPhy::RX:
446
      NS_LOG_DEBUG ("drop packet because of channel switching while reception");
447
      m_endPlcpRxEvent.Cancel ();
448
      m_endRxEvent.Cancel ();
449
      goto switchChannel;
450
      break;
451
    case YansWifiPhy::TX:
452
      NS_LOG_DEBUG ("channel switching postponed until end of current transmission");
453
      Simulator::Schedule (GetDelayUntilIdle (), &YansWifiPhy::SetChannelNumber, this, nch);
454
      break;
455
    case YansWifiPhy::CCA_BUSY:
456
    case YansWifiPhy::IDLE:
457
      goto switchChannel;
458
      break;
459
    case YansWifiPhy::SLEEP:
460
      NS_LOG_DEBUG ("channel switching ignored in sleep mode");
461
      break;
462
    default:
463
      NS_ASSERT (false);
464
      break;
465
    }
466
467
  return;
468
469
switchChannel:
470
471
  NS_LOG_DEBUG ("switching channel " << m_channelNumber << " -> " << nch);
472
  m_state->SwitchToChannelSwitching (m_channelSwitchDelay);
473
  m_interference.EraseEvents ();
474
  /*
475
   * Needed here to be able to correctly sensed the medium for the first
476
   * time after the switching. The actual switching is not performed until
477
   * after m_channelSwitchDelay. Packets received during the switching
478
   * state are added to the event list and are employed later to figure
479
   * out the state of the medium after the switching.
480
   */
481
  m_channelNumber = nch;
482
}
483
484
uint16_t
485
YansWifiPhy::GetChannelNumber (void) const
486
{
487
  return m_channelNumber;
488
}
489
490
Time
514
Time
491
YansWifiPhy::GetChannelSwitchDelay (void) const
515
YansWifiPhy::GetChannelSwitchDelay (void) const
492
{
516
{
493
  return m_channelSwitchDelay;
517
  return m_channelSwitchDelay;
494
}
518
}
495
519
496
double
497
YansWifiPhy::GetChannelFrequencyMhz () const
498
{
499
  return m_channelStartingFrequency + 5 * GetChannelNumber ();
500
}
501
502
void
520
void
503
YansWifiPhy::SetSleepMode (void)
521
YansWifiPhy::SetSleepMode (void)
504
{
522
{
 Lines 820-826    Link Here 
820
  struct mpduInfo aMpdu;
838
  struct mpduInfo aMpdu;
821
  aMpdu.type = mpdutype;
839
  aMpdu.type = mpdutype;
822
  aMpdu.mpduRefNumber = m_txMpduReferenceNumber;
840
  aMpdu.mpduRefNumber = m_txMpduReferenceNumber;
823
  NotifyMonitorSniffTx (packet, (uint16_t)GetChannelFrequencyMhz (), GetChannelNumber (), dataRate500KbpsUnits, preamble, txVector, aMpdu);
841
  NotifyMonitorSniffTx (packet, (uint16_t)GetFrequency (), GetChannelNumber (), dataRate500KbpsUnits, preamble, txVector, aMpdu);
824
  m_state->SwitchToTx (txDuration, packet, GetPowerDbm (txVector.GetTxPowerLevel ()), txVector, preamble);
842
  m_state->SwitchToTx (txDuration, packet, GetPowerDbm (txVector.GetTxPowerLevel ()), txVector, preamble);
825
  m_channel->Send (this, packet, GetPowerDbm (txVector.GetTxPowerLevel ()) + m_txGainDb, txVector, preamble, mpdutype, txDuration);
843
  m_channel->Send (this, packet, GetPowerDbm (txVector.GetTxPowerLevel ()) + m_txGainDb, txVector, preamble, mpdutype, txDuration);
826
}
844
}
 Lines 872-879    Link Here 
872
YansWifiPhy::Configure80211a (void)
890
YansWifiPhy::Configure80211a (void)
873
{
891
{
874
  NS_LOG_FUNCTION (this);
892
  NS_LOG_FUNCTION (this);
875
  m_channelStartingFrequency = 5e3; //5.000 GHz
876
  SetChannelWidth (20); //20 MHz
877
893
878
  m_deviceRateSet.push_back (WifiPhy::GetOfdmRate6Mbps ());
894
  m_deviceRateSet.push_back (WifiPhy::GetOfdmRate6Mbps ());
879
  m_deviceRateSet.push_back (WifiPhy::GetOfdmRate9Mbps ());
895
  m_deviceRateSet.push_back (WifiPhy::GetOfdmRate9Mbps ());
 Lines 889-896    Link Here 
889
YansWifiPhy::Configure80211b (void)
905
YansWifiPhy::Configure80211b (void)
890
{
906
{
891
  NS_LOG_FUNCTION (this);
907
  NS_LOG_FUNCTION (this);
892
  m_channelStartingFrequency = 2407; //2.407 GHz
893
  SetChannelWidth (22); //22 MHz
894
908
895
  m_deviceRateSet.push_back (WifiPhy::GetDsssRate1Mbps ());
909
  m_deviceRateSet.push_back (WifiPhy::GetDsssRate1Mbps ());
896
  m_deviceRateSet.push_back (WifiPhy::GetDsssRate2Mbps ());
910
  m_deviceRateSet.push_back (WifiPhy::GetDsssRate2Mbps ());
 Lines 903-909    Link Here 
903
{
917
{
904
  NS_LOG_FUNCTION (this);
918
  NS_LOG_FUNCTION (this);
905
  Configure80211b ();
919
  Configure80211b ();
906
  SetChannelWidth (20); //20 MHz
907
920
908
  m_deviceRateSet.push_back (WifiPhy::GetErpOfdmRate6Mbps ());
921
  m_deviceRateSet.push_back (WifiPhy::GetErpOfdmRate6Mbps ());
909
  m_deviceRateSet.push_back (WifiPhy::GetErpOfdmRate9Mbps ());
922
  m_deviceRateSet.push_back (WifiPhy::GetErpOfdmRate9Mbps ());
 Lines 919-926    Link Here 
919
YansWifiPhy::Configure80211_10Mhz (void)
932
YansWifiPhy::Configure80211_10Mhz (void)
920
{
933
{
921
  NS_LOG_FUNCTION (this);
934
  NS_LOG_FUNCTION (this);
922
  m_channelStartingFrequency = 5e3; //5.000 GHz, suppose 802.11a
923
  SetChannelWidth (10); //10 MHz
924
935
925
  m_deviceRateSet.push_back (WifiPhy::GetOfdmRate3MbpsBW10MHz ());
936
  m_deviceRateSet.push_back (WifiPhy::GetOfdmRate3MbpsBW10MHz ());
926
  m_deviceRateSet.push_back (WifiPhy::GetOfdmRate4_5MbpsBW10MHz ());
937
  m_deviceRateSet.push_back (WifiPhy::GetOfdmRate4_5MbpsBW10MHz ());
 Lines 936-943    Link Here 
936
YansWifiPhy::Configure80211_5Mhz (void)
947
YansWifiPhy::Configure80211_5Mhz (void)
937
{
948
{
938
  NS_LOG_FUNCTION (this);
949
  NS_LOG_FUNCTION (this);
939
  m_channelStartingFrequency = 5e3; //5.000 GHz, suppose 802.11a
940
  SetChannelWidth (5); //5 MHz
941
950
942
  m_deviceRateSet.push_back (WifiPhy::GetOfdmRate1_5MbpsBW5MHz ());
951
  m_deviceRateSet.push_back (WifiPhy::GetOfdmRate1_5MbpsBW5MHz ());
943
  m_deviceRateSet.push_back (WifiPhy::GetOfdmRate2_25MbpsBW5MHz ());
952
  m_deviceRateSet.push_back (WifiPhy::GetOfdmRate2_25MbpsBW5MHz ());
 Lines 953-960    Link Here 
953
YansWifiPhy::ConfigureHolland (void)
962
YansWifiPhy::ConfigureHolland (void)
954
{
963
{
955
  NS_LOG_FUNCTION (this);
964
  NS_LOG_FUNCTION (this);
956
  m_channelStartingFrequency = 5e3; //5.000 GHz
957
  SetChannelWidth (20); //20 MHz
958
965
959
  m_deviceRateSet.push_back (WifiPhy::GetOfdmRate6Mbps ());
966
  m_deviceRateSet.push_back (WifiPhy::GetOfdmRate6Mbps ());
960
  m_deviceRateSet.push_back (WifiPhy::GetOfdmRate12Mbps ());
967
  m_deviceRateSet.push_back (WifiPhy::GetOfdmRate12Mbps ());
 Lines 1036-1051    Link Here 
1036
YansWifiPhy::Configure80211n (void)
1043
YansWifiPhy::Configure80211n (void)
1037
{
1044
{
1038
  NS_LOG_FUNCTION (this);
1045
  NS_LOG_FUNCTION (this);
1039
  if (m_channelStartingFrequency >= 2400 && m_channelStartingFrequency <= 2500) //at 2.4 GHz
1046
  if (GetFrequency () >= 2400 && GetFrequency () <= 2500) //at 2.4 GHz
1040
    {
1047
    {
1041
      Configure80211b ();
1048
      Configure80211b ();
1042
      Configure80211g ();
1049
      Configure80211g ();
1043
    }
1050
    }
1044
  if (m_channelStartingFrequency >= 5000 && m_channelStartingFrequency <= 6000) //at 5 GHz
1051
  if (GetFrequency () >= 5000 && GetFrequency () <= 6000) //at 5 GHz
1045
    {
1052
    {
1046
      Configure80211a ();
1053
      Configure80211a ();
1047
    }
1054
    }
1048
  SetChannelWidth (20); //20 MHz
1049
  m_bssMembershipSelectorSet.push_back (HT_PHY);
1055
  m_bssMembershipSelectorSet.push_back (HT_PHY);
1050
  ConfigureHtDeviceMcsSet ();
1056
  ConfigureHtDeviceMcsSet ();
1051
}
1057
}
 Lines 1054-1062    Link Here 
1054
YansWifiPhy::Configure80211ac (void)
1060
YansWifiPhy::Configure80211ac (void)
1055
{
1061
{
1056
  NS_LOG_FUNCTION (this);
1062
  NS_LOG_FUNCTION (this);
1057
  m_channelStartingFrequency = 5e3; //5.000 GHz
1058
  Configure80211n ();
1063
  Configure80211n ();
1059
  SetChannelWidth (80); //80 MHz
1060
1064
1061
  m_deviceMcsSet.push_back (WifiPhy::GetVhtMcs0 ());
1065
  m_deviceMcsSet.push_back (WifiPhy::GetVhtMcs0 ());
1062
  m_deviceMcsSet.push_back (WifiPhy::GetVhtMcs1 ());
1066
  m_deviceMcsSet.push_back (WifiPhy::GetVhtMcs1 ());
 Lines 1202-1208    Link Here 
1202
          struct mpduInfo aMpdu;
1206
          struct mpduInfo aMpdu;
1203
          aMpdu.type = mpdutype;
1207
          aMpdu.type = mpdutype;
1204
          aMpdu.mpduRefNumber = m_rxMpduReferenceNumber;
1208
          aMpdu.mpduRefNumber = m_rxMpduReferenceNumber;
1205
          NotifyMonitorSniffRx (packet, (uint16_t)GetChannelFrequencyMhz (), GetChannelNumber (), dataRate500KbpsUnits, event->GetPreambleType (), event->GetTxVector (), aMpdu, signalNoise);
1209
          NotifyMonitorSniffRx (packet, (uint16_t)GetFrequency (), GetChannelNumber (), dataRate500KbpsUnits, event->GetPreambleType (), event->GetTxVector (), aMpdu, signalNoise);
1206
          m_state->SwitchFromRxEndOk (packet, snrPer.snr, event->GetTxVector (), event->GetPreambleType ());
1210
          m_state->SwitchFromRxEndOk (packet, snrPer.snr, event->GetTxVector (), event->GetPreambleType ());
1207
        }
1211
        }
1208
      else
1212
      else
 Lines 1232-1243    Link Here 
1232
}
1236
}
1233
1237
1234
void
1238
void
1235
YansWifiPhy::SetFrequency (uint32_t freq)
1236
{
1237
  m_channelStartingFrequency = freq;
1238
}
1239
1240
void
1241
YansWifiPhy::SetNumberOfTransmitAntennas (uint32_t tx)
1239
YansWifiPhy::SetNumberOfTransmitAntennas (uint32_t tx)
1242
{
1240
{
1243
  m_numberOfTransmitters = tx;
1241
  m_numberOfTransmitters = tx;
 Lines 1281-1292    Link Here 
1281
}
1279
}
1282
1280
1283
uint32_t
1281
uint32_t
1284
YansWifiPhy::GetFrequency (void) const
1285
{
1286
  return m_channelStartingFrequency;
1287
}
1288
1289
uint32_t
1290
YansWifiPhy::GetNumberOfTransmitAntennas (void) const
1282
YansWifiPhy::GetNumberOfTransmitAntennas (void) const
1291
{
1283
{
1292
  return m_numberOfTransmitters;
1284
  return m_numberOfTransmitters;
 Lines 1328-1347    Link Here 
1328
  m_shortPreamble = enable;
1320
  m_shortPreamble = enable;
1329
}
1321
}
1330
1322
1331
void
1332
YansWifiPhy::SetChannelWidth (uint32_t channelwidth)
1333
{
1334
  NS_ASSERT_MSG (channelwidth == 5 || channelwidth == 10 || channelwidth == 20 || channelwidth == 22 || channelwidth == 40 || channelwidth == 80 || channelwidth == 160, "wrong channel width value");
1335
  m_channelWidth = channelwidth;
1336
  AddSupportedChannelWidth (channelwidth);
1337
}
1338
1339
uint32_t
1340
YansWifiPhy::GetChannelWidth (void) const
1341
{
1342
  return m_channelWidth;
1343
}
1344
1345
uint8_t 
1323
uint8_t 
1346
YansWifiPhy::GetSupportedRxSpatialStreams (void) const
1324
YansWifiPhy::GetSupportedRxSpatialStreams (void) const
1347
{
1325
{
 Lines 1354-1379    Link Here 
1354
  return (static_cast<uint8_t> (GetNumberOfTransmitAntennas ()));
1332
  return (static_cast<uint8_t> (GetNumberOfTransmitAntennas ()));
1355
}
1333
}
1356
1334
1357
void
1358
YansWifiPhy::AddSupportedChannelWidth (uint32_t width)
1359
{
1360
  NS_LOG_FUNCTION (this << width);
1361
  for (std::vector<uint32_t>::size_type i = 0; i != m_supportedChannelWidthSet.size (); i++)
1362
    {
1363
      if (m_supportedChannelWidthSet[i] == width)
1364
        {
1365
          return;
1366
        }
1367
    }
1368
  m_supportedChannelWidthSet.push_back (width);
1369
}
1370
1371
std::vector<uint32_t> 
1372
YansWifiPhy::GetSupportedChannelWidthSet (void) const
1373
{
1374
  return m_supportedChannelWidthSet;
1375
}
1376
1377
uint32_t
1335
uint32_t
1378
YansWifiPhy::GetNBssMembershipSelectors (void) const
1336
YansWifiPhy::GetNBssMembershipSelectors (void) const
1379
{
1337
{
(-)a/src/wifi/model/yans-wifi-phy.h (-43 / +3 lines)
 Lines 78-104    Link Here 
78
   */
78
   */
79
  void SetChannel (Ptr<YansWifiChannel> channel);
79
  void SetChannel (Ptr<YansWifiChannel> channel);
80
  /**
80
  /**
81
   * Set the current channel number.
82
   *
83
   * \param id the channel number
84
   */
85
  void SetChannelNumber (uint16_t id);
86
  /**
87
   * Return the current channel number.
88
   *
89
   * \return the current channel number
90
   */
91
  uint16_t GetChannelNumber (void) const;
92
  /**
93
   * \return the required time for channel switch operation of this WifiPhy
81
   * \return the required time for channel switch operation of this WifiPhy
94
   */
82
   */
95
  Time GetChannelSwitchDelay (void) const;
83
  Time GetChannelSwitchDelay (void) const;
96
  /**
97
   * Return current center channel frequency in MHz.
98
   *
99
   * \return the current center channel frequency in MHz
100
   */
101
  double GetChannelFrequencyMhz () const;
102
84
103
  /**
85
  /**
104
   * Starting receiving the plcp of a packet (i.e. the first bit of the preamble has arrived).
86
   * Starting receiving the plcp of a packet (i.e. the first bit of the preamble has arrived).
 Lines 315-328    Link Here 
315
  int64_t AssignStreams (int64_t stream);
297
  int64_t AssignStreams (int64_t stream);
316
298
317
  /**
299
  /**
318
   * \param freq the operating frequency on this node (2.4 GHz or 5GHz).
319
   */
320
  virtual void SetFrequency (uint32_t freq);
321
  /**
322
   * \return the operating frequency on this node
323
   */
324
  virtual uint32_t GetFrequency (void) const;
325
  /**
326
   * \param tx the number of transmitters on this node.
300
   * \param tx the number of transmitters on this node.
327
   */
301
   */
328
  virtual void SetNumberOfTransmitAntennas (uint32_t tx);
302
  virtual void SetNumberOfTransmitAntennas (uint32_t tx);
 Lines 397-419    Link Here 
397
   * \returns if short PLCP preamble is supported or not
371
   * \returns if short PLCP preamble is supported or not
398
   */
372
   */
399
  virtual bool GetShortPlcpPreambleSupported (void) const;
373
  virtual bool GetShortPlcpPreambleSupported (void) const;
400
  /**
401
   * Return channel width.
402
   *
403
   * \return channel width
404
   */
405
  virtual uint32_t GetChannelWidth (void) const;
406
  /**
407
   * Set channel width.
408
   *
409
   * \param channel width
410
   */
411
  virtual void SetChannelWidth (uint32_t channelwidth);
412
374
413
  virtual uint8_t GetSupportedRxSpatialStreams (void) const;
375
  virtual uint8_t GetSupportedRxSpatialStreams (void) const;
414
  virtual uint8_t GetSupportedTxSpatialStreams (void) const;
376
  virtual uint8_t GetSupportedTxSpatialStreams (void) const;
415
  virtual void AddSupportedChannelWidth (uint32_t width);
416
  virtual std::vector<uint32_t> GetSupportedChannelWidthSet (void) const;
417
  virtual uint32_t GetNBssMembershipSelectors (void) const;
377
  virtual uint32_t GetNBssMembershipSelectors (void) const;
418
  virtual uint32_t GetBssMembershipSelector (uint32_t selector) const;
378
  virtual uint32_t GetBssMembershipSelector (uint32_t selector) const;
419
  virtual WifiModeList GetMembershipSelectorModes (uint32_t selector);
379
  virtual WifiModeList GetMembershipSelectorModes (uint32_t selector);
 Lines 428-433    Link Here 
428
  virtual void DoInitialize (void);
388
  virtual void DoInitialize (void);
429
  virtual void DoDispose (void);
389
  virtual void DoDispose (void);
430
390
391
  // Inherited
392
  virtual bool DoChannelSwitch (uint16_t id);
393
  virtual bool DoFrequencySwitch (uint32_t frequency);
431
  /**
394
  /**
432
   * Configure YansWifiPhy with appropriate channel frequency and
395
   * Configure YansWifiPhy with appropriate channel frequency and
433
   * supported rates for 802.11a standard.
396
   * supported rates for 802.11a standard.
 Lines 504-510    Link Here 
504
  uint32_t m_nTxPower;            //!< Number of available transmission power levels
467
  uint32_t m_nTxPower;            //!< Number of available transmission power levels
505
468
506
  Ptr<YansWifiChannel> m_channel;        //!< YansWifiChannel that this YansWifiPhy is connected to
469
  Ptr<YansWifiChannel> m_channel;        //!< YansWifiChannel that this YansWifiPhy is connected to
507
  uint16_t             m_channelNumber;  //!< Operating channel number
508
  Ptr<NetDevice>       m_device;         //!< Pointer to the device
470
  Ptr<NetDevice>       m_device;         //!< Pointer to the device
509
  Ptr<MobilityModel>   m_mobility;       //!< Pointer to the mobility model
471
  Ptr<MobilityModel>   m_mobility;       //!< Pointer to the mobility model
510
472
 Lines 514-521    Link Here 
514
  bool     m_stbc;                  //!< Flag if STBC is used
476
  bool     m_stbc;                  //!< Flag if STBC is used
515
  bool     m_greenfield;            //!< Flag if GreenField format is supported
477
  bool     m_greenfield;            //!< Flag if GreenField format is supported
516
  bool     m_guardInterval;         //!< Flag if short guard interval is used
478
  bool     m_guardInterval;         //!< Flag if short guard interval is used
517
  uint32_t m_channelWidth;          //!< Channel width
518
  std::vector<uint32_t> m_supportedChannelWidthSet; //!< Supported channel width
519
  bool     m_shortPreamble;         //!< Flag if short PLCP preamble is supported
479
  bool     m_shortPreamble;         //!< Flag if short PLCP preamble is supported
520
480
521
  /**
481
  /**
(-)a/src/wifi/test/wifi-test.cc (+317 lines)
 Lines 618-623    Link Here 
618
  NS_TEST_ASSERT_MSG_EQ (result, true, "packet reception unexpectedly stopped after adapting fragmentation threshold!");
618
  NS_TEST_ASSERT_MSG_EQ (result, true, "packet reception unexpectedly stopped after adapting fragmentation threshold!");
619
}
619
}
620
620
621
class SetChannelFrequencyTest: public TestCase
622
{
623
public:
624
  SetChannelFrequencyTest ();
625
626
  virtual void DoRun (void);
627
628
629
private:
630
631
  Ptr<YansWifiPhy> GetYansWifiPhyPtr (const NetDeviceContainer &nc) const;
632
633
};
634
635
SetChannelFrequencyTest::SetChannelFrequencyTest ()
636
  : TestCase ("Test case for setting WifiPhy channel and frequency")
637
{
638
}
639
640
Ptr<YansWifiPhy>
641
SetChannelFrequencyTest::GetYansWifiPhyPtr (const NetDeviceContainer &nc) const
642
{
643
  Ptr<WifiNetDevice> wnd = nc.Get (0)->GetObject<WifiNetDevice> ();
644
  Ptr<WifiPhy> wp = wnd->GetPhy ();
645
  return wp->GetObject<YansWifiPhy> ();
646
}
647
648
void
649
SetChannelFrequencyTest::DoRun ()
650
{
651
  NodeContainer wifiStaNode;
652
  wifiStaNode.Create (1);
653
  NodeContainer wifiApNode;
654
  wifiApNode.Create (1);
655
656
  YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
657
  YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
658
  phy.SetChannel (channel.Create ());
659
660
  // Configure and declare other generic components of this example
661
  Ssid ssid;
662
  ssid = Ssid ("wifi-phy-configuration");
663
  WifiMacHelper macSta;
664
  macSta.SetType ("ns3::StaWifiMac",
665
                  "Ssid", SsidValue (ssid),
666
                  "ActiveProbing", BooleanValue (false));
667
  NetDeviceContainer staDevice;
668
  Ptr<YansWifiPhy> phySta;
669
670
  // Cases taken from src/wifi/examples/wifi-phy-configuration.cc example
671
  {
672
      // case 0
673
      // Default configuration, without WifiHelper::SetStandard or WifiHelper
674
      phySta = CreateObject<YansWifiPhy> ();
675
      // The default results in an invalid configuration of channel 0,
676
      // width 20, and frequency 0 MHz
677
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 0, "default configuration");
678
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "default configuration");
679
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 0, "default configuration");
680
  }
681
  {
682
      // case 1
683
      WifiHelper wifi;
684
      // By default, WifiHelper will use WIFI_PHY_STANDARD_80211a
685
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
686
      phySta = GetYansWifiPhyPtr (staDevice);
687
      // We expect channel 36, width 20, frequency 5180
688
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 36, "default configuration");
689
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "default configuration");
690
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5180, "default configuration");
691
  }
692
  {
693
      // case 2
694
      WifiHelper wifi;
695
      wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
696
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
697
      phySta = GetYansWifiPhyPtr (staDevice);
698
      // We expect channel 1, width 22, frequency 2412
699
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 1, "802.11b configuration");
700
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 22, "802.11b configuration");
701
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 2412, "802.11b configuration");
702
  }
703
  {
704
      // case 3
705
      WifiHelper wifi;
706
      wifi.SetStandard (WIFI_PHY_STANDARD_80211g);
707
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
708
      phySta = GetYansWifiPhyPtr (staDevice);
709
      // We expect channel 1, width 20, frequency 2412
710
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 1, "802.11g configuration");
711
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11g configuration");
712
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 2412, "802.11g configuration");
713
  }
714
  {
715
      // case 4
716
      WifiHelper wifi;
717
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
718
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
719
      phySta = GetYansWifiPhyPtr (staDevice);
720
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 36, "802.11n-5GHz configuration");
721
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11n-5GHz configuration");
722
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5180, "802.11n-5GHz configuration");
723
  }
724
  {
725
      // case 5
726
      WifiHelper wifi;
727
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_2_4GHZ);
728
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
729
      phySta = GetYansWifiPhyPtr (staDevice);
730
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 1, "802.11n-2.4GHz configuration");
731
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11n-2.4GHz configuration");
732
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 2412, "802.11n-2.4GHz configuration");
733
  }
734
  {
735
      // case 6
736
      WifiHelper wifi;
737
      wifi.SetStandard (WIFI_PHY_STANDARD_80211ac);
738
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
739
      phySta = GetYansWifiPhyPtr (staDevice);
740
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 42, "802.11ac configuration");
741
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 80, "802.11ac configuration");
742
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5210, "802.11ac configuration");
743
  }
744
  {
745
      // case 7
746
      WifiHelper wifi;
747
      wifi.SetStandard (WIFI_PHY_STANDARD_80211_10MHZ);
748
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
749
      phySta = GetYansWifiPhyPtr (staDevice);
750
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 172, "802.11 10Mhz configuration");
751
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 10, "802.11 10Mhz configuration");
752
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5860, "802.11 10Mhz configuration");
753
  }
754
  {
755
      // case 8
756
      WifiHelper wifi;
757
      wifi.SetStandard (WIFI_PHY_STANDARD_80211_5MHZ);
758
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
759
      phySta = GetYansWifiPhyPtr (staDevice);
760
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 0, "802.11 5Mhz configuration");
761
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 5, "802.11 5Mhz configuration");
762
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5860, "802.11 5Mhz configuration");
763
  }
764
  {
765
      // case 9
766
      WifiHelper wifi;
767
      wifi.SetStandard (WIFI_PHY_STANDARD_holland);
768
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
769
      phySta = GetYansWifiPhyPtr (staDevice);
770
      // We expect channel 36, width 20, frequency 5180
771
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 36, "802.11 5Mhz configuration");
772
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5Mhz configuration");
773
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5180, "802.11 5Mhz configuration");
774
  }
775
  {
776
      // case 10
777
      WifiHelper wifi;
778
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
779
      phy.Set ("ChannelNumber", UintegerValue(44));
780
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
781
      phySta = GetYansWifiPhyPtr (staDevice);
782
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 44, "802.11 5GHz configuration");
783
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
784
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5220, "802.11 5GHz configuration");
785
  }
786
  {
787
      // case 11
788
      WifiHelper wifi;
789
      phy.Set ("ChannelNumber", UintegerValue(44));
790
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
791
      phySta = GetYansWifiPhyPtr (staDevice);
792
      // Post-install reconfiguration to channel number 40
793
      Config::Set ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/ChannelNumber", UintegerValue(40));
794
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 40, "802.11 5GHz configuration");
795
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
796
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5200, "802.11 5GHz configuration");
797
  }
798
  {
799
      // case 12
800
      WifiHelper wifi;
801
      phy.Set ("ChannelNumber", UintegerValue (44));
802
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
803
      phySta = GetYansWifiPhyPtr (staDevice);
804
      // Post-install reconfiguration to channel width 40 MHz
805
      Config::Set ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/ChannelWidth", UintegerValue(40));
806
      // Although channel 44 is configured originally for 20 MHz, we
807
      // allow it to be used for 40 MHz here
808
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 44, "802.11 5GHz configuration");
809
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 40, "802.11 5GHz configuration");
810
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5220, "802.11 5GHz configuration");
811
  }
812
      // modify cases 13 and 14 to avoid Config::SetDefault ()
813
  {
814
      // case 13
815
      WifiHelper wifi;
816
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
817
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
818
      phySta = GetYansWifiPhyPtr (staDevice);
819
      phySta->SetAttribute ("ChannelNumber", UintegerValue (44));
820
      // Post-install reconfiguration to channel width 40 MHz
821
      Config::Set ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/ChannelWidth", UintegerValue(40));
822
      // Although channel 44 is configured originally for 20 MHz, we
823
      // allow it to be used for 40 MHz here
824
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 44, "802.11 5GHz configuration");
825
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 40, "802.11 5GHz configuration");
826
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5220, "802.11 5GHz configuration");
827
  }
828
  {
829
      // case 14
830
      WifiHelper wifi;
831
      // Test that setting Frequency to a non-standard value will zero the
832
      // channel number
833
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
834
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
835
      phySta = GetYansWifiPhyPtr (staDevice);
836
      phySta->SetAttribute ("Frequency", UintegerValue (5281));
837
      // We expect channel number to be zero since frequency doesn't match
838
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 0, "802.11 5GHz configuration");
839
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
840
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5281, "802.11 5GHz configuration");
841
  }
842
  {
843
      // case 15:
844
      WifiHelper wifi;
845
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
846
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
847
      phySta = GetYansWifiPhyPtr (staDevice);
848
      // Test that setting Frequency to a standard value will set the
849
      // channel number correctly
850
      phySta->SetAttribute ("Frequency", UintegerValue (5500));
851
      // We expect channel number to be 100 due to frequency 5500
852
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 100, "802.11 5GHz configuration");
853
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
854
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5500, "802.11 5GHz configuration");
855
  }
856
  {
857
      // case 16:
858
      WifiHelper wifi;
859
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
860
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
861
      phySta = GetYansWifiPhyPtr (staDevice);
862
      // This case will error exit due to invalid channel number unless
863
      // we provide the DefineChannelNumber() below
864
      phySta->DefineChannelNumber (99, WIFI_PHY_STANDARD_80211n_5GHZ, 5185, 40);
865
      phySta->SetAttribute ("ChannelNumber", UintegerValue (99));
866
  }
867
  {
868
      // case 17:
869
      WifiHelper wifi;
870
      // Test how channel number behaves when frequency is non-standard
871
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
872
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
873
      phySta = GetYansWifiPhyPtr (staDevice);
874
      phySta->SetAttribute ("Frequency", UintegerValue (5181));
875
      // We expect channel number to be 0 due to unknown center frequency 5181
876
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 0, "802.11 5GHz configuration");
877
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
878
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5181, "802.11 5GHz configuration");
879
      phySta->SetAttribute ("Frequency", UintegerValue (5180));
880
      // We expect channel number to be 36 due to known center frequency 5180
881
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 36, "802.11 5GHz configuration");
882
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
883
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5180, "802.11 5GHz configuration");
884
      phySta->SetAttribute ("Frequency", UintegerValue (5179));
885
      // We expect channel number to be 0 due to unknown center frequency 5179
886
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 0, "802.11 5GHz configuration");
887
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
888
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5179, "802.11 5GHz configuration");
889
      phySta->SetAttribute ("ChannelNumber", UintegerValue (36));
890
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 36, "802.11 5GHz configuration");
891
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
892
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5180, "802.11 5GHz configuration");
893
  }
894
  {
895
      // case 18:
896
      WifiHelper wifi;
897
      // Set both channel and frequency to consistent values
898
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
899
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
900
      phySta = GetYansWifiPhyPtr (staDevice);
901
      phySta->SetAttribute ("Frequency", UintegerValue (5200));
902
      phySta->SetAttribute ("ChannelNumber", UintegerValue (40));
903
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 40, "802.11 5GHz configuration");
904
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
905
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5200, "802.11 5GHz configuration");
906
      // Set both channel and frequency to inconsistent values
907
      phySta->SetAttribute ("Frequency", UintegerValue (5200));
908
      phySta->SetAttribute ("ChannelNumber", UintegerValue (36));
909
      // We expect channel number to be 36
910
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 36, "802.11 5GHz configuration");
911
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
912
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5180, "802.11 5GHz configuration");
913
      phySta->SetAttribute ("ChannelNumber", UintegerValue (36));
914
      phySta->SetAttribute ("Frequency", UintegerValue (5200));
915
      // We expect channel number to be 40
916
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 40, "802.11 5GHz configuration");
917
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
918
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5200, "802.11 5GHz configuration");
919
      phySta->SetAttribute ("Frequency", UintegerValue (5179));
920
      phySta->SetAttribute ("ChannelNumber", UintegerValue (36));
921
      // We expect channel number to be 36
922
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 36, "802.11 5GHz configuration");
923
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
924
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5180, "802.11 5GHz configuration");
925
      phySta->SetAttribute ("ChannelNumber", UintegerValue (36));
926
      phySta->SetAttribute ("Frequency", UintegerValue (5179));
927
      // We expect channel number to be 0
928
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 0, "802.11 5GHz configuration");
929
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
930
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5179, "802.11 5GHz configuration");
931
  }
932
933
Simulator::Destroy ();
934
935
}
936
621
//-----------------------------------------------------------------------------
937
//-----------------------------------------------------------------------------
622
class WifiTestSuite : public TestSuite
938
class WifiTestSuite : public TestSuite
623
{
939
{
 Lines 633-638    Link Here 
633
  AddTestCase (new InterferenceHelperSequenceTest, TestCase::QUICK); //Bug 991
949
  AddTestCase (new InterferenceHelperSequenceTest, TestCase::QUICK); //Bug 991
634
  AddTestCase (new Bug555TestCase, TestCase::QUICK); //Bug 555
950
  AddTestCase (new Bug555TestCase, TestCase::QUICK); //Bug 555
635
  AddTestCase (new Bug730TestCase, TestCase::QUICK); //Bug 730
951
  AddTestCase (new Bug730TestCase, TestCase::QUICK); //Bug 730
952
  AddTestCase (new SetChannelFrequencyTest, TestCase::QUICK);
636
}
953
}
637
954
638
static WifiTestSuite g_wifiTestSuite;
955
static WifiTestSuite g_wifiTestSuite;

Return to bug 2412