【转】leach协议在NS2.33上的安装

本文提供LEACH协议在NS2.33上的详细安装步骤及注意事项,包括文件修改、环境配置等内容,确保LEACH协议能正常运行。

【转】leach协议在NS2.33上的安装 收藏
转自:http://julysaquarius.blogbus.com/logs/56634215.html

当初装leach的时候,装了好几遍,网上搜到的资料十分少,不过还是有位大侠分享的他的经验,我在他的经验基础了,再加上自己实践出的经验,写下这篇文章。

直接在2.33中安装leach的话,会把原来的相关文件给覆盖,这样2.33上新添加的的协议将不能运行。所以这种方法行不通。为了解决这个问题,既不让其覆盖我们2.33上的文件,也使得leach协议能够运行,那么这种方法就比较复杂了,需要的人工劳动多了一点。

首先我们先找个目录把mit.tar.gz文件解压开来,用 gunzip mit.tar.gz和 tar –xvf mit.tar 解压,但是不直接解压到目录/ns-allinone-2.33/ns-2.33下,而是在/ns-allinone-2.33/ns-2.33/leach 这个目录下,其中的leacn文件夹是自己新建的。

将解压出来的文件A一一的对应我们/ns-allinone-2.33/ns-2.33目录下的文件B进行修改,将A中与B内容不同的地方,添加进B去,切记,不是完全复制,是添加进去,而B中多出来的内容,不要删掉。B中没有的文件,可以直接添加的B里去。这里有个规律,leach协议新添加进去的代码都是以#ifdef MIT_uAMPS开始,#endif为结束的。因此可以快速的进行修改。

注意一点,leach协议解压出来的文件里的tcl/mobility里有4个快捷方式,为了以后运行的方便,我们在给2.33中添加的时候,可以直接把这4个快捷方式所指的文件放进来,而不需要放快捷方式了。

需要额外修改的地方:
1、将common/packet.h里添加的
#ifdef MIT_uAMPS
    PT_RCA,
#endif
修改为:
#ifdef MIT_uAMPS
static const packet_t PT_RCA = 61;
#endif
同理,将最后一个包的值改为62。即 static packet_t  PT_NTYPE = 62


2、将mac/wireless-phy.h文件中,添加进去的
#ifdef MIT_uAMPS
    EnergyResource *energy_;  // Energy resource
    int alive_;         // 0 = dead, 1 = alive
//endif
//ifdef MIT_uAMPS_temp
    double Efriss_amp_;    // Xmit amp  energy (J/bit/m^2)
    double Etwo_ray_amp_;    // Xmit amp energy (J/bit/m^4)
    double  EXcvr_;        // Xcvr energy (J/bit)
    double Pfriss_amp_;    // Friss base transmission  power (W/m^2)
    double Ptwo_ray_amp_;    // Two-ray base transmission power (W/m^4)
    double PXcvr_;          // Xcvr Power (W)
    int sleep_;        // 0 = awake, 1 =  asleep
    int ss_;        // amount of spreading
    double time_finish_rcv_;             double dist_;            // approx. distance to transmitter
private:
double pktEnergy(double pt, double pxcvr, int nbytes);
#endif
中的private注释掉,即为:
#ifdef MIT_uAMPS
    EnergyResource *energy_;  // Energy resource
    int alive_;         // 0 = dead, 1 = alive
//endif
//ifdef MIT_uAMPS_temp
    double Efriss_amp_;    // Xmit amp  energy (J/bit/m^2)
    double Etwo_ray_amp_;    // Xmit amp energy (J/bit/m^4)
    double  EXcvr_;        // Xcvr energy (J/bit)
    double Pfriss_amp_;    // Friss base transmission  power (W/m^2)
    double Ptwo_ray_amp_;    // Two-ray base transmission power (W/m^4)
    double PXcvr_;          // Xcvr Power (W)
    int sleep_;        // 0 = awake, 1 =  asleep
    int ss_;        // amount of spreading
    double time_finish_rcv_;             double dist_;            // approx. distance to transmitter
//private:
double pktEnergy(double pt, double pxcvr, int nbytes);
#endif


3、将mac/wireless-phy.h文件中的第150行,本来注释掉的// MobileNode * node_; 取消注释。


4、将mac/wireless-phy.cc文件中,int  WirelessPhy::command(int argc, const char*const* argv)
这个函数里的node_ = (Node *)obj; 修改为node_ = (MobileNode *)obj;大约在添加好的2.33文件里的238行。


5、由于第4步的修改影响到了其他文件,所以我还需要将mac/wireless-phyExt.cc里的第133行,node_ = (Node *)obj; 同样改为node_ = (MobileNode *)obj;(在int WirelessPhyExt::command(int argc, const char*const* argv)函数里)。

修改MakeFile文件,按照下面三步来进行:
(1)将DMIT_uAMPS添加到DEFINE行的最后,即为
DEFINE = -DTCP_DELAY_BIND_ALL …… -Drng_test -DMIT_uAMPS
(2)将I./mit/rca  I./mit/uAMPS 添加到 INCLUDE列的后面,即为
    INCLUDES = /
    ……

    -I./diffusion3/lib/main -I./diffusion3/lib /

    -I./diffusion3/lib/nr -I./diffusion3/ns /

    -I./diffusion3/filter_core -I./asim/ -I./qs /

    -I./mit/rca -I./mit/uAMPS /

