|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
35 #include "ns3/command-line.h"
36 #include "ns3/config.h"
37 #include "ns3/string.h"
39 #include "ns3/yans-wifi-helper.h"
41 #include "ns3/mobility-helper.h"
42 #include "ns3/on-off-helper.h"
43 #include "ns3/yans-wifi-channel.h"
44 #include "ns3/mobility-model.h"
45 #include "ns3/packet-sink.h"
46 #include "ns3/packet-sink-helper.h"
47 #include "ns3/tcp-westwood.h"
48 #include "ns3/internet-stack-helper.h"
49 #include "ns3/ipv4-address-helper.h"
50 #include "ns3/ipv4-global-routing-helper.h"
64 std::cout << now.
GetSeconds () <<
"s: \t" << cur <<
" Mbit/s" << std::endl;
70 main (
int argc,
char *argv[])
72 uint32_t payloadSize = 1472;
73 std::string dataRate =
"100Mbps";
74 std::string tcpVariant =
"TcpNewReno";
75 std::string phyRate =
"HtMcs7";
76 double simulationTime = 10;
77 bool pcapTracing =
false;
81 cmd.AddValue (
"payloadSize",
"Payload size in bytes", payloadSize);
82 cmd.AddValue (
"dataRate",
"Application data ate", dataRate);
83 cmd.AddValue (
"tcpVariant",
"Transport protocol to use: TcpNewReno, "
84 "TcpHybla, TcpHighSpeed, TcpHtcp, TcpVegas, TcpScalable, TcpVeno, "
85 "TcpBic, TcpYeah, TcpIllinois, TcpWestwood, TcpWestwoodPlus, TcpLedbat ", tcpVariant);
86 cmd.AddValue (
"phyRate",
"Physical layer bitrate", phyRate);
87 cmd.AddValue (
"simulationTime",
"Simulation time in seconds", simulationTime);
88 cmd.AddValue (
"pcap",
"Enable/disable PCAP Tracing", pcapTracing);
89 cmd.Parse (argc, argv);
91 tcpVariant = std::string (
"ns3::") + tcpVariant;
93 if (tcpVariant.compare (
"ns3::TcpWestwoodPlus") == 0)
134 wifiMac.
SetType (
"ns3::ApWifiMac",
138 apDevice = wifiHelper.
Install (wifiPhy, wifiMac, apWifiNode);
141 wifiMac.
SetType (
"ns3::StaWifiMac",
150 positionAlloc->
Add (Vector (0.0, 0.0, 0.0));
151 positionAlloc->
Add (Vector (1.0, 1.0, 0.0));
153 mobility.SetPositionAllocator (positionAlloc);
154 mobility.SetMobilityModel (
"ns3::ConstantPositionMobilityModel");
160 stack.Install (networkNodes);
163 address.SetBase (
"10.0.0.0",
"255.255.255.0");
165 apInterface =
address.Assign (apDevice);
175 sink = StaticCast<PacketSink> (sinkApp.
Get (0));
179 server.SetAttribute (
"PacketSize",
UintegerValue (payloadSize));
180 server.SetAttribute (
"OnTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=1]"));
181 server.SetAttribute (
"OffTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=0]"));
202 double averageThroughput = ((
sink->
GetTotalRx () * 8) / (1e6 * simulationTime));
206 if (averageThroughput < 50)
208 NS_LOG_ERROR (
"Obtained throughput is not in the expected boundaries!");
211 std::cout <<
"\nAverage throughput: " << averageThroughput <<
" Mbit/s" << std::endl;
holds a vector of ns3::NetDevice pointers
@ WIFI_STANDARD_80211n_5GHZ
a unique identifier for an interface.
#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.
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 SetPropagationDelay(std::string name, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
void EnablePcap(std::string prefix, Ptr< NetDevice > nd, bool promiscuous=false, bool explicitFilename=false)
Enable pcap output the indicated net device.
static Time Now(void)
Return the current simulation virtual time.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
helps to create WifiNetDevice objects
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void AddPropagationLoss(std::string name, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
@ DLT_IEEE802_11_RADIO
Include Radiotap link layer information.
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
void SetErrorRateModel(std::string name, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
void SetChannel(Ptr< YansWifiChannel > channel)
This class can be used to hold variables of floating point type such as 'double' or 'float'.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Hold variables of type enum.
AttributeValue implementation for Ssid.
The IEEE 802.11 SSID Information Element.
Class for representing data rates.
AttributeValue implementation for TypeId.
Ptr< YansWifiChannel > Create(void) const
static void PopulateRoutingTables(void)
Build a routing database and initialize the routing tables of the nodes in the simulation.
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
uint64_t GetTotalRx() const
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
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.
Simulation virtual time values and global simulation resolution.
static bool LookupByNameFailSafe(std::string name, TypeId *tid)
Get a TypeId by name.
static void Run(void)
Run the simulation.
void SetRemoteStationManager(std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
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.
void CalculateThroughput()
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
void SetPcapDataLinkType(SupportedPcapDataLinkTypes dlt)
Set the data link type of PCAP traces to be used.
static Ipv4Address GetAny(void)
virtual void SetStandard(WifiStandard standard)
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.
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
holds a vector of ns3::Application pointers.
keep track of a set of node pointers.
void SetType(std::string type, Args &&... args)
static TypeId GetTypeId(void)
Get the type ID.
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)
aggregate IP/TCP/UDP functionality to existing Nodes.
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Helper class used to assign positions and mobility models to nodes.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer::Iterator first, NodeContainer::Iterator last) const