34 #include "ns3/command-line.h"
35 #include "ns3/config.h"
36 #include "ns3/internet-stack-helper.h"
37 #include "ns3/ipv4-address-helper.h"
38 #include "ns3/ipv4-global-routing-helper.h"
40 #include "ns3/mobility-helper.h"
41 #include "ns3/mobility-model.h"
42 #include "ns3/on-off-helper.h"
43 #include "ns3/packet-sink-helper.h"
44 #include "ns3/packet-sink.h"
46 #include "ns3/string.h"
47 #include "ns3/tcp-westwood-plus.h"
48 #include "ns3/yans-wifi-channel.h"
49 #include "ns3/yans-wifi-helper.h"
67 std::cout << now.
GetSeconds() <<
"s: \t" << cur <<
" Mbit/s" << std::endl;
73 main(
int argc,
char* argv[])
75 uint32_t payloadSize = 1472;
76 std::string dataRate =
"100Mbps";
77 std::string tcpVariant =
"TcpNewReno";
78 std::string phyRate =
"HtMcs7";
79 double simulationTime = 10;
80 bool pcapTracing =
false;
84 cmd.AddValue(
"payloadSize",
"Payload size in bytes", payloadSize);
85 cmd.AddValue(
"dataRate",
"Application data ate", dataRate);
86 cmd.AddValue(
"tcpVariant",
87 "Transport protocol to use: TcpNewReno, "
88 "TcpHybla, TcpHighSpeed, TcpHtcp, TcpVegas, TcpScalable, TcpVeno, "
89 "TcpBic, TcpYeah, TcpIllinois, TcpWestwood, TcpWestwoodPlus, TcpLedbat ",
91 cmd.AddValue(
"phyRate",
"Physical layer bitrate", phyRate);
92 cmd.AddValue(
"simulationTime",
"Simulation time in seconds", simulationTime);
93 cmd.AddValue(
"pcap",
"Enable/disable PCAP Tracing", pcapTracing);
94 cmd.Parse(argc, argv);
96 tcpVariant = std::string(
"ns3::") + tcpVariant;
100 "TypeId " << tcpVariant <<
" not found");
133 wifiMac.
SetType(
"ns3::ApWifiMac",
"Ssid", SsidValue(
ssid));
136 apDevice = wifiHelper.
Install(wifiPhy, wifiMac, apWifiNode);
139 wifiMac.
SetType(
"ns3::StaWifiMac",
"Ssid", SsidValue(
ssid));
147 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
148 positionAlloc->Add(Vector(1.0, 1.0, 0.0));
150 mobility.SetPositionAllocator(positionAlloc);
151 mobility.SetMobilityModel(
"ns3::ConstantPositionMobilityModel");
157 stack.Install(networkNodes);
160 address.SetBase(
"10.0.0.0",
"255.255.255.0");
162 apInterface =
address.Assign(apDevice);
173 sink = StaticCast<PacketSink>(sinkApp.
Get(0));
178 server.SetAttribute(
"OnTime",
StringValue(
"ns3::ConstantRandomVariable[Constant=1]"));
179 server.SetAttribute(
"OffTime",
StringValue(
"ns3::ConstantRandomVariable[Constant=0]"));
180 server.SetAttribute(
"DataRate", DataRateValue(
DataRate(dataRate)));
200 double averageThroughput = ((
sink->
GetTotalRx() * 8) / (1e6 * simulationTime));
204 if (averageThroughput < 50)
206 NS_LOG_ERROR(
"Obtained throughput is not in the expected boundaries!");
209 std::cout <<
"\nAverage throughput: " << averageThroughput <<
" Mbit/s" << std::endl;
holds a vector of ns3::Application pointers.
void Start(Time start) const
Start all of the Applications in this container at the start time given as a parameter.
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
Parse command-line arguments.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
static Ipv4Address GetAny()
static void PopulateRoutingTables()
Build a routing database and initialize the routing tables of the nodes in the simulation.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Helper class used to assign positions and mobility models to nodes.
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
uint64_t GetTotalRx() const
void EnablePcap(std::string prefix, Ptr< NetDevice > nd, bool promiscuous=false, bool explicitFilename=false)
Enable pcap output the indicated net device.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static Time Now()
Return the current simulation virtual time.
static void Run()
Run the simulation.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
The IEEE 802.11 SSID Information Element.
Hold variables of type string.
Simulation virtual time values and global simulation resolution.
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
a unique identifier for an interface.
static TypeId LookupByName(std::string name)
Get a TypeId by name.
static bool LookupByNameFailSafe(std::string name, TypeId *tid)
Get a TypeId by name.
Hold an unsigned integer type.
helps to create WifiNetDevice objects
void SetRemoteStationManager(std::string type, Args &&... args)
Helper function used to set the station manager.
virtual void SetStandard(WifiStandard standard)
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer::Iterator first, NodeContainer::Iterator last) const
create MAC layers for a ns3::WifiNetDevice.
void SetType(std::string type, Args &&... args)
void SetPcapDataLinkType(SupportedPcapDataLinkTypes dlt)
Set the data link type of PCAP traces to be used.
void SetErrorRateModel(std::string type, Args &&... args)
Helper function used to set the error rate model.
@ DLT_IEEE802_11_RADIO
Include Radiotap link layer information.
manage and create wifi channel objects for the YANS model.
void SetPropagationDelay(std::string name, Ts &&... args)
void AddPropagationLoss(std::string name, Ts &&... args)
Ptr< YansWifiChannel > Create() const
Make it easy to create and manage PHY objects for the YANS model.
void SetChannel(Ptr< YansWifiChannel > channel)
void SetDefault(std::string name, const AttributeValue &value)
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
void(* DataRate)(DataRate oldValue, DataRate newValue)
TracedValue callback signature for DataRate.
Time Seconds(double value)
Construct a Time in the indicated unit.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< PacketSink > sink
Pointer to the packet sink application.
void CalculateThroughput()
Calculate the throughput.
uint64_t lastTotalRx
The value of the last total received bytes.