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

(-)a/CHANGES.html (+2 lines)
 Lines 66-71    Link Here 
66
    As a consequence, SocketAddressTag has been completely removed from ns-3.
66
    As a consequence, SocketAddressTag has been completely removed from ns-3.
67
    Users can use RecvFrom (for UDP), GetPeerName (for TCP), or similar. 
67
    Users can use RecvFrom (for UDP), GetPeerName (for TCP), or similar. 
68
</li>
68
</li>
69
<li>The attributes YansWifiPhy::Frequency, YansWifiPhy::ChannelNumber, and YansWifiPhy::ChannelWidth, and the related accessor methods, were moved to base class WifiPhy.  YansWifiPhy::GetChannelFrequencyMhz() was deleted.  A new method WifiPhy::DefineChannelNumber () was added to allow users to define relationships between channel number, standard, frequency, and channel width.
69
</ul>
70
</ul>
70
<h2>Changes to build system:</h2>
71
<h2>Changes to build system:</h2>
71
<ul>
72
<ul>
 Lines 73-78    Link Here 
73
<h2>Changed behavior:</h2>
74
<h2>Changed behavior:</h2>
74
This section is for behavioral changes to the models that were not due to a bug fix.
75
This section is for behavioral changes to the models that were not due to a bug fix.
75
<ul>
76
<ul>
77
  <li> (wifi) The relationship between channel number, frequency, channel width, and Wi-Fi standard has been revised (see bug 2412).  Previously, ChannelNumber and Frequency were attributes of class YansWifiPhy, and the frequency was defined as the start of the band.  Now, Frequency has been redefined to be the center frequency of the channel, and the underlying device relies on the pair of frequency and channel width to control behavior; the channel number and Wi-Fi standard are used as attributes to configure frequency and channel width.  The wifi module documentation discusses this change and the new behavior.
76
</ul>
78
</ul>
77
79
78
<hr>
80
<hr>
(-)a/RELEASE_NOTES (+1 lines)
 Lines 65-70    Link Here 
65
- Bug 2402 - IPv4 Interface forwarding state is not honored
65
- Bug 2402 - IPv4 Interface forwarding state is not honored
66
- Bug 2406 - Poor 802.11g performance in ad-hoc mode
66
- Bug 2406 - Poor 802.11g performance in ad-hoc mode
67
- Bug 2408 - Simulation fails when 802.11n/ac is running with HT Minstrel and pcap enabled
67
- Bug 2408 - Simulation fails when 802.11n/ac is running with HT Minstrel and pcap enabled
68
- Bug 2412 - align WifiPhy frequency and channel number
68
- Bug 2414 - UdpSocket doesn't call NotifyConnectionFailed
69
- Bug 2414 - UdpSocket doesn't call NotifyConnectionFailed
69
- Bug 2419 - BsmApplication should use RecvFrom and not SocketAddressTag
70
- Bug 2419 - BsmApplication should use RecvFrom and not SocketAddressTag
70
- Bug 2420 - Remove code duplication between Wifi and Wave modules
71
- Bug 2420 - Remove code duplication between Wifi and Wave modules
(-)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
(-)086e86199836 (+392 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
  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
75
76
  // Configure and declare other generic components of this example
77
  Ssid ssid;
78
  ssid = Ssid ("wifi-phy-configuration");
79
  WifiMacHelper macSta;
80
  macSta.SetType ("ns3::StaWifiMac",
81
                  "Ssid", SsidValue (ssid),
82
                  "ActiveProbing", BooleanValue (false));
83
  WifiMacHelper macAp;
84
  macAp.SetType ("ns3::ApWifiMac",
85
                 "Ssid", SsidValue (ssid),
86
                 "BeaconInterval", TimeValue (MicroSeconds (102400)),
87
                 "BeaconGeneration", BooleanValue (true));
88
  NetDeviceContainer staDevice;
89
  NetDeviceContainer apDevice;
90
  Ptr<YansWifiPhy> phySta;
91
  Config::SetDefault ("ns3::ConfigStore::Filename", StringValue ("output-attributes-" + std::to_string (testCase) + ".txt"));
92
  Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue ("RawText"));
93
  Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Save"));
94
95
  switch (testCase)
96
  {
97
    case 0:
98
      // Default configuration, without WifiHelper::SetStandard or WifiHelper
99
      phySta = CreateObject<YansWifiPhy> ();
100
      // The default results in an invalid configuration of channel 0,
101
      // width 20, and frequency 0 MHz
102
      NS_ASSERT (phySta->GetChannelNumber () == 0);
103
      NS_ASSERT (phySta->GetChannelWidth () == 20);
104
      NS_ASSERT (phySta->GetFrequency () == 0);
105
      PrintAttributesIfEnabled (printAttributes);
106
      break;
107
108
    // The following cases test the setting of WifiPhyStandard alone;
109
    // i.e. without further channel number/width/frequency configuration
110
111
    case 1:
112
      // By default, WifiHelper will use WIFI_PHY_STANDARD_80211a
113
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
114
      apDevice = wifi.Install (phy, macAp, wifiApNode.Get(0));
115
      phySta = GetYansWifiPhyPtr (staDevice);
116
      // We expect channel 36, width 20, frequency 5180
117
      NS_ASSERT (phySta->GetChannelNumber () == 36);
118
      NS_ASSERT (phySta->GetChannelWidth () == 20);
119
      NS_ASSERT (phySta->GetFrequency () == 5180);
120
      PrintAttributesIfEnabled (printAttributes);
121
      break;
122
    case 2:
123
      wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
124
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
125
      apDevice = wifi.Install (phy, macAp, wifiApNode.Get(0));
126
      phySta = GetYansWifiPhyPtr (staDevice);
127
      // We expect channel 1, width 22, frequency 2412
128
      NS_ASSERT (phySta->GetChannelNumber () == 1);
129
      NS_ASSERT (phySta->GetChannelWidth () == 22);
130
      NS_ASSERT (phySta->GetFrequency () == 2412);
131
      PrintAttributesIfEnabled (printAttributes);
132
      break;
133
    case 3:
134
      wifi.SetStandard (WIFI_PHY_STANDARD_80211g);
135
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
136
      apDevice = wifi.Install (phy, macAp, wifiApNode.Get(0));
137
      phySta = GetYansWifiPhyPtr (staDevice);
138
      // We expect channel 1, width 20, frequency 2412
139
      NS_ASSERT (phySta->GetChannelNumber () == 1);
140
      NS_ASSERT (phySta->GetChannelWidth () == 20);
141
      NS_ASSERT (phySta->GetFrequency () == 2412);
142
      PrintAttributesIfEnabled (printAttributes);
143
      break;
144
    case 4:
145
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
146
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
147
      apDevice = wifi.Install (phy, macAp, wifiApNode.Get(0));
148
      phySta = GetYansWifiPhyPtr (staDevice);
149
      // We expect channel 36, width 20, frequency 5180
150
      NS_ASSERT (phySta->GetChannelNumber () == 36);
151
      NS_ASSERT (phySta->GetChannelWidth () == 20);
152
      NS_ASSERT (phySta->GetFrequency () == 5180);
153
      PrintAttributesIfEnabled (printAttributes);
154
      break;
155
    case 5:
156
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_2_4GHZ);
157
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
158
      apDevice = wifi.Install (phy, macAp, wifiApNode.Get(0));
159
      phySta = GetYansWifiPhyPtr (staDevice);
160
      // We expect channel 1, width 20, frequency 2412
161
      NS_ASSERT (phySta->GetChannelNumber () == 1);
162
      NS_ASSERT (phySta->GetChannelWidth () == 20);
163
      NS_ASSERT (phySta->GetFrequency () == 2412);
164
      PrintAttributesIfEnabled (printAttributes);
165
      break;
166
    case 6:
167
      wifi.SetStandard (WIFI_PHY_STANDARD_80211ac);
168
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
169
      apDevice = wifi.Install (phy, macAp, wifiApNode.Get(0));
170
      phySta = GetYansWifiPhyPtr (staDevice);
171
      // We expect channel 42, width 80, frequency 5210
172
      NS_ASSERT (phySta->GetChannelNumber () == 42);
173
      NS_ASSERT (phySta->GetChannelWidth () == 80);
174
      NS_ASSERT (phySta->GetFrequency () == 5210);
175
      PrintAttributesIfEnabled (printAttributes);
176
      break;
177
    case 7:
178
      wifi.SetStandard (WIFI_PHY_STANDARD_80211_10MHZ);
179
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
180
      apDevice = wifi.Install (phy, macAp, wifiApNode.Get(0));
181
      phySta = GetYansWifiPhyPtr (staDevice);
182
      // We expect channel 172, width 10, frequency 5860
183
      NS_ASSERT (phySta->GetChannelNumber () == 172);
184
      NS_ASSERT (phySta->GetChannelWidth () == 10);
185
      NS_ASSERT (phySta->GetFrequency () == 5860);
186
      PrintAttributesIfEnabled (printAttributes);
187
      break;
188
    case 8:
189
      wifi.SetStandard (WIFI_PHY_STANDARD_80211_5MHZ);
190
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
191
      apDevice = wifi.Install (phy, macAp, wifiApNode.Get(0));
192
      phySta = GetYansWifiPhyPtr (staDevice);
193
      // We expect channel 0, width 5, frequency 5860
194
      // Channel 0 because 5MHz channels are not officially defined
195
      NS_ASSERT (phySta->GetChannelNumber () == 0);
196
      NS_ASSERT (phySta->GetChannelWidth () == 5);
197
      NS_ASSERT (phySta->GetFrequency () == 5860);
198
      PrintAttributesIfEnabled (printAttributes);
199
      break;
200
    case 9:
