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" 110 std::string apTypeString;
113 apTypeString =
"WIFI_PHY_STANDARD_80211g";
117 apTypeString =
"WIFI_PHY_STANDARD_80211n_2_4GHZ";
120 std::cout <<
"Run: " << params.
testName 125 <<
"\n\t apType=" << apTypeString
128 <<
"\n\t rifsMode=" << params.
rifsMode 129 <<
"\n\t nWifiB=" << params.
nWifiB 131 <<
"\n\t nWifiG=" << params.
nWifiG 141 double throughput = 0;
142 uint32_t nWifiB = params.
nWifiB;
143 uint32_t nWifiG = params.
nWifiG;
150 wifiBStaNodes.
Create (nWifiB);
152 wifiGStaNodes.
Create (nWifiG);
154 wifiNNGFStaNodes.
Create (nWifiNNGF);
156 wifiNGFStaNodes.
Create (nWifiNGF);
161 channel.AddPropagationLoss (
"ns3::RangePropagationLossModel");
168 wifi.SetRemoteStationManager (
"ns3::IdealWifiManager");
176 mac.SetType (
"ns3::StaWifiMac",
184 bStaDevice =
wifi.Install (
phy,
mac, wifiBStaNodes);
189 gStaDevice =
wifi.Install (
phy,
mac, wifiGStaNodes);
194 mac.SetType (
"ns3::StaWifiMac",
198 nNGFStaDevice =
wifi.Install (
phy,
mac, wifiNNGFStaNodes);
199 nGFStaDevice =
wifi.Install (
phy,
mac, wifiNGFStaNodes);
204 mac.SetType (
"ns3::ApWifiMac",
244 htConfiguration->SetGreenfieldSupported (
true);
259 positionAlloc->
Add (Vector (0.0, 0.0, 0.0));
260 for (uint32_t i = 0; i < nWifiB; i++)
262 positionAlloc->
Add (Vector (5.0, 0.0, 0.0));
264 for (uint32_t i = 0; i < nWifiG; i++)
266 positionAlloc->
Add (Vector (0.0, 5.0, 0.0));
268 for (uint32_t i = 0; i < nWifiNNGF; i++)
270 positionAlloc->
Add (Vector (0.0, 0.0, 5.0));
272 for (uint32_t i = 0; i < nWifiNGF; i++)
274 positionAlloc->
Add (Vector (0.0, 0.0, 5.0));
277 mobility.SetPositionAllocator (positionAlloc);
278 mobility.SetMobilityModel (
"ns3::ConstantPositionMobilityModel");
282 mobility.Install (wifiNNGFStaNodes);
288 stack.Install (wifiBStaNodes);
289 stack.Install (wifiGStaNodes);
290 stack.Install (wifiNNGFStaNodes);
291 stack.Install (wifiNGFStaNodes);
294 address.SetBase (
"192.168.1.0",
"255.255.255.0");
296 bStaInterface =
address.Assign (bStaDevice);
298 gStaInterface =
address.Assign (gStaDevice);
300 nNGFStaInterface =
address.Assign (nNGFStaDevice);
302 nGFStaInterface =
address.Assign (nGFStaDevice);
304 ApInterface =
address.Assign (apDevice);
317 client.SetAttribute (
"Interval",
TimeValue (
Time (
"0.0002")));
318 client.SetAttribute (
"PacketSize",
UintegerValue (payloadSize));
323 clientApps.Add (client.Install (wifiBStaNodes));
327 clientApps.Add (client.Install (wifiGStaNodes));
331 clientApps.Add (client.Install (wifiNNGFStaNodes));
335 clientApps.Add (client.Install (wifiNGFStaNodes));
343 uint64_t totalPacketsThrough = DynamicCast<UdpServer> (serverApp.
Get (0))->GetReceived ();
344 throughput = totalPacketsThrough * payloadSize * 8 / (simulationTime * 1000000.0);
348 uint16_t
port = 50000;
388 uint64_t totalPacketsThrough = DynamicCast<PacketSink> (serverApp.
Get (0))->GetTotalRx ();
389 throughput += totalPacketsThrough * 8 / (simulationTime * 1000000.0);
395 int main (
int argc,
char *argv[])
419 bool verifyResults = 0;
422 cmd.AddValue (
"payloadSize",
"Payload size in bytes", params.
payloadSize);
423 cmd.AddValue (
"simulationTime",
"Simulation time in seconds", params.
simulationTime);
424 cmd.AddValue (
"isUdp",
"UDP if set to 1, TCP otherwise", params.
isUdp);
425 cmd.AddValue (
"verifyResults",
"Enable/disable results verification at the end of the simulation", verifyResults);
426 cmd.Parse (argc, argv);
429 double throughput = 0;
431 params.
testName =
"g only with all g features disabled";
433 if (verifyResults && (throughput < 22.5 || throughput > 23.5))
435 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
438 std::cout <<
"Throughput: " << throughput <<
" Mbit/s \n" << std::endl;
440 params.
testName =
"g only with short slot time enabled";
446 if (verifyResults && (throughput < 29 || throughput > 30))
448 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
451 std::cout <<
"Throughput: " << throughput <<
" Mbit/s \n" << std::endl;
453 params.
testName =
"Mixed b/g with all g features disabled";
459 if (verifyResults && (throughput < 22.5 || throughput > 23.5))
461 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
464 std::cout <<
"Throughput: " << throughput <<
" Mbit/s \n" << std::endl;
466 params.
testName =
"Mixed b/g with short plcp preamble enabled";
472 if (verifyResults && (throughput < 22.5 || throughput > 23.5))
474 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
477 std::cout <<
"Throughput: " << throughput <<
" Mbit/s \n" << std::endl;
479 params.
testName =
"Mixed b/g with short slot time enabled using RTS-CTS protection";
486 if (verifyResults && (throughput < 19 || throughput > 20))
488 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
491 std::cout <<
"Throughput: " << throughput <<
" Mbit/s \n" << std::endl;
493 params.
testName =
"Mixed b/g with short plcp preamble enabled using RTS-CTS protection";
499 if (verifyResults && (throughput < 19 || throughput > 20))
501 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
504 std::cout <<
"Throughput: " << throughput <<
" Mbit/s \n" << std::endl;
506 params.
testName =
"Mixed b/g with short slot time enabled using CTS-TO-SELF protection";
513 if (verifyResults && (throughput < 20.5 || throughput > 21.5))
515 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
518 std::cout <<
"Throughput: " << throughput <<
" Mbit/s \n" << std::endl;
520 params.
testName =
"Mixed b/g with short plcp preamble enabled using CTS-TO-SELF protection";
526 if (verifyResults && (throughput < 20.5 || throughput > 21.5))
528 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
531 std::cout <<
"Throughput: " << throughput <<
" Mbit/s \n" << std::endl;
533 params.
testName =
"HT GF not supported";
548 if (verifyResults && (throughput < 43 || throughput > 44))
550 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
553 std::cout <<
"Throughput: " << throughput <<
" Mbit/s \n" << std::endl;
555 params.
testName =
"HT only with GF used";
570 if (verifyResults && (throughput < 44 || throughput > 45))
572 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
575 std::cout <<
"Throughput: " << throughput <<
" Mbit/s \n" << std::endl;
577 params.
testName =
"HT only with GF allowed but disabled by protection";
592 if (verifyResults && (throughput < 43 || throughput > 44))
594 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
597 std::cout <<
"Throughput: " << throughput <<
" Mbit/s \n" << std::endl;
599 params.
testName =
"HT only with GF not supported by the receiver";
614 if (verifyResults && (throughput < 43 || throughput > 44))
616 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
619 std::cout <<
"Throughput: " << throughput <<
" Mbit/s \n" << std::endl;
621 params.
testName =
"Mixed HT/non-HT with GF enabled";
636 if (verifyResults && (throughput < 44 || throughput > 45))
638 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
641 std::cout <<
"Throughput: " << throughput <<
" Mbit/s \n" << std::endl;
643 params.
testName =
"HT only with RIFS enabled";
660 if (verifyResults && (throughput < 44 || throughput > 45))
662 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
665 std::cout <<
"Throughput: " << throughput <<
" Mbit/s \n" << std::endl;
667 params.
testName =
"Mixed HT/non-HT with RIFS enabled but not forbidden";
684 if (verifyResults && (throughput < 44 || throughput > 45))
686 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
689 std::cout <<
"Throughput: " << throughput <<
" Mbit/s \n" << std::endl;
691 params.
testName =
"Mixed HT/non-HT with RIFS enabled but forbidden";
708 if (verifyResults && (throughput < 43 || throughput > 44))
710 NS_LOG_ERROR (
"Obtained throughput " << throughput <<
" is not in the expected boundaries!");
713 std::cout <<
"Throughput: " << throughput <<
" Mbit/s \n" << std::endl;
ERP-OFDM PHY (Clause 19, Section 19.5)
Helper class for UAN CW MAC example.
holds a vector of ns3::Application pointers.
Simulation virtual time values and global simulation resolution.
static Ipv4Address GetAny(void)
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.
void Set(std::string path, const AttributeValue &value)
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.
ApplicationContainer Install(NodeContainer c) const
Install an ns3::PacketSinkApplication on each node of the input container configured with all the att...
aggregate IP/TCP/UDP functionality to existing Nodes.
uint32_t nWifiNGreenfield
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes...
HT PHY for the 2.4 GHz band (clause 20)
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.
a polymophic address class
WifiPhyStandard
Identifies the PHY specification that a Wifi device is configured to use.
ApplicationContainer Install(NodeContainer c) const
Install an ns3::OnOffApplication on each node of the input container configured with all the attribut...
double Run(Parameters params)
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.
bool nGreenfieldHasTraffic
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.
Hold objects of type Ptr<T>.
std::string erpProtectionMode
DSSS PHY (Clause 15) and HR/DSSS PHY (Clause 18)
manage and create wifi channel objects for the yans model.
create MAC layers for a ns3::WifiNetDevice.
uint32_t nWifiNNonGreenfield
The IEEE 802.11 SSID Information Element.
Helper class used to assign positions and mobility models to nodes.
AttributeValue implementation for Address.
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
ApplicationContainer Install(NodeContainer c)
Create one UDP server application on each of the Nodes in the NodeContainer.
void experiment(std::string queue_disc_type)
AttributeValue implementation for DataRate.
void SetTxopLimit(Time txopLimit)
Set the TXOP limit.
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
bool nNonGreenfieldHasTraffic
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.
Ptr< HtConfiguration > GetHtConfiguration(void) const
Include Radiotap link layer information.
void GetAttribute(std::string name, AttributeValue &value) const
Get the value of an attribute, raising fatal errors if unsuccessful.
bool apSupportsGreenfield
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)
Helper function used to set the underlying application attributes.
bool enableShortPlcpPreamble