文档库 最新最全的文档下载
当前位置:文档库 › Leach协议

Leach协议

目录

一、Leach协议与NS的关系 (2)

二、算法设计思想 (3)

三、簇头建立算法流程图 (4)

四、难点解决 (6)

五、算法运行结果分析 (9)

参考文献 (9)

一、Leach协议与NS的关系

为了实现leach 协议,对ns进行扩展。在ns中增加了一个事件驱动模拟器支持模拟无线传感器网络协议。这些扩展包括MAC协议,用于计算和交互的能量分配模型和leach协议的体系结构。

网络拓扑结构可以通过简单的Nodes, Links, Agents和Applications 描述。Nodes相当于网络中的终端主机, Links 是用于Nodes交互的连接器, Agent用来实现不同网络协议,是支持分组产生和丢弃的节点。Applications 用来产生数据和实现不同的应用函数。一旦网络拓扑结构建立起来后,模拟通过启动节点上的Applications运行。

为了在ns中支持无线传感器网络,在ns中增加了 mobile nodes, MAC 协议和信道传播模型Channel 。

Applications类的头文件用Tcl语言写的,节点中的其他函数功能用C++语言写成的。

数据包的发送过程:

Applications创建数据包(data packets),然后发送给Agent. Agent执行协议栈中运输层和网络层的功能,将数据包发送给CMUTrace,。 CMUTrace将packets的统计数据写到trace 文件,然后将packets发至Connector。Connector将数据包传送给用于数据链路处理的链路层(LL).经过一小段时间的延迟后,数据包由LL发送给Queue缓冲队列。如果是还没有传送过的数据包,Queue将以队列进行存储。然后Queue将数据包出队列,发送到MAC层。然后开始运行MAC(媒体访问控制)协议。最终,packets被发送到网络接口层(Network Interface),网络接口层将packets加上正确的传输能量,然后将packets发送到Channel. Channel将packets进行拷贝,并发往连接信道的每一个节点。

发送过程可参考如下图1

数据包的接收过程:

数据包被节点的网络接口接收,并被向上传送至MAC层,Link-Layer, Connector, CMUTrace, 和Agent 函数. Agent 对数据包进行判定,并将数据包到达的信息通知给Application.

接收过程与发送过程传输的路径相反。

二、算法设计思想

Leach协议跨越几个层次实现的协议,Leachapp应用在最高层Application。它是自适应分簇拓扑算法。周期执行,每轮循环分为簇头的建立阶段和稳定的数据通信阶段。

(1)簇头建立阶段:初始阶段,每个节点从0和1中随机产生一个数,如果这个数小于阀值T(n),该节点就成为当前轮的簇头。

其中,P是期望的簇头数在所有节点中占的百分比,r是选举轮数,r mod (1/p)代表这一轮循环中当选过簇头的节点个数,G是这一轮循环中未当选过簇头的节点集合。

每个节点自主选择是否成为当前轮的簇头并通过广播的形式报告给其他节点。簇头通过CSMA MAC协议进行广播,所有的簇头以相同的传输能量进行广播。

簇头建立起来之后,每个非簇头节点要决定在当前轮中自己属于哪个簇头。非簇头节点根据收到的广播信号强度决定加入哪个簇头。非簇头节点决定了自己属于哪个簇头后,必须通知簇头节点它是该簇的成员。非簇头节点同样通过CSMA MAC协议将自己加入该簇的信息报告给簇头节点。

簇头节点收到所有的非簇头节点加入的信息后,基于本簇内加入的节点数目创建TDMA调度,通知每个节点什么时间可以传输数据。

在leach协议中,具体通过calculatePi()函数计算门限值thresh.

double LeachApp::calculatePi()

{

register int n = config_.numberNodes_; //节点个数

register int k = config_.desiredClusters_; //期望簇头数

double thresh; //阀值

if (hasBeenClusterHead())

thresh = 0; //已经是簇头,本轮中不再成为簇头

else if (n - k * round_ < 1)

thresh = 1; //将节点设置为簇头else

thresh = (double) k / (n - k * round_);

return thresh;

}

(2)数据传输阶段:

一个簇内的信息传输会影响相邻簇。为了减少这种信号干扰,各个簇内的信息交互通过不同的CDMA编码。簇头可以决定本簇中节点所用的CDMA编码。这个用于当前阶段的CDMA编码在广播簇头的时候发送给簇内节点。具体在advertiseClusterHead()中实现。

此外,簇头根据本簇内的节点个数创建TDMA调度。具体的,簇头在findBestCluster()函数中调用createSchedule(),而由createSchedule()函数具体创建TDMA调度。

当簇内节点收到这个消息后,它们会在各自的时间槽内发送数据。簇头节点收到所有的数据后执行信号处理函数压缩数据为一个信号,并将这个合成的信号发给基站。

三、簇头建立算法流程图

簇头的建立是在decideClusterHead()函数实现。具体流程图如图1

N

N

N

图1 簇头建立算法流程图

四、难点解决

1. CDMA编码问题

Leach协议中不同簇内用不同的CDMA编码,同一个簇内采用同一个CDMA 编码进行数据传输。如果以各个簇头为结点,建立完全图。为了使各个簇采用不同的编码,利用PCA边着色。

