21 #include "ns3/command-line.h" 22 #include "ns3/string.h" 23 #include "ns3/pointer.h" 25 #include "ns3/yans-wifi-helper.h" 27 #include "ns3/mobility-helper.h" 28 #include "ns3/internet-stack-helper.h" 29 #include "ns3/ipv4-address-helper.h" 30 #include "ns3/udp-client-server-helper.h" 31 #include "ns3/on-off-helper.h" 32 #include "ns3/yans-wifi-channel.h" 33 #include "ns3/wifi-net-device.h" 34 #include "ns3/qos-txop.h" 35 #include "ns3/wifi-mac.h" 68 int main (
int argc,
char *argv[])
70 uint32_t payloadSize = 1472;
71 double simulationTime = 10;
74 bool verifyResults = 0;
77 cmd.AddValue (
"payloadSize",
"Payload size in bytes", payloadSize);
78 cmd.AddValue (
"simulationTime",
"Simulation time in seconds", simulationTime);
79 cmd.AddValue (
"distance",
"Distance in meters between the station and the access point", distance);
80 cmd.AddValue (
"enablePcap",
"Enable/disable pcap file generation",
enablePcap);
81 cmd.AddValue (
"verifyResults",
"Enable/disable results verification at the end of the simulation", verifyResults);
82 cmd.Parse (argc, argv);
95 wifi.SetRemoteStationManager (
"ns3::IdealWifiManager");
98 NetDeviceContainer staDeviceA, staDeviceB, staDeviceC, staDeviceD, apDeviceA, apDeviceB, apDeviceC, apDeviceD;
104 mac.SetType (
"ns3::StaWifiMac",
109 mac.SetType (
"ns3::ApWifiMac",
118 mac.SetType (
"ns3::StaWifiMac",
124 mac.SetType (
"ns3::ApWifiMac",
143 mac.SetType (
"ns3::StaWifiMac",
149 mac.SetType (
"ns3::ApWifiMac",
158 mac.SetType (
"ns3::StaWifiMac",
164 mac.SetType (
"ns3::ApWifiMac",
172 wifi_dev = DynamicCast<WifiNetDevice> (dev);
173 wifi_mac = wifi_dev->
GetMac ();
174 wifi_mac->GetAttribute (
"VI_Txop", ptr);
181 mobility.SetMobilityModel (
"ns3::ConstantPositionMobilityModel");
184 positionAlloc->
Add (Vector (0.0, 0.0, 0.0));
185 positionAlloc->
Add (Vector (10.0, 0.0, 0.0));
186 positionAlloc->
Add (Vector (20.0, 0.0, 0.0));
187 positionAlloc->
Add (Vector (30.0, 0.0, 0.0));
189 positionAlloc->
Add (Vector (distance, 0.0, 0.0));
190 positionAlloc->
Add (Vector (10 + distance, 0.0, 0.0));
191 positionAlloc->
Add (Vector (20 + distance, 0.0, 0.0));
192 positionAlloc->
Add (Vector (30 + distance, 0.0, 0.0));
196 mobility.SetPositionAllocator (positionAlloc);
202 stack.Install (wifiApNodes);
206 address.SetBase (
"192.168.1.0",
"255.255.255.0");
208 StaInterfaceA =
address.Assign (staDeviceA);
210 ApInterfaceA =
address.Assign (apDeviceA);
212 address.SetBase (
"192.168.2.0",
"255.255.255.0");
214 StaInterfaceB =
address.Assign (staDeviceB);
216 ApInterfaceB =
address.Assign (apDeviceB);
218 address.SetBase (
"192.168.3.0",
"255.255.255.0");
220 StaInterfaceC =
address.Assign (staDeviceC);
222 ApInterfaceC =
address.Assign (apDeviceC);
224 address.SetBase (
"192.168.4.0",
"255.255.255.0");
226 StaInterfaceD =
address.Assign (staDeviceD);
228 ApInterfaceD =
address.Assign (apDeviceD);
231 uint16_t
port = 5001;
240 OnOffHelper clientA (
"ns3::UdpSocketFactory", destA);
241 clientA.SetAttribute (
"OnTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=1]"));
242 clientA.SetAttribute (
"OffTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=0]"));
243 clientA.SetAttribute (
"DataRate",
StringValue (
"100000kb/s"));
244 clientA.SetAttribute (
"PacketSize",
UintegerValue (payloadSize));
258 OnOffHelper clientB (
"ns3::UdpSocketFactory", destB);
259 clientB.SetAttribute (
"OnTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=1]"));
260 clientB.SetAttribute (
"OffTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=0]"));
261 clientB.SetAttribute (
"DataRate",
StringValue (
"100000kb/s"));
262 clientB.SetAttribute (
"PacketSize",
UintegerValue (payloadSize));
276 OnOffHelper clientC (
"ns3::UdpSocketFactory", destC);
277 clientC.SetAttribute (
"OnTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=1]"));
278 clientC.SetAttribute (
"OffTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=0]"));
279 clientC.SetAttribute (
"DataRate",
StringValue (
"100000kb/s"));
280 clientC.SetAttribute (
"PacketSize",
UintegerValue (payloadSize));
294 OnOffHelper clientD (
"ns3::UdpSocketFactory", destD);
295 clientD.SetAttribute (
"OnTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=1]"));
296 clientD.SetAttribute (
"OffTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=0]"));
297 clientD.SetAttribute (
"DataRate",
StringValue (
"100000kb/s"));
298 clientD.SetAttribute (
"PacketSize",
UintegerValue (payloadSize));
306 phy.EnablePcap (
"AP_A", apDeviceA.
Get (0));
307 phy.EnablePcap (
"STA_A", staDeviceA.
Get (0));
308 phy.EnablePcap (
"AP_B", apDeviceB.
Get (0));
309 phy.EnablePcap (
"STA_B", staDeviceB.
Get (0));
310 phy.EnablePcap (
"AP_C", apDeviceC.
Get (0));
311 phy.EnablePcap (
"STA_C", staDeviceC.
Get (0));
312 phy.EnablePcap (
"AP_D", apDeviceD.
Get (0));
313 phy.EnablePcap (
"STA_D", staDeviceD.
Get (0));
320 uint64_t totalPacketsThroughA = DynamicCast<UdpServer> (serverAppA.
Get (0))->GetReceived ();
321 uint64_t totalPacketsThroughB = DynamicCast<UdpServer> (serverAppB.
Get (0))->GetReceived ();
322 uint64_t totalPacketsThroughC = DynamicCast<UdpServer> (serverAppC.
Get (0))->GetReceived ();
323 uint64_t totalPacketsThroughD = DynamicCast<UdpServer> (serverAppD.
Get (0))->GetReceived ();
327 double throughput = totalPacketsThroughA * payloadSize * 8 / (simulationTime * 1000000.0);
328 std::cout <<
"Throughput for AC_BE with default TXOP limit (0ms): " << throughput <<
" Mbit/s" <<
'\n';
329 if (verifyResults && (throughput < 28 || throughput > 29))
331 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
335 throughput = totalPacketsThroughB * payloadSize * 8 / (simulationTime * 1000000.0);
336 std::cout <<
"Throughput for AC_BE with non-default TXOP limit (3.008ms): " << throughput <<
" Mbit/s" <<
'\n';
337 if (verifyResults && (throughput < 35.5 || throughput > 36.5))
339 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
343 throughput = totalPacketsThroughC * payloadSize * 8 / (simulationTime * 1000000.0);
344 std::cout <<
"Throughput for AC_VI with default TXOP limit (3.008ms): " << throughput <<
" Mbit/s" <<
'\n';
345 if (verifyResults && (throughput < 36 || throughput > 37))
347 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
351 throughput = totalPacketsThroughD * payloadSize * 8 / (simulationTime * 1000000.0);
352 std::cout <<
"Throughput for AC_VI with non-default TXOP limit (0ms): " << throughput <<
" Mbit/s" <<
'\n';
353 if (verifyResults && (throughput < 31.5 || throughput > 32.5))
355 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.
Smart pointer class similar to boost::intrusive_ptr.
AttributeValue implementation for Boolean.
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.
static YansWifiPhyHelper Default(void)
Create a phy helper in a default working state.
helps to create WifiNetDevice objects
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
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().
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 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.
void GetAttribute(std::string name, AttributeValue &value) const
Get the value of an attribute, raising fatal errors if unsuccessful.
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.