< Simulation of IEEE 802.15.4/ZigBee with Network Simulator-2 (ns-2) - Scripts Home

Vaddina Prakash Rao Homepage

Note that the copyrights for the programs and scripts remain with the original authors as indicated at the beginning of the respective source files. However, some of the programs are coded by me and the rest have been extensively modified.

 

Note that the programs and scripts included in the package are designed solely to suite my simulation requirements. And each time the focus has been to get the desired result in the least possible time with least possible effort rather than developing a compact and bug-free code. So please be aware of possible bugs, redundant code, or undesired consequences or results.

wpan.tcl


Download the scenario file that i have used in most of my simulations here. This file has been written to be used with the utility autosim, to carry out the simulation for several iterations with out user interference.

The wireless PAN scenario (*.tcl) file contains parameters and variables which help change the network scenario and settings and control the simulation process. Settings like, channel type, propagation model, queue length, node starting time, beacon order, superframe order, start and stop time of the simulation, file containing the current seed value, antenna height, and several other parameters specific to WPAN simulations are referred as TCL commands. The file also creates the scenario file using the utility, scen_gen. It also contains commands (which can be enabled/disabled) to start the network animator, and scripts analyzing the trace file, after the simulation.

Necesary changes to adapt the code to your system with your own path (where autosim, cbrgen_star.tcl and scen_gen reside) are:

Line 33: set val(cp) "/root/ns-2/ns-allinone-2.28/ns-2.28/examples/backoff_test/traffic"

Line 57: exec /root/ns-2/ns-allinone-2.28/ns-2.28/examples/backoff_test/scen_gen $temp1 25 25 9

Line 133: source /root/ns-2/ns-allinone-2.28/ns-2.28/examples/backoff_test/wpan.scn

Be sure that you have execute permission for "wpan.tcl", if not, you can have problems using it with the utility autosim.

Hence it may not work for a manual operation (without the utility autosim), if you want to use it in this way, please create in the same directory a file called "current_seed.txt" with the seed value and a file called "traffic" with the traffic scenario (you can get this traffic using the cbrgen_star.tcl script).

This file is fed to the network simulator, which would generate its traces into a performance (*.tr) and animation (*.nam) files. The analyzing script file (avg_throughput.awk) takes the trace file (*.tr) as input and writes an analysis out of it into custom files which are used to attain a final analysis using the analyze program.

scen_gen.cc


Download the C++ source file here. Compile it with the command, "g++ -o scen_gen scen_gen.cc" to create the executable with the file name, scen_gen.

It is an application that determines the coordinates of the nodes with reference to the position of the PAN-Coordinator, to place them equidistantly around the coordinator. The resultant coordinates are saved in the scenario file, *.scn. The following graphic will help understand how the nodes are placed.

Fig1: Node Arrangement

Parameters: It accepts the following command line parameters

root@desktop:/root# scen_gen [number-of-nodes] [X-Pos-of-coord] [Y-Pos-of-coord] [Personal-Operating-Space]

 

number-of-nodes: Number of nodes to be placed around the coordinator.

X-Pos-of-coord: X position of the coordinator, with respect to the area of the network dimensions.

Y-Pos-of-coord: Y position of the coordinator, with respect to the area of operation of the network.

Personal-Operating-Space: The operating space or the reachabilitiy of the coordinator. The nodes are required to be placed equidistantly around the coordinator, for the test scenarios in this report, within the operating space of the coordinator, this parameter is utilized to arrange the nodes along an imaginary circle drawn around the coordinator with this value as radius.

Example: root@desktop:/root# scen_gen 11 25 25 10

 

root@desktop:/root# scen_gen [?/help]

The help/usage messages.

Functionality: This utility would automatically generate the coordinates of the nodes to place them around the coordinator, along an imaginary circle drawn with a radius equal to the Personal Operating Space.

Working: Running the utility would create a file, wpan.scn, to be used by the source scenario file, wpan.tcl. Edit the source file to change the resultant scenario file name.

cbrgen_star.tcl


Download the tcl source file here.

 

The script file is used to generate the traffic scenario. Look at the section, "Functionality" for more information.

Parameters: It accepts the following command line parameters

root@desktop:/root# ns cbrgen star.tcl [-type cbrtcp] [-nn nodes] [-seed input-seed] [-mc max connections] [-rate datarate] [-starttime st][-timegap tg]

