Skip to content

Event Trace File Generation in a ns-3 Simulation

Trace Files For Analysisconfused-code

ns-3 provides more than one way to log events for further analysis of a  network simulation.

Read the following article to get some idea about different ways of using rich rich tracing features of ns-3.

Rich Tracing Features available in ns-3 – really a Strength? Or Weakness?

 

This article is about an elementary way of creating object-level event traces.

From the tradition of the previous ns-2 simulator, people always want to do the trace analysis using “event trace files” similar to that of an ns-2 simulation.  ns-3’s Ascii Trace file is somewhat similar to ns-2’s trace file. But the format of ns-3’s Ascii Trace is entirely different from that of ns-2.

So the trace analysis scripts that were written for ns2 traces using scripting languages such as awk, Perl can not be used “as it is” to do trace analysis on ns-3 Ascii trace files – but we can make it work after suitable modifications in them.

But, according to my understanding, the format of ns-3’s Ascii trace file may need custom parsing for a different type of protocols that may be used in a simulation; so a custom trace analysis script that was written for one particular ns-3 simulation, probably will not be suitable for analysing the trace files of entirely different ns-3 simulation.

One of the ns-3 developer/Maintainer Tommaso Pecorella  once mentioned the following in ns-3 user group reply :
” I highly suggest Dart, Ruby or R. Seriously, it depends on the file and what is inside the file. This topic has been discussed in the past: there’s no common structure for the traces (beside a very few) simply because there’s too many cases. Consult the manual about how tracing works and the source files you’re running to find out what are the data you’re obtaining. Next, they can be analysed with any system, usually gnuplot, or matlab. Even Excel could do.”
From that, we can understand that there is no standard way of doing analysis on this primitive form of ns-3 trace file. The format of this trace file will differ with respect to the modules that are used in a typical ns-3 simulation.

Creating Ascii Trace files in an ns-3 Simulation

In this example, we are going to extend the simulation script that we prepared in a previous article http://www.projectguideline.com/start-experiencing-ns-3-with-a-simple-simulation/

SimpleNS3Simulation3.cc

#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/point-to-point-module.h”
#include “ns3/internet-module.h”
#include “ns3/applications-module.h”
using namespace ns3;int main (int argc, char *argv[])
{
NodeContainer nodes;
nodes.Create (2);PointToPointHelper channel;
channel.SetDeviceAttribute (“DataRate”, StringValue (“5Mbps”));
channel.SetChannelAttribute (“Delay”, StringValue (“2ms”));NetDeviceContainer netDevices;
netDevices = channel.Install (nodes);InternetStackHelper ipStack;
ipStack.Install (nodes);Ipv4AddressHelper ipAddresses;
ipAddresses.SetBase (“192.168.1.0”, “255.255.255.0”);Ipv4InterfaceContainer ipinterfaces = ipAddresses.Assign (netDevices);UdpEchoServerHelper udpEchoServer (9);

ApplicationContainer serverApps = udpEchoServer.Install (nodes.Get (1));
serverApps.Start (Seconds (1.0));

UdpEchoClientHelper udpEchoClient (ipinterfaces.GetAddress (1), 9);

ApplicationContainer clientApps = udpEchoClient.Install (nodes.Get (0));
clientApps.Start (Seconds (2.0));

AsciiTraceHelper eventTraces;
channel.EnableAsciiAll(eventTraces.CreateFileStream(“SimpleNS3Simulation_EventTraceOutput.tr”));

Simulator::Run ();
}

 

We just added two lines at the bottom to generate the Ascii Trace file output for doing trace analysis on an ns-3 simulation.

 

Running the Script “SimpleNS3Simulation3.cc”

If you run the script, it will not generate any interesting outputs in the terminal; because I just removed all the lines which actually shows some “LogComponent” outputs to make you understand how we can use the Log Components in a typical simulation. There is no need to enable the Log Components in the simulation script itself – later we may enable it by setting the environment variable before running the simulation.

Download the file “SimpleNS3Simulation3” and copy it to the folder ns-allinone-3.25/ns-3.25/scratch

Change to the directory “ns-3.25”

$ cd ns-allinone-3.25/ns-3.25/

And run the simulation

$ waf –run SimpleNS3Simulation3

After running the simulation, an Ascii trace file will be generated in the name “SimpleNS3Simulation_EventTraceOutput.tr

The following are some of the lines from that SimpleNS3Simulation_EventTraceOutput.tr file.

 

