The MIT uAMPS ns Code Extensions解读

翻译:2010-11-27 wcdj
注:对于专有名词和较简单的语句不进行翻译,如有翻译不合适的地方请您留言指正,多谢。

The MIT uAMPS ns Code Extensions Version 1.0



MIT uAMPS extensions to ns 添加了对large-scale WSN的支持。这些extensions包括:节点能量消耗模型节点状态 以及几个路由协议 。这份文档描述了uAMPS对ns的additions部分和一些关于如何使用这个代码进行ns仿真的相关细节。(文档假设读者熟悉ns的操作)

1      Overview of ns Mobile Node
本文所做的工作是基于ns-2.1b5这个发行版,包括CMU Wireless and Mobility platform。CMU对基本的ns simulator增加了包括:mobile nodes, MAC protocols, and channel propagation models。图1显示了a mobile node这个设备的实现。The Application创建了将要传输给Agent【注释】的"data packets"。
【注释】[Agent] 。在ns里,网络中的节点之间实际上是不传输数据的,而使用的是虚拟的数据 ,in the form of a packet of a given length, is transmitted. 因此,packets have a certain size but do not actually contain any data.

Agent 扮演了protocol stack中传输层和网络层 的作用。Agent传输packets of data给CMUTrace,然后由CMUTrace来完成记录关于the packets to trace files的数据。packets然后被发送给Connector,Connector把packets传递给Link-Layer for data-link processing。在一小段延迟后,packets从Link-Layer传递到Queue,在Queue这里,packets被排队。一旦a packet从Queue中移除,它就被发送到MAC,在这里运行media access protocols。最后,这个packet被发送给Network Interface,在这里,the correct transmit power被添加到这个packet中,然后这个packet通过Channel被发送。这个Channel向连接在这个channel上的每个节点发送一份这个packet的copy。
补充:在接收端
The packets are received by each node's Network Interface and then passed up through the MAC, Link-Layer, Connector, CMUTrace, and Agent functions. The Agent de-packetizes(解包) the data and sends notification of packet arrival to the Application.

 

pic

 

2      Resource-Adaptive Node
在ns中添加了Resource-Adaptive Node(资源自适应节点),例如图2所示。
pic

R-A Node具有的新特点是:the Resources和the Resource Manager。Resource Manager提供了a common interface在application和the individual resources之间。Resource可以是任何需要被监视的东西,例如,energy和node neighbors。The Application更新the status of the node's resources through the Resource Manager using the functions:
add:          add more of a resource to the node's supply
remove:     remove some of a resource from the node's supply
query:        find out what amount of the resource the node currently has.

For example, the Energy Resource is used to keep track of a node's energy. The initial energy level is set at the beginning of the simulation, and throughout the simulation, energy is removed by the Application as the node performs computation of data(数据的计算) and by the Network Interface during packet transmission and reception(数据的发送和接收). The Application (and any lower-layer functions) can also find out how much energy remains at any given time. This is useful for implementing resource-adaptive protocols, that change their behavior based on the current level of the resource(根据目前能量资源的多少来决定节点的行为).

例如图3所示,执行一个简单的radio energy dissipation model。
pic

在这个模型中,transmitter端消耗的能量在the radio electronics和the power amplifier,而receiver端消耗能量在the radio electronics。
The amount of energy removed for computation or communication is defined by the user at the beginning of the simualtion .
用户对于节点计算和通信所消耗的能量大小可以在仿真中自定义。

3      Network Interface
The Network Interface扮演的是物理层 的功能(physical-layer functions)。
When it receives a packet from the MAC-layer, it sets the transmit power based on an approximation of the distance to the receiver (assuming power control is used, as in all the protocols we implemented) , removes the appropriate amount of energy to send the packet, and sends the packet to the Channel.
发送端根据接收端的距离设置发送功率(假设,在节点中可以使用power control)。
If the node has used up all its energy after transmitting the packet, the node is dead and will be removed from the channel. Nodes that have dead do not have any impact on the routing protocols, and any data sent to a node that is dead is thrown away.
如果节点的能量用完了,它将被移除channel,节点的“死亡”不会影响路由协议,任何发送给它的数据都被丢弃。

