|
|
| 1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 |
/* |
| 3 |
* Copyright (c) 2015 Sébastien Deronne |
| 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: Sébastien Deronne <sebastien.deronne@gmail.com> |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "ns3/core-module.h" |
| 22 |
#include "ns3/network-module.h" |
| 23 |
#include "ns3/applications-module.h" |
| 24 |
#include "ns3/wifi-module.h" |
| 25 |
#include "ns3/mobility-module.h" |
| 26 |
#include "ns3/ipv4-global-routing-helper.h" |
| 27 |
#include "ns3/internet-module.h" |
| 28 |
|
| 29 |
//This is a simple example in order to show how 802.11n MPDU aggregation feature works. |
| 30 |
// |
| 31 |
//Network topology: |
| 32 |
// |
| 33 |
// Wifi 192.168.1.0 |
| 34 |
// |
| 35 |
// AP |
| 36 |
// * * |
| 37 |
// | | |
| 38 |
// n2 n3 |
| 39 |
// |
| 40 |
//Packets in this simulation aren't marked with a QosTag so they are considered |
| 41 |
//belonging to BestEffort Access Class (AC_BE). |
| 42 |
|
| 43 |
using namespace ns3; |
| 44 |
|
| 45 |
NS_LOG_COMPONENT_DEFINE ("SimpleMpduAggregation"); |
| 46 |
|
| 47 |
int main (int argc, char *argv[]) |
| 48 |
{ |
| 49 |
uint32_t payloadSize = 1472; //bytes |
| 50 |
uint64_t simulationTime = 10; //seconds |
| 51 |
bool enableRts = 0; |
| 52 |
|
| 53 |
CommandLine cmd; |
| 54 |
cmd.AddValue("payloadSize", "Payload size in bytes", payloadSize); |
| 55 |
cmd.AddValue("enableRts", "Enable RTS/CTS", enableRts); |
| 56 |
cmd.AddValue("simulationTime", "Simulation time in seconds", simulationTime); |
| 57 |
cmd.Parse (argc, argv); |
| 58 |
|
| 59 |
std::cout << "nMPDU" << "\t\tThroughput (Mbit/s)" << '\n'; |
| 60 |
|
| 61 |
for (int i = 0 ; i <= 6; i++) |
| 62 |
{ |
| 63 |
uint32_t nMpdu = std::pow(2,i); |
| 64 |
|
| 65 |
if(!enableRts) |
| 66 |
Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("999999")); |
| 67 |
else |
| 68 |
Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("0")); |
| 69 |
|
| 70 |
Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("990000")); |
| 71 |
|
| 72 |
NodeContainer wifiStaNode; |
| 73 |
wifiStaNode.Create (1); |
| 74 |
NodeContainer wifiApNode; |
| 75 |
wifiApNode.Create(1); |
| 76 |
|
| 77 |
YansWifiChannelHelper channel = YansWifiChannelHelper::Default (); |
| 78 |
YansWifiPhyHelper phy = YansWifiPhyHelper::Default (); |
| 79 |
phy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO); |
| 80 |
phy.SetChannel (channel.Create()); |
| 81 |
|
| 82 |
WifiHelper wifi = WifiHelper::Default (); |
| 83 |
wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ); |
| 84 |
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue("OfdmRate65MbpsBW20MHz"), "ControlMode", StringValue("OfdmRate6_5MbpsBW20MHz")); |
| 85 |
HtWifiMacHelper mac = HtWifiMacHelper::Default (); |
| 86 |
|
| 87 |
Ssid ssid = Ssid ("simple-mpdu-aggregation"); |
| 88 |
mac.SetType ("ns3::StaWifiMac", |
| 89 |
"Ssid", SsidValue (ssid), |
| 90 |
"ActiveProbing", BooleanValue (false)); |
| 91 |
|
| 92 |
if (nMpdu > 1) mac.SetBlockAckThresholdForAc (AC_BE, 2); |
| 93 |
|
| 94 |
mac.SetMpduAggregatorForAc (AC_BE,"ns3::MpduStandardAggregator", |
| 95 |
"MaxAmpduSize", UintegerValue (nMpdu*(payloadSize+100))); |
| 96 |
|
| 97 |
NetDeviceContainer staDevice; |
| 98 |
staDevice = wifi.Install (phy, mac, wifiStaNode); |
| 99 |
|
| 100 |
mac.SetType ("ns3::ApWifiMac", |
| 101 |
"Ssid", SsidValue (ssid), |
| 102 |
"BeaconInterval", TimeValue (MicroSeconds(102400)), |
| 103 |
"BeaconGeneration", BooleanValue (true)); |
| 104 |
|
| 105 |
if (nMpdu > 1) mac.SetBlockAckThresholdForAc (AC_BE, 2); |
| 106 |
|
| 107 |
mac.SetMpduAggregatorForAc (AC_BE,"ns3::MpduStandardAggregator", |
| 108 |
"MaxAmpduSize", UintegerValue (nMpdu*(payloadSize+100))); |
| 109 |
|
| 110 |
NetDeviceContainer apDevice; |
| 111 |
apDevice = wifi.Install (phy, mac, wifiApNode); |
| 112 |
|
| 113 |
MobilityHelper mobility; |
| 114 |
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> (); |
| 115 |
|
| 116 |
positionAlloc->Add (Vector (0.0, 0.0, 0.0)); |
| 117 |
positionAlloc->Add (Vector (1.0, 0.0, 0.0)); |
| 118 |
mobility.SetPositionAllocator (positionAlloc); |
| 119 |
|
| 120 |
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); |
| 121 |
|
| 122 |
mobility.Install (wifiApNode); |
| 123 |
mobility.Install (wifiStaNode); |
| 124 |
|
| 125 |
InternetStackHelper stack; |
| 126 |
stack.Install (wifiApNode); |
| 127 |
stack.Install (wifiStaNode); |
| 128 |
|
| 129 |
Ipv4AddressHelper address; |
| 130 |
|
| 131 |
address.SetBase ("192.168.1.0", "255.255.255.0"); |
| 132 |
Ipv4InterfaceContainer StaInterface; |
| 133 |
StaInterface = address.Assign (staDevice); |
| 134 |
Ipv4InterfaceContainer ApInterface; |
| 135 |
ApInterface = address.Assign (apDevice); |
| 136 |
|
| 137 |
UdpServerHelper myServer (9); |
| 138 |
ApplicationContainer serverApp = myServer.Install (wifiStaNode.Get (0)); |
| 139 |
serverApp.Start (Seconds (0.0)); |
| 140 |
serverApp.Stop (Seconds (simulationTime+1)); |
| 141 |
|
| 142 |
UdpClientHelper myClient (StaInterface.GetAddress (0), 9); |
| 143 |
myClient.SetAttribute ("MaxPackets", UintegerValue (4294967295)); |
| 144 |
myClient.SetAttribute ("Interval", TimeValue (Time ("0.00002"))); //packets/s |
| 145 |
myClient.SetAttribute ("PacketSize", UintegerValue (payloadSize)); |
| 146 |
|
| 147 |
ApplicationContainer clientApp = myClient.Install (wifiApNode.Get (0)); |
| 148 |
clientApp.Start (Seconds (1.0)); |
| 149 |
clientApp.Stop (Seconds (simulationTime+1)); |
| 150 |
|
| 151 |
Simulator::Stop (Seconds (simulationTime+1)); |
| 152 |
|
| 153 |
Simulator::Run (); |
| 154 |
Simulator::Destroy (); |
| 155 |
|
| 156 |
uint32_t totalPacketsThrough = DynamicCast<UdpServer>(serverApp.Get (0))->GetReceived (); |
| 157 |
double throughput = totalPacketsThrough*payloadSize*8/(simulationTime*1000000.0); |
| 158 |
|
| 159 |
std::cout << nMpdu << "\t\t" << throughput << '\n'; |
| 160 |
} |
| 161 |
return 0; |
| 162 |
} |