Simple method to analyze NS2 Trace file
Today I am going to show a simple perl code to analyze NS2 trace file as an example of AODV routing protocol. As you know when you run simulation, NS2 generates a trace file like sometrace.tr. It will give a lot of information about your simulation result. Not knowing how to analyze this file it is useless to run NS2 simulator. In this topic we will learn how to compute delivery ratio and message overhead.
First go to your home directory and create bin directory there. We will create trace file here so that we can access it from anywhere we want.
cd ~ mkdir bin cd bin
Download analyze.pl file, which is attached to the post, to the bin directory. I will explain main points of the code. Following code opens a file to write simulation results.
$ofile="simulation_result.csv"; open OUT, ">$ofile" or die "$0 cannot open output file $ofile: $!";
Usually in trace file each line is started with some letter like r, s, D, N. Each of the letters has meaning. For detailed meaning of the letter refer to the NS Manual Page . And following perl code extracts lines which start with "s", which means sent packets. It maybe : control packets (AODV), data packets (cbr). We are only interested in packets those are sent by routers (RTR). If you enable MAC trace, the packets sent or received by MAC layer is also shown.
if (/^s/){
if (/^s.*AODV/) {
$aodvSent++;
if (/^s.*REQUEST/) {
$aodvSendRequest++;
}
elsif (/^s.*REPLY/) {
$aodvSendReply++;
}
}
elsif (/^s.*AGT/) {
$dataSent++;
}
}
REQUEST - AODV Route Request (RREQ) packets
REPLY - AODV Route Reply (RREP) packets;
AGT - Packets those are sent by agent such as cbr, udp, tcp;
And following code counts packet received by each function.
elsif (/^r/){
if (/^r.*AODV/) {
$aodvRecv++;
if (/^r.*REQUEST/) {
$aodvRecvRequest++;
}
elsif (/^r.*REPLY/) {
$aodvRecvReply++;
}
}
elsif (/^r.*AGT/) {
$dataRecv++;
}
}
Finally packets which are dropped are counted using following code :
elsif (/^D/) {
if (/^D.*AODV/) {
if (/^D.*REQUEST/) {
$aodvDropRequest++;
}
elsif (/^D.*REPLY/) {
$aodvDropReply++;
}
}
if (/^D.*RTR/) {
$routerDrop++;
}
}
Now we will analyze example file. In this post I have written about simulating WSN with AODV protocol, download it and do following. ( I am assuming you have already put analyze.pl file into your bin directory). Here is full source code to the analyze file : analyze.pl. More trace analyzer code is available in the this archive.
ns aodv_802_15_4.tcl cat trace-aodv-802-15-4.tr | analyze.pl
The result would something like this :

