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

(-)dd4acdd1a4ca (+319 lines)
Added Link Here 
1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License version 2 as
5
 * published by the Free Software Foundation;
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 *
16
 * Authors: Sébastien Deronne <sebastien.deronne@gmail.com>
17
 */
18
19
// This example is used to validate 802.11n MIMO.
20
//
21
// It ouputs plots of the throughput versus the distance
22
// for every HT MCS value and from 1 to 4 MIMO streams.
23
//
24
// The simulation assumes a single station in an infrastructure network:
25
//
26
//  STA     AP
27
//    *     *
28
//    |     |
29
//   n1     n2
30
//
31
// The user can choose whether UDP or TCP should be used and can configure
32
// some 802.11n parameters (frequency, channel width and guard interval).
33
34
#include "ns3/core-module.h"
35
#include "ns3/network-module.h"
36
#include "ns3/applications-module.h"
37
#include "ns3/wifi-module.h"
38
#include "ns3/mobility-module.h"
39
#include "ns3/ipv4-global-routing-helper.h"
40
#include "ns3/internet-module.h"
41
#include "ns3/gnuplot.h"
42
#include <fstream>
43
#include <vector>
44
#include <cmath>
45
46
using namespace ns3;
47
48
int main (int argc, char *argv[])
49
{
50
  std::ofstream file ("80211n-mimo-throughput.plt");
51
  
52
  std::vector <std::string> modes;
53
  modes.push_back ("HtMcs0");
54
  modes.push_back ("HtMcs1");
55
  modes.push_back ("HtMcs2");
56
  modes.push_back ("HtMcs3");
57
  modes.push_back ("HtMcs4");
58
  modes.push_back ("HtMcs5");
59
  modes.push_back ("HtMcs6");
60
  modes.push_back ("HtMcs7");
61
  modes.push_back ("HtMcs8");
62
  modes.push_back ("HtMcs9");
63
  modes.push_back ("HtMcs10");
64
  modes.push_back ("HtMcs11");
65
  modes.push_back ("HtMcs12");
66
  modes.push_back ("HtMcs13");
67
  modes.push_back ("HtMcs14");
68
  modes.push_back ("HtMcs15");
69
  modes.push_back ("HtMcs16");
70
  modes.push_back ("HtMcs17");
71
  modes.push_back ("HtMcs18");
72
  modes.push_back ("HtMcs19");
73
  modes.push_back ("HtMcs20");
74
  modes.push_back ("HtMcs21");
75
  modes.push_back ("HtMcs22");
76
  modes.push_back ("HtMcs23");
77
  modes.push_back ("HtMcs24");
78
  modes.push_back ("HtMcs25");
79
  modes.push_back ("HtMcs26");
80
  modes.push_back ("HtMcs27");
81
  modes.push_back ("HtMcs28");
82
  modes.push_back ("HtMcs29");
83
  modes.push_back ("HtMcs30");
84
  modes.push_back ("HtMcs31");
85
  
86
  bool udp = true;
87
  double simulationTime = 5; //seconds
88
  double frequency = 5.0; //whether 2.4 or 5.0 GHz
89
  double step = 5; //meters
90
  bool shortGuardInterval = false;
91
  bool channelBonding = false;
92
93
  CommandLine cmd;
94
  cmd.AddValue ("step", "Granularity of the results to be plotted in meters", step);
95
  cmd.AddValue ("channelBonding", "Enable/disable channel bonding (channel width = 20 MHz if false, channel width = 40 MHz if true)", channelBonding);
96
  cmd.AddValue ("shortGuardInterval", "Enable/disable short guard interval", shortGuardInterval);
97
  cmd.AddValue ("frequency", "Whether working in the 2.4 or 5.0 GHz band (other values gets rejected)", frequency);
98
  cmd.AddValue ("udp", "UDP if set to 1, TCP otherwise", udp);
99
  cmd.Parse (argc,argv);
100
101
  Gnuplot plot = Gnuplot ("80211n-mimo-throughput.eps");
102
103
  for (uint32_t i = 0; i < modes.size (); i++) //MCS
104
    {
105
      std::cout << modes[i] << std::endl;
106
      Gnuplot2dDataset dataset (modes[i]);
107
      for (int d = 0; d <= 100; ) //distance
108
        {
109
          std::cout << "Distance = " << d << "m: "<< std::endl;
110
          uint32_t payloadSize; //1500 byte IP packet
111
          if (udp)
112
            {
113
              payloadSize = 1472; //bytes
114
            }
115
          else
116
            {
117
              payloadSize = 1448; //bytes
118
              Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (payloadSize));
119
            }
120
              
121
          uint8_t nStreams = 1 + (i / 8); //number of MIMO streams
122
123
          NodeContainer wifiStaNode;
124
          wifiStaNode.Create (1);
125
          NodeContainer wifiApNode;
126
          wifiApNode.Create (1);
127
128
          YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
129
          YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
130
          phy.SetChannel (channel.Create ());
131
132
          // Set guard interval
133
          phy.Set ("ShortGuardEnabled", BooleanValue (shortGuardInterval));
134
          // Set MIMO capabilities
135
          phy.Set ("TxAntennas", UintegerValue (nStreams));
136
          phy.Set ("RxAntennas", UintegerValue (nStreams));
137
138
          WifiMacHelper mac;
139
          WifiHelper wifi;
140
          if (frequency == 5.0)
141
            {
142
              wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
143
            }
144
          else if (frequency == 2.4)
145
            {
146
              wifi.SetStandard (WIFI_PHY_STANDARD_80211n_2_4GHZ);
147
              Config::SetDefault ("ns3::LogDistancePropagationLossModel::ReferenceLoss", DoubleValue (40.046));
148
            }
149
          else
150
            {
151
              std::cout<<"Wrong frequency value!"<<std::endl;
152
              return 0;
153
            }
154
155
          wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager","DataMode", StringValue (modes[i]),
156
                                        "ControlMode", StringValue (modes[i]));
157
                
158
          Ssid ssid = Ssid ("ns3-80211n");
159
160
          mac.SetType ("ns3::StaWifiMac",
161
                       "Ssid", SsidValue (ssid),
162
                       "ActiveProbing", BooleanValue (false));
163
164
          NetDeviceContainer staDevice;
165
          staDevice = wifi.Install (phy, mac, wifiStaNode);
166
167
          mac.SetType ("ns3::ApWifiMac",
168
                       "Ssid", SsidValue (ssid));
169
170
          NetDeviceContainer apDevice;
171
          apDevice = wifi.Install (phy, mac, wifiApNode);
172
173
          // Set channel width
174
          if (channelBonding)
175
            {
176
              Config::Set ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/ChannelWidth", UintegerValue (40));
177
            }
178
179
          // mobility.
180
          MobilityHelper mobility;
181
          Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
182
183
          positionAlloc->Add (Vector (0.0, 0.0, 0.0));
184
          positionAlloc->Add (Vector (d, 0.0, 0.0));
185
          mobility.SetPositionAllocator (positionAlloc);
186
187
          mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
188
189
          mobility.Install (wifiApNode);
190
          mobility.Install (wifiStaNode);
191
192
          /* Internet stack*/
193
          InternetStackHelper stack;
194
          stack.Install (wifiApNode);
195
          stack.Install (wifiStaNode);
196
197
          Ipv4AddressHelper address;
198
199
          address.SetBase ("192.168.1.0", "255.255.255.0");
200
          Ipv4InterfaceContainer staNodeInterface;
201
          Ipv4InterfaceContainer apNodeInterface;
202
          
203
          staNodeInterface = address.Assign (staDevice);
204
          apNodeInterface = address.Assign (apDevice);
205
206
          /* Setting applications */
207
          ApplicationContainer serverApp, sinkApp;
208
          if (udp)
209
            {
210
              //UDP flow
211
              UdpServerHelper myServer (9);
212
              serverApp = myServer.Install (wifiStaNode.Get (0));
213
              serverApp.Start (Seconds (0.0));
214
              serverApp.Stop (Seconds (simulationTime + 1));
215
216
              UdpClientHelper myClient (staNodeInterface.GetAddress (0), 9);
217
              myClient.SetAttribute ("MaxPackets", UintegerValue (4294967295u));
218
              myClient.SetAttribute ("Interval", TimeValue (Time ("0.00001"))); //packets/s
219
              myClient.SetAttribute ("PacketSize", UintegerValue (payloadSize));
220
221
              ApplicationContainer clientApp = myClient.Install (wifiApNode.Get (0));
222
              clientApp.Start (Seconds (1.0));
223
              clientApp.Stop (Seconds (simulationTime + 1));
224
            }
225
          else
226
            {
227
              //TCP flow
228
              uint16_t port = 50000;
229
              Address apLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port));
