|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
21 #include "ns3/command-line.h"
22 #include "ns3/config.h"
23 #include "ns3/string.h"
24 #include "ns3/pointer.h"
26 #include "ns3/yans-wifi-helper.h"
28 #include "ns3/mobility-helper.h"
29 #include "ns3/internet-stack-helper.h"
30 #include "ns3/ipv4-address-helper.h"
31 #include "ns3/udp-client-server-helper.h"
32 #include "ns3/on-off-helper.h"
33 #include "ns3/yans-wifi-channel.h"
34 #include "ns3/wifi-net-device.h"
35 #include "ns3/qos-txop.h"
36 #include "ns3/wifi-mac.h"
37 #include "ns3/packet-sink-helper.h"
38 #include "ns3/packet-sink.h"
39 #include "ns3/ht-configuration.h"
97 std::string apTypeString;
100 apTypeString =
"WIFI_STANDARD_80211g";
104 apTypeString =
"WIFI_STANDARD_80211n_2_4GHZ";
107 std::cout <<
"Run: " << params.
testName
112 <<
"\n\t apType=" << apTypeString
113 <<
"\n\t nWifiB=" << params.
nWifiB
115 <<
"\n\t nWifiG=" << params.
nWifiG
117 <<
"\n\t nWifiN=" << params.
nWifiN
123 double throughput = 0;
124 uint32_t nWifiB = params.
nWifiB;
125 uint32_t nWifiG = params.
nWifiG;
126 uint32_t nWifiN = params.
nWifiN;
131 wifiBStaNodes.
Create (nWifiB);
133 wifiGStaNodes.
Create (nWifiG);
135 wifiNStaNodes.
Create (nWifiN);
140 channel.AddPropagationLoss (
"ns3::RangePropagationLossModel");
146 wifi.SetRemoteStationManager (
"ns3::IdealWifiManager");
154 mac.SetType (
"ns3::StaWifiMac",
162 bStaDevice =
wifi.Install (
phy,
mac, wifiBStaNodes);
167 gStaDevice =
wifi.Install (
phy,
mac, wifiGStaNodes);
172 mac.SetType (
"ns3::StaWifiMac",
176 nStaDevice =
wifi.Install (
phy,
mac, wifiNStaNodes);
181 mac.SetType (
"ns3::ApWifiMac",
217 positionAlloc->
Add (Vector (0.0, 0.0, 0.0));
218 for (uint32_t i = 0; i < nWifiB; i++)
220 positionAlloc->
Add (Vector (5.0, 0.0, 0.0));
222 for (uint32_t i = 0; i < nWifiG; i++)
224 positionAlloc->
Add (Vector (0.0, 5.0, 0.0));
226 for (uint32_t i = 0; i < nWifiN; i++)
228 positionAlloc->
Add (Vector (0.0, 0.0, 5.0));
231 mobility.SetPositionAllocator (positionAlloc);
232 mobility.SetMobilityModel (
"ns3::ConstantPositionMobilityModel");
241 stack.Install (wifiBStaNodes);
242 stack.Install (wifiGStaNodes);
243 stack.Install (wifiNStaNodes);
246 address.SetBase (
"192.168.1.0",
"255.255.255.0");
248 bStaInterface =
address.Assign (bStaDevice);
250 gStaInterface =
address.Assign (gStaDevice);
252 nStaInterface =
address.Assign (nStaDevice);
254 ApInterface =
address.Assign (apDevice);
289 uint64_t totalPacketsThrough = DynamicCast<UdpServer> (serverApp.
Get (0))->GetReceived ();
290 throughput = totalPacketsThrough * payloadSize * 8 / (simulationTime * 1000000.0);
294 uint16_t
port = 50000;
330 uint64_t totalPacketsThrough = DynamicCast<PacketSink> (serverApp.
Get (0))->GetTotalRx ();
331 throughput += totalPacketsThrough * 8 / (simulationTime * 1000000.0);
337 int main (
int argc,
char *argv[])
356 bool verifyResults = 0;
359 cmd.AddValue (
"payloadSize",
"Payload size in bytes", params.
payloadSize);
360 cmd.AddValue (
"simulationTime",
"Simulation time in seconds", params.
simulationTime);
361 cmd.AddValue (
"isUdp",
"UDP if set to 1, TCP otherwise", params.
isUdp);
362 cmd.AddValue (
"verifyResults",
"Enable/disable results verification at the end of the simulation", verifyResults);
363 cmd.Parse (argc, argv);
366 double throughput = 0;
368 params.
testName =
"g only with all g features disabled";
370 if (verifyResults && (throughput < 22.5 || throughput > 23.5))
372 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
375 std::cout <<
"Throughput: " << throughput <<
" Mbit/s \n" << std::endl;
377 params.
testName =
"g only with short slot time enabled";
383 if (verifyResults && (throughput < 29 || throughput > 30))
385 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
388 std::cout <<
"Throughput: " << throughput <<
" Mbit/s \n" << std::endl;
390 params.
testName =
"Mixed b/g with all g features disabled";
396 if (verifyResults && (throughput < 22.5 || throughput > 23.5))
398 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
401 std::cout <<
"Throughput: " << throughput <<
" Mbit/s \n" << std::endl;
403 params.
testName =
"Mixed b/g with short plcp preamble enabled";
409 if (verifyResults && (throughput < 22.5 || throughput > 23.5))
411 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
414 std::cout <<
"Throughput: " << throughput <<
" Mbit/s \n" << std::endl;
416 params.
testName =
"Mixed b/g with short slot time enabled using RTS-CTS protection";
423 if (verifyResults && (throughput < 19 || throughput > 20))
425 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
428 std::cout <<
"Throughput: " << throughput <<
" Mbit/s \n" << std::endl;
430 params.
testName =
"Mixed b/g with short plcp preamble enabled using RTS-CTS protection";
436 if (verifyResults && (throughput < 19 || throughput > 20))
438 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
441 std::cout <<
"Throughput: " << throughput <<
" Mbit/s \n" << std::endl;
443 params.
testName =
"Mixed b/g with short slot time enabled using CTS-TO-SELF protection";
450 if (verifyResults && (throughput < 20.5 || throughput > 21.5))
452 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
455 std::cout <<
"Throughput: " << throughput <<
" Mbit/s \n" << std::endl;
457 params.
testName =
"Mixed b/g with short plcp preamble enabled using CTS-TO-SELF protection";
463 if (verifyResults && (throughput < 20.5 || throughput > 21.5))
465 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
468 std::cout <<
"Throughput: " << throughput <<
" Mbit/s \n" << std::endl;
482 if (verifyResults && (throughput < 44 || throughput > 45))
484 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
487 std::cout <<
"Throughput: " << throughput <<
" Mbit/s \n" << std::endl;
489 params.
testName =
"Mixed HT/non-HT";
501 if (verifyResults && (throughput < 44 || throughput > 45))
503 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
506 std::cout <<
"Throughput: " << throughput <<
" Mbit/s \n" << std::endl;
holds a vector of ns3::NetDevice pointers
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
AttributeValue implementation for DataRate.
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
void SetAttribute(std::string name, const AttributeValue &value)
Record an attribute to be set in each Application after it is is created.
static YansWifiChannelHelper Default(void)
Create a channel helper in a default working state.
Create a client application which sends UDP packets carrying a 32bit sequence number and a 64 bit tim...
Make it easy to create and manage PHY objects for the YANS model.
Parse command-line arguments.
void Add(Vector v)
Add a position to the list of positions.
void Set(std::string path, const AttributeValue &value)
AttributeValue implementation for Boolean.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
helps to create WifiNetDevice objects
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.
AttributeValue implementation for Address.
Hold objects of type Ptr<T>.
std::string erpProtectionMode
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
AttributeValue implementation for Ssid.
The IEEE 802.11 SSID Information Element.
Create a server application which waits for input UDP packets and uses the information carried into t...
void experiment(std::string queue_disc_type)
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
a polymophic address class
void GetAttribute(std::string name, AttributeValue &value) const
Get the value of an attribute, raising fatal errors if unsuccessful.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
Helper class for UAN CW MAC example.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Gnuplot2dDataset Run(const WifiHelper &wifi, const YansWifiPhyHelper &wifiPhy, const WifiMacHelper &wifiMac, const YansWifiChannelHelper &wifiChannel)
Simulation virtual time values and global simulation resolution.
void SetAttribute(std::string name, const AttributeValue &value)
Helper function used to set the underlying application attributes.
Handle packet fragmentation and retransmissions for QoS data frames as well as MSDU aggregation (A-MS...
static void Run(void)
Run the simulation.
Hold variables of type string.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
ApplicationContainer Install(NodeContainer c) const
Install an ns3::OnOffApplication on each node of the input container configured with all the attribut...
static Ipv4Address GetAny(void)
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter.
Time Seconds(double value)
Construct a Time in the indicated unit.
bool enableShortPhyPreamble
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
holds a vector of ns3::Application pointers.
ApplicationContainer Install(NodeContainer c)
AttributeValue implementation for Time.
void SetTxopLimit(Time txopLimit)
Set the TXOP limit.
ApplicationContainer Install(NodeContainer c)
Create one UDP server application on each of the Nodes in the NodeContainer.
keep track of a set of node pointers.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Hold an unsigned integer type.
manage and create wifi channel objects for the YANS model.
create MAC layers for a ns3::WifiNetDevice.
void SetDefault(std::string name, const AttributeValue &value)
@ WIFI_STANDARD_80211n_2_4GHZ
WifiStandard
Identifies the allowed configurations that a Wifi device is configured to use.
aggregate IP/TCP/UDP functionality to existing Nodes.
Helper class used to assign positions and mobility models to nodes.
ApplicationContainer Install(NodeContainer c) const
Install an ns3::PacketSinkApplication on each node of the input container configured with all the att...
Ptr< WifiMac > GetMac(void) const