How to calculate the packets that are dropped/ lost in a LTE network

220 views
Skip to first unread message

aadesh shah

unread,
Apr 28, 2020, 10:12:30 AM4/28/20
to ns-3-users
Hello All,

I am trying to calculate the exact amounts of packets that are lost or dropped. I am trying to use flowmonitor but other seems to be an error in flow monitor. Is there any other way? And how I can verify the numbers provided my flowmonitor.


I even want to figure out the exact reason for packet drop or lost? Is there a way to do it?

I tried the following using flowmonitor but I got no returns.

          for (uint32_t reasonCode = 0; reasonCode < i->second.packetsDropped.size (); reasonCode++)
          {
              outFile<<"Print in";
              outFile << "<packetsDropped reasonCode=" << reasonCode
                      << " number=" << i->second.packetsDropped[reasonCode] << "\n";

          }
          std::cout<<i->second.packetsDropped.at(0)<<std::endl; 


Can anyone help me out with this? If there is any other method except flowmonitor then it would be great if you provide a guidance or even a help with flowmonitor would be appreciated.

Regards,
Aadesh Shah

Nadia Kalsoom

unread,
Apr 30, 2020, 4:32:05 AM4/30/20
to ns-3-users
aadesh shah
to see the lost packets you should change the simulation time 10 or may more seconds more than app time

aadesh shah

unread,
Apr 30, 2020, 4:46:37 AM4/30/20
to ns-3-users
Hello Nadia,

My simulation time already appstoptime+1seconds. I am using this on mmwave module. Do you have a demo working code?  thats my flowmonitor code:
std::string outputDir = "./";
    std::string simTag= "test4";
    flowMonitor->CheckForLostPackets ();
    Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier> (flowHelper.GetClassifier ());
    FlowMonitor::FlowStatsContainer stats = flowMonitor->GetFlowStats ();

    double averageFlowThroughput = 0.0;
    double averageFlowDelay = 0.0;
    uint32_t sumLostPackets = 0.0;
    uint32_t sumTxPackets = 0.0;

    std::ofstream outFile;
    std::string filename = outputDir + "/" + simTag;
    outFile.open (filename.c_str (), std::ofstream::out | std::ofstream::app);
    if (!outFile.is_open ())
    {
      std::cout<<"Can't open file " << filename;
      return 1;
    }
    outFile.setf (std::ios_base::fixed);

  for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator i = stats.begin (); i != stats.end (); ++i)
    {
     
      Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow(i->first);
      std::stringstream protoStream;
      protoStream << (uint16_t) t.protocol;
      if (t.protocol == 6)
        {
          protoStream.str ("TCP");
        }
      if (t.protocol == 17)
        {
          protoStream.str ("UDP");

        }
      for (uint32_t reasonCode = 0; reasonCode < i->second.packetsDropped.size (); reasonCode++)
      {
          outFile<<"Print in";
          outFile << "<packetsDropped reasonCode=" << reasonCode
                  << " number=" << i->second.packetsDropped[reasonCode] << "\n";

      }
        outFile << "Flow " << i->first << " (" << t.sourceAddress << ":" << t.sourcePort << " -> " << t.destinationAddress << ":" << t.destinationPort << ") proto " << protoStream.str () << "\n";
        outFile << "  Tx Packets: " << i->second.txPackets << "\n";
        outFile << "  Tx Bytes:   " << i->second.txBytes << "\n";
        outFile << "  TxOffered:  " << i->second.txBytes * 8.0 / (endSimTime - startSimTime) / 1000 / 1000  << " Mbps\n";
        outFile << "  Rx Bytes:   " << i->second.rxBytes << "\n";
        outFile << "  Lost Packets: " << i->second.lostPackets<< "\n";
        // outFile << " Packets Dropped : " << i-> second.packetsDropped<<"\n";
        // outFile << " Byte Dropped: " << i->second.bytesDropped<<"\n";
        sumTxPackets += i->second.txPackets;
        sumLostPackets+= i->second.lostPackets;
      if (i->second.rxPackets > 0)
        {
          // Measure the duration of the flow from receiver's perspective
          double rxDuration = i->second.timeLastRxPacket.GetSeconds () - i->second.timeFirstTxPacket.GetSeconds ();

          averageFlowThroughput += i->second.rxBytes * 8.0 / rxDuration / 1000 / 1000;
          averageFlowDelay += 1000 * i->second.delaySum.GetSeconds () / i->second.rxPackets;

          outFile << "  Throughput: " << i->second.rxBytes * 8.0 / rxDuration / 1000 / 1000  << " Mbps\n";
          outFile << "  Mean delay:  " << 1000 * i->second.delaySum.GetSeconds () / i->second.rxPackets << " ms\n";
          //outFile << "  Mean upt:  " << i->second.uptSum / i->second.rxPackets / 1000/1000 << " Mbps \n";
          outFile << "  Mean jitter:  " << 1000 * i->second.jitterSum.GetSeconds () / i->second.rxPackets  << " ms\n";
//          for (uint32_t reasonCode = 0; reasonCode < i->second.packetsDropped.size (); reasonCode++)
//          {
//              outFile<<"Print in";
//              outFile << "<packetsDropped reasonCode=" << reasonCode
//                      << " number=" << i->second.packetsDropped[reasonCode] << "\n";
//
//          }
          // std::cout<<i->second.packetsDropped(0)<<std::endl;
          for (uint32_t reasonCode = 0; reasonCode < i->second.bytesDropped.size (); reasonCode++)
          {
              std::cout<<"\n"<< "<bytesDropped reasonCode=\"" << reasonCode << "\""
                      << " bytes=\"" << i->second.bytesDropped[reasonCode] << std::endl;
          }
        }
      else
        {
          outFile << "  Throughput:  0 Mbps\n";
          outFile << "  Mean delay:  0 ms\n";
          outFile << "  Mean upt:  0  Mbps \n";
          outFile << "  Mean jitter: 0 ms\n";
        }
      outFile << "\n" << "Loss Packet %" <<(((i->second.txPackets-i->second.rxPackets)*1.0)/i->second.txPackets);
      outFile << "  Rx Packets: " << i->second.rxPackets << "\n";

    }


    outFile << "\n" << "Packets Transmitted" << sumTxPackets << "\n";
    outFile << "\n" << "Packets Lost" << sumLostPackets << "\n";
   
    outFile << "\n\n  Mean flow throughput: " << averageFlowThroughput / stats.size() << "\n";
    outFile << "  Mean flow delay: " << averageFlowDelay / stats.size () << "\n";
    outFile <<"----------------------------------------Next Simulation -------------------------------------------------------------------------------------" << "\n";
  outFile.close ();

  flowMonitor->SerializeToXmlFile("test4.xml", true, true);

  Simulator::Destroy ();
Let me know if there are any error.
thanks and regards,
Aadesh Shah
Reply all
Reply to author
Forward
0 new messages