230
              PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", apLocalAddress);
231
              sinkApp = packetSinkHelper.Install (wifiStaNode.Get (0));
232
233
              sinkApp.Start (Seconds (0.0));
234
              sinkApp.Stop (Seconds (simulationTime + 1));
235
236
              OnOffHelper onoff ("ns3::TcpSocketFactory",Ipv4Address::GetAny ());
237
              onoff.SetAttribute ("OnTime",  StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
238
              onoff.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
239
              onoff.SetAttribute ("PacketSize", UintegerValue (payloadSize));
240
              onoff.SetAttribute ("DataRate", DataRateValue (1000000000)); //bit/s
241
              ApplicationContainer apps;
242
243
              AddressValue remoteAddress (InetSocketAddress (staNodeInterface.GetAddress (0), port));
244
              onoff.SetAttribute ("Remote", remoteAddress);
245
              apps.Add (onoff.Install (wifiApNode.Get (0)));
246
              apps.Start (Seconds (1.0));
247
              apps.Stop (Seconds (simulationTime + 1));
248
            }
249
250
          Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
251
          
252
          Simulator::Stop (Seconds (simulationTime + 1));
253
          Simulator::Run ();
254
          Simulator::Destroy ();
255
256
          double throughput = 0;
257
          if (udp)
258
            {
259
              //UDP
260
              uint32_t totalPacketsThrough = DynamicCast<UdpServer> (serverApp.Get (0))->GetReceived ();
261
              throughput = totalPacketsThrough * payloadSize * 8 / (simulationTime * 1000000.0); //Mbit/s
262
            }
