Pages

Wednesday 28 November 2012

Installing WSN LEACH Protocol on NS-2.34 in Fedora


Here I am sharing my experience of installing WSN LEACH protocol on NS-2.34 in fedora 8 system. After searching in the Google a lot, I came across the following few useful links, explaining about installing Leach on NS-2. Here they are:

And
Linuxquestions.org (few valuable posts)

So, here the Step-by-Step method  to install LEACH.

You system need to be installed with NS-2.34 and the compiler gcc-4.3. these two are pre-requisite for installing LEACH.

Let, the home directory of ns-2.34 is "/opt/ns-allinone-2.34"

Download the package "ns-234-leach.tar.gz" into the directory "/opt/ns-allinone-2.34/ns-2.34".

Download the bash file "leach-setup.sh" into the directory "/opt/ns-allinone-2.34/ns-2.34".

Note:  If the home directory of your "ns-2.34" is other than "/opt/...", then you need to find "/opt/ns-allinone-2.34" and replace with "yourpath/ns-allinone-2.34" for the file "leach-setup.sh".

Now, move to the directory "/opt/ns-allinone-2.34/ns-2.34" and patch the file "leach-setup.sh".

cd  /opt/ns-allinone-2.34/ns-2.34/
bash  leach-setup.sh

If the home directory of your "ns-2.34" is other than "/opt/...", then you need to find "/opt/ns-allinone-2.34" and replace with "yourpath/ns-allinone-2.34" for the follwoing two files:
          - "Makefile" : found in the directory "yourpath/ns-allinone-2.34/ns-2.34".
          - "Makefile.in" : found in the directory "yourpath/ns-allinone-2.34/ns-2.34".

Edit both “Makefile” & “Makefile.in” as following:
CC = gcc-4.3
CPP = g++-4.3

Once the above steps are done, run the following commands in the Terminal:
./configure
make clean
make depend
make

When you using the make command you will get the following error:
Code:
********************************************************************
trace/cmu-trace.cc: In member function ‘void CMUTrace::format(Packet*, const char*)’:
trace/cmu-trace.cc:1327: error: ‘format_rca’ was not declared in this scope
trace/cmu-trace.cc: At global scope:
trace/cmu-trace.cc:1523: error: no ‘void CMUTrace::format_rca(Packet*, int)’ member function declared in class ‘CMUTrace’
make: *** [trace/cmu-trace.o] Error 1
********************************************************************
  To fix it you need to add the following code in “cmu-trace.h” file starting from line 165:
Code:
********************************************************************

#ifdef MIT_uAMPS
      void    format_rca(Packet *p, int offset);
#define ADV_CHAR             'A'
#define REQ_CHAR             'R'
#define DATA_CHAR            'D'

#endif
********************************************************************

 And following into ns-default.tcl (line 765) to suppress few warnings:
 ********************************************************************
# ——————————————————
Phy/WirelessPhy set alive_ 1
Phy/WirelessPhy set Efriss_amp_ 100e-12
Phy/WirelessPhy set Etwo_ray_amp_ 0.013e-12

Phy/WirelessPhy set EXcvr_ 50e-9
Phy/WirelessPhy set sleep_ 0
Phy/WirelessPhy set ss_ 1
Phy/WirelessPhy set dist_ 0
# ——————————————————
********************************************************************
Now run the following the commands to re-compile ns in terminal.
make clean
make depend
make

 If the above commands passed successfully then you are ready to test your "Leach" by running “./test_leach” command.
 ./test_leach

Now go to the following directory “yourpath/ns-allinone-2.34/ns-2.34/ns-234-leach/mit/leach_sims” and check the file "leach.err",

You may get few errors in the leach.err file as follows:
******************************************************************** 
can't read "env(RCA_LIBRARY)": no such variable
    while executing
"source $env(RCA_LIBRARY)/ns-ranode.tcl"
    (file "mit/uAMPS/sims/uamps.tcl" line 9)
      ......................
      .....Code Omitted.....
      ......................
      (procedure "source" line 8)
    invoked from within
"source tcl/mobility/$opt(rp).tcl"
    (file "tcl/ex/wireless.tcl" line 187)

******************************************************************** 

The problem is in the path. What modify all the paths in “ns-allinone-2.34/ns-2.34/mit/uAMPS/sims/uamps.tcl”. Here is the modified code below the commented out lines (lines beginning with '#'):
Code:
********************************************************************   
############################################################################
#
# This code was developed as part of the MIT uAMPS project. (June, 2000)
#
############################################################################

global opt bs

#source $env(RCA_LIBRARY)/ns-ranode.tcl
source /hema/home/ns-allinone-2.35-RC4/ns-2.35/mit/rca/ns-ranode.tcl

#source $env(uAMPS_LIBRARY)/ns-bsapp.tcl
source /hema/home/ns-allinone-2.35-RC4/ns-2.35/mit/uAMPS/ns-bsapp.tcl

#source $env(uAMPS_LIBRARY)/extras.tcl
source /hema/home/ns-allinone-2.35-RC4/ns-2.35/mit/uAMPS/extras.tcl

#source $env(uAMPS_LIBRARY)/stats.tcl
source /hema/home/ns-allinone-2.35-RC4/ns-2.35/mit/uAMPS/stats.tcl

#Uncomment these lines to use gdb to debug the c code
#source mit/uAMPS/ns-bsapp.tcl
#source mit/uAMPS/extras.tcl
#source mit/uAMPS/stats.tcl

#source $env(RCA_LIBRARY)/resources/ns-resource-manager.tcl
source /hema/home/ns-allinone-2.35-RC4/ns-2.35/mit/rca/resources/ns-resource-manager.tcl

#source $env(RCA_LIBRARY)/resources/ns-energy-resource.tcl
source /hema/home/ns-allinone-2.35-RC4/ns-2.35/mit/rca/resources/ns-energy-resource.tcl

#source $env(RCA_LIBRARY)/resources/ns-neighbor-resource.tcl
source /hema/home/ns-allinone-2.35-RC4/ns-2.35/mit/rca/resources/ns-neighbor-resource.tcl
********************************************************************  
Now run the following the commands to re-compile ns in terminal.
make clean
make depend
make

and execute following again: ./test_leach
Now check the file "leach.err", if no error reported then go to "leach.out"  for results!