|
|
| 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 |
for (int mcs = 0; mcs <= 31; mcs++) |
| 90 |
wifi.SetStandard (WIFI_PHY_STANDARD_80211n_2_4GHZ); |
57 |
{ |
| 91 |
HtWifiMacHelper mac = HtWifiMacHelper::Default (); |
58 |
uint32_t payloadSize; //1500 byte IP packet |
| 92 |
|
59 |
if (udp) |
|
|
60 |
{ |
| 61 |
payloadSize = 1472; //bytes |
| 62 |
} |
| 63 |
else |
| 64 |
{ |
| 65 |
payloadSize = 1448; //bytes |
| 66 |
Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (payloadSize)); |
| 67 |
} |
| 93 |
|
68 |
|
| 94 |
Ssid ssid = Ssid ("ns380211n"); |
69 |
NodeContainer wifiStaNode; |
| 95 |
double datarate = 0; |
70 |
wifiStaNode.Create (1); |
| 96 |
StringValue DataRate; |
71 |
NodeContainer wifiApNode; |
| 97 |
if (i==0) |
72 |
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 |
|
73 |
|
| 123 |
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager","DataMode", DataRate, |
74 |
YansWifiChannelHelper channel = YansWifiChannelHelper::Default (); |
| 124 |
"ControlMode", DataRate); |
75 |
YansWifiPhyHelper phy = YansWifiPhyHelper::Default (); |
| 125 |
mac.SetType ("ns3::StaWifiMac", |
76 |
phy.SetChannel (channel.Create ()); |
| 126 |
"Ssid", SsidValue (ssid), |
|
|
| 127 |
"ActiveProbing", BooleanValue (false)); |
| 128 |
|
| 129 |
NetDeviceContainer staDevices; |
| 130 |
staDevices = wifi.Install (phy, mac, wifiNodes); |
| 131 |
|
77 |
|
| 132 |
mac.SetType ("ns3::ApWifiMac", |
78 |
if (mcs <= 7) |
| 133 |
"Ssid", SsidValue (ssid)); |
79 |
{ |
| 134 |
|
80 |
phy.Set ("ShortGuardEnabled", BooleanValue (false)); |
| 135 |
NetDeviceContainer apDevice; |
81 |
phy.Set ("ChannelBonding", BooleanValue (false)); |
| 136 |
apDevice = wifi.Install (phy, mac, wifiApNode); |
82 |
} |
| 137 |
/* Ptr<WifiRemoteStationManager> apStationManager = |
83 |
else if (mcs > 7 && mcs <= 15) |
| 138 |
DynamicCast<WifiNetDevice>(apDevice.Get (0))->GetRemoteStationManager (); |
84 |
{ |
| 139 |
apStationManager->AddBasicMode (WifiMode ("OfdmRate13MbpsBW20MHz")); |
85 |
phy.Set ("ShortGuardEnabled", BooleanValue (true)); |
| 140 |
apStationManager->AddBasicMode (WifiMode ("OfdmRate19_5MbpsBW20MHz")); |
86 |
phy.Set ("ChannelBonding", BooleanValue (false)); |
| 141 |
apStationManager->AddBasicMode (WifiMode ("OfdmRate26MbpsBW20MHz")); |
87 |
} |
| 142 |
apStationManager->AddBasicMode (WifiMode ("OfdmRate39MbpsBW20MHz")); |
88 |
else if (mcs > 15 && mcs <= 23) |
| 143 |
Ptr<WifiRemoteStationManager> staStationManager = |
89 |
{ |
| 144 |
DynamicCast<WifiNetDevice> (staDevices.Get (0))->GetRemoteStationManager (); |
90 |
phy.Set ("ShortGuardEnabled", BooleanValue (false)); |
| 145 |
staStationManager->AddBasicMode (WifiMode ("OfdmRate13MbpsBW20MHz")); |
91 |
phy.Set ("ChannelBonding", BooleanValue (true)); |
| 146 |
staStationManager->AddBasicMode (WifiMode ("OfdmRate19_5MbpsBW20MHz")); |
92 |
} |
| 147 |
staStationManager->AddBasicMode (WifiMode ("OfdmRate26MbpsBW20MHz")); |
93 |
else |
| 148 |
staStationManager->AddBasicMode (WifiMode ("OfdmRate39MbpsBW20MHz"));*/ |
94 |
{ |
| 149 |
|
95 |
phy.Set ("ShortGuardEnabled", BooleanValue (true)); |
| 150 |
// mobility. |
96 |
phy.Set ("ChannelBonding", BooleanValue (true)); |
| 151 |
MobilityHelper mobility; |
97 |
} |
| 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 |
|
98 |
|
| 160 |
/* Internet stack*/ |
99 |
WifiHelper wifi = WifiHelper::Default (); |
| 161 |
InternetStackHelper stack; |
100 |
wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ); |
| 162 |
stack.Install (wifiApNode); |
101 |
HtWifiMacHelper mac = HtWifiMacHelper::Default (); |
| 163 |
stack.Install (wifiNodes); |
|
|
| 164 |
|
102 |
|
| 165 |
Ipv4AddressHelper address; |
103 |
Ssid ssid = Ssid ("ns380211n"); |
| 166 |
|
104 |
|
| 167 |
address.SetBase ("10.1.3.0", "255.255.255.0"); |
105 |
double datarate = 0; |
| 168 |
Ipv4InterfaceContainer wifiNodesInterfaces; |
106 |
StringValue DataRate; |
| 169 |
Ipv4InterfaceContainer apNodeInterface; |
107 |
if (mcs == 0) |
|
|
108 |
{ |
| 109 |
DataRate = StringValue ("OfdmRate6_5MbpsBW20MHz"); |
| 110 |
datarate = 6.5; |
| 111 |
} |
| 112 |
else if (mcs == 1) |
| 113 |
{ |
| 114 |
DataRate = StringValue ("OfdmRate13MbpsBW20MHz"); |
| 115 |
datarate = 13; |
| 116 |
} |
| 117 |
else if (mcs == 2) |
| 118 |
{ |
| 119 |
DataRate = StringValue ("OfdmRate19_5MbpsBW20MHz"); |
| 120 |
datarate = 19.5; |
| 121 |
} |
| 122 |
else if (mcs == 3) |
| 123 |
{ |
| 124 |
DataRate = StringValue ("OfdmRate26MbpsBW20MHz"); |
| 125 |
datarate = 26; |
| 126 |
} |
| 127 |
else if (mcs == 4) |
| 128 |
{ |
| 129 |
DataRate = StringValue ("OfdmRate39MbpsBW20MHz"); |
| 130 |
datarate = 39; |
| 131 |
} |
| 132 |
else if (mcs == 5) |
| 133 |
{ |
| 134 |
DataRate = StringValue ("OfdmRate52MbpsBW20MHz"); |
| 135 |
datarate = 52; |
| 136 |
} |
| 137 |
else if (mcs == 6) |
| 138 |
{ |
| 139 |
DataRate = StringValue ("OfdmRate58_5MbpsBW20MHz"); |
| 140 |
datarate = 58.5; |
| 141 |
} |
| 142 |
else if (mcs == 7) |
| 143 |
{ |
| 144 |
DataRate = StringValue ("OfdmRate65MbpsBW20MHz"); |
| 145 |
datarate = 65; |
| 146 |
} |
| 147 |
else if (mcs == 8) |
| 148 |
{ |
| 149 |
DataRate = StringValue ("OfdmRate7_2MbpsBW20MHz"); |
| 150 |
datarate = 7.2; |
| 151 |
} |
| 152 |
else if (mcs == 9) |
| 153 |
{ |
| 154 |
DataRate = StringValue ("OfdmRate14_4MbpsBW20MHz"); |
| 155 |
datarate = 14.4; |
| 156 |
} |
| 157 |
else if (mcs == 10) |
| 158 |
{ |
| 159 |
DataRate = StringValue ("OfdmRate21_7MbpsBW20MHz"); |
| 160 |
datarate = 21.7; |
| 161 |
} |
| 162 |
else if (mcs == 11) |
| 163 |
{ |
| 164 |
DataRate = StringValue ("OfdmRate28_9MbpsBW20MHz"); |
| 165 |
datarate = 28.9; |
| 166 |
} |
| 167 |
else if (mcs == 12) |
| 168 |
{ |
| 169 |
DataRate = StringValue ("OfdmRate43_3MbpsBW20MHz"); |
| 170 |
datarate = 43.3; |
| 171 |
} |
| 172 |
else if (mcs == 13) |
| 173 |
{ |
| 174 |
DataRate = StringValue ("OfdmRate57_8MbpsBW20MHz"); |
| 175 |
datarate = 57.8; |
| 176 |
} |
| 177 |
else if (mcs == 14) |
| 178 |
{ |
| 179 |
DataRate = StringValue ("OfdmRate65MbpsBW20MHzShGi"); |
| 180 |
datarate = 65; |
| 181 |
} |
| 182 |
else if (mcs == 15) |
| 183 |
{ |
| 184 |
DataRate = StringValue ("OfdmRate72_2MbpsBW20MHz"); |
| 185 |
datarate = 72.2; |
| 186 |
} |
| 187 |
else if (mcs == 16) |
| 188 |
{ |
| 189 |
DataRate = StringValue ("OfdmRate13_5MbpsBW40MHz"); |
| 190 |
datarate = 13.5; |
| 191 |
} |
| 192 |
else if (mcs == 17) |
| 193 |
{ |
| 194 |
DataRate = StringValue ("OfdmRate27MbpsBW40MHz"); |
| 195 |
datarate = 27; |
| 196 |
} |
| 197 |
else if (mcs == 18) |
| 198 |
{ |
| 199 |
DataRate = StringValue ("OfdmRate40_5MbpsBW40MHz"); |
| 200 |
datarate = 40.5; |
| 201 |
} |
| 202 |
else if (mcs == 19) |
| 203 |
{ |
| 204 |
DataRate = StringValue ("OfdmRate54MbpsBW40MHz"); |
| 205 |
datarate = 54; |
| 206 |
} |
| 207 |
else if (mcs == 20) |
| 208 |
{ |
| 209 |
DataRate = StringValue ("OfdmRate81MbpsBW40MHz"); |
| 210 |
datarate = 81; |
| 211 |
} |
| 212 |
else if (mcs == 21) |
| 213 |
{ |
| 214 |
DataRate = StringValue ("OfdmRate108MbpsBW40MHz"); |
| 215 |
datarate = 108; |
| 216 |
} |
| 217 |
else if (mcs == 22) |
| 218 |
{ |
| 219 |
DataRate = StringValue ("OfdmRate121_5MbpsBW40MHz"); |
| 220 |
datarate = 121.5; |
| 221 |
} |
| 222 |
else if (mcs == 23) |
| 223 |
{ |
| 224 |
DataRate = StringValue ("OfdmRate135MbpsBW40MHz"); |
| 225 |
datarate = 135; |
| 226 |
} |
| 227 |
else if (mcs == 24) |
| 228 |
{ |
| 229 |
DataRate = StringValue ("OfdmRate15MbpsBW40MHz"); |
| 230 |
datarate = 15; |
| 231 |
} |
| 232 |
else if (mcs == 25) |
| 233 |
{ |
| 234 |
DataRate = StringValue ("OfdmRate30MbpsBW40MHz"); |
| 235 |
datarate = 30; |
| 236 |
} |
| 237 |
else if (mcs == 26) |
| 238 |
{ |
| 239 |
DataRate = StringValue ("OfdmRate45MbpsBW40MHz"); |
| 240 |
datarate = 45; |
| 241 |
} |
| 242 |
else if (mcs == 27) |
| 243 |
{ |
| 244 |
DataRate = StringValue ("OfdmRate60MbpsBW40MHz"); |
| 245 |
datarate = 60; |
| 246 |
} |
| 247 |
else if (mcs == 28) |
| 248 |
{ |
| 249 |
DataRate = StringValue ("OfdmRate90MbpsBW40MHz"); |
| 250 |
datarate = 90; |
| 251 |
} |
| 252 |
else if (mcs == 29) |
| 253 |
{ |
| 254 |
DataRate = StringValue ("OfdmRate120MbpsBW40MHz"); |
| 255 |
datarate = 120; |
| 256 |
} |
| 257 |
else if (mcs == 30) |
| 258 |
{ |
| 259 |
DataRate = StringValue ("OfdmRate135MbpsBW40MHzShGi"); |
| 260 |
datarate = 135; |
| 261 |
} |
| 262 |
else |
| 263 |
{ |
| 264 |
DataRate = StringValue ("OfdmRate150MbpsBW40MHz"); |
| 265 |
datarate = 150; |
| 266 |
} |
| 170 |
|
267 |
|
| 171 |
wifiNodesInterfaces = address.Assign (staDevices); |
268 |
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager","DataMode", DataRate, |
| 172 |
apNodeInterface = address.Assign (apDevice); |
269 |
"ControlMode", DataRate); |
|
|
270 |
mac.SetType ("ns3::StaWifiMac", |
| 271 |
"Ssid", SsidValue (ssid), |
| 272 |
"ActiveProbing", BooleanValue (false)); |
| 173 |
|
273 |
|
| 174 |
ApplicationContainer serverApps,sink1App; |
274 |
NetDeviceContainer staDevices; |
|
|
275 |
staDevices = wifi.Install (phy, mac, wifiStaNode); |
| 175 |
|
276 |
|
| 176 |
double t=10; |
277 |
mac.SetType ("ns3::ApWifiMac", |
|
|
278 |
"Ssid", SsidValue (ssid)); |
| 177 |
|
279 |
|
| 178 |
/* Setting applications */ |
280 |
NetDeviceContainer apDevice; |
| 179 |
if (udp) |
281 |
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 |
|
282 |
|
| 186 |
UdpClientHelper myClient (wifiNodesInterfaces.GetAddress (0), 9); |
283 |
// mobility. |
| 187 |
myClient.SetAttribute ("MaxPackets", UintegerValue (64707202)); |
284 |
MobilityHelper mobility; |
| 188 |
myClient.SetAttribute ("Interval", TimeValue (Time ("0.00002"))); |
285 |
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 |
|
286 |
|
| 198 |
//TCP flow |
287 |
positionAlloc->Add (Vector (0.0, 0.0, 0.0)); |
| 199 |
uint16_t port = 50000; |
288 |
positionAlloc->Add (Vector (1.0, 0.0, 0.0)); |
| 200 |
Address apLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port)); |
289 |
mobility.SetPositionAllocator (positionAlloc); |
| 201 |
PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", apLocalAddress); |
|
|
| 202 |
sink1App = packetSinkHelper.Install (wifiNodes.Get (0)); |
| 203 |
|
290 |
|
| 204 |
sink1App.Start (Seconds (0.0)); |
291 |
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 |
|
292 |
|
| 214 |
AddressValue remoteAddress (InetSocketAddress (wifiNodesInterfaces.GetAddress(0), port)); |
293 |
mobility.Install (wifiApNode); |
| 215 |
onoff.SetAttribute ("Remote", remoteAddress); |
294 |
mobility.Install (wifiStaNode); |
| 216 |
apps.Add (onoff.Install (wifiApNode.Get (0))); |
|
|
| 217 |
apps.Start (Seconds (0.0)); |
| 218 |
apps.Stop (Seconds (t)); |
| 219 |
} |
| 220 |
|
295 |
|
| 221 |
|
296 |
/* Internet stack*/ |
| 222 |
Ipv4GlobalRoutingHelper::PopulateRoutingTables (); |
297 |
InternetStackHelper stack; |
|
|
298 |
stack.Install (wifiApNode); |
| 299 |
stack.Install (wifiStaNode); |
| 223 |
|
300 |
|
| 224 |
Simulator::Stop (Seconds (t)); |
301 |
Ipv4AddressHelper address; |
| 225 |
Simulator::Run (); |
|
|
| 226 |
Simulator::Destroy (); |
| 227 |
|
302 |
|
| 228 |
//UDP |
303 |
address.SetBase ("192.168.1.0", "255.255.255.0"); |
| 229 |
if (udp) |
304 |
Ipv4InterfaceContainer wifiNodesInterfaces; |
| 230 |
{ |
305 |
Ipv4InterfaceContainer apNodeInterface; |
| 231 |
uint32_t totalPacketsThrough = DynamicCast<UdpServer>(serverApps.Get (0))->GetReceived (); |
306 |
|
| 232 |
throughput=totalPacketsThrough*1500*8/(t*1000000.0); |
307 |
wifiNodesInterfaces = address.Assign (staDevices); |
| 233 |
} |
308 |
apNodeInterface = address.Assign (apDevice); |
| 234 |
else |
309 |
|
| 235 |
{ |
310 |
ApplicationContainer serverApps,sink1App; |
| 236 |
//TCP |
311 |
|
| 237 |
uint32_t totalPacketsThrough = DynamicCast<PacketSink>(sink1App.Get (0))->GetTotalRx (); |
312 |
/* Setting applications */ |
| 238 |
throughput=totalPacketsThrough*8/((t-3)*1000000.0); |
313 |
if (udp) |
| 239 |
} |
314 |
{ |
| 240 |
|
315 |
//UDP flow |
| 241 |
std::cout << datarate <<" " << throughput << '\n'; |
316 |
UdpServerHelper myServer (9); |
| 242 |
} |
317 |
serverApps = myServer.Install (wifiStaNode.Get (0)); |
|
|
318 |
serverApps.Start (Seconds (0.0)); |
| 319 |
serverApps.Stop (Seconds (simulationTime)); |
| 320 |
|
| 321 |
UdpClientHelper myClient (wifiNodesInterfaces.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 clientApps = myClient.Install (wifiApNode.Get (0)); |
| 327 |
clientApps.Start (Seconds (1.0)); |
| 328 |
clientApps.Stop (Seconds (simulationTime)); |
| 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 |
sink1App = packetSinkHelper.Install (wifiStaNode.Get (0)); |
| 337 |
|
| 338 |
sink1App.Start (Seconds (0.0)); |
| 339 |
sink1App.Stop (Seconds (simulationTime)); |
| 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 (500000000)); //bit/s |
| 346 |
ApplicationContainer apps; |
| 347 |
|
| 348 |
AddressValue remoteAddress (InetSocketAddress (wifiNodesInterfaces.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)); |
| 353 |
} |
| 354 |
|
| 355 |
Ipv4GlobalRoutingHelper::PopulateRoutingTables (); |
| 356 |
|
| 357 |
Simulator::Stop (Seconds (simulationTime)); |
| 358 |
Simulator::Run (); |
| 359 |
Simulator::Destroy (); |
| 360 |
|
| 361 |
double throughput = 0; |
| 362 |
if (udp) |
| 363 |
{ |
| 364 |
//UDP |
| 365 |
uint32_t totalPacketsThrough = DynamicCast<UdpServer> (serverApps.Get (0))->GetReceived (); |
| 366 |
throughput = totalPacketsThrough * payloadSize * 8 / ((simulationTime - 1) * 1000000.0); //Mbit/s |
| 367 |
} |
| 368 |
else |
| 369 |
{ |
| 370 |
//TCP |
| 371 |
uint32_t totalPacketsThrough = DynamicCast<PacketSink> (sink1App.Get (0))->GetTotalRx (); |
| 372 |
throughput = totalPacketsThrough * 8 / ((simulationTime - 1) * 1000000.0); //Mbit/s |
| 373 |
} |
| 374 |
std::cout << "DataRate" << "\t" << "Throughput" << '\n'; |
| 375 |
std::cout << datarate << "\t\t" << throughput << " Mbit/s" << std::endl; |
| 376 |
} |
| 243 |
return 0; |
377 |
return 0; |
| 244 |
} |
378 |
} |