Adding Leach protocol in ns2.34

let’s your ns2 is installed in /home/arun/ns/ns-allinone2.34
I suppose that ns-2.34 is installed with the compiler gcc-4.3.
download both files in  …//ns.2.34
1. LeachCode
2.Installing_file
and make sure that in leach-setup.sh please change the path in this file and run

arun@merom:~$ cd /home/arun/ns/ns-allinone-2.34/ns-2.34/
arun@merom:/home/arun/ns/ns-allinone-2.34/ns-2.34$ sudo bash leach-setup.sh
arun@merom:/home/arun/ns/ns-allinone-2.34/ns-2.34$./configure
arun@merom:/home/arun/ns/ns-allinone-2.34/ns-2.34$make clean
arun@merom:/home/arun/ns/ns-allinone-2.34/ns-2.34$make depend
arun@merom:/home/arun/ns/ns-allinone-2.34/ns-2.34$make
arun@merom:/home/arun/ns/ns-allinone-2.34/ns-2.34$make install

after running  “make ” you will get error

[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

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 /home/arun/ns/ns-allinone-2.35-RC4/ns-2.35/mit/rca/ns-ranode.tcl
#source $env(uAMPS_LIBRARY)/ns-bsapp.tcl
source /home/arun/ns/ns-allinone-2.35-RC4/ns-2.35/mit/uAMPS/ns-bsapp.tcl
#source $env(uAMPS_LIBRARY)/extras.tcl
source /home/merom/ns-allinone-2.35-RC4/ns-2.35/mit/uAMPS/extras.tcl
#source $env(uAMPS_LIBRARY)/stats.tcl
source/home/arun/ns/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 /home/arun/ns/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 /home/arun/ns/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 /home/arun/ns/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!

 

 

run again all commands it will work 🙂

for more please refer

http://forum.wsnlab.ir/pdf/LEACH.inNS2.wsnlab.ir.pdf

 

Error in installing NS2

Hello ,

errors while installing ns2

can’t find X includesotcl-1.13 configuration failed! Exiting …Please check http://www.isi.edu/nsnam/ns/ns-problems.html

solutions for that :

please copy and paste in shell

sudo apt-get install xorg-dev
sudo apt-get install libx11-dev
sudo apt-get install libxt-dev

Enjoy :)

|