examples/wireless/ht-wifi-network.cc
author Sébastien Deronne <sebastien.deronne@gmail.com>
Sat, 05 Sep 2015 13:33:43 +0200
changeset 11642 d5269b583f2a
parent 11640 8dfcbf71cb06
child 11643 eb0fc97dfd5b
permissions -rw-r--r--
Update documentation and extend functionnalities of ht and vht wifi examples
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10139
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
     1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
     2
/*
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
     3
 * Copyright (c) 2009 MIRKO BANCHI
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
     4
 *
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
11628
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
10139
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
     8
 *
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
    12
 * GNU General Public License for more details.
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
    13
 *
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
    17
 *
11197
e6c47334f36c improve ht-wifi-network example
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 10963
diff changeset
    18
 * Authors: Mirko Banchi <mk.banchi@gmail.com>
e6c47334f36c improve ht-wifi-network example
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 10963
diff changeset
    19
 *          Sebastien Deronne <sebastien.deronne@gmail.com>
10139
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
    20
 */
11642
d5269b583f2a Update documentation and extend functionnalities of ht and vht wifi examples
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11640
diff changeset
    21
10139
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
    22
#include "ns3/core-module.h"
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
    23
#include "ns3/network-module.h"
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
    24
#include "ns3/applications-module.h"
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
    25
#include "ns3/wifi-module.h"
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
    26
#include "ns3/mobility-module.h"
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
    27
#include "ns3/ipv4-global-routing-helper.h"
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
    28
#include "ns3/internet-module.h"
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
    29
11642
d5269b583f2a Update documentation and extend functionnalities of ht and vht wifi examples
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11640
diff changeset
    30
// This is a simple example in order to show how to configure an IEEE 802.11n Wi-Fi network.
10139
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
    31
//
11642
d5269b583f2a Update documentation and extend functionnalities of ht and vht wifi examples
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11640
diff changeset
    32
// It ouputs the UDP or TCP goodput for every VHT bitrate value, which depends on the MCS value (0 to 7), the
d5269b583f2a Update documentation and extend functionnalities of ht and vht wifi examples
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11640
diff changeset
    33
// channel width (20, 40, 80 or 160 MHz) and the guard interval (long or short). The PHY bitrate is constant
d5269b583f2a Update documentation and extend functionnalities of ht and vht wifi examples
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11640
diff changeset
    34
// over all the simulation run. The user can also specify the distance between the access point and the
d5269b583f2a Update documentation and extend functionnalities of ht and vht wifi examples
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11640
diff changeset
    35
// station: the larger the distance the smaller the goodput.
11197
e6c47334f36c improve ht-wifi-network example
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 10963
diff changeset
    36
//
11642
d5269b583f2a Update documentation and extend functionnalities of ht and vht wifi examples
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11640
diff changeset
    37
// The simulation assumes a single station in an infrastructure network:
11197
e6c47334f36c improve ht-wifi-network example
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 10963
diff changeset
    38
//
11642
d5269b583f2a Update documentation and extend functionnalities of ht and vht wifi examples
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11640
diff changeset
    39
//  STA     AP
d5269b583f2a Update documentation and extend functionnalities of ht and vht wifi examples
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11640
diff changeset
    40
//    *     *
d5269b583f2a Update documentation and extend functionnalities of ht and vht wifi examples
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11640
diff changeset
    41
//    |     |
d5269b583f2a Update documentation and extend functionnalities of ht and vht wifi examples
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11640
diff changeset
    42
//   n1     n2
10139
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
    43
//
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
    44
//Packets in this simulation aren't marked with a QosTag so they are considered
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
    45
//belonging to BestEffort Access Class (AC_BE).
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
    46
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
    47
using namespace ns3;
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
    48
11197
e6c47334f36c improve ht-wifi-network example
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 10963
diff changeset
    49
NS_LOG_COMPONENT_DEFINE ("ht-wifi-network");
10139
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
    50
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
    51