When receiving data, the packet enters the node's Network Interface from the Channel.
If the node is in the sleep state, the Network Interface discards the packets, since sleeping nodes cannot receive or transmit any packets.
如果节点处于休眠状态,Network Interface将会丢弃传递给它的packets,因为睡眠节点不能接收和发送packets。
Therefore, there is no energy cost to these nodes even when packets are being transmitted in their vicinity.
睡眠节点不消耗能量。
However, if data are being sent to a sleeping node, they wil be lost since the node has no way of knowing that it missed a packet. Therefore, the routing protocols must ensure that a transmitting node only sends data to a receiving node when the receiving node is awake to guarantee delivery of the data.
路由协议必须保证一个发送节点向一个接收节点发送数据时,接收节点必须处于awake状态。

【情况一】
If the node is awake, the Network Interface determines the received power of the packet. If the received power is below a detection threshold (P_r-detect), the packet is thrown away, as the node would not have been able to detect that a packet was transmitted.
如果接收节点的能量<P_r-detect,接收节点将丢弃packet。
【情况二】
If the received power is above the detection threshold but below a successful reception threshold (P_r-thresh), the packet is marked as erroneous and passed up the stack.
如果P_r-detect<接收节点的能量<P_r-thresh,packet被标记为错误的,并沿着stack向上传递。
It is not thrown away because reception of this packet affects the ability to successfully receive other packets at the same time.
这种packet不丢弃。
【情况三】
Finally, if the received power is above  P_r-thresh, the packet has been received successfully and is passed up the stack to the MAC class.
如果接收节点的能量>P_r-thresh,packet被成功接收并沿着stack向上传递给MAC class。

The code that implements the functions described in this section is found in wireless-phy.cc

4      MAC Protocol
We create a new MAC protocol type, called MacSensor .
我们使用一个新的MAC协议,MacSensor。
This protocol is a combination of carrier-sense multiple access (CSMA ), time-division multiple access (TDMA ), and a simple model of direct-sequence spread spectrum (DS-SS ).
MacSensor协议包括:载波监听多路访问CSMA协议,时分复用多路访问和直接序列扩频。

TDMA is implemented within the Application by only having the Application send data to the Agent during the specified TDMA time-slot【注释】.
【注释】[time-slot]。In this implementation of TDMA, it is assumed that the clocks of all the nodes are synchronized (同步的). However, it would be more accurate if the clock drift(时钟偏移) was modeled and explicit synchronization was performed. This is an area for future work.
即,假设所有节点的时钟是同步的。

CSMA is implemented in the MacSensor class, and DS-SS is implemented jointly within the application and the MacSensor class.
Non-persistent CSMA is implemented in MacSensor.
CSMA在MacSensor中不是持续运行的
To perform CSMA, the node senses the channel before transmission. If the channel is currently being used by someone else, the node sets a back-off timer to expire(终止) after a random amount of time, where the timer is chosen uniformly(一致的) with a maximum time equal to the transmit time of the packet it is waiting to transmit.
节点在传输数据前要监听channel信道。如果信道目前正在被占用,节点就会停止发送并设置一个back-off timer计时器,在一个随机的时间后,这个时间最长等于一个packet的传输时间,然后节点开始重新检测信道是否可用。

This back-off policy for CSMA is effective for our protocols because all nodes are transmitting packets with the same length during a given time. Therefore, the maximum amount of time that the channel will be busy is equal to the amount of time it would take to transmit the node's packet.
这CSMA的回退策略对我们的协议是有效的,因为所有节点都在一个特定的时间发送具有相同长度的包。

Once the back-off timer expires, the node again senses the channel. If it is still busy (presumably someone else captured the channel first), the node again sets a back-off timer. This continues until the node senses a free channel.

Once the channel is free, the state of the node is set to indicate that the node is currently transmitting data and the node passes the packet to the Network Interface. The node must also set a transmit-timer so it knows when it has finished transmitting the packet and can reset its state to idle.

It is important that the state of the node is set accurately because a node cannot transmit two packets at the same time, and a node cannot receive a packet while it is transmitting.
节点的状态需要被精确地设置。

PS:关于介绍DS-SS 的部分省略。(可参考原文)

