|
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 |
// The throughput is obtained for a given number of aggregated MPDUs. |
31 |
// |
32 |
// The number of aggregated MPDUs can be chosen by the user through the nMpdus attibute. |
33 |
// A value of 1 means that no MPDU aggregation is performed. |
34 |
// |
35 |
// Example: ./waf --run "simple-mpdu-aggregation --nMpdus=64" |
36 |
// |
37 |
// Network topology: |
38 |
// |
39 |
// Wifi 192.168.1.0 |
40 |
// |
41 |
// AP |
42 |
// * * |
43 |
// | | |
44 |
// n1 n2 |
45 |
// |
46 |
// Packets in this simulation aren't marked with a QosTag so they are considered |
47 |
// belonging to BestEffort Access Class (AC_BE). |
48 |
|
49 |
using namespace ns3; |
50 |
|
51 |
NS_LOG_COMPONENT_DEFINE ("SimpleMpduAggregation"); |
52 |
|
53 |
int main (int argc, char *argv[]) |
54 |
{ |
55 |
uint32_t payloadSize = 1472; //bytes |
56 |
uint64_t simulationTime = 10; //seconds |
57 |
uint32_t nMpdus = 1; |
58 |
bool enableRts = 0; |
59 |
|
60 |
CommandLine cmd; |
61 |
cmd.AddValue("nMpdus", "Number of aggregated MPDUs", nMpdus); //number of aggregated MPDUs specified by the user |
62 |
cmd.AddValue("payloadSize", "Payload size in bytes", payloadSize); |
63 |
cmd.AddValue("enableRts", "Enable RTS/CTS", enableRts); |
64 |
cmd.AddValue("simulationTime", "Simulation time in seconds", simulationTime); |
65 |
cmd.Parse (argc, argv); |
66 |
|
67 |
if(!enableRts) |
68 |
Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("999999")); |
69 |
else |
70 |
Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("0")); |
71 |
|
72 |
Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("990000")); |
73 |
|
74 |
NodeContainer wifiStaNode; |
75 |
wifiStaNode.Create (1); |
76 |
NodeContainer wifiApNode; |
77 |
wifiApNode.Create(1); |
78 |
|
79 |
YansWifiChannelHelper channel = YansWifiChannelHelper::Default (); |
80 |
YansWifiPhyHelper phy = YansWifiPhyHelper::Default (); |
81 |
phy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO); |
82 |
phy.SetChannel (channel.Create()); |
83 |
|
84 |
WifiHelper wifi = WifiHelper::Default (); |
85 |
wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ); |
86 |
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue("OfdmRate65MbpsBW20MHz"), "ControlMode", StringValue("OfdmRate6_5MbpsBW20MHz")); |
87 |
HtWifiMacHelper mac = HtWifiMacHelper::Default (); |
88 |
|
89 |
Ssid ssid = Ssid ("simple-mpdu-aggregation"); |
90 |
mac.SetType ("ns3::StaWifiMac", |
91 |
"Ssid", SsidValue (ssid), |
92 |
"ActiveProbing", BooleanValue (false)); |
93 |
|
94 |
if (nMpdus > 1) mac.SetBlockAckThresholdForAc (AC_BE, 2); //enable Block ACK when A-MPDU is enabled (i.e. nMpdus > 1) |
95 |
|
96 |
mac.SetMpduAggregatorForAc (AC_BE,"ns3::MpduStandardAggregator", |
97 |
"MaxAmpduSize", UintegerValue (nMpdus*(payloadSize+100))); //enable MPDU aggregation for AC_BE with a maximum aggregated size of nMpdus*(payloadSize+100) bytes, i.e. nMpdus aggregated packets in an A-MPDU |
98 |
|
99 |
NetDeviceContainer staDevice; |
100 |
staDevice = wifi.Install (phy, mac, wifiStaNode); |
101 |
|
102 |
mac.SetType ("ns3::ApWifiMac", |
103 |
"Ssid", SsidValue (ssid), |
104 |
"BeaconInterval", TimeValue (MicroSeconds(102400)), |
105 |
"BeaconGeneration", BooleanValue (true)); |
106 |
|
107 |
if (nMpdus > 1) mac.SetBlockAckThresholdForAc (AC_BE, 2); //enable Block ACK when A-MPDU is enabled (i.e. nMpdus > 1) |
108 |
|
109 |
mac.SetMpduAggregatorForAc (AC_BE,"ns3::MpduStandardAggregator", |
110 |
"MaxAmpduSize", UintegerValue (nMpdus*(payloadSize+100))); //enable MPDU aggregation for AC_BE with a maximum aggregated size of nMpdus*(payloadSize+100) bytes, i.e. nMpdus aggregated packets in an A-MPDU |
111 |
|
112 |
NetDeviceContainer apDevice; |
113 |
apDevice = wifi.Install (phy, mac, wifiApNode); |
114 |
|
115 |
/* Setting mobility model */ |
116 |
MobilityHelper mobility; |
117 |
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> (); |
118 |
|
119 |
positionAlloc->Add (Vector (0.0, 0.0, 0.0)); |
120 |
positionAlloc->Add (Vector (1.0, 0.0, 0.0)); |
121 |
mobility.SetPositionAllocator (positionAlloc); |
122 |
|
123 |
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); |
124 |
|
125 |
mobility.Install (wifiApNode); |
126 |
mobility.Install (wifiStaNode); |
127 |
|
128 |
/* Internet stack*/ |
129 |
InternetStackHelper stack; |
130 |
stack.Install (wifiApNode); |
131 |
stack.Install (wifiStaNode); |
132 |
|
133 |
Ipv4AddressHelper address; |
134 |
|
135 |
address.SetBase ("192.168.1.0", "255.255.255.0"); |
136 |
Ipv4InterfaceContainer StaInterface; |
137 |
StaInterface = address.Assign (staDevice); |
138 |
Ipv4InterfaceContainer ApInterface; |
139 |
ApInterface = address.Assign (apDevice); |
140 |
|
141 |
/* Setting applications */ |
142 |
UdpServerHelper myServer (9); |
143 |
ApplicationContainer serverApp = myServer.Install (wifiStaNode.Get (0)); |
144 |
serverApp.Start (Seconds (0.0)); |
145 |
serverApp.Stop (Seconds (simulationTime+1)); |
146 |
|
147 |
UdpClientHelper myClient (StaInterface.GetAddress (0), 9); |
148 |
myClient.SetAttribute ("MaxPackets", UintegerValue (4294967295)); |
149 |
myClient.SetAttribute ("Interval", TimeValue (Time ("0.00002"))); //packets/s |
150 |
myClient.SetAttribute ("PacketSize", UintegerValue (payloadSize)); |
151 |
|
152 |
ApplicationContainer clientApp = myClient.Install (wifiApNode.Get (0)); |
153 |
clientApp.Start (Seconds (1.0)); |
154 |
clientApp.Stop (Seconds (simulationTime+1)); |
155 |
|
156 |
Simulator::Stop (Seconds (simulationTime+1)); |
157 |
|
158 |
Simulator::Run (); |
159 |
Simulator::Destroy (); |
160 |
|
161 |
uint32_t totalPacketsThrough = DynamicCast<UdpServer>(serverApp.Get (0))->GetReceived (); |
162 |
double throughput = totalPacketsThrough*payloadSize*8/(simulationTime*1000000.0); |
163 |
std::cout << "Throughput: " << throughput << " Mbit/s" << '\n'; |
164 |
|
165 |
return 0; |
166 |
} |