|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
40 #include "ns3/core-module.h"
41 #include "ns3/network-module.h"
42 #include "ns3/internet-module.h"
43 #include "ns3/point-to-point-module.h"
44 #include "ns3/applications-module.h"
45 #include "ns3/error-model.h"
46 #include "ns3/tcp-header.h"
47 #include "ns3/udp-header.h"
49 #include "ns3/event-id.h"
50 #include "ns3/flow-monitor-helper.h"
51 #include "ns3/ipv4-global-routing-helper.h"
52 #include "ns3/traffic-control-module.h"
207 int main (
int argc,
char *argv[])
209 std::string transport_prot =
"TcpWestwood";
210 double error_p = 0.0;
211 std::string bandwidth =
"2Mbps";
212 std::string delay =
"0.01ms";
213 std::string access_bandwidth =
"10Mbps";
214 std::string access_delay =
"45ms";
216 std::string prefix_file_name =
"TcpVariantsComparison";
217 uint64_t data_mbytes = 0;
218 uint32_t mtu_bytes = 400;
219 uint16_t num_flows = 1;
220 double duration = 100.0;
222 bool flow_monitor =
false;
225 std::string queue_disc_type =
"ns3::PfifoFastQueueDisc";
226 std::string recovery =
"ns3::TcpClassicRecovery";
230 cmd.AddValue (
"transport_prot",
"Transport protocol to use: TcpNewReno, TcpLinuxReno, "
231 "TcpHybla, TcpHighSpeed, TcpHtcp, TcpVegas, TcpScalable, TcpVeno, "
232 "TcpBic, TcpYeah, TcpIllinois, TcpWestwood, TcpWestwoodPlus, TcpLedbat, "
233 "TcpLp, TcpDctcp, TcpCubic, TcpBbr", transport_prot);
234 cmd.AddValue (
"error_p",
"Packet error rate", error_p);
235 cmd.AddValue (
"bandwidth",
"Bottleneck bandwidth", bandwidth);
236 cmd.AddValue (
"delay",
"Bottleneck delay", delay);
237 cmd.AddValue (
"access_bandwidth",
"Access link bandwidth", access_bandwidth);
238 cmd.AddValue (
"access_delay",
"Access link delay", access_delay);
239 cmd.AddValue (
"tracing",
"Flag to enable/disable tracing",
tracing);
240 cmd.AddValue (
"prefix_name",
"Prefix of output trace file", prefix_file_name);
241 cmd.AddValue (
"data",
"Number of Megabytes of data to transmit", data_mbytes);
242 cmd.AddValue (
"mtu",
"Size of IP packets to send in bytes", mtu_bytes);
243 cmd.AddValue (
"num_flows",
"Number of flows", num_flows);
244 cmd.AddValue (
"duration",
"Time to allow flows to run in seconds", duration);
245 cmd.AddValue (
"run",
"Run index (for setting repeatable seeds)", run);
246 cmd.AddValue (
"flow_monitor",
"Enable flow monitor", flow_monitor);
247 cmd.AddValue (
"pcap_tracing",
"Enable or disable PCAP tracing", pcap);
248 cmd.AddValue (
"queue_disc_type",
"Queue disc type for gateway (e.g. ns3::CoDelQueueDisc)", queue_disc_type);
249 cmd.AddValue (
"sack",
"Enable or disable SACK option", sack);
250 cmd.AddValue (
"recovery",
"Recovery algorithm type to use (e.g., ns3::TcpPrrRecovery", recovery);
251 cmd.Parse (argc, argv);
253 transport_prot = std::string (
"ns3::") + transport_prot;
272 uint32_t tcp_adu_size = mtu_bytes - 20 - (ip_header + tcp_header);
276 double start_time = 0.1;
277 double stop_time = start_time + duration;
287 if (transport_prot.compare (
"ns3::TcpWestwoodPlus") == 0)
305 sources.
Create (num_flows);
334 address.SetBase (
"10.0.0.0",
"255.255.255.0");
344 DataRate access_b (access_bandwidth);
346 Time access_d (access_delay);
347 Time bottle_d (delay);
349 uint32_t size =
static_cast<uint32_t
>((
std::min (access_b, bottle_b).GetBitRate () / 8) *
350 ((access_d + bottle_d) * 2).GetSeconds ());
357 for (uint32_t i = 0; i < num_flows; i++)
366 if (queue_disc_type.compare (
"ns3::PfifoFastQueueDisc") == 0)
370 else if (queue_disc_type.compare (
"ns3::CoDelQueueDisc") == 0)
376 NS_FATAL_ERROR (
"Queue not recognized. Allowed values are ns3::CoDelQueueDisc or ns3::PfifoFastQueueDisc");
386 uint16_t
port = 50000;
390 for (uint16_t i = 0; i < sources.
GetN (); i++)
395 ftp.SetAttribute (
"Remote", remoteAddress);
397 ftp.SetAttribute (
"MaxBytes",
UintegerValue (data_mbytes * 1000000));
414 ascii.open ((prefix_file_name +
"-ascii").c_str ());
417 stack.EnableAsciiIpv4All (ascii_wrap);
holds a vector of ns3::NetDevice pointers
a unique identifier for an interface.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
static Ptr< OutputStreamWrapper > cWndStream
static void TraceRto(std::string rto_tr_file_name)
Parse command-line arguments.
AttributeValue implementation for Boolean.
static void TraceInFlight(std::string &in_flight_file_name)
static TypeId GetTypeId(void)
Get the type ID.
static uint32_t cWndValue
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 Ptr< OutputStreamWrapper > nextTxStream
static void RtoTracer(Time oldval, Time newval)
static Time Now(void)
Return the current simulation virtual time.
bool tracing
Flag to enable/disable generation of tracing files.
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.
static Ptr< OutputStreamWrapper > ssThreshStream
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void SetUnit(enum ErrorUnit error_unit)
static void TraceNextRx(std::string &next_rx_seq_file_name)
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.
static uint32_t ssThreshValue
void EnablePcapAll(std::string prefix, bool promiscuous=false)
Enable pcap output on each device (which is of the appropriate type) in the set of all nodes created ...
AttributeValue implementation for Address.
NetDeviceContainer Install(NodeContainer c)
A helper to make it easier to instantiate an ns3::BulkSendApplication on a set of nodes.
uint32_t GetN(void) const
Get the number of Ptr<Node> stored in this container.
Hold objects of type Ptr<T>.
std::ostream * GetStream(void)
Return a pointer to an ostream previously set in the wrapper.
@ PACKETS
Use number of packets for queue size.
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.
Hold variables of type enum.
static void SetRun(uint64_t run)
Set the run number of simulation.
static Ptr< OutputStreamWrapper > inFlightStream
static void RttTracer(Time oldval, Time newval)
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Class for representing data rates.
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
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.
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
static Ptr< OutputStreamWrapper > rtoStream
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
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.
static void TraceSsThresh(std::string ssthresh_tr_file_name)
#define NS_UNUSED(x)
Mark a local variable as unused.
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 void SetSeed(uint32_t seed)
Set the seed.
static Ptr< OutputStreamWrapper > rttStream
static void InFlightTracer(uint32_t old, uint32_t inFlight)
static bool LookupByNameFailSafe(std::string name, TypeId *tid)
Get a TypeId by name.
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...
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
static void Run(void)
Run the simulation.
Hold variables of type string.
void SerializeToXmlFile(std::string fileName, bool enableHistograms, bool enableProbes)
Same as SerializeToXmlStream, but writes to a file instead.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
Manage ASCII trace files for device models.
void SetRate(double rate)
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
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.
static void NextTxTracer(SequenceNumber32 old, SequenceNumber32 nextTx)
Time Seconds(double value)
Construct a Time in the indicated unit.
Build a set of QueueDisc objects.
Determine which packets are errored corresponding to an underlying distribution, rate,...
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.
@ BYTES
Use number of bytes for queue size.
static void CwndTracer(uint32_t oldval, uint32_t newval)
static void TraceNextTx(std::string &next_tx_seq_file_name)
Build a set of PointToPointNetDevice objects.
keep track of a set of node pointers.
static TypeId GetTypeId(void)
Get the type ID.
static void TraceRtt(std::string rtt_tr_file_name)
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
Hold an unsigned integer type.
void SetDefault(std::string name, const AttributeValue &value)
A class encapsulating an output stream.
static void NextRxTracer(SequenceNumber32 old, SequenceNumber32 nextRx)
Class for representing queue sizes.
aggregate IP/TCP/UDP functionality to existing Nodes.
static TypeId LookupByName(std::string name)
Get a TypeId by name.
void SetRandomVariable(Ptr< RandomVariableStream >)
static Ptr< OutputStreamWrapper > nextRxStream
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
static void TraceCwnd(std::string cwnd_tr_file_name)
static void SsThreshTracer(uint32_t oldval, uint32_t newval)