WSN中负载平衡的LEACH通信协议研究

合集下载

WSN中LEACH和LEACH-C、MTE协议性能比较

WSN中LEACH和LEACH-C、MTE协议性能比较
文在 N S 2中对 L E A CH、 L E A C H— C 和 MT E三 种 协 议 进 行 仿 真, 对 比 分 析 其性 能 。 1 无 线 传 感 器 网络 中的 路 由协 议
Ab s t r a c t
F i r s t wor k i ng pr i n ci pl e of LE ACH pr o t oc ol i n wi r e l e s s s en s or n e t wor k s i s an a l y s e d Th en c om p ar i s on o f L EACH, L EACH-C an d M T E wa s m a de i n t h e s i mul a t i on s et t hr ou gh NS2. Si mu l a t i on r e s ul t s sh o w t h at , t h e n e t wor k l i f e t i me o f MTE i s l o ng er t h an L EACH an d LE ACH —C. L EACH ou t per f or ms L EACH — C. wh en t h e t o ca t i o ns o f SI NK n ode wi t hi n t h e s e n si ng r e gi on. Wh er e as , LE ACH—C i s su pe r i or t o LE ACH. Ke y wor d s: W SN. NS2, L EACH, L EACH—C, MTE
陈建 建 高 莹 ( 安徽工业大学电气信息学院, 安徽 马鞍山 2 4 3 0 0 2 )
摘 要
首 先 分 析 无 线传 感 器 网 络 中 L E A CH 协 议 工 作 原 理 , 然 后 通 过 NS 2将 L E A C H和 L E AC H— C、 MT E在 设 置 的 仿 真 环 境 中做 了仿 真 对 比 。 仿 真 结 果表 明 , MT E比 L E A CH 和 L E A CH — C 有 更 长 的 网络 生存 时 间 , 当S I N K 节 点位 置在 感知 区域 内时

WSN中负载平衡的LEACH通信协议研究

WSN中负载平衡的LEACH通信协议研究

0引言无线传感器网络集成了传感器、微机电系统和网络3大关键技术,它借助于内置的形式多样的传感器测量所在周边环境的热、红外、声纳和雷达来测量包括温度、湿度、速度、光强度、压力等我们感兴趣的物质现象[1-2]。

由于它成本低、体积小、能耗少的特点,成为远程监测领域越来越受重视的工具,广泛应用于军事、环境科学、医疗以及空间探索等生产生活的重要部门。

层次型路由协议是无线传感器网络中一种能量有效的路由协议,这类协议将所有的节点分为若干簇,每个簇选举一个首领(又称簇头),簇内节点采集信息发送给簇头,由簇头进行数据融合后将信息转发给Sink节点。

这样能够减少数据通信量,由于大部分节点在相当长的时间关闭通信模块,所以能够显著延长整个网络生存期。

LEACH[3]、PAGASIS[4]、TEEN[5]和DEEC[6]都属于这类协议。

本文通过定量分析节点能耗,建立了节点的能耗模型,分析出了造成LEACH网络中节点之间能耗不均的原因,在此基础上提出了改进方法。

本文首先介绍了研究背景;然后剖析了LEACH协议并找出了造成能耗不均的原因;提出了LB-LEACH协议;并对所提出协议进行了仿真实验及分析;最后进行总结并对未来工作进行展望。

1研究背景Low-energy Adaptive Clustering Hierarchy(LEACH)是层次型路由协议的代表,是一种自适应分簇拓扑算法。

它的研究基于以下前提:①所有节点同构且能量自持;②所有节点都能直接与Sink通信;③节点能够控制发送能量,并能够支持多种不同的MAC协议;④节点间的通信是对称的:A发信息给B 与B发信息给A需要消耗相同的能量。

LEACH的执行是周期性的,每轮循环分为簇的建立阶段和稳定的数据通信阶段。