所谓PCA边着色问题,指在完全图中给节点的每条邻接边分配不同的码。每个节点用一个码在其邻接边(即链路)上进行发送或接收数据。

以下,图2是PCA着色问题的一个示例。

图2 PCA边着色示意图

如果记PCA需要的最大可用码数为:#(PCA)

根据图论知识:

#(PCA)<=2⊿-1 ,其中⊿指图中节点的最大度数

例如:在图2中,节点的最大度数为6,故⊿为6

在leach协议中,假定期望的簇头数为n,再加上汇聚节点,所以,节点的最大度数⊿为(n+1)。因此,

#(PCA)<=2(n+1)-1=2n+1

在https://www.wendangku.net/doc/f0142512.html,程序中,簇头建立后,簇头决定本簇内的CDMA编码。这是在广播簇头时确定的,即advertiseClusterHead()函数中。

numCodesAvail = 2 * config_.spreading_ - 1; //计算最大可用码

clusterCode = (mac_->myADVnum() % numCodesAvail) + 1; //设置CDMA 编码

在https://www.wendangku.net/doc/f0142512.html,程序中,struct leachConfig中对desiredClusters_(期望的簇头数)和config_.spreading进行了定义。

在initializeConfig()函数中语句:

config_.spreading_ = config_.desiredClusters_ + 1在LeachApp的构造函数LeachApp(int nNodes, int nClusters, double maxDist) 中语句:config_.desiredClusters_ = nClusters

在TCL脚本中

set val(n_common) 10 //普通节点个数可任意设置,此处设为10

set val(n_ch) 0 //簇头数初始值为0

set val(n_ch) [expr int($val(n_common) * 2 / 10)] //对期望的簇头数进行了设置,为普通节点个数的20%(即上式中的 2/10)因此,可以计算得出numCodesAvail

在mac-sensor.h中,

int myADVnum_; // 收到的广播消息,即邻近的簇头节点的个数

inline int & myADVnum() { return myADVnum_; }

myADVnum()是在MAC层中计算求得。启动运行后,计算每个簇头的邻近簇头发来的ADV。

因此,可求得clusterCode

2. TDMA调度

在findBestCluster()函数中,当判定节点是簇头节点时需要createScheduler。在createScheduler函数中,如果簇内节点不空,就需要创建TDMA时分复用帧。

frameTime 表示该簇头节点分配的一个时间帧;

clusterNodes_.size() 表示一个簇内的节点个数

config_.ssSlotTime_ 表示一个时间帧内的小的时隙

lstRndDelay 表示缓冲时间

xmitTime_ 表示簇内所有节点的数据发送时间

createScheduler函数主要语句如下:

frameTime_ = (5 + clusterNodes_.size()) * config_.ssSlotTime_; //计算时间帧

lstRndDelay_ = Random::uniform(0, 0.01); //随机选取缓冲时间

xmitTime_ = config_.ssSlotTime_ * (clusterNodes_.size()) + lstRndDelay_;

Scheduler::instance().schedule(

eventHandler_,

new LeachEvent(&LeachApp::sendDataToBS),

xmitTime_);

3. clearClusterChoices()

由于各个簇头形成和建立起来的时间不同,而簇头建立起来后需要广播ADV, 通知其他节点加入。簇头广播的ADV会被网络中的所有节点接收到,即簇头和普通节点都能收到先建立起来的簇头发来的ADV。普通节点收到簇头发来的通知包后都会将该数据包加入自己的一个接收队列。对后来建立起来的簇头来说,一旦自己成为簇头,就会删除其他簇头发来的广播包;对没有成为簇头的普通节点来说,需要出接收的簇头队列中选出一个距离最近的簇头加入,然后删除接收队列中的广播包。

在decideClusterHead()函数中,当节点成为簇头后,需要执行clearClusterChoices(), 函数clearClusterChoices()主要语句如下:for (CHs::iterator it = clusterChoices_.begin(); it != clusterChoices_.end(); it++)

{

chadv element = (chadv) *it;

if (element.object != NULL)

delete element.object;

}

而普通节点则需要在findBestCluster()中找到最优簇头(即距离最近的簇头)后,执行clearClusterChoices()

4. 一些定义

(1)virtual double TxTime(int n) { return n * 8.0 / 1000000.0; }

TxTime指以1 Mbps的速度传输n bit数据所需要的时间

(2) double lstRndDelay_; // 上次随机延迟时间int currentCH_; //当前簇头

int currentCHMAC_; //当前簇头所用的MAC协议

bool listenADV_; // 是否收听ADV

bool listenJOINREQ_; // 是否监听加入请求

五、算法运行结果分析

1.场景介绍

用ns模拟每个节点向基站传输数据

Basic Configuration:

图3 Basic Configuration配置图Access Point:

图4 Access Point配置图

Common Node:

图5 Common Node配置图

输出得到TCL文件。在ns环境下运行该TCL文件,得到trace文件。

2. trace 文件分析

trace的功能是详细记录模拟的过程,可以根据用户的需要记录模拟过程中的任何一个细节。所有对模拟的分析是基于trace文件。截取一部分文件代码如下:

