camculate delay for OnOff application in wifi

278 views
Skip to first unread message

Angelina

unread,
Jul 21, 2017, 11:58:44 AM7/21/17
to ns-3-users
hello,

I want to calculate the end to end delay for packets generated by an OnOffApplication, I use a PaketSink to capture the generated packet and calculate  the throughput.
I need now to know how to calculate the delay?? according to the ns3 documentation I think that I should use the Tx trace source of the OnOff Application and the Rx trace source of PacketSink, thus I calculate the delay for each packet, and determine the average delay.
An other option is to use the flowMonitor.

would you please tell me which method should be used? OR there's a better method.

Thank youu

Konstantinos

unread,
Jul 21, 2017, 12:10:39 PM7/21/17
to ns-3-users
Hi,

These two are the main methods, FlowMonitor and traces feeding the data collection framework. You could also generate ASCII/PCAP trace files and calculate delays through analysis, but that's even more complecated.

It is up to you which one to choose. Both are provided in some examples inside the ns-3 codebase. 

Regards
K

Angelina

unread,
Jul 23, 2017, 6:34:16 AM7/23/17
to ns-3-users
Thank you!
In the Pcap file the time refers to the time of generation of the packet by th OnOff application and the reception by the sink? I mean, the difference between these times is the end to end delay?

Konstantinos

unread,
Jul 23, 2017, 10:00:18 AM7/23/17
to ns-3-users
In the PCAP, the Rx/Tx times are at the link layer and per link/hop. 
If you have multi-hop then it would need further calculations for end-to-end delay. If you only have single hop links, then the delay would be the same.

FlowMonitor would be the easiest method to calculate end-to-end delay. Simply generate the XML trace file and parse it with the python script that is available with ns-3 for FlowMonitor analysis.

Regards,
K

Angelina

unread,
Jul 25, 2017, 12:27:42 PM7/25/17
to ns-3-users

Thank you so much constantinos,

When if I add a timestamp when the packet is generated (SendPacket() in onOffApplication), the when I receive the packet I can calculate the tx delay.
To this end I have added these two methods in packet.h and packet.cc

uint32_t
Packet::ReadTimeStamp()
{
return timeStamp;
}
void
Packet::AddTimeStamp()
{
timeStamp=Simulator::Now().GetSeconds();
}


as I have explained the AddTimeStamp method is called by the sendPacketmethod in the onOffApplication class :

void OnOffApplication::SendPacket ()
{
  NS_LOG_FUNCTION (this);

  NS_ASSERT (m_sendEvent.IsExpired ());
  Ptr<Packet> packet = Create<Packet> (m_pktSize);
  packet->AddTimeStamp();
  m_txTrace (packet);
  m_socket->Send (packet);
  m_totBytes += m_pktSize;
  if (InetSocketAddress::IsMatchingType (m_peer))
    {
      NS_LOG_INFO ("At time " << Simulator::Now ().GetSeconds ()
                   << "s on-off application sent "
                   <<  packet->GetSize () << " bytes to "
                   << InetSocketAddress::ConvertFrom(m_peer).GetIpv4 ()
                   << " port " << InetSocketAddress::ConvertFrom (m_peer).GetPort ()
                   << " total Tx " << m_totBytes << " bytes");
    }
  else if (Inet6SocketAddress::IsMatchingType (m_peer))
    {
      NS_LOG_INFO ("At time " << Simulator::Now ().GetSeconds ()
                   << "s on-off application sent "
                   <<  packet->GetSize () << " bytes to "
                   << Inet6SocketAddress::ConvertFrom(m_peer).GetIpv6 ()
                   << " port " << Inet6SocketAddress::ConvertFrom (m_peer).GetPort ()
                   << " total Tx " << m_totBytes << " bytes");
    }
  m_lastStartTime = Simulator::Now ();
  m_residualBits = 0;
  ScheduleNextTx ();
}



In my programm I have added this traceSink :

  uint32_t packetCounter=0;
  uint32_t calculatedDelay=0;
 
  /* Create Sink Rx Trace */
         void SinkRxTrace(Ptr<const Packet> pkt, const Address &addr)
              {  
                  uint32_t currentTimeStamp=pkt->ReadTimeStamp();
                  std::cout<<"currentTimeStamp="<<currentTimeStamp<<'\n';
                 // calculatedDelay+=(Simulator::Now()-(&pkt->ReadTimeStamp()));
                  packetCounter++;
                
               }



the output is:
../scratch/dmg_throughput_1mcs.cc: In function ‘void SinkRxTrace(ns3::Ptr<const ns3::Packet>, const ns3::Address&)’:
../scratch/dmg_throughput_1mcs.cc:39:64: error: passing ‘const ns3::Packet’ as ‘this’ argument discards qualifiers [-fpermissive]
                   uint32_t currentTimeStamp=pkt->ReadTimeStamp();
                                                                ^
In file included from ./ns3/application-packet-probe.h:31:0,
                 from ./ns3/applications-module.h:10,
                 from ../scratch/dmg_throughput_1mcs.cc:5:
./ns3/packet.h:312:12: note:   in call to ‘uint32_t ns3::Packet::ReadTimeStamp()’
   uint32_t ReadTimeStamp ();
            ^


can you please help me to explain the meaning of this error and the cause behind!

thanks!

Konstantinos

unread,
Jul 25, 2017, 12:42:35 PM7/25/17
to ns-3-users
Hi,

The method to add the timestamp is incorrect. You should either add a packet tag or header that you would then read them.
See for example how the UdpClient/Server application uses the SeqTsHeader to do exactly what you want.
And yes, you can add the SeqTsHeader in your OnOffApp and read it later when you receive it in PacketSink.

Regards
K

kaouthar mansour

unread,
Jul 25, 2017, 7:45:21 PM7/25/17
to ns-3-...@googlegroups.com
Hi,

many thanks!

I don't understand what we don't use the GetAverageDelay() method of the packtSink class? I thinks that this is the easiest method.

kaouther MANSOUR
Ingénieur chercheur en Réseaux Informatiques et Télécommunication

--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to a topic in the Google Groups "ns-3-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ns-3-users/TEthDKtIcLU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ns-3-users+unsubscribe@googlegroups.com.
To post to this group, send email to ns-3-...@googlegroups.com.
Visit this group at https://groups.google.com/group/ns-3-users.
For more options, visit https://groups.google.com/d/optout.

Konstantinos

unread,
Jul 26, 2017, 4:55:04 AM7/26/17
to ns-3-users
Hi,

I do not understand your question. There is no GetAverageDelay method in PacketSink class, at least not in the default ns-3 codebase.

Regards
K
Reply all
Reply to author
Forward
0 new messages