NS2与网络仿真part3

合集下载

NS2仿真实验报告

NS2仿真实验报告

Ns2简单有线网络仿真实验报告一、实验概述1、在windows系统下安装Centos虚拟机2、在Centos系统下安装NS2仿真工具包3、Nam方式示例二、实验内容1)NS2仿真工具包安装说明1.在Centos系统下设置root账户2.解压NS2文件3.安装ns-allinone-2.35设置环境变量4.验证NS2工具包安装情况2)Nam方式Otcl脚本# 产生一个仿真的对象set ns [new Simulator]#针对不同的资料流定义不同的颜色,这是要给NAM用的$ns color 1 Green$ns color 2 Red#开启一个NAM trace fileset nf [open out.nam w]$ns namtrace-all $nf#开启一个trace file,用来记录封包传送的过程set nd [open out.tr w]$ns trace-all $nd#定义一个结束的程序proc finish {} {global ns nf nd$ns flush-traceclose $nfclose $nd#以背景执行的方式去执行NAMexec nam out.nam &exit 0}#产生6个网络节点set n0 [$ns node]set n1 [$ns node]set n2 [$ns node]set n3 [$ns node]set n4 [$ns node]set n5 [$ns node]#把节点连接起来$ns duplex-link $n0 $n2 2Mb 10ms DropTail$ns duplex-link $n1 $n2 2Mb 10ms DropTail$ns duplex-link $n2 $n3 1.7Mb 20ms DropTail$ns duplex-link $n3 $n4 1.7Mb 30ms DropTail$ns duplex-link $n3 $n5 1.5Mb 30ms DropTail#设定ns2到n3之间的Queue Size为10个封包大小$ns queue-limit $n2 $n3 10$ns queue-limit $n3 $n4 5#$ns queue-limit $n3 $n5 10#设定节点的位置,这是要给NAM用的$ns duplex-link-op $n0 $n2 orient right-down$ns duplex-link-op $n1 $n2 orient right-up$ns duplex-link-op $n2 $n3 orient right$ns duplex-link-op $n3 $n4 orient right-up$ns duplex-link-op $n3 $n5 orient right-down#观测n2到n3之间queue的变化,这是要给NAM用的$ns duplex-link-op $n2 $n3 queuePos 0.5#建立一条n0-n5TCP的联机set tcp [new Agent/TCP]$ns attach-agent $n0 $tcpset sink [new Agent/TCPSink]$ns attach-agent $n5 $sink$ns connect $tcp $sink#在NAM中,TCP的联机会以Green表示$tcp set fid_ 1#在TCP联机之上建立FTP应用程序set ftp [new Application/FTP]$ftp attach-agent $tcp$ftp set type_ FTP#建立一条UDP的联机set udp [new Agent/UDP]$ns attach-agent $n1 $udpset null [new Agent/Null]$ns attach-agent $n3 $null$ns connect $udp $null#在NAM中,UDP的联机会以红色表示$udp set fid_ 2#在UDP联机之上建立CBR应用程序set cbr [new Application/Traffic/CBR]$cbr attach-agent $udp$cbr set type_ CBR$cbr set packet_size_ 1000$cbr set rate_ 1mb$cbr set random_ false#设定FTP和CBR资料传送开始和结束时间$ns at 0.1 "$cbr start"$ns at 1.0 "$ftp start"$ns at 4.0 "$ftp stop"$ns at 4.5 "$cbr stop"#结束TCP的联机(不一定需要写下面的程序代码来实际结束联机)$ns at 4.5 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink"#在仿真环境中,5秒后去呼叫finish来结束仿真(这样要注意仿真环境中#的5秒并不一定等于实际仿真的时间$ns at 5.0 "finish"#执行仿真$ns run3)仿真结果仿真结束后,会产生out.nam和out.tr两个档案用来把仿真的过程用可视化的方式呈现出来4)数据分析1.End-to-End Delay把测量CBR封包端点到端点间延迟时间的awk程序,写在档案measure-delay.awk档案中BEGIN {#程序初始化,设定一变量以记录目前最高处理封包的ID。

基于NS2的网络仿真

基于NS2的网络仿真

课设(三):基于NS2的网络仿真一、课程设计目的1、理解NS2的基本概念;2、熟悉安装NS2的实验环境和基本操作;3、仿真分析UDP通信协议;4、学会生成NS2的Tcl脚本及仿真结果分析;二、课程设计原理1、UDP协议(1)协议概述UDP是User Datagram Protocol的简称,中文名是用户数据报协议,是OSI(Open System Interconnection,开放式系统互联)参考模型中一种无连接的传输层协议,它主要用于不要求分组顺序到达的传输中,分组传输顺序的检查与排序由应用层完成,提供面向事务的简单不可靠信息传送服务。

(2)协议功能描述UDP在IP数据报的头部仅仅加入了复用和数据校验(字段),UDP首部字段由4个部分组成,其中两个是可选的。

各16位的源端口和目的端口用来标记发送和接受的应用进程,因为UDP不需要应答,所以源端口是可选的,如果源端口不用,那么置为零。

在目的端口后面是长度固定的以字节为单位的长度字段,用来指定UDP数据报包括数据部分的长度。

由于缺乏可靠性,UDP应用一般必须允许一定量的丢包、出错和复制。

由于UDP协议缺乏拥塞避免和控制机制,需要基于网络的机制来减小因失控和高速UDP流量负荷而导致的拥塞崩溃效应。

