TCP throughput measurement 2 (multiple tcp flows)
Topology
N0(Multiple TCP
Senders)----P2Plink(5Mbps,2ms)---N1(Multiple TCP Sinks)
Throughput-tcp2.cc (put this file under scratch)
#include <fstream> #include <string.h> #include "ns3/core-module.h" #include "ns3/internet-module.h" #include "ns3/point-to-point-module.h" #include "ns3/packet-sink.h" #include "ns3/packet-sink-helper.h" #include "ns3/applications-module.h" using namespace ns3; NS_LOG_COMPONENT_DEFINE ("ThroughputTCP2"); const int no=3;
/* number of tcp flows */ Ptr<PacketSink> sink[no];
/* Pointer to the packet sink application */ uint64_t lastTotalRx[no];
/* The value of the last total received bytes */ double cur[no]; void CalculateThroughput () { Time now =
Simulator::Now ();
std::cout
<< now.GetSeconds (); for(int
j=0;j<no;j++){
cur[j] = (sink[j]->GetTotalRx () - lastTotalRx[j]) * (double) 8 /
1e6;
std::cout << "\t" << cur[j];
lastTotalRx[j] = sink[j]->GetTotalRx (); } std::cout
<< std::endl;
Simulator::Schedule (MilliSeconds (1000), &CalculateThroughput); } int main (int argc, char *argv[]) {
NS_LOG_INFO ("Create nodes.");
NodeContainer n; n.Create
(2);
InternetStackHelper internet;
internet.Install (n);
NS_LOG_INFO ("Create channels.");
PointToPointHelper pointToPoint; pointToPoint.SetDeviceAttribute
("DataRate", StringValue ("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue
("2ms"));
pointToPoint.SetDeviceAttribute("Mtu",
UintegerValue(1400));
NetDeviceContainer p2pDevices; p2pDevices
= pointToPoint.Install (n);
Ipv4AddressHelper ipv4;
NS_LOG_INFO ("Assign IP Addresses.");
ipv4.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer i = ipv4.Assign (p2pDevices);
NS_LOG_INFO ("Create Applications."); for(int
j=0; j<no; j++) {
PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory",
InetSocketAddress (Ipv4Address::GetAny (), 9+j));
ApplicationContainer sinkApp = sinkHelper.Install (n.Get(1));
sinkApp.Start (Seconds (0.0));
sink[j] = StaticCast<PacketSink> (sinkApp.Get (0)); } for(int
j=0; j<no; j++) {
BulkSendHelper source ("ns3::TcpSocketFactory",
(InetSocketAddress (i.GetAddress (1), 9+j)));
source.SetAttribute ("MaxBytes", UintegerValue (0));
ApplicationContainer sourceApps=source.Install (n.Get (0));
sourceApps.Start (Seconds (1.0));
sourceApps.Stop (Seconds (10.0));
}
Simulator::Schedule (Seconds (1.0), &CalculateThroughput);
Simulator::Stop (Seconds (12.0));
NS_LOG_INFO ("Run Simulation."); Simulator::Run
();
Simulator::Destroy ();
NS_LOG_INFO ("Done."); } |
Execution
If we want to get the throughput for flow 2, we can do like the following step. (The first column is time, and the second is the throughput)
Last Modified: 2022/2/5
Dr. Chih-Heng Ke
Department
of Computer Science and Information Engineering, National Quemoy
University, Kinmen, Taiwan
Email:
smallko@gmail.com