201
      wifi.SetStandard (WIFI_PHY_STANDARD_holland);
202
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
203
      apDevice = wifi.Install (phy, macAp, wifiApNode.Get(0));
204
      phySta = GetYansWifiPhyPtr (staDevice);
205
      // We expect channel 36, width 20, frequency 5180
206
      NS_ASSERT (phySta->GetChannelNumber () == 36);
207
      NS_ASSERT (phySta->GetChannelWidth () == 20);
208
      NS_ASSERT (phySta->GetFrequency () == 5180);
209
      PrintAttributesIfEnabled (printAttributes);
210
      break;
211
    case 10:
212
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
213
      phy.Set ("ChannelNumber", UintegerValue(44));
214
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
215
      apDevice = wifi.Install (phy, macAp, wifiApNode.Get(0));
216
      phySta = GetYansWifiPhyPtr (staDevice);
217
      // We expect channel 44, width 20, frequency 5220
218
      NS_ASSERT (phySta->GetChannelNumber () == 44);
219
      NS_ASSERT (phySta->GetChannelWidth () == 20);
220
      NS_ASSERT (phySta->GetFrequency () == 5220);
221
      PrintAttributesIfEnabled (printAttributes);
222
      break;
223
224
    case 11:
225
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
226
      phy.Set ("ChannelNumber", UintegerValue(44));
227
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
228
      apDevice = wifi.Install (phy, macAp, wifiApNode.Get(0));
229
      phySta = GetYansWifiPhyPtr (staDevice);
230
      // Post-install reconfiguration to channel number 40
231
      Config::Set ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/ChannelNumber", UintegerValue(40));
232
      Config::Set ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/ChannelNumber", UintegerValue(40));
233
      // We expect channel 40, width 20, frequency 5200
234
      NS_ASSERT (phySta->GetChannelNumber () == 40);
235
      NS_ASSERT (phySta->GetChannelWidth () == 20);
236
      NS_ASSERT (phySta->GetFrequency () == 5200);
237
      PrintAttributesIfEnabled (printAttributes);
238
      break;
239
240
    case 12:
241
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
242
      phy.Set ("ChannelNumber", UintegerValue (44));
243
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
244
      apDevice = wifi.Install (phy, macAp, wifiApNode.Get(0));
245
      phySta = GetYansWifiPhyPtr (staDevice);
246
      // Post-install reconfiguration to channel width 40 MHz
247
      Config::Set ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/ChannelWidth", UintegerValue(40));
248
      Config::Set ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/ChannelWidth", UintegerValue(40));
249
      // Although channel 44 is configured originally for 20 MHz, we 
250
      // allow it to be used for 40 MHz here
251
      NS_ASSERT (phySta->GetChannelNumber () == 44);
252
      NS_ASSERT (phySta->GetChannelWidth () == 40);
253
      NS_ASSERT (phySta->GetFrequency () == 5220);
254
      PrintAttributesIfEnabled (printAttributes);
255
      break;
256
257
    case 13:
258
      Config::SetDefault ("ns3::WifiPhy::ChannelNumber", UintegerValue (44));
259
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
260
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
261
      apDevice = wifi.Install (phy, macAp, wifiApNode.Get(0));
262
      phySta = GetYansWifiPhyPtr (staDevice);
263
      // Post-install reconfiguration to channel width 40 MHz
264
      Config::Set ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/ChannelWidth", UintegerValue(40));
265
      Config::Set ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/ChannelWidth", UintegerValue(40));
266
      // Although channel 44 is configured originally for 20 MHz, we 
267
      // allow it to be used for 40 MHz here
268
      NS_ASSERT (phySta->GetChannelNumber () == 44);
269
      NS_ASSERT (phySta->GetChannelWidth () == 40);
270
      NS_ASSERT (phySta->GetFrequency () == 5220);
271
      PrintAttributesIfEnabled (printAttributes);
272
      break;
273
274
    case 14:
275
      // Test that setting Frequency to a non-standard value will zero the
276
      // channel number
277
      Config::SetDefault ("ns3::WifiPhy::Frequency", UintegerValue (5281));
278
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
279
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
280
      apDevice = wifi.Install (phy, macAp, wifiApNode.Get(0));
281
      phySta = GetYansWifiPhyPtr (staDevice);
282
      // We expect channel number to be zero since frequency doesn't match
283
      NS_ASSERT (phySta->GetChannelNumber () == 0);
284
      NS_ASSERT (phySta->GetChannelWidth () == 20);
285
      NS_ASSERT (phySta->GetFrequency () == 5281);
286
      PrintAttributesIfEnabled (printAttributes);
287
      break;
288
289
    case 15:
290
      // Test that setting Frequency to a standard value will set the
291
      // channel number correctly
292
      Config::SetDefault ("ns3::WifiPhy::Frequency", UintegerValue (5500));
293
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
294
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
295
      apDevice = wifi.Install (phy, macAp, wifiApNode.Get (0));
296
      phySta = GetYansWifiPhyPtr (staDevice);
297
      // We expect channel number to be 100 due to frequency 5500
298
      NS_ASSERT (phySta->GetChannelNumber () == 100);
299
      NS_ASSERT (phySta->GetChannelWidth () == 20);
300
      NS_ASSERT (phySta->GetFrequency () == 5500);
301
      PrintAttributesIfEnabled (printAttributes);
302
      break;
303
304
    case 16:
305
      // Define a new channel number
306
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
307
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
308
      apDevice = wifi.Install (phy, macAp, wifiApNode.Get (0));
309
      phySta = GetYansWifiPhyPtr (staDevice);
310
      // This case will error exit due to invalid channel number unless
311
      // we provide the DefineChannelNumber() below
312
      phySta->DefineChannelNumber (99, WIFI_PHY_STANDARD_80211n_5GHZ, 5185, 40);
313
      phySta->SetAttribute ("ChannelNumber", UintegerValue (99));
314
      PrintAttributesIfEnabled (printAttributes);
315
      break;
316
317
    case 17:
318
      // Test how channel number behaves when frequency is non-standard
319
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
320
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
321
      apDevice = wifi.Install (phy, macAp, wifiApNode.Get(0));
322
      phySta = GetYansWifiPhyPtr (staDevice);
323
      phySta->SetAttribute ("Frequency", UintegerValue (5181));
324
      // We expect channel number to be 0 due to unknown center frequency 5181
325
      NS_ASSERT (phySta->GetChannelNumber () == 0);
326
      NS_ASSERT (phySta->GetChannelWidth () == 20);
327
      NS_ASSERT (phySta->GetFrequency () == 5181);
328
      phySta->SetAttribute ("Frequency", UintegerValue (5180));
329
      // We expect channel number to be 36 due to known center frequency 5180
330
      NS_ASSERT (phySta->GetChannelNumber () == 36);
331
      NS_ASSERT (phySta->GetChannelWidth () == 20);
332
      NS_ASSERT (phySta->GetFrequency () == 5180);
333
      phySta->SetAttribute ("Frequency", UintegerValue (5179));
334
      // We expect channel number to be 0 due to unknown center frequency 5179
335
      NS_ASSERT (phySta->GetChannelNumber () == 0);
336
      NS_ASSERT (phySta->GetChannelWidth () == 20);
337
      NS_ASSERT (phySta->GetFrequency () == 5179);
338
      phySta->SetAttribute ("ChannelNumber", UintegerValue (36));
339
      NS_ASSERT (phySta->GetChannelNumber () == 36);
340
      NS_ASSERT (phySta->GetChannelWidth () == 20);
341
      NS_ASSERT (phySta->GetFrequency () == 5180);
342
      PrintAttributesIfEnabled (printAttributes);
343
      break;
344
345
    case 18:
346
      // Set both channel and frequency to consistent values
347
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
348
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
349
      apDevice = wifi.Install (phy, macAp, wifiApNode.Get(0));
350
      phySta = GetYansWifiPhyPtr (staDevice);
351
      phySta->SetAttribute ("Frequency", UintegerValue (5200));
352
      phySta->SetAttribute ("ChannelNumber", UintegerValue (40));
353
      NS_ASSERT (phySta->GetChannelNumber () == 40);
354
      NS_ASSERT (phySta->GetChannelWidth () == 20);
355
      NS_ASSERT (phySta->GetFrequency () == 5200);
356
      // Set both channel and frequency to inconsistent values
357
      phySta->SetAttribute ("Frequency", UintegerValue (5200));
358
      phySta->SetAttribute ("ChannelNumber", UintegerValue (36));
359
      // We expect channel number to be 36 
360
      NS_ASSERT (phySta->GetChannelNumber () == 36);
361
      NS_ASSERT (phySta->GetChannelWidth () == 20);
362
      NS_ASSERT (phySta->GetFrequency () == 5180);
363
      phySta->SetAttribute ("ChannelNumber", UintegerValue (36));
364
      phySta->SetAttribute ("Frequency", UintegerValue (5200));
365
      // We expect channel number to be 40 
366
      NS_ASSERT (phySta->GetChannelNumber () == 40);
367
      NS_ASSERT (phySta->GetChannelWidth () == 20);
368
      NS_ASSERT (phySta->GetFrequency () == 5200);
369
      phySta->SetAttribute ("Frequency", UintegerValue (5179));
370
      phySta->SetAttribute ("ChannelNumber", UintegerValue (36));
371
      // We expect channel number to be 36 
372
      NS_ASSERT (phySta->GetChannelNumber () == 36);
373
      NS_ASSERT (phySta->GetChannelWidth () == 20);
374
      NS_ASSERT (phySta->GetFrequency () == 5180);
375
      phySta->SetAttribute ("ChannelNumber", UintegerValue (36));