在簇的建立阶段,相邻节点动态地成簇,用以下方式随机产生簇头(cluster head,CH):节点产生[0-1]的随机数,如果这个数小于阈值T(n),则广播自己是簇头的ADV消息,T(n)的计算公式如下={1,式中:P ——成为CH 的概率,r ——现在的轮数,G ——在过去的(r mod 1/P )轮中还没有做过CH 的节点集合。

无线传感器网络LEACH协议的研究与改进

无线传感器网络LEACH协议的研究与改进

无线传感器网络LEACH协议的研究与改进摘要:LEACH(Low Energy Adaptive Clustering Hierarchy)是一种经典的WSN 分层路由协议,它采取自适应分簇算法,一定程度上延长了网络生存期。

然而LEACH路由协议的簇头随机产生,没有考虑节点的剩余能量,未达到簇头最优。

LEACH簇头与基站直接通信,如果两者距离较远,则会带来较大的能量损耗。

结合LEACH及LEACH现有的一些改进算法。

综合考虑了节点的剩余能量和簇首节点数目,簇头和基站之间采用单跳和多跳结合策略,有效地降低了能耗,保证了网络负载的平衡。

关键字:LEACH协议;无线传感器网络;簇头选举算法Abstract:LEACH (Low Energy Adaptive Clustering Hierarchy) is a classic WSN hierarchical routing protocol, it has taken to extend the lifetime of the network adaptive clustering algorithm, to a certain extent. However, the routing protocol LEACH cluster head randomly generated, without considering the residual energy of the node, the cluster head does not reach the optimum. LEACH cluster head directly communicate with the base station, if the distance between the two, it will bring greater energy loss. LEACH and LEACH combining some of the existing improved algorithms. Considering the remaining energy is used between nodes and cluster head node number, cluster head and base single-hop and multi-hop combined with strategies to effectively reduce energy consumption, to ensure the balance network load.KEYWORDS: Low Energy Adaptive Clustering Hierarchy(LEACH);Wireless Sensor Network(WSN);cluster-head selection algorithm1 引言无线传感器网络(WSN)不需要固定网络支持,具有快速展开、抗毁性强等优势,能够适用于人们无法接近的恶劣或特殊环境,在军事、商业、医疗、家庭和环境监测等方面广泛应用。

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

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

无线传感器网络LEACH协议的研究摘要:无线传感器网络因其在军事、经济、民生等方面广阔的应用前景成为21世纪的前沿热点研究领域[1]。

在传感器节点能量有限的情况下,提高路由效率,延长网络寿命成为无线传感器网络需考虑的问题。

由于采取分簇,数据融合的思想,LEACH协议有着较高的路由效率,但在实际应用,尤其是大规模网络中,仍存在负载不均衡等问题。

本文主要分析了LEACH协议的基本思想及优缺点,随后针对大规模的网络环境对其分簇算法进行改进。

前人提出一种有效的方法计算最优簇首个数,本文推算出适合本文中网络环境的公式并加以应用。

本文用NS2进行仿真,仿真后的结果表明,改进后的分簇算法更为有效,延长了网络寿命,增大了网络传送数据量。

关键词:无线传感器网络;路由协议;LEACH;分簇思想Research on Routing Protocol of LEACH in WSNShen Y uanyiDept. of Information and Telecommunication,NUPTABSTRACT: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; clustering1LEACH协议介绍与分析1.1 LEACH算法思想算法基本思想[2]是:以循环的方式随机选择簇头节点,将整个网络的能量负载平均分配到每个传感器节点中,从而达到降低网络能源消耗、提高网络整体生存时间的目的。

leach协议

leach协议

leach协议协议名称:Leach协议一、背景介绍Leach协议(Low Energy Adaptive Clustering Hierarchy)是一种用于无线传感器网络(WSN)中的能量高效的分簇协议。

该协议通过将传感器节点划分为簇(cluster)并选择簇头(cluster head)来降低能量消耗,延长网络寿命。

本协议旨在实现高效的数据传输和能量平衡。

二、协议目标1. 降低无线传感器网络中的能量消耗,延长网络寿命。

2. 提供高效的数据传输和通信能力。

3. 实现传感器节点之间的能量平衡,避免能量耗尽导致节点失效。

三、协议内容1. 初始化阶段a. 每个传感器节点随机选择一个时间片作为其通信轮次。

b. 节点根据其能量水平决定是否成为簇头节点,能量水平高的节点更有可能成为簇头节点。

c. 节点广播自己的簇头选择信息,并收集其他节点的选择信息。

d. 节点根据收到的选择信息决定是否加入某个簇。

2. 簇形成阶段a. 节点选择一个簇头节点作为其父节点,并发送加入请求。

b. 簇头节点接收加入请求,并根据一定的策略选择是否接受该节点加入。

c. 被接受的节点成为该簇的成员,否则继续选择其他簇头节点发送加入请求。

d. 簇头节点维护成员列表,并将该列表发送给所有成员节点。

3. 数据传输阶段a. 簇头节点收集成员节点的数据,并进行聚合处理。

b. 簇头节点将聚合后的数据发送给基站或其他目标节点。

c. 成员节点将自己采集到的数据发送给簇头节点。

4. 能量平衡机制a. 簇头节点周期性地向成员节点广播能量消耗情况。

b. 成员节点根据收到的能量消耗情况,决定是否重新选择簇头节点。

c. 节点在一定时间内轮流担任簇头节点的角色,以实现能量的均衡分配。

四、协议优势1. 能量高效:通过分簇和选择簇头节点的方式,降低了能量消耗,延长了网络寿命。

2. 高效的数据传输:簇头节点对成员节点的数据进行聚合处理,减少了冗余数据的传输。

3. 能量平衡:通过周期性地重新选择簇头节点,实现了能量的均衡分配,避免了能量耗尽导致节点失效。

WSN中LEACH协议源码分析研究

WSN中LEACH协议源码分析研究

WSN中LEACH协议源码分析分析(一)首先对wireless.tcl进行分析,先对默认地脚本选项进行初始化:set opt(chan)Channel/WirelessChannelset opt(prop) Propagation/TwoRayGroundset opt(netif)Phy/WirelessPhyset opt(mac) Mac/802_11set opt(ifq) Queue/DropTail/PriQueueset opt(ll) LLset opt(ant) Antenna/OmniAntennaset opt(x) 0 ;# X dimension of the topographyset opt(y) 0 ;# Y dimension of the topographyset opt(cp) ""set opt(sc) "../mobility/scene/scen-670x670-50-600-20-2" ;# scenario fileset opt(ifqlen)50;# max packet in ifset opt(nn) 51 ;# number of nodesset opt(seed) 0.0set opt(stop) 10.0 ;# simulation timeset opt(tr) out.tr ;# trace fileset opt(rp) dsdv ;# routing protocol scriptset opt(lm) "on" ;# log movement在这个wireless.tcl中设置了一些全局变量:## Initialize Global Variables#set ns_ [new Simulator]set chan [new $opt(chan)]set prop [new $opt(prop)]set topo [new Topography]set tracefd [open $opt(tr) w]$topo load_flatgrid $opt(x) $opt(y)$prop topography $topo这些初始化将在后面地使用中用到,该文件最重要地是创建leach节点:创建方法如下:} elseif { [string compare $opt(rp) "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 "$node_($i) reset"; //完成后,重置节点地应用}$ns_ at $opt(stop).00000001 "puts \"NS EXITING...\" ; $ns_ halt"if { $opt(sc) == "" } {puts "*** NOTE: no scenario file specified."set opt(sc) "none"} else {puts "Loading scenario file..."source $opt(sc)puts "Load complete..."}ns在什么时候结束simulation,并告诉ns加载sc场景文件.最后$ns_ run则ns就开始运行了.分析(二)上节对wireless.tcl进行了简要地分析,接下来对Uamps.tcl脚本进行分析.set opt(Efriss_amp) [expr [expr 1.1 * $opt(RXThresh) * 16 * $PI * $PI] / \[expr $opt(bw) * $opt(Gt) * $opt(Gr) * $l * $l]]# Etwo_ray_amp = RXThresh / (Rb Gt Gr ht^2 hr^2)set opt(Etwo_ray_amp) [expr 1.1 * $opt(RXThresh) / \[expr $opt(bw) * $opt(Gt) * $opt(Gr) * \$opt(ht) * $opt(ht) * $opt(ht) * $opt(ht)]]set opt(EXcvr) 50e-9 ;# Energy for radio circuitryset opt(e_bf) 5e-9 ;# Beamforming energy (J/bit)set opt(Esense) 0 ;# Sensing energy (J/bit)set opt(thresh_energy) 0.00 ;# Threshold for power adaptationset opt(Pidle) 0 ;# Idle power (W)set opt(Psleep) 0 ;# Sleep power (W)set initialized 0set rng_ [new RNG]#用于产生随机数首先往opt数组里面添加一些变量,并对这些变量进行初化.opt(Psleep) ,opt(Pidle),opt(thresh_energy)在ns-leach.tcl中使用到,这个是计算单位时间空闲所消耗地能量和休眠所消耗地能量.这个脚本主要是创建leach节点:if {$initialized == 0} {#remove old tracesens_initset initialized 1}# Remove old trace files.catch "eval exec rm [glob -nocomplain $opt(dirname)/TDMAschedule.*.txt]"catch "exec rm $opt(dirname)/$opt(filename).energy"catch "exec rm $opt(dirname)/$opt(filename).data"catch "exec rm $opt(dirname)/$opt(filename).alive"catch "exec rm $opt(dirname)/startup.energy"catch "exec rm $opt(dirname)/init.energy"如果没有初始化过,则将以前地跟踪文件删除,接着回到创建leach地函数中,创建节点:if {$id != $opt(nn_)} {puts -nonewline "$id "#importantset node_($id) [new MobileNode/ResourceAwareNode]} else {puts "($opt(nn_) == BS)"set node_($id) [new MobileNode/ResourceAwareNode $BS_NODE]}如果不是簇头节点则将$opt(nn_)-1个节点设置为一般节点,将$opt(nn_)设置为BS节点.newMobileNode/ResourceAwareNode函数是在ns-ranode.tcl中.分析完这个我们接下来分析newMobileNode/ResourceAwareNode这个函数.set node $node_($id)if {$id != $opt(nn_)} {# Set initial node energy.if {$opt(eq_energy) == 1} {$node set-energy $opt(init_energy) $opt(thresh_energy)} else {由于eq-energy在leach-test中给定,将eq-energy=1;则每个节点都会对能量进行初始化,设置节点地初始能量和门槛能量(个人理解,死亡能量).set high_e_nodes [list 97 19 12 87 8 22 83 55 34 72]if {[lsearch $high_e_nodes $id] == -1} {set E 2} else {set E 200}$node set-energy $E $opt(thresh_energy)set initf [open "$opt(dirname)/init.energy" a]puts $initf "$id\t$E"close $initf将不属于list中地能量初始化能量设置为2,将属于list中地能量设置为200.并将初始化能量写到init.energy中,将节点id和节点初始能量写进去.else {# Base station has an infinite amount of energy.$node set-energy 50000 $opt(thresh_energy)}节点为簇头节点,则将节点地初始化能量设置为50000,能量无限.到此为止,创建节点完成并将每个节点地能量初始化完成.下一节将分析ns-ranode.tcl脚本.区分普通节点和簇头节点地不同.接下来是配置节点信道和跟踪文件:$ns_ at 0.0 "$node_($id) start-app" ns在0地时候启动应用,应用在ns-ranode.tcl中分析.分析(三)对前面两个脚本进行分析后,已经创建好节点和设置好节点地初始能量,将opt(nn_)-1个节点设置为普通节点,而将opt(nn_)设置为bs.现在对ns-ranode.tcl进行分析.好了我们现在就开始分析这个脚本.Class MobileNode/ResourceAwareNode -superclass Node/MobileNodeMobileNode/ResourceAwareNode instproc init argsset bs_node [lindex $args 0]eval $self next [lreplace $args 0 0]args由参数传递进来,若节点为簇头节点则bs_node=1,调用父类初始化函数.set ResourceManager_ [new ResourceManager]$ResourceManager_ Register [new Resource/NeighborResource]set energy [new Resource/Energy]$ResourceManager_ Register $energyResourceManager在ns-resouce-manager.tcl中定义地.Resource/NeighborResource在ns-neighbor-resource中对能量进行管理.# Create a new agent and attach it to the nodeif {$bs_node == 1} {set agent [new Agent/BSAgent]} else {set agent [new Agent/RCAgent]}set rca_agent_ $agent普通节点地应用为RCAgent,BS地应用为BSAGgent. 并将应用attch到node上.下面两段看不明白,但是这两段不影响看程序.set haslist [find_haslist [$self id]]if {$bs_node == 1} {set rca [new $opt(bsapp)]} else {set rca [new $opt(rcapp) $opt(mtype) $wantslist $haslist]}$ns_ attach-agent $self $agent$rca attach-agent $agentset rca_app_ $rca将bs节点地应用设置为bsapp,普通节点地应用设置为rcaapp,并将节点地服务设置为不同地服务.bsapp在ns-app.tcl中.$opt(rcapp)定义在leach.tcl中,opt(mtype)定义在leach.tcl 中.set opt(rcapp) "Application/LEACH" ;# Application typeset opt(ra_adv) [TxTime [expr $opt(hdr_size) + 4]];# Total time (s) for CH ADVs;# Assume max 4(nn*%) CHsset opt(ra_adv_total) [expr $opt(ra_adv)*($opt(num_clusters)*4 + 1)];# RA Time (s) for nodes' join reqsset opt(ra_join) [expr 0.01 * $opt(nn_)];# Buffer time for join req xmittalset opt(ra_delay) [TxTime [expr $opt(hdr_size) + 4]];# Maximum time required to transmit;# a schedule (n nodes in 1 cluster)set opt(xmit_sch) [expr 0.005 + [TxTime [expr $opt(nn_)*4+$opt(hdr_size)]]];# Overhead time for cluster set-upset opt(start_xmit) [expr $opt(ra_adv_total) + $opt(ra_join) + $opt(xmit_sch)]一般节点地应用为Application/LEACH,最终sink节点地应用为Application/BSApp.通过前3次地分析得出,在分析1中定义变量,在分析2中创建leach节点,在分析3中将节点地应用绑定在节点上.下面将分析leach地主要协议ns-leach.tcl脚本.分析(四)完成前面3个脚本地分析,最后进行ns-leach.tcl脚本地分析.首先我们看下这个脚本要使用地有哪些功能.Application/LEACH instproc init args {} 对leach进行初始化,即构造函数.下面是leach地一些方法Application/LEACH instproc start {} {}Application/LEACH instproc getRandomNumber {llim ulim} {} 得到随机数Application/LEACH instproc node {} {}Application/LEACH instproc nodeID {} {}Application/LEACH instproc mac {} {}Application/LEACH instproc getX {} {}Application/LEACH instproc getY {} {}Application/LEACH instproc getER {} {}Application/LEACH instproc GoToSleep {} {} 节点进行休眠Application/LEACH instproc WakeUp {} {}节点醒来Application/LEACH instproc setCode code {}{}Application/LEACH instproc checkAlive {} {} 节点是否存活Application/LEACH instproc isClusterHead? {} {} 判断是否是簇头节点Application/LEACH instproc hasbeenClusterHead? {} {} 判断是否成为过簇头节点Application/LEACH instproc hasnotbeenClusterHead {} {}hasbeench=0不是簇头节点Application/LEACH instproc setClusterHead {} {} 设置为簇头节点Application/LEACH instproc unsetClusterHead {} {} 设置为非簇头节点Application/LEACH instproc decideClusterHead {} {} 决定簇头节点,非常重要Application/LEACH instproc advertiseClusterHead {} {} 广播簇头节点Application/LEACH instproc findBestCluster {} {} 找到最佳簇Application/LEACH instproc informClusterHead {} {} 通知簇头节点Application/LEACH instproc createSchedule {} {} 创建TDMA调度接收功能:Application/LEACH instproc recv {args} {}Application/LEACH instproc recvADV_CH {msg} {}Application/LEACH instproc recvJOIN_REQ {nodeID} {}Application/LEACH instproc recvADV_SCH {order} {}Application/LEACH instproc recvDA TA {msg} {}发送功能:Application/LEACH instproc sendData {} {}Application/LEACH instproc send {mac_dst link_dst type msgdata_size dist code} {} Application/LEACH instproc send_now {mac_dst link_dst type msg data_size dist code} {} Application/LEACH instproc SendDataToBS {} {}Application/LEACH instproc SendMyDataToBS {} {}分析(五)由leach 分析三可知,一般节点地应用为Application/LEACH.则现在就是如何选择簇头节点和设置门槛值.我们接下来分析leach 分析4中红色地方法.在leach 分析3中创建一个Application/LEACH对象则就会自动调用start方法.Application/LEACH instproc start {} {[$self mac] set node_num_ [$self nodeID]$self decideClusterHead$self checkAlive}在这个方法中会调用decideClusterHead和checkAlive方法.Application/LEACH instproc GoToSleep {} {global opt ns_$self instvar begin_idle_ begin_sleep_[[$self node] set netif_(0)] set sleep_ 1# If node has been awake, remove idle energy (e.g., the amount of energy# dissipated while the node is in the idle state). Otherwise, the node# has been asleep and must remove sleep energy (e.g., the amount of# energy dissipated while the node is in the sleep state).if {$begin_idle_ > $begin_sleep_} {set idle_energy [expr $opt(Pidle) * [expr [$ns_ now] - $begin_idle_]][$self getER] remove $idle_energy} else {set sleep_energy [expr $opt(Psleep) * [expr [$ns_ now] - $begin_sleep_]][$self getER] remove $sleep_energy}set begin_sleep_ [$ns_ now]set begin_idle_ 0}分析(六)在start中调用下面这个方法.Application/LEACH instproc decideClusterHead {} {global ns_ chan opt node_$self instvar alive_ TDMAschedule_$self instvar begin_idle_ begin_sleep_# Check the alive status of the node. If the node has run out of# energy, it no longer functions in the network.set ISalive [[[$self node] set netif_(0)] set alive_]if {$alive_ == 1} {if {$ISalive == 0} {puts "Node [$self nodeID] is DEAD!!!!"$chan removeif [[$self node] set netif_(0)]set alive_ 0set opt(nn_) [expr $opt(nn_) - 1]set ISalive [[[$self node] set netif_(0)] set alive_] #从网络接口netif中查看当前节点状况如果节点存活,但是节点能量耗光,则$chan removeif [[$self node] set netif_(0)]将节点信道中移出,并将节点设置为死亡.节点地总数目减少一个.if {$opt(eq_energy) == 1} {## Pi(t) = k / (N - k mod(r,N/k))# where k is the expected number of clusters per round# N is the total number of sensor nodes in the network# and r is the number of rounds that have already passed.#set nn $opt(nn_)if {[expr $nn - $opt(num_clusters) * $round_] < 1} {set thresh 1} else {set thresh [expr double($opt(num_clusters)) / \[expr $nn - $opt(num_clusters) * $round_]]# Whenever round_ is 0, all nodes are eligible to be cluster-head.if {$round_ == 0} {$self hasnotbeenClusterHead}}# If node has been cluster-head in this group of rounds, it will not# act as a cluster-head for this round.if {[$self hasbeenClusterHead?]} {set thresh 0}} else {## Pi(t) = Ei(t) / Etotal(t) * k# where k is the expected number of clusters per round,# Ei(t) is the node's current energy, and Etotal(t) is the total# energy from all nodes in the network.#set Etotal 0# Note! In a real network, would need a routing protocol to get this# information. Alternatively, each node could estimate Etotal(t) from# the energy of nodes in its cluster.for {set id 0} {$id < [expr $opt(nn)-1]} {incr id} {set app [$node_($id) set rca_app_]set E [[$app getER] query]set Etotal [expr $Etotal + $E]}set E [[$self getER] query]set thresh [expr double([expr $E * $opt(num_clusters)]) / $Etotal]}上面是对thresh地计算,当(N - k mod(r,N/k))<1,则将thresh设置为1,否则节点thresh=k / (N - k mod(r,N/k)),每个节点在一个1/p中都要成为簇头节点一次.p=簇头节点占所有节点地比例,在r=0地时候每个节点都有机会吃呢更为簇头节点.如果节点成为过簇头节点则thresh=0,则这个节点在1/p轮后才可以成为簇头节点.if {[$self getRandomNumber 0 1] < $thresh} {puts "$nodeID: *******************************************"puts "$nodeID: Is a cluster head at time [$ns_ now]"$self setClusterHeadset random_access [$self getRandomNumber 0 $opt(ra_adv)] #opt(ra_adv) in leach.tcl$ns_ at [expr $now_ + $random_access] "$self advertiseClusterHead"} else {puts "$nodeID: *******************************************"$self unsetClusterHead}如果thresh>getRandomNumber,则节点成为簇头节点.然后调用advertiseClusterHead方法.set next_change_time_ [expr $now_ + $opt(ch_change)]$ns_ at $next_change_time_ "$self decideClusterHead"$ns_ at [expr $now_ + $opt(ra_adv_total)] "$self findBestCluster"当节点成为簇头节点,则节点调用advertiseClusterHead方法.set chID [$self nodeID]set currentCH_ $chIDpp "Cluster Head $currentCH_ broadcasting ADV at time [$ns_ now]"set mac_dst $MAC_BROADCASTset link_dst $LINK_BROADCAST set msg [list $currentCH_] set datasize [expr $BYTES_ID * [llength $msg]] # Send beacons opt(max_dist) meters so all nodes can hear. $self send $mac_dst $link_dst $ADV_CH $msg $datasize $opt(max_dist) $code_将该节点设置为簇头节点,设置当前节点所处地簇号.然后发送数据,广播该节点为簇头信息到全局网络.在$ns_ at [expr $now_ + $opt(ra_adv_total)] "$self findBestCluster"调用findBestCluster方法.分析(七)当簇头发出了一个ADV类型地包时,其他地节点会接收这个包,并会将发送这个包地簇头地节点号按顺序先后记录在clusterChoices_中,还会计算每个簇头到接收节点地距离并记录在clusterDist_中.这样可以方便每个节点选簇地时候进行比较.具体地实现在ns-leach.tcl 中地recvADV_CH函数中.findBestClusterif [$self isClusterHead?] {# If node is CH, determine code and create a TDMA schedule.set dist_ $opt(max_dist)set currentCH_ $nodeIDset myADVnum_ [[$self mac] set myADVnum_]# There are opt(spreading) - 1 codes available b/c need 1 code# for communication with the base station.set numCodesAvail [expr 2 * $opt(spreading) - 1]set ClusterCode [expr int(fmod($myADVnum_, $numCodesAvail)) + 1]$ns_ at [expr $now_ + $opt(ra_adv_total) + $opt(ra_join)] \"$self createSchedule"}如果这个节点是簇头节点,设置为当前地簇头,set numCodesAvail [expr 2 * $opt(spreading) - 1]set ClusterCode [expr int(fmod($myADVnum_, $numCodesAvail)) + 1]这两句没看懂在一个随机时间后调用createSchedule,节点根据自己收到地clusterChoices,选择最近地簇头作为簇头节点.选择好簇头节点就informClusterHead.发送完数据就进入休眠状态. Application/LEACH instproc createSchedule {} {global ns_ opt ADV_SCH MAC_BROADCAST BYTES_ID$self instvar clusterNodes_ TDMAschedule_$self instvar dist_ code_ now_ beginningE_set numNodes [llength $clusterNodes_]set chID [$self nodeID]if {$numNodes == 0} {set xmitOrder ""puts "Warning! There are no nodes in this cluster ($chID)!"$self SendMyDataToBS} else {# Set the TDMA schedule and send it to all nodes in the cluster.set xmitOrder $clusterNodes_set msg [list $xmitOrder]set spreading_factor $opt(spreading)set datasize [expr $spreading_factor * $BYTES_ID * [llength $xmitOrder]]pp "$chID sending TDMA schedule: $xmitOrder at time [$ns_ now]"pp "Packet size is $datasize."set mac_dst $MAC_BROADCASTset link_dst $chID$self send $mac_dst $link_dst $ADV_SCH $msg $datasize $dist_ $code_}set TDMAschedule_ $xmitOrderset outf [open $opt(dirname)/TDMAschedule.$now_.txt a]puts $outf "$chID\t$TDMAschedule_"close $outfset outf [open $opt(dirname)/startup.energy a]puts $outf "[$ns_ now]\t$chID\t[expr $beginningE_ - [[$self getER] query]] "close $outf}在recvADV_SCH给每个节点一个时间间隙发送数据set frame_time_ [expr [expr 5 + [llength [join $order]]] * $opt(ss_slot_time)]set xmitTime_ [expr $opt(ss_slot_time) * $ind]set end_frm_time_ [expr $frame_time_ - $xmitTime_]set xmitat [expr [$ns_ now] + $xmitTime_]pp "$nodeID scheduled to transmit at $xmitat. It is now [$ns_ now]."if {[expr $xmitat + $end_frm_time_] < \[expr $next_change_time_ - 10 * $opt(ss_slot_time)]} {$ns_ at $xmitat "$self sendData"具体实现方法看不太懂.版权申明本文部分内容,包括文字、图片、以及设计等在网上搜集整理.版权为个人所有This article includes some parts, including text, pictures, and design. Copyright is personal ownership.RQxPv。

WSN中负载平衡的LEACH通信协议研究


环 境 的热 、 外 、 纳 和 雷 达 来 测 量 包 括 温 度 、 度 、 度 、 红 声 湿 速 光 强 度 、 力 等 我 们 感 兴 趣 的物 质 现 象 “ 于 它 成 本 低 、 积 压 。 。由 体
小、 能耗 少 的 特 点 , 为 远 程 监 测 领 域 越 来 越 受 重 视 的 工 具 , 成 广 泛 应 用 于 军 事 、 境 科 学 、 疗 以 及 空 间 探 索 等 生 产 生 活 的 环 医
t ed s d a tg f n aa c dl a . Bya ay i gt ee e g — o s mi go n d s ncu t r r ACH, t ee e g - o s mi gmo e h ia v n a e u b ln e d o o l zn n r c n u n f o e l se s o n h y i f LE h n r c n u n d l y
关 键 词 : 线 传 感 器 网络 ; 负 载 平 衡 ; 聚 类 ; 内 核 节 点 ; 边 界 节 点 ; 簇 首 无
中 图法分类号 : P 9 T 33
文献标 识码 : A
文章编 号 :0072 2 0) 84 0—4 10 —04(0 7 1—4 30
S u y o a — aa e t d fl d b lnc dLEA CH r t c lf rwiee ss n o ew o k o p o o o o r ls e s rn t r Z NG azo g LU h-e YU egc eg HA Hu-h n , I Z ii, j P n -hn
维普资讯
第2卷 8
Vo. 8 12
第 1 期 8
NO 1 . 8

WSN中LEACH协议源码分析报告

WSN中LEACH协议源码分析分析(一)首先对wireless.tcl进行分析,先对默认的脚本选项进行初始化:set opt(chan)Channel/\VirelessChannelset opt(prop) Propagatioii/TwoRayGroundset opt(netif)PhyAVirelessPhyset opt(mac) Mac/802_l 1set opt(ifq) Qucuc/DropTail/PriQueueset opt(ll) LLset opt(ant) Antenna/OmniAntennaset opt(x) 0 。

# X dimension of the topographyset opt(y) 0。

# Y dimension of the topographyset opt(cp),H,set opt(sc) N../mobility/scene/scen-670x670-50-600-20-2u。

# scenario file set opt(ifqlen)50o # max packet in ifset opt(nn) 51。

# number of nodesset opt(secd) 0.0set opt(stop) 10.0 o # simulation timeset opt(tr) out.tr。

# trace fileset opt(rp) dsdv 。

# routing protocol scriptset 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协议研究与优化 论文

LEACH协议研究与优化摘要:近年来在微电子技术、通信技术、无线传输技术方面取得的巨大成就使得低成本、低功耗、小体积短通信距离的多功能无线传感器的实现成为可能。

在传感器节点能量有限的情况下,提高路由效率,延长网络寿命成为无线传感器网络需考虑的问题。

[1]由于采取分簇,数据融合的思想,LEACH协议有着较高的路由效率,但在实际应用,尤其是大规模网络中,仍存在负载不均衡等问题。

本文主要分析了LEACH协议的基本思想及优缺点,随后针对大规模的网络环境对其分簇算法进行改进。

关键词:无线传感网络路由协议LEACH 分簇思想Abstract:In recent years, microelectronic technology, communications technology, the tremendous achievements made wireless transmission technology enables low cost, low power, small size short communication distance multifunctional wireless sensors to achieve possible. In the case of limited energy of sensor nodes to improve routing efficiency and prolong the network lifetime becomes a problem in wireless sensor networks need to be considered. As a result of clustering, data fusion ideas, LEACH routing protocol has a higher efficiency, but in practical applications, especially large-scale networks, there are still load imbalance and other issues. This paper analyzes the advantages and disadvantages of the basic idea of LEACH, followed by improvements in its clustering algorithm for large-scale network environment.Keywords:WSN routing protocol LEACH clustering1.概述无线传感器网络因其在军事、经济、民生等方面广阔的应用前景成为21世纪的前沿热点研究领域。

基于leach的wsn路由协议研究

传感器网络协议负责使各个独立节点形成一个多跳的数据传输网络,目前研究的重点 是网络层协议和数据链路层协议。网络层的路由协议决定监测信息的传输路径;数据链路 层的介质访问控制用来构建底层的基础结构,控制传感器节点的通信过程和工作模式。
在无线传感器网络中,路由协议不仅关心单个节点的能量消耗,更关心整个网络能量 的均衡消耗,这样才能延长整个网络的生存周期。同时,无线传感器网络是以数据为中心 的,这在路由协议中表现得最为突出,每个节点没必要采用全网统一的编址,可以根据感 兴趣的数据建立数据源到汇聚节点之间的转发路径。目前提出了多种类型的传感器网络路 由协议,如基于能量感知的路由协议、基于查询的路由协议等。 (3)数据融合
由于无线传感器网络具有密集型、随机分布的特点,使其非常适合应用于恶劣的战场 环境中,包括侦察敌情、监控兵力、装备和物资,判断生物化学攻击等方面。美国国防部 远景计划研究局已投资几千万美元,帮助大学进行”智能尘埃”传感器技术的研发。哈伯研 究公司总裁阿尔门丁格预测:智能尘埃式传感器及有关的技术销售将从2004年的1000万 美元增加到2010年的几十亿美元。 4.其他领域
muting protocols are analyzed.Problems in WSN routing design is summarized also.
algorithm 3.After deep analysis on LEACH protocol,thesis presented a new routing
研究生签名:二纪日期:旦星!丝
南京邮电大学学位论文使用授权声明
南京邮电大学、中国科学技术信息研究所、国家图书馆有权保留 本人所送交学位论文的复印件和电子文档,可以采用影印、缩印或其 他复制手段保存论文。本人电子文档的内容和纸质论文的内容相一 致。除在保密期内的保密论文外,允许论文被查阅和借阅,可以公布 (包括刊登)论文的全部或部分内容。论文的公布(包括刊登)授权 南京邮电大学研究生部办理。
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

0引言无线传感器网络集成了传感器、微机电系统和网络3大关键技术,它借助于内置的形式多样的传感器测量所在周边环境的热、红外、声纳和雷达来测量包括温度、湿度、速度、光强度、压力等我们感兴趣的物质现象[1-2]。

由于它成本低、体积小、能耗少的特点,成为远程监测领域越来越受重视的工具,广泛应用于军事、环境科学、医疗以及空间探索等生产生活的重要部门。

层次型路由协议是无线传感器网络中一种能量有效的路由协议,这类协议将所有的节点分为若干簇,每个簇选举一个首领(又称簇头),簇内节点采集信息发送给簇头,由簇头进行数据融合后将信息转发给Sink节点。

这样能够减少数据通信量,由于大部分节点在相当长的时间关闭通信模块,所以能够显著延长整个网络生存期。

LEACH[3]、PAGASIS[4]、TEEN[5]和DEEC[6]都属于这类协议。

本文通过定量分析节点能耗,建立了节点的能耗模型,分析出了造成LEACH网络中节点之间能耗不均的原因,在此基础上提出了改进方法。

本文首先介绍了研究背景;然后剖析了LEACH协议并找出了造成能耗不均的原因;提出了LB-LEACH协议;并对所提出协议进行了仿真实验及分析;最后进行总结并对未来工作进行展望。

1研究背景Low-energy Adaptive Clustering Hierarchy(LEACH)是层次型路由协议的代表,是一种自适应分簇拓扑算法。

它的研究基于以下前提:①所有节点同构且能量自持;②所有节点都能直接与Sink通信;③节点能够控制发送能量,并能够支持多种不同的MAC协议;④节点间的通信是对称的:A发信息给B 与B发信息给A需要消耗相同的能量。

LEACH的执行是周期性的,每轮循环分为簇的建立阶段和稳定的数据通信阶段。

在簇的建立阶段,相邻节点动态地成簇,用以下方式随机产生簇头(cluster head,CH):节点产生[0-1]的随机数,如果这个数小于阈值T(n),则广播自己是簇头的ADV消息,T(n)的计算公式如下={1,式中:P ——成为CH 的概率,r ——现在的轮数,G ——在过去的(r mod 1/P )轮中还没有做过CH 的节点集合。

非簇头节点(cluster member ,CM )收到消息后根据自己与CH 之间的距离或收到广播的先后顺序来选择加入哪个簇,并发送加入簇请求给CH 。

当CH 接收完加入请求后,就产生一个TDMA 定时信息连同本簇内使用的CDMA 编码一起发送给所有CM ,簇建立阶段完成。

在数据通信阶段,CM 在自己的TDMA 时槽内发送数据包给CH ,CH 收集齐CM 的数据包后,运用数据融合算法处理数据,并将结果发送给Sink 节点。

图1是LEACH 的运行过程图。

2LEACH 能耗分析2.1First Order Radio ModelLEACH 采用的是无线传感器网络中通常采用的一阶无线模式,其能耗模型如图2所示。

在这种模式下,节点发送k比特的数据消耗的能量为,××amp是在信号放大器内消耗的能量比例系数,随着d 变化,fs=10pJ/bit/m 2;d ≥d 0时取=×£¬¾ùÔÈ·Ö²¼ÔÚ的区域内,本轮中CH的个数为比特。

融合1比特数据消耗的能量为E DA ,数据融合的比例为+++×4(4)其中:——CH 与Sink 的距离,这里假定两者距离较远。

簇内每个CM 在一个frame内消耗的能量为+2(5)为该CM 到CH 的距离。

整个网络一个frame 内消耗的能量是=:1[7],即/2(7)(7)式推导可参见文献[7]。

根据(7)式以及LEACH 的实验证明,簇头占节点总数的5%时为最优[7-9],也就是说每个簇中CM 与CH 之比为19:1时最优。

当然,这是在理想状态下。

实际情况是,LEACH 协议由于CH 分布的不均衡,造成了簇与簇之间节点数量的严重不均衡,文献[7-8]的实验结果也证明了这一点。

为便于比较,取一轮运行中两个簇进行研究,假设两个簇头标识CHID 分别为i 、j ,簇中CM个数为,每个CM分配的时槽长度是,则由(5)式得,在一轮内,簇i 中一个CM节点消耗的能量为+++4F r a m e图2First Order Radio ModelE TxE *kK首先做如下定义:定义1在分簇过程中,CM 节点只收到一个CH 节点的ADV 广播信息,或收到多个CH 节点的ADV 信息,但其中一个信息的信号强度明显强于其它信号,称此CM 节点(记作i )是这个CH 节点(记作J )的内核节点,记做i ∈Core_SET (J )(J ∈CH_SET )。

定义2在分簇过程中,CM 节点收到两个或两个以上CH节点的ADV 广播信息,且其中两个或多个信息的信号强度相差不大,则从中选取信号强度最大的两个J 和K ,若EsignalK(E signal 为信号强度,E signal (J )为较小者)称这个CM 节点i 是CH 节点J 和K 的边界节点,记做i ∈Border_SET (J ),i ∈Border_SET (K )(J,K ∈CH_SET )。

其中i ∈Core_SET (J)(½øÐбȽϣ¬ÈôÈÔÂú×ãi ∈Border_SET (J )且i ∈Border_SET (K )则转②;若根据信号强度计算i 不再是边界节点,则i 选择信号最强的簇发送加入信息,等待W 时槽来临;②设count (J )≥count (K ),若count (J )-count (K )≥,则比较两者到BS 的距离dtoBS ,选择距离Sink 较远的CH 加入。

其中=3。

(3)W slot :J∈CH_SET )wakeup ()。

CH节点根据加入节点的数量为每个CM 节点分配一个时槽,创建一个时槽调度表,并以广播的形式发送该表,随之一起发送的还有该簇本轮内使用的CDMA 编码。

(4)Data Transmission :CM 节点采集数据信息并在分配给自己的时槽内将数据发送给CH ,CH 节点对数据进行融合后发送给Sink 节点。

一轮执行完之后,又重新按该算法进行分簇及传送。

新协议对原有LEACH 协议的分簇过程进行了分解,分解后的分簇过程分为多个时槽,每个节点在没有自己参与的时槽内进行睡眠,减少不必要的能耗。

通过两次计算来确定节点是否是边界节点能够排除外界有干扰的情况,提高精确度。

新协议在能耗上只比LEACH 多了CH 广播一次短信息包的能耗,达到了平衡簇间节点个数减少能耗的目的,而多出的这个能耗相对于数据发送阶段的能耗完全可以忽略不计。

协议中取80%,而信号强度之比用距离平方的反比来表示。

Sink 节点在(50,10)的位置。

在上述环境中对LEACH 以及LB-LEACH 做了对比仿真。

采用一半节点死亡的时间作为网络生存时间的评价标准。

因为若网络中一半节点死亡,剩余节点的能量已经很低,而网络的连通度也无法有效保证。

网络生存时间的对比如图4所示。

LB-LEACH 下的网络生存时间为11315s ,而LEACH 的则为9621s ,说明LB-LEACH 在延长网络寿命上性能要优于LEACH ;LB-LEACH 第一个节点的死亡时间为3420s ,晚于LEACH 中的2568s ,这也说明了均衡网络负载对避免节点的早死有一定作用。

图5说明了Sink 节点接收到数据包的情况以及网络的能耗,由图可知,LB-LEACH 和LEACH 在相同工作时间内传输的数据包基本相同,而在生存时间内,LB-LEACH 发送数据包总数为30815个,而LEACH 发送了26440个。

而在同一时间内,LB-LEACH 的能耗要小于LEACH 的能耗。

仿真实验证明,LB-LEACH 的生存时间比LEACH 提高了17.61%,而发送的数据包个数比LEACH 提高了16.55%,且LB-LEACH 首个节点死亡时间也晚于LEACH ,这些数据说明LB-LEACH 要优于LEACH 。

5结束语本文通过建立节点的能耗模型,对簇中节点能耗进行了定量分析,找出了LEACH 中造成网络中能耗分布不均衡以及图3LB-LEACH 的执行过程Set UpSteadyState T slotS slotW slotFrame 1roundNodes dead in each round in leach;Nodes left in LEACH Nodes dead in each round in LB-LEACH;Nodes left in LB-LEACH图4节点的生存期及死亡时间Time (Second )节点早死的原因,并针对这些不足对LEACH 协议进行了改进,提出了LB-LEACH 协议。

新协议定义了边界节点和内核节点,通过边界节点的选择入簇实现了均衡分簇,使网络中节点的能耗更加均衡。

OMNET++的实验证明,LB-LEACH 在延长网络生存期、增加发送数据包个数以及避免节点早死方面具有较好的效果,实现了网络内的负载均衡。

下一步的工作是将LB-LEACH 改造成簇间多跳协议,以适应大规模网络。

参考文献:[1]任丰原,黄海宁,林闯.无线传感器网络[J ].软件学报,2003,14(7):1282-1291.[2]Akyildiz I,Su W.Wireless sensor networks:A survey [J ].Com-puter Networks,2002,38(4):393-422.[3]Heinzelman W,Chandrakasan A.Energy-efficient communica-tion protocol for wireless microsensor networks [C ].Proceedings of the 33th Hawaii International Conference on System Scien-ces,2000.[4]Lindsey S,Raghavenda CS.PEGASIS:Power efficient gathering in sensor information systems [C ].Williamson DA.Proc of the IEEE Aerospace Conf.New York:IEEE Press,2002:1125-1130.[5]Manjeshwar A,Agrawal DP.TEEN:A routing protocol for enha-nced efficiency in wireless sensor networks [C ].Proceedings of the 15th Parallel and Distributed Processing Symposium.San Francisco:IEEE Computer Society,2001:2009-2015.[6]卿利,朱清新,王明文.异构传感器网络的分布式能量有效成簇算法[J ].软件学报,2006,17(3):481-489.[7]Wendi B Heinzelman,Anantha P Chandrakasan,Hari Bala-krishnan.An application-specific protocol architecture for wire-less microsensor networks [J ].IEEE Transactions on Wireless Communications,2002,1(4):660-670.[8]Wang Ying,Xiong Mudi.Monte carlo simulation of leach proto-col for wireless sensor networks [C ].Dalian:Proceedings of the Sixth International Conference on Parallel and Distributed Com-puting,2005:85-88.[9]杨冕,秦前清.基于无线传感器网络的路由协议[J ].计算机工程与应用,2004,40(32):130-132.(上接第4402页)图5节点能耗及数据包发送Data packets transmitted in LEACH;Energy dissipated in LEACH Data packets transmitted in LB-LEACH;Energy dissipated inLB-LEACH50001000080000600004000020000E n e r g y d i s s i p a t e d (1.0E -4J )Time (Second )5结束语网络不遵循泊松模型,但是能够用自相似过程描述。

相关文档
最新文档