263
          else
264
            {
265
              //TCP
266
              uint32_t totalPacketsThrough = DynamicCast<PacketSink> (sinkApp.Get (0))->GetTotalRx ();
267
              throughput = totalPacketsThrough * 8 / (simulationTime * 1000000.0); //Mbit/s
268
            }
269
          dataset.Add (d, throughput);
270
          std::cout << throughput << " Mbit/s" <<std::endl;
271
          d += step;
272
        }
273
      plot.AddDataset (dataset);
274
    }
275
276
  plot.SetTerminal ("postscript eps color enh \"Times-BoldItalic\"");
277
  plot.SetLegend ("Distance (Meters)", "Throughput (Mbit/s)");
278
  plot.SetExtra  ("set xrange [0:100]\n\
279
set yrange [0:600]\n\
280
set ytics 0,50,600\n\
281
set style line 1 dashtype 1 linewidth 5\n\
282
set style line 2 dashtype 1 linewidth 5\n\
283
set style line 3 dashtype 1 linewidth 5\n\
284
set style line 4 dashtype 1 linewidth 5\n\
285
set style line 5 dashtype 1 linewidth 5\n\
286
set style line 6 dashtype 1 linewidth 5\n\
287
set style line 7 dashtype 1 linewidth 5\n\
288
set style line 8 dashtype 1 linewidth 5\n\
289
set style line 9 dashtype 2 linewidth 5\n\
290
set style line 10 dashtype 2 linewidth 5\n\
291
set style line 11 dashtype 2 linewidth 5\n\
292
set style line 12 dashtype 2 linewidth 5\n\
293
set style line 13 dashtype 2 linewidth 5\n\
294
set style line 14 dashtype 2 linewidth 5\n\
295
set style line 15 dashtype 2 linewidth 5\n\
296
set style line 16 dashtype 2 linewidth 5\n\
297
set style line 17 dashtype 3 linewidth 5\n\
298
set style line 18 dashtype 3 linewidth 5\n\
299
set style line 19 dashtype 3 linewidth 5\n\
300
set style line 20 dashtype 3 linewidth 5\n\
301
set style line 21 dashtype 3 linewidth 5\n\
302
set style line 22 dashtype 3 linewidth 5\n\
303
set style line 23 dashtype 3 linewidth 5\n\
304
set style line 24 dashtype 3 linewidth 5\n\
305
set style line 25 dashtype 4 linewidth 5\n\
306
set style line 26 dashtype 4 linewidth 5\n\
307
set style line 27 dashtype 4 linewidth 5\n\
308
set style line 28 dashtype 4 linewidth 5\n\
309
set style line 29 dashtype 4 linewidth 5\n\
310
set style line 30 dashtype 4 linewidth 5\n\
311
set style line 31 dashtype 4 linewidth 5\n\
312
set style line 32 dashtype 4 linewidth 5\n\
313
set style increment user"                                                                                                                                                                                                                                                                                                                                   );
314
  plot.GenerateOutput (file);
315
  file.close ();
316
317
  return 0;
318
}
319
(-)a/examples/wireless/wscript (+3 lines)
 Lines 79-83    Link Here 