376
      phySta->SetAttribute ("Frequency", UintegerValue (5179));
377
      // We expect channel number to be 0 
378
      NS_ASSERT (phySta->GetChannelNumber () == 0);
379
      NS_ASSERT (phySta->GetChannelWidth () == 20);
380
      NS_ASSERT (phySta->GetFrequency () == 5179);
381
      PrintAttributesIfEnabled (printAttributes);
382
      break;
383
384
    default:
385
      std::cerr << "Invalid testcase number " << testCase << std::endl;
386
      exit (1);
387
      break;
388
  }
389
390
  // No need to Simulator::Run (); this is a configuration example
391
  Simulator::Destroy ();
392
}
(-)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 (+504 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::DoInitialize (void)
247
{
248
  NS_LOG_FUNCTION (this);
249
  // Perform some initialization checks
250
  if (GetChannelNumber () != 0 && GetStandard () == WIFI_PHY_STANDARD_UNSPECIFIED)
251
    {
252
      NS_FATAL_ERROR ("Error, ChannelNumber " << GetChannelNumber () << " was set by user, but not a standard");
253
    }
254
  if (GetChannelNumber () != 0 && GetFrequency () == 0)
255
    {
256
      NS_FATAL_ERROR ("Error, ChannelNumber " << GetChannelNumber () << " set but no frequency is configured");
257
    }
258
}
259
260
void
261
WifiPhy::ConfigureDefaultsForStandard (enum WifiPhyStandard standard)
262
{
263
  NS_LOG_FUNCTION (this << standard);
264
  switch (standard)
265
    {
266
    case WIFI_PHY_STANDARD_80211a:
267
      SetChannelWidth (20);
268
      SetFrequency (5180);
269
      // Channel number should be aligned by SetFrequency () to 36
270
      NS_ASSERT (GetChannelNumber () == 36);
271
      break;
272
    case WIFI_PHY_STANDARD_80211b:
273
      SetChannelWidth (22);
274
      SetFrequency (2412);
275
      // Channel number should be aligned by SetFrequency () to 1
276
      NS_ASSERT (GetChannelNumber () == 1);
277
      break;
278
    case WIFI_PHY_STANDARD_80211g:
279
      SetChannelWidth (20);
280
      SetFrequency (2412);
281
      // Channel number should be aligned by SetFrequency () to 1
282
      NS_ASSERT (GetChannelNumber () == 1);
283
      break;
284
    case WIFI_PHY_STANDARD_80211_10MHZ:
285
      SetChannelWidth (10);
286
      SetFrequency (5860);
287
      // Channel number should be aligned by SetFrequency () to 172
288
      NS_ASSERT (GetChannelNumber () == 172);
289
      break;
290
    case WIFI_PHY_STANDARD_80211_5MHZ:
291
      SetChannelWidth (5);
292
      SetFrequency (5860);
293
      // Channel number should be aligned by SetFrequency () to 0 
294
      NS_ASSERT (GetChannelNumber () == 0);
295
      break;
296
    case WIFI_PHY_STANDARD_holland:
297
      SetChannelWidth (20);
298
      SetFrequency (5180);
299
      // Channel number should be aligned by SetFrequency () to 36
300
      NS_ASSERT (GetChannelNumber () == 36);
301
      break;
302
    case WIFI_PHY_STANDARD_80211n_2_4GHZ:
303
      SetChannelWidth (20);
304
      SetFrequency (2412);
305
      // Channel number should be aligned by SetFrequency () to 1
306
      NS_ASSERT (GetChannelNumber () == 1);
307
      break;
308
    case WIFI_PHY_STANDARD_80211n_5GHZ:
309
      SetChannelWidth (20);
310
      SetFrequency (5180);
311
      // Channel number should be aligned by SetFrequency () to 36
312
      NS_ASSERT (GetChannelNumber () == 36);
313
      break;
314
    case WIFI_PHY_STANDARD_80211ac:
315
      SetChannelWidth (80);
316
      SetFrequency (5210);
317
      // Channel number should be aligned by SetFrequency () to 42
318
      NS_ASSERT (GetChannelNumber () == 42);
319
      break;
320
    case WIFI_PHY_STANDARD_UNSPECIFIED:
321
      NS_LOG_WARN ("Configuring unspecified standard; performing no action");
322
      break;
323
    default:
324
      NS_ASSERT (false);
325
      break;
326
    }
327
}
328
329
bool 
330
WifiPhy::DefineChannelNumber (uint16_t channelNumber, enum WifiPhyStandard standard, uint32_t frequency, uint32_t channelWidth)
331
{
332
  NS_LOG_FUNCTION (this << channelNumber << standard << frequency << channelWidth);
333
  ChannelNumberStandardPair p = std::make_pair (channelNumber, standard);
334
  ChannelToFrequencyWidthMap::const_iterator it;
335
  it = m_channelToFrequencyWidth.find (p);
336
  if (it != m_channelToFrequencyWidth.end ())
337
    {
338
      NS_LOG_DEBUG ("channel number/standard already defined; returning false");
339
      return false;
340
    }
341
  FrequencyWidthPair f = std::make_pair (frequency, channelWidth);
342
  m_channelToFrequencyWidth[p] = f;
343
  return true;
344
}
345
346
uint16_t 
347
WifiPhy::FindChannelNumberForFrequencyWidth (uint32_t frequency, uint32_t width) const
348
{
349
  NS_LOG_FUNCTION (this << frequency << width);
350
  bool found = false;
351
  FrequencyWidthPair f = std::make_pair (frequency, width);
352
  ChannelToFrequencyWidthMap::const_iterator it = m_channelToFrequencyWidth.begin ();
353
  while (it != m_channelToFrequencyWidth.end ())
354
    {
355
      if (it->second == f)
356
        {
357
           found = true;
358
           break;
359
        }
360
      ++it;
361
    }
362
  if (found)
363
    {
364
      NS_LOG_DEBUG ("Found, returning " << it->first.first);
365
      return (it->first.first);
366
    }
367
  else
368
    {
369
      NS_LOG_DEBUG ("Not found, returning 0");
370
      return 0;
371
    }
372
}
373
374
void
375
WifiPhy::ConfigureChannelForStandard (enum WifiPhyStandard standard)
376
{
377
  NS_LOG_FUNCTION (this << standard);
378
  // If the user has configured both Frequency and ChannelNumber, Frequency
379
  // takes precedence 
380
  if (GetFrequency () != 0)
381
    {
382
      // If Frequency is already set, then see whether a ChannelNumber can
383
      // be found that matches Frequency and ChannelWidth.  If so, configure 
384
      // the ChannelNumber to that channel number.  If not, set 
385
      // ChannelNumber to zero.
386
      NS_LOG_DEBUG ("Frequency set; checking whether a channel number corresponds");
387
      uint32_t channelNumberSearched = FindChannelNumberForFrequencyWidth (GetFrequency (), GetChannelWidth ());
388
      if (channelNumberSearched)
389
        {
390
          NS_LOG_DEBUG ("Channel number found; setting to " << channelNumberSearched);
391
          SetChannelNumber (channelNumberSearched);
392
        }
393
      else
394
        {
395
          NS_LOG_DEBUG ("Channel number not found; setting to zero");
396
          SetChannelNumber (0);
397
        }
398
    }
399
  else if (GetChannelNumber () != 0)
400
    {
401
      // If the channel number is known for this particular standard or for 
402
      // the unspecified standard, configure using the known values;
403
      // otherwise, this is a configuration error
404
      NS_LOG_DEBUG ("Configuring for channel number " << GetChannelNumber ());
405
      FrequencyWidthPair f = GetFrequencyWidthForChannelNumberStandard (GetChannelNumber (), standard);
406
      if (f.first == 0)
407
        {
408
          // the specific pair of number/standard is not known
409
          NS_LOG_DEBUG ("Falling back to check WIFI_PHY_STANDARD_UNSPECIFIED");
410
          f = GetFrequencyWidthForChannelNumberStandard (GetChannelNumber (), WIFI_PHY_STANDARD_UNSPECIFIED);
411
        }
412
      if (f.first == 0)
413
        {
414
          NS_FATAL_ERROR ("Error, ChannelNumber " << GetChannelNumber () << " is unknown for this standard");
415
        }
416
      else
417
        {
418
          NS_LOG_DEBUG ("Setting frequency to " << f.first << "; width to " << f.second);
419
          SetFrequency (f.first);
420
          SetChannelWidth (f.second);
421
        }
422
    }
423
}
424
425
void
426
WifiPhy::ConfigureStandard (enum WifiPhyStandard standard)
427
{
428
  NS_LOG_FUNCTION (this << standard);
429
  m_standard = standard;
430
  if (GetFrequency () == 0 && GetChannelNumber () == 0)
431
    {
432
      ConfigureDefaultsForStandard (standard);
433
    }
434
  else
435
    {
436
      // The user has configured either (or both) Frequency or ChannelNumber
437
      ConfigureChannelForStandard (standard);
438
    }
439
}
440
441
enum WifiPhyStandard
442
WifiPhy::GetStandard (void) const
443
{
444
  return m_standard;
445
}
446
447
void
448
WifiPhy::SetFrequency (uint32_t frequency)
449
{
450
  NS_LOG_FUNCTION (this << frequency);
451
  // If the user has configured both Frequency and ChannelNumber, Frequency
452
  // takes precedence 
453
  if (GetFrequency () == frequency)
454
    {
455
      NS_LOG_DEBUG ("No frequency change requested");
456
      return;
457
    }
458
  if (frequency == 0)
459
    {
460
      DoFrequencySwitch (0);
461
      NS_LOG_DEBUG ("Setting frequency and channel number to zero");
462
      m_channelCenterFrequency = 0;
463
      m_channelNumber = 0;
464
      return;
465
    }
466
  // See if there corresponds a channel number to the requested frequency.
467
  uint16_t nch = FindChannelNumberForFrequencyWidth (frequency, GetChannelWidth ());
468
  if (nch != 0)
469
    {
470
      NS_LOG_DEBUG ("Setting frequency " << frequency << " corresponds to channel " << nch);
471
      if (DoFrequencySwitch (frequency))
472
        {
473
          NS_LOG_DEBUG ("Channel frequency switched to " << frequency << "; channel number to " << nch);
474
          m_channelCenterFrequency = frequency;
475
          m_channelNumber = nch;
476
        }
477
    else
478
        {
479
          NS_LOG_DEBUG ("Suppressing reassignment of frequency");
480
        }
481
    }
482
  else
483
    {
484
      NS_LOG_DEBUG ("Channel number is unknown for frequency " << frequency);
485
      if (DoFrequencySwitch (frequency))
486
        {
487
          NS_LOG_DEBUG ("Channel frequency switched to " << frequency << "; channel number to " << 0);
488
          m_channelCenterFrequency = frequency;
489
          m_channelNumber = 0;
490
        }
491
      else
492
        {
493
          NS_LOG_DEBUG ("Suppressing reassignment of frequency");
494
        }
495
    }
496
}
497
498
uint32_t
499
WifiPhy::GetFrequency (void) const
500
{
501
  return m_channelCenterFrequency;
502
}
503
504
void
505
WifiPhy::SetChannelWidth (uint32_t channelwidth)
506
{
507
  NS_ASSERT_MSG (channelwidth == 5 || channelwidth == 10 || channelwidth == 20 || channelwidth == 22 || channelwidth == 40 || channelwidth == 80 || channelwidth == 160, "wrong channel width value");
508
  m_channelWidth = channelwidth;
509
  AddSupportedChannelWidth (channelwidth);
510
}
511
512
uint32_t
513
WifiPhy::GetChannelWidth (void) const
514
{
515
  return m_channelWidth;
516
}
517
518
void
519
WifiPhy::AddSupportedChannelWidth (uint32_t width)
520
{
521
  NS_LOG_FUNCTION (this << width);
522
  for (std::vector<uint32_t>::size_type i = 0; i != m_supportedChannelWidthSet.size (); i++)
523
    {
524
      if (m_supportedChannelWidthSet[i] == width)
525
        {
526
          return;
527
        }
528
    }
529
  NS_LOG_FUNCTION ("Adding " << width << " to supported channel width set");
530
  m_supportedChannelWidthSet.push_back (width);
531
}
532
533
std::vector<uint32_t> 
534
WifiPhy::GetSupportedChannelWidthSet (void) const
535
{
536
  return m_supportedChannelWidthSet;
537
}
538
539
WifiPhy::FrequencyWidthPair
540
WifiPhy::GetFrequencyWidthForChannelNumberStandard (uint16_t channelNumber, enum WifiPhyStandard standard) const
541
{
542
  ChannelNumberStandardPair p = std::make_pair (channelNumber, standard);
543
  FrequencyWidthPair f = m_channelToFrequencyWidth[p];
544
  return f;
545
}
546
547
void
548
WifiPhy::SetChannelNumber (uint16_t nch)
549
{
550
  NS_LOG_FUNCTION (this << nch);
551
  if (GetChannelNumber () == nch)
552
    {
553
      NS_LOG_DEBUG ("No channel change requested");
554
      return;
555
    }
556
  if (nch == 0)
557
    {
558
      // This case corresponds to when there is not a known channel
559
      // number for the requested frequency.  There is no need to call
560
      // DoChannelSwitch () because DoFrequencySwitch () should have been
561
      // called by the client
562
      NS_LOG_DEBUG ("Setting channel number to zero");
563
      m_channelNumber = 0;
564
      return;
565
    }
566
567
  if (IsInitialized () == false && GetStandard () == WIFI_PHY_STANDARD_UNSPECIFIED)
568
    {
569
      // This is not a run-time channel switch, and user has not yet
570
      // specified a standard to correspond to the channel number,
571
      // so we just need to set the channel number now, and the 
572
      // DoInitialize () method should perform checking at run-time that 
573
      // the standard was eventually set
574
      NS_LOG_DEBUG ("Setting channel number to " << nch);
575
      m_channelNumber = nch;
576
      return;
577
    }
578
579
  // First make sure that the channel number is defined for the standard
580
  // in use
581
  FrequencyWidthPair f = GetFrequencyWidthForChannelNumberStandard (nch, GetStandard ());
582
  if (f.first == 0)
583
    {
584
      f = GetFrequencyWidthForChannelNumberStandard (nch, WIFI_PHY_STANDARD_UNSPECIFIED);
585
    }
586
  if (f.first != 0)
587
    {
588
      if (DoChannelSwitch (nch))
589
        {
590
          NS_LOG_DEBUG ("Setting frequency to " << f.first << "; width to " << f.second);
591
          m_channelCenterFrequency = f.first;
592
          SetChannelWidth (f.second);
593
          m_channelNumber = nch;
594
        }
595
      else
596
        {
597
          // Subclass may have suppressed (e.g. waiting for state change)
598
          NS_LOG_DEBUG ("Channel switch suppressed");
599
        }
600
    }
601
  else
602
    {
603
      NS_FATAL_ERROR ("Frequency not found for channel number " << nch);
604
    }
605
}
606
607
uint16_t
608
WifiPhy::GetChannelNumber (void) const
609
{
610
  return m_channelNumber;
611
}
612
613
bool
614
WifiPhy::DoChannelSwitch (uint16_t nch)
615
{
616
  return true;
617
}
618
619
bool
620
WifiPhy::DoFrequencySwitch (uint32_t frequency)
621
{
622
  return true;
623
}
624
121
WifiMode
625
WifiMode
122
WifiPhy::GetHtPlcpHeaderMode (WifiMode payloadMode)
626
WifiPhy::GetHtPlcpHeaderMode (WifiMode payloadMode)
123
{
627
{
(-)a/src/wifi/model/wifi-phy.h (-17 / +119 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
   * Get the configured Wi-Fi standard
587
   *
588
   * \return the Wi-Fi standard that has been configured
589
   */
590
  virtual enum WifiPhyStandard GetStandard (void) const;
591
592
  /**
593
   * Add a channel definition to the WifiPhy.  The pair (channelNumber,
594
   * WifiPhyStandard) may then be used to lookup a pair (frequency, 
595
   * channelWidth).
596
   *
597
   * If the channel is not already defined for the standard, the method
598
   * should return true; otherwise false.
599
   *
600
   * \param channelNumber the channel number to define
601
   * \param standard the applicable WifiPhyStandard
602
   * \param frequency the frequency (MHz)
603
   * \param channelWidth the channel width (MHz)
604
   *
605
   * \return true if the channel definition succeeded
606
   */
607
  bool DefineChannelNumber (uint16_t channelNumber, enum WifiPhyStandard standard, uint32_t frequency, uint32_t channelWidth);
608
609
  /**
610
   * A pair of a ChannelNumber and WifiPhyStandard
611
   */
612
  typedef std::pair<uint16_t, enum WifiPhyStandard> ChannelNumberStandardPair;
613
  /**
614
   * A pair of a center Frequency and a ChannelWidth
615
   */
616
  typedef std::pair<uint32_t, uint32_t> FrequencyWidthPair;
580
617
581
  /**
618
  /**
582
   * Return the WifiChannel this WifiPhy is connected to.
619
   * Return the WifiChannel this WifiPhy is connected to.
 Lines 1210-1222    Link Here 
1210
  virtual int64_t AssignStreams (int64_t stream) = 0;
1247
  virtual int64_t AssignStreams (int64_t stream) = 0;
1211
1248
1212
  /**
1249
  /**
1213
   * \param freq the operating frequency on this node.
1250
   * \param freq the operating center frequency (MHz) on this node.
1214
   */
1251
   */
1215
  virtual void SetFrequency (uint32_t freq) = 0;
1252
  virtual void SetFrequency (uint32_t freq);
1216
  /**
1253
  /**
1217
   * \return the operating frequency on this node
1254
   * \return the operating center frequency (MHz) 
1218
   */
1255
   */
1219
  virtual uint32_t GetFrequency (void) const = 0;
1256
  virtual uint32_t GetFrequency (void) const;
1220
  /**
1257
  /**
1221
   * \param tx the number of transmitters on this node.
1258
   * \param tx the number of transmitters on this node.
1222
   */
1259
   */
 Lines 1276-1286    Link Here 
1276
  /**
1313
  /**
1277
   * \return the channel width
1314
   * \return the channel width
1278
   */
1315
   */
1279
  virtual uint32_t GetChannelWidth (void) const = 0;
1316
  virtual uint32_t GetChannelWidth (void) const;
1280
  /**
1317
  /**
1281
   * \param channelwidth channel width
1318
   * \param channelwidth channel width
1282
   */
1319
   */
1283
  virtual void SetChannelWidth (uint32_t channelwidth) = 0;
1320
  virtual void SetChannelWidth (uint32_t channelwidth);
1321
  /**
1322
   * \param channelwidth channel width (in MHz) to support
1323
   */
1324
  virtual void AddSupportedChannelWidth (uint32_t channelwidth);
1325
  /**
1326
   * \return a vector containing the supported channel widths, values in MHz
1327
   */
1328
  virtual std::vector<uint32_t> GetSupportedChannelWidthSet (void) const;
1284
  /**
1329
  /**
1285
   * \return the maximum number of supported Rx spatial streams
1330
   * \return the maximum number of supported Rx spatial streams
1286
   */
1331
   */
 Lines 1290-1303    Link Here 
1290
   */
1335
   */
1291
  virtual uint8_t GetSupportedTxSpatialStreams (void) const = 0;
1336
  virtual uint8_t GetSupportedTxSpatialStreams (void) const = 0;
1292
  /**
1337
  /**
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.
1338
   * Convert from dBm to Watts.
1302
   *
1339
   *
1303
   * \param dbm the power in dBm
1340
   * \param dbm the power in dBm
 Lines 1330-1337    Link Here 
1330
   */
1367
   */
1331
  double RatioToDb (double ratio) const;
1368
  double RatioToDb (double ratio) const;
1332
1369
1370
protected:
1371
  // Inherited
1372
  virtual void DoInitialize (void);
1373
  /**
1374
   * The default implementation does nothing and returns true.  This method 
1375
   * is typically called internally by SetChannelNumber ().
1376
   *
1377
   * \brief Perform any actions necessary when user changes channel number
1378
   * \param id channel number to try to switch to
1379
   * \return true if WifiPhy can actually change the number; false if not
1380
   * \see SetChannelNumber
1381
   */
1382
  virtual bool DoChannelSwitch (uint16_t id);
1383
  /**
1384
   * The default implementation does nothing and returns true.  This method
1385
   * is typically called internally by SetFrequency ().
1386
   *
1387
   * \brief Perform any actions necessary when user changes frequency
1388
   * \param frequency frequency to try to switch to
1389
   * \return true if WifiPhy can actually change the frequency; false if not
1390
   * \see SetFrequency
1391
   */
1392
  virtual bool DoFrequencySwitch (uint32_t frequency);
1333
private:
1393
private:
1334
  /**
1394
  /**
1395
   * Configure the PHY-level parameters for different Wi-Fi standard.
1396
   * This method is called when defaults for each standard must be 
1397
   * selected.
1398
   *
1399
   * \param standard the Wi-Fi standard
1400
   */
1401
  virtual void ConfigureDefaultsForStandard (enum WifiPhyStandard standard);
1402
  /**
1403
   * Configure the PHY-level parameters for different Wi-Fi standard.
1404
   * This method is called when the Frequency or ChannelNumber attributes
1405
   * are set by the user.  If the Frequency or ChannelNumber are valid for
1406
   * the standard, they are used instead.
1407
   *
1408
   * \param standard the Wi-Fi standard
1409
   */
1410
  virtual void ConfigureChannelForStandard (enum WifiPhyStandard standard);
1411
  /**
1412
   * Look for channel number matching the frequency and width
1413
   * \param frequency The center frequency to use
1414
   * \param width The channel width to use
1415
   * \return the channel number if found, zero if not
1416
   */
1417
  uint16_t FindChannelNumberForFrequencyWidth (uint32_t frequency, uint32_t width) const;
1418
  /**
1419
   * Lookup frequency/width pair for channelNumber/standard pair
1420
   * \param channelNumber The channel number to check
1421
   * \param standard The WifiPhyStandard to check
1422
   * \return the FrequencyWidthPair found
1423
   */
1424
  FrequencyWidthPair GetFrequencyWidthForChannelNumberStandard (uint16_t channelNumber, enum WifiPhyStandard standard) const;
1425
  /**
1335
   * The trace source fired when a packet begins the transmission process on
1426
   * The trace source fired when a packet begins the transmission process on
1336
   * the medium.
1427
   * the medium.
1337
   *
1428
   *
 Lines 1408-1413    Link Here 
1408
  TracedCallback<Ptr<const Packet>, uint16_t, uint16_t, uint32_t,
1499
  TracedCallback<Ptr<const Packet>, uint16_t, uint16_t, uint32_t,
1409
                 WifiPreamble, WifiTxVector, struct mpduInfo> m_phyMonitorSniffTxTrace;
1500
                 WifiPreamble, WifiTxVector, struct mpduInfo> m_phyMonitorSniffTxTrace;
1410
1501
1502
  enum WifiPhyStandard m_standard;     //!< WifiPhyStandard
1503
  uint32_t m_channelCenterFrequency;   //!< Center frequency in MHz
1504
  uint32_t m_channelWidth;             //!< Channel width
1505
1506
1507
  typedef std::map<ChannelNumberStandardPair,FrequencyWidthPair> ChannelToFrequencyWidthMap;
1508
  static ChannelToFrequencyWidthMap m_channelToFrequencyWidth;
1509
1510
  std::vector<uint32_t> m_supportedChannelWidthSet; //!< Supported channel width
1511
  uint16_t             m_channelNumber;  //!< Operating channel number
1512
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
1513
  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
1514
  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
};
1515
};
(-)a/src/wifi/model/yans-wifi-phy.cc (-157 / +107 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_endRxEvent (),
192
    m_channelNumber (1),
193
    m_endRxEvent (),
194
    m_endPlcpRxEvent (),
174
    m_endPlcpRxEvent (),
195
    m_channelStartingFrequency (0),
196
    m_mpdusNum (0),
175
    m_mpdusNum (0),
197
    m_plcpSuccess (false),
176
    m_plcpSuccess (false),
198
    m_txMpduReferenceNumber (0xffffffff),
177
    m_txMpduReferenceNumber (0xffffffff),
 Lines 220-236    Link Here 
220
  m_state = 0;
199
  m_state = 0;
221
}
200
}
222
201
223
void
202
bool
224
YansWifiPhy::DoInitialize ()
203
YansWifiPhy::DoChannelSwitch (uint16_t nch)
225
{
204
{
226
  NS_LOG_FUNCTION (this);
205
  if (!IsInitialized ())
227
  m_initialized = true;
206
    {
207
      //this is not channel switch, this is initialization
208
      NS_LOG_DEBUG ("initialize to channel " << nch);
209
      return true;
210
    }
211
212
  NS_ASSERT (!IsStateSwitching ());
213
  switch (m_state->GetState ())
214
    {
215
    case YansWifiPhy::RX:
216
      NS_LOG_DEBUG ("drop packet because of channel switching while reception");
217
      m_endPlcpRxEvent.Cancel ();
218
      m_endRxEvent.Cancel ();
219
      goto switchChannel;
220
      break;
221
    case YansWifiPhy::TX:
222
      NS_LOG_DEBUG ("channel switching postponed until end of current transmission");
223
      Simulator::Schedule (GetDelayUntilIdle (), &WifiPhy::SetChannelNumber, this, nch);
224
      break;
225
    case YansWifiPhy::CCA_BUSY:
226
    case YansWifiPhy::IDLE:
227
      goto switchChannel;
228
      break;
229
    case YansWifiPhy::SLEEP:
230
      NS_LOG_DEBUG ("channel switching ignored in sleep mode");
231
      break;
232
    default:
233
      NS_ASSERT (false);
234
      break;
235
    }
236
237
  return false;
238
239
switchChannel:
240
241
  NS_LOG_DEBUG ("switching channel " << GetChannelNumber () << " -> " << nch);
242
  m_state->SwitchToChannelSwitching (m_channelSwitchDelay);
243
  m_interference.EraseEvents ();
244
  /*
245
   * Needed here to be able to correctly sensed the medium for the first
246
   * time after the switching. The actual switching is not performed until
247
   * after m_channelSwitchDelay. Packets received during the switching
248
   * state are added to the event list and are employed later to figure
249
   * out the state of the medium after the switching.
250
   */
251
  return true;
252
}
253
254
bool
255
YansWifiPhy::DoFrequencySwitch (uint32_t frequency)
256
{
257
  if (!IsInitialized ())
258
    {
259
      //this is not channel switch, this is initialization
260
      NS_LOG_DEBUG ("start at frequency " << frequency);
261
      return true;
262
    }
263
264
  NS_ASSERT (!IsStateSwitching ());
265
  switch (m_state->GetState ())
266
    {
267
    case YansWifiPhy::RX:
268
      NS_LOG_DEBUG ("drop packet because of channel/frequency switching while reception");
269
      m_endPlcpRxEvent.Cancel ();
270
      m_endRxEvent.Cancel ();
271
      goto switchFrequency;
272
      break;
273
    case YansWifiPhy::TX:
274
      NS_LOG_DEBUG ("channel/frequency switching postponed until end of current transmission");
275
      Simulator::Schedule (GetDelayUntilIdle (), &WifiPhy::SetFrequency, this, frequency);
276
      break;
277
    case YansWifiPhy::CCA_BUSY:
278
    case YansWifiPhy::IDLE:
279
      goto switchFrequency;
280
      break;
281
    case YansWifiPhy::SLEEP:
282
      NS_LOG_DEBUG ("frequency switching ignored in sleep mode");
283
      break;
284
    default:
285
      NS_ASSERT (false);
286
      break;
287
    }
288
289
  return false;
290
291
switchFrequency:
292
293
  NS_LOG_DEBUG ("switching frequency " << GetFrequency () << " -> " << frequency);
294
  m_state->SwitchToChannelSwitching (m_channelSwitchDelay);
295
  m_interference.EraseEvents ();
296
  /*
297
   * Needed here to be able to correctly sensed the medium for the first
298
   * time after the switching. The actual switching is not performed until
299
   * after m_channelSwitchDelay. Packets received during the switching
300
   * state are added to the event list and are employed later to figure
301
   * out the state of the medium after the switching.
302
   */
303
  return true;
228
}
304
}
229
305
230
void
306
void
231
YansWifiPhy::ConfigureStandard (enum WifiPhyStandard standard)
307
YansWifiPhy::ConfigureStandard (enum WifiPhyStandard standard)
232
{
308
{
233
  NS_LOG_FUNCTION (this << standard);
309
  NS_LOG_FUNCTION (this << standard);
310
  WifiPhy::ConfigureStandard (standard); // set up base class
234
  switch (standard)
311
  switch (standard)
235
    {
312
    {
236
    case WIFI_PHY_STANDARD_80211a:
313
    case WIFI_PHY_STANDARD_80211a:
 Lines 252-262    Link Here 
252
      ConfigureHolland ();
329
      ConfigureHolland ();
253
      break;
330
      break;
254
    case WIFI_PHY_STANDARD_80211n_2_4GHZ:
331
    case WIFI_PHY_STANDARD_80211n_2_4GHZ:
255
      m_channelStartingFrequency = 2407;
256
      Configure80211n ();
332
      Configure80211n ();
257
      break;
333
      break;
258
    case WIFI_PHY_STANDARD_80211n_5GHZ:
334
    case WIFI_PHY_STANDARD_80211n_5GHZ:
259
      m_channelStartingFrequency = 5e3;
260
      Configure80211n ();
335
      Configure80211n ();
261
      break;
336
      break;
262
    case WIFI_PHY_STANDARD_80211ac:
337
    case WIFI_PHY_STANDARD_80211ac:
 Lines 428-504    Link Here 
428
  m_channel->Add (this);
503
  m_channel->Add (this);
429
}
504
}
430
505
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
506
Time
491
YansWifiPhy::GetChannelSwitchDelay (void) const
507
YansWifiPhy::GetChannelSwitchDelay (void) const
492
{
508
{
493
  return m_channelSwitchDelay;
509
  return m_channelSwitchDelay;
494
}
510
}
495
511
496
double
497
YansWifiPhy::GetChannelFrequencyMhz () const
498
{
499
  return m_channelStartingFrequency + 5 * GetChannelNumber ();
500
}
501
502
void
512
void
503
YansWifiPhy::SetSleepMode (void)
513
YansWifiPhy::SetSleepMode (void)
504
{
514
{
 Lines 825-831    Link Here 
825
  struct mpduInfo aMpdu;
835
  struct mpduInfo aMpdu;
826
  aMpdu.type = mpdutype;
836
  aMpdu.type = mpdutype;
827
  aMpdu.mpduRefNumber = m_txMpduReferenceNumber;
837
  aMpdu.mpduRefNumber = m_txMpduReferenceNumber;
828
  NotifyMonitorSniffTx (packet, (uint16_t)GetChannelFrequencyMhz (), GetChannelNumber (), dataRate500KbpsUnits, preamble, txVector, aMpdu);
838
  NotifyMonitorSniffTx (packet, (uint16_t)GetFrequency (), GetChannelNumber (), dataRate500KbpsUnits, preamble, txVector, aMpdu);
829
  m_state->SwitchToTx (txDuration, packet, GetPowerDbm (txVector.GetTxPowerLevel ()), txVector, preamble);
839
  m_state->SwitchToTx (txDuration, packet, GetPowerDbm (txVector.GetTxPowerLevel ()), txVector, preamble);
830
  m_channel->Send (this, packet, GetPowerDbm (txVector.GetTxPowerLevel ()) + m_txGainDb, txVector, preamble, mpdutype, txDuration);
840
  m_channel->Send (this, packet, GetPowerDbm (txVector.GetTxPowerLevel ()) + m_txGainDb, txVector, preamble, mpdutype, txDuration);
831
}
841
}
 Lines 877-884    Link Here 
877
YansWifiPhy::Configure80211a (void)
887
YansWifiPhy::Configure80211a (void)
878
{
888
{
879
  NS_LOG_FUNCTION (this);
889
  NS_LOG_FUNCTION (this);
880
  m_channelStartingFrequency = 5e3; //5.000 GHz
881
  SetChannelWidth (20); //20 MHz
882
890
883
  m_deviceRateSet.push_back (WifiPhy::GetOfdmRate6Mbps ());
891
  m_deviceRateSet.push_back (WifiPhy::GetOfdmRate6Mbps ());
884
  m_deviceRateSet.push_back (WifiPhy::GetOfdmRate9Mbps ());
892
  m_deviceRateSet.push_back (WifiPhy::GetOfdmRate9Mbps ());
 Lines 894-901    Link Here 
894
YansWifiPhy::Configure80211b (void)
902
YansWifiPhy::Configure80211b (void)
895
{
903
{
896
  NS_LOG_FUNCTION (this);
904
  NS_LOG_FUNCTION (this);
897
  m_channelStartingFrequency = 2407; //2.407 GHz
898
  SetChannelWidth (22); //22 MHz
899
905
900
  m_deviceRateSet.push_back (WifiPhy::GetDsssRate1Mbps ());
906
  m_deviceRateSet.push_back (WifiPhy::GetDsssRate1Mbps ());
901
  m_deviceRateSet.push_back (WifiPhy::GetDsssRate2Mbps ());
907
  m_deviceRateSet.push_back (WifiPhy::GetDsssRate2Mbps ());
 Lines 908-914    Link Here 
908
{
914
{
909
  NS_LOG_FUNCTION (this);
915
  NS_LOG_FUNCTION (this);
910
  Configure80211b ();
916
  Configure80211b ();
911
  SetChannelWidth (20); //20 MHz
912
917
913
  m_deviceRateSet.push_back (WifiPhy::GetErpOfdmRate6Mbps ());
918
  m_deviceRateSet.push_back (WifiPhy::GetErpOfdmRate6Mbps ());
914
  m_deviceRateSet.push_back (WifiPhy::GetErpOfdmRate9Mbps ());
919
  m_deviceRateSet.push_back (WifiPhy::GetErpOfdmRate9Mbps ());
 Lines 924-931    Link Here 
924
YansWifiPhy::Configure80211_10Mhz (void)
929
YansWifiPhy::Configure80211_10Mhz (void)
925
{
930
{
926
  NS_LOG_FUNCTION (this);
931
  NS_LOG_FUNCTION (this);
927
  m_channelStartingFrequency = 5e3; //5.000 GHz, suppose 802.11a
928
  SetChannelWidth (10); //10 MHz
929
932
930
  m_deviceRateSet.push_back (WifiPhy::GetOfdmRate3MbpsBW10MHz ());
933
  m_deviceRateSet.push_back (WifiPhy::GetOfdmRate3MbpsBW10MHz ());
931
  m_deviceRateSet.push_back (WifiPhy::GetOfdmRate4_5MbpsBW10MHz ());
934
  m_deviceRateSet.push_back (WifiPhy::GetOfdmRate4_5MbpsBW10MHz ());
 Lines 941-948    Link Here 
941
YansWifiPhy::Configure80211_5Mhz (void)
944
YansWifiPhy::Configure80211_5Mhz (void)
942
{
945
{
943
  NS_LOG_FUNCTION (this);
946
  NS_LOG_FUNCTION (this);
944
  m_channelStartingFrequency = 5e3; //5.000 GHz, suppose 802.11a
945
  SetChannelWidth (5); //5 MHz
946
947
947
  m_deviceRateSet.push_back (WifiPhy::GetOfdmRate1_5MbpsBW5MHz ());
948
  m_deviceRateSet.push_back (WifiPhy::GetOfdmRate1_5MbpsBW5MHz ());
948
  m_deviceRateSet.push_back (WifiPhy::GetOfdmRate2_25MbpsBW5MHz ());
949
  m_deviceRateSet.push_back (WifiPhy::GetOfdmRate2_25MbpsBW5MHz ());
 Lines 958-965    Link Here 
958
YansWifiPhy::ConfigureHolland (void)
959
YansWifiPhy::ConfigureHolland (void)
959
{
960
{
960
  NS_LOG_FUNCTION (this);
961
  NS_LOG_FUNCTION (this);
961
  m_channelStartingFrequency = 5e3; //5.000 GHz
962
  SetChannelWidth (20); //20 MHz
963
962
964
  m_deviceRateSet.push_back (WifiPhy::GetOfdmRate6Mbps ());
963
  m_deviceRateSet.push_back (WifiPhy::GetOfdmRate6Mbps ());
965
  m_deviceRateSet.push_back (WifiPhy::GetOfdmRate12Mbps ());
964
  m_deviceRateSet.push_back (WifiPhy::GetOfdmRate12Mbps ());
 Lines 1041-1056    Link Here 
1041
YansWifiPhy::Configure80211n (void)
1040
YansWifiPhy::Configure80211n (void)
1042
{
1041
{
1043
  NS_LOG_FUNCTION (this);
1042
  NS_LOG_FUNCTION (this);
1044
  if (m_channelStartingFrequency >= 2400 && m_channelStartingFrequency <= 2500) //at 2.4 GHz
1043
  if (GetFrequency () >= 2400 && GetFrequency () <= 2500) //at 2.4 GHz
1045
    {
1044
    {
1046
      Configure80211b ();
1045
      Configure80211b ();
1047
      Configure80211g ();
1046
      Configure80211g ();
1048
    }
1047
    }
1049
  if (m_channelStartingFrequency >= 5000 && m_channelStartingFrequency <= 6000) //at 5 GHz
1048
  if (GetFrequency () >= 5000 && GetFrequency () <= 6000) //at 5 GHz
1050
    {
1049
    {
1051
      Configure80211a ();
1050
      Configure80211a ();
1052
    }
1051
    }
1053
  SetChannelWidth (20); //20 MHz
1054
  m_bssMembershipSelectorSet.push_back (HT_PHY);
1052
  m_bssMembershipSelectorSet.push_back (HT_PHY);
1055
  ConfigureHtDeviceMcsSet ();
1053
  ConfigureHtDeviceMcsSet ();
1056
}
1054
}
 Lines 1059-1067    Link Here 
1059
YansWifiPhy::Configure80211ac (void)
1057
YansWifiPhy::Configure80211ac (void)
1060
{
1058
{
1061
  NS_LOG_FUNCTION (this);
1059
  NS_LOG_FUNCTION (this);
1062
  m_channelStartingFrequency = 5e3; //5.000 GHz
1063
  Configure80211n ();
1060
  Configure80211n ();
1064
  SetChannelWidth (80); //80 MHz
1065
1061
1066
  m_deviceMcsSet.push_back (WifiPhy::GetVhtMcs0 ());
1062
  m_deviceMcsSet.push_back (WifiPhy::GetVhtMcs0 ());
1067
  m_deviceMcsSet.push_back (WifiPhy::GetVhtMcs1 ());
1063
  m_deviceMcsSet.push_back (WifiPhy::GetVhtMcs1 ());
 Lines 1207-1213    Link Here 
1207
          struct mpduInfo aMpdu;
1203
          struct mpduInfo aMpdu;
1208
          aMpdu.type = mpdutype;
1204
          aMpdu.type = mpdutype;
1209
          aMpdu.mpduRefNumber = m_rxMpduReferenceNumber;
1205
          aMpdu.mpduRefNumber = m_rxMpduReferenceNumber;
1210
          NotifyMonitorSniffRx (packet, (uint16_t)GetChannelFrequencyMhz (), GetChannelNumber (), dataRate500KbpsUnits, event->GetPreambleType (), event->GetTxVector (), aMpdu, signalNoise);
1206
          NotifyMonitorSniffRx (packet, (uint16_t)GetFrequency (), GetChannelNumber (), dataRate500KbpsUnits, event->GetPreambleType (), event->GetTxVector (), aMpdu, signalNoise);
1211
          m_state->SwitchFromRxEndOk (packet, snrPer.snr, event->GetTxVector (), event->GetPreambleType ());
1207
          m_state->SwitchFromRxEndOk (packet, snrPer.snr, event->GetTxVector (), event->GetPreambleType ());
1212
        }
1208
        }
1213
      else
1209
      else
 Lines 1237-1248    Link Here 
1237
}
1233
}
1238
1234
1239
void
1235
void
1240
YansWifiPhy::SetFrequency (uint32_t freq)
1241
{
1242
  m_channelStartingFrequency = freq;
1243
}
1244
1245
void
1246
YansWifiPhy::SetNumberOfTransmitAntennas (uint32_t tx)
1236
YansWifiPhy::SetNumberOfTransmitAntennas (uint32_t tx)
1247
{
1237
{
1248
  m_numberOfTransmitters = tx;
1238
  m_numberOfTransmitters = tx;
 Lines 1286-1297    Link Here 
1286
}
1276
}
1287
1277
1288
uint32_t
1278
uint32_t
1289
YansWifiPhy::GetFrequency (void) const
1290
{
1291
  return m_channelStartingFrequency;
1292
}
1293
1294
uint32_t
1295
YansWifiPhy::GetNumberOfTransmitAntennas (void) const
1279
YansWifiPhy::GetNumberOfTransmitAntennas (void) const
1296
{
1280
{
1297
  return m_numberOfTransmitters;
1281
  return m_numberOfTransmitters;
 Lines 1333-1352    Link Here 
1333
  m_shortPreamble = enable;
1317
  m_shortPreamble = enable;
1334
}
1318
}
1335
1319
1336
void
1337
YansWifiPhy::SetChannelWidth (uint32_t channelwidth)
1338
{
1339
  NS_ASSERT_MSG (channelwidth == 5 || channelwidth == 10 || channelwidth == 20 || channelwidth == 22 || channelwidth == 40 || channelwidth == 80 || channelwidth == 160, "wrong channel width value");
1340
  m_channelWidth = channelwidth;
1341
  AddSupportedChannelWidth (channelwidth);
1342
}
1343
1344
uint32_t
1345
YansWifiPhy::GetChannelWidth (void) const
1346
{
1347
  return m_channelWidth;
1348
}
1349
1350
uint8_t 
1320
uint8_t 
1351
YansWifiPhy::GetSupportedRxSpatialStreams (void) const
1321
YansWifiPhy::GetSupportedRxSpatialStreams (void) const
1352
{
1322
{
 Lines 1359-1384    Link Here 
1359
  return (static_cast<uint8_t> (GetNumberOfTransmitAntennas ()));
1329
  return (static_cast<uint8_t> (GetNumberOfTransmitAntennas ()));
1360
}
1330
}
1361
1331
1362
void
1363
YansWifiPhy::AddSupportedChannelWidth (uint32_t width)
1364
{
1365
  NS_LOG_FUNCTION (this << width);
1366
  for (std::vector<uint32_t>::size_type i = 0; i != m_supportedChannelWidthSet.size (); i++)
1367
    {
1368
      if (m_supportedChannelWidthSet[i] == width)
1369
        {
1370
          return;
1371
        }
1372
    }
1373
  m_supportedChannelWidthSet.push_back (width);
1374
}
1375
1376
std::vector<uint32_t> 
1377
YansWifiPhy::GetSupportedChannelWidthSet (void) const
1378
{
1379
  return m_supportedChannelWidthSet;
1380
}
1381
1382
uint32_t
1332
uint32_t
1383
YansWifiPhy::GetNBssMembershipSelectors (void) const
1333
YansWifiPhy::GetNBssMembershipSelectors (void) const
1384
{
1334
{
(-)a/src/wifi/model/yans-wifi-phy.h (-48 / +6 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 424-433    Link Here 
424
  virtual uint8_t GetNMcs (void) const;
384
  virtual uint8_t GetNMcs (void) const;
425
  virtual WifiMode GetMcs (uint8_t mcs) const;
385
  virtual WifiMode GetMcs (uint8_t mcs) const;
426
386
387
protected:
388
  // Inherited
389
  virtual void DoDispose (void);
390
  virtual bool DoChannelSwitch (uint16_t id);
391
  virtual bool DoFrequencySwitch (uint32_t frequency);
392
427
private:
393
private:
428
  virtual void DoInitialize (void);
429
  virtual void DoDispose (void);
430
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 494-500    Link Here 
494
   */
457
   */
495
  void EndReceive (Ptr<Packet> packet, enum WifiPreamble preamble, enum mpduType mpdutype, Ptr<InterferenceHelper::Event> event);
458
  void EndReceive (Ptr<Packet> packet, enum WifiPreamble preamble, enum mpduType mpdutype, Ptr<InterferenceHelper::Event> event);
496
459
497
  bool     m_initialized;         //!< Flag for runtime initialization
498
  double   m_edThresholdW;        //!< Energy detection threshold in watts
460
  double   m_edThresholdW;        //!< Energy detection threshold in watts
499
  double   m_ccaMode1ThresholdW;  //!< Clear channel assessment (CCA) threshold in watts
461
  double   m_ccaMode1ThresholdW;  //!< Clear channel assessment (CCA) threshold in watts
500
  double   m_txGainDb;            //!< Transmission gain (dB)
462
  double   m_txGainDb;            //!< Transmission gain (dB)
 Lines 504-510    Link Here 
504
  uint32_t m_nTxPower;            //!< Number of available transmission power levels
466
  uint32_t m_nTxPower;            //!< Number of available transmission power levels
505
467
506
  Ptr<YansWifiChannel> m_channel;        //!< YansWifiChannel that this YansWifiPhy is connected to
468
  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
469
  Ptr<NetDevice>       m_device;         //!< Pointer to the device
509
  Ptr<MobilityModel>   m_mobility;       //!< Pointer to the mobility model
470
  Ptr<MobilityModel>   m_mobility;       //!< Pointer to the mobility model
510
471
 Lines 514-521    Link Here 
514
  bool     m_stbc;                  //!< Flag if STBC is used
475
  bool     m_stbc;                  //!< Flag if STBC is used
515
  bool     m_greenfield;            //!< Flag if GreenField format is supported
476
  bool     m_greenfield;            //!< Flag if GreenField format is supported
516
  bool     m_guardInterval;         //!< Flag if short guard interval is used
477
  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
478
  bool     m_shortPreamble;         //!< Flag if short PLCP preamble is supported
520
479
521
  /**
480
  /**
 Lines 562-568    Link Here 
562
  EventId m_endPlcpRxEvent;
521
  EventId m_endPlcpRxEvent;
563
522
564
  Ptr<UniformRandomVariable> m_random;  //!< Provides uniform random variables.
523
  Ptr<UniformRandomVariable> m_random;  //!< Provides uniform random variables.
565
  double m_channelStartingFrequency;    //!< Standard-dependent center frequency of 0-th channel in MHz
566
  Ptr<WifiPhyStateHelper> m_state;      //!< Pointer to WifiPhyStateHelper
524
  Ptr<WifiPhyStateHelper> m_state;      //!< Pointer to WifiPhyStateHelper
567
  InterferenceHelper m_interference;    //!< Pointer to InterferenceHelper
525
  InterferenceHelper m_interference;    //!< Pointer to InterferenceHelper
568
  Time m_channelSwitchDelay;            //!< Time required to switch between channel
526
  Time m_channelSwitchDelay;            //!< Time required to switch between channel
(-)a/src/wifi/test/wifi-test.cc (+332 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.SetRemoteStationManager ("ns3::IdealWifiManager");
718
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
719
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
720
      phySta = GetYansWifiPhyPtr (staDevice);
721
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 36, "802.11n-5GHz configuration");
722
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11n-5GHz configuration");
723
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5180, "802.11n-5GHz configuration");
724
  }
725
  {
726
      // case 5
727
      WifiHelper wifi;
728
      wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
729
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_2_4GHZ);
730
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
731
      phySta = GetYansWifiPhyPtr (staDevice);
732
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 1, "802.11n-2.4GHz configuration");
733
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11n-2.4GHz configuration");
734
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 2412, "802.11n-2.4GHz configuration");
735
  }
736
  {
737
      // case 6
738
      WifiHelper wifi;
739
      wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
740
      wifi.SetStandard (WIFI_PHY_STANDARD_80211ac);
741
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
742
      phySta = GetYansWifiPhyPtr (staDevice);
743
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 42, "802.11ac configuration");
744
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 80, "802.11ac configuration");
745
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5210, "802.11ac configuration");
746
  }
747
  {
748
      // case 7
749
      WifiHelper wifi;
750
      wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
751
      wifi.SetStandard (WIFI_PHY_STANDARD_80211_10MHZ);
752
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
753
      phySta = GetYansWifiPhyPtr (staDevice);
754
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 172, "802.11 10Mhz configuration");
755
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 10, "802.11 10Mhz configuration");
756
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5860, "802.11 10Mhz configuration");
757
  }
758
  {
759
      // case 8
760
      WifiHelper wifi;
761
      wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
762
      wifi.SetStandard (WIFI_PHY_STANDARD_80211_5MHZ);
763
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
764
      phySta = GetYansWifiPhyPtr (staDevice);
765
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 0, "802.11 5Mhz configuration");
766
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 5, "802.11 5Mhz configuration");
767
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5860, "802.11 5Mhz configuration");
768
  }
769
  {
770
      // case 9
771
      WifiHelper wifi;
772
      wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
773
      wifi.SetStandard (WIFI_PHY_STANDARD_holland);
774
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
775
      phySta = GetYansWifiPhyPtr (staDevice);
776
      // We expect channel 36, width 20, frequency 5180
777
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 36, "802.11 5Mhz configuration");
778
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5Mhz configuration");
779
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5180, "802.11 5Mhz configuration");
780
  }
781
  {
782
      // case 10
783
      WifiHelper wifi;
784
      wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
785
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
786
      phy.Set ("ChannelNumber", UintegerValue(44));
787
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
788
      phySta = GetYansWifiPhyPtr (staDevice);
789
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 44, "802.11 5GHz configuration");
790
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
791
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5220, "802.11 5GHz configuration");
792
  }
793
  {
794
      // case 11
795
      WifiHelper wifi;
796
      wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
797
      phy.Set ("ChannelNumber", UintegerValue(44));
798
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
799
      phySta = GetYansWifiPhyPtr (staDevice);
800
      // Post-install reconfiguration to channel number 40
801
      Config::Set ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/ChannelNumber", UintegerValue(40));
802
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 40, "802.11 5GHz configuration");
803
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
804
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5200, "802.11 5GHz configuration");
805
  }
806
  {
807
      // case 12
808
      WifiHelper wifi;
809
      wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
810
      phy.Set ("ChannelNumber", UintegerValue (44));
811
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
812
      phySta = GetYansWifiPhyPtr (staDevice);
813
      // Post-install reconfiguration to channel width 40 MHz
814
      Config::Set ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/ChannelWidth", UintegerValue(40));
815
      // Although channel 44 is configured originally for 20 MHz, we
816
      // allow it to be used for 40 MHz here
817
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 44, "802.11 5GHz configuration");
818
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 40, "802.11 5GHz configuration");
819
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5220, "802.11 5GHz configuration");
820
  }
821
      // modify cases 13 and 14 to avoid Config::SetDefault ()
822
  {
823
      // case 13
824
      WifiHelper wifi;
825
      wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
826
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
827
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
828
      phySta = GetYansWifiPhyPtr (staDevice);
829
      phySta->SetAttribute ("ChannelNumber", UintegerValue (44));
830
      // Post-install reconfiguration to channel width 40 MHz
831
      Config::Set ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/ChannelWidth", UintegerValue(40));
832
      // Although channel 44 is configured originally for 20 MHz, we
833
      // allow it to be used for 40 MHz here
834
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 44, "802.11 5GHz configuration");
835
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 40, "802.11 5GHz configuration");
836
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5220, "802.11 5GHz configuration");
837
  }
838
  {
839
      // case 14
840
      WifiHelper wifi;
841
      wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
842
      // Test that setting Frequency to a non-standard value will zero the
843
      // channel number
844
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
845
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
846
      phySta = GetYansWifiPhyPtr (staDevice);
847
      phySta->SetAttribute ("Frequency", UintegerValue (5281));
848
      // We expect channel number to be zero since frequency doesn't match
849
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 0, "802.11 5GHz configuration");
850
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
851
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5281, "802.11 5GHz configuration");
852
  }
853
  {
854
      // case 15:
855
      WifiHelper wifi;
856
      wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
857
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
858
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
859
      phySta = GetYansWifiPhyPtr (staDevice);
860
      // Test that setting Frequency to a standard value will set the
861
      // channel number correctly
862
      phySta->SetAttribute ("Frequency", UintegerValue (5500));
863
      // We expect channel number to be 100 due to frequency 5500
864
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 100, "802.11 5GHz configuration");
865
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
866
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5500, "802.11 5GHz configuration");
867
  }
868
  {
869
      // case 16:
870
      WifiHelper wifi;
871
      wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
872
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
873
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
874
      phySta = GetYansWifiPhyPtr (staDevice);
875
      // This case will error exit due to invalid channel number unless
876
      // we provide the DefineChannelNumber() below
877
      phySta->DefineChannelNumber (99, WIFI_PHY_STANDARD_80211n_5GHZ, 5185, 40);
878
      phySta->SetAttribute ("ChannelNumber", UintegerValue (99));
879
  }
880
  {
881
      // case 17:
882
      WifiHelper wifi;
883
      wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
884
      // Test how channel number behaves when frequency is non-standard
885
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
886
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
887
      phySta = GetYansWifiPhyPtr (staDevice);
888
      phySta->SetAttribute ("Frequency", UintegerValue (5181));
889
      // We expect channel number to be 0 due to unknown center frequency 5181
890
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 0, "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 (), 5181, "802.11 5GHz configuration");
893
      phySta->SetAttribute ("Frequency", UintegerValue (5180));
894
      // We expect channel number to be 36 due to known center frequency 5180
895
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 36, "802.11 5GHz configuration");
896
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
897
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5180, "802.11 5GHz configuration");
898
      phySta->SetAttribute ("Frequency", UintegerValue (5179));
899
      // We expect channel number to be 0 due to unknown center frequency 5179
900
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 0, "802.11 5GHz configuration");
901
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
902
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5179, "802.11 5GHz configuration");
903
      phySta->SetAttribute ("ChannelNumber", UintegerValue (36));
904
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 36, "802.11 5GHz configuration");
905
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
906
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5180, "802.11 5GHz configuration");
907
  }
908
  {
909
      // case 18:
910
      WifiHelper wifi;
911
      wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
912
      // Set both channel and frequency to consistent values
913
      wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
914
      staDevice = wifi.Install (phy, macSta, wifiStaNode.Get(0));
915
      phySta = GetYansWifiPhyPtr (staDevice);
916
      phySta->SetAttribute ("Frequency", UintegerValue (5200));
917
      phySta->SetAttribute ("ChannelNumber", UintegerValue (40));
918
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 40, "802.11 5GHz configuration");
919
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
920
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5200, "802.11 5GHz configuration");
921
      // Set both channel and frequency to inconsistent values
922
      phySta->SetAttribute ("Frequency", UintegerValue (5200));
923
      phySta->SetAttribute ("ChannelNumber", UintegerValue (36));
924
      // We expect channel number to be 36
925
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 36, "802.11 5GHz configuration");
926
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
927
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5180, "802.11 5GHz configuration");
928
      phySta->SetAttribute ("ChannelNumber", UintegerValue (36));
929
      phySta->SetAttribute ("Frequency", UintegerValue (5200));
930
      // We expect channel number to be 40
931
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 40, "802.11 5GHz configuration");
932
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
933
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5200, "802.11 5GHz configuration");
934
      phySta->SetAttribute ("Frequency", UintegerValue (5179));
935
      phySta->SetAttribute ("ChannelNumber", UintegerValue (36));
936
      // We expect channel number to be 36
937
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 36, "802.11 5GHz configuration");
938
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
939
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5180, "802.11 5GHz configuration");
940
      phySta->SetAttribute ("ChannelNumber", UintegerValue (36));
941
      phySta->SetAttribute ("Frequency", UintegerValue (5179));
942
      // We expect channel number to be 0
943
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 0, "802.11 5GHz configuration");
944
      NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
945
      NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5179, "802.11 5GHz configuration");
946
  }
947
948
Simulator::Destroy ();
949
950
}
951
621
//-----------------------------------------------------------------------------
952
//-----------------------------------------------------------------------------
622
class WifiTestSuite : public TestSuite
953
class WifiTestSuite : public TestSuite
623
{
954
{
 Lines 633-638    Link Here 
633
  AddTestCase (new InterferenceHelperSequenceTest, TestCase::QUICK); //Bug 991
964
  AddTestCase (new InterferenceHelperSequenceTest, TestCase::QUICK); //Bug 991
634
  AddTestCase (new Bug555TestCase, TestCase::QUICK); //Bug 555
965
  AddTestCase (new Bug555TestCase, TestCase::QUICK); //Bug 555
635
  AddTestCase (new Bug730TestCase, TestCase::QUICK); //Bug 730
966
  AddTestCase (new Bug730TestCase, TestCase::QUICK); //Bug 730
967
  AddTestCase (new SetChannelFrequencyTest, TestCase::QUICK);
636
}
968
}
637
969
638
static WifiTestSuite g_wifiTestSuite;
970
static WifiTestSuite g_wifiTestSuite;

Return to bug 2412