-
Notifications
You must be signed in to change notification settings - Fork 5
/
test.cc
179 lines (149 loc) · 6.74 KB
/
test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2015 Sébastien Deronne
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Sébastien Deronne <[email protected]>
*/
#include "ns3/core-module.h"
#include "ns3/applications-module.h"
#include "ns3/wifi-module.h"
#include "ns3/mobility-module.h"
#include "ns3/internet-module.h"
// This example considers two hidden stations in an 802.11n network which supports MPDU aggregation.
// The user can specify whether RTS/CTS is used and can set the number of aggregated MPDUs.
//
// Example: ./waf --run "simple-ht-hidden-stations --enableRts=1 --nMpdus=8"
//
// Network topology:
//
// Wifi 192.168.1.0
//
// AP
// * * *
// | | |
// n1 n2 n3
//
// Packets in this simulation aren't marked with a QosTag so they are considered
// belonging to BestEffort Access Class (AC_BE).
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("SimplesHtHiddenStations");
int main (int argc, char *argv[])
{
uint32_t payloadSize = 1472; //bytes
uint64_t simulationTime = 10; //seconds
uint32_t nMpdus = 1;
uint32_t maxAmpduSize = 0;
bool enableRts = 0;
double minExpectedThroughput = 0;
double maxExpectedThroughput = 0;
CommandLine cmd;
cmd.AddValue ("nMpdus", "Number of aggregated MPDUs", nMpdus);
cmd.AddValue ("payloadSize", "Payload size in bytes", payloadSize);
cmd.AddValue ("enableRts", "Enable RTS/CTS", enableRts);
cmd.AddValue ("simulationTime", "Simulation time in seconds", simulationTime);
cmd.AddValue ("minExpectedThroughput", "if set, simulation fails if the lowest throughput is below this value", minExpectedThroughput);
cmd.AddValue ("maxExpectedThroughput", "if set, simulation fails if the highest throughput is above this value", maxExpectedThroughput);
cmd.Parse (argc, argv);
if (!enableRts)
{
Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("999999"));
}
else
{
Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("0"));
}
//Set the maximum size for A-MPDU with regards to the payload size
maxAmpduSize = nMpdus * (payloadSize + 200);
// Set the maximum wireless range to 5 meters in order to reproduce a hidden nodes scenario, i.e. the distance between hidden stations is larger than 5 meters
Config::SetDefault ("ns3::RangePropagationLossModel::MaxRange", DoubleValue (5));
NodeContainer wifiStaNodes;
wifiStaNodes.Create (2);
NodeContainer wifiApNode;
wifiApNode.Create (1);
YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
channel.AddPropagationLoss ("ns3::RangePropagationLossModel"); //wireless range limited to 5 meters!
YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
phy.SetPcapDataLinkType (WifiPhyHelper::DLT_IEEE802_11_RADIO);
phy.SetChannel (channel.Create ());
WifiHelper wifi;
wifi.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue ("HtMcs7"), "ControlMode", StringValue ("HtMcs0"));
WifiMacHelper mac;
Ssid ssid = Ssid ("simple-mpdu-aggregation");
mac.SetType ("ns3::StaWifiMac",
"Ssid", SsidValue (ssid),
"BE_MaxAmpduSize", UintegerValue (maxAmpduSize));
NetDeviceContainer staDevices;
staDevices = wifi.Install (phy, mac, wifiStaNodes);
mac.SetType ("ns3::ApWifiMac",
"Ssid", SsidValue (ssid),
"EnableBeaconJitter", BooleanValue (false),
"BE_MaxAmpduSize", UintegerValue (maxAmpduSize));
NetDeviceContainer apDevice;
apDevice = wifi.Install (phy, mac, wifiApNode);
// Setting mobility model
MobilityHelper mobility;
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
// AP is between the two stations, each station being located at 5 meters from the AP.
// The distance between the two stations is thus equal to 10 meters.
// Since the wireless range is limited to 5 meters, the two stations are hidden from each other.
positionAlloc->Add (Vector (5.0, 0.0, 0.0));
positionAlloc->Add (Vector (0.0, 0.0, 0.0));
positionAlloc->Add (Vector (10.0, 0.0, 0.0));
mobility.SetPositionAllocator (positionAlloc);
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (wifiApNode);
mobility.Install (wifiStaNodes);
// Internet stack
InternetStackHelper stack;
stack.Install (wifiApNode);
stack.Install (wifiStaNodes);
Ipv4AddressHelper address;
address.SetBase ("192.168.1.0", "255.255.255.0");
Ipv4InterfaceContainer StaInterface;
StaInterface = address.Assign (staDevices);
Ipv4InterfaceContainer ApInterface;
ApInterface = address.Assign (apDevice);
// Setting applications
uint16_t port = 9;
UdpServerHelper server (port);
ApplicationContainer serverApp = server.Install (wifiApNode);
serverApp.Start (Seconds (0.0));
serverApp.Stop (Seconds (simulationTime + 1));
UdpClientHelper client (ApInterface.GetAddress (0), port);
client.SetAttribute ("MaxPackets", UintegerValue (4294967295u));
client.SetAttribute ("Interval", TimeValue (Time ("0.00002"))); //packets/s
client.SetAttribute ("PacketSize", UintegerValue (payloadSize));
// Saturated UDP traffic from stations to AP
ApplicationContainer clientApp1 = client.Install (wifiStaNodes);
clientApp1.Start (Seconds (1.0));
clientApp1.Stop (Seconds (simulationTime + 1));
phy.EnablePcap ("SimpleHtHiddenStations_Ap", apDevice.Get (0));
phy.EnablePcap ("SimpleHtHiddenStations_Sta1", staDevices.Get (0));
phy.EnablePcap ("SimpleHtHiddenStations_Sta2", staDevices.Get (1));
Simulator::Stop (Seconds (simulationTime + 1));
Simulator::Run ();
Simulator::Destroy ();
uint32_t totalPacketsThrough = DynamicCast<UdpServer> (serverApp.Get (0))->GetReceived ();
double throughput = totalPacketsThrough * payloadSize * 8 / (simulationTime * 1000000.0);
std::cout << "Throughput: " << throughput << " Mbit/s" << '\n';
if (throughput < minExpectedThroughput || (maxExpectedThroughput > 0 && throughput > maxExpectedThroughput))
{
NS_LOG_ERROR ("Obtained throughput " << throughput << " is not in the expected boundaries!");
exit (1);
}
return 0;
}