Reading Notes on NS2(13)

无线网络的模拟

 

[1] 无线网络概述

无线网络是指以无线信道作为传输媒介的计算机网络,它直接利用电磁波在空中发送/接收数据,无需线缆介质,目前为止数据传输速率已经能够达到54Mbps,传输距离可达20km。
目前无线网络可以分为两类:
(1)有固定接入点的无线网络(Infrastructure Wireless Networks)
通常所说的移动通信系统(例如手机)属于这类,特点是所有移动终端的通信都必须通过固定接入点(例如基站)来完成。
(2)无固定接入点的无线网络(Infrastructureless Wireless Networks)
通常称这种网络为Ad Hoc网络或MANET(Mobile Adhoc Networks)。Ad Hoc网络无固定的路由器,网络中的节点既是通信终端,同时也是转发数据包的路由器,通常又称之为自组织网络(self-organized network)。
注意:
(a)Ad Hoc网络无需任何固定接入节点,信息数据的交互全部通过无线网络各移动终端之间接力的方式来实现。
(b)Ad Hoc网络通常应用于很难设立固定接入点或者固定接入点建造代价较高的场合。

 


[2] NS2的无线网络的移动节点

无线模块最初是由CMU的Monarch工作组引入到NS中的。此无线模块不仅可以对WLAN或者多跳的Ad Hoc等无线网络进行模拟,还可以模拟有线和无线混合的复杂网络。


移动节点的结构

无线模型的核心是移动节点(Mobile Node),它代表实际无线网络中的站点(Station, STA)。
移动节点是由一系列的网络构建构成的,这些构件包括:LL, ARP, IFq, Mac, NetIF (详见P.91图3.23)
注意:
(1)NS2中实现了WLAN采用的IEEE 802.11的DCF(Distributed Coordination Function)MAC协议。此外,还实现了无线传感器网络(WSN)所使用的IEEE 802.15标准。
(2)802.11的MAC控制采用的是CSMA/CA (通过物理载波检测和虚拟载波检测[NAV网络分配矢量,表示媒介空闲剩余时间值]策略的结合);而以太网802.3的MAC控制采用是CSMA/CD。


移动节点的创建

创建无线网络的模拟场景最主要的就是创建移动节点。移动节点的创建与有线节点的创建不同。
主要的区别是:在创建移动节点之前,必须对移动节点进行配置。

创建一个移动节点的方法:
步骤一:调用模拟器对象ns的内部过程node-config{}对移动节点进行配置。
步骤二:调用模拟器对象ns的内部过程node{}正真地创建移动节点。


移动节点的运动

NS2中,移动节点可以在一个三维的拓扑中运动,然而实际上第三维(z轴)并没有被使用。这样移动节点就在一个z=0的二维平面中运动。
有两种方法使移动节点运动:
(1)确定节点的起始位置和终止位置,然后通过调用节点对象的内部过程setdest{}使节点从起始位置向终止位置移动。
注意:
通常将设置节点运动的代码存放在一个单独的场景文件中。NS2也提供了setdest工具用来随机生成无线网络所需要的节点的运动场景文件。当节点较多时,使用setdest工具自动产生节点的运动场景给Tcl编程人员带来了极大的方便。

[Attention!] 代码中的setdest是node对象的一个内部过程,而后面的setdest工具是NS2用来自动生成节点运动场景的工具,两者的含义完全不同。一个是内部过程,而另一个是工具。setdest工具的用法见P.94

代码自动生成以后,可以在Tcl脚本中使用source命令引入所生成文件中的代码,即:source scen-filename 但是在使用的时候必须要保证两点:1,source scen-filename这行代码必须放在创建移动节点之后。2,自动产生的代码中的node数组、模拟器对象、god对象必须已经在Tcl脚本中创建并且名称相同。这样才可以直接使用。

(2)使用start命令使节点随机运动。
$mobilenode是移动节点对象,start命令能使移动节点从随机位置开始随机运动,终止位置和移动速度都是随机产生的。


[总结] 创建一个无线网络模拟场景的步骤

(1)创建一个拓扑对象,设定移动节点运动的范围。
(2)配置节点,调用模拟器对象ns的内部过程node-config{}配置节点。
(3)创建一个god对象,动态地保存各移动节点之间的连接关系。
(4)调用模拟器对象ns的node{}内部过程创建移动节点。
(5)调用god对象的set-dist{}过程,设置各节点之间的最短跳数。
(6)使用上面两种方法引发节点运动。


[3] NS2的无线网络的路由代理
在NS2中实现了4种Ad Hoc无线路由协议:
表驱动路由协议
(1)DSDV——是传统的距离向量算法的改进版本

