收藏 分享(赏)

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

上传人:yjrm16270 文档编号:6077476 上传时间:2019-03-26 格式:DOC 页数:30 大小:289.62KB
下载 相关 举报
ns2无线网、有线无线混合组网详细编码解释.doc_第1页
第1页 / 共30页
ns2无线网、有线无线混合组网详细编码解释.doc_第2页
第2页 / 共30页
ns2无线网、有线无线混合组网详细编码解释.doc_第3页
第3页 / 共30页
ns2无线网、有线无线混合组网详细编码解释.doc_第4页
第4页 / 共30页
ns2无线网、有线无线混合组网详细编码解释.doc_第5页
第5页 / 共30页
点击查看更多>>
资源描述

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.1 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 10ms DropTailThis fo

5、r 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 r

6、e-layout 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 to udp0set cbr0 new Appli

7、cation/Traffic/CBR$cbr0 set packetSize_ 500$cbr0 set interval_ 0.005$cbr0 attach-agent $udp0set null0 new Agent/Null$ns attach-agent $n(3) $null0$ns connect $udp0 $null0$ns at 0.5 “$cbr0 start“$ns at 4.5 “$cbr0 stop“The code above should look familiar to you by now. The only difference to the last s

8、ections is 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 u

9、sed by the traffic) go down for a second.$ns rtmodel-at 1.0 down $n(1) $n(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

10、 sent from node 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

11、through the network. 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 t

12、hrough the nodes 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

13、 run a simple 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

14、 earlier version 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_(1). The mobilenodes move about within an area whose boundary is defined

15、 in this example 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 n

16、odes as they 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.t

17、cl click here.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 # channel typeset val(prop) Propagati

18、on/TwoRayGround ;# radio-propagation modelset val(ant) Antenna/OmniAntenna ;# Antenna typeset val(ll) LL ;# Link layer 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_1

19、1 ;# MAC typeset val(rp) DSDV ;# ad-hoc routing protocol set val(nn) 2 ;# number of mobilenodesNext we go to the main part of the program and start by creating an instance of the simulator,set ns_ new SimulatorThen setup trace support by opening file simple.tr and call the procedure trace-all as fol

20、lows: set tracefd open simple.tr w$ns_ trace-all $tracefd Next create a topology object that keeps track of movements of mobilenodes within the topological boundary. set topo new TopographyWe had earlier mentioned that mobilenodes move within a topology of 500mX500m. We provide the topography object

21、 with x and y co-ordinates of the boundary, (x=500, y=500) : $topo load_flatgrid 500 500The topography is broken up into grids and the default 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-go

22、d $val(nn)Quoted from CMU document on god, “God (General Operations Director) is the object that is used to store global information about the 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.“ Cu

23、rrently, God object stores the total number of mobilenodes and a table of shortest number of hops required to reach from one node to another. The next hop information is normally loaded into god object from movement pattern files, before simulation begins, since calculating this on the fly during si

24、mulation runs can be quite time consuming. However, in order to keep this example simple we avoid using movement pattern files and thus do not 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-

25、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 created during a simulation. In addition to the evaluation functionalities, the God object is called internally by MAC objects in mobilenodes. So even though we

26、may not utilise God for evaluation purposes,(as in this example) we still need to create God.Next, we create mobilenodes. The node creation APIs 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. Downlo

27、ad 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 create them. Node configuration API may consist of defining the type of addressing (flat/hierarchical etc), the type of adhoc routing protocol, Link Layer, MAC la

28、yer, IfQ etc. The configuration API can be defined as follows:(parameter examples)# $ns_ node-config -addressingType flat or hierarchical or expanded# -adhocRouting DSDV or DSR or TORA# -llType LL# -macType Mac/802_11# -propType “Propagation/TwoRayGround“# -ifqType “Queue/DropTail/PriQueue“# -ifqLen

29、 50# -phyType “Phy/WirelessPhy“# -antType “Antenna/OmniAntenna“# -channelType “Channel/WirelessChannel“# -topoInstance $topo# -energyModel “EnergyModel“# -initialEnergy (in Joules)# -rxPower (in W)# -txPower (in W)# -agentTrace ON or OFF# -routerTrace ON or OFF# -macTrace ON or OFF# -movementTrace O

30、N or OFFAll default values for these options are NULL except: addressingType: flat We are going to use the default value of flat addressing; Also lets turn on only AgentTrace and RouterTrace; You can experiment with the traces by turning all of them on. AgentTraces are marked with AGT, RouterTrace w

31、ith 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 API for creating mobilenodes looks as follows:# Configure nodes$ns_ node-config -adhocRouting $val(rp) -llType $

32、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) -agentTrace ON -routerTrace ON -macTrace OFF -movementTrace OFFNext we create the 2 mobilenodes as follows:for set i 0 $i $val(n

33、n) incr i set node_($i) $ns_ node $node_($i) random-motion 0 ;# disable random motion The random-motion for nodes is disabled here, as we are going to provide node position and movement(speed $ns_ at 150.0001 “stop“$ns_ at 150.0002 “puts “NS EXITING.“ ; $ns_ halt“proc stop global ns_ tracefdclose $t