UDP协议只在IP的数据报服务之上增加了很少的功能,这就是端口的功能(有了端口,运输层就能进行复用和分用)和差错检测的功能。

另外,UDP协议应用程序可以是客户机,也可以是服务器程序,不必向TCP协议应用程序那样必须分别建立客户机程序和服务器程序。

在远程控制软件中,如果在局域网内部传输屏幕信息,则使用UDP协议比较容易实现。

但UDP协议不提供可靠性,它的可靠性是交给其他网络设备来解决。

同时用UDP协议来传输的数据一般较小,它需要IP协议来为它对数据进行分段。

2、NS2概述NS2(Network Simulator version2,网络仿真软件第二版)是一种面向对象的网络仿真器,本质上是一个离散事件模拟器。

NS2网络模拟(精)

NS2网络模拟(精)

NS2网络模拟(精)The application of wireless Ad-hoc network[Hospital mobile server]Lin QiuDepartment of Mathematics&Computing2009University of South QueenslandQueensland,AustraliaSupervised by Dr.ZhongWei,Zhang*********************ABSTRACTWireless ad-hoc networks have attracted many applications in part decade due to its feature of being wireless and with-out?xed nodes as router or gateway.This type of network has an important potential of being token in the healthcareor hospitals,where the physical connectivities is hard,or not economical.In this paper,we simulate a wireless ad-hoc network by using NS2,inspect its performance under manydi?erent settings and models.General TermsWireless ad-hoc networkKeywordsInstantaneous throughput,Average throughput,Congestion win-dow size1.INTRODUCTIONA wireless ad-hoc network is actually decentralized wire-less network in which each node may transfer data for other nodes.This?exibility provide users with a potential to re-placing traditional networks anywhere,the physical connec-tivity is a concern.We also,however,realized that the TCP performance onwireless ad-hoc network has some sever lim-itions.2.BLUE POINTDesigning a blue point for whole hospital mobile server with wireless Ad-hoc network by NS2.Copyright c USQ2009.The design for NS2show as below:Simulation Time:50secTopology:400m x400mMobility of nodes is de?ned as following:–Node A:(1,1–Node B:(1,399–Node C:(399,1–Node D:(200,200–Node E:(399,399–At time0,node A and C start moving towards the initial position of node E and B respectivelyat speed of30milesecond.–At time0,node E and B start moving towards the initial position of node A and C respectivelyat speed of30milesecond.–Once they reach the targeted location,reverse the direction and return to the original position atthe same speed.There are two TCP connections:–Connection1:From A to E–Connection2:From C to B–Both start2seconds after the simulation starts.–Both congestion window size:50packets,packet.size:1000bytes,the minimum timeout period:0.2second.–Both tra?c sources are FTP sources.Scenarios:–llType:LL–IFQ Len:50–IFQ Type:QueueDropTailPriQueue–Antenna:Antenna/OmniAntenna–Propagation model:PropagationTwoRayGround–Physical layer:PhyWirelessPhy–Channel:ChannelWirelessChannel–Mac layer protocol:802.11–Network Routing Protocol:AODV–TCP protocol:TCP RenoOther design:–Set Link layer typeLL set mindelay50usLL set delay25usLL set bandwidth0–Set interface queue typeQueueDropTailPriQueueset Prefer Routing protocols1–Unity gain,omni-directional antennas set up the antennas to be centered in the node and1.5me-ters above itAntennaOmniAntenna set X0AntennaOmniAntenna set Y0AntennaOmniAntenna set Z 1.5AntennaOmniAntenna set Gt 1.0AntennaOmniAntenna set Gr 1.0–Set network interface type Initialize the Shared-Media interface with parameters to make it worklike the914MHz Luccent WaveLAN DSSS radiointerfacePhyWirelessPhy set CPThresh10.0PhyWirelessPhy set CSThresh 1.559e-11PhyWirelessPhy set RXThresh 3.652e-10PhyWirelessPhy set Rb2*1e6PhyWirelessPhy set Pt0.2818PhyWirelessPhy set freq914e+6PhyWirelessPhy set L 1.0Collect the data from network topology by Perl –Average throughput data–Instantaneous throughput data–Congestion window size dataWhen t he thousands of data gained,plotting a few in-tuitionistic2D graphs with Gnuplot and Xgraph show its variability.–Instantaneous throughput graph–Congestion window size graphResults presentation(units should be speci?ed e.g.bytes/sec,bit/sec,etc–Explain the TCP performance changes over time.–Compare the TCP performance of the two WORK SIMULATIONAssume there are many hospital departments,mobile de-vice of sta?s by a wide variety of healthcare professionals, with some crossover between departments,such as accident and emergency(A&Ewhere are likely to take in patientat?rst.Main diagnostic department in which building,Pa-tients,doctors and nurses are assessed and seen from the dif-ferent departments.Other department,like Elderly services department or General surgery department where has ex-pertdoctors.Each department con?gure own wireless de-vice that directly communicate with the central diagnos-tic department in case of responding a emergency.To help achievement of wireless network c on?guration,NS2software make a mirror for its con?guration running.3.1Layer con?gurationThose basic parameters for simulation provide the simple information for di?erent layers.set val(chanChannel/WirelessChannel;#channel typeset val(propPropagation/TwoRayGround;#radio-propagation model set val(netifPhy/WirelessPhy;#network interface typeset val(macMac/80211;#MAC typeset val(ifqQueue/DropTail/PriQueue;#interface queue type set val(llLL;#link layer typeset val(antAntenna/OmniAntenna;#antenna modelset val(ifqlen50;#max packet in ifqset val(nn5;#number of mobile nodesset val(rpAODV;#routing protocolset val(x400;#X dimension of topographyset val(y400;#Y dimension of topographyset val(stop50;#time of simulation end3.2Nodes con?gurationHere is a nod es con?guration shown blow[?],$ns node-con?g-adhocRouting$val(rp-llType$val(ll-macType$val(mac-ifqType$val(ifq-ifqLen$val(ifqlen-antType$val(ant-propType$val(prop-phyType$val(netif-channelType$val(chan-topoInstance$topo-agentTrace ON-routerTrace ON-macTrace ON-movementTrace OFF3.3Antennas,Network interfaceThose con?gurations of Antennas and Network interface con?gure like the requirement given,which has been shown above.3.4Network T opology#Create the number of nodesset node(A[$ns node]set node (B[$ns node]set node (C[$ns node]set node (D[$ns node]set node (E[$nsnode]Figure 1:Wireless Ad-hoc network topology Start doing project work,network model is shown in Fig-ure 1,which is a wireless ad hoc network consisting of 5nodes(A,B,C,D,E represent as 0,1,2,3,4.The nodes D which is a special node known as an router which is an access point manages communication among other nodes(A,B,D,E,and all other nodes can be considered as clients.$node (A setX 1.0$node (A setY 1.0$node (A setZ 0.0$node (B setX 1.0$node (B setY 399.0$node (B setZ 0.0$node (C setX 399.0$node(C setY 1.0$node (C setZ 0.0$node (D setX 200.0$node (D setY 200.0$node (D setZ0.0$node (E setX 399.0$node (E setY 399.0$node (E setZ 0.03.5TCP connectionThere are two TCP con?gur ations with 5nodes using Newreno TCPalgorithm.Newreno algorithm that is a ver-sion of Reno for deal with congestion on the network.When the packet is lost,using ”fast retransmit”and ”fast recov-ery”mechanism controls the congestion window.[?][?]NewReno algrithom processing approaches:Step1:Resend the ACK packet for three timesIf the third ACK had received and fast recovery does not access process,to check the accumulative value whether it is greater than recover variable.If it is,then going to next step 2,or it is not,then going to next step 3.Step2:Transfer fast retransmitSetup slow start threshold as max(FlighSize /2,2*SMSSFlighSize represents the data sent but it does not ar-rive at the destination yet.So the max serial number save into the recover variable and send out then going to step 4.?Step3:Do not transfer fast retransmitDo not access doing fast retransmit and fast recovery and do not change ssthresh.Going to step 6.?Step4:Fast retransmit Retransmit the packet that had been lost and setup the congestion window size as ssthresh+3*SMSS.?Step5:Fast recoveryDuring the fast recovery,to increase the congestion window size when every ACK packet resend have re-ceived.?Step6:Fast recovery continueContinue send a data segment if the congestion window size and receiver allow.?Step7:CheckoutWhen a new ACK packet had received,then doing checkout that has two conditions:1.Fully checkoutCheck every data from ACK including recover serial number and data information,and setup the CWND as min(ssthresh,FlighSize+SMSS.2.Part checkout Generate a part of ACK when the ACK does not full checkout,and retransmit ?rst segment that has not been checkout.According to new ACK,to decrease CWND.Step8:Retransmit timeoutwhen the packet retransmit timeout,to save the biggest serial number to recover variable then stop fast recov-ery.set tcp [new Agent/TCP/Newreno]$tcp set class 1$tcp set window 50 $tcp set packetSize 1000Agent/TCPSink/DelAck set interval 200ms set sink [newAgent/TCPSink/DelAck]$ns attach-agent $node (E$sink $ns connect $tcp $sinkset ftp [new Application/FTP]$ftp attach-agent $tcp $ns at2.0”$ftp start”set tcp2[new Agent/TCP/Newreno]$tcp2set class 2$tcp2set window 50$tcp2set packetSize 1000Agent/TCPSink/DelAck set interval 200ms set sink2[newAgent/TCPSink/DelAck]$ns attach-agent $node (C$tcp2$ns attach-agent $node(B$sink2$ns connect $tcp2$sink2set ftp2[new Application/FTP]$ftp2attach-agent $tcp2$ns at 2.0”$ftp2start”The design of TCP agent between node A to node E and Node C to Node B of which the packets in the black round signal have limited as 1000bytes,and their minimum time-out period also is set to 0.2second.The congestion windo w’s size setup 50packets[?].3.6Nodes’Movement5nodes are with initial positions at time 0.After that,the node A,B,C,E are moving to node D slowly and syn-chronously with 30milesecond.$ns at 0.0”$node (Asetdest 200.0200.030.0”$ns at 0.0”$node (Csetdest200.0200.030.0”$ns at 0.0”$node (Bsetdest 200.0200.030.0”$ns at 0.0”$node (Esetdest 200.0200.030.0”When the distance between adjacent client nodes is 199mile,the reverse time between client node and core node we can known as 199.0?sqrt (2/30.0.$ns at [ex pr 199.0*sqrt(2/30.0]”$node (Asetdest 1.01.030.0”$ns at [expr 199.0*sqrt(2/30.0]”$node (Csetdest 399.01.030.0”$ns a t [expr 199.0*sqrt(2/30.0]”$node (Bsetdest 1.0399.030.0”$ns at [expr 199.0*sqrt(2/30.0]”$node (Esetdest 399.0399.030.0”The Figure 2show that all nodes converge at (200,200around 9.4seconds and return back at the sametime.Figure 2:Nodes ?ock together4.DATA ANALYSIS 4.1Congestion Window SizeXgraph is used to plot the graph for result analysis that is provded by network simulator.It allows to create postscript,Tgif ?les and others,by clicking on the botton of the NAM as “Hdcpy”.In this project,Xgraph commands process a con-gestion window size(CWND.The procedure called plotWin-dow is added in the TCL ?le that generate an outputle.Figure 3:Congestion Window SizeIn this procedure,we also set up the instantaneous size of the window of TCP with the tim e intervals of 0.1second,and generate another ?le is ”win.tr”.We can monitor a plot of congestion window using the data from this ?le.Using TCP/Reno connection is the modern version take the FTP tra?c.When the packet is lost,TCP connection is going to nex t step that is adopting ”fastrecovery”strategy control the congestion window.In other word,to setup size into the half of congestion window,then to increase the size of 1/congestion window.According to this theory,FTP tra?c set up in this project will increase gradually during 20seconds when CWND start happen at 2second.However,at 19.41second,CWND goes down directly to 1and continue keep this value constantly because two FTP tra?c stopped at 19.5second.In addition,each TCP also maintain a window called the Congestion Window or cwnd have de?ned size as ing congestion window (cwndadjust the transmis-sion rate in order to ?x up the TCP network congestion.The congestionwindow either increases or decreases that depend on ACKs (acknowledgementsbeca use it re?ects the status of link’s bu?er queues.This chart shows the value of con-gestion window based on observed packets (duplicate ACKsand plots the value of congestion window against time.Theslope of the congestion window indicates the rate at which data is being transmitted.In the slow start phase-cwnd increases exponentially;in congestion avoidance-cwnd in-creases linearly subject to a maximum of2*mss per round trip time.4.2Sorting traf?c?leNetwork smiulator can do a lot of process on data events when it happens at the network.The one thing is to analyze the data result that is to extract relevant information from traces and to manipulate them.There are two ways you can handle these traces?les.An example of a line in the ouput trace iss2.0000000000AGT—0tcp40[0000]——-[0:04:0 320][00]00The?rst?eld is a letter that can have the values r,s,f,dfor”received”,”sent”,”forwarded”and”dropped”, respectively.It can also be M for giving a location or a movement indication was shown before.The second?eld i s the time.The third?eld is the node number.The fourth?eld is MAC to indicate if the packet con-cerns a MAC layer,it is AGT to indicate a transport layer(e.g.tcppacket,or RTR if it concerns the routed packet.It can also be IFQ to indicate events related to the interference priority queue(like drop of packets.After the dahses come the global sequence number of the packet(this is not the tcp sequence number.At the next?eld comes more information on the packet type(e.g.tcp,ack or udp.Then comes the p acket size in bytes.The4numbers in the?rst square barkets concern mac layer information.The?rst hexadecimal number0 which speci?es the expected time in seconds to send this data packet over the wireless channel.The second number0,stands for the MAC-id of the sending node and the tird,0,is that of the receiveing node.The last 0,is the MAC type.The next numbers in the second square brackets con-cern the IP source and destination addresses.The third brackets concern the tcp information:its se-quence number and acknowledgement number.There are other formats shown in the tra?c?le out.tr likethis:M0.000000(1.00,1.00,0.00,(200.00,200.00,30.00 where the?rst number is the moving time,the second is the node number,then comes the origin and destination loca-tions,and last one is given the speed.[?]To purify data that we need,Perl language help in the TCL?le can automatically generate the graph,but too many command lines write into the TCL?le will cause thebu?overloaded.To address this problem,we may write Perl into other?les and executed commands by manually typing when we need to research these data.Because”out.tr”?le track all tra?c of nodes including ACK,AGT,MAC and soon,we must sort two TCPs through-put data out.In this case,the data are received by node E(node4from transport layer belong a TCP connection, while another data are received by node B(node1transfer-ring on the network,which is second TCPconnection.grep”r”./tra?c/out.tr|grep”tcp”|grep ”4”|grep”AGT”>./tra?c/tcp1.tr&grep”r”./tra?c/out.tr|grep”tcp”|grep”1”|grep”AGT”>./tra?c/tcp2.tr&4.3Average throughputAfter sorting data,it is going to calculate average through-put.A parameter as granularity where we compute how many bytes were transmitted during time interval speci?ed.In this case,all nodes must stop at50seconds.perl./perl/AvgTp.pl./tra?c/tcp1.tr50&perl./perl/AvgTp.pl./tra?c/tcp2.tr50&Figure4:Average throughputFigure4shows on the TCP1connection,the total through-put is373180bytes which start at2second and end at17.7 second so the average throughput is373180/(17.7-2=23769 bytes/second.TCP2connection start running a bitlaterFigure5:Average throughputand stop earlier than TCP1connection.So the total through-put is345620and average throughput during17.6seconds is22076bytes/second.4.4Instantaneous throughputTo record two TCPs Instantaneous throughput into the ?les,and every0.1is a small time interval for instantaneousthroughput.perl./perl/tcp1InsTp.pl./tra?c/tcp1.tr0.1 &perl./perl/tcp2InsTp.pl./tra?c/tcp2.tr0.1& Plotting two TCPs Instantaneous throughput.plot’./tra?c/tcp1Ins.tr’t”TCP1inst”w lines 1,’./tra?c/tcp2Ins.tr’t”TCP2inst”w li nes2as the life of patients.Wireless Ad-hoc netowrk operate in hospital,which has a centralized supporting structure like an access point assist other wireless device in orderto keep connected with the wireless system from one place to the other.Hospital mobile server,that is the aim of being salvage. When a dying patient sent into the hospital,doctor in charge of a case and assistant medical director s can immediately know the ?rst information of patient before doing operation and they can read the state of illness at real time. However,traditional hospital information system that built in wired network for providing basic server is adapt for some settled position like pharmacal apartment,rest apartment and so on,which wired network has more secure,more bandwidth and more reliable than wireless Ad-hoc network. Therefore, building a wireless network combine working with wired network from a traditional hospital is really necessary. Figure 6: Two TCPs Instantaneous throughput In Figure6,we present both instantaneous throughput of TCP connection during every 0.1 second.On TCP1, traf?c start 3.5 second and ituctuantes dramatically in every second.There are 5 times tra?c reach 50000 bytes respectively at 5 second,9 second,14 second, 15 second and 17.5 second.However,thetra?c go trhoughput TCP2 connection which quite di?erence from TCP1 connection, where start tra?c at 5 second,and most oftra?c has instantaneous throughput with 30000 bytes or 40000 bytes, although there are tra?c reach 50000 bytes for 3 times at 9 second, 15 second and 16 second.The reason of both TCP connections have large tra?c around at 5 second, 9 second and 15 second is that in 5 second,both nodes of a connection reach at the range of middle node D when they are moving, after that in 9 second, all nodes accumulate together and ?nally all nodes are going out of range of node D in 15 second.7. ACKNOWLEDGMENTS I would like to thank Dr. ZhongWei,Zhang for his help in studying TCL and Perl language. APPENDIX A. A.1 A.2 A.3 A.3.1 A.3.2 A.3.3 A.3.4 A.3.5 A.3.6 HEADINGS IN APPENDICES Introduction Blue point Network simulation Layer con?guration Nodes con?guration Antennas,Network interface Netwo rk Topology TCP connection Nodes’Movement 5. LIMITATIONS After the data analyse, the design of hospital mobile server can be come true, but there are some limitations for wireless ad-hoc network. ? Limitation of throughput The total throughput is limited c ause more server join in and more bandwidth consume. ? Interference Interference always is a mainproblem of wireless network.Without cable contained,a signal discover to impact with another signal,especially for hospital where have many electronic devices. ? Lack of security Between node and node,there are traf?cs go through by wireless tunnel.Thosetra?cs are easier be listening and attacking,and ?nally it causes whole network unreliable.A.4 A.4.1 A.4.2 A.4.3 A.4.4 Data Analysis Congestion Window Size So rting traf?c ?le Average throughput Instantaneous throughput A.5 A.6 A.7 A.8 Limitations ConclusionAcknowledgments References 6. CONCLUSION In a conclusion, we already researched some contents are given a bird’s eye view of wireless Ad-hoc network based on the Network simulator. The Network exists to help in medical care system related to the historical evolution of hospitals until the present day by providing.A wireless network is a great way to save time in working hospital,actually。

网络仿真软件介绍

网络仿真软件介绍
仿真环境
1、Matlab
2、SPW 3、NS2/NS3
4、OPNET
5、主流网络仿真软件比较
主流网络仿真软件简介
MATLAB
MATLAB 是英文 MATrix LABoratory(矩阵实验室)的缩写。MATLAB 软件是由美国
Mathworks 公司推出的用于数值计算和图形处理的科学计算系统环境。MATLAB 环 境下,用户集成了程序设计、数值计算、图形绘制、输入输出、文件管理、网络仿 真、人工智能/神经网络、 工业控制等各个领域的研究功能。 MATLAB 提供了一个人机交互的系统环境,该系统的基本数据结构是矩阵,在生成 矩陈对象时,不要求作明确的维数说明。与利用 C语言或FORTRAN语言作数值计 算的程序设计相比,利用MATLAB可以节省大量的编程时间。
主流网络仿真软件简介
SPW/SPD
SPW(Signal Processing Worksystem)仿真软件是 CoWare Inc.公
司的产品,现已改名为SPD (Signal Processing Designer)
它提供了面向电子系统的模块化设计、仿真及实施环境,是进行算
法开发,滤波器设计,C 代码生成,硬/软件结构联合设计和硬件 综合的理想环境。 SPW的一个显著特点是他提供了HDS ( Hardware Design System ) 接口和MATLAB接口。MATLAB里面的很多模型可以直接调入 SPW,然后利用 HDS 生成 C 语言仿真代码或者是 HDL(Hardware Description Language) 语言仿真代码。 SPW 通常可以应用于无线和有线载波通信、多媒体和网络设计与 分析等领域。
OPNET标准模型库

基于NS2的移动自组网路由协议的仿真与实现.

基于NS2的移动自组网路由协议的仿真与实现.

2007,43(6Computer Engineering and Applications计算机工程与应用1引言移动自组网具有完全自组的运行方式和灵活的网络结构,可以真正地实现任何时间任何地点的网络互联通信,是一种无中心的网络,网络的带宽有限,而且网络拓扑动态变化的网络,这些特点决定了移动自组网在现实中应用的关键问题取决于路由问题的解决;而在真实的网络中,设计和调试网络协议是一件困难和复杂的事情,仿真成了最佳可供选择的测试、评估和验证手段之一,这不仅适用于网络模型的构造和设计、协议性能的评价与分析,还适用于网络协议的开发与研究以及真实网络的故障诊断。

网络模拟器NS2(Network Simulator v2是一种免费、源代码公开的模拟软件平台,其协议代码与真实网络应用代码很相似,仿真结果具有可靠性。

NS2是一个面向对象的离散事件驱动的网络模拟器,支持多个流行的网络协议如TCP、UDP和路由调度、拥塞控制算法等[1];相对于一般的离散型模拟器,NS2的优势在于它有非常丰富的构件库,而且这些对象易于组合,易于拓展,但是对用户的编程能力,实际网络协议的理解能力要求较高[2]。

在本文中,利用NS2已有的对象,组合所要研究的网络系统模型,在NS2中添加移动自组网中一个单播路由协议后进行网络仿真。

2NS2的仿真原理和拓展方法2.1NS2的仿真原理NS2采用编译和解释双层结构,编译层由C++类组成,C++语言执行速度快而修改和编译速度慢,故只用于编译层协议细节的实现;前端是一个OTCL(Object Tool Command Language解释器,OTCL修改快且可用于交互操作,用于解释层中仿真对象的设置,这种分裂对象仿真增强了构件库的可扩展性和可组合性[3]。

仿真器内核定义了有层次的编译类结构;在OTCL解释器中有相似的解释类结构。

用户通过解释器创立新的仿真对象之后,解释器对它进行初始化,与编译类结构中相应的对象建立映射。

多接口无线mesh网地NS2仿真

多接口无线mesh网地NS2仿真

word编号:审定成绩:某某邮电大学毕业设计〔论文〕设计〔论文〕题目:多接口无线mesh网的NS2仿真学院名称:通信与信息工程学院学生姓名:专业:电子信息工程班级:学号:指导教师:辩论组负责人:填表时间:年月某某邮电大学教务处制摘要IEEE802.11标准定义了在2.4GHz和5GHz频段内多个不重叠的物理层信道。

然而,现在大多数的无线网状网是在一个单一的信道下配置的,以确保所有的节点相连接。

因此,无线频段所提供的频谱并没有被充分利用。

为了满足高吞吐量的需求,必须利用一切可用的资源。

NS2(Network Simulator v2)是一款开放源代码的网络模拟软件,由于任何人可以获得、使用和修改其源代码,因而成为目前主流的网络仿真软件。

目前,NS2中的无线通信模型只支持单信道的仿真,并不支持无线网络的多信道仿真。

所以为了进展无线网络的多信道协议仿真,必须扩展NS2。

本文首先介绍了无线网状网络和仿真工具NS2,论述了现有的几种基于NS2的多信道扩展方法。

根据相关文献,在NS2中添加多信道多接口支持,使之支持多接口多信道以与接口转换。

为了证明多接口技术的优势,我们在NS2中对无线网状网络进展仿真,仿真结果证明了在提高网络容量方面的有效性,利用每个无线节点的多接口,可以提高无线网络的吞吐量。

【关键词】无线网状网 NS2 多信道多接口吞吐量ABSTRACTIEEE802.11 standard defines more than 2.4GHz and 5GHz frequency band not overlapping the physical layer channel. Now, however, most of the wireless mesh network is a single channel configuration, to ensure that all the nodes connected. Therefore,the wireless frequency band the total bandwidth available has not been fully utilized. To meet the demand for high-throughput, we must use all available bandwidth. In previous studies a number of remendations, through the interference-free transmission of multiple simultaneous use of multi-channel, multi-interface to increase network capacity.NS2(Network Simulator v2) is an open source software of network simulation, because anyone can get use and modify its source code, it has been became the mainstream of network simulation software, But MAC does not support multi-channel simulation NS2, NS2 in the wireless munication model supportsonly single channel simulation. Therefore, in order to facilitate the conduct of multi-channel wireless network, MAC protocol simulation, we must expand NS2.This paper introduces wireless mesh network and NS2, discusses several existing multi-channel protocol simulation of different development methods of NS2.According to research, we add multi-channel multi-interface support in NS2, so that multi-channel multi-interface, and interface conversion. In order to prove that the proposed conversion algorithm and multi-channel multi-interface, interface technology advantages, we simulation of wireless mesh networks in the NS2, Simulation results show the increased network capacity in terms of effectiveness, use of each wireless node, multi-channel multi-interface, can greatly improve the throughput of wireless networks.【Key words】Wireless mesh networksNS2 Multi-ChannelMulti-InterfaceThroughput capacity目录前言 (1)第一章无线网状网 (1)第一节无线网状网概述1第二节无线网状网的结构2一、根底设施的网状网结构3二、客户机结构4三、混合式结构5第三节无线网状网的优势5第四节本章小结7第二章多信道多接口解决方案 (7)第一节相关研究9第二节方案简介10一、HMCP协议11二、AODV协议13第三节本章小结15第三章NS2与无线网络仿真 (16)第一节NS2根本原理16一、NS2简介16二、NS2移动节点模型17三、根本工作流程19第二节NS2多信道扩展现状19一、TENS19二、Hyacinth20三、Ramon20四、MMSM21五、研究现状小结23第三节扩展NS2错误!未定义书签。

[课件]NS2网络模拟简介以及MTE、LEACH、LEACH-C协议仿真PPT

[课件]NS2网络模拟简介以及MTE、LEACH、LEACH-C协议仿真PPT

NS2的总体系结构


NS2的目录结构
ns-2.34:存放C++代码的地方; ns-2.34\tcl:存放OTcl代码的地方; Ns-2.34\tcl\lib:存放与组件(agent, node, link, packet, address, routing ) 实现有关的OTcl代码;在此目录下,有以下几个文件:ns-lib.tcl: Simulator 类定义与成员函数实现,如 run,simplexlink,flush-trace等;ns-default.tcl :各种网络组件配置的缺省值。 ns-2.34\tcl\ex, ns-2.34\tcl\test: 存放一些例子脚本文件和验证结果。

NS2的部分类结构


分类器——classifier是Ns-2基本网络组件的一个大类。 它的基本派生类有地址分类器(AddrClassifier)和多播 分类器(McastClassifier)等。基于分类器的基本网络 组件具有1个或多个可能的数据输出路径,属于交换 (Switch)设备(对应来说,连接器Connector只有一个 数据的输出路径)。 拓扑结点(Node)是由一个结点入口对象和若干个分类 器(Classifier)组成的一个符合对象。
节点存活率

节点能量消耗

数据包发送量
仿真后生成 x.data,x.alive,x.energy等文件(x对应的为协 议名称),分别对应的为各个协议的数据包传送个数, 节点生存情况和节点能量消耗,用awk语言编写程序, 提取数据进行分析 在Cygwin中用gnuplot 作出分析结果曲线


节点分布拓扑图(基站位置(0,0))

LEACH模型

NS2仿真实验分析报告

NS2仿真实验分析报告

NS2仿真实验分析报告一引言1 NS2简介NS2是一款开放源代码的网络模拟软件,最初由UC Berkeley开发。

它是一种向象的网络模拟器,它本质上是一个离散事件模拟器,其本身有一个模拟时钟,所有的模拟都由离散事件驱动。

其采用了分裂对象模型的开发机制,采用C++和OTcl两种语言进行开发。

它们之间采用Tclcl 进行自动连接和映射。

考虑效率和操作便利等因素,NS2将数据通道和控制通道的实现相分离。

为了减少分组和事件的处理时间,事件调度器和数据通道上的基本网络组件对象都使用C++编写,这些对象通过Tclcl映射对OTcl解释器可见。

目前NS2可以用于模拟各种不同的通信网络,它功能强大,模块丰富,已经实现的主要模块有:网络传输协议,如TCP和UDP;业务源流量产生器,如FTP、Telnet、CBR、We b和VBR;路由队列管理机制,如DropTail、RED和CBQ;路由算法;以及无线网络WLAN、移动IP和卫星通信网络等模块,也为进行局域网的模拟实现了多播协议以及一些MAC子层协议。

2 基本概念(1)RED:随机早期探测(Random Early Detect,RED)。

RED属于主动队列管(Active Queue Management, AQW),是目前常见的TCP上防止拥塞的手段。

它通过以一定概率丢失或标记报文来通知端系统网络的拥塞情况。

RED使用平均队列长度度量网络的拥塞程度,然后以线性方式将拥塞信息反馈给端系统。

RED使用最小阈值,最大阈值和最大概率等几个参数。

RED的基本思想是通过监控路由器输出端口队列的平均长度来探测拥塞,一旦发现拥塞逼近,就随机地选择连接来通知拥塞,使它们在队列溢出导致丢包之前减少拥塞窗口,降低发送数据速度,缓解网络拥塞。

RED配置在路由器监视网络流量以便避免拥塞,当拥塞即将发生时,它随机丢弃进来的分组,而不是等到队列缓冲区满是才开始丢弃所有进来的分组,这样可以最少化全局同步的发生。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

例:UDP上的CBR
#Setup a UDP connection set udp [new Agent/UDP] $ns attach-agent $n1 $udp set null [new Agent/Null] $ns attach-agent $n5 $null $ns connect $udp $null $udp set fid_ 2 #Setup a CBR over UDP connection set cbr [new Application/Traffic/CBR] $cbr attach-agent $udp $cbr set packetSize_ 1000 $cbr set rate_ 0.01Mb $cbr set random_ false
另一个例子
第三步:建立代理和应用
set tcp1 [new Agent/TCP] set sink1 [new Agent/TCPSink] $ns_ attach-agent $n0 $tcp1 $ns_ attach-agent $n3 $sink1 $ns_ connect $tcp1 $sink1
• • • • • • • • • • • • • • #=================================== # Links Definition #=================================== #Createlinks between nodes $ns duplex-link $n0 $n2 2.0Mb 10ms DropTail $ns queue-limit $n0 $n2 10 $ns duplex-link $n1 $n2 2.0Mb 10ms DropTail $ns queue-limit $n1 $n2 10 $ns duplex-link $n3 $n4 2.0Mb 10ms DropTail $ns queue-limit $n3 $n4 10 $ns duplex-link $n3 $n5 2.0Mb 10ms DropTail $ns queue-limit $n3 $n5 10 $ns duplex-link $n2 $n3 1.0Mb 10ms DropTail $ns queue-limit $n2 $n3 10
另一个例子
第一步:准备开始
set ns_ [new Simulator] set tracefile [open out.tr w] set namtracefile [open out.nam w] $ns_ trace-all $tracefile $ns_ namtrace-all $namtracefile proc finish {} { global ns_ tracefile namtracefile $ns_ flush-trace close $tracefile close $namtracefile exec nam out.nam & exit 0 }
网络节点和链路
• 下图给出了单向链路的形式。队列溢出通过将丢弃的包发送到Null代理 来实现。对象TTL计算每个到达包的TTL参数。双向链路由两条并行单向 链路构成。
单向链路结构
代理和应用
• • • • • • • • • • • #======================= # Agents Definition #======================= #Setup a UDP connection set udp0 [new Agent/UDP] $ns attach-agent $n0 $udp0 set null2 [new Agent/Null] $ns attach-agent $n4 $null2 $ns connect $udp0 $null2 $udp0 set packetSize_ 1500 $udp0 set fid_ 1 • • • • • • • • • • • #========================== # Applications Definition #========================== #Setup a CBR Application over UDP connection set cbr0 [new Application/Traffic/CBR] $cbr0 attach-agent $udp0 $cbr0 set packetSize_ 1500 $cbr0 set rate_ 1.0Mb $cbr0 set random_ null $ns at 1.0 "$cbr0 start" $ns at 4.0 "$cbr0 stop"
NS2 与网络仿真
Part3 – NS2仿真入门 fzhh@
NS2仿真入门
• • • • • • • • 从例子开始 网络节点与链路 代理与应用 事件调度 另一个例子 NAM可视化工具 Trace文件 AWK工具
从例子开始
网络节点和链路
• • • • • • • • • • #=================================== # Nodes Definition #=================================== #Create 6 nodes set n0 [$ns node] set n1 [$ns node] set n2 [$ns node] set n3 [$ns node] set n4 [$ns node] set n5 [$ns node]
代理和应用
• 代理和应用(Agent/Application) 代理(Agent):即协议,如TCP,UDP 应用(Application):如FTP,CBR 流量(traffic):由源节点、目的结点、代理、应用构成的总 称。 • 定义TCP代理:set tcp [new Agent/TCP] set sink [new Agent/TCPSink] 定义UDP代理: set udp [new Agent/UDP] set null [new Agent/Null]
网络节点和链路
• 定义一个结点的方法为:set n0 [$ns node]
这将产生一个ns结点,并由变量n0获得指针,因此后面就能使用$n0来 访问该结点。 当创建了多个结点以后,用户就能定义他们之间的链路。 set n1 [$ns node] set n2 [$ns node] …
网络节点和链路
另一个例子
描述:这个网络包含4个结点 (n0,n1,n2.n3)。 n0和n2、n1和n2之间是2Mbps带宽、 10ms延迟的双工链路。 n2和n3之间是1.7Mbps带宽、20ms延迟 的双工链路。每个链路都使用DropTail 队列,最大包数量为10。 一个“TCP”代理被绑定到n0,“TCP”接 收器绑定到n3,并在这两个结点之间 建立连接。缺省情况下,一个“TCP” 代理产生的数据包最大尺寸为1KB。 “TCP”接收器给主叫方发送ACK包和释 放收到的包。 一个“UDP”代理被绑定到n1,“null” 代理被绑定到n3,并在这两个结点之 间建立连接。 一个“ftp”和一个“cbr”应用程序(流 量发生器)分别被绑定到“TCP”和 “UDP”代理。“cbr”通过配置能产生 1KB大小数据包,速率为1Mbps。 “cbr”预设在0.1s开始,在4.5s结束。 “ftp”预设在1.0s开始,在4.0s结束。

事件调度
• 事件调度:在指定时间安排指定的事件. 格式:$ns at “…”,如 $ns at 1.0 "$cbr0 start" $ns at 4.0 "$cbr0 stop“ $ns at 2.0 "$cbr1 start" $ns at 3.0 "$cbr1 stop"
代理和应用
例: TCP上的FTP • • • • • • • • • • • #Setup a TCP connection set tcp [new Agent/TCP] $ns attach-agent $n0 $tcp set sink [new Agent/TCPSink] $ns attach-agent $n4 $sink $ns connect $tcp $sink $tcp set fid_ 1 $tcp set packetion set ftp [new Application/FTP] $ftp attach-agent $tcp
网络节点和链路
定义链路:
$ns duplex-link $n0 $n2 2.0Mb 10ms DropTail
• 这条语句说明在结点n0和n2之间创建一条双向链路,该链路10ms的延迟, 并且单向具有2Mb/s的容量。 • 若要定义单向链路,只需将“duplex-link”替换成“simplex-link”。 • 在NS中,结点的输出队列作为链路的一部分,因此,链路定义还需要包 含对队列溢出的处理。在上面的例子中,假如输出队列发生溢出时,则 最后一个到达的包将被丢掉(DropTail 机制)。 • 定义每条链路的队列容量(缺省值50:ns-default.tcl)。比如: #Set Queue Size of link (n0-n2) to 10 $ns queue-limit $n0 $n2 10 注:缺省值50,文件ns-default.tcl中 Queue set limit_ 50
NAM可视化工具
• NAM工具:图形化场景排列和重放仿真过程 • 例:ns example.tcl ->out.tr, out.nam
NAM可视化工具
• 中间结果
NAM可视化工具
• NAM能做的事情还有以下几点: • 1. 对结点指定颜色,比如指定结点n0为红色: $n0 color red • 2. 指定结点形状,缺省情况下是圆形。若指定其它形状可键入命令“$n1 shape box”,其中“box”还可为“hexagon”、 “circle” • 3. 指定链路颜色,比如 $ns duplex-link-op $n0 $n2 color "green“ • 4. 添加标签(label)。比如给结点3从1.2秒起添加标签“active node”,可 以使用下面的语句 $ns at 1.2 "$n3 label \"active node\"" 要给链路n0-n2添加标签,可以使用下面的语句: $ns duplex-link-op $n0 $n2 label "TCP input link" ……
相关文档
最新文档