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" 35 #include "ns3/wifi-net-device.h" 36 #include "ns3/wifi-mac.h" 76 int main (
int argc,
char *argv[])
78 uint32_t payloadSize = 1472;
79 double simulationTime = 10;
83 bool verifyResults = 0;
86 cmd.AddValue (
"payloadSize",
"Payload size in bytes", payloadSize);
87 cmd.AddValue (
"enableRts",
"Enable or disable RTS/CTS", enableRts);
88 cmd.AddValue (
"simulationTime",
"Simulation time in seconds", simulationTime);
89 cmd.AddValue (
"distance",
"Distance in meters between the station and the access point", distance);
90 cmd.AddValue (
"enablePcap",
"Enable/disable pcap file generation",
enablePcap);
91 cmd.AddValue (
"verifyResults",
"Enable/disable results verification at the end of the simulation", verifyResults);
92 cmd.Parse (argc, argv);
108 wifi.SetRemoteStationManager (
"ns3::ConstantRateWifiManager",
"DataMode",
StringValue (
"HtMcs7"),
"ControlMode",
StringValue (
"HtMcs0"));
111 NetDeviceContainer staDeviceA, staDeviceB, staDeviceC, staDeviceD, apDeviceA, apDeviceB, apDeviceC, apDeviceD;
117 mac.SetType (
"ns3::StaWifiMac",
121 mac.SetType (
"ns3::ApWifiMac",
129 mac.SetType (
"ns3::StaWifiMac",
139 mac.SetType (
"ns3::ApWifiMac",
146 wifi_dev = DynamicCast<WifiNetDevice> (dev);
152 mac.SetType (
"ns3::StaWifiMac",
159 wifi_dev = DynamicCast<WifiNetDevice> (dev);
163 mac.SetType (
"ns3::ApWifiMac",
170 wifi_dev = DynamicCast<WifiNetDevice> (dev);
177 mac.SetType (
"ns3::StaWifiMac",
185 wifi_dev = DynamicCast<WifiNetDevice> (dev);
189 mac.SetType (
"ns3::ApWifiMac",
197 wifi_dev = DynamicCast<WifiNetDevice> (dev);
204 mobility.SetMobilityModel (
"ns3::ConstantPositionMobilityModel");
207 positionAlloc->
Add (Vector (0.0, 0.0, 0.0));
208 positionAlloc->
Add (Vector (10.0, 0.0, 0.0));
209 positionAlloc->
Add (Vector (20.0, 0.0, 0.0));
210 positionAlloc->
Add (Vector (30.0, 0.0, 0.0));
212 positionAlloc->
Add (Vector (distance, 0.0, 0.0));
213 positionAlloc->
Add (Vector (10 + distance, 0.0, 0.0));
214 positionAlloc->
Add (Vector (20 + distance, 0.0, 0.0));
215 positionAlloc->
Add (Vector (30 + distance, 0.0, 0.0));
217 mobility.SetPositionAllocator (positionAlloc);
223 stack.Install (wifiApNodes);
227 address.SetBase (
"192.168.1.0",
"255.255.255.0");
229 StaInterfaceA =
address.Assign (staDeviceA);
231 ApInterfaceA =
address.Assign (apDeviceA);
233 address.SetBase (
"192.168.2.0",
"255.255.255.0");
235 StaInterfaceB =
address.Assign (staDeviceB);
237 ApInterfaceB =
address.Assign (apDeviceB);
239 address.SetBase (
"192.168.3.0",
"255.255.255.0");
241 StaInterfaceC =
address.Assign (staDeviceC);
243 ApInterfaceC =
address.Assign (apDeviceC);
245 address.SetBase (
"192.168.4.0",
"255.255.255.0");
247 StaInterfaceD =
address.Assign (staDeviceD);
249 ApInterfaceD =
address.Assign (apDeviceD);
260 clientA.SetAttribute (
"Interval",
TimeValue (
Time (
"0.0001")));
261 clientA.SetAttribute (
"PacketSize",
UintegerValue (payloadSize));
274 clientB.SetAttribute (
"Interval",
TimeValue (
Time (
"0.0001")));
275 clientB.SetAttribute (
"PacketSize",
UintegerValue (payloadSize));
288 clientC.SetAttribute (
"Interval",
TimeValue (
Time (
"0.0001")));
289 clientC.SetAttribute (
"PacketSize",
UintegerValue (payloadSize));
302 clientD.SetAttribute (
"Interval",
TimeValue (
Time (
"0.0001")));
303 clientD.SetAttribute (
"PacketSize",
UintegerValue (payloadSize));
311 phy.EnablePcap (
"AP_A", apDeviceA.
Get (0));
312 phy.EnablePcap (
"STA_A", staDeviceA.
Get (0));
313 phy.EnablePcap (
"AP_B", apDeviceB.
Get (0));
314 phy.EnablePcap (
"STA_B", staDeviceB.
Get (0));
315 phy.EnablePcap (
"AP_C", apDeviceC.
Get (0));
316 phy.EnablePcap (
"STA_C", staDeviceC.
Get (0));
317 phy.EnablePcap (
"AP_D", apDeviceD.
Get (0));
318 phy.EnablePcap (
"STA_D", staDeviceD.
Get (0));
325 uint64_t totalPacketsThroughA = DynamicCast<UdpServer> (serverAppA.
Get (0))->GetReceived ();
326 uint64_t totalPacketsThroughB = DynamicCast<UdpServer> (serverAppB.
Get (0))->GetReceived ();
327 uint64_t totalPacketsThroughC = DynamicCast<UdpServer> (serverAppC.
Get (0))->GetReceived ();
328 uint64_t totalPacketsThroughD = DynamicCast<UdpServer> (serverAppD.
Get (0))->GetReceived ();
332 double throughput = totalPacketsThroughA * payloadSize * 8 / (simulationTime * 1000000.0);
333 std::cout <<
"Throughput with default configuration (A-MPDU aggregation enabled, 65kB): " << throughput <<
" Mbit/s" <<
'\n';
334 if (verifyResults && (throughput < 58.5 || throughput > 59.5))
336 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
340 throughput = totalPacketsThroughB * payloadSize * 8 / (simulationTime * 1000000.0);
341 std::cout <<
"Throughput with aggregation disabled: " << throughput <<
" Mbit/s" <<
'\n';
342 if (verifyResults && (throughput < 30 || throughput > 31))
344 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
348 throughput = totalPacketsThroughC * payloadSize * 8 / (simulationTime * 1000000.0);
349 std::cout <<
"Throughput with A-MPDU disabled and A-MSDU enabled (8kB): " << throughput <<
" Mbit/s" <<
'\n';
350 if (verifyResults && (throughput < 51 || throughput > 52))
352 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
356 throughput = totalPacketsThroughD * payloadSize * 8 / (simulationTime * 1000000.0);
357 std::cout <<
"Throughput with A-MPDU enabled (32kB) and A-MSDU enabled (4kB): " << throughput <<
" Mbit/s" <<
'\n';
358 if (verifyResults && (throughput < 58 || throughput > 59))
360 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.
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
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...
Ptr< WifiMac > GetMac(void) const
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.