按需路由协议
(2)DSR——包含路由发现和路由维护
(3)AODV——是DSR和DSDV的结合
(4)TORA

在NS2中,无线节点的Adhoc routing属性有4个可选值(DSDV、DSR、AODV、TORA),可以根据需要在配置节点时选择合适的路由算法。


[4] 无线网络的能量模型和无线传播模型

无线网络能量模型

NS2中实现的能量模型是一个节点的属性,它显示了移动主体的能量水平。在模拟开始时,节点的能量模型有一个初始值initialEnergy_。移动节点在发送数据和接受数据时都有能量消耗。在NS2中,可以通过 txPower_ 和 rxPower_ 这两个属性分别设定节点发送数据和接受数据时的能量消耗。

无线传播模型

NS2支持3种无线传播模型:FreeSpace、TowRayGround和Shadowing模型。
这些传播模型是移动节点用来预测接收到的每个分组的信号能量。
无线传播模型也是节点的一个属性,可以在节点配置时进行设定。

注意:
NS2提供threshold工具用来计算在某种传输模型下,如何设定接收功率阀值来控制无线传输的范围。(需要用gcc对源文件进行编译,见P.100)


[5] 无线Trace
无线Trace的格式有两个版本:老版本 和 修订版
详见P.102

 

 

 

[6] 无线网络模拟实例

模拟的范围区域为1000m*1000m,共有3个移动节点。在节点0和节点2之间建立一条CBR/UDP的连接。在模拟时间200s时,节点1开始从位置(500,500)移动到(500,900),然后在500s时,再从位置(500,900)移动到(500,100)。全部的模拟时间为1000s。拓扑为:

0 (350,500)  150m   1 (500,500)  150m   2 (650,500)

 

 

The Network Simulator, Version 3 -------------------------------- Table of Contents: ------------------ 1) An overview 2) Building ns-3 3) Running ns-3 4) Getting access to the ns-3 documentation 5) Working with the development version of ns-3 Note: Much more substantial information about ns-3 can be found at http://www.nsnam.org 1) An Open Source project ------------------------- ns-3 is a free open source project aiming to build a discrete-event network simulator targeted for simulation research and education. This is a collaborative project; we hope that the missing pieces of the models we have not yet implemented will be contributed by the community in an open collaboration process. The process of contributing to the ns-3 project varies with the people involved, the amount of time they can invest and the type of model they want to work on, but the current process that the project tries to follow is described here: http://www.nsnam.org/developers/contributing-code/ This README excerpts some details from a more extensive tutorial that is maintained at: http://www.nsnam.org/documentation/latest/ 2) Building ns-3 ---------------- The code for the framework and the default models provided by ns-3 is built as a set of libraries. User simulations are expected to be written as simple programs that make use of these ns-3 libraries. To build the set of default libraries and the example programs included in this package, you need to use the tool 'waf'. Detailed information on how use waf is included in the file doc/build.txt However, the real quick and dirty way to get started is to type the command ./waf configure --enable-examples followed by ./waf in the the directory which contains this README file. The files built will be copied in the build/ directory. The current codebase is expected to build and run on the set of platforms listed in the RELEASE_NOTES file. Other platforms may or may not work: we welcome patches to improve the portability of the code to these other platforms. 3) Running ns-3 --------------- On recent Linux systems, once you have built ns-3 (with examples enabled), it should be easy to run the sample programs with the following command, such as: ./waf --run simple-global-routing That program should generate a simple-global-routing.tr text trace file and a set of simple-global-routing-xx-xx.pcap binary pcap trace files, which can be read by tcpdump -tt -r filename.pcap The program source can be found in the examples/routing directory. 4) Getting access to the ns-3 documentation ------------------------------------------- Once you have verified that your build of ns-3 works by running the simple-point-to-point example as outlined in 4) above, it is quite likely that you will want to get started on reading some ns-3 documentation. All of that documentation should always be available from the ns-3 website: http:://www.nsnam.org/documentation/. This documentation includes: - a tutorial - a reference manual - models in the ns-3 model library - a wiki for user-contributed tips: http://www.nsnam.org/wiki/ - API documentation generated using doxygen: this is a reference manual, most likely not very well suited as introductory text: http://www.nsnam.org/doxygen/index.html 5) Working with the development version of ns-3 ----------------------------------------------- If you want to download and use the development version of ns-3, you need to use the tool 'mercurial'. A quick and dirty cheat sheet is included in doc/mercurial.txt but reading through the mercurial tutorials included on the mercurial website is usually a good idea if you are not familiar with it. If you have successfully installed mercurial, you can get a copy of the development version with the following command: "hg clone http://code.nsnam.org/ns-3-dev"
最新发布
03-08
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值