79
    obj = bld.create_ns3_program('simple-ht-hidden-stations', ['internet', 'mobility', 'wifi', 'applications'])    
79
    obj = bld.create_ns3_program('simple-ht-hidden-stations', ['internet', 'mobility', 'wifi', 'applications'])    
80
    obj.source = 'simple-ht-hidden-stations.cc'
80
    obj.source = 'simple-ht-hidden-stations.cc'
81
81
82
    obj = bld.create_ns3_program('80211n-mimo', ['core','internet', 'mobility', 'wifi', 'applications', 'propagation'])
83
    obj.source = '80211n-mimo.cc'
84
82
    obj = bld.create_ns3_program('mixed-bg-network', ['internet', 'mobility', 'wifi', 'applications'])    
85
    obj = bld.create_ns3_program('mixed-bg-network', ['internet', 'mobility', 'wifi', 'applications'])    
83
    obj.source = 'mixed-bg-network.cc'
86
    obj.source = 'mixed-bg-network.cc'
(-)a/src/wifi/doc/source/wifi-design.rst (-4 / +5 lines)
 Lines 146-153    Link Here 
146
The physical layer and channel models operate on a per-packet basis, with
146
The physical layer and channel models operate on a per-packet basis, with
147
no frequency-selective propagation or interference effects.  Detailed
147
no frequency-selective propagation or interference effects.  Detailed
148
link simulations are not performed, nor are frequency-selective fading
148
link simulations are not performed, nor are frequency-selective fading
149
or interference models available.  Directional antennas and MIMO are also
149
or interference models available.  Directional antennas are also not
150
not supported at this time.  For additive white gaussian noise (AWGN) 
150
supported at this time.  For additive white gaussian noise (AWGN)
151
scenarios, or wideband interference scenarios, performance is governed
151
scenarios, or wideband interference scenarios, performance is governed
152
by the application of analytical models (based on modulation and factors
152
by the application of analytical models (based on modulation and factors
153
such as channel width) to the received signal-to-noise ratio, where noise
153
such as channel width) to the received signal-to-noise ratio, where noise
 Lines 155-162    Link Here 
155
packets.  Moreover, interference from other technologies is not modeled.
155
packets.  Moreover, interference from other technologies is not modeled.
156
The following details pertain to the physical layer and channel models:
156
The following details pertain to the physical layer and channel models:
157
157
158
* 802.11n MIMO is not supported
158
* 802.11n/ac MIMO currently uses the same 802.11n/ac SISO Yans and Nist error rate models
159
* 802.11n/ac MIMO is not supported
159
* 802.11ac MU-MIMO is not supported
160
* Antenna diversity is not supported
160
* 802.11n/ac beamforming is not supported
161
* 802.11n/ac beamforming is not supported
161
* PLCP preamble reception is not modeled
162
* PLCP preamble reception is not modeled
162
* PHY_RXSTART is not supported
163
* PHY_RXSTART is not supported
(-)a/src/wifi/doc/source/wifi-user.rst (+6 lines)
 Lines 117-122    Link Here 
117
117
118
 wifiPhyHelper.Set ("ShortGuardEnabled", BooleanValue(true));
118
 wifiPhyHelper.Set ("ShortGuardEnabled", BooleanValue(true));
119
119
120
In order to enable 802.11n/ac MIMO, the number of Rx antennas as well as the number of Tx antennas need to be configured.
121
For example, this code enables 2x2 MIMO::
122
123
 wifiPhyHelper.Set ("TxAntennas", UintegerValue (2));
124
 wifiPhyHelper.Set ("RxAntennas", UintegerValue (2));
125
120
Furthermore, 802.11n provides an optional mode (GreenField mode) to reduce preamble durations and which is only compatible with 802.11n devices. This mode is enabled as follows::
126
Furthermore, 802.11n provides an optional mode (GreenField mode) to reduce preamble durations and which is only compatible with 802.11n devices. This mode is enabled as follows::
121
127
122
 wifiPhyHelper.Set ("GreenfieldEnabled",BooleanValue(true));
128
 wifiPhyHelper.Set ("GreenfieldEnabled",BooleanValue(true));

Return to bug 2296