|
15 |
* along with this program; if not, write to the Free Software |
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 |
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 |
* |
17 |
* |
18 |
* Author: Mirko Banchi <mk.banchi@gmail.com> |
18 |
* Authors: Mirko Banchi <mk.banchi@gmail.com> |
|
|
19 |
* Sebastien Deronne <sebastien.deronne@gmail.com> |
19 |
*/ |
20 |
*/ |
20 |
#include "ns3/core-module.h" |
21 |
#include "ns3/core-module.h" |
21 |
#include "ns3/network-module.h" |
22 |
#include "ns3/network-module.h" |
|
25 |
#include "ns3/ipv4-global-routing-helper.h" |
26 |
#include "ns3/ipv4-global-routing-helper.h" |
26 |
#include "ns3/internet-module.h" |
27 |
#include "ns3/internet-module.h" |
27 |
|
28 |
|
28 |
//This is a simple example in order to show how 802.11n frame aggregation feature (A-MSDU) works. |
29 |
//This is a simple example of an IEEE 802.11n Wi-Fi network. |
29 |
// |
30 |
// |
30 |
//Network topology: |
31 |
//Network topology: |
31 |
// |
32 |
// |
32 |
// Wifi 192.168.1.0 |
33 |
// Wifi 192.168.1.0 |
33 |
// |
34 |
// |
34 |
// AP |
35 |
// AP |
35 |
// * * * |
36 |
// * * |
36 |
// | | | |
37 |
// | | |
37 |
// n1 n2 n3 |
38 |
// n1 n2 |
38 |
// |
39 |
// |
39 |
//Packets in this simulation aren't marked with a QosTag so they are considered |
40 |
//Packets in this simulation aren't marked with a QosTag so they are considered |
40 |
//belonging to BestEffort Access Class (AC_BE). |
41 |
//belonging to BestEffort Access Class (AC_BE). |
41 |
|
42 |
|
42 |
using namespace ns3; |
43 |
using namespace ns3; |
43 |
|
44 |
|
44 |
NS_LOG_COMPONENT_DEFINE ("DataRates"); |
45 |
NS_LOG_COMPONENT_DEFINE ("ht-wifi-network"); |
45 |
|
|
|
46 |
double rxBytessum=0; |
47 |
double throughput=0; |
48 |
|
49 |
|
50 |
//=========================================================================== |
51 |
//Set position of the nodes |
52 |
//=========================================================================== |
53 |
static void |
54 |
SetPosition (Ptr<Node> node, Vector position) |
55 |
{ |
56 |
Ptr<MobilityModel> mobility = node->GetObject<MobilityModel> (); |
57 |
mobility->SetPosition (position); |
58 |
} |
59 |
|
60 |
//========================================================================== |
61 |
//========================================================================== |
62 |
|
46 |
|
63 |
int main (int argc, char *argv[]) |
47 |
int main (int argc, char *argv[]) |
64 |
{ |
48 |
{ |
65 |
std::cout << "DataRate" <<" " << "Throughput" << '\n'; |
|
|
66 |
bool udp = true; |
49 |
bool udp = true; |
67 |
int i=2; |
50 |
double simulationTime = 10; //seconds |
68 |
for (;i <= 2; i++) |
51 |
CommandLine cmd; |
69 |
{ |
52 |
cmd.AddValue ("simulationTime", "Simulation time in seconds", simulationTime); |
70 |
uint32_t nWifi = 1; |
53 |
cmd.AddValue ("udp", "UDP if set to 1, TCP otherwise", udp); |
71 |
CommandLine cmd; |
54 |
cmd.Parse (argc,argv); |
72 |
cmd.AddValue ("nWifi", "Number of wifi STA devices", nWifi); |
|
|
73 |
cmd.Parse (argc,argv); |
74 |
Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("990000")); |
75 |
// disable rts cts all the time. |
76 |
Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("99000")); |
77 |
NodeContainer wifiNodes; |
78 |
wifiNodes.Create (1); |
79 |
NodeContainer wifiApNode; |
80 |
wifiApNode.Create (1); |
81 |
|
82 |
YansWifiChannelHelper channel = YansWifiChannelHelper::Default (); |
83 |
YansWifiPhyHelper phy = YansWifiPhyHelper::Default (); |
84 |
phy.SetChannel (channel.Create ()); |
85 |
if (i ==3 || i == 4) |
86 |
phy.Set ("ShortGuardEnabled",BooleanValue(true)); |
87 |
//phy.Set ("GreenfieldEnabled",BooleanValue(true)); |
88 |
|
55 |
|
89 |
WifiHelper wifi = WifiHelper::Default (); |
56 |
std::cout << "DataRate" << "\t" << "Throughput" << '\n'; |
90 |
wifi.SetStandard (WIFI_PHY_STANDARD_80211n_2_4GHZ); |
57 |
for (int mcs = 0; mcs <= 31; mcs++) |
91 |
HtWifiMacHelper mac = HtWifiMacHelper::Default (); |
58 |
{ |
92 |
|
59 |
uint32_t payloadSize; //1500 byte IP packet |
|
|
60 |
if (udp) |
61 |
{ |
62 |
payloadSize = 1472; //bytes |
63 |
} |
64 |
else |
65 |
{ |
66 |
payloadSize = 1448; //bytes |
67 |
Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (payloadSize)); |
68 |
} |
93 |
|
69 |
|
94 |
Ssid ssid = Ssid ("ns380211n"); |
70 |
NodeContainer wifiStaNode; |
95 |
double datarate = 0; |
71 |
wifiStaNode.Create (1); |
96 |
StringValue DataRate; |
72 |
NodeContainer wifiApNode; |
97 |
if (i==0) |
73 |
wifiApNode.Create (1); |
98 |
{ |
|
|
99 |
DataRate = StringValue("OfdmRate6_5MbpsBW20MHz"); |
100 |
datarate = 6.5; |
101 |
} |
102 |
else if (i==1) |
103 |
{ |
104 |
DataRate = StringValue("OfdmRate58_5MbpsBW20MHz"); |
105 |
datarate = 58.5; |
106 |
} |
107 |
else if (i == 2) |
108 |
{ |
109 |
DataRate = StringValue("OfdmRate65MbpsBW20MHz"); |
110 |
datarate = 65; |
111 |
} |
112 |
else if (i == 3) |
113 |
{ |
114 |
DataRate = StringValue("OfdmRate57_8MbpsBW20MHz"); |
115 |
datarate = 57.8; |
116 |
} |
117 |
else if (i == 4) |
118 |
{ |
119 |
DataRate = StringValue("OfdmRate72_2MbpsBW20MHz"); |
120 |
datarate = 72.2; |
121 |
} |
122 |
|
74 |
|
123 |
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager","DataMode", DataRate, |
75 |
YansWifiChannelHelper channel = YansWifiChannelHelper::Default (); |
124 |
"ControlMode", DataRate); |
76 |
YansWifiPhyHelper phy = YansWifiPhyHelper::Default (); |
125 |
mac.SetType ("ns3::StaWifiMac", |
77 |
phy.SetChannel (channel.Create ()); |
126 |
"Ssid", SsidValue (ssid), |
|
|
127 |
"ActiveProbing", BooleanValue (false)); |
128 |
|
129 |
NetDeviceContainer staDevices; |
130 |
staDevices = wifi.Install (phy, mac, wifiNodes); |
131 |
|
78 |
|
132 |
mac.SetType ("ns3::ApWifiMac", |
79 |
if (mcs <= 7) |
133 |
"Ssid", SsidValue (ssid)); |
80 |
{ |
134 |
|
81 |
phy.Set ("ShortGuardEnabled", BooleanValue (false)); |
135 |
NetDeviceContainer apDevice; |
82 |
phy.Set ("ChannelBonding", BooleanValue (false)); |
136 |
apDevice = wifi.Install (phy, mac, wifiApNode); |
83 |
} |
137 |
/* Ptr<WifiRemoteStationManager> apStationManager = |
84 |
else if (mcs > 7 && mcs <= 15) |
138 |
DynamicCast<WifiNetDevice>(apDevice.Get (0))->GetRemoteStationManager (); |
85 |
{ |
139 |
apStationManager->AddBasicMode (WifiMode ("OfdmRate13MbpsBW20MHz")); |
86 |
phy.Set ("ShortGuardEnabled", BooleanValue (true)); |
140 |
apStationManager->AddBasicMode (WifiMode ("OfdmRate19_5MbpsBW20MHz")); |
87 |
phy.Set ("ChannelBonding", BooleanValue (false)); |
141 |
apStationManager->AddBasicMode (WifiMode ("OfdmRate26MbpsBW20MHz")); |
88 |
} |
142 |
apStationManager->AddBasicMode (WifiMode ("OfdmRate39MbpsBW20MHz")); |
89 |
else if (mcs > 15 && mcs <= 23) |
143 |
Ptr<WifiRemoteStationManager> staStationManager = |
90 |
{ |
144 |
DynamicCast<WifiNetDevice> (staDevices.Get (0))->GetRemoteStationManager (); |
91 |
phy.Set ("ShortGuardEnabled", BooleanValue (false)); |
145 |
staStationManager->AddBasicMode (WifiMode ("OfdmRate13MbpsBW20MHz")); |
92 |
phy.Set ("ChannelBonding", BooleanValue (true)); |
146 |
staStationManager->AddBasicMode (WifiMode ("OfdmRate19_5MbpsBW20MHz")); |
93 |
} |
147 |
staStationManager->AddBasicMode (WifiMode ("OfdmRate26MbpsBW20MHz")); |
94 |
else |
148 |
staStationManager->AddBasicMode (WifiMode ("OfdmRate39MbpsBW20MHz"));*/ |
95 |
{ |
149 |
|
96 |
phy.Set ("ShortGuardEnabled", BooleanValue (true)); |
150 |
// mobility. |
97 |
phy.Set ("ChannelBonding", BooleanValue (true)); |
151 |
MobilityHelper mobility; |
98 |
} |
152 |
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); |
|
|
153 |
mobility.Install (wifiNodes); |
154 |
mobility.Install (wifiApNode); |
155 |
|
156 |
SetPosition (wifiNodes.Get(0), Vector (1.0,0.0,0.0)); |
157 |
SetPosition (wifiApNode.Get(0), Vector (0.0,0.0,0.0)); |
158 |
|
159 |
|
99 |
|
160 |
/* Internet stack*/ |
100 |
WifiHelper wifi = WifiHelper::Default (); |
161 |
InternetStackHelper stack; |
101 |
wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ); |
162 |
stack.Install (wifiApNode); |
102 |
HtWifiMacHelper mac = HtWifiMacHelper::Default (); |
163 |
stack.Install (wifiNodes); |
|
|
164 |
|
103 |
|
165 |
Ipv4AddressHelper address; |
104 |
Ssid ssid = Ssid ("ns380211n"); |
166 |
|
105 |
|
167 |
address.SetBase ("10.1.3.0", "255.255.255.0"); |
106 |
double datarate = 0; |
168 |
Ipv4InterfaceContainer wifiNodesInterfaces; |
107 |
StringValue DataRate; |
169 |
Ipv4InterfaceContainer apNodeInterface; |
108 |
if (mcs == 0) |
|
|
109 |
{ |
110 |
DataRate = StringValue ("OfdmRate6_5MbpsBW20MHz"); |
111 |
datarate = 6.5; |
112 |
} |
113 |
else if (mcs == 1) |
114 |
{ |
115 |
DataRate = StringValue ("OfdmRate13MbpsBW20MHz"); |
116 |
datarate = 13; |
117 |
} |
118 |
else if (mcs == 2) |
119 |
{ |
120 |
DataRate = StringValue ("OfdmRate19_5MbpsBW20MHz"); |
121 |
datarate = 19.5; |
122 |
} |
123 |
else if (mcs == 3) |
124 |
{ |
125 |
DataRate = StringValue ("OfdmRate26MbpsBW20MHz"); |
126 |
datarate = 26; |
127 |
} |
128 |
else if (mcs == 4) |
129 |
{ |
130 |
DataRate = StringValue ("OfdmRate39MbpsBW20MHz"); |
131 |
datarate = 39; |
132 |
} |
133 |
else if (mcs == 5) |
134 |
{ |
135 |
DataRate = StringValue ("OfdmRate52MbpsBW20MHz"); |
136 |
datarate = 52; |
137 |
} |
138 |
else if (mcs == 6) |
139 |
{ |
140 |
DataRate = StringValue ("OfdmRate58_5MbpsBW20MHz"); |
141 |
datarate = 58.5; |
142 |
} |
143 |
else if (mcs == 7) |
144 |
{ |
145 |
DataRate = StringValue ("OfdmRate65MbpsBW20MHz"); |
146 |
datarate = 65; |
147 |
} |
148 |
else if (mcs == 8) |
149 |
{ |
150 |
DataRate = StringValue ("OfdmRate7_2MbpsBW20MHz"); |
151 |
datarate = 7.2; |
152 |
} |
153 |
else if (mcs == 9) |
154 |
{ |
155 |
DataRate = StringValue ("OfdmRate14_4MbpsBW20MHz"); |
156 |
datarate = 14.4; |
157 |
} |
158 |
else if (mcs == 10) |
159 |
{ |
160 |
DataRate = StringValue ("OfdmRate21_7MbpsBW20MHz"); |
161 |
datarate = 21.7; |
162 |
} |
163 |
else if (mcs == 11) |
164 |
{ |
165 |
DataRate = StringValue ("OfdmRate28_9MbpsBW20MHz"); |
166 |
datarate = 28.9; |
167 |
} |
168 |
else if (mcs == 12) |
169 |
{ |
170 |
DataRate = StringValue ("OfdmRate43_3MbpsBW20MHz"); |
171 |
datarate = 43.3; |
172 |
} |
173 |
else if (mcs == 13) |
174 |
{ |
175 |
DataRate = StringValue ("OfdmRate57_8MbpsBW20MHz"); |
176 |
datarate = 57.8; |
177 |
} |
178 |
else if (mcs == 14) |
179 |
{ |
180 |
DataRate = StringValue ("OfdmRate65MbpsBW20MHzShGi"); |
181 |
datarate = 65; |
182 |
} |
183 |
else if (mcs == 15) |
184 |
{ |
185 |
DataRate = StringValue ("OfdmRate72_2MbpsBW20MHz"); |
186 |
datarate = 72.2; |
187 |
} |
188 |
else if (mcs == 16) |
189 |
{ |
190 |
DataRate = StringValue ("OfdmRate13_5MbpsBW40MHz"); |
191 |
datarate = 13.5; |
192 |
} |
193 |
else if (mcs == 17) |
194 |
{ |
195 |
DataRate = StringValue ("OfdmRate27MbpsBW40MHz"); |
196 |
datarate = 27; |
197 |
} |
198 |
else if (mcs == 18) |
199 |
{ |
200 |
DataRate = StringValue ("OfdmRate40_5MbpsBW40MHz"); |
201 |
datarate = 40.5; |
202 |
} |
203 |
else if (mcs == 19) |
204 |
{ |
205 |
DataRate = StringValue ("OfdmRate54MbpsBW40MHz"); |
206 |
datarate = 54; |
207 |
} |
208 |
else if (mcs == 20) |
209 |
{ |
210 |
DataRate = StringValue ("OfdmRate81MbpsBW40MHz"); |
211 |
datarate = 81; |
212 |
} |
213 |
else if (mcs == 21) |
214 |
{ |
215 |
DataRate = StringValue ("OfdmRate108MbpsBW40MHz"); |
216 |
datarate = 108; |
217 |
} |
218 |
else if (mcs == 22) |
219 |
{ |
220 |
DataRate = StringValue ("OfdmRate121_5MbpsBW40MHz"); |
221 |
datarate = 121.5; |
222 |
} |
223 |
else if (mcs == 23) |
224 |
{ |
225 |
DataRate = StringValue ("OfdmRate135MbpsBW40MHz"); |
226 |
datarate = 135; |
227 |
} |
228 |
else if (mcs == 24) |
229 |
{ |
230 |
DataRate = StringValue ("OfdmRate15MbpsBW40MHz"); |
231 |
datarate = 15; |
232 |
} |
233 |
else if (mcs == 25) |
234 |
{ |
235 |
DataRate = StringValue ("OfdmRate30MbpsBW40MHz"); |
236 |
datarate = 30; |
237 |
} |
238 |
else if (mcs == 26) |
239 |
{ |
240 |
DataRate = StringValue ("OfdmRate45MbpsBW40MHz"); |
241 |
datarate = 45; |
242 |
} |
243 |
else if (mcs == 27) |
244 |
{ |
245 |
DataRate = StringValue ("OfdmRate60MbpsBW40MHz"); |
246 |
datarate = 60; |
247 |
} |
248 |
else if (mcs == 28) |
249 |
{ |
250 |
DataRate = StringValue ("OfdmRate90MbpsBW40MHz"); |
251 |
datarate = 90; |
252 |
} |
253 |
else if (mcs == 29) |
254 |
{ |
255 |
DataRate = StringValue ("OfdmRate120MbpsBW40MHz"); |
256 |
datarate = 120; |
257 |
} |
258 |
else if (mcs == 30) |
259 |
{ |
260 |
DataRate = StringValue ("OfdmRate135MbpsBW40MHzShGi"); |
261 |
datarate = 135; |
262 |
} |
263 |
else |
264 |
{ |
265 |
DataRate = StringValue ("OfdmRate150MbpsBW40MHz"); |
266 |
datarate = 150; |
267 |
} |
170 |
|
268 |
|
171 |
wifiNodesInterfaces = address.Assign (staDevices); |
269 |
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager","DataMode", DataRate, |
172 |
apNodeInterface = address.Assign (apDevice); |
270 |
"ControlMode", DataRate); |
|
|
271 |
mac.SetType ("ns3::StaWifiMac", |
272 |
"Ssid", SsidValue (ssid), |
273 |
"ActiveProbing", BooleanValue (false)); |
173 |
|
274 |
|
174 |
ApplicationContainer serverApps,sink1App; |
275 |
NetDeviceContainer staDevice; |
|
|
276 |
staDevice = wifi.Install (phy, mac, wifiStaNode); |
175 |
|
277 |
|
176 |
double t=10; |
278 |
mac.SetType ("ns3::ApWifiMac", |
|
|
279 |
"Ssid", SsidValue (ssid)); |
177 |
|
280 |
|
178 |
/* Setting applications */ |
281 |
NetDeviceContainer apDevice; |
179 |
if (udp) |
282 |
apDevice = wifi.Install (phy, mac, wifiApNode); |
180 |
{ |
|
|
181 |
UdpServerHelper myServer (9); |
182 |
serverApps = myServer.Install (wifiNodes.Get (0)); |
183 |
serverApps.Start (Seconds (0.0)); |
184 |
serverApps.Stop (Seconds (t)); |
185 |
|
283 |
|
186 |
UdpClientHelper myClient (wifiNodesInterfaces.GetAddress (0), 9); |
284 |
// mobility. |
187 |
myClient.SetAttribute ("MaxPackets", UintegerValue (64707202)); |
285 |
MobilityHelper mobility; |
188 |
myClient.SetAttribute ("Interval", TimeValue (Time ("0.00002"))); |
286 |
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> (); |
189 |
myClient.SetAttribute ("PacketSize", UintegerValue (1500)); |
|
|
190 |
|
191 |
ApplicationContainer clientApps = myClient.Install (wifiApNode.Get (0)); |
192 |
clientApps.Start (Seconds (0.0)); |
193 |
clientApps.Stop (Seconds (t)); |
194 |
} |
195 |
else |
196 |
{ |
197 |
|
287 |
|
198 |
//TCP flow |
288 |
positionAlloc->Add (Vector (0.0, 0.0, 0.0)); |
199 |
uint16_t port = 50000; |
289 |
positionAlloc->Add (Vector (1.0, 0.0, 0.0)); |
200 |
Address apLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port)); |
290 |
mobility.SetPositionAllocator (positionAlloc); |
201 |
PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", apLocalAddress); |
|
|
202 |
sink1App = packetSinkHelper.Install (wifiNodes.Get (0)); |
203 |
|
291 |
|
204 |
sink1App.Start (Seconds (0.0)); |
292 |
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); |
205 |
sink1App.Stop (Seconds (t)); |
|
|
206 |
|
207 |
OnOffHelper onoff ("ns3::TcpSocketFactory",Ipv4Address::GetAny ()); |
208 |
onoff.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=30.0]")); //in seconds |
209 |
onoff.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0.0]")); |
210 |
onoff.SetAttribute ("PacketSize", UintegerValue (1500-30));//1024 |
211 |
onoff.SetAttribute ("DataRate", DataRateValue (100000000));//51200 |
212 |
ApplicationContainer apps; |
213 |
|
293 |
|
214 |
AddressValue remoteAddress (InetSocketAddress (wifiNodesInterfaces.GetAddress(0), port)); |
294 |
mobility.Install (wifiApNode); |
215 |
onoff.SetAttribute ("Remote", remoteAddress); |
295 |
mobility.Install (wifiStaNode); |
216 |
apps.Add (onoff.Install (wifiApNode.Get (0))); |
|
|
217 |
apps.Start (Seconds (0.0)); |
218 |
apps.Stop (Seconds (t)); |
219 |
} |
220 |
|
296 |
|
221 |
|
297 |
/* Internet stack*/ |
222 |
Ipv4GlobalRoutingHelper::PopulateRoutingTables (); |
298 |
InternetStackHelper stack; |
|
|
299 |
stack.Install (wifiApNode); |
300 |
stack.Install (wifiStaNode); |
223 |
|
301 |
|
224 |
Simulator::Stop (Seconds (t)); |
302 |
Ipv4AddressHelper address; |
225 |
Simulator::Run (); |
|
|
226 |
Simulator::Destroy (); |
227 |
|
303 |
|
228 |
//UDP |
304 |
address.SetBase ("192.168.1.0", "255.255.255.0"); |
229 |
if (udp) |
305 |
Ipv4InterfaceContainer staNodeInterface; |
230 |
{ |
306 |
Ipv4InterfaceContainer apNodeInterface; |
231 |
uint32_t totalPacketsThrough = DynamicCast<UdpServer>(serverApps.Get (0))->GetReceived (); |
307 |
|
232 |
throughput=totalPacketsThrough*1500*8/(t*1000000.0); |
308 |
staNodeInterface = address.Assign (staDevice); |
233 |
} |
309 |
apNodeInterface = address.Assign (apDevice); |
234 |
else |
310 |
|
235 |
{ |
311 |
/* Setting applications */ |
236 |
//TCP |
312 |
ApplicationContainer serverApp, sinkApp; |
237 |
uint32_t totalPacketsThrough = DynamicCast<PacketSink>(sink1App.Get (0))->GetTotalRx (); |
313 |
if (udp) |
238 |
throughput=totalPacketsThrough*8/((t-3)*1000000.0); |
314 |
{ |
239 |
} |
315 |
//UDP flow |
240 |
|
316 |
UdpServerHelper myServer (9); |
241 |
std::cout << datarate <<" " << throughput << '\n'; |
317 |
serverApp = myServer.Install (wifiStaNode.Get (0)); |
242 |
} |
318 |
serverApp.Start (Seconds (0.0)); |
|
|
319 |
serverApp.Stop (Seconds (simulationTime+1)); |
320 |
|
321 |
UdpClientHelper myClient (staNodeInterface.GetAddress (0), 9); |
322 |
myClient.SetAttribute ("MaxPackets", UintegerValue (4294967295)); |
323 |
myClient.SetAttribute ("Interval", TimeValue (Time ("0.00002"))); //packets/s |
324 |
myClient.SetAttribute ("PacketSize", UintegerValue (payloadSize)); |
325 |
|
326 |
ApplicationContainer clientApp = myClient.Install (wifiApNode.Get (0)); |
327 |
clientApp.Start (Seconds (1.0)); |
328 |
clientApp.Stop (Seconds (simulationTime+1)); |
329 |
} |
330 |
else |
331 |
{ |
332 |
//TCP flow |
333 |
uint16_t port = 50000; |
334 |
Address apLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port)); |
335 |
PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", apLocalAddress); |
336 |
sinkApp = packetSinkHelper.Install (wifiStaNode.Get (0)); |
337 |
|
338 |
sinkApp.Start (Seconds (0.0)); |
339 |
sinkApp.Stop (Seconds (simulationTime+1)); |
340 |
|
341 |
OnOffHelper onoff ("ns3::TcpSocketFactory",Ipv4Address::GetAny ()); |
342 |
onoff.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]")); |
343 |
onoff.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]")); |
344 |
onoff.SetAttribute ("PacketSize", UintegerValue (payloadSize)); |
345 |
onoff.SetAttribute ("DataRate", DataRateValue (1000000000)); //bit/s |
346 |
ApplicationContainer apps; |
347 |
|
348 |
AddressValue remoteAddress (InetSocketAddress (staNodeInterface.GetAddress (0), port)); |
349 |
onoff.SetAttribute ("Remote", remoteAddress); |
350 |
apps.Add (onoff.Install (wifiApNode.Get (0))); |
351 |
apps.Start (Seconds (1.0)); |
352 |
apps.Stop (Seconds (simulationTime+1)); |
353 |
} |
354 |
|
355 |
Ipv4GlobalRoutingHelper::PopulateRoutingTables (); |
356 |
|
357 |
Simulator::Stop (Seconds (simulationTime+1)); |
358 |
Simulator::Run (); |
359 |
Simulator::Destroy (); |
360 |
|
361 |
double throughput = 0; |
362 |
if (udp) |
363 |
{ |
364 |
//UDP |
365 |
uint32_t totalPacketsThrough = DynamicCast<UdpServer> (serverApp.Get (0))->GetReceived (); |
366 |
throughput = totalPacketsThrough * payloadSize * 8 / (simulationTime * 1000000.0); //Mbit/s |
367 |
} |
368 |
else |
369 |
{ |
370 |
//TCP |
371 |
uint32_t totalPacketsThrough = DynamicCast<PacketSink> (sinkApp.Get (0))->GetTotalRx (); |
372 |
throughput = totalPacketsThrough * 8 / (simulationTime * 1000000.0); //Mbit/s |
373 |
} |
374 |
std::cout << datarate << "\t\t" << throughput << " Mbit/s" << std::endl; |
375 |
} |
243 |
return 0; |
376 |
return 0; |
244 |
} |
377 |
} |