+ 2 /NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Enqueue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 0 protocol 17 offset (bytes) 0 flags [none] length: 128 192.168.1.1 > 192.168.1.2) ns3::UdpHeader (length: 108 49153 > 9) Payload (size=100)
– 2 /NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Dequeue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 0 protocol 17 offset (bytes) 0 flags [none] length: 128 192.168.1.1 > 192.168.1.2) ns3::UdpHeader (length: 108 49153 > 9) Payload (size=100)
r 2.00221 /NodeList/1/DeviceList/0/$ns3::PointToPointNetDevice/MacRx ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 0 protocol 17 offset (bytes) 0 flags [none] length: 128 192.168.1.1 > 192.168.1.2) ns3::UdpHeader (length: 108 49153 > 9) Payload (size=100)
+ 2.00221 /NodeList/1/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Enqueue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 0 protocol 17 offset (bytes) 0 flags [none] length: 128 192.168.1.2 > 192.168.1.1) ns3::UdpHeader (length: 108 9 > 49153) Payload (size=100)
– 2.00221 /NodeList/1/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Dequeue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 0 protocol 17 offset (bytes) 0 flags [none] length: 128 192.168.1.2 > 192.168.1.1) ns3::UdpHeader (length: 108 9 > 49153) Payload (size=100)
r 2.00442 /NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/MacRx ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 0 protocol 17 offset (bytes) 0 flags [none] length: 128 192.168.1.2 > 192.168.1.1) ns3::UdpHeader (length: 108 9 > 49153) Payload (size=100)
+ 3 /NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Enqueue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 1 protocol 17 offset (bytes) 0 flags [none] length: 128 192.168.1.1 > 192.168.1.2) ns3::UdpHeader (length: 108 49153 > 9) Payload (size=100)
– 3 /NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Dequeue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 1 protocol 17 offset (bytes) 0 flags [none] length: 128 192.168.1.1 > 192.168.1.2) ns3::UdpHeader (length: 108 49153 > 9) Payload (size=100)
r 3.00221 /NodeList/1/DeviceList/0/$ns3::PointToPointNetDevice/MacRx ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 1 protocol 17 offset (bytes) 0 flags [none] length: 128 192.168.1.1 > 192.168.1.2) ns3::UdpHeader (length: 108 49153 > 9) Payload (size=100)
+ 3.00221 /NodeList/1/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Enqueue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 1 protocol 17 offset (bytes) 0 flags [none] length: 128 192.168.1.2 > 192.168.1.1) ns3::UdpHeader (length: 108 9 > 49153) Payload (size=100)
– 3.00221 /NodeList/1/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Dequeue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 1 protocol 17 offset (bytes) 0 flags [none] length: 128 192.168.1.2 > 192.168.1.1) ns3::UdpHeader (length: 108 9 > 49153) Payload (size=100)
r 3.00442 /NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/MacRx ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 1 protocol 17 offset (bytes) 0 flags [none] length: 128 192.168.1.2 > 192.168.1.1) ns3::UdpHeader (length: 108 9 > 49153) Payload (size=100)
+ 4 /NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Enqueue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 2 protocol 17 offset (bytes) 0 flags [none] length: 128 192.168.1.1 > 192.168.1.2) ns3::UdpHeader (length: 108 49153 > 9) Payload (size=100)
– 4 /NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Dequeue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 2 protocol 17 offset (bytes) 0 flags [none] length: 128 192.168.1.1 > 192.168.1.2) ns3::UdpHeader (length: 108 49153 > 9) Payload (size=100)
r 4.00221 /NodeList/1/DeviceList/0/$ns3::PointToPointNetDevice/MacRx ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 2 protocol 17 offset (bytes) 0 flags [none] length: 128 192.168.1.1 > 192.168.1.2) ns3::UdpHeader (length: 108 49153 > 9) Payload (size=100)
+ 4.00221 /NodeList/1/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Enqueue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 2 protocol 17 offset (bytes) 0 flags [none] length: 128 192.168.1.2 > 192.168.1.1) ns3::UdpHeader (length: 108 9 > 49153) Payload (size=100)
– 4.00221 /NodeList/1/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Dequeue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 2 protocol 17 offset (bytes) 0 flags [none] length: 128 192.168.1.2 > 192.168.1.1) ns3::UdpHeader (length: 108 9 > 49153) Payload (size=100)
r 4.00442 /NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/MacRx ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 2 protocol 17 offset (bytes) 0 flags [none] length: 128 192.168.1.2 > 192.168.1.1) ns3::UdpHeader (length: 108 9 > 49153) Payload (size=100)
+ 5 /NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Enqueue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 3 protocol 17 offset (bytes) 0 flags [none] length: 128 192.168.1.1 > 192.168.1.2) ns3::UdpHeader (length: 108 49153 > 9) Payload (size=100)
– 5 /NodeList/0/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Dequeue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 3 protocol 17 offset (bytes) 0 flags [none] length: 128 192.168.1.1 > 192.168.1.2) ns3::UdpHeader (length: 108 49153 > 9) Payload (size=100)
……………………………………………
…………………………………………….
…………………………………………….
One may learn more about tracing from the following link:
Using the Tracing System
The following article shows a primitive way of doing analysis on the created trace file.

Trace Analysis of ns-3 Ascii Traces using TraceMetrics Tool – An elementary Trace Analysis Solution for ns-3

The following article shows an elementary way of doing trace analysis:

Trace Analysis of TCP Flows Under ns-3 MANET/ FANET/ VANET/ WSN Scenario

 

For doing trace analysis for scholarly research works, one may follow the following article:

 

Generating Genuine, Quality Tables & Graphs for Publication.

WhatsApp Discuss Through WhatsApp