Trace File in NS2

What is trace file?Requirements for generating Trace file in NS2 Simulation?

Trace file is written by an application for storing whole information in a network.For generating trace file in NS2,we require the file to be written in OTCL Script.



Syntax for generating trace file in NS2:



File name is out and also said stored data in trace format.

nf ->file handler

w   -> write which means file is opened for writing

r     -> reading

a     ->appending

The second line tells the simulator to trace each packet on every link in the topology and for that we give file handler nf for the simulator ns


Structure of trace file:

Event Time From node To node Pkt type Pkt size Flags Fid Src addr Dst addr Seq num Pkt id


  • Event gives you four possible symbols ‘+’ ‘-‘ ‘r’ ‘d’. These four symbols correspond respectively to enqueued, dequeued, received and dropped.
  • Time field gives the time at which the event occurs.
  • From node field gives you the input node of the link at which the event occurs.
  • To node field gives you the the output node at which the event occurs.
  • Packet type field shows the information about the packet type.i.e whether the packet is UDP or TCP.
  • Packet size field gives the packet size.
  • Flag field give information about some flags.
  • Fid field is the flow id(fid) for IPv6 that a user can set for each flow in a tcl script.It is also used for specifying the color of flow in NAM display.
  • The ninth field is the source address.
  • The tenth field is the destination address.
  • The eleventh field is the network layer protocol’s packet sequence number.
  • The last field shows the unique id of packet.


Examples of trace events:

Command-for-Viewing-Trace-File-in-NS2 Command for Viewing Trace File in NS2 Simulation.



Journal Support for NS2 Projects : ( Trace File in NS2)