Leach protocol installation in network simulator 2

Leach protocol installation in ns2 had to go through the following steps:
 As far as I have studied, I got two patches for Leach

1. MIT patch
2. Mannasim patch- I didnt work much with it but if you dont want to meddle much with tcl, you can use it.
Ok, the prerequisite is Ubuntu 10.04. We need to install ns-2.34  over that because LEACH MIT patch was made in 2000. Its a little painful to use the old OS, but it has to be done. Again you can have your OS on a virtual box on windows (only if you are not concerned with speed and not in love with your computer).
1. Download  ns-234-leach.tar.gz. Keep this in your /home/$userID/ns-allinone-2.34/ns-2.34. (Assuming you ns-allinone is in home dir)
Leach ns2.34 
2.Download the bash file "leach-setup.sh" into the directory " /home/$userID/ns-allinone-2.34/ns-2.34".
 leach-sh
3- Now find /home/arun/ns-allinone-2.35/ns-2.35 in the leach-setup.sh file and replace it with your own path.
/home/$username/ns-allinone-2.34/ns-2.34
4- Move to the directory "/home/$username/ns-allinone-2.34/ns-2.34" and patch the file "leach-setup.sh"
just write$ bash leach-setup.sh 
5- Now you need to edit Makefile.in and Makefile. Go to /home/$username/ns-allinone-2.34/ns-2.34 where you will find these files
6. Edit both “Makefile” & “Makefile.in” as following:
CC = gcc-4.3
CPP = g++-4.3(Not necessary. I did not need to )
7- run the following commands
wsn@ubuntu:/home/$username/ns-allinone-2.34/ns-2.34$./configure
wsn@ubuntu
/home/$username/
ns-allinone-2.34/ns-2.34$make clean
wsn@ubuntu
/home/$username/ns-allinone-2.34/ns-2.34$make
7- If the previous commands passed successfully then you are ready to test your "Leach" by running bash ./test:
wsn@ubuntu:/home/$username/ns-allinone-2.34/ns-2.34$bash ./test
8. If you get errors in the terminal as 
[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.] then you need to find these lines.. in
/ns-allinone-2.34/ns-2.34/trace/cmu-trace.h
void format_imep(Packet *p, int offset);
void format_aodv(Packet *p, int offset);
void format_aomdv(Packet *p, int offset);

After this lines add...........
#ifdef MIT_uAMPS
void format_rca(Packet *p, int offset);
#endif
#ifdef MIT_uAMPS
#define ADV_CHAR 'A'
#define REQ_CHAR 'R'
#define DATA_CHAR 'D'
#endif

and also add this line into /home/anupama/ns-allinone-2.34/ns-2.34/tcl/lib/ns-default.tcl (line 765):

    # ——————————————————
    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
    # ——————————————————

9. Now again do a make 
wsn@ubuntu/home/$username/ns-allinone-2.34/ns-2.34$make
wsn@ubuntu/home/$username/ns-allinone-2.34/ns-2.34$bash ./test

Now go to  ns-allinone-2.34/ns-2.34/mit/leach_sims/leach.out
Probably there will be errors in 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)

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

Now for that 
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/anupama/ns-allinone-2.34/ns-2.34/mit/rca/ns-ranode.tcl

#source $env(uAMPS_LIBRARY)/ns-bsapp.tcl

source /home/anupama/ns-allinone-2.34/ns-2.34/mit/uAMPS/ns-bsapp.tcl

#source $env(uAMPS_LIBRARY)/extras.tcl
source /home/anupama/ns-allinone-2.34/ns-2.34/mit/uAMPS/extras.tcl

#source $env(uAMPS_LIBRARY)/stats.tcl

source /home/anupama/ns-allinone-2.34/ns-2.34/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/anupama/ns-allinone-2.34/ns-2.34/mit/rca/resources/ns-resource-manager.tcl

#source $env(RCA_LIBRARY)/resources/ns-energy-resource.tcl

source /home/anupama/ns-allinone-2.34/ns-2.34/mit/rca/resources/ns-energy-resource.tcl

#source $env(RCA_LIBRARY)/resources/ns-neighbor-resource.tcl

source /home/anupama/ns-allinone-2.34/ns-2.34/mit/rca/resources/ns-neighbor-resource.tcl
********************************************************************
Replace anupama with your username.
Again do a bash ./test and hopefully you will get the results in leach.out.
**********************************************************
Now if you want to have a look on the leach-c results, go to file
/home/$username/ns-allinone-2.34/ns-2.34/leach_test
Here you can just replace leach with leach-c and see results of leach-c too.
Again the energy values in this patch is not correct. For making it correct,
 In \mac\Wireless-Phy.cc:
Code:

if (energy_)

{

if(alive_ != 0) // Deepa

{

if (energy_->remove(pktEnergy(Pt_, PXcvr_, ch->size())) != 0)

{

printf("alive = 0\n");

alive_ = 0;

}
} // Deepa

}

i.e., add the <code> if(alive_ != 0) </code> wherever the remove energy function is called,

and in mit\rca\energy.cc :
Code:

int EnergyResource::remove(double amount)

{

double new_level = energy_level_ - amount;

if(new_level >= 0 )

{

energy_level_ = new_level;

expended_ += amount;

} // Deepa
Now again remake and look at the correct energy 
 

 
 

Comments

Popular posts from this blog

Installing Qt Jambi For java

How to Install NS All In One 2.35 in Ubuntu 12.04

What Is Tomcat Default Administrator Password ?