Traffic generator with packet tagging

112 views
Skip to first unread message

John Scott

unread,
Mar 13, 2017, 11:31:15 AM3/13/17
to ns-3-users
Hi all,

I am modifying the "wifi-simple-adhoc-grid" script to add more nodes, different mobility pattern, etc.
When trace files are enabled, I can see the data packets on Wireshark. Since it uses UDP, there is no Sequence numbers. In order to compute latency from the source node to the sink node, I would like to add a packet tag to each outgoing packet, then parse the tracing file using that tag.

I read the packet tagging documentation (https://www.nsnam.org/docs/release/3.10/manual/html/packets.html#adding-and-removing-tags), but I'm not sure how to implement that in the GenerateTraffic function. Could you assist please?

static void GenerateTraffic (Ptr<Socket> socket, uint32_t pktSize,
                             uint32_t pktCount
, Time pktInterval )
{
 
if (pktCount > 0)
   
{
      socket
->Send (Create<Packet> (pktSize));
     
Simulator::Schedule (pktInterval, &GenerateTraffic,
                           socket
, pktSize,pktCount-1, pktInterval);
   
}
 
else
   
{
      socket
->Close ();
   
}
}


Thank you

Konstantinos

unread,
Mar 13, 2017, 11:58:50 AM3/13/17
to ns-3-users
Hi,

In this example, the packet creation is within the send method, i.e.
socket->Send (Create<Packet> (pktSize));
You can take the Create() outside, add the packet tag and then send it.

I would however recommend using header instead of tag and do the delay calculation within your scenario, not with post processing the trace file. 
Have a look at the UdpClient/Server which adds the SeqTs header
and then when it receives the packet it calculates the delay
Message has been deleted

John Scott

unread,
Mar 13, 2017, 2:27:04 PM3/13/17
to ns-3-users
HI Konstantinos,

I modified the generateTraffic function to the following

#include "ns3/udp-client.h"
#include "ns3/seq-ts-header.h"


static void GenerateTraffic (Ptr<Socket> socket, uint32_t pktSize,
                             uint32_t pktCount
, Time pktInterval )
{

 
SeqTsHeader seqTs;
  seqTs
.SetSeq (m_sent);
 
Ptr<Packet> p = Create<Packet> (pktSize);
  p
->AddHeader (seqTs);
 
 
if (pktCount > 0)
   
{
     
//socket->Send (Create<Packet> (pktSize));
      socket
->Send (p);
     
++m_sent;

     
Simulator::Schedule (pktInterval, &GenerateTraffic,
                           socket
, pktSize,pktCount-1, pktInterval);
   
}
 
else
   
{
      socket
->Close ();
   
}
}

but I'm getting an error

error: m_sent was not declared in this scope


Did I add the wrong libraries or I am using the `m_sent` wrong?


Thanks

Konstantinos

unread,
Mar 14, 2017, 5:25:56 AM3/14/17
to ns-3-users
Hi,

As the compiler complained, m_sent was not declared in this scope. 
Where have you defined that variable? That variable is basically the Sequence Number of that packet.

Regards,
K

John Scott

unread,
Mar 14, 2017, 9:40:15 AM3/14/17
to ns-3-users
Hi Konstatinos,

Thanks, it's working now.
I just couldn't find the tag in Wireshark or Tshark. Is there a way to make the tag visible to those applications?

Cheers

Konstantinos

unread,
Mar 14, 2017, 9:59:01 AM3/14/17
to ns-3-users
No, PacketTags are ns-3 metadata.
That's why I recommended headers as they are physicallly included at the packets and you could read them.

John Scott

unread,
Mar 14, 2017, 5:08:45 PM3/14/17
to ns-3-users
Hi K,

I used the SeqTs method that add a header to the UDP client/server application. Shouldn't that be enough?

Thanks

int m_sent = 0;


static void GenerateTraffic (Ptr<Socket> socket, uint32_t pktSize,
                             uint32_t pktCount
, Time pktInterval )
{

 
SeqTsHeader seqTs;
  seqTs
.SetSeq (m_sent);
 
Ptr<Packet> p = Create<Packet> (pktSize);
  p
->AddHeader (seqTs);
 
 
if (pktCount > 0)
   
{
     
//socket->Send (Create<Packet> (pktSize));
      socket
->Send (p);
     
++m_sent;

Konstantinos

unread,
Mar 15, 2017, 5:36:34 AM3/15/17
to ns-3-users
Hi,

Enough for what? This header is added to the packets that you sent. 
Then you will need to read that header, to calculate the delay as in the Server example application.

John Scott

unread,
Mar 15, 2017, 6:40:14 PM3/15/17
to ns-3-users
Hi K,

I was hoping that the tagging was going to be enough for me to see the tag on Wireshark as I want to write a script to read the PCAP files at the source and sink, comparing the received and sent times.

Thanks
Reply all
Reply to author
Forward
0 new messages