|
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
|
2 /* |
|
3 * Copyright (c) 2009 MIRKO BANCHI |
|
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: Mirko Banchi <mk.banchi@gmail.com> |
|
19 */ |
|
20 #include "ns3/core-module.h" |
|
21 #include "ns3/network-module.h" |
|
22 #include "ns3/applications-module.h" |
|
23 #include "ns3/wifi-module.h" |
|
24 #include "ns3/mobility-module.h" |
|
25 #include "ns3/ipv4-global-routing-helper.h" |
|
26 #include "ns3/internet-module.h" |
|
27 |
|
28 //This is a simple example in order to show how 802.11n frame aggregation feature (A-MSDU) works. |
|
29 // |
|
30 //Network topology: |
|
31 // |
|
32 // Wifi 192.168.1.0 |
|
33 // |
|
34 // AP |
|
35 // * * * |
|
36 // | | | |
|
37 // n1 n2 n3 |
|
38 // |
|
39 //Packets in this simulation aren't marked with a QosTag so they are considered |
|
40 //belonging to BestEffort Access Class (AC_BE). |
|
41 |
|
42 using namespace ns3; |
|
43 |
|
44 NS_LOG_COMPONENT_DEFINE ("DataRates"); |
|
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 |
|
63 int main (int argc, char *argv[]) |
|
64 { |
|
65 std::cout << "DataRate" <<" " << "Throughput" << '\n'; |
|
66 bool udp = true; |
|
67 int i=2; |
|
68 for (;i <= 2; i++) |
|
69 { |
|
70 uint32_t nWifi = 1; |
|
71 CommandLine cmd; |
|
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 |
|
89 WifiHelper wifi = WifiHelper::Default (); |
|
90 wifi.SetStandard (WIFI_PHY_STANDARD_80211n_2_4GHZ); |
|
91 HtWifiMacHelper mac = HtWifiMacHelper::Default (); |
|
92 |
|
93 |
|
94 Ssid ssid = Ssid ("ns380211n"); |
|
95 double datarate; |
|
96 StringValue DataRate; |
|
97 if (i==0) |
|
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 |
|
123 wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager","DataMode", DataRate, |
|
124 "ControlMode", DataRate); |
|
125 mac.SetType ("ns3::StaWifiMac", |
|
126 "Ssid", SsidValue (ssid), |
|
127 "ActiveProbing", BooleanValue (false)); |
|
128 |
|
129 NetDeviceContainer staDevices; |
|
130 staDevices = wifi.Install (phy, mac, wifiNodes); |
|
131 |
|
132 mac.SetType ("ns3::ApWifiMac", |
|
133 "Ssid", SsidValue (ssid)); |
|
134 |
|
135 NetDeviceContainer apDevice; |
|
136 apDevice = wifi.Install (phy, mac, wifiApNode); |
|
137 /* Ptr<WifiRemoteStationManager> apStationManager = |
|
138 DynamicCast<WifiNetDevice>(apDevice.Get (0))->GetRemoteStationManager (); |
|
139 apStationManager->AddBasicMode (WifiMode ("OfdmRate13MbpsBW20MHz")); |
|
140 apStationManager->AddBasicMode (WifiMode ("OfdmRate19_5MbpsBW20MHz")); |
|
141 apStationManager->AddBasicMode (WifiMode ("OfdmRate26MbpsBW20MHz")); |
|
142 apStationManager->AddBasicMode (WifiMode ("OfdmRate39MbpsBW20MHz")); |
|
143 Ptr<WifiRemoteStationManager> staStationManager = |
|
144 DynamicCast<WifiNetDevice> (staDevices.Get (0))->GetRemoteStationManager (); |
|
145 staStationManager->AddBasicMode (WifiMode ("OfdmRate13MbpsBW20MHz")); |
|
146 staStationManager->AddBasicMode (WifiMode ("OfdmRate19_5MbpsBW20MHz")); |
|
147 staStationManager->AddBasicMode (WifiMode ("OfdmRate26MbpsBW20MHz")); |
|
148 staStationManager->AddBasicMode (WifiMode ("OfdmRate39MbpsBW20MHz"));*/ |
|
149 |
|
150 // mobility. |
|
151 MobilityHelper mobility; |
|
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 |
|
160 /* Internet stack*/ |
|
161 InternetStackHelper stack; |
|
162 stack.Install (wifiApNode); |
|
163 stack.Install (wifiNodes); |
|
164 |
|
165 Ipv4AddressHelper address; |
|
166 |
|
167 address.SetBase ("10.1.3.0", "255.255.255.0"); |
|
168 Ipv4InterfaceContainer wifiNodesInterfaces; |
|
169 Ipv4InterfaceContainer apNodeInterface; |
|
170 |
|
171 wifiNodesInterfaces = address.Assign (staDevices); |
|
172 apNodeInterface = address.Assign (apDevice); |
|
173 |
|
174 ApplicationContainer serverApps,sink1App; |
|
175 |
|
176 double t=10; |
|
177 |
|
178 /* Setting applications */ |
|
179 if (udp) |
|
180 { |
|
181 UdpServerHelper myServer (9); |
|
182 serverApps = myServer.Install (wifiNodes.Get (0)); |
|
183 serverApps.Start (Seconds (0.0)); |
|
184 serverApps.Stop (Seconds (t)); |
|
185 |
|
186 UdpClientHelper myClient (wifiNodesInterfaces.GetAddress (0), 9); |
|
187 myClient.SetAttribute ("MaxPackets", UintegerValue (64707202)); |
|
188 myClient.SetAttribute ("Interval", TimeValue (Time ("0.00002"))); |
|
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 |
|
198 //TCP flow |
|
199 uint16_t port = 50000; |
|
200 Address apLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port)); |
|
201 PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", apLocalAddress); |
|
202 sink1App = packetSinkHelper.Install (wifiNodes.Get (0)); |
|
203 |
|
204 sink1App.Start (Seconds (0.0)); |
|
205 sink1App.Stop (Seconds (t)); |
|
206 |
|
207 OnOffHelper onoff ("ns3::TcpSocketFactory",Ipv4Address::GetAny ()); |
|
208 onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable(30)));//in seconds |
|
209 onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable(0))); |
|
210 onoff.SetAttribute ("PacketSize", UintegerValue (1500-30));//1024 |
|
211 onoff.SetAttribute ("DataRate", DataRateValue (100000000));//51200 |
|
212 ApplicationContainer apps; |
|
213 |
|
214 AddressValue remoteAddress (InetSocketAddress (wifiNodesInterfaces.GetAddress(0), port)); |
|
215 onoff.SetAttribute ("Remote", remoteAddress); |
|
216 apps.Add (onoff.Install (wifiApNode.Get (0))); |
|
217 apps.Start (Seconds (0.0)); |
|
218 apps.Stop (Seconds (t)); |
|
219 } |
|
220 |
|
221 |
|
222 Ipv4GlobalRoutingHelper::PopulateRoutingTables (); |
|
223 |
|
224 Simulator::Stop (Seconds (t)); |
|
225 Simulator::Run (); |
|
226 Simulator::Destroy (); |
|
227 |
|
228 //UDP |
|
229 if (udp) |
|
230 { |
|
231 uint32_t totalPacketsThrough = DynamicCast<UdpServer>(serverApps.Get (0))->GetReceived (); |
|
232 throughput=totalPacketsThrough*1500*8/(t*1000000.0); |
|
233 } |
|
234 else |
|
235 { |
|
236 //TCP |
|
237 uint32_t totalPacketsThrough = DynamicCast<PacketSink>(sink1App.Get (0))->GetTotalRx (); |
|
238 throughput=totalPacketsThrough*8/((t-3)*1000000.0); |
|
239 } |
|
240 |
|
241 std::cout << datarate <<" " << throughput << '\n'; |
|
242 } |
|
243 return 0; |
|
244 } |