ns2无线网、有线无线混合组网详细编码解释

上传人:m**** 文档编号:185426733 上传时间:2023-02-03 格式:DOCX 页数:29 大小:207.89KB
收藏 版权申诉 举报 下载
ns2无线网、有线无线混合组网详细编码解释_第1页
第1页 / 共29页
ns2无线网、有线无线混合组网详细编码解释_第2页
第2页 / 共29页
ns2无线网、有线无线混合组网详细编码解释_第3页
第3页 / 共29页
资源描述:

《ns2无线网、有线无线混合组网详细编码解释》由会员分享,可在线阅读,更多相关《ns2无线网、有线无线混合组网详细编码解释(29页珍藏版)》请在装配图网上搜索。

1、1 Network dynamicsPrevious section Next section Back to the indexIn this section I am going to show you an example for a dynamic network where the routing adjusts to a link failure. On the way there Ill show you how you can keep a larger number of nodes in a Tcl array instead of giving each node its

2、 own name.VI.1. Creating a larger topologyI suggest you call the Tcl script for this example example3.tcl. You can already insert the template from section IV.l into the file.As always, the topology has to be created first, though this time we take a different approach which you will find more comfo

3、rtable when you want to create larger topologies. The following code creates seven nodes and stores them in the array n().for set i 0 $i 7 incr i set n($i) $ns nodeYou have certainly seen for loops in other programming languages before, and I am sure you understand the structure at once. Note that a

4、rrays, just like other variables in Tcl, dont have to be declared first.Now were going to connect the nodes to create a circular topology. The following piece of code might look a bit more complicated at first.for set i 0 $i 7 incr i $ns duplex-link $n($i) $n(expr ($i+1)%7) 1Mb 10msDropTailThis for

5、loop connects all nodes with the next node in the array with the exception of the last node, which is being connected with the first node. To accomplish that, I used the % (modulo) operator.When you run the script now, the topology might look a bit strange in nam at first, but after you hit the re-l

6、ayout button it should look like the picture below.VI.2. Link failureThe next step is to send some data from node n(0) to node n(3).#Create a UDP agent and attach it to node n(0)set udp0 new Agent/UDP$ns attach-agent $n(0) $udp0# Create a CBR traffic source and attach it toudp0set cbrO new Applicati

7、on/Traffic/CBR$cbrO set packetSize_ 500$cbrO set interval 0.005$cbr0 attach-agent $udp0set nullO new Agent/Null$ns attach-agent $n(3) $null0$ns connect $udp0 $null0$ns at 0.5 $cbr0 start$ns at 4.5 $cbr0 stopThe code above should look familiar to you by now. The only difference to the last sections i

8、s that now we have to use the node array elements.If you start the script, you will see that the traffic takes the shortest path from node 0 to node 3 through nodes 1 and 2, as could be expected. Now we add another interesting feature. We let the link between node 1 and 2 (which is being used by the

9、 traffic) go down for a second.$ns rtmodel-at 1.0 down $n(l)$琐2)$ns rtmodel-at 2.0 up $n(1) $n(2)It is probably not too hard to understand these two lines. Now you can start the script again and you will see that between the seconds 1.0 and 2.0 the link will be down, and all data that is sent from n

10、ode 0 is lost.Now I will show you how to use dynamic routing to solve that problem. Add the following line at the beginning of your Tcl script, after the simulator object has been created.$ns rtproto DVStart the simulation again, and you will see how at first a lot of small packets run through the n

11、etwork. If you slow nam down enough to click on one of them, you will see that they are rtProtoDV packets which are being used to exchange routing information between the nodes. When the link goes down again at 1.0 seconds, the routing will be updated and the traffic will be re-routed through the no

12、des 6, 5 and 4.2 Running Wireless Simulations in nsPrevious section Next section Back to the indexIn this section, you are going to learn to use the mobile wireless simulation model available in ns. The section consists of two parts. In the first subsection, we discuss how to create and run a simple

13、 2-node wireless network simulation. In second subsection, we will extend our example (in subsection 1) to create a relatively more complex wireless scenario.IMPORTANT: This tutorial chapter uses new node APIs which are available as of ns-2.1b6, released January 18, 2000. If you have an earlier vers

14、ion of ns you must upgrade to use these features.IX.1. Creating a simple wireless scenarioWe are going to simulate a very simple 2-node wireless scenario. The topology consists of two mobilenodes, node_(0) and node_(l). The mobilenodes move about within an area whose boundary is defined in this exam