s -t 0.007580973 -Hs 1 -Hd -2 -Ni 1 -Nx 48.64 -Ny 86.26 -Nz 0.00 -Ne 10.000000 -Nl AGT -Nw --- -Ma 0 -Md 1000000 -Ms 0 -Mt 0 -Is 1.0 -Id -1.0 -It rca -Il 4 -If 0 -Ii 0 -Iv 32

r -t 0.007580973 -Hs 1 -Hd -2 -Ni 1 -Nx 48.64 -Ny 86.26 -Nz 0.00 -Ne 10.000000 -Nl RTR -Nw --- -Ma 0 -Md 1000000 -Ms 0 -Mt 0 -Is 1.0 -Id -1.0 -It rca -Il 4 -If 0 -Ii 0 -Iv 32

s -t 0.007580973 -Hs 1 -Hd -2 -Ni 1 -Nx 48.64 -Ny 86.26 -Nz 0.00 -Ne 10.000000 -Nl RTR -Nw --- -Ma 0 -Md 1000000 -Ms 0 -Mt 0 -Is 1.0 -Id -1.0 -It rca -Il 4 -If 0 -Ii 0 -Iv 32

在文件分析中主要用到t, Ni, Ne这几个数据。其中,t 后面的数字代表时间,Ni后面的数字代表节点ID,Ne后面的数字代表节点能量

使用语言gwak, 绘图工具gnuplot. 上述场景中生成的trace文件名为:trace.tr

去掉所有以N开头的行数,该行为统计数据,得到文件trace1.tr

(1)单个节点能量变化统计:

以节点1为例,提取所有Ni等于1的节点的时间和相应能量,存入文件

1.txt.

在gawk环境中,输入代码如下:

gawk ‘$9==/1/{print $3,$17}’trace1.tr >1.txt

得到统计数据如下:

0.007580973 10.000000

0.007580973 10.000000

0.007580973 10.000000

0.007605973 10.000000

2.461346376 9.963363

2.461371376 9.963363

2.461371376 9.963363

3.536372973 9.945803

3.536372973 9.945803

3.536372973 9.945803

3.536397973 9.945803

在gnuplot环境中输入:

gnuplot ‘1.txt’ using 1:2

得到的能量变化图如下图所示:

图6 节点1能量变化图

(2) 工作节点能量统计:

从trace.tr文件中提取普通节点的数据。

gawk ‘$1~/N/ { print $3,$5,&7 }’ trace.tr >n.txt //第3列代表

时间,第5列代表节点ID,

第7列代表能量值 gawk ‘$2!=0 { print $1,$3}’n.txt >2.txt //去掉sink节点,sink 节点ID为0

再从2.txt中进行能量统计,统计时间间隔为0.5秒

gawk ‘{ if($1<0.5) sum+=$2 };

END { print sum }’ 2.txt >3.txt

gawk ‘{ if($1<1.0) sum+=$2 };

END { print sum }’ 2.txt >>3.txt

gawk ‘{ if($1<2.5) sum+=$2 };

END { print sum }’ 2.txt >>3.txt

gawk ‘{ if($1<3.0) sum+=$2 };

END { print sum }’ 2.txt >>3.txt

gawk ‘{ if($1<3.5) sum+=$2 };

END { print sum }’ 2.txt >>3.txt

gawk ‘{ if($1<4.0) sum+=$2 };

END { print sum }’ 2.txt >>3.txt

gawk ‘{ if($1<4.5) sum+=$2 };

END { print sum }’ 2.txt >>3.txt

得到文件3.txt的统计数据如下:

0.5 3918.84

1.0 2937.01

2.5 1395.12

3.0 4700.22

3.5 519

4.79

4.0 3271.12

4.5 1132.38

全网间隔时间为0.5秒工作节点能量变化图:

图7 工作节点能量变化图

3.全网所有节点能量和变化统计

在gawk环境下输入:

gawk ‘$9!=0 { print $3,$9,$17}’trace1.tr >4.txt//提取普通节点的时间,ID,能量

将以下程序写入文件1.awk

BEGIN{

FS=" "

unit=0.5;

ftime=0;

time=0;

for(i=1;i<=50;i++)

{ e[i]=10.0;

sum+=e[i];

}

printf "%f ,%f\n",time,sum;

time+=unit;

}