int main (int argc, char *argv[])
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
    52
{
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
    53
  bool udp = true;
11197
e6c47334f36c improve ht-wifi-network example
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 10963
diff changeset
    54
  double simulationTime = 10; //seconds
11642
d5269b583f2a Update documentation and extend functionnalities of ht and vht wifi examples
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11640
diff changeset
    55
  double distance = 1.0; //meters
d5269b583f2a Update documentation and extend functionnalities of ht and vht wifi examples
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11640
diff changeset
    56
  double frequency = 5.0; //whether 2.4 or 5.0 GHz
d5269b583f2a Update documentation and extend functionnalities of ht and vht wifi examples
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11640
diff changeset
    57
  
11197
e6c47334f36c improve ht-wifi-network example
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 10963
diff changeset
    58
  CommandLine cmd;
11642
d5269b583f2a Update documentation and extend functionnalities of ht and vht wifi examples
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11640
diff changeset
    59
  cmd.AddValue ("frequency", "Whether working in the 2.4 or 5.0 GHz band (other values gets rejected)", frequency);
d5269b583f2a Update documentation and extend functionnalities of ht and vht wifi examples
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11640
diff changeset
    60
  cmd.AddValue ("distance", "Distance in meters between the station and the access point", distance);
11197
e6c47334f36c improve ht-wifi-network example
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 10963
diff changeset
    61
  cmd.AddValue ("simulationTime", "Simulation time in seconds", simulationTime);
e6c47334f36c improve ht-wifi-network example
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 10963
diff changeset
    62
  cmd.AddValue ("udp", "UDP if set to 1, TCP otherwise", udp);
e6c47334f36c improve ht-wifi-network example
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 10963
diff changeset
    63
  cmd.Parse (argc,argv);
10139
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
    64
11628
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
    65
  std::cout << "MCS value" << "\t\t" << "Channel width" << "\t\t" << "short GI" << "\t\t" << "Throughput" << '\n';
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
    66
  for (int i = 0; i <= 7; i++) //MCS
11197
e6c47334f36c improve ht-wifi-network example
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 10963
diff changeset
    67
    {
11628
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
    68
      for (int j = 20; j <= 40; ) //channel width
11197
e6c47334f36c improve ht-wifi-network example
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 10963
diff changeset
    69
        {
11628
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
    70
          for (int k = 0; k < 2; k++) //GI: 0 and 1
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
    71
            {
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
    72
              uint32_t payloadSize; //1500 byte IP packet
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
    73
              if (udp)
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
    74
                {
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
    75
                  payloadSize = 1472; //bytes
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
    76
                }
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
    77
              else
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
    78
                {
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
    79
                  payloadSize = 1448; //bytes
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
    80
                  Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (payloadSize));
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
    81
                }
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
    82
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
    83
              NodeContainer wifiStaNode;
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
    84
              wifiStaNode.Create (1);
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
    85
              NodeContainer wifiApNode;
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
    86
              wifiApNode.Create (1);
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
    87
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
    88
              YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
    89
              YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
    90
              phy.SetChannel (channel.Create ());
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
    91
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
    92
              // Set guard interval
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
    93
              phy.Set ("ShortGuardEnabled", BooleanValue (k));
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
    94
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
    95
              WifiHelper wifi = WifiHelper::Default ();
11642
d5269b583f2a Update documentation and extend functionnalities of ht and vht wifi examples
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11640
diff changeset
    96
              if (frequency == 5.0)
d5269b583f2a Update documentation and extend functionnalities of ht and vht wifi examples
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11640
diff changeset
    97
                {
d5269b583f2a Update documentation and extend functionnalities of ht and vht wifi examples
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11640
diff changeset
    98
                  wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
d5269b583f2a Update documentation and extend functionnalities of ht and vht wifi examples
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11640
diff changeset
    99
                }
d5269b583f2a Update documentation and extend functionnalities of ht and vht wifi examples
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11640
diff changeset
   100
              else if (frequency == 2.4)
d5269b583f2a Update documentation and extend functionnalities of ht and vht wifi examples
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11640
diff changeset
   101
                {
d5269b583f2a Update documentation and extend functionnalities of ht and vht wifi examples
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11640
diff changeset
   102
                  wifi.SetStandard (WIFI_PHY_STANDARD_80211n_2_4GHZ);
d5269b583f2a Update documentation and extend functionnalities of ht and vht wifi examples
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11640
diff changeset
   103
                  Config::SetDefault ("ns3::LogDistancePropagationLossModel::ReferenceLoss", DoubleValue (40.046));
d5269b583f2a Update documentation and extend functionnalities of ht and vht wifi examples
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11640
diff changeset
   104
                }
d5269b583f2a Update documentation and extend functionnalities of ht and vht wifi examples
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11640
diff changeset
   105
              else
d5269b583f2a Update documentation and extend functionnalities of ht and vht wifi examples
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11640
diff changeset
   106
                {
d5269b583f2a Update documentation and extend functionnalities of ht and vht wifi examples
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11640
diff changeset
   107
                  std::cout<<"Wrong frequency value!"<<std::endl;
d5269b583f2a Update documentation and extend functionnalities of ht and vht wifi examples
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11640
diff changeset
   108
                  return 0;
d5269b583f2a Update documentation and extend functionnalities of ht and vht wifi examples
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11640
diff changeset
   109
                }
d5269b583f2a Update documentation and extend functionnalities of ht and vht wifi examples
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11640
diff changeset
   110
11628
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   111
              HtWifiMacHelper mac = HtWifiMacHelper::Default ();
11640
8dfcbf71cb06 Add helper to convert mcs values into datarate values
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11628
diff changeset
   112
              StringValue DataRate = HtWifiMacHelper::DataRateForMcs (i);
11628
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   113
              wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager","DataMode", DataRate,
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   114
                                            "ControlMode", DataRate);
11640
8dfcbf71cb06 Add helper to convert mcs values into datarate values
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11628
diff changeset
   115
                
8dfcbf71cb06 Add helper to convert mcs values into datarate values
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11628
diff changeset
   116
              Ssid ssid = Ssid ("ns3-80211n");
8dfcbf71cb06 Add helper to convert mcs values into datarate values
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11628
diff changeset
   117
11628
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   118
              mac.SetType ("ns3::StaWifiMac",
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   119
                           "Ssid", SsidValue (ssid),
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   120
                           "ActiveProbing", BooleanValue (false));
11197
e6c47334f36c improve ht-wifi-network example
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 10963
diff changeset
   121
11628
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   122
              NetDeviceContainer staDevice;
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   123
              staDevice = wifi.Install (phy, mac, wifiStaNode);
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   124
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   125
              mac.SetType ("ns3::ApWifiMac",
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   126
                           "Ssid", SsidValue (ssid));
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   127
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   128
              NetDeviceContainer apDevice;
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   129
              apDevice = wifi.Install (phy, mac, wifiApNode);
11197
e6c47334f36c improve ht-wifi-network example
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 10963
diff changeset
   130
11628
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   131
              // Set channel width
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   132
              Config::Set ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/ChannelWidth", UintegerValue (j));
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   133
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   134
              // mobility.
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   135
              MobilityHelper mobility;
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   136
              Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
11197
e6c47334f36c improve ht-wifi-network example
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 10963
diff changeset
   137
11628
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   138
              positionAlloc->Add (Vector (0.0, 0.0, 0.0));
11642
d5269b583f2a Update documentation and extend functionnalities of ht and vht wifi examples
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11640
diff changeset
   139
              positionAlloc->Add (Vector (distance, 0.0, 0.0));
11628
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   140
              mobility.SetPositionAllocator (positionAlloc);
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   141
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   142
              mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
11197
e6c47334f36c improve ht-wifi-network example
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 10963
diff changeset
   143
11628
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   144
              mobility.Install (wifiApNode);
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   145
              mobility.Install (wifiStaNode);
11197
e6c47334f36c improve ht-wifi-network example
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 10963
diff changeset
   146
11628
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   147
              /* Internet stack*/
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   148
              InternetStackHelper stack;
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   149
              stack.Install (wifiApNode);
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   150
              stack.Install (wifiStaNode);
10139
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
   151
11628
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   152
              Ipv4AddressHelper address;
11197
e6c47334f36c improve ht-wifi-network example
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 10963
diff changeset
   153
11628
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   154
              address.SetBase ("192.168.1.0", "255.255.255.0");
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   155
              Ipv4InterfaceContainer staNodeInterface;
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   156
              Ipv4InterfaceContainer apNodeInterface;
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   157
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   158
              staNodeInterface = address.Assign (staDevice);
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   159
              apNodeInterface = address.Assign (apDevice);
11197
e6c47334f36c improve ht-wifi-network example
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 10963
diff changeset
   160
11628
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   161
              /* Setting applications */
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   162
              ApplicationContainer serverApp, sinkApp;
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   163
              if (udp)
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   164
                {
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   165
                  //UDP flow
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   166
                  UdpServerHelper myServer (9);
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   167
                  serverApp = myServer.Install (wifiStaNode.Get (0));
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   168
                  serverApp.Start (Seconds (0.0));
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   169
                  serverApp.Stop (Seconds (simulationTime + 1));
10139
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
   170
11628
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   171
                  UdpClientHelper myClient (staNodeInterface.GetAddress (0), 9);
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   172
                  myClient.SetAttribute ("MaxPackets", UintegerValue (4294967295u));
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   173
                  myClient.SetAttribute ("Interval", TimeValue (Time ("0.00001"))); //packets/s
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   174
                  myClient.SetAttribute ("PacketSize", UintegerValue (payloadSize));
11197
e6c47334f36c improve ht-wifi-network example
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 10963
diff changeset
   175
11628
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   176
                  ApplicationContainer clientApp = myClient.Install (wifiApNode.Get (0));
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   177
                  clientApp.Start (Seconds (1.0));
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   178
                  clientApp.Stop (Seconds (simulationTime + 1));
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   179
                }
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   180
              else
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   181
                {
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   182
                  //TCP flow
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   183
                  uint16_t port = 50000;
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   184
                  Address apLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port));
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   185
                  PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", apLocalAddress);
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   186
                  sinkApp = packetSinkHelper.Install (wifiStaNode.Get (0));
11197
e6c47334f36c improve ht-wifi-network example
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 10963
diff changeset
   187
11628
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   188
                  sinkApp.Start (Seconds (0.0));
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   189
                  sinkApp.Stop (Seconds (simulationTime + 1));
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   190
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   191
                  OnOffHelper onoff ("ns3::TcpSocketFactory",Ipv4Address::GetAny ());
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   192
                  onoff.SetAttribute ("OnTime",  StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   193
                  onoff.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   194
                  onoff.SetAttribute ("PacketSize", UintegerValue (payloadSize));
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   195
                  onoff.SetAttribute ("DataRate", DataRateValue (1000000000)); //bit/s
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   196
                  ApplicationContainer apps;
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   197
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   198
                  AddressValue remoteAddress (InetSocketAddress (staNodeInterface.GetAddress (0), port));
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   199
                  onoff.SetAttribute ("Remote", remoteAddress);
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   200
                  apps.Add (onoff.Install (wifiApNode.Get (0)));
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   201
                  apps.Start (Seconds (1.0));
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   202
                  apps.Stop (Seconds (simulationTime + 1));
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   203
                }
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   204
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   205
              Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
10139
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
   206
11628
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   207
              Simulator::Stop (Seconds (simulationTime + 1));
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   208
              Simulator::Run ();
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   209
              Simulator::Destroy ();
10139
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
   210
11628
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   211
              double throughput = 0;
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   212
              if (udp)
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   213
                {
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   214
                  //UDP
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   215
                  uint32_t totalPacketsThrough = DynamicCast<UdpServer> (serverApp.Get (0))->GetReceived ();
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   216
                  throughput = totalPacketsThrough * payloadSize * 8 / (simulationTime * 1000000.0); //Mbit/s
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   217
                }
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   218
              else
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   219
                {
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   220
                  //TCP
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   221
                  uint32_t totalPacketsThrough = DynamicCast<PacketSink> (sinkApp.Get (0))->GetTotalRx ();
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   222
                  throughput = totalPacketsThrough * 8 / (simulationTime * 1000000.0); //Mbit/s
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   223
                }
11640
8dfcbf71cb06 Add helper to convert mcs values into datarate values
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11628
diff changeset
   224
              std::cout << i << "\t\t\t" << j << " MHz\t\t\t" << k << "\t\t\t" << throughput << " Mbit/s" << std::endl;
11628
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   225
            }
243b71de25a0 add support for IEEE 802.11ac
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 11235
diff changeset
   226
          j *= 2;
11197
e6c47334f36c improve ht-wifi-network example
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 10963
diff changeset
   227
        }
e6c47334f36c improve ht-wifi-network example
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 10963
diff changeset
   228
    }
10139
17a71cd49da3 partial 802.11n support
Ghada Badawy <gbadawy@gmail.com>
parents:
diff changeset
   229
  return 0;
11197
e6c47334f36c improve ht-wifi-network example
Sébastien Deronne <sebastien.deronne@gmail.com>
parents: 10963
diff changeset
   230
}