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"
75 *cWndStream->
GetStream () <<
"0.0 " << oldval << std::endl;
92 *ssThreshStream->
GetStream () <<
"0.0 " << oldval << std::endl;
159 int main (
int argc,
char *argv[])
161 std::string transport_prot =
"TcpWestwood";
162 double error_p = 0.0;
163 std::string bandwidth =
"2Mbps";
164 std::string delay =
"0.01ms";
165 std::string access_bandwidth =
"10Mbps";
166 std::string access_delay =
"45ms";
167 bool tracing =
false;
168 std::string prefix_file_name =
"TcpVariantsComparison";
169 double data_mbytes = 0;
170 uint32_t mtu_bytes = 400;
171 uint16_t num_flows = 1;
172 float duration = 100;
174 bool flow_monitor =
false;
176 std::string queue_disc_type =
"ns3::PfifoFastQueueDisc";
180 cmd.
AddValue (
"transport_prot",
"Transport protocol to use: TcpNewReno, "
181 " TcpWestwood, TcpWestwoodPlus ", transport_prot);
182 cmd.
AddValue (
"error_p",
"Packet error rate", error_p);
183 cmd.
AddValue (
"bandwidth",
"Bottleneck bandwidth", bandwidth);
184 cmd.
AddValue (
"delay",
"Bottleneck delay", delay);
185 cmd.
AddValue (
"access_bandwidth",
"Access link bandwidth", access_bandwidth);
186 cmd.
AddValue (
"access_delay",
"Access link delay", access_delay);
187 cmd.
AddValue (
"tracing",
"Flag to enable/disable tracing", tracing);
188 cmd.
AddValue (
"prefix_name",
"Prefix of output trace file", prefix_file_name);
189 cmd.
AddValue (
"data",
"Number of Megabytes of data to transmit", data_mbytes);
190 cmd.
AddValue (
"mtu",
"Size of IP packets to send in bytes", mtu_bytes);
191 cmd.
AddValue (
"num_flows",
"Number of flows", num_flows);
192 cmd.
AddValue (
"duration",
"Time to allow flows to run in seconds", duration);
193 cmd.
AddValue (
"run",
"Run index (for setting repeatable seeds)", run);
194 cmd.
AddValue (
"flow_monitor",
"Enable flow monitor", flow_monitor);
195 cmd.
AddValue (
"pcap_tracing",
"Enable or disable PCAP tracing", pcap);
196 cmd.
AddValue (
"queue_disc_type",
"Queue disc type for gateway (e.g. ns3::CoDelQueueDisc)", queue_disc_type);
197 cmd.
Parse (argc, argv);
216 uint32_t tcp_adu_size = mtu_bytes - 20 - (ip_header + tcp_header);
220 float start_time = 0.1;
221 float stop_time = start_time + duration;
228 if (transport_prot.compare (
"TcpNewReno") == 0)
232 else if (transport_prot.compare (
"TcpWestwood") == 0)
237 else if (transport_prot.compare (
"TcpWestwoodPlus") == 0)
253 sources.
Create (num_flows);
283 address.
SetBase (
"10.0.0.0",
"255.255.255.0");
293 DataRate access_b (access_bandwidth);
295 Time access_d (access_delay);
296 Time bottle_d (delay);
300 uint32_t size = (
std::min (access_b, bottle_b).GetBitRate () / 8) *
301 ((access_d + bottle_d) * 2).GetSeconds ();
306 for (
int i = 0; i < num_flows; i++)
309 devices = LocalLink.
Install (sources.
Get (i), gateways.
Get (0));
314 devices = UnReLink.
Install (gateways.
Get (0), sinks.
Get (i));
315 if (queue_disc_type.compare (
"ns3::PfifoFastQueueDisc") == 0)
319 else if (queue_disc_type.compare (
"ns3::CoDelQueueDisc") == 0)
325 NS_FATAL_ERROR (
"Queue not recognized. Allowed values are ns3::CoDelQueueDisc or ns3::PfifoFastQueueDisc");
328 interfaces = address.
Assign (devices);
329 sink_interfaces.
Add (interfaces.
Get (1));
335 uint16_t
port = 50000;
339 for (uint16_t i = 0; i < sources.
GetN (); i++)
343 if (transport_prot.compare (
"TcpNewReno") == 0
344 || transport_prot.compare (
"TcpWestwood") == 0
345 || transport_prot.compare (
"TcpWestwoodPlus") == 0
346 || transport_prot.compare (
"TcpHybla") == 0
347 || transport_prot.compare (
"TcpHighSpeed") == 0
348 || transport_prot.compare (
"TcpBic") == 0
349 || transport_prot.compare (
"TcpCubic") == 0)
353 ftp.SetAttribute (
"Remote", remoteAddress);
355 ftp.SetAttribute (
"MaxBytes",
UintegerValue (
int(data_mbytes * 1000000)));
368 NS_LOG_DEBUG (
"Invalid transport protocol " << transport_prot <<
" specified");
378 ascii.open ((prefix_file_name +
"-ascii").c_str ());
holds a vector of ns3::Application pointers.
Simulation virtual time values and global simulation resolution.
Manage ASCII trace files for device models.
static Ipv4Address GetAny(void)
void SetStream(int64_t stream)
Specifies the stream number for this RNG stream.
std::pair< Ptr< Ipv4 >, uint32_t > Get(uint32_t i) const
Get the std::pair of an Ptr and interface stored at the location specified by the index...
QueueDiscContainer Install(NetDeviceContainer c)
A helper to make it easier to instantiate an ns3::BulkSendApplication on a set of nodes...
holds a vector of std::pair of Ptr and interface index.
static void PopulateRoutingTables(void)
Build a routing database and initialize the routing tables of the nodes in the simulation.
Hold variables of type string.
NetDeviceContainer Install(NodeContainer c)
Use number of bytes for maximum queue size.
void Add(const Ipv4InterfaceContainer &other)
Concatenate the entries in the other container with ours.
static void Run(void)
Run the simulation.
Ptr< OutputStreamWrapper > cWndStream
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
aggregate IP/TCP/UDP functionality to existing Nodes.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
A helper to make it easier to instantiate an ns3::PacketSinkApplication 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. ...
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 AddPacketFilter(uint16_t handle, std::string type, std::string n01="", const AttributeValue &v01=EmptyAttributeValue(), std::string n02="", const AttributeValue &v02=EmptyAttributeValue(), std::string n03="", const AttributeValue &v03=EmptyAttributeValue(), std::string n04="", const AttributeValue &v04=EmptyAttributeValue(), std::string n05="", const AttributeValue &v05=EmptyAttributeValue(), std::string n06="", const AttributeValue &v06=EmptyAttributeValue(), std::string n07="", const AttributeValue &v07=EmptyAttributeValue(), std::string n08="", const AttributeValue &v08=EmptyAttributeValue())
Helper function used to add a packet filter (of the given type and with the given attributes) to the ...
void SerializeToXmlFile(std::string fileName, bool enableHistograms, bool enableProbes)
Same as SerializeToXmlStream, but writes to a file instead.
static void SetRun(uint64_t run)
Set the run number of simulation.
a polymophic address class
uint32_t GetN(void) const
Get the number of Ptr stored in this container.
Class for representing data rates.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Ptr< OutputStreamWrapper > rttStream
static void RttTracer(Time oldval, Time newval)
static TypeId GetTypeId(void)
Get the type ID.
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 ...
Hold variables of type enum.
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
void InstallAll(void) const
Aggregate IPv4, IPv6, UDP, and TCP stacks to all nodes in the simulation.
Hold an unsigned integer type.
void SetRate(double rate)
holds a vector of ns3::NetDevice pointers
A class encapsulating an output stream.
AttributeValue implementation for TypeId.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
Build a set of QueueDisc objects.
Ptr< FlowMonitor > InstallAll()
Enable flow monitoring on all nodes.
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
Parse command-line arguments.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
void EnableAsciiIpv4All(std::string prefix)
Enable ascii trace output on all Ipv4 and interface pairs existing in the set of all nodes created in...
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
static void CwndTracer(uint32_t oldval, uint32_t newval)
static TypeId GetTypeId(void)
Get the type ID.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
Hold objects of type Ptr.
static void TraceSsThresh(std::string ssthresh_tr_file_name)
uint16_t SetRootQueueDisc(std::string type, std::string n01="", const AttributeValue &v01=EmptyAttributeValue(), std::string n02="", const AttributeValue &v02=EmptyAttributeValue(), std::string n03="", const AttributeValue &v03=EmptyAttributeValue(), std::string n04="", const AttributeValue &v04=EmptyAttributeValue(), std::string n05="", const AttributeValue &v05=EmptyAttributeValue(), std::string n06="", const AttributeValue &v06=EmptyAttributeValue(), std::string n07="", const AttributeValue &v07=EmptyAttributeValue(), std::string n08="", const AttributeValue &v08=EmptyAttributeValue(), std::string n09="", const AttributeValue &v09=EmptyAttributeValue(), std::string n10="", const AttributeValue &v10=EmptyAttributeValue(), std::string n11="", const AttributeValue &v11=EmptyAttributeValue(), std::string n12="", const AttributeValue &v12=EmptyAttributeValue(), std::string n13="", const AttributeValue &v13=EmptyAttributeValue(), std::string n14="", const AttributeValue &v14=EmptyAttributeValue(), std::string n15="", const AttributeValue &v15=EmptyAttributeValue())
Helper function used to set a root queue disc of the given type and with the given attributes...
static TypeId GetTypeId(void)
Get the type ID.
Ptr< OutputStreamWrapper > rtoStream
Helper to enable IP flow monitoring on a set of Nodes.
static Time Now(void)
Return the current simulation virtual time.
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
static void SetSeed(uint32_t seed)
Set the seed.
void SetUnit(enum ErrorUnit error_unit)
AttributeValue implementation for Address.
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Time Seconds(double value)
Construct a Time in the indicated unit.
void SetDefault(std::string name, const AttributeValue &value)
void SetRandomVariable(Ptr< RandomVariableStream >)
Ipv4Address NewNetwork(void)
Increment the network number and reset the IP address counter to the base value provided in the SetBa...
void Parse(int argc, char *argv[])
Parse the program arguments.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
static void TraceRtt(std::string rtt_tr_file_name)
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Determine which packets are errored corresponding to an underlying distribution, rate, and unit.
static void RtoTracer(Time oldval, Time newval)
static void TraceCwnd(std::string cwnd_tr_file_name)
static void SsThreshTracer(uint32_t oldval, uint32_t newval)
std::ostream * GetStream(void)
Return a pointer to an ostream previously set in the wrapper.
Ptr< OutputStreamWrapper > ssThreshStream
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
static void TraceRto(std::string rto_tr_file_name)