36#include "ns3/applications-module.h"
37#include "ns3/core-module.h"
39#include "ns3/error-model.h"
40#include "ns3/event-id.h"
41#include "ns3/flow-monitor-helper.h"
42#include "ns3/internet-module.h"
43#include "ns3/ipv4-global-routing-helper.h"
44#include "ns3/network-module.h"
45#include "ns3/point-to-point-module.h"
46#include "ns3/tcp-header.h"
47#include "ns3/traffic-control-module.h"
48#include "ns3/udp-header.h"
62static std::map<uint32_t, Ptr<OutputStreamWrapper>>
cWndStream;
63static std::map<uint32_t, Ptr<OutputStreamWrapper>>
65static std::map<uint32_t, Ptr<OutputStreamWrapper>>
rttStream;
66static std::map<uint32_t, Ptr<OutputStreamWrapper>>
rtoStream;
82 std::size_t
const n1 = context.find_first_of(
'/', 1);
83 std::size_t
const n2 = context.find_first_of(
'/', n1 + 1);
84 return std::stoul(context.substr(n1 + 1, n2 - n1 - 1));
101 *
cWndStream[nodeId]->GetStream() <<
"0.0 " << oldval << std::endl;
128 *
ssThreshStream[nodeId]->GetStream() <<
"0.0 " << oldval << std::endl;
244 "/$ns3::TcpL4Protocol/SocketList/0/CongestionWindow",
260 "/$ns3::TcpL4Protocol/SocketList/0/SlowStartThreshold",
275 Config::Connect(
"/NodeList/" + std::to_string(nodeId) +
"/$ns3::TcpL4Protocol/SocketList/0/RTT",
290 Config::Connect(
"/NodeList/" + std::to_string(nodeId) +
"/$ns3::TcpL4Protocol/SocketList/0/RTO",
306 "/$ns3::TcpL4Protocol/SocketList/0/NextTxSequence",
322 "/$ns3::TcpL4Protocol/SocketList/0/BytesInFlight",
338 "/$ns3::TcpL4Protocol/SocketList/1/RxBuffer/NextRxSequence",
343main(
int argc,
char* argv[])
345 std::string transport_prot =
"TcpWestwood";
346 double error_p = 0.0;
347 std::string bandwidth =
"2Mbps";
348 std::string delay =
"0.01ms";
349 std::string access_bandwidth =
"10Mbps";
350 std::string access_delay =
"45ms";
352 std::string prefix_file_name =
"TcpVariantsComparison";
353 uint64_t data_mbytes = 0;
355 uint16_t num_flows = 1;
356 double duration = 100.0;
358 bool flow_monitor =
false;
361 std::string queue_disc_type =
"ns3::PfifoFastQueueDisc";
362 std::string recovery =
"ns3::TcpClassicRecovery";
365 cmd.AddValue(
"transport_prot",
366 "Transport protocol to use: TcpNewReno, TcpLinuxReno, "
367 "TcpHybla, TcpHighSpeed, TcpHtcp, TcpVegas, TcpScalable, TcpVeno, "
368 "TcpBic, TcpYeah, TcpIllinois, TcpWestwood, TcpWestwoodPlus, TcpLedbat, "
369 "TcpLp, TcpDctcp, TcpCubic, TcpBbr",
371 cmd.AddValue(
"error_p",
"Packet error rate", error_p);
372 cmd.AddValue(
"bandwidth",
"Bottleneck bandwidth", bandwidth);
373 cmd.AddValue(
"delay",
"Bottleneck delay", delay);
374 cmd.AddValue(
"access_bandwidth",
"Access link bandwidth", access_bandwidth);
375 cmd.AddValue(
"access_delay",
"Access link delay", access_delay);
376 cmd.AddValue(
"tracing",
"Flag to enable/disable tracing",
tracing);
377 cmd.AddValue(
"prefix_name",
"Prefix of output trace file", prefix_file_name);
378 cmd.AddValue(
"data",
"Number of Megabytes of data to transmit", data_mbytes);
379 cmd.AddValue(
"mtu",
"Size of IP packets to send in bytes", mtu_bytes);
380 cmd.AddValue(
"num_flows",
"Number of flows", num_flows);
381 cmd.AddValue(
"duration",
"Time to allow flows to run in seconds", duration);
382 cmd.AddValue(
"run",
"Run index (for setting repeatable seeds)", run);
383 cmd.AddValue(
"flow_monitor",
"Enable flow monitor", flow_monitor);
384 cmd.AddValue(
"pcap_tracing",
"Enable or disable PCAP tracing", pcap);
385 cmd.AddValue(
"queue_disc_type",
386 "Queue disc type for gateway (e.g. ns3::CoDelQueueDisc)",
388 cmd.AddValue(
"sack",
"Enable or disable SACK option", sack);
389 cmd.AddValue(
"recovery",
"Recovery algorithm type to use (e.g., ns3::TcpPrrRecovery", recovery);
390 cmd.Parse(argc, argv);
392 transport_prot = std::string(
"ns3::") + transport_prot;
394 SeedManager::SetSeed(1);
395 SeedManager::SetRun(run);
411 uint32_t tcp_adu_size = mtu_bytes - 20 - (ip_header + tcp_header);
415 double start_time = 0.1;
416 double stop_time = start_time + duration;
426 if (transport_prot ==
"ns3::TcpWestwoodPlus")
437 "TypeId " << transport_prot <<
" not found");
439 TypeIdValue(TypeId::LookupByName(transport_prot)));
446 sources.
Create(num_flows);
456 error_model.
SetUnit(RateErrorModel::ERROR_UNIT_PACKET);
474 address.SetBase(
"10.0.0.0",
"255.255.255.0");
484 DataRate access_b(access_bandwidth);
486 Time access_d(access_delay);
487 Time bottle_d(delay);
490 ((access_d + bottle_d) * 2).GetSeconds());
497 for (
uint32_t i = 0; i < num_flows; i++)
506 if (queue_disc_type ==
"ns3::PfifoFastQueueDisc")
510 else if (queue_disc_type ==
"ns3::CoDelQueueDisc")
516 NS_FATAL_ERROR(
"Queue not recognized. Allowed values are ns3::CoDelQueueDisc or "
517 "ns3::PfifoFastQueueDisc");
525 Ipv4GlobalRoutingHelper::PopulateRoutingTables();
527 uint16_t
port = 50000;
536 ftp.SetAttribute(
"Remote", remoteAddress);
538 ftp.SetAttribute(
"MaxBytes",
UintegerValue(data_mbytes * 1000000));
544 sinkHelper.SetAttribute(
"Protocol",
TypeIdValue(TcpSocketFactory::GetTypeId()));
555 ascii.open(prefix_file_name +
"-ascii");
557 stack.EnableAsciiIpv4All(ascii_wrap);
559 for (uint16_t index = 0; index < num_flows; index++)
561 std::string flowString;
564 flowString =
"-flow" + std::to_string(index);
572 Simulator::Schedule(
Seconds(start_time * index + 0.00001),
574 prefix_file_name + flowString +
"-cwnd.data",
576 Simulator::Schedule(
Seconds(start_time * index + 0.00001),
578 prefix_file_name + flowString +
"-ssth.data",
580 Simulator::Schedule(
Seconds(start_time * index + 0.00001),
582 prefix_file_name + flowString +
"-rtt.data",
584 Simulator::Schedule(
Seconds(start_time * index + 0.00001),
586 prefix_file_name + flowString +
"-rto.data",
588 Simulator::Schedule(
Seconds(start_time * index + 0.00001),
590 prefix_file_name + flowString +
"-next-tx.data",
592 Simulator::Schedule(
Seconds(start_time * index + 0.00001),
594 prefix_file_name + flowString +
"-inflight.data",
596 Simulator::Schedule(
Seconds(start_time * index + 0.1),
598 prefix_file_name + flowString +
"-next-rx.data",
599 num_flows + index + 1);
616 Simulator::Stop(
Seconds(stop_time));
624 Simulator::Destroy();
a polymophic address class
AttributeValue implementation for Address.
holds a vector of ns3::Application pointers.
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter.
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
Manage ASCII trace files for device models.
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.
AttributeValue implementation for Boolean.
A helper to make it easier to instantiate an ns3::BulkSendApplication on a set of nodes.
Parse command-line arguments.
Class for representing data rates.
Hold variables of type enum.
Helper to enable IP flow monitoring on a set of Nodes.
Ptr< FlowMonitor > InstallAll()
Enable flow monitoring on all nodes.
void SerializeToXmlFile(std::string fileName, bool enableHistograms, bool enableProbes)
Same as SerializeToXmlStream, but writes to a file instead.
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
void Add(const Ipv4InterfaceContainer &other)
Concatenate the entries in the other container with ours.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
uint32_t GetN() const
Get the number of Ptr<Node> stored in this container.
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 class encapsulating an output stream.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
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 ...
Build a set of PointToPointNetDevice objects.
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.
NetDeviceContainer Install(NodeContainer c)
Hold objects of type Ptr<T>.
Class for representing queue sizes.
AttributeValue implementation for QueueSize.
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
Determine which packets are errored corresponding to an underlying distribution, rate,...
void SetRate(double rate)
void SetUnit(enum ErrorUnit error_unit)
void SetRandomVariable(Ptr< RandomVariableStream >)
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.
Build a set of QueueDisc objects.
QueueDiscContainer Install(NetDeviceContainer c)
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.
a unique identifier for an interface.
AttributeValue implementation for TypeId.
Hold an unsigned integer type.
void SetDefault(std::string name, const AttributeValue &value)
void Connect(std::string path, const CallbackBase &cb)
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
@ BYTES
Use number of bytes for queue size.
@ PACKETS
Use number of packets for queue size.
Time Now()
create an ns3::Time instance which contains the current simulation time.
Time Seconds(double value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
static void RttTracer(std::string context, Time oldval, Time newval)
RTT tracer.
static std::map< uint32_t, bool > firstCwnd
First congestion window.
static std::map< uint32_t, uint32_t > cWndValue
congestion window value.
static void TraceInFlight(std::string &in_flight_file_name, uint32_t nodeId)
In flight trace connection.
static void NextRxTracer(std::string context, SequenceNumber32 old, SequenceNumber32 nextRx)
Next RX tracer.
static std::map< uint32_t, Ptr< OutputStreamWrapper > > nextTxStream
Next TX outut stream.
static std::map< uint32_t, Ptr< OutputStreamWrapper > > inFlightStream
In flight outut stream.
static std::map< uint32_t, bool > firstSshThr
First SlowStart threshold.
static std::map< uint32_t, bool > firstRto
First RTO.
static std::map< uint32_t, Ptr< OutputStreamWrapper > > nextRxStream
Next RX outut stream.
static uint32_t GetNodeIdFromContext(std::string context)
Get the Node Id From Context.
static std::map< uint32_t, Ptr< OutputStreamWrapper > > rtoStream
RTO outut stream.
static void InFlightTracer(std::string context, uint32_t old, uint32_t inFlight)
In-flight tracer.
static void NextTxTracer(std::string context, SequenceNumber32 old, SequenceNumber32 nextTx)
Next TX tracer.
static std::map< uint32_t, uint32_t > ssThreshValue
SlowStart threshold value.
static void TraceRtt(std::string rtt_tr_file_name, uint32_t nodeId)
RTT trace connection.
static void TraceSsThresh(std::string ssthresh_tr_file_name, uint32_t nodeId)
Slow start threshold trace connection.
static std::map< uint32_t, bool > firstRtt
First RTT.
static void TraceNextTx(std::string &next_tx_seq_file_name, uint32_t nodeId)
Next TX trace connection.
static void CwndTracer(std::string context, uint32_t oldval, uint32_t newval)
Congestion window tracer.
static void SsThreshTracer(std::string context, uint32_t oldval, uint32_t newval)
Slow start threshold tracer.
static std::map< uint32_t, Ptr< OutputStreamWrapper > > ssThreshStream
SlowStart threshold outut stream.
static std::map< uint32_t, Ptr< OutputStreamWrapper > > rttStream
RTT outut stream.
static void TraceCwnd(std::string cwnd_tr_file_name, uint32_t nodeId)
Congestion window trace connection.
static void RtoTracer(std::string context, Time oldval, Time newval)
RTO tracer.
static void TraceNextRx(std::string &next_rx_seq_file_name, uint32_t nodeId)
Next RX trace connection.
static std::map< uint32_t, Ptr< OutputStreamWrapper > > cWndStream
Congstion window outut stream.
static void TraceRto(std::string rto_tr_file_name, uint32_t nodeId)
RTO trace connection.
bool tracing
Flag to enable/disable generation of tracing files.