15、ple as 500mX500m. The nodes start out initially at two opposite ends of the boundary . Then they move towards each other in the first half of the simulation and again move away for the second half. A TCP connection is setup between the two mobilenodes. Packets are exchanged between the nodes as they

16、 come within hearing range of one another. As they move away, packets start getting dropped.Just as with any other ns simulation, we begin by creating a tcl script for the wireless simulation. We will call this file simple-wireless.tcl. If you want to download a copy of simple-wireless.tcl click her

17、e.A mobilenode consists of network components like Link Layer (LL), Interface Queue (IfQ), MAC layer, the wireless channel nodes transmit and receive signals from etc. For details about these network components see section 1 of chapter 15 of ns Notes & Documentation (now renamed as ns Manual). At th

18、e beginning of a wireless simulation, we need to define the type for each of these network components. Additionally, we need to define other parameters like the type of antenna, the radio-propagation model, the type of ad-hoc routing protocol used by mobilenodes etc. See comments in the code below f

19、or a brief description of each variable defined. The array used to define these variables, val() is not global as it used to be in the earlier wireless scripts. For details and available optional values of these variables, see chapter 15 (mobile networking in ns) of ns documentation. We begin our sc

20、ript simple-wireless.tcl with a list of these different parameters described above, as follows:# # Define options#set val(chan)Channel/WirelessChannel;# channel typeset val(prop)Propagation/TwoRayGround ;# radio-propagation modelset val(ant)Antenna/OmniAntenna;# Antenna typeset val(ll)LL;# Link laye

21、r typeset val(ifq)Queue/DropTail/PriQueue;# Interface queue typeset val(ifqlen)50;# max packet in ifqset val(netif)Phy/WirelessPhy;# network interface typeset val(mac)Mac/802_11;# MAC typeset val(rp)DSDV;# ad-hoc routing protocolset val(nn)2;# number of mobilenodesNext we go to the main part of the

22、program and start by creating an instance of the simulator,set ns_newSimulatorThen setup trace support by opening file simple.tr and call the procedure trace-all as follows: set tracefdopensimple.tr w$ns_ trace-all $tracefdNext create a topology object that keeps track of movements of mobilenodes wi

23、thin the topological boundary.set topo newTopographyWe had earlier mentioned that mobilenodes move within a topology of 500mX500m. We provide the topography object with x and y co-ordinates of the boundary, (x=500, y=500):$topo load_flatgrid 500500The topography is broken up into grids and the defau

24、lt value of grid resolution is 1. A diferent value can be passed as a third parameter to load_flatgrid above.Next we create the object God, as follows:create-god$val(nn)Quoted from CMU document on god, God (General Operations Director) is the object that is used to store global information about the

25、 state of the environment, network or nodes that an omniscent observer would have, but that should not be made known to any participant in the simulation. Currently, God object stores the total number of mobilenodes and a table of shortest number of hops required to reach from one node to another. T

26、he next hop information is normally loaded into god object from movement pattern files, before simulation begins, since calculating this on the fly during simulation runs can be quite time consuming. However, in order to keep this example simple we avoid using movement pattern files and thus do not

27、provide God with next hop information. The usage of movement pattern files and feeding of next hop info to God shall be shown in the example in the next sub-section.The procedure create-god is defined in ns/tcl/mobility/com.tcl, which allows only a single global instance of the God object to be crea

28、ted during a simulation. In addition to the evaluation functionalities, the God object is called internally by MAC objects in mobilenodes. So even though we may not utilise God for evaluation purposes,(as in this example) we still need to create God.Next, we create mobilenodes. The node creation API

29、s have been revised and here we shall be using the new APIs to create mobilenodes.IMPORTANT NOTE: The new APIs are not available with ns2.1b5 release. Download the daily snapshot version if the next release (2.1b6 upwards) is not as yet available.First, we need to configure nodes before we can creat

30、e them. Node configuration API may consist of defining the type of addressing (flat/hierarchical etc), the type of adhoc routing protocol, Link Layer, MAC layer, IfQ etc. The configuration API can be defined as follows:(parameter examples)# $ns_ node-config -addressingType flat or hierarchical or ex

