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"    26 #include "ns3/pointer.h"    28 #include "ns3/yans-wifi-helper.h"    30 #include "ns3/mobility-helper.h"    31 #include "ns3/internet-stack-helper.h"    32 #include "ns3/ipv4-address-helper.h"    33 #include "ns3/udp-client-server-helper.h"    34 #include "ns3/packet-sink-helper.h"    35 #include "ns3/yans-wifi-channel.h"    36 #include "ns3/wifi-net-device.h"    37 #include "ns3/wifi-mac.h"    38 #include "ns3/qos-txop.h"    95 int main (
int argc, 
char *argv[])
    97   uint32_t payloadSize = 1472; 
    98   double simulationTime = 10; 
    99   double txopLimit = 3520; 
   103   bool verifyResults = 0; 
   106   cmd.AddValue (
"payloadSize", 
"Payload size in bytes", payloadSize);
   107   cmd.AddValue (
"enableRts", 
"Enable or disable RTS/CTS", enableRts);
   108   cmd.AddValue (
"txopLimit", 
"TXOP duration in microseconds", txopLimit);
   109   cmd.AddValue (
"simulationTime", 
"Simulation time in seconds", simulationTime);
   110   cmd.AddValue (
"distance", 
"Distance in meters between the station and the access point", distance);
   111   cmd.AddValue (
"enablePcap", 
"Enable/disable pcap file generation", 
enablePcap);
   112   cmd.AddValue (
"verifyResults", 
"Enable/disable results verification at the end of the simulation", verifyResults);
   113   cmd.Parse (argc, argv);
   129   wifi.SetRemoteStationManager (
"ns3::ConstantRateWifiManager", 
"DataMode", 
StringValue (
"HtMcs7"), 
"ControlMode", 
StringValue (
"HtMcs0"));
   132   NetDeviceContainer staDeviceA, staDeviceB, staDeviceC, staDeviceD, apDeviceA, apDeviceB, apDeviceC, apDeviceD;
   138   mac.SetType (
"ns3::StaWifiMac",
   142   mac.SetType (
"ns3::ApWifiMac",
   152   wifi_dev->
GetMac ()->GetAttribute (
"BE_Txop", ptr);
   163   mac.SetType (
"ns3::StaWifiMac",
   170   wifi_dev = DynamicCast<WifiNetDevice> (dev);
   173   mac.SetType (
"ns3::ApWifiMac",
   180   wifi_dev = DynamicCast<WifiNetDevice> (dev);
   184   wifi_dev->
GetMac ()->GetAttribute (
"BE_Txop", ptr);
   195   mac.SetType (
"ns3::StaWifiMac",
   202   wifi_dev = DynamicCast<WifiNetDevice> (dev);
   206   mac.SetType (
"ns3::ApWifiMac",
   213   wifi_dev = DynamicCast<WifiNetDevice> (dev);
   218   wifi_dev->
GetMac ()->GetAttribute (
"BE_Txop", ptr);
   229   mac.SetType (
"ns3::StaWifiMac",
   237   wifi_dev = DynamicCast<WifiNetDevice> (dev);
   241   mac.SetType (
"ns3::ApWifiMac",
   249   wifi_dev = DynamicCast<WifiNetDevice> (dev);
   254   wifi_dev->
GetMac ()->GetAttribute (
"BE_Txop", ptr);
   265   mobility.SetMobilityModel (
"ns3::ConstantPositionMobilityModel");
   268   positionAlloc->
Add (Vector (0.0, 0.0, 0.0));
   269   positionAlloc->
Add (Vector (10.0, 0.0, 0.0));
   270   positionAlloc->
Add (Vector (20.0, 0.0, 0.0));
   271   positionAlloc->
Add (Vector (30.0, 0.0, 0.0));
   273   positionAlloc->
Add (Vector (distance, 0.0, 0.0));
   274   positionAlloc->
Add (Vector (10 + distance, 0.0, 0.0));
   275   positionAlloc->
Add (Vector (20 + distance, 0.0, 0.0));
   276   positionAlloc->
Add (Vector (30 + distance, 0.0, 0.0));
   278   mobility.SetPositionAllocator (positionAlloc);
   284   stack.Install (wifiApNodes);
   288   address.SetBase (
"192.168.1.0", 
"255.255.255.0");
   290   StaInterfaceA = 
address.Assign (staDeviceA);
   292   ApInterfaceA = 
address.Assign (apDeviceA);
   294   address.SetBase (
"192.168.2.0", 
"255.255.255.0");
   296   StaInterfaceB = 
address.Assign (staDeviceB);
   298   ApInterfaceB = 
address.Assign (apDeviceB);
   300   address.SetBase (
"192.168.3.0", 
"255.255.255.0");
   302   StaInterfaceC = 
address.Assign (staDeviceC);
   304   ApInterfaceC = 
address.Assign (apDeviceC);
   306   address.SetBase (
"192.168.4.0", 
"255.255.255.0");
   308   StaInterfaceD = 
address.Assign (staDeviceD);
   310   ApInterfaceD = 
address.Assign (apDeviceD);
   321   clientA.SetAttribute (
"Interval", 
TimeValue (
Time (
"0.0001"))); 
   322   clientA.SetAttribute (
"PacketSize", 
UintegerValue (payloadSize));
   335   clientB.SetAttribute (
"Interval", 
TimeValue (
Time (
"0.0001"))); 
   336   clientB.SetAttribute (
"PacketSize", 
UintegerValue (payloadSize));
   349   clientC.SetAttribute (
"Interval", 
TimeValue (
Time (
"0.0001"))); 
   350   clientC.SetAttribute (
"PacketSize", 
UintegerValue (payloadSize));
   363   clientD.SetAttribute (
"Interval", 
TimeValue (
Time (
"0.0001"))); 
   364   clientD.SetAttribute (
"PacketSize", 
UintegerValue (payloadSize));
   372       phy.EnablePcap (
"AP_A", apDeviceA.
Get (0));
   373       phy.EnablePcap (
"STA_A", staDeviceA.
Get (0));
   374       phy.EnablePcap (
"AP_B", apDeviceB.
Get (0));
   375       phy.EnablePcap (
"STA_B", staDeviceB.
Get (0));
   376       phy.EnablePcap (
"AP_C", apDeviceC.
Get (0));
   377       phy.EnablePcap (
"STA_C", staDeviceC.
Get (0));
   378       phy.EnablePcap (
"AP_D", apDeviceD.
Get (0));
   379       phy.EnablePcap (
"STA_D", staDeviceD.
Get (0));
   386   uint64_t totalPacketsThroughA = DynamicCast<UdpServer> (serverAppA.
Get (0))->GetReceived ();
   387   uint64_t totalPacketsThroughB = DynamicCast<UdpServer> (serverAppB.
Get (0))->GetReceived ();
   388   uint64_t totalPacketsThroughC = DynamicCast<UdpServer> (serverAppC.
Get (0))->GetReceived ();
   389   uint64_t totalPacketsThroughD = DynamicCast<UdpServer> (serverAppD.
Get (0))->GetReceived ();
   393   double throughput = totalPacketsThroughA * payloadSize * 8 / (simulationTime * 1000000.0);
   394   std::cout << 
"Default configuration (A-MPDU aggregation enabled, 65kB): " << 
'\n'   395             << 
"  Throughput = " << throughput << 
" Mbit/s" << 
'\n';
   396   if (verifyResults && (throughput < 57.5 || throughput > 58.5))
   398       NS_LOG_ERROR (
"Obtained throughput " << throughput << 
" is not in the expected boundaries!");
   403       std::cout << 
"  Maximum TXOP duration (TXOP limit = " << txopLimit << 
"us): "   407           NS_LOG_ERROR (
"Maximum TXOP duration " << netA.
m_max << 
" is not in the expected boundaries!");
   412   throughput = totalPacketsThroughB * payloadSize * 8 / (simulationTime * 1000000.0);
   413   std::cout << 
"Aggregation disabled: " << 
'\n'   414             << 
"  Throughput = " << throughput << 
" Mbit/s" << 
'\n';
   415   if (verifyResults && (throughput < 39 || throughput > 40))
   417       NS_LOG_ERROR (
"Obtained throughput " << throughput << 
" is not in the expected boundaries!");
   422       std::cout << 
"  Maximum TXOP duration (TXOP limit = " << txopLimit << 
"us): "   426           NS_LOG_ERROR (
"Maximum TXOP duration " << netB.
m_max << 
" is not in the expected boundaries!");
   431   throughput = totalPacketsThroughC * payloadSize * 8 / (simulationTime * 1000000.0);
   432   std::cout << 
"A-MPDU disabled and A-MSDU enabled (8kB): " << 
'\n'   433             << 
"  Throughput = " << throughput << 
" Mbit/s" << 
'\n';
   434   if (verifyResults && (throughput < 53 || throughput > 54))
   436       NS_LOG_ERROR (
"Obtained throughput " << throughput << 
" is not in the expected boundaries!");
   441       std::cout << 
"  Maximum TXOP duration (TXOP limit = " << txopLimit << 
"us): "   445           NS_LOG_ERROR (
"Maximum TXOP duration " << netC.
m_max << 
" is not in the expected boundaries!");
   450   throughput = totalPacketsThroughD * payloadSize * 8 / (simulationTime * 1000000.0);
   451   std::cout << 
"A-MPDU enabled (32kB) and A-MSDU enabled (4kB): " << 
'\n'   452             << 
"  Throughput = " << throughput << 
" Mbit/s" << 
'\n';
   453   if (verifyResults && (throughput < 58 || throughput > 59))
   455       NS_LOG_ERROR (
"Obtained throughput " << throughput << 
" is not in the expected boundaries!");
   460       std::cout << 
"  Maximum TXOP duration (TXOP limit = " << txopLimit << 
"us): "   464           NS_LOG_ERROR (
"Maximum TXOP duration " << netD.
m_max << 
" 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. 
 
Handle packet fragmentation and retransmissions for QoS data frames as well as MSDU aggregation (A-MS...
 
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. 
 
Keeps the maximum duration among all TXOPs. 
 
static YansWifiPhyHelper Default(void)
Create a phy helper in a default working state. 
 
helps to create WifiNetDevice objects 
 
void Trace(Time startTime, Time duration)
 
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...
 
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
 
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. 
 
int64_t GetMicroSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit. 
 
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context. 
 
Every class exported by the ns3 library is enclosed in the ns3 namespace. 
 
keep track of a set of node pointers. 
 
Hold objects of type Ptr<T>. 
 
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
 
void SetTxopLimit(Time txopLimit)
Set the TXOP limit. 
 
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. 
 
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit. 
 
#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.