Hi all,
I am looking for compute the TCP throughput and goodput.
For me when I talk about throughput it is the amount of data receive at TCP layer by the sink.
Instead goodput is the amount of data received at TCP layer without any duplicate packet.
I think that for throughput I found the solution. Instead for the goodput I have doubt.
For the throughput purpose a wrote these lines and two functions:
int idSinkNode = (int)floor((float)n_nodes/2);
uint32_t port = 20;
Address sinkLocalAddressReceiver1(InetSocketAddress (interfaces.GetAddress (idSinkNode), port));
BulkSendHelper sourceFTP ("ns3::TcpSocketFactory",sinkLocalAddressReceiver1);
sourceFTP.SetAttribute ("MaxBytes", UintegerValue (maxBytes));
ApplicationContainer sourceAppsFTP = sourceFTP.Install (nodes.Get (0));
sourceAppsFTP.Start (Seconds (50.0));
sourceAppsFTP.Stop (Seconds (1000.0));
Address sinkLocalAddress(InetSocketAddress (Ipv4Address::GetAny (), port));
PacketSinkHelper sink ("ns3::TcpSocketFactory", sinkLocalAddress);
ApplicationContainer sinkAppsTraffic = sink.Install (nodes.Get (idSinkNode));
sinkAppsTraffic.Start (Seconds (50.0));
sinkAppsTraffic.Stop (Seconds (1000.0));
std::string receiverNodeConfig = "/NodeList/"+to_string(idSinkNode)+"/ApplicationList/*/$ns3::PacketSink/Rx";
Config::ConnectWithoutContext (receiverNodeConfig, MakeCallback (&SinkRx2));
Simulator::Schedule (Seconds (50.0), &ThroughputPerSecond, sinkAppsTraffic.Get(0),0 ,0 , nodes.Get (idSinkNode));
-and the two function:
static void SinkRx2 (Ptr<const Packet> p, const Address &ad)
{
uint8_t buf[6];
ad.CopyTo (buf);
Ipv4Address ipv4 = Ipv4Address::Deserialize (buf);
p->Print(outTest);
uint32_t ipAdd = ipv4.Get() ;
int a = ((ipAdd >> 24) & 0xff) ;
int b = ((ipAdd >> 16) & 0xff) ;
int c = ((ipAdd >> 8) & 0xff);
int d = ((ipAdd >> 0) & 0xff);
std::cout << Simulator::Now().GetSeconds()<< "\t"<< a <<"."<<b<< "."<< c<<"."<< d <<"\t"<< "ID: " << p->GetUid()<<"\t" << p->GetSize() << "\t" << std::endl;
}
void
ThroughputPerSecond (Ptr<Application> sink1Apps, int totalPacketsThrough, float prevThroughput ,Ptr<Node> node)
{
double throughput = 0.0;
Ptr<PacketSink> sink1 = DynamicCast<PacketSink> (sink1Apps);
totalPacketsThrough = sink1->GetTotalRx ();
throughput = (totalPacketsThrough*8/(1000000.0)) - prevThroughput;
prevThroughput = (totalPacketsThrough*8)/(1000000.0);
std::cout << (Simulator::Now ()).GetSeconds () << "\t"<< throughput <<std::endl;
Simulator::Schedule (Seconds (1.0), &ThroughputPerSecond, sink1Apps, totalPacketsThrough, prevThroughput, node);
}
My doubt regards the function SinkRx2. My idea is to extract the TCP sequence number from the packet received by the sink node. Is it good? I also think that GetUid() is not what I am lookinh for, amn't I?
Thank you a lot
Matteo