Leach协议性能分析(1)

本文介绍如何使用特定脚本分析LEACH协议产生的数据文件,包括节点存活状态、能量消耗及节点间的数据交互情况。
$ ./test

结果文档在mit/uAMPS/sims文件夹下,分别为:wireless.alive    wireless.energy   wireless.data
wireless.alive
第一行是运行时间,第二行就节点ID,第三行是如果是1,表示该节点还存活,如果是0,则表示节点死亡。wireless.energywireless.data也是同样的结构,对于leach产生的数据,可分为很多方面,如节点能量消耗,节点存活数量,速率,节点之间发送与接收数据等。

对于leach.alive,可分析节点存活数,gwak –v outfile=live –f getNodelive.awk leach.alive,其中getNodelive.awk需要自己编写;

getNodelive.awk文件如下:
BEGIN{
      step=10;    #间隔时间
      time=0;    
      i=0;
      j=0;
      }
{if($3==0){ i++; }
j++;
if(j==20){
       j=0;
       printf"%d  %d\n",time,20-i>>outfile;
       time+=step;
       i=0;
}
}

对于leach.energy,可分析节点的能量消耗,如
gawk ‘{if($2==18){ if($3>2) $3=2; print $1,$3>>18.data;} if($2==65){if($3>2) $3=2; print $1,$3>>65.data}}’ leach.energy   (节点18和节点65)

对于leach.tr,可以分析的相当多,如分析节点间发送和接受数据关系
gawk -v src=8 -v  dst=29 -v outfile1=node8 -v outfile2=node29 -f getNodeRecv1.awk leach-out.tr

getNodeRecv1.awk 文件如下:
# getNodeRecv1.awk

BEGIN {largest_seq=0;
packet_send++;
}

{
if($1=="s")
{
if($6>largest_seq)largest_seq=$6;
}
if($1=="s"&&$3==("_" src "_")&&$4=="AGT")
{
packet_send++;
send_time[$6]=$2;
}
if($1=="r"&&$3==("_" dst "_")&&$4=="MAC")
{
packet_rcvd++;
rcvd_time[$6]=$2;
}
}
END{
for(i=0;i<largest_seq;i++)
{if(rcvd_time[i]!=0)
{printf"%f %d\n",rcvd_time[i],i>>outfile2;}
if(send_time[i]!=0)
{printf"%f %d\n",send_time[i],i>>outfile1;}
}
}

getRatio1.awk文件如下:
# 速率
# 初始化设定
BEGIN {
        sendLine = 0;
        recvLine = 0;
    fowardLine = 0;
}
# 应用层收到包
$0 ~/^s.* AGT/ {
        sendLine ++ ;
}
# 应用层发送包
$0 ~/^r.* AGT/ {
        recvLine ++ ;
}
# 路由层转发包
$0 ~/^f.* RTR/ {
        fowardLine ++ ;
}
# 最后输出结果
END {
        printf "cbr s:%d r:%d, r/s Ratio:%.4f, f:%d \n", sendLine, recvLine, (recvLine/sendLine),fowardLine>>outfile;
}
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)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值