type: Traffic type (cbr/tcp)

nn: Number of nodes in the scenario

seed: Seed to the RNG to generate a random traffic pattern

mc: Maximum Number of traffic flows

rate: Traffic rate in kbps

starttime: The time at which the first traffic flow would start

timegap: The time gap with which other traffic flows would start with respect to the first traffic flow.

Functionality: It is a tcl script file, capable of generating a random traffic scenario between nodes. This particular program is a modified version of the original script file, specifically designed for a star topology. The primary modification has been in the way communication direction is defined. Since a star topology cannot support communication between two nodes (none of them being a coordinator), the script file has been modified to produce only communication between a node and a coordinator. Another version of the program, extensively used for several experiments in this project, is available, to generate communication between a node and the coordinator, with coordinator always being the destination.

Working: Running this script file would generate the desired traffic scenario which can be alternatively be piped to a file, to be used with, wpan.tcl.

avg_throughput.awk


Download the awk source file here.

 

The source file can be used to extract the performance metrices from the trace files.

Parameters: The script file need to be parsed with a trace file(*.tr only, not *.nam) to extract the average performance metrices.

root@desktop:/root# awk -f avg_throughput.awk [Trace-File]

Functioning: The script file currently supports generating metrices that will be include in "performance.txt" and "drops.txt".

Working: Executing the script would generate the performance metrices, and are automatically piped to the files, "performance.txt" and "drops.txt". These files can be used to generate the final analysis files using the analyze program. The performance metrices which are piped to "performance.txt":

1 Throughput

2 Minimum Delay

3 Maximum Delay

4 Average Delay

5 Data Packets Transmitted

6 Data Packets Successfully Received by their Respective Destinations

7 Packets Dropped

8. Data Packet Delivery Ratio

9. Average Initial Energy

10. Average Energy Used

11. Average Percentage Energy Used

12. Node Packet Discrepancy Ratio

The drop statistics in the file "drop.txt" are:

1 APS

2 LQI

3 END_     DROP_END_OF_SIMULATION

4 COL       DROP_MAC_COLLISION

5 DUP       DROP_MAC_DUPLICATE

6 ERR       DROP_MAC_PACKET_ERROR

7 RET       DROP_MAC_RETRY_COUNT_EXCEEDED

8. STA       DROP_MAC_INVALID_STATE

9. BSY       DROP_MAC_BUSY

10.NRTE   DROP_RTR_NO_ROUTE

11.LOOP   DROP_RTR_ROUTE_LOOP

13.TTL       DROP_RTR_TTL

14.TOUT   DROP_RTR_QTIMEOUT

15.CBK     DROP_RTR_MAC_CALLBACK

16.IFQ       DROP_IFQ_QFULL

17.ARP     DROP_IFQ_ARP_FULL

18.OUT     DROP_OUTSIDE_SUBNET

19.Hashes

Autosim.cc


Download the C++ source file here. Compile it with the command, "g++ -o autosim autosim.cc" to create the executable with the file name, autosim.

It is the source file to generate the excutable autosim. Certain parameters like the path to the scenario file, path to the ns executable, path to the traffic generator, etc are hardcoded. Hence make appropriate changes before using it for your simulations. Also note that it has been changed over a million times to suit my simulation requirements. Hence there may be code that might be absolutely irrelevant and often confusing and misleading. User discretion is adviced. Change these lines into the path where you have the NS binary file and the "wpan868.tcl" and "wpan24.tcl" files (NOTE: "wpan24.tcl" is not available).

Line 13: #define SIM24 "/root/ns-2/ns-allinone-2.28/ns-2.28/ns /root/ns-2/ns-allinone-2.28/ns-2.28/examples/backoff_test/wpan24.tcl > test.txt"

Line 14: #define SIM868 "/root/ns-2/ns-allinone-2.28/ns-2.28/ns /root/ns-2/ns-allinone-2.28/ns-2.28/examples/backoff_test/wpan868.tcl > test.txt"

Parameters: It accepts the following command line options.

root@desktop:/root# autosim [868/24]

868: Indicates that the simulation is carried for the radio frequency of 868Mhz.

24: Indicates the simulation frequency, as 2.4Ghz.