{

if(ftime<$1 &&$1

{ k=$2;

e[k]=$3;

}

}

END {

sum=0

for(i=1;i<=50;i++)

sum+=e[i]

printf "%f,%f\n",time,sum;

}

在awk环境下,输入

awk –f 1.awk trace1.tr >5.txt

在5.txt文件中得到的是0到0.5秒之间全网的总能量。

再不断地将每个时间间隔为0.5秒的数据写入文件5.txt(只需在文件

5.txt 中不断追加统计数据)。最后可以得到0到4.5秒之间全网在每0.5

秒的时间间隔内的总能量。

最后得到的5.txt统计数据如下:

0.000000 ,500.000000

0.500000,499.757217

1.000000,499.504800

1.500000,499.504800

2.000000,499.504800

2.500000,499.172733

3.000000,498.436798

3.500000,497.875816

4.000000,497.525730

4.500000,496.948944

在gnuplot环境下,输入命令:

gnuplot ‘5.txt’ using 1:2 with lp

最后得到的全网能量变化情况如下图所示:

图8 全网能量统计图

4. 生成的簇头和簇内节点统计

设置普通节点个数50,AP节点1个,仿真时间10秒,普通节点位置随机产生。生成TCL文件,运行该TCL文件将结果输出到2.tr文件中。

在gawk环境中,输入下列命令:

gawk ‘($1==”On”)&&($7==”at”){print $0}’ 2.tr >3.tr

gawk ‘BEGIN {FS=”“}; {print $10,$11,$12,$13,$14,$15,$16}’3.tr > 3.txt 在3.txt文件中得到以下数据:

ClusterHead 11,ClusterNode: 47

ClusterHead 23,ClusterNode: 10 28 16 35

ClusterHead 9,ClusterNode: 33 26

ClusterHead 25,ClusterNode: 49 2 19 46

ClusterHead 24,ClusterNode: 41 29 36 7 21

ClusterHead 37,ClusterNode: 8

ClusterHead 50,ClusterNode:

ClusterHead 15,ClusterNode: 6 3 48

ClusterHead 39,ClusterNode: 45 22 34 31 5

ClusterHead 18,ClusterNode: 30

ClusterHead 40,ClusterNode: 44

ClusterHead 42,ClusterNode: 32 17 14

ClusterHead 13,ClusterNode: 38 27 4 12 20

ClusterHead 43,ClusterNode: 1

5. 生成的nam图

图9 nam图

参考文献

[1] 《Distributed code assignments for CDMA packet radio networks》(FTP:10.10.138.1)

[2] 《heinzelman_PhDthesis_Application-Specific Protocol Architectures for Wireless Networks》(FTP:10.10.138.1)

[3] 《Leach_PPT》(FTP:10.10.138.1)

[4] 《NS与网络模拟》(徐雷鸣,庞博,赵耀编著,人民邮电出版社)

Ns2.34上leach协议的完美移植

Ns2.34上leach协议的完美移植 经过几天的不断实验,以及网上各位前辈的帮助,终于成功将leach协议完美移植到ns2.34上,下面是我的安装笔记。 Step1 在ns-2.34的目录下新建一个leach文件夹,将leach.tar.gz放入这个文件夹 Step2 在终端中进入这个目录下,键入tar zxf leach.tar.gz Step3 ①将leach/mit整个目录复制到ns-allinone-2.34/ns-2.34中 ②将leach/mac目录下的https://www.wendangku.net/doc/f0142512.html,, mac-sensor.h, https://www.wendangku.net/doc/f0142512.html,, mac-sensor-timers.h四个文件复制到ns-allinone-2.34/ns-2.34/mac中 ③将leach/tcl/mobility目录下的四个文件复制到ns-allinone-2.34/ns-2.34/tcl/mobility中 ④将ns-allinone-2.34/ns-2.34/tcl/ex目录下的wireless.tcl重命名为wireless_1.tcl,再将leach/tcl/ex目录下的wireless.tcl复制到ns-allinone-2.34/ns-2.34/tcl/ex中⑤将leach目录下的test,leach_test,package_up三个文件复制到ns-allinone-2.34/ ns-2.34中 Step3 修改文件 ①需要修改的文件有: ns-allinone-2.34/ns-2.34/apps/https://www.wendangku.net/doc/f0142512.html,,app.h ns-allinone-2.34/ns-2.34/trace/https://www.wendangku.net/doc/f0142512.html,,cmu-trace.h ns-allinone-2.34/ns-2.34/common/https://www.wendangku.net/doc/f0142512.html,,https://www.wendangku.net/doc/f0142512.html,,packet.h ns-allinone-2.34/ns-2.34/mac/https://www.wendangku.net/doc/f0142512.html,,ll.h,https://www.wendangku.net/doc/f0142512.html,,https://www.wendangku.net/doc/f0142512.html,,phy.h,wireless-phy.c c,wireless-phy.h ②修改方法: 对于leach目录下相应的文件(即刚才未复制的文件),将代码中以“#ifdef MIT_uAMPS”开始,并以“#endif”结束的部分复制到以上文件对应的位置 这个过此要小心核对修改,否则前功尽弃 ③特殊情况 <1> ns-allinone-2.34/ns-2.34/common/packet.h中大约185行,根据其他变量的格式将代码更改为 #ifdef MIT_uAMPS static const packet_t PT_RCA = 61; #endif 并将最后一个枚举值改为62 这个过程可以随情况改变,还要注意的是packet.h文件并不是只改这一部分,前面的修改依然要。 <2> ns-allinone-2.34/ns-2.34/mac/wireless-phy.h,给类WirelessPhy添加public变量,大约105行 #ifdef MIT_uAMPS MobileNode * node_;

LEACH协议的算法结构及最新研究进展

LEACH协议的算法结构及最新研究进展 1 LEACH协议算法结构 LEACH这个协议的解释是:低功耗自适应集簇分层型协议。通过名字,我们就能想到这个协议的大概作用了。那么在这之中,我们先来研究一下它的算法。 该算法基本思想是:以循环的方式随机选择蔟首节点,将整个网络的能量负载平均分配到每个传感器节点中,从而达到降低网络能源消耗、提高网络整体生存时间的目的。仿真表明,与一般的平面多跳路由协议和静态分层算法相比,LEACH协议可以将网络生命周期延长15%。LEACH在运行过程中不断的循环执行蔟的重构过程,每个蔟重构过程可以用回合的概念来描述。每个回合可以分成两个阶段:蔟的建立阶段和传输数据的稳定阶段。为了节省资源开销,稳定阶段的持续时间要大于建立阶段的持续时间。蔟的建立过程可分成4个阶段:蔟首节点的选择、蔟首节点的广播、蔟首节点的建立和调度机制的生成。 蔟首节点的选择依据网络中所需要的蔟首节点总数和迄今为止每个节点已成为蔟首节点的次数来决定。具体的选择办法是:每个传感器节点随机选择0-1之间的一个值。如果选定的值小于某一个阀值,那么这个节点成为蔟首节点。 选定蔟首节点后,通过广播告知整个网络。网络中的其他节点根据接收信息的信号强度决定从属的蔟,并通知相应的蔟首节点,完成蔟的建立。最后,蔟首节点采用TDMA方式为蔟中每个节点分配向其传递数据的时间点。 稳定阶段中,传感器节点将采集的数据传送到蔟首节点。蔟首节点对蔟中所有节点所采集的数据进行信息融合后再传送给汇聚节点,这是一种叫少通信业务量的合理工作模型。稳定阶段持续一段时间后,网络重新进入蔟的建立阶段,进行下一回合的蔟重构,不断循环,每个蔟采用不同的CDMA代码进行通信来减少其他蔟内节点的干扰。 LEACH协议主要分为两个阶段:即簇建立阶段(setup phase)和稳定运行阶段(ready phase)。簇建立阶段和稳定运行阶段所持续的时间总和为一轮(round)。为减少协议开销,稳定运行阶段的持续时间要长于簇建立阶段。 在簇建立阶段,传感器节点随机生成一个0,1之间的随机数,并且与阈值T(n)做比较,如果小于该阈值,则该节点就会当选为簇头。在稳定阶段,传感器节点将采集的数据传送到簇首节点。簇首节点对采集的数据进行数据融合后再将信息传送给汇聚中心,汇聚中心将数据传送给监控中心来进行数据的处理。稳定阶段持续一段时间后,网络重新进行簇的建立阶段,进行下一轮的簇重建,不断循环。 2 LEACH协议的特点 1 为了减少传送到汇聚节点的信息数量,蔟首节点负责融合来自蔟内不同源节点所产生的数据,并将融合后的数据发送到汇聚点。 2 LEACH采用基于TDMA/CDMA的MAC层机制来减少蔟内和蔟间的冲突。 3 由于数据采集是集中的和周期性的,因此该协议非常适合于要求连续监控的应用系统。 4 对于终端使用者来说,由于它并不需要立即得到所有的数据,因此协议不需要周期性的传输数据,这样可以达到限制传感器节点能量消耗的目的。 5 在给定的时间间隔后,协议重新选举蔟首节点,以保证无线传感器网络获取同意的能量分布。

WSN中LEACH协议源码分析报告

WSN中LEACH协议源码分析 分析(一) 首先对wireless.tcl进行分析,先对默认的脚本选项进行初始化: set opt(chan)Channel/\VirelessChannel set opt(prop) Propagatioii/TwoRayGround set opt(netif)PhyAVirelessPhy set opt(mac) Mac/802_l 1 set opt(ifq) Qucuc/DropTail/PriQueue set opt(ll) LL set opt(ant) Antenna/OmniAntenna set opt(x) 0 。# X dimension of the topography set opt(y) 0。# Y dimension of the topography set opt(cp),H, set opt(sc) N../mobility/scene/scen-670x670-50-600-20-2u。# scenario file set opt(ifqlen)50o # max packet in if set opt(nn) 51。# number of nodes set opt(secd) 0.0 set opt(stop) 10.0 o # simulation time set opt(tr) out.tr。# trace file set opt(rp) dsdv 。 # routing protocol script set opt(lm) M on H。# log movement 在这个wireless.tcl中设置了一些全局变呈:: # #Initialize Global Variables # set ns_ [new Simulator] set chan [new $opt(chan)] set prop [new $opt(prop)] set topo [newTopography] set tracefd [open Sopt(tr) w] Stopo Ioad_flatgrid $opt(x) $opt(y) Sprop topography Stopo 这些初始化将在后而的使用中用到,该文件最重要的是创建leach 17点:创建方法如下: } elseif { [string compare Sopt(rp) M leach,,]==0} { for {set i 0} {$i < $opt(nn) } {incr i} { leach-create-mobile-node $i } 如果路由协议是leach协议,则在Uamps.tcl中调用leach-create-mobile-node方法创建leach节点。将在第二小节讲如何创建leach节点。 for {set i 0} {$i < $opt(nn) } {incr i} { $ns_ at $opt(stop).000000001 M Snode_($i) reset”。〃完成后,重宜右点的应用

无线传感器网络LEACH协议研究

无线传感器网络LEACH协议的研究 摘要:无线传感器网络因其在军事、经济、民生等方面广阔的应用前景成为21世纪的前沿热点研究领域[1]。在传感器节点能量有限的情况下,提高路由效率,延长网络寿命成为无线传感器网络需考虑的问题。由于采取分簇,数据融合的思想,LEACH协议有着较高的路由效率,但在实际应用,尤其是大规模网络中,仍存在负载不均衡等问题。本文主要分析了LEACH协议的基本思想及优缺点,随后针对大规模的网络环境对其分簇算法进行改进。前人提出一种有效的方法计算最优簇首个数,本文推算出适合本文中网络环境的公式并加以应用。本文用NS2进行仿真,仿真后的结果表明,改进后的分簇算法更为有效,延长了网络寿命,增大了网络传送数据量。 关键词:无线传感器网络;路由协议;LEACH;分簇思想 Research on Routing Protocol of LEACH in WSN Shen Y uanyi Dept. of Information and Telecommunication,NUPT ABSTRACT:Nowadays, wireless sensor network has become a hot spot of 21st century because of its wide application on military, economy and human life. On the condition that the energy of a sensor node is limited, how to improve the routing efficiency and expand the network’s lifespan has been an important issue to consider. LEACH maintains quite high routing efficiency for its idea of clustering and data gathering. But in practical, it still has problems such as load unbalance especially in large scale network. The article mainly analyses the basic idea of LEACH, the benefits and drawbacks of it and later introduce an improvement on clustering algorithm according to large scale network. Key words:WSN;routing protocol; LEACH; clustering 1LEACH协议介绍与分析 1.1 LEACH算法思想 算法基本思想[2]是:以循环的方式随机选择簇头节点,将整个网络的能量负载平均分配到每个传感器节点中,从而达到降低网络能源消耗、提高网络整体生存时间的目的。LEACH在运行过程中不断的循环执行簇的重构过程,每个簇重构过程可以用回合的概念来描述[3]。每个回合可以分成两个阶段:簇的建立阶段和传输数据的稳定阶段。 1.2 LEACH算法的分析 LEACH协议的优点[4]有: (1)LEACH 通过减少参与路由计算的节点数目,减少了路由表尺寸。(2)LEACH协议是一种分簇路由协议,降低了非簇首节点的任务复杂度,不必对通信路由进行维护。(3)协议不需要周期性的传输数据。(4)在给定的时间间隔后,协议重新选举簇首节点,以保证无线传感器网络获取同意的能量分布。 由于LEACH算法是建立在一些假设上,所以在实际应用中LEACH协议存在一些问题:(1)在LEACH协议中,簇头的选举是随机产生的,这样的随机性可能会导致簇头

LEACH协议簇头

《单片机原理与接口技术》期中论文 论文题目 LEACH协议簇头 选择算法的改进 姓名 学号 学院电气工程学院 专业班级 2008级通信工程

目录 引言................................. 错误!未定义书签。 1 LEACH协议 .......................... 错误!未定义书签。 LEACH 协议介绍.................... 错误!未定义书签。 LEACH 协议的能量损耗模型.......... 错误!未定义书签。 LEACH 的不足在于:................ 错误!未定义书签。 LEACH 协议的优化.................. 错误!未定义书签。 基本思想....................... 错误!未定义书签。 改进细节........................ 错误!未定义书签。 2 簇头选择算法的改进LEACH-H ........... 错误!未定义书签。 簇头初选........................... 错误!未定义书签。 簇头调整过程....................... 错误!未定义书签。 3仿真结果 ............................ 错误!未定义书签。 4仿真分析 ............................ 错误!未定义书签。 5结束语 .............................. 错误!未定义书签。参考文献 ............................. 错误!未定义书签。

Ubuntu安装ns-2.35及leach协议安装

Ubuntu 13.10下安装ns-2.35及leach协议安装 powered by Hong Sheng , Jiangsu university ,Zhenjiang 583301743@https://www.wendangku.net/doc/f0142512.html, Tue Nov 25 , 2013 之所以选择基于linux的操作系统ubuntu来安装ns2,是因为我个人特别讨厌Microsoft 开发的基于windows的cygwin软件,此软件安装的时候不仅有各种错误,UI也不够友好。而,有关ubuntu的安装,大家可以自行baidu或google之。下面只讲解ns-2.35和leach协议的安装过程。 1. Ubuntu 13.10下ns- 2.35安装 step 1:下载ns2.35,https://www.wendangku.net/doc/f0142512.html,/s/1h8rj0#dir/path=%2FNS解压,放在home/xx下,xx是你的用户名 step 2:更新源包,终端输入:sudo apt-get update step 3:安装依赖包 sudo apt-get install tcl8.5-dev tk8.5-dev sudo apt-get install build-essential autoconf automake sudo apt-get install perl xgraph libxt-dev libx11-dev libxmu-dev step 4:修改ns-allinone-2.35中ls.h文件的代码 将void eraseAll() { erase(baseMap::begin(), baseMap::end()); } 改为: void eraseAll() { this->erase(baseMap::begin(), baseMap::end()); } step 5:sudo ls /usr/bin/gcc* //查看系统已经安装的gcc版本。Ubuntu 13.10默认安装了gcc-4.8 //和gcc-4.8版本的,如果是其他版本的linux操作系统且没有安装 //高于4.0版本的gcc/g++。则需要手动安装gcc/g++-4.8 sudo apt-get install gcc-4.8 g++-4.8 // 对于Ubuntu 13.10,此项是非必须的 sudo export CC=gcc-4.8 sudo export CXX=g++-4.8 //CC和CXX是全局变量,用来指定make将会用哪个版本的gcc/g++编译器生成 //makefile文件。如果没有这一步,保证你会makefile失败!!!因为,在ns-2.35文件夹//下的makefile.in 中要求配置全局变量。 echo $CC echo $CXX //查看全局变量导入成功了没有,如果成功,则执行 sudo ./install //开始进行安装,大概等5分钟左右。 ....... 出现以下的内容,每个人的/home/xx/不同,我的用户名是nan,所以,显示了以下信息。 Ns-allinone package has been installed successfully. Here are the installation places: tcl8.5.10: /home/nan/ns-allinone-2.35/{bin,include,lib} tk8.5.10: /home/nan/ns-allinone-2.35/{bin,include,lib} otcl: /home/nan/ns-allinone-2.35/otcl-1.14 tclcl: /home/nan/ns-allinone-2.35/tclcl-1.20 ns: /home/nan/ns-allinone-2.35/ns-2.35/ns nam:/home/nan/ns-allinone-2.35/nam-1.15/nam xgraph: /home/nan/ns-allinone-2.35/xgraph-12.2 gt-itm: /home/nan/ns-allinone-2.35/itm, edriver, sgb2alt, sgb2ns, sgb2comns, sgb2hierns

LEACH协议的MATLAIB仿真代码

Matlab Code for LEACH NodeNums = 100; % the num of node AreaR = 100 ; % the area of simulate NodeTranR=10; % the transit Radius Elec=50 * 10^(-9); % Eamp=100*10^(-12); Bx=50; % The Postion of Baseation By=175; MaxInteral =700; % the leach simulate time Pch=0.05; % the desired percentage of cluster heads InitEn=0.5; % the init energy of all node Tr=30; TDMA=100; Kbit=2000; % the bits of a node transmiting a packet every time BandWitch = 1*10.^(6); % Channel Bandwitch TOS_LOCAL_ADDRESS = 0; for i=1:(MaxInteral) AliveNode(i)=NodeNums; AmountData(i)=0; end sym alldata; alldata=0; LAECH = zeros(1,MaxInteral); LAENO = zeros(1,MaxInteral); for i=1:1:NodeNums EnNode(i)=InitEn; % the init energy of all node StateNode(i)=1; % the State of all node 1: alive 0:dead ClusterHeads(i)=0; % the Set of Cluster Head ,1: cluster head 0 :node Rounds=0; % the round end Threshold=0; % the threshold of node becoming a cluster-head Node.x=AreaR*rand(1,NodeNums); % the position of node Node.y=AreaR*rand(1,NodeNums); Node.c=zeros(1,NodeNums); Node.d=zeros(1,NodeNums); Node.l=zeros(1,NodeNums); Node.csize=zeros(1,NodeNums); Node.initclEn=zeros(1,NodeNums); % for i=1:NodeNums % Node.c(i)=0; % the Cluster head of node

SEP协议

1 SEP:A Stable Election Protocol for clustered heterogeneous wireless sensor networks G EORGIOS S MARAGDAKIS I BRAHIM M ATTA A ZER B ESTAVROS Computer Science Department Boston University gsmaragd,matta,best@https://www.wendangku.net/doc/f0142512.html, Abstract—We study the impact of heterogeneity of nodes, in terms of their energy,in wireless sensor networks that are hierarchically clustered.In these networks some of the nodes become cluster heads,aggregate the data of their cluster members and transmit it to the sink.We assume that a percentage of the population of sensor nodes is equipped with additional energy resources—this is a source of heterogeneity which may result from the initial setting or as the operation of the network evolves. We also assume that the sensors are randomly(uniformly) distributed and are not mobile,the coordinates of the sink and the dimensions of the sensor?eld are known.We show that the behavior of such sensor networks becomes very unstable once the?rst node dies,especially in the presence of node heterogeneity.Classical clustering protocols assume that all the nodes are equipped with the same amount of energy and as a result,they can not take full advantage of the presence of node heterogeneity.We propose SEP,a heterogeneous-aware protocol to prolong the time interval before the death of the?rst node(we refer to as stability period),which is crucial for many applications where the feedback from the sensor network must be reliable. SEP is based on weighted election probabilities of each node to become cluster head according to the remaining energy in each node.We show by simulation that SEP always prolongs the stability period compared to(and that the average throughput is greater than)the one obtained using current clustering protocols. We conclude by studying the sensitivity of our SEP protocol to heterogeneity parameters capturing energy imbalance in the network.We found that SEP yields longer stability region for higher values of extra energy brought by more powerful nodes. I.I NTRODUCTION Motivation:Wireless Sensor Networks are networks of tiny, battery powered sensor nodes with limited on-board process-ing,storage and radio capabilities[1].Nodes sense and send their reports toward a processing center which is called“sink.”The design of protocols and applications for such networks has to be energy aware in order to prolong the lifetime of the network,because the replacement of the embedded batteries is a very dif?cult process once these nodes have been deployed.Classical approaches like Direct Transmission and Minimum Transmission Energy[2]do not guarantee well balanced distribution of the energy load among nodes of the sensor https://www.wendangku.net/doc/f0142512.html,ing Direct Transmission(DT),sensor nodes transmit directly to the sink,as a result nodes that are far away from the sink would die?rst[3].On the other hand, using Minimum Transmission Energy(MTE),data is routed This work was supported in part by NSF grants ITR ANI-0205294,EIA-0202067,ANI-0095988,and ANI-9986397.over minimum-cost routes,where cost re?ects the transmission power expended.Under MTE,nodes that are near the sink act as relays with higher probability than nodes that are far from the sink.Thus nodes near the sink tend to die fast.Under both DT and MTE,a part of the?eld will not be monitored for a signi?cant part of the lifetime of the network,and as a result the sensing process of the?eld will be biased.A solution proposed in[4],called LEACH,guarantees that the energy load is well distributed by dynamically created clusters,using cluster heads dynamically elected according to a priori optimal probability.Cluster heads aggregate reports from their cluster members before forwarding them to the sink.By rotating the cluster-head role uniformly among all nodes,each node tends to expend the same energy over time. Most of the analytical results for LEACH-type schemes are obtained assuming that the nodes of the sensor network are equipped with the same amount of energy—this is the case of homogeneous sensor networks.In this paper we study the impact of heterogeneity in terms of node energy.We assume that a percentage of the node population is equipped with more energy than the rest of the nodes in the same network—this is the case of heterogeneous sensor networks.We are motivated by the fact that there are a lot of applications that would highly bene?t from understanding the impact of such heterogeneity.One of these applications could be the re-energization of sensor networks.As the lifetime of sensor networks is limited there is a need to re-energize the sensor network by adding more nodes.These nodes will be equipped with more energy than the nodes that are already in use,which creates heterogeneity in terms of node energy.Note that due to practical/cost constraints it is not always possible to satisfy the constraints for optimal distribution between different types of nodes as proposed in[5]. There are also applications where the spatial density of sen-sors is a constraint.Assuming that with the current technology the cost of a sensor is tens of times greater than the cost of embedded batteries,it will be valuable to examine whether the lifetime of the network could be increased by simply distribut-ing extra energy to some existing nodes without introducing new nodes.1 1We also study the case of uniformly distributing such extra energy over all nodes.In practice,however,it maybe dif?cult to achieve such uniform distribution because extra energy could be expressed only in terms of discrete battery units.Even if this is possible,we show in this paper that such fair distribution of extra energy is not always bene?cial.

Leach协议

目录 一、Leach协议与NS的关系 (2) 二、算法设计思想 (3) 三、簇头建立算法流程图 (4) 四、难点解决 (6) 五、算法运行结果分析 (9) 参考文献 (9)

一、Leach协议与NS的关系 为了实现leach 协议,对ns进行扩展。在ns中增加了一个事件驱动模拟器支持模拟无线传感器网络协议。这些扩展包括MAC协议,用于计算和交互的能量分配模型和leach协议的体系结构。 网络拓扑结构可以通过简单的Nodes, Links, Agents和Applications 描述。Nodes相当于网络中的终端主机, Links 是用于Nodes交互的连接器, Agent用来实现不同网络协议,是支持分组产生和丢弃的节点。Applications 用来产生数据和实现不同的应用函数。一旦网络拓扑结构建立起来后,模拟通过启动节点上的Applications运行。 为了在ns中支持无线传感器网络,在ns中增加了 mobile nodes, MAC 协议和信道传播模型Channel 。 Applications类的头文件用Tcl语言写的,节点中的其他函数功能用C++语言写成的。 数据包的发送过程: Applications创建数据包(data packets),然后发送给Agent. Agent执行协议栈中运输层和网络层的功能,将数据包发送给CMUTrace,。 CMUTrace将packets的统计数据写到trace 文件,然后将packets发至Connector。Connector将数据包传送给用于数据链路处理的链路层(LL).经过一小段时间的延迟后,数据包由LL发送给Queue缓冲队列。如果是还没有传送过的数据包,Queue将以队列进行存储。然后Queue将数据包出队列,发送到MAC层。然后开始运行MAC(媒体访问控制)协议。最终,packets被发送到网络接口层(Network Interface),网络接口层将packets加上正确的传输能量,然后将packets发送到Channel. Channel将packets进行拷贝,并发往连接信道的每一个节点。 发送过程可参考如下图1 数据包的接收过程: 数据包被节点的网络接口接收,并被向上传送至MAC层,Link-Layer, Connector, CMUTrace, 和Agent 函数. Agent 对数据包进行判定,并将数据包到达的信息通知给Application. 接收过程与发送过程传输的路径相反。

相关文档