34、racefdAt time 150.0s, the simulation shall stop. The nodes are reset at that time and the “$ns_ halt“ is called at 150.0002s, a little later after resetting the nodes. The procedure stop is called to flush out traces and close the trace file. And finally the command to start the simulation,puts “Sta

35、rting Simulation.“$ns_ runSave the file simple-wireless.tcl. In order to download a copy of the file click here. Next run the simulation in the usual way (type at prompt: “ns simple-wireless.tcl“ )At the end of the simulation run, trace-output file simple.tr is created. As we have turned on the Agen

36、tTrace and RouterTrace we see DSDV routing messages and TCP pkts being received and sent by Router and Agent objects in node _0_ and _1_. Note that all wireless traces starts with WL in their first field. See Chapter 15 of ns documentation for details on wireless trace. We see TCP flow starting at 1

37、0.0s from node0. Initially both the nodes are far apart and thus TCP pkts are dropped by node0 as it cannot hear from node1. Around 81.0s the routing info begins to be exchanged between both the nodes and around 100.0s we see the first TCP pkt being received by the Agent at node1 which then sends an

38、 ACK back to node0 and the TCP connection is setup. However as node1 starts to move away from node0, the connection breaks down again around time 116.0s. Pkts start getting dropped as the nodes move away from one another.IX.2. Using node-movement/traffic-pattern files and other features in wireless

39、simulationsAs an extension to the previous sub-section, we are going to simulate a simple multihop wireless scenario consisting of 3 mobilenodes here. As before, the mobilenodes move within the boundaries of a defined topology. However the node movements for this example shall be read from a node-mo

40、vement file called scen-3-test. scen-3-test defines random node movements for the 3 mobilenodes within a topology of 670mX670m. This file is available as a part of the ns distribution and can be found, along with other node-movement files, under directory ns/tcl/mobility/scene. Random node movement

41、files like scen-3-test can be generated using CMUs node-movement generator “setdest“. Details on generation of node movement files are covered in section XI.2 of this tutorial.In addition to node-movements, traffic flows that are setup between the mobilenodes, are also read from a traffic-pattern fi

42、le called cbr-3-test. cbr-3-test is also available under ns/tcl/mobility/scene. Random CBR and TCP flows are setup between the 3 mobilenodes and data packets are sent, forwarded or received by nodes within hearing range of one another. See cbr-3-test to find out more about the traffic flows that are

43、 setup. These traffic-pattern files can also be generated using CMUs TCP/CBR traffic generator script. More about this is discussed in section XI.1 of this tutorial.We shall make changes to the script, simple-wireless.tcl, we had created in section IX.1. and shall call the resulting file wireless1.t

44、cl. For a copy of wireless1.tcl download from here. In addition to the variables (LL, MAC, antenna etc) that were declared at the beginning of the script, we now define some more parameters like the connection-pattern and node-movement file, x and y values for the topology boundary, a seed value for

45、 the random-number generator, time for the simulation to stop, for convinience. They are listed as follows:set val(chan) Channel/WirelessChannelset val(prop) Propagation/TwoRayGroundset val(netif) Phy/WirelessPhyset val(mac) Mac/802_11set val(ifq) Queue/DropTail/PriQueueset val(ll) LLset val(ant) An

46、tenna/OmniAntennaset val(x) 670 ;# X dimension of the topographyset val(y) 670 ;# Y dimension of the topographyset val(ifqlen) 50 ;# max packet in ifqset val(seed) 0.0set val(adhocRouting) DSRset val(nn) 3 ;# how many nodes are simulatedset val(cp) “/mobility/scene/cbr-3-test“ set val(sc) “/mobility

47、/scene/scen-3-test“ set val(stop) 2000.0 ;# simulation timeNumber of mobilenodes is changed to 3; Also we use DSR (dynamic source routing) as the adhoc routing protocol inplace of DSDV (Destination sequence distance vector); After creation of ns_, the simulator instance, open a file (wireless1-out.t

48、r) for wireless traces. Also we are going to set up nam traces.set tracefd open wireless1-out.tr w ;# for wireless traces$ns_ trace-all $tracefdset namtrace open wireless1-out.nam w ;# for nam tracing$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)Next (after creation of mobilenodes) source node-movement and connection pattern files that were defined earlier as val(sc) and val(cp) respectively.# # Define node moveme

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 通信信息 > 光网络传输

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报