Functionality: The autosim program is a simple application with a purpose of automating the simulation process. If a report need to produce conclusive results, they should be generated in a random fashion taking the mean of several results. However since doing this manually is not possible an idea of an application which is capable of doing this automatically has been conceived. This application is capable of generating a new seed value for each simulation, choosing the next datarate to be simulated, creating the respective traffic file for the current seed and datarate, taking a backup of the traffic files, choosing the right simulation path and network scenario file and finally conducting the simulation for the current RNG seed.

 

The first step in operating the autosim application, is creating the file, parameters.txt, which holds all the simulation parameters. Its contents include: the path to the NS execution (which must be adapted to your path), the number of simulations to be performed, the parameters for the traffic generation, the number of datarates and correspondingly, the datarate values for which simulation is to be performed. The seed for the random number generator is chosen as the simulation iteration number. Hence if the simulation is conducted for hundred number of times, the seed value ranges anything between one to hundred, based on the current iteration number.

 

This application is designed to support either frequency band operations. Specifying the frequency of operation of the PAN would allow it to use the right simulation source file (*.tcl ) (NOTE: "wpan24.tcl" is not available). The program is also responsible for choosing the right simulation path and the source file (*.tcl ) containing the network scenario and settings, and executing it with ns.

 

Working: Upon starting the application with a command like, say, autosim 868, we tell the program to simulate for the frequency band of 868Mhz. This would allow it to choose wpan868.tcl as the input to the simulator, and then generates the traffic file, makes a copy of it in the directory, dir traffic for later reference, saves the current seed value in the temporary file, "current_seed.txt" and finally executes the simulation.

 

Analyze Program


Download the package here.

 

The program that analyzes the final results to generate results that can be used to create graphs. The folder contains the files, analyze.cc, which can be compiled to generate the executable, analyze. This program is dependent on the awk script files, dfind_avg868.awk and find_avg868.awk in the current working directory for its correct operation. Running the program autosim would write the analysis of the simulation for each run into the files, performance.txt and drops.txt. Copy these two files into this directory and execute the program to generate the final results in the files, new_performance868.txt and new_drops868.txt. If there are segmentation errors in the simulations which can be easily identified by observing the file, performance.txt, execute the program analyze to generate the average values for a certain number of successful simulations. This can be specified by the parameters, "ideal_num_sims" and "max_num_sims".

 

File Descriptions:

1. final_graphs_868.txt - Contains the average of the indicated number of simulation iterations involving the performance metrics.

2. final_drops_868.txt - Contains the average of successful simulations involving drop statistics.

3. new_performance868.txt - Extract of the successful simulations from performance.txt and rewrite them into this file.

4. new_drops868.txt - Extract of the successful simulations from drops.txt and rewrite them into this file.

Parameters: The analyze utility can parsed with the following parameters.

root@desktop:/root# analyze [?/help]

root@desktop:/root# analyze

Default analysis, taking ideal simulations as 100 and maximum simulations to be 135.

root@desktop:/root# analyze [ideal_num_sims] [max_num_sims]

Analysis, giving an opportunity to specify the ideal and the maximum number of simulations.

Functioning: Analyze is the utility designed to produce the average values of the metrics for all the simulations. These files contain the simulations that were successful. It is customary to simulate a particular scenario for more than the required number of seed values. This would give room for unsuccessful simulations to be deleted from the final analysis. The analyze utility would just do that. From the input files, it eliminates the seed values for which simulation has been unsuccessful and rewrites the other simulations to the required/ideal number, into the two output files. If in a particular case, the ideal number of simulations are 100, and we have simulated the scenario for 135, we would have at least 35 extra simulations as backup incase any of the first 100 simulations have failed due to segmentation faults. The remaining seed values which have been left over after filling up the failed simulations are dropped from the analysis. It also calculates the average for each simulation variable (datarate), which can be used to build graphs.

 

Working: It takes the files, performance.txt, and drops.txt as input and generates the following files as output.

1. new performance868.txt

2. new drops868.txt

The working of the utility can be summed up in two steps. In the first step, the program would eliminate the unwanted simulations and generate the new performance and drop files and later would present these new files to a few other script files which are required to be present in the current working directory. These script files are awk scripts, used to find the average of the entries of the new performance and drop files, in column wise. As a result the following files are created, which would hold the

final graphable results.

1. final graphs 868.txt

2. final drops 868.txt


The following figures depicts the iterated simulation process using the scripts/programs described here.

 

Fig2: The simulation process structure

 

 

Fig3: The analyze process structure

Home

Contact:

Vaddina Prakash Rao Homepage