Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
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 hybrid aggregation feat ure works. | |
30 // Hybrid aggregation is the simultaneous use of MSDU and MPDU aggregation schem es. | |
31 // | |
32 // The throughput is obtained for a given number of aggregated MSDUs and MPDUs. | |
33 // The number of aggregated MSDUs and MPDUs can be chosen by the user through th e nMsdus and nMpdus attibutes, respectively. | |
34 // | |
35 // Example: ./waf --run "simple-hybrid-aggregation --nMsdus=3 --nMpdus=8" | |
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). | |
Tom Henderson
2015/03/21 16:57:11
can you add here some comments about what users sh
S. Deronne
2015/05/04 17:02:56
Some comments have been added.
| |
48 | |
49 using namespace ns3; | |
50 | |
51 NS_LOG_COMPONENT_DEFINE ("SimpleHybridAggregation"); | |
52 | |
53 int main (int argc, char *argv[]) | |
54 { | |
55 uint32_t payloadSize = 1472; //bytes | |
56 uint64_t simulationTime = 10; //seconds | |
57 uint32_t nMsdus = 1; | |
58 uint32_t nMpdus = 1; | |
59 bool enableRts = 0; | |
60 ···· | |
61 CommandLine cmd; | |
62 cmd.AddValue("nMsdus", "Number of aggregated MSDUs", nMsdus); //number of aggr egated MSDUs specified by the user | |
63 cmd.AddValue("nMpdus", "Number of aggregated MPDUs", nMpdus); //number of aggr egated MPDUs specified by the user | |
64 cmd.AddValue("payloadSize", "Payload size in bytes", payloadSize); | |
65 cmd.AddValue("enableRts", "Enable RTS/CTS", enableRts); | |
66 cmd.AddValue("simulationTime", "Simulation time in seconds", simulationTime); | |
67 cmd.Parse (argc, argv); | |
68 ···· | |
69 if(!enableRts) | |
70 Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", String Value ("999999")); | |
Tom Henderson
2015/03/21 16:57:11
I suggest to run 'utils/check-style.py -i -f examp
S. Deronne
2015/03/28 20:08:26
Done.
| |
71 else | |
72 Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", String Value ("0")); | |
73 ····· | |
74 Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", S tringValue ("990000")); | |
75 | |
76 NodeContainer wifiStaNode; | |
77 wifiStaNode.Create (1); | |
78 NodeContainer wifiApNode; | |
79 wifiApNode.Create(1); | |
80 | |
81 YansWifiChannelHelper channel = YansWifiChannelHelper::Default (); | |
82 YansWifiPhyHelper phy = YansWifiPhyHelper::Default (); | |
83 phy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO); | |
84 phy.SetChannel (channel.Create()); | |
85 | |
86 WifiHelper wifi = WifiHelper::Default (); | |
87 wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ); | |
88 wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", | |
89 "DataMode", StringValue("OfdmRate65MbpsBW20MHz") , | |
90 "ControlMode", StringValue("OfdmRate6_5MbpsBW20M Hz")); | |
91 HtWifiMacHelper mac = HtWifiMacHelper::Default (); | |
92 | |
93 Ssid ssid = Ssid ("simple-hybrid-aggregation"); | |
94 mac.SetType ("ns3::StaWifiMac", | |
95 "Ssid", SsidValue (ssid), | |
96 "ActiveProbing", BooleanValue (false)); | |
97 ···· | |
98 | |
99 //Enable hybrid aggregation at the STA side | |
Tom Henderson
2015/03/21 16:57:11
The API below looks a bit more complicated than it
S. Deronne
2015/05/04 17:02:56
Aggregation-related parameters are set per AC.
Thi
| |
100 if (nMpdus > 1) mac.SetBlockAckThresholdForAc (AC_BE, 2); | |
101 if(nMsdus > 0) | |
102 { | |
103 mac.SetMpduAggregatorForAc (AC_BE,"ns3::MpduStandardAggregator", | |
104 "MaxAmpduSize", UintegerValue (nMpdus*(nMs dus*(payloadSize+100)))); | |
105 } | |
106 else | |
107 { | |
108 mac.SetMpduAggregatorForAc (AC_BE,"ns3::MpduStandardAggregator", | |
109 "MaxAmpduSize", UintegerValue (nMpdus*(pay loadSize+200))); | |
110 } | |
111 mac.SetMpduAggregatorForAc (AC_BE,"ns3::MpduStandardAggregator", | |
112 "MaxAmpduSize", UintegerValue (nMpdus*(payloadSize +100))); | |
113 ···· | |
114 ·· | |
115 NetDeviceContainer staDevice; | |
116 staDevice = wifi.Install (phy, mac, wifiStaNode); | |
117 | |
118 mac.SetType ("ns3::ApWifiMac", | |
119 "Ssid", SsidValue (ssid), | |
120 "BeaconInterval", TimeValue (MicroSeconds(102400)), | |
121 "BeaconGeneration", BooleanValue (true)); | |
122 | |
123 //Enable hybrid aggregation at the AP side | |
124 if (nMpdus > 1) mac.SetBlockAckThresholdForAc (AC_BE, 2); | |
125 if(nMsdus > 0) | |
126 { | |
127 mac.SetMpduAggregatorForAc (AC_BE,"ns3::MpduStandardAggregator", | |
128 "MaxAmpduSize", UintegerValue (nMpdus*(nMs dus*(payloadSize+100)))); | |
129 } | |
130 else | |
131 { | |
132 mac.SetMpduAggregatorForAc (AC_BE,"ns3::MpduStandardAggregator", | |
133 "MaxAmpduSize", UintegerValue (nMpdus*(pay loadSize+200))); | |
134 } | |
135 mac.SetMpduAggregatorForAc (AC_BE,"ns3::MpduStandardAggregator", | |
136 "MaxAmpduSize", UintegerValue (nMpdus*(payloadSize +100))); | |
137 | |
138 NetDeviceContainer apDevice; | |
139 apDevice = wifi.Install (phy, mac, wifiApNode); | |
140 | |
141 /* Setting mobility model */ | |
142 MobilityHelper mobility; | |
143 Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> (); | |
144 | |
145 positionAlloc->Add (Vector (0.0, 0.0, 0.0)); | |
146 positionAlloc->Add (Vector (1.0, 0.0, 0.0)); | |
147 mobility.SetPositionAllocator (positionAlloc); | |
148 | |
149 mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); | |
150 | |
151 mobility.Install (wifiApNode); | |
152 mobility.Install (wifiStaNode); | |
153 | |
154 /* Internet stack*/ | |
155 InternetStackHelper stack; | |
156 stack.Install (wifiApNode); | |
157 stack.Install (wifiStaNode); | |
158 | |
159 Ipv4AddressHelper address; | |
160 | |
161 address.SetBase ("192.168.1.0", "255.255.255.0"); | |
162 Ipv4InterfaceContainer StaInterface; | |
163 StaInterface = address.Assign (staDevice); | |
164 Ipv4InterfaceContainer ApInterface; | |
165 ApInterface = address.Assign (apDevice); | |
166 · | |
167 /* Setting applications */ | |
168 UdpServerHelper myServer (9); | |
169 ApplicationContainer serverApp = myServer.Install (wifiStaNode.Get (0)); | |
170 serverApp.Start (Seconds (0.0)); | |
171 serverApp.Stop (Seconds (simulationTime+1)); | |
172 ······ | |
173 UdpClientHelper myClient (StaInterface.GetAddress (0), 9); | |
174 myClient.SetAttribute ("MaxPackets", UintegerValue (4294967295)); | |
175 myClient.SetAttribute ("Interval", TimeValue (Time ("0.00002"))); //packets/s | |
176 myClient.SetAttribute ("PacketSize", UintegerValue (payloadSize)); | |
177 ·············· | |
178 ApplicationContainer clientApp = myClient.Install (wifiApNode.Get (0)); | |
179 clientApp.Start (Seconds (1.0)); | |
180 clientApp.Stop (Seconds (simulationTime+1)); | |
181 ······ | |
182 Simulator::Stop (Seconds (simulationTime+1)); | |
183 | |
184 Simulator::Run (); | |
185 Simulator::Destroy (); | |
186 ······ | |
187 uint32_t totalPacketsThrough = DynamicCast<UdpServer>(serverApp.Get (0))->GetR eceived (); | |
188 double throughput = totalPacketsThrough*payloadSize*8/(simulationTime*1000000. 0); | |
189 std::cout << "Throughput: " << throughput << " Mbit/s" << '\n'; | |
190 ···· | |
191 return 0; | |
192 } | |
OLD | NEW |