21 #include "ns3/command-line.h" 22 #include "ns3/config.h" 23 #include "ns3/uinteger.h" 24 #include "ns3/boolean.h" 25 #include "ns3/string.h" 27 #include "ns3/yans-wifi-helper.h" 29 #include "ns3/mobility-helper.h" 30 #include "ns3/internet-stack-helper.h" 31 #include "ns3/ipv4-address-helper.h" 32 #include "ns3/udp-client-server-helper.h" 33 #include "ns3/packet-sink-helper.h" 34 #include "ns3/yans-wifi-channel.h" 74 int main (
int argc,
char *argv[])
76 uint32_t payloadSize = 1472;
77 double simulationTime = 10;
81 bool verifyResults = 0;
84 cmd.AddValue (
"payloadSize",
"Payload size in bytes", payloadSize);
85 cmd.AddValue (
"enableRts",
"Enable or disable RTS/CTS", enableRts);
86 cmd.AddValue (
"simulationTime",
"Simulation time in seconds", simulationTime);
87 cmd.AddValue (
"distance",
"Distance in meters between the station and the access point", distance);
88 cmd.AddValue (
"enablePcap",
"Enable/disable pcap file generation",
enablePcap);
89 cmd.AddValue (
"verifyResults",
"Enable/disable results verification at the end of the simulation", verifyResults);
90 cmd.Parse (argc, argv);
106 wifi.SetRemoteStationManager (
"ns3::ConstantRateWifiManager",
"DataMode",
StringValue (
"HtMcs7"),
"ControlMode",
StringValue (
"HtMcs0"));
109 NetDeviceContainer staDeviceA, staDeviceB, staDeviceC, staDeviceD, apDeviceA, apDeviceB, apDeviceC, apDeviceD;
115 mac.SetType (
"ns3::StaWifiMac",
119 mac.SetType (
"ns3::ApWifiMac",
127 mac.SetType (
"ns3::StaWifiMac",
133 mac.SetType (
"ns3::ApWifiMac",
141 mac.SetType (
"ns3::StaWifiMac",
148 mac.SetType (
"ns3::ApWifiMac",
156 mac.SetType (
"ns3::StaWifiMac",
163 mac.SetType (
"ns3::ApWifiMac",
171 mobility.SetMobilityModel (
"ns3::ConstantPositionMobilityModel");
174 positionAlloc->
Add (Vector (0.0, 0.0, 0.0));
175 positionAlloc->
Add (Vector (10.0, 0.0, 0.0));
176 positionAlloc->
Add (Vector (20.0, 0.0, 0.0));
177 positionAlloc->
Add (Vector (30.0, 0.0, 0.0));
179 positionAlloc->
Add (Vector (distance, 0.0, 0.0));
180 positionAlloc->
Add (Vector (10 + distance, 0.0, 0.0));
181 positionAlloc->
Add (Vector (20 + distance, 0.0, 0.0));
182 positionAlloc->
Add (Vector (30 + distance, 0.0, 0.0));
184 mobility.SetPositionAllocator (positionAlloc);
190 stack.Install (wifiApNodes);
194 address.SetBase (
"192.168.1.0",
"255.255.255.0");
196 StaInterfaceA =
address.Assign (staDeviceA);
198 ApInterfaceA =
address.Assign (apDeviceA);
200 address.SetBase (
"192.168.2.0",
"255.255.255.0");
202 StaInterfaceB =
address.Assign (staDeviceB);
204 ApInterfaceB =
address.Assign (apDeviceB);
206 address.SetBase (
"192.168.3.0",
"255.255.255.0");
208 StaInterfaceC =
address.Assign (staDeviceC);
210 ApInterfaceC =
address.Assign (apDeviceC);
212 address.SetBase (
"192.168.4.0",
"255.255.255.0");
214 StaInterfaceD =
address.Assign (staDeviceD);
216 ApInterfaceD =
address.Assign (apDeviceD);
227 clientA.SetAttribute (
"Interval",
TimeValue (
Time (
"0.00002")));
228 clientA.SetAttribute (
"PacketSize",
UintegerValue (payloadSize));
241 clientB.SetAttribute (
"Interval",
TimeValue (
Time (
"0.00002")));
242 clientB.SetAttribute (
"PacketSize",
UintegerValue (payloadSize));
255 clientC.SetAttribute (
"Interval",
TimeValue (
Time (
"0.00002")));
256 clientC.SetAttribute (
"PacketSize",
UintegerValue (payloadSize));
269 clientD.SetAttribute (
"Interval",
TimeValue (
Time (
"0.00002")));
270 clientD.SetAttribute (
"PacketSize",
UintegerValue (payloadSize));
278 phy.EnablePcap (
"AP_A", apDeviceA.
Get (0));
279 phy.EnablePcap (
"STA_A", staDeviceA.
Get (0));
280 phy.EnablePcap (
"AP_B", apDeviceB.
Get (0));
281 phy.EnablePcap (
"STA_B", staDeviceB.
Get (0));
282 phy.EnablePcap (
"AP_C", apDeviceC.
Get (0));
283 phy.EnablePcap (
"STA_C", staDeviceC.
Get (0));
284 phy.EnablePcap (
"AP_D", apDeviceD.
Get (0));
285 phy.EnablePcap (
"STA_D", staDeviceD.
Get (0));
292 uint64_t totalPacketsThroughA = DynamicCast<UdpServer> (serverAppA.
Get (0))->GetReceived ();
293 uint64_t totalPacketsThroughB = DynamicCast<UdpServer> (serverAppB.
Get (0))->GetReceived ();
294 uint64_t totalPacketsThroughC = DynamicCast<UdpServer> (serverAppC.
Get (0))->GetReceived ();
295 uint64_t totalPacketsThroughD = DynamicCast<UdpServer> (serverAppD.
Get (0))->GetReceived ();
299 double throughput = totalPacketsThroughA * payloadSize * 8 / (simulationTime * 1000000.0);
300 std::cout <<
"Throughput with default configuration (A-MPDU aggregation enabled, 65kB): " << throughput <<
" Mbit/s" <<
'\n';
301 if (verifyResults && (throughput < 59 || throughput > 60))
303 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
307 throughput = totalPacketsThroughB * payloadSize * 8 / (simulationTime * 1000000.0);
308 std::cout <<
"Throughput with aggregation disabled: " << throughput <<
" Mbit/s" <<
'\n';
309 if (verifyResults && (throughput < 30 || throughput > 30.5))
311 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
315 throughput = totalPacketsThroughC * payloadSize * 8 / (simulationTime * 1000000.0);
316 std::cout <<
"Throughput with A-MPDU disabled and A-MSDU enabled (8kB): " << throughput <<
" Mbit/s" <<
'\n';
317 if (verifyResults && (throughput < 51 || throughput > 52))
319 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
323 throughput = totalPacketsThroughD * payloadSize * 8 / (simulationTime * 1000000.0);
324 std::cout <<
"Throughput with A-MPDU enabled (32kB) and A-MSDU enabled (4kB): " << throughput <<
" Mbit/s" <<
'\n';
325 if (verifyResults && (throughput < 58 || throughput > 59))
327 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
holds a vector of ns3::Application pointers.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
Simulation virtual time values and global simulation resolution.
Smart pointer class similar to boost::intrusive_ptr.
AttributeValue implementation for Boolean.
HT PHY for the 5 GHz band (clause 20)
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Hold variables of type string.
Make it easy to create and manage PHY objects for the yans model.
static YansWifiChannelHelper Default(void)
Create a channel helper in a default working state.
static void Run(void)
Run the simulation.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
aggregate IP/TCP/UDP functionality to existing Nodes.
static YansWifiPhyHelper Default(void)
Create a phy helper in a default working state.
helps to create WifiNetDevice objects
Create a client application which sends UDP packets carrying a 32bit sequence number and a 64 bit tim...
AttributeValue implementation for Time.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Hold an unsigned integer type.
holds a vector of ns3::NetDevice pointers
Create a server application which waits for input UDP packets and uses the information carried into t...
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
Parse command-line arguments.
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
void SetAttribute(std::string name, const AttributeValue &value)
Record an attribute to be set in each Application after it is is created.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
manage and create wifi channel objects for the yans model.
create MAC layers for a ns3::WifiNetDevice.
The IEEE 802.11 SSID Information Element.
Helper class used to assign positions and mobility models to nodes.
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Time Seconds(double value)
Construct a Time in the indicated unit.
AttributeValue implementation for Ssid.
void SetDefault(std::string name, const AttributeValue &value)
void Add(Vector v)
Add a position to the list of positions.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Include Radiotap link layer information.
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.