If the node is neither transmitting nor receiving when the new packet arrives, the node's state is set to indicate that the node is currently receiving a packet and a timer is set that expires after the length of time required to receive the packet. When the timer expires, the node checks the address field of the packet. If the address is the node's address (or the broadcast address), the packet is sent up the stack to the Queue. Otherwise, the packet is not intended for this node and is dropped.
当节点接收数据的时候,它的状态会被设置为receiving状态,并启动一个timer,这个timer的时间是接收数据所需要的时间,当这个timer终止后,节点检测packet的address,如果是自己的地址or广播地址,这个packet会被沿着协议stack传递给上一层Queue,否者这个packet不是要传给这个节点的packet并把它丢弃。

The code that implements the functions described in this section is found in mac-sensor.cc and mac-sensor-timer.cc【注释】.
【注释】mac-sensor-timer.cc。This code borrows heavily from the implementation of the Mac802_11 Class from ns.

5      LEACH Protocols
LEACH 【3】is implemented exactly as described in Chapter 3 of 【2】. Since LEACH is an application-specific protocol architecture, it is implemented as a subclass(子集) of ns's Application class. The code that implements these functions is in ns-leach.tcl.
LEACH的具体实现可以在参考文献【2】的第三章中找到。因为LEACH是一个基于具体应用的协议框架,它是作为Application class的一个子集。关于实现这些功能的代码可以在ns-leach.tcl中找到。
【2】W. Heinzelman. Application-Specific Protocol Architectures for Wireless Networks . PhD thesis, Massachusetts Institute of Technology, 2000.
【3】W. Heinzelman. A. Chandrakasan, and H. Balakrishnan. Energy-Efficient Routing Protocol for Wireless Microsensor Networks. In Proc. 33rd Hawaii International Conference on System Sciences (HICSS'00), Jan. 2000.

LEACH-C is also implemented as described in Chapter 3 of 【2】. LEACH-C uses many of the same functions as LEACH (only the set-up phase differs), so it is implemented as a sub-class of LEACH. The code that implements LEACH-C is found in ns-leach-c.tcl.
LEACH-C使用了很多和LEACH相同的functions,只是在set-up phase不一样

6      Base Station Application
The base station node has no energy constraints and is the node to which all data are eventually sent . Therefore, the base station node must keep track of(记录) all the data that it receives, as determining when the base station receives the data provides an estimate the latency of different protocols, and determining how much data is received during a given time provides quality information about the different protocols. To perform these functions, we created a BSApp Application.
基站节点是一个没有能量限制的,并且基站接收所有要发送的数据。因此,基站节点必须记录所有它收到的数据信息。比如,确定基站接收数据的时间——用于衡量不同协议的延迟,以及确定在给定时间基站接收到的数据量——用于衡量不同协议的质量信息。

For most of the protocols, this is the only function the base station serves. However, for LEACH-C, the base station must also receive small information packets from each node at the beginning of each round that contain the node's location and current energy level. Once the base station receives this data from all nodes, it must determine optimal clusters. As discussed in Chapter 3 of 【2】, the base station performs simulated annealing(模拟退火算法, to solve the NP-hard problem of finding k optimal clusters) to determine these clusters.
然而,对于LEACH-C协议,基站节点在每一轮开始的时候还必须接收一些短的packets从每一个节点,这些packets中的信息包括:节点的位置信息和节点的能量状态。一旦基站接收到所有节点发送的信息后,基站计算出一个最优的分簇。
Since this is a computationally intense algorithm, the simulated annealing algorithm was implemented in C++, using an Agent called BSAgent. BSAgent determines the optimal clusters and sends this imformation up the stack to BSApplication. The base station node then broadcasts this information to the nodes in the network. These functions are implemented in the files ns-baspp.tcl and bsagent.cc.
因为模拟退火算法是一个复杂度高的计算,所以它放在C++中执行,使用一个Agent叫做BSAgent。BSAgent决定最优分簇,然后将最优分簇信息沿着stack传递给BSApplication。然后基站节点向网络中的所有节点广播这个最优分簇信息。

7      MTE Routing
For MTE routing, routes from each node to the base station were chosen such that each node's next-hop neighbor is the closest node that is in the direction of the base station.
每个节点向基站发送数据的路由的方式是,每个节点将数据发送给它的下一跳节点,这个下一跳邻居节点被定义为在基站方向离它最近的节点。
Each node requires a certain amount of energy to determine their next-hop neighbor. When a node dies, all of that node's upstream neighbors (i.e., all the nodes that send their data to this node ) begin transmitting their data to the node's next-hop neighbor.
每个节点在决定它们下一跳邻居节点的时候需要一个确定的能量,即,根据通信节点的远近使用不同的传输功率。当某个节点“死亡”了,这个节点所有的上游邻居节点,即,向它发送数据的节点,就把要向这个“死亡”节点传送的数据直接传给“死亡”节点的下一跳邻居节点。

Nodes adjust their transmit power to the minimum required to reach their next-hop neighbor. This reduces interference with other transmissions and reduces the nodes' energy dissipation. Communication with the next-hop neighbor occurs using a CSMA MAC protocol, and when a node receives data from one of its upstream neighbors, it forwards the data to its next-hop neighbor. This continues until the data reach the base station. These functions are implemented in ns-mte.tcl.
节点可以调节它们的传输功率,使得向下一跳节点传输的时候使用最小的功率。这样做可以减少与其他通信相互之间的干扰以及减少节点能量的消耗。与next-hop neighbor通信使用的是CSMA MAC protocol,当一个节点接收到它的一个上游邻居节点发送的数据时,它就将这个接收到的数据继续转发给它的下一跳节点。这个转发过程直到数据达到base station。

8      Static-Clustering
The static clustering protocol is identical to LEACH except the clusters are chosen a-priori and fixed. The clusters are formed using the simulated annealing algorithm as in LEACH-C. Static clustering includes scheduled data transmissions form the cluster memebers to the cluster-head and data aggregation at the cluster-head. Static-clustering is implemented in ns-stat-cluster.tcl .
Static-Clustering协议和LEACH协议基本相同,只是簇是事先选择和固定好的。


9      Statistics Collection
We added statistics collection to keep track of the internal state of the network and the individual sensors during the simulation. At periodic intervals, the following data are collected.
1. Amount of energy consumed by each node .
2. Amount of data received at the base station from each node .
3. Number of nodes still alive .
Using these statistics, we can evaluate the effectiveness of the different communication protocols.
我们可以对数据进行分析,包括:每个节点消耗的能量,基站接收到的数据量,存活的节点数。

10      The Code
We added #ifdef uAMPS ... #endif wrappers(包装) around all code we added to existing ns files, including:
app.[cc,h], channel.cc, cmu-trace.[cc,h], mac.cc, packet.[cc,h], phy.[cc,h], and wireless-phy.[cc.h].
We also added the files:
mac-sensor.[cc,h], and mac-sensor-timers.[cc,h].

The files to implement Resource-Adaptive nodes, agents, and link-layer functions are in the directory mit/rca and include:
ns-ranode.tcl, rcagent.[cc,h], rca-ll.[cc,h], resource.[cc,h], energy.[cc,h].

The routing protocol files are in the directory mit/uAMPS and includes:
ns-leach.tcl, ns-leach-c.tcl, ns-mte.tcl, and ns-stat-clus.tcl.
In addition, the files ns-bsapp.tcl, extras.tcl, and stats.tcl contain functions needed to run the the routing protocols.
The files bsagent.[cc,h] contain the base station agent functions.

11      Running the Simulator
The following environment variables must be set:
# LEACH
export RCA_LIBRARY =`pwd`/ns-allinone-2.27/ns-2.27/mit/rca
export uAMPS_LIBRARY =`pwd`/ns-allinone-2.27/ns-2.27/mit/uAMPS

Each of the protocols can be run by setting the rp option to "leach", "leach-c", "mte", or "stat-clus".

The file tcl/ex/wireless.tcl sets some of the simulation parameters and sources the file tcl/mobility/leach.tcl (or leach-c.tcl, mte.tcl, or stat-clus.tcl). These files are linked to files with the same names in mit/uAMPS/sims.
在tcl/ex/wireless.tcl文件中可以设置一些仿真的参数,在代码中通过执行sources tcl/mobility/leach.tcl 脚本,来执行不同的协议。tcl/mobility/leach.tcl等这4个文件都是快捷方式,它们都link到mit/uAMPS/sims 目录下的原文件。

Each of these files sets parameters specific to that protocol and sources the file mit/uAMPS/sims/uamps.tcl , which contains the parameters that are the same for all the routing protocols (e.g., channel bandwidth, data signal size, etc.).
上面的那些文件设置每个具体协议的参数,而mit/uAMPS/sims/uamps.tcl文件包含了所有路由协议相同的参数,例如,信道带宽,数据包大小,等等。

Table 1 shows a list of parameters that are set at the beginning of a simulation .
(略)

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值