31、panded#-adhocRouting DSDV or DSR or TORA#-llTypeLL#-macTypeMac/802_11#-propTypePropagation/TwoRayGround#-ifqTypeQueue/DropTail/PriQueue#-ifqLen50#-phyTypePhy/WirelessPhy#-antTypeAntenna/OmniAntenna#-channelTypeChannel/WirelessChannel#-topoInstance$topo#-energyModelEnergyModel#-initialEnergy(in Joule

32、s)#-rxPower(in W)#-txPower(in W)#-agentTraceON or OFF#-routerTraceON or OFF-macTraceON or OFF# -movementTrace ON or OFFAll default values for these options are NULL except: addressingType: flatWe are going to use the default value of flat addressing; Also lets turn on only AgentTrace and RouterTrace

33、; You can experiment with the traces by turning all of them on. AgentTraces are marked with AGT, RouterTrace with RTR and MacTrace with MAC in their 5th fields. MovementTrace, when turned on, shows the movement of the mobilenodes and the trace is marked with M in their 2nd field.The configuration AP

34、I for creating mobilenodes looks as follows:# Configure nodes$ns_ node-config -adhocRouting$val(rp) -llType $val(ll)-macType$val(mac) -ifqType$val(ifq) -ifqLen$val(ifqlen) -antType$val(ant) -propType$val(prop) -phyType$val(netif) -topoInstance$topo -channelType$val(chan) -agentTraceON -routerTraceON

35、 -macTraceOFF -movementTrace OFFNext we create the 2 mobilenodes as follows:for set i 0 $i $val(nn) incr i set node_($i) $ns_ node $node_($i) random-motion 0;# disablerandom motionThe random-motion for nodes is disabled here, as we are going to provide node position and movement(speed & direction) d

36、irectives next.Now that we have created mobilenodes, we need to give them a position to start with,# Provide initial (X,Y, for now Z=0) co-ordinates for node_(0) and node_(1)#$node_(0) set X_ 5.0$node_(0) set Y_ 2.0$node_(0) set Z_ 0.0$node_(1) set X_ 390.0$node_(1) set Y_ 385.0$node_(1) set Z_ 0.0N

37、ode0 has a starting position of (5,2) while Nodel starts off at location (390,385).Next produce some node movements,# Node_(1) starts to move towards node_(0)#$ns_ at 50.0 $node_(1) setdest 25.0 20.0 15.0$ns_ at 10.0 $node_(0) setdest 20.0 18.0 1.0# Node_(1) then starts to move away fromnode_(0)$ns_

38、 at 100.0 $node_(1) setdest 490.0 480.015.0$ns_ at 50.0 $node_(1) setdest 25.0 20.0 15.0 means at time 50.0s, node1 starts to move towards the destination (x=25,y=20) at a speed of 15m/s. This API is used to change direction and speed of movement of the mobilenodes.Next setup traffic flow between th

39、e two nodes as follows:# TCP connections between node_(0) and node_(l)set tcp new Agent/TCP$tcp set class_ 2set sink new Agent/TCPSink$ns_ attach-agent $node_(0) $tcp$ns_ attach-agent $node_(1) $sink$ns_ connect $tcp $sinkset ftp new Application/FTP$ftp attach-agent $tcp$ns_ at 10.0 $ftp startThis s

40、ets up a TCP connection betwen the two nodes with a TCP source on nodeO.Then we need to define stop time when the simulation ends and tell mobilenodes to reset which actually resets thier internal network components,# Tell nodes when the simulation ends#for set i 0 $i thelfile is not formatted prope

41、rly. If calcdest rejects a movement patt ernfileyou have crea ted,the easiesway to f orma tit properlyis o ftento load i tinto ad-hockey and then save it out again. If ad-hockey can read your input correctly, its output will properly formatted for calcdest.Both set destand calcdeslcalcula tehesho rt

42、 estiumber of hops bet ween nodes based on the nominal radio range, ignoring any effects that might be introduced by the propagation model in an actualsimulationThe nominal range is eitheiprovidedas an argument to the programs, or extracted from the header in node-movement pattern files.The path len

43、gth information provided to god was used by CMUs Monarch Project to analyze the path length optimality of ad hoc network routing protocols, and so was printed out as part of th( CMUTrace output for each packet.Other uses that CMU has found for the information are: Characterizing the rate of topology change in a movement pattern. Identifying the frequency and size of partitions. Experimenting with the behavior of the routing protoco

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!