|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
56 #include "ns3/core-module.h"
57 #include "ns3/network-module.h"
58 #include "ns3/internet-module.h"
59 #include "ns3/point-to-point-module.h"
60 #include "ns3/applications-module.h"
61 #include "ns3/internet-apps-module.h"
62 #include "ns3/traffic-control-module.h"
63 #include "ns3/flow-monitor-module.h"
86 uint64_t totalPackets = DynamicCast<PacketSink> (app.
Get (0))->GetTotalRx ();
93 std::cout << context <<
"=" << rtt.
GetMilliSeconds () <<
" ms" << std::endl;
96 int main (
int argc,
char *argv[])
98 std::string bandwidth =
"10Mbps";
99 std::string delay =
"5ms";
100 std::string queueDiscType =
"PfifoFast";
101 uint32_t queueDiscSize = 1000;
102 uint32_t netdevicesQueueSize = 50;
105 std::string flowsDatarate =
"20Mbps";
106 uint32_t flowsPacketsSize = 1000;
109 float simDuration = 60;
110 float samplingPeriod = 1;
113 cmd.AddValue (
"bandwidth",
"Bottleneck bandwidth", bandwidth);
114 cmd.AddValue (
"delay",
"Bottleneck delay", delay);
115 cmd.AddValue (
"queueDiscType",
"Bottleneck queue disc type in {PfifoFast, ARED, CoDel, FqCoDel, PIE, prio}", queueDiscType);
116 cmd.AddValue (
"queueDiscSize",
"Bottleneck queue disc size in packets", queueDiscSize);
117 cmd.AddValue (
"netdevicesQueueSize",
"Bottleneck netdevices queue size in packets", netdevicesQueueSize);
118 cmd.AddValue (
"bql",
"Enable byte queue limits on bottleneck netdevices", bql);
119 cmd.AddValue (
"flowsDatarate",
"Upload and download flows datarate", flowsDatarate);
120 cmd.AddValue (
"flowsPacketsSize",
"Upload and download flows packets sizes", flowsPacketsSize);
121 cmd.AddValue (
"startTime",
"Simulation start time",
startTime);
122 cmd.AddValue (
"simDuration",
"Simulation duration in seconds", simDuration);
123 cmd.AddValue (
"samplingPeriod",
"Goodput sampling period in seconds", samplingPeriod);
124 cmd.Parse (argc, argv);
143 bottleneckLink.
SetQueue (
"ns3::DropTailQueue",
"MaxSize",
StringValue (std::to_string (netdevicesQueueSize) +
"p"));
155 if (queueDiscType.compare (
"PfifoFast") == 0)
160 else if (queueDiscType.compare (
"ARED") == 0)
167 else if (queueDiscType.compare (
"CoDel") == 0)
173 else if (queueDiscType.compare (
"FqCoDel") == 0)
179 else if (queueDiscType.compare (
"PIE") == 0)
185 else if (queueDiscType.compare (
"prio") == 0)
187 uint16_t handle = tchBottleneck.
SetRootQueueDisc (
"ns3::PrioQueueDisc",
"Priomap",
204 tchPfifoFastAccess.
Install (devicesAccessLink);
206 address.SetBase (
"192.168.0.0",
"255.255.255.0");
212 qdiscs = tchBottleneck.
Install (devicesBottleneckLink);
224 queueDiscType = queueDiscType +
"-bql";
228 Ptr<Queue<Packet> > queue = StaticCast<PointToPointNetDevice> (devicesBottleneckLink.
Get (0))->GetQueue ();
233 n1Interface.
Add (interfacesAccess.
Get (0));
236 n3Interface.
Add (interfacesBottleneck.
Get (1));
250 uploadApp.
Add (sinkHelperUp.Install (n3));
254 onOffHelperUp.SetAttribute (
"Remote",
AddressValue (socketAddressUp));
255 onOffHelperUp.SetAttribute (
"OnTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=1]"));
256 onOffHelperUp.SetAttribute (
"OffTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=0]"));
257 onOffHelperUp.SetAttribute (
"PacketSize",
UintegerValue (flowsPacketsSize));
258 onOffHelperUp.SetAttribute (
"DataRate",
StringValue (flowsDatarate));
259 sourceApps.
Add (onOffHelperUp.Install (n1));
266 downloadApp.
Add (sinkHelperDown.Install (n1));
270 onOffHelperDown.SetAttribute (
"Remote",
AddressValue (socketAddressDown));
271 onOffHelperDown.SetAttribute (
"OnTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=1]"));
272 onOffHelperDown.SetAttribute (
"OffTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=0]"));
273 onOffHelperDown.SetAttribute (
"PacketSize",
UintegerValue (flowsPacketsSize));
274 onOffHelperDown.SetAttribute (
"DataRate",
StringValue (flowsDatarate));
275 sourceApps.
Add (onOffHelperDown.Install (n3));
293 uploadGoodputStream, samplingPeriod);
296 downloadGoodputStream, samplingPeriod);
holds a vector of ns3::NetDevice pointers
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
Parse command-line arguments.
AttributeValue implementation for Boolean.
static TypeId GetTypeId(void)
Get the type ID.
uint16_t SetRootQueueDisc(const std::string &type, Args &&... args)
Helper function used to set a root queue disc of the given type and with the given attributes.
static Time Now(void)
Return the current simulation virtual time.
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.
void SetQueue(std::string type, 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())
Each point to point net device must have a queue to pass packets through.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
static void PingRtt(std::string context, Time rtt)
void SetDeviceAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each NetDevice created by the helper.
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
AttributeValue implementation for Address.
NetDeviceContainer Install(NodeContainer c)
std::ostream * GetStream(void)
Return a pointer to an ostream previously set in the wrapper.
@ PACKETS
Use number of packets for queue size.
void LimitsTrace(Ptr< OutputStreamWrapper > stream, uint32_t oldVal, uint32_t newVal)
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container.
Helper to enable IP flow monitoring on a set of Nodes.
AttributeValue implementation for TypeId.
static void PopulateRoutingTables(void)
Build a routing database and initialize the routing tables of the nodes in the simulation.
void SetQueueLimits(std::string type, Args &&... args)
Helper function used to add a queue limits object to the transmission queues of the devices.
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
QueueDiscContainer Install(NetDeviceContainer c)
Ptr< FlowMonitor > InstallAll()
Enable flow monitoring on all nodes.
a polymophic address class
Create a IPv4 ping application and associate it to a node.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Ptr< OutputStreamWrapper > CreateFileStream(std::string filename, std::ios::openmode filemode=std::ios::out)
Create and initialize an output stream object we'll use to write the traced bits.
Holds a vector of ns3::QueueDisc pointers.
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.
void BytesInQueueTrace(Ptr< OutputStreamWrapper > stream, uint32_t oldVal, uint32_t newVal)
std::pair< Ptr< Ipv4 >, uint32_t > Get(uint32_t i) const
Get the std::pair of an Ptr<Ipv4> and interface stored at the location specified by the index.
static void GoodputSampling(std::string fileName, ApplicationContainer app, Ptr< OutputStreamWrapper > stream, float period)
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
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.
Manage ASCII trace files for device models.
int64_t GetMilliSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Network device transmission queue interface.
void Connect(std::string path, const CallbackBase &cb)
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.
Callback< R > MakeBoundCallback(R(*fnPtr)(TX), ARG a1)
Make Callbacks with one bound argument.
Build a set of QueueDisc objects.
void Add(const Ipv4InterfaceContainer &other)
Concatenate the entries in the other container with ours.
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
holds a vector of ns3::Application pointers.
Build a set of PointToPointNetDevice objects.
keep track of a set of node pointers.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Hold an unsigned integer type.
ApplicationContainer Install(NodeContainer nodes) const
Install a Ping application on each Node in the provided NodeContainer.
void SetDefault(std::string name, const AttributeValue &value)
ClassIdList AddQueueDiscClasses(uint16_t handle, uint16_t count, const std::string &type, Args &&... args)
Helper function used to add the given number of queue disc classes (of the given type and with the gi...
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
uint16_t AddChildQueueDisc(uint16_t handle, uint16_t classId, const std::string &type, Args &&... args)
Helper function used to attach a child queue disc (of the given type and with the given attributes) t...
Class for representing queue sizes.
aggregate IP/TCP/UDP functionality to existing Nodes.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
std::vector< uint16_t > ClassIdList
Container type for Class IDs.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
void SerializeToXmlFile(std::string fileName, bool enableHistograms, bool enableProbes)
Same as SerializeToXmlStream, but writes to a file instead.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.