std::map<FlowId, FlowMonitor::FlowStats> stats = flow_monitor->GetFlowStats (); uint32_t txPacketsum = 0; uint32_t rxPacketsum = 0; uint32_t DropPacketsum = 0; uint32_t LostPacketsum = 0; double Delaysum = 0;
for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator i = stats.begin (); i != stats.end (); ++i) { txPacketsum += i->second.txPackets; rxPacketsum += i->second.rxPackets; LostPacketsum += i->second.lostPackets; DropPacketsum += i->second.packetsDropped.size(); Delaysum += i->second.delaySum.GetSeconds(); } std::cout << " All Tx Packets: " << txPacketsum << "\n"; std::cout << " All Rx Packets: " << rxPacketsum << "\n"; std::cout << " All Delay: " << Delaysum / txPacketsum <<"\n"; std::cout << " All Lost Packets: " << LostPacketsum << "\n"; std::cout << " All Drop Packets: " << DropPacketsum << "\n"; std::cout << " Packets Delivery Ratio: " << ((rxPacketsum *100) / txPacketsum) << "%" << "\n"; std::cout << " Packets Lost Ratio: " << ((LostPacketsum *100) / txPacketsum) << "%" << "\n";Hi guys,maybe I have a total misunderstanding of how the flow monitor in NS-3 works. I try to measure the packet delivery ratio of TCP in a wireless single hop testbed. The channel is set up to lose approximately 50% of all packets. I use OLSR for routing.
First of all I decided to test the channel with simple UDP transmissions, I used the UdpEchoServer/Client and their Tx/Rx traces to measure the sent and recieved packets. If I send 1000 packets, the server will recieve 494 packets, which is ok and the same number of packets as recognized by the pcap file.
But the flow monitor tells me there are 1030 packets sent and 510 recieved?
for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator i = stats.begin (); i != stats.end (); ++i)
{
Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow (i->first);
if (t.destinationAddress == Ipv4Address("10.10.10.10")){
// only data with destination address 10.10.10.10 will be printed..
}} If I try to deploy this on a TCP flow with 1000 bytes to send, flow monitor tells me there are 9 packets sent and 9 packets recieved. A look in the pcap files tells me there are 10 TCP packets sent on the client side and 5 packets recieved on the server side (I used the tcp bulk sender application).
I used the flow monitor code found in https://groups.google.com/forum/#!topic/ns-3-users/e63hi63K8CU and some different examples.
So my question is, do I missunderstand how flow monitor works? Or is there another mistake in my code?
Why is the TCP PDR allways 100%?
<?xml version="1.0" ?><FlowMonitor> <FlowStats> <Flow flowId="1" timeFirstTxPacket="+700000000000.0ns" timeFirstRxPacket="+700000042100.0ns" timeLastTxPacket="+700005343000.0ns" timeLastRxPacket="+700008183100.0ns" delaySum="+6302698.0ns" jitterSum="+7326400.0ns" lastDelay="+2840100.0ns" txBytes="1264" rxBytes="1264" txPackets="5" rxPackets="5" lostPackets="0" timesForwarded="0"> <delayHistogram nBins="3" > <bin index="0" start="0" width="0.001" count="3" /> <bin index="2" start="0.002" width="0.001" count="2" /> </delayHistogram> <jitterHistogram nBins="3" > <bin index="0" start="0" width="0.001" count="1" /> <bin index="1" start="0.001" width="0.001" count="1" /> <bin index="2" start="0.002" width="0.001" count="2" /> </jitterHistogram> <packetSizeHistogram nBins="30" > <bin index="2" start="40" width="20" count="3" /> <bin index="25" start="500" width="20" count="1" /> <bin index="29" start="580" width="20" count="1" /> </packetSizeHistogram> <flowInterruptionsHistogram nBins="0" > </flowInterruptionsHistogram> </Flow>
Sink Node:
....
}else{ BulkSendHelper source ("ns3::TcpSocketFactory", InetSocketAddress (interfaces.GetAddress (sinkNode), 80)); // Set the amount of data to send in bytes. Zero is unlimited. source.SetAttribute ("MaxBytes", UintegerValue (maxBytes)); ApplicationContainer sourceApps = source.Install (nodes.Get (sourceNode)); sourceApps.Start (tcp_send_start); sourceApps.Stop (Seconds (2000.0));
PacketSinkHelper sink ("ns3::TcpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), 80)); pplicationContainer sinkApps = sink.Install (nodes.Get (sinkNode)); sinkApps.Start (Seconds (0.0)); sinkApps.Stop (Seconds (2000.0)); DynamicCast<PacketSink> (sinkApps.Get (0))->TraceConnectWithoutContext ("Rx", MakeCallback(cb_tcp_sink_received)); } FlowMonitorHelper flowHelper; Ptr<FlowMonitor> flow_monitor = flowHelper.InstallAll(); //---------------------------------------------------------------------------------- //--- SIMULATION // NetAnim - Create the animation object and configure for specified output AnimationInterface anim (animFile); // Stoppen der Simulation notwendig, da OLSR Packete neue Events generieren Simulator::Stop (Seconds (2000.0)); NS_LOG_INFO ("Run Simulation."); std::cout << "Testing from node " << sourceNode << " to " << sinkNode << std::endl; std::cout << "----------" << std::endl; Simulator::Run (); // Flow Monitor flow_monitor->CheckForLostPackets (); Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier> (flowHelper.GetClassifier ()); std::map<FlowId, FlowMonitor::FlowStats> stats = flow_monitor->GetFlowStats ();
uint32_t txPacketsum = 0; uint32_t rxPacketsum = 0; double Delaysum = 0;
for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator i = stats.begin (); i != stats.end (); ++i) { Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow (i->first); if ((t.destinationAddress == Ipv4Address("10.0.0.2")) && (t.sourceAddress == Ipv4Address("10.0.0.1"))){ txPacketsum += i->second.txPackets; rxPacketsum += i->second.rxPackets; } } std::cout << " All Tx Packets: " << txPacketsum << "\n"; std::cout << " All Rx Packets: " << rxPacketsum << "\n"; std::cout << " Packets Delivery Ratio: " << ((rxPacketsum *100) / txPacketsum) << "%" << "\n"; flow_monitor->SerializeToXmlFile("jnc_flow", true, true); Simulator::Destroy (); }jan@JTP:~/ns-3-dev$ ./waf --run "scratch/JNC/JNC --op_mode=1 --tracing=true --maxBytes=4000 --mac_retr_off=false"Waf: Entering directory `/home/jan/ns-3-dev/build'Waf: Leaving directory `/home/jan/ns-3-dev/build'Build commands will be stored in build/compile_commands.json'build' finished successfully (1.157s)----------Positions at time t=0s: Node #0 has pos 0:0:0 Node #1 has pos 30:0:0----------Testing from node 0 to 1----------Time: 30, 3.32, 0.015174 All Tx Packets: 11 All Rx Packets: 11 Packets Delivery Ratio: 100%
jan@JTP:~/ns-3-dev$ ./waf --run "scratch/JNC/JNC --op_mode=1 --tracing=true --maxBytes=4000 --mac_retr_off=true"Waf: Entering directory `/home/jan/ns-3-dev/build'Waf: Leaving directory `/home/jan/ns-3-dev/build'Build commands will be stored in build/compile_commands.json'build' finished successfully (1.179s)----------Positions at time t=0s: Node #0 has pos 0:0:0 Node #1 has pos 30:0:0----------Testing from node 0 to 1----------Time: 30, 3.32, 26.222304 All Tx Packets: 22 All Rx Packets: 13 Packets Delivery Ratio: 59%