97 #include "ns3/core-module.h" 98 #include "ns3/network-module.h" 99 #include "ns3/internet-module.h" 100 #include "ns3/point-to-point-module.h" 101 #include "ns3/applications-module.h" 102 #include "ns3/traffic-control-module.h" 121 std::cout <<
"Progress to " << std::fixed << std::setprecision (1) <<
Simulator::Now ().
GetSeconds () <<
" seconds simulation time" << std::endl;
146 for (std::size_t i = 0; i < 10; i++)
150 for (std::size_t i = 0; i < 20; i++)
154 for (std::size_t i = 0; i < 10; i++)
163 for (std::size_t i = 0; i < 10; i++)
167 for (std::size_t i = 0; i < 20; i++)
171 for (std::size_t i = 0; i < 10; i++)
182 uint64_t sumSquares = 0;
185 for (std::size_t i = 0; i < 10; i++)
190 average = ((sum / 10) * 8 / measurementWindow.
GetSeconds ()) / 1e6;
191 fairness =
static_cast<double> (sum * sum) / (10 * sumSquares);
193 << std::fixed << std::setprecision (2) << average <<
" Mbps; fairness: " 194 << std::fixed << std::setprecision (3) << fairness << std::endl;
199 for (std::size_t i = 0; i < 20; i++)
204 average = ((sum / 20) * 8 / measurementWindow.
GetSeconds ()) / 1e6;
205 fairness =
static_cast<double> (sum * sum) / (20 * sumSquares);
207 << std::fixed << std::setprecision (2) << average <<
" Mbps; fairness: " 208 << std::fixed << std::setprecision (3) << fairness << std::endl;
213 for (std::size_t i = 0; i < 10; i++)
218 average = ((sum / 10) * 8 / measurementWindow.
GetSeconds ()) / 1e6;
219 fairness =
static_cast<double> (sum * sum) / (10 * sumSquares);
221 << std::fixed << std::setprecision (2) << average <<
" Mbps; fairness: " 222 << std::fixed << std::setprecision (3) << fairness << std::endl;
224 for (std::size_t i = 0; i < 10; i++)
228 for (std::size_t i = 0; i < 20; i++)
232 fairnessIndex <<
"Aggregate user-level throughput for flows through T1: " <<
static_cast<double> (sum * 8) / 1e9 <<
" Gbps" << std::endl;
234 for (std::size_t i = 0; i < 10; i++)
238 for (std::size_t i = 0; i < 10; i++)
242 fairnessIndex <<
"Aggregate user-level throughput for flows to R1: " <<
static_cast<double> (sum * 8) / 1e9 <<
" Gbps" << std::endl;
250 Time backlog =
Seconds (static_cast<double> (qSize * 1500 * 8) / 1e10);
261 Time backlog =
Seconds (static_cast<double> (qSize * 1500 * 8) / 1e9);
268 int main (
int argc,
char *argv[])
270 std::string outputFilePath =
".";
271 std::string tcpTypeId =
"TcpDctcp";
275 bool enableSwitchEcn =
true;
279 cmd.AddValue (
"tcpTypeId",
"ns-3 TCP TypeId", tcpTypeId);
280 cmd.AddValue (
"flowStartupWindow",
"startup time window (TCP staggered starts)", flowStartupWindow);
281 cmd.AddValue (
"convergenceTime",
"convergence time", convergenceTime);
282 cmd.AddValue (
"measurementWindow",
"measurement window", measurementWindow);
283 cmd.AddValue (
"enableSwitchEcn",
"enable ECN at switches", enableSwitchEcn);
284 cmd.Parse (argc, argv);
289 Time stopTime = flowStartupWindow + convergenceTime + measurementWindow;
336 std::vector<NetDeviceContainer> S1T1;
338 std::vector<NetDeviceContainer> S2T1;
340 std::vector<NetDeviceContainer> S3T2;
342 std::vector<NetDeviceContainer> R2T2;
347 for (std::size_t i = 0; i < 10; i++)
350 S1T1.push_back (pointToPointSR.
Install (
n, T1));
352 for (std::size_t i = 0; i < 20; i++)
355 S2T1.push_back (pointToPointSR.
Install (
n, T1));
357 for (std::size_t i = 0; i < 10; i++)
360 S3T2.push_back (pointToPointSR.
Install (
n, T2));
362 for (std::size_t i = 0; i < 20; i++)
365 R2T2.push_back (pointToPointSR.
Install (
n, T2));
390 for (std::size_t i = 0; i < 10; i++)
392 tchRed1.
Install (S1T1[i].Get (1));
394 for (std::size_t i = 0; i < 20; i++)
396 tchRed1.
Install (S2T1[i].Get (1));
398 for (std::size_t i = 0; i < 10; i++)
400 tchRed1.
Install (S3T2[i].Get (1));
402 for (std::size_t i = 0; i < 20; i++)
404 tchRed1.
Install (R2T2[i].Get (1));
408 std::vector<Ipv4InterfaceContainer> ipS1T1;
410 std::vector<Ipv4InterfaceContainer> ipS2T1;
412 std::vector<Ipv4InterfaceContainer> ipS3T2;
414 std::vector<Ipv4InterfaceContainer> ipR2T2;
416 address.SetBase (
"172.16.1.0",
"255.255.255.0");
418 address.SetBase (
"192.168.0.0",
"255.255.255.0");
420 address.SetBase (
"10.1.1.0",
"255.255.255.0");
421 for (std::size_t i = 0; i < 10; i++)
423 ipS1T1.push_back (
address.Assign (S1T1[i]));
426 address.SetBase (
"10.2.1.0",
"255.255.255.0");
427 for (std::size_t i = 0; i < 20; i++)
429 ipS2T1.push_back (
address.Assign (S2T1[i]));
432 address.SetBase (
"10.3.1.0",
"255.255.255.0");
433 for (std::size_t i = 0; i < 10; i++)
435 ipS3T2.push_back (
address.Assign (S3T2[i]));
438 address.SetBase (
"10.4.1.0",
"255.255.255.0");
439 for (std::size_t i = 0; i < 20; i++)
441 ipR2T2.push_back (
address.Assign (R2T2[i]));
448 std::vector<Ptr<PacketSink> > r2Sinks;
449 r2Sinks.reserve (20);
450 for (std::size_t i = 0; i < 20; i++)
452 uint16_t
port = 50000 + i;
457 r2Sinks.push_back (packetSink);
462 clientHelper1.SetAttribute (
"OnTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=1]"));
463 clientHelper1.SetAttribute (
"OffTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=0]"));
465 clientHelper1.SetAttribute (
"PacketSize",
UintegerValue (1000));
469 clientHelper1.SetAttribute (
"Remote", remoteAddress);
470 clientApps1.
Add (clientHelper1.Install (S2.
Get (i)));
471 clientApps1.
Start (i * flowStartupWindow / 20 + clientStartTime +
MilliSeconds (i * 5));
476 std::vector<Ptr<PacketSink> > s1r1Sinks;
477 std::vector<Ptr<PacketSink> > s3r1Sinks;
478 s1r1Sinks.reserve (10);
479 s3r1Sinks.reserve (10);
480 for (std::size_t i = 0; i < 20; i++)
482 uint16_t
port = 50000 + i;
489 s1r1Sinks.push_back (packetSink);
493 s3r1Sinks.push_back (packetSink);
499 clientHelper1.SetAttribute (
"OnTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=1]"));
500 clientHelper1.SetAttribute (
"OffTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=0]"));
502 clientHelper1.SetAttribute (
"PacketSize",
UintegerValue (1000));
506 clientHelper1.SetAttribute (
"Remote", remoteAddress);
509 clientApps1.
Add (clientHelper1.Install (S1.
Get (i)));
510 clientApps1.
Start (i * flowStartupWindow / 10 + clientStartTime +
MilliSeconds (i * 5));
514 clientApps1.
Add (clientHelper1.Install (S3.
Get (i - 10)));
515 clientApps1.
Start ((i - 10) * flowStartupWindow / 10 + clientStartTime +
MilliSeconds (i * 5));
521 rxS1R1Throughput.open (
"dctcp-example-s1-r1-throughput.dat", std::ios::out);
523 rxS2R2Throughput.open (
"dctcp-example-s2-r2-throughput.dat", std::ios::out);
525 rxS3R1Throughput.open (
"dctcp-example-s3-r1-throughput.dat", std::ios::out);
527 fairnessIndex.open (
"dctcp-example-fairness.dat", std::ios::out);
528 t1QueueLength.open (
"dctcp-example-t1-length.dat", std::ios::out);
529 t1QueueLength <<
"#Time(s) qlen(pkts) qlen(us)" << std::endl;
530 t2QueueLength.open (
"dctcp-example-t2-length.dat", std::ios::out);
531 t2QueueLength <<
"#Time(s) qlen(pkts) qlen(us)" << std::endl;
532 for (std::size_t i = 0; i < 10; i++)
536 for (std::size_t i = 0; i < 20; i++)
540 for (std::size_t i = 0; i < 10; i++)
holds a vector of ns3::Application pointers.
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
Simulation virtual time values and global simulation resolution.
uint32_t GetNPackets(void) const
Get the number of packets stored by the queue disc.
static Ipv4Address GetAny(void)
AttributeValue implementation for Boolean.
QueueDiscContainer Install(NetDeviceContainer c)
Class for representing queue sizes.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
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)
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container. ...
Callback< R > MakeBoundCallback(R(*fnPtr)(TX), ARG a1)
Make Callbacks with one bound argument.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
static void Run(void)
Run the simulation.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes...
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.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
std::ofstream t2QueueLength
a polymophic address class
Holds a vector of ns3::QueueDisc pointers.
std::vector< uint64_t > rxS2R2Bytes
Class for representing data rates.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
void TraceS1R1Sink(std::size_t index, Ptr< const Packet > p, const Address &a)
Hold an unsigned integer type.
holds a vector of ns3::NetDevice pointers
std::stringstream filePlotQueue1
std::ofstream t1QueueLength
std::vector< uint64_t > rxS1R1Bytes
Build a set of QueueDisc objects.
static void Bind(std::string name, const AttributeValue &value)
Iterate over the set of GlobalValues until a matching name is found and then set its value with Globa...
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.
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
int64_t GetMicroSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
std::ofstream rxS1R1Throughput
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
void CheckT2QueueSize(Ptr< QueueDisc > queue)
Ptr< QueueDisc > Get(std::size_t i) const
Get the Ptr<QueueDisc> stored in this container at a given index.
void PrintThroughput(Time measurementWindow)
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...
void InitializeCounters(void)
Time TimeStep(uint64_t ts)
static Time Now(void)
Return the current simulation virtual time.
void PrintProgress(Time interval)
void TraceS3R1Sink(std::size_t index, Ptr< const Packet > p, const Address &a)
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
void PrintFairness(Time measurementWindow)
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...
std::ofstream rxS2R2Throughput
void TraceS2R2Sink(std::size_t index, Ptr< const Packet > p, const Address &a)
AttributeValue implementation for DataRate.
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Time Seconds(double value)
Construct a Time in the indicated unit.
void SetDefault(std::string name, const AttributeValue &value)
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
std::vector< uint64_t > rxS3R1Bytes
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
std::ofstream rxS3R1Throughput
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Receive and consume traffic generated to an IP address and port.
std::ofstream fairnessIndex
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
void CheckT1QueueSize(Ptr< QueueDisc > queue)
std::stringstream filePlotQueue2