……

(3)将代码
mit/rca/energy.o mit/rca/rcagent.o /
mit/rca/rca-ll.o mit/rca/resource.o /
mac/mac-sensor-timers.o mac/mac-sensor.o mit/uAMPS/bsagent.o /
添加到代码gaf/gaf.o /之前

这样,文件我们就都修改完了,下面就是编译了,即需要make了。

进入到/ns-allinone-2.33/ns-2.33目录下,输入make clean


如果没有出错,输入make,这时就需要较长时间的等待了。(如果你改的文件是makefile.in,那么应该有提示说你的makefile.in文件比make文件新,需要重新configure,这时输入./configure即可。)


make成功后,我们就要测试一下我们的Leach文件是否能够运行了。

这时,直接输入./test,估计肯定会有Line3和Line5行的提示错误,要处理这个问题,只需打开test文件,将里面的代码改为:

#!/bin/bash
cd tcl/exns wireless-demo-csci694.tcl
sleep 2
cd ../../
./leach_test
即可。

重新运行,应该就会得到结果了,显示如下:
num_nodes is set 3
node-configwarning: Please use -channel as shown in tcl/ex/wireless-mitf.tcl
create-wireless-node
DSDV
INITIALIZE THE LIST xListHead
create-wireless-node
DSDV
create-wireless-node
DSDV
Loading connection pattern...
Loading scenario file...
Starting Simulation...
channel.cc:sendUp - Calc highestAntennaZ_ and distCST_
highestAntennaZ_ = 1.5,  distCST_ = 550.0
SORTING LISTS ...DONE!
NS EXITING...

这时,打开/mit/leach_sims/leach.err,也许你会看到有错误,应该是环境变量设置的问题。那么就要对环境变量进行设置,需要在.bashrc中加入环境变量
export RCA_LIBRARY=$(ns的安装目录)/mit/rca
export uAMPS_LIBRARY=$(ns的安装目录)/mit/uAMPS
注意,“ns的安装目录”要改成你自己的目录。

重新运行./test,这时打开/mit/leach_sims/leach.err,也许你还会看到有错误,应该是说环境变量找不到等问题。这时候说明你设置的环境变量没有起作用, 那么你可以直接修改mit/uAMPS/sims/uamps.tcl文件。
将代码
source $env(RCA_LIBRARY)/ns-ranode.tcl
source $env(uAMPS_LIBRARY)/ns-bsapp.tcl
source $env(uAMPS_LIBRARY)/extras.tcl
source $env(uAMPS_LIBRARY)/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 $env(RCA_LIBRARY)/resources/ns-energy-resource.tcl
source $env(RCA_LIBRARY)/resources/ns-neighbor-resource.tcl
修改成代码
source mit/rca/ns-ranode.tcl
source mit/uAMPS/ns-bsapp.tcl
source mit/uAMPS/extras.tcl
source mit/uAMPS/stats.tc
lsource mit/rca/resources/ns-resource-manager.tcl
source mit/rca/resources/ns-energy-resource.tcl
source mit/rca/resources/ns-neighbor-resource.tcl即可。

这时再运行./test应该没有问题了,反正我的安装是没有问题了。

再次打开leach.err文件,里面出现代码:
INITIALIZE THE LIST xListHead
SORTING LISTS ...DONE!

这样就成功了。恭喜你!

 

本文来自优快云博客,转载请标明出处:http://blog.youkuaiyun.com/qq361301276/archive/2010/03/08/5356390.aspx

This is a simulation of LEACH (Low-Energy Adaptive Clustering Hierarchy), a well-known cluster-based protocol for sensor networks with an extension to make it solar-aware. This simulation was created for the following paper: Thiemo Voigt, Hartmut Ritter, Jochen Schiller, Adam Dunkels, and Juan Alonso. Solar-aware Clustering in Wireless Sensor Networks. In Proceedings of the Ninth IEEE Symposium on Computers and Communications, June 2004. http://www.sics.se/~thiemo/iscc2004Final.pdf Abstract: "Energy conservation plays a crucial in wireless sensor networks since such networks are designed to be placed in hostile and non-accessible areas. While battery-driven sensors will run out of battery sooner or later, the use of renewable energy sources such as solar power or gravitation may extend the lifetime of a sensor network. We propose to utilize solar power in wireless sensor networks and extend LEACH, a well-known cluster-based protocol for sensor networks to become solar-aware. The presented simulation results show that making LEACH solar-aware significantly extends the lifetime of sensor networks." The code contains two directories: one is a distributed LEACH version, the other one a centralized where the base station (assumed to know everything) chooses the optimal cluster head. The "optimal" is in the code approximated via rules that include some kind of geopgraphical criteria among others. In solar.h you choose if you want to have solar turned on or not and also set some other parameters. To compile on Linux: opp_makemake -f -N make On Windows with Visual C++: opp_nmakemake -f -N nmake -f Makefile.vc Hope you find the model useful. Thiemo Voigt (thiemo@sics.se) (model packaged by Andras Varga)
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值