A Wireless Sensor Networks Bibliography
Here is the list of sensor network bibliography prepared by Autonomous Networks Research Group at USC. () means the number of papers available on this topic. I believe this list will be very useful to decide your future research, and write your related work.
Topic 1: Introduction
1. Visions and Applications (27)
2. Hardware (15)
3. Surveys and Taxonomy (6)
Topic 2: Deployment, Localization, Synchronization, Calibration
1. Deployment (99)
2. Localization (83)
3. Time Synchronization (26)
4. Calibration (8)
Topic 3: Wireless Communication
1. Wireless Radio and Link Characteristics (35)
2. MAC Protocols (67)
3. Link Layer Techniques (28)
4. Power Control (18)
Topic 4: Networking
1. Topology Control (43)
2. Data Gathering (33)
3. Geographic Routing (18)
4. Robust Routing (34)
5. Mobile Nodes (19)
6. Resource Aware Routing (20)
7. Autonomic Routing (5)
8. Network Monitoring (14)
9. Network Coding (4)
Topic 5: Data-centric Querying, Routing, and Storage
1. Routing and Aggregation (105)
2. Querying and Databases (36)
3. Storage (23)
Topic 6: Capacity and Lifetime
1. Capacity (23)
2. Lifetime Optimization (34)
Topic 7: Transport
1. Transport Layer (29)
Topic 8: Signal Processing and Computation
1. Target Tracking (36)
2. Diffuse Phenomena (10)
3. Compression (18)
4. Detection and Estimation (32)
5. Middleware and Task Allocation (11)
6. Distributed Algorithms (19)
7. Programming (5)
Topic 9: Security
1. Security (71)
Topic 10: Sensor Network Architecture
1. Sensor Network Architecture (9)
Topic 11: Miscellaneous
1. Software (35)
2. Sensing (2)
Due to the copyright I can't not include complete list here. But, here is a {LINK} to the list.
Multipath Routing in Wireless Sensor Networks
- Highly-Resilient, Energy-Efficient Multipath Routing in Wireless Sensor Networks 2001
- Multipath Virtual Sink Architecture for Wireless Sensor Networks 2006
- Label-based Multipath Routing (LMR) in Wireless Sensor Networks 2004
- Node-Disjoint Parallel Multi-Path Routing in Wireless Sensor Networks 2005
- Minimum Energy Disjoint Path Routing in Wireless Ad-Hoc Networks (Mobicom 2003)
- RELIABLE ENERGY AWARE ROUTING IN WIRELESS SENSOR NETWORKS 2007
- Reliable Splitted Multipath Routing for Wireless Sensor Networks 2004
- Towards Efficient Routing in Wireless Sensor Networks PPT
- A Dependable Multipath Routing Protocol in Wireless Sensor Networks 2006
- An energy-efficient multipath routing algorithm for wireless sensor networks 2003
- A Scalable Priority-Based Multi-Path Routing Protocol for Wireless Sensor Networks 2005 (Missing)
- Reliable Transfer on Wireless Sensor Networks 2004
- MRC: Multiplicative-increase/additive-decrease Multipath Routing In Wireless Sensor Networks 2004
- An Energy-Efficient Multipath Routing Protocol for Wireless Sensor Networks 2006
- The energy-robustness tradeoff for routing in wireless sensor networks 2003
- INSENS: Intrusion-Tolerant Routing in Wireless Sensor Networks 2003
- Optimal Multi-sink Positioning and Energy-Efficient Routing in Wireless Sensor Networks 2005
- Multi-objective Mobile Agent Routing in Wireless Sensor Networks 2005
- Meshed multipath routing with selective forwarding: an efficient strategy in wireless sensor networks 2003
- A priority-based multi-path routing protocol for sensor networks 2004
- Energy-Efficient Multipath Routing in Wireless Sensor Networks (Missing)
- Energy Efficient Routing with Guaranteed Delivery in Wireless Sensor Networks 2003
- Multipath Routing in Sensor Networks
- Multipath Routing for Data Dissemination in Energy Efficient Sensor Networks.
- MidHopRoute: a multiple path routing framework for load balancing with service differentiation in wireless sensor networks 2006 (missing)
- A Fault-tolerant Multipath Routing Protocol in Wireless Sensor Networks 2004
- Minimizing Latency in Wireless Sensor Networks - A Survey
- Reducing Congestion Effects in Wireless Networks by Multipath Routing 2006
- Multi-path delivery with selective quality along different paths(missing)
- H-SPREAD: A hybrid multipath scheme for secure and reliable data (missing)
- MIMO Techniques in Cluster-Based Wireless Sensor Networks 2006
- Efficient Routing from Multiple Sources to Multiple Sinks in Wireless Sensor Networks 2007
- Multi Mobile Agent Deployment in Wireless Sensor Networks
- A Low-Latency Routing Protocol for Wireless Sensor Networks
- A Fault-Tolerant Routing Algorithm for Wireless Sensor Networks
- PSGR: Priority-based Stateless Geo-Routing in Wireless Sensor Networks 2005
- DISJOINT AND BRAIDED MULTIPATH ROUTING FOR WIRELESS SENSOR NETWORKS 2005
- Trade-Off between Traffic Overhead and Reliability in Multipath Routing for Wireless Sensor Networks 2003
- Energy-balancing multipath routing protocol for wireless sensor networks 2006
- Spatial energy balancing through proactive multipath routing in wireless multihop networks 2007
- Disjoint multipath routing using colored trees 2007
- A Power Balanced Multipath Routing Protocol inWireless Ad-Hoc Sensor Networks 2006
- Multipath Disjoint Routing Algorithm for Ad Hoc Wireless Sensor Networks 2005
- A distributed admission control system for MANET environments supporting multipath routing protocols 2007
- An Energy-Efficient Hierarchical Multiple-Choice Routing Path Protocol for Wireless Sensor Networks 2006
- A Novel Multipath Disjoint Routing to Support Ad Hoc Wireless Sensor Networks 2006
- Performance evaluation: Node-disjointness-based multipath routing for mobile ad hoc networks 2004
- Routing & performance modelling: Multipath routing and multiple description coding in ad-hoc networks: a simulation study 2004
- Reliable Multipath Information Dissemination via Label Forwarding in Wireless Sensor Networks 2006
- MMSPEED: Multipath Multi-SPEED Protocol for QoS Guarantee of Reliability and Timeliness in Wireless Sensor Networks 2006
- Performance of multipath routing for on-demand protocols in mobile ad hoc networks 2001
- Routing optimizations: Minimum energy disjoint path routing in wireless ad-hoc networks 2003
- Multipath Fresnel Zone Routing for Wireless Ad Hoc Networks (2004)
- A Survey on Dependable Routing in Sensor Networks, Ad hoc Networks, and Cellular Networks 2004