网络分析与测试实验2_使用NS2模拟有线网络
- 格式:doc
- 大小:155.00 KB
- 文档页数:9
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的TCP协议代码,来简单的观察窗口阈值的不同算法对网络资源利用率的影响。
实验步骤:1. 实验环境搭建(1)系统环境:虚拟机:virtrulbox;操作系统:linux/ubuntu 10.04工作目录:/home/wangtao/workspace/(2)NS2安装与使用:下载NS2软件包到工作目录,地址/sourceforge/nsnam/ns-allinone-2.33.tar.gz解压(注:以下斜体字为命令行命令)tar -zxf ns-allinone-2.33.tar.gzcd ns-allinone-2.33./install(中间的两个bug已经修改,此处忽略)耐心等待安装完毕后将出现如下画面说明安装正常:接下来是系统环境配置,重新进入终端cd ~vim .bashrc(如果没有安装vim最好安装一下,sudo apt-get install vim)在打开的.bashrc的末尾加上以下内容:PATH="$PATH:/home/wangtao/worksapce/ns-allinone-2.33/bin:/home/wangtao/worksapce/ns-a llinone-2.33/tcl8.4.18/unix"exportLD_LIBRARY_PATH="$LD_LIBRARY_PAHT:/home/wangtao/worksapce/ns-allinone-2.33/otcl-1.13,/ home/wangtao/worksapce/ns-allinone-2.33/lib"exportTCL_LIBRARY="$TCL_LIBRARY:/home/wangtao/worksapce/ns-allinone-2.33/tcl8.4.18/library"保存并退出,重新进入终端安装xgraphsudo apt-get install xgraph运行一个简单的例子,以证明环境安装完成:ns /home/wangtao/workspace/ ns-allinone-2.33/tcl/ex/simple.tcl出现如下图说明成功:2.修改代码vim /home/wangtao/workspace/ns-allinone-2.33/tcp/(将窗口阈值一半变为的窗口阈值1/3——wt_)第一处:……if (cwnd_ < ssthresh_)slowstart = 1;if (precision_reduce_) {//halfwin = windowd() / 2; //wangtaohalfwin = windowd() / 3;第二处:……} else {int temp;//temp = (int)(window() / 2);//wangtaotemp = (int)(window() / 3);halfwin = (double) temp;……第三处:……switch (how) {case 0:/* timeouts *///ssthresh_ = int( window() / 2 );//wangtaossthresh_ = int( window() / 3 );if (ssthresh_ < 2)ssthresh_ = 2;cwnd_ = int(wnd_restart_);break;case 1:……第四处……case 4:/* Tahoe dup acks *///ssthresh_ = int( window() / 2 );//wangtaossthresh_ = int( window() / 3 );if (ssthresh_ < 2)ssthresh_ = 2;cwnd_ = 1;break;default:abort();……3.编写tcl代码,实现一个简单的3节点,2条链路的网络网络如下图,具体代码见附件中的源代码。
网络模拟器NS-2及其应用分析本例将介绍如何使用一些工具来分析和呈现模拟结果,主要是测量端到端的延迟,而采用的方法一是去分析Trace文件,方法二是去修改NS核心,把所需要测量的数据直接记录下来,限于篇幅我们不在此进一步介绍方法二。
模拟场景如图4所示,包含四个节点(n0,n1,n2,n3),假设n0,n2和n1,n2之间链路带宽2Mbps,延迟为10ms;n2和n3之间链路带宽1.7Mbps,延迟为20ms;每个链路用DropT ail策略;n2和n3之间链路最大队列长度为10;n0,n3之间有一条建立在TCP上的FTP连接,n1,n3之间有一条建立在UDP上CBR连接;CBR是在0.1秒开始发送,在4.5秒结束,FTP是在1.0秒开始发送,在4.0秒结束。
图4 模拟场景3.1 建立Otcl模拟代码文件#创建一个模拟对象set ns [new Simulator]#为数据流定义不同的颜色,供NAM用$ns color 1 Blue$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-trace#关闭NAM trace fileclose $nfclose $nd#以后台方式执行NAMexec nam out.nam &exit 0}#创建四个节点set n0 [$ns node]set n1 [$ns node]set n2 [$ns node]set n3 [$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 #设定n2和n3之间最大队列长度为10$ns queue-limit $n2 $n3 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#设定n2-n3间的队列位置,供NAM用$ns duplex-link-op $n2 $n3 queuePos 0.5#建立一条TCP连接set tcp [new Agent/TCP]$tcp set class_ 2$ns attach-agent $n0 $tcpset sink [new Agent/TCPSink]$ns attach-agent $n3 $sink$ns connect $tcp $sink#在NAM中,TCP的连接以蓝色表示$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"#在5.0秒调用finish过程结束模拟$ns at 5.0 "finish"#执行模拟$ns run本例子在FedoraCore4,ns-2.29下测试通过,模拟结束后,产生两个文件,一个是out.na m,这是供NAM用的,用来可视化整个模拟过程;另一个是out.tr,记录了模拟过程中数据包传送中的所有事件,这是我们分析的重点。
ns2的基本功能和用法。
NS2是一款广泛使用的离散事件网络仿真器,它可以用来模拟网络协议、网络拓扑结构、传输层协议等各种网络方面的问题。
在本文中,我们将会详细介绍NS2的基本功能和用法,让您了解如何使用这个强大的工具来开展网络仿真和探索。
第一部分:NS2的简介NS2全称Network Simulator 2,是一款免费且开源的网络仿真平台,它可以运行于Linux和Windows操作系统。
NS2是C++编写的,它是由一个模块化的体系结构构建而成的。
NS2可以帮助你模拟和测试各种网络协议和技术,包括但不限于TCP/IP、WiFi、无线通信、移动通信、卫星通信等。
NS2的基本组成部分包括:- OTcl:OTcl是一个面向对象的Tcl解释器,它被用来编写NS2的脚本文件。
它可以帮助您表示仿真模型以及控制仿真场景和参数。
- C++代码:NS2的模拟核心是由C++编写的,它包含了底层的网络协议处理逻辑和数据结构。
- Trace:NS2的Trace模块可以记录仿真过程中所有的事件和消息交换。
我们可以通过Trace来分析仿真结果,并对仿真场景进行可视化。
总结NS2是一个开源且强大的网络仿真器,它的核心部分是由C++编写而成的。
NS2可以帮助您模拟和测试各种网络协议和技术,并提供一个强大的OTcl 脚本语言来控制和配置仿真模型。
第二部分:NS2的基本功能NS2提供了很多强大的功能,如下所示:1. 拓扑结构模拟NS2可以帮助我们模拟各种网络拓扑结构,例如星型、树形结构、层次结构等。
通过定义节点、连接和协议,我们可以很容易地构建复杂的拓扑结构,并进行仿真和测试。
2. 参数设置和控制通过OTcl脚本,我们可以轻松地配置和控制仿真模型。
我们可以设置各种参数,例如发送速率、仿真持续时间、节点位置等等。
此外,我们还可以通过设置事件触发器来控制仿真场景的流程。
3. 模拟协议NS2可以帮助我们模拟各种协议,例如TCP、UDP、ICMP等。
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。
NS2仿真与网络实验教学陈建锐【摘要】针对计算机网络实验教学存在的问题,介绍了目前应用较为广泛的网络仿真器NS2的工作原理和特点.探讨了NS2在网络教学中的应用,提出了将网络仿真工具NS2应用于网络课程教学和实验的方法,有利于学生更加直观地理解网络协议的实现原理,提高网络教学的效果,并给出了应用实例.【期刊名称】《实验科学与技术》【年(卷),期】2010(008)002【总页数】3页(P75-77)【关键词】NS2软件;网络仿真;实验教学【作者】陈建锐【作者单位】湛江师范学院实验教学管理处,广东,湛江,524048【正文语种】中文【中图分类】TP391.9;G642.423计算机网络是一门理论与应用紧密结合的课程。
计算机网络原理涉及很多协议、算法以及一些特殊的网络环境,这些内容在传统的实验环境下很难模拟或成本太高。
目前在机房的单机环境下很多网络原理、网络应用的实验由于实验条件的限制无法开展。
仿真技术为我们解决上述问题提供了一种很好的方法,使得利用有限的实验设备开展以前无法开展的实验成为可能。
例如在NS2下可以进行网络协议的演示、建立移动网络仿真环境、测试网络协议的性能、模拟网络流量的传输,而不必担心对实验室原有计算机系统的影响。
不仅如此,NS2软件所具备的独特的管理机制还可使实验教师轻而易举地完成实验系统的维护,促进计算机实验教学方式的改进与创新。
鉴于计算机网络实验教学的需要以及NS2软件的特殊功能及优点,构建一个虚拟计算机网络实验环境进行实验教学具有重要意义。
NS-Network Simulator是一个面向网络的离散事件模拟器。
是一个面向对象的、可扩展的、易配置的、可编程的事件驱动仿真引擎,由LBNL (Lawrence BerkeleyNational Laboratory)的网络研究组研制开发,是DARPA支持的V I NT项目的核心部分。
NS功能强大,能够仿真有线和无线网(本地和卫星网),局域网和广域网,并支持多种协议如传输层的TCP、UDP协议,应用层的FTP、Telnet、Web协议,支持Droptail、RED等几种路由器队列管理机制以及Dijkstra、动态路由、静态路由、组播路由等路由算法。
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配置在路由器监视网络流量以便避免拥塞,当拥塞即将发生时,它随机丢弃进来的分组,而不是等到队列缓冲区满是才开始丢弃所有进来的分组,这样可以最少化全局同步的发生。
基于NS-2的有线网络仿真
白云;孟克其劳;韩建峰;任治刚;辛莉
【期刊名称】《铁路计算机应用》
【年(卷),期】2009(018)002
【摘要】目前,比较流行的通用仿真工具主要有NS-2和OPNET等.介绍了一款可用于有线网络仿真的免费软件NS-2,分析了该软件的构成和软件特性,重点讨论如何使用NS-2软件进行网络仿真,并给出了具体实例.
【总页数】4页(P22-25)
【作者】白云;孟克其劳;韩建峰;任治刚;辛莉
【作者单位】内蒙古工业大学,信息工程学院,呼和浩特010051;内蒙古工业大学,信息工程学院,呼和浩特010051;内蒙古工业大学,信息工程学院,呼和浩特010051;内蒙古工业大学,信息工程学院,呼和浩特010051;内蒙古工业大学,信息工程学院,呼和浩特010051
【正文语种】中文
【中图分类】TP393
【相关文献】
1.基于NS-2的无线自组织网络仿真实验设计 [J], 蔡虔
2.基于NS-2的卫星网络仿真方法的研究 [J], 叶晓国;肖甫;孙力娟;王汝传
3.基于NS-2的无线传感器网络仿真模块扩展方法的研究 [J], 叶晓国
4.基于NS-2网络仿真协议的功能扩展 [J], 永华;刘广钟
5.基于NS-2的无线网络仿真分析与研究 [J], 罗薇; 罗娟; 彭兵
因版权原因,仅展示原文概要,查看原文内容请购买。
本文部分内容来自网络整理,本司不为其真实性负责,如有异议或侵权请及时联系,本司将立即删除!== 本文为word格式,下载后可方便编辑和修改! ==NS2与网络模拟学习总结报告HUNAN CITY UNIVERSITYNS2与网络模拟学习总结报告专业:网络工程学生姓名:班级学号:201X年 11月 5日1. 所学章节重点内容概要第一章:NS2简介一.NS2(Network Simulator - Version2)1.由C++和OTcl编写2.面向对象的,事件驱动的网络模拟器。
? UC Berkeley设计? 多用于多播和MAC层协议仿真? :NS2安装? 在NS2是在Unix平台下运行的? NS2的使用? Windows平台1.需先安装Cygwin,模拟Unix环境2.安装虚拟机,在虚拟的Unix或Linux环境下安装NS2 ? :TCL语法? TCL简介1.TCL-”tickle”2.所有平台都支持3.NS2中主要描述网络环境和参数? TCL基本语法1.唯一数据类型:字符串2.字符串的三中形式(命令,表达式,列表)3.注释:#? :NS2语法? 建立在Tcl脚本语言之上? 拥有自己的库? Tcl脚本标准模板? 编写一个简单的Tcl脚本1.添加两个节点,一条连接2.传输数据? 简单网络拓扑结构和模拟实例? ~第九章:NS2结果分析? 跟踪文件Out.tr1.NS2执行过程中会自动产生一个跟踪文件2.记录数据包(分组)的传输情况? 动画演示工具NAM1.NAM基于Tcl/Tk的动画演示工具2.NAM进行演示3.基本命令格式4.NS2中NAM常用命令? 分析工具Awk1.Awk是一种程序语言,具有一般程序语言的常见功能2.Awk具备一些特殊的内在功能,使其擅长处理数据记录(Record),字段(Field)型的数据3.常用来处理和分析NS2的跟踪文件4.Awk在读入数据后会把每个记录的每个字段的值存入字段变量? 绘图工具Xgr aph,Gnuplot1.XGraph是NS2自带的简单绘图工具2.Gnuplot是一个命令行的交互式绘图工具? :模拟器(Simulator)? 类Simulator1.在\ns-2.33\tcl\lib\ns-lib.tcl和\ns-2.33\common\scheduler.{cc,h}2.提供模拟配置和事件调度方案3.初始化? 调度器和事件1.NS2是事件驱动(event-driven)模拟器2.NS2支持四种调度机制3.设置模拟调度的机制命令? 其他1.时钟精度2.常用命令? :节点和包(node and packet)? 类node和类packet。
课程:计算机网络项目:实验4 ns2 实验一、实验目的安装并运行网络仿真器NS2,了解其功能模块及配套工具的使用,掌握利用NS2进行网络仿真的方法,为进一步的网络系统性能分析设计创造良好的条件。
二、实验原理NS2(Network Simulator version 2,网络仿真软件第二版)是一种面向对象的网络仿真器,本质上是一个离散事件模拟器。
最早来源于1989年哥伦比亚大学开发的Real Network Simulator项目,是一款开源免费的网络模拟软件。
由加州大学伯克利分校(UC Berkeley)开发而成。
它本身有一个虚拟时钟,所有的仿真都由离散事件驱动的。
目前NS2 可用于仿真各种不同的通信网络。
已经实现的仿真模块有:网络传输协议,如TCP 和UDP;业务源流量产生器,如FTP、Telnet、Web CBR 和VBR;路由队列管理机制,如Droptai、RED和CBQ;路由算法,如Dijkstra,以及无线网络的WLAN,Ad hoc路由,移动IP 和卫星通信网络等。
NS2也为进行局域网的仿真而实现了多播以及一些MAC子层协议。
NS2使用C++和OTcl作为开发语言。
NS2可以说是OTcl的脚本解释器,它包含仿真事件调度器、网络组件对象库以及网络构建模型库等。
事件调度器用于计算仿真时间,并且激活事件队列中的当前事件,执行一些相关的事件,网络组件通过传递分组来相互通信,但这并不耗费仿真时间。
所有需要花费仿真时间来处理分组的网络组件都必须要使用事件调度器,它先为这个分组发出一个事件,然后等待这个事件被调度回来之后,才能做下一步的处理工作。
事件调度器的另一个用处就是计时。
由于效率的原因,NS2将数据通道和控制通道的实现相分离,为了减少分组和事件的处理时间,事件调度器和数据通道上的基本网络组件对象都使用C++写出并编译的,这些对象通过映射对OTcl解释器可见。
三、实验内容(1)安装ns-allinone-2.35(2)NS2仿真示例-nam方式四、实验结果与分析:建立一个OTcl脚本文件set ns [new Simulator] /建立对象$ns color 1 Blue /设定颜色$ns color 2 Redset nf [open out.nam w] /打开跟踪文件$ns namtrace-all $nfproc finish {} { /定义结束过程global ns nf$ns flush-traceclose $nfexec nam out.nam &exit 0}set ns0 [$ns node]set ns1 [$ns node]set ns2 [$ns node]set ns3 [$ns node]$ns duplex-link $ns0 $ns2 1Mb 10ms DropTail$ns duplex-link $ns1 $ns2 1Mb 10ms DropTail$ns duplex-link $ns3 $ns2 1Mb 10ms DropTail$ns duplex-link-op $ns0 $ns2 orient right-down$ns duplex-link-op $ns1 $ns2 orient right-up$ns duplex-link-op $ns2 $ns3 orient right$ns duplex-link-op $ns2 $ns3 queuePos 0.5set udp0 [new Agent/UDP] /建立代理UDP $udp0 set class_ 1$ns attach-agent $ns0 $udp0set cbr0 [new Application/Traffic/CBR]$cbr0 set packetSize_ 500$cbr0 set interval_ 0.005$cbr0 attach-agent $udp0set udp1 [new Agent/UDP]$udp1 set class_ 2$ns attach-agent $ns1 $udp1set cbr1 [new Application/Traffic/CBR]$cbr1 set packetSize_ 500$cbr1 set interval_ 0.005$cbr1 attach-agent $udp1set null0 [new Agent/Null] /建立代理NULL$ns attach-agent $ns3 $null0$ns connect $udp0 $null0$ns connect$udp1 $null0$ns at 0.5 "$cbr0 start" /传送数据$ns at 1.0 "$cbr1 start"$ns at 4.0 "$cbr1 stop"$ns at 4.5 "$cbr0 stop"$ns at 5.0 "finish" /调用结束过程$ns run /仿真结果如下:实验分析:系统从n0开始传送数据实验分析:系统从n1开始传送数据实验分析:采用FIFO机制丢包,丢弃n0发送的数据包(3)代码:set ns [new Simulator]set f0 [open out0.tr w]set f1 [open out1.tr w]set f2 [open out2.tr w]for { set i 0 } { $i<5 } {incr i} {set n$i [$ns node]}$ns duplex-link $n0 $n3 1Mb 100ms DropTail$ns duplex-link $n1 $n3 1Mb 100ms DropTail$ns duplex-link $n2 $n3 1Mb 100ms DropTail$ns duplex-link $n3 $n4 1Mb 100ms DropTailproc finish {} {global f0 f1 f2close $f0close $f1close $f2exec xgraph out0.tr out1.tr out2.tr -geometry 800x400 & exit 0}proc attach-expoo-traffic { node sink size burst idle rate } { set ns [Simulator instance]set source [new Agent/UDP]$ns attach-agent $node $sourceset traffic [new Application/Traffic/Exponential]$traffic set packetSize_ $size$traffic set burst_time_ $burst$traffic set idle_time_ $idle$traffic set rate_ $rate$traffic attach-agent $source$ns connect $source $sinkreturn $traffic}proc record {} {global sink0 sink1 sink2 f0 f1 f2set ns [Simulator instance]set time 0.5set bw0 [$sink0 set bytes_]set bw1 [$sink1 set bytes_]set bw2 [$sink2 set bytes_]set now [$ns now]puts $f0 "$now [expr $bw0/$time*8/1000000]"puts $f1 "$now [expr $bw1/$time*8/1000000]"puts $f2 "$now [expr $bw2/$time*8/1000000]"$sink0 set bytes_ 0$sink1 set bytes_ 0$sink2 set bytes_ 0$ns at [expr $now+$time] "record"}set sink0 [new Agent/LossMonitor]set sink1 [new Agent/LossMonitor]set sink2 [new Agent/LossMonitor]$ns attach-agent $n4 $sink0$ns attach-agent $n4 $sink1$ns attach-agent $n4 $sink2set source0 [attach-expoo-traffic $n0 $sink0 200 2s 1s 100k]set source1 [attach-expoo-traffic $n1 $sink1 200 2s 1s 200k]set source2 [attach-expoo-traffic $n2 $sink2 200 2s 1s 300k]$ns at 0.0 "record"$ns at 10.0 "$source0 start"$ns at 10.0 "$source1 start"$ns at 10.0 "$source2 start"$ns at 50.0 "$source0 stop"$ns at 50.0 "$source1 stop"$ns at 50.0 "$source2 stop"$ns at 60.0 "finish"$ns run结果如下:实验分析:三条数据流的峰值分别为0.1Mbit/s, 0.2Mbit/s,0.3Mbit/s五、实验总结在nam辅助分析工具中发现ftp1在零秒开始启动,ftp2在第三秒时刻开始启动,都在第十秒停止,这符合设计目标。
基于NS2的网络仿真与性能测试肖权权;段迅【摘要】互联网是一个庞大的、复杂的、开放的网络集合.深入了解和优化网络性能并不是一件容易的事.为了方便网络管理者对网络进行管理,探讨了NS-2仿真平台体系结构、构建环境和仿真流程,提出了采用NS2网络仿真器建立网络模拟场景来获得网络性能参数的方法,通过分析NS2网络仿真过程产生的记录文件,利用awk、gnuplot等工具获得网络的封包遗失率( Packet Loss Rate)、端到端的延迟(End-to-End Delay)、吞吐量(Throughput)等性能指标呈现了模拟结果.实验表明利用网络仿真求解网络性能参数具有直观可靠、成本低、灵活可靠、避重就轻、易于比较等优点.通过实例分析验证了该方法的有效性.%The Internet is ahuge,complicated and open network. Understanding and optimizing the network performance is not an easy task. In order to make easier for mangers to manage the network,discussed NS2 simulation platform architecture,environment and simulation process. Then, used the NS2 to simulation network scenarios to obtain the network perfomance parameters. Through the analysis of NS2 network simulation process to produce records,use the awk,gnuplot and other tools to obtain the network performance parameters. Experiments show that using NS2 to get network performance parameters has advantages,such asintuitive,reliable,low cost,flexible and reliable,easy to compare. From a example,testing and venfing this method is useful.【期刊名称】《计算机技术与发展》【年(卷),期】2012(022)004【总页数】4页(P25-28)【关键词】网络仿真;遗失率;延迟;吞吐量【作者】肖权权;段迅【作者单位】贵州大学计算机科学与信息学院,贵州贵阳550025;贵州大学计算机科学与信息学院,贵州贵阳550025【正文语种】中文【中图分类】TP390 引言随着Internet不断快速发展,网络研究人员经常需要对网络性能等方面进行研究或优化。
移动自组织网络实验报告NS2网络仿真实验何云瑞13120073电信研1301班1.实验目的和要求1.学会NS2的安装过程,并熟悉NS2的环境;2.观察并解释NAM动画,分析Trace文档。
3.学会用awk和gnuplot分析吞吐量、封包延迟、抖动率和封包丢失率。
2.实验环境先在PC上安装VMware虚拟机,再在虚拟机上安装Ubuntu系统,最后再Ubuntu系统上安装NS2软件,本次实验采用的是NS-2.34版本。
3.基本概念3.1 NS2简介NS2是一款开放源代码的网络模拟软件,最初由UC Berkeley开发。
它是一种面向对象的网络模拟器,它本质上是一个离散事件模拟器,其本身有一个模拟时钟,所有的模拟都由离散事件驱动。
其采用了分裂对象模型的开发机制,采用C++和OTcl两种语言进行开发。
它们之间采用TclCL进行自动连接和映射。
考虑效率和操作便利等因素,NS2将数据通道和控制通道的实现相分离.为了减少封包和事件的处理时间,事件调度器和数据通道上的基本网络组件对象都使用C++编写,这些对象通过TclCL映射对OTcl解释器可见。
目前,NS2可以用于模拟各种不同的通信网络,它功能强大,模块丰富,已经实现的主要模块有:网络传输协议,如TCP和UDP;业务源流量产生器,如FTP、Telnet、CBR、Web和VBR;路由队列管理机制,如Droptail、RED和CBQ;路由算法;以及无线网络WLAN、移动IP和卫星通信网络等模块。
也为进行局域网的模拟实现了多播协议以及一些MAC子层协议。
3。
2 NS2的功能模块NS2仿真器封装了许多功能模块,最基本的是节点、链路、代理、数据包格式等,下面对各个模块进行简单的介绍:(1)事件调度器:目前NS2提供了四种具有不同数据结构的调度器,分别是链表、堆、日历表和实时调度器。
(2)节点(node):是由TclObject对象组成的复合组件,在NS2中可以表示端节点和路由器.(3)链路(link):由多个组件复合而成,用来连接网络节点.所有的链路都是以队列的形式来管理封包的到达、离开和丢弃。
HUNAN CITY UNIVERSITYNS2与网络模拟实验报告实验题目:环形链路模拟 _____专业:网络工程__________学生姓名: ______班级学号: ____2015年 10 月 14 日1.实验目的•熟悉NS2网络模拟的基本操作流程•练习TCL脚本代码的编写•理解基本的网络节点和连接的创建过程、以及数据流的发生•掌握大型网络的生成和配置2.实验原理NS2是指 Network Simulator version 2,NS(Network Simulator)是一种针对网络技术的源代码公开的、免费的软件模拟平台,研究人员使用它可以很容易的进行网络技术的开发,而且发展到今天,它所包含的模块几乎涉及到了网络技术的所有方面。
所以,NS成了目前学术界广泛使用的一种网络模拟软件。
此外,NS也可作为一种辅助教学的工具,已被广泛应用在了网络技术的教学方面。
因此,目前在学术界和教育界,有大量的人正在使用NS。
NS2是一种面向对象的网络仿真器,本质上是一个离散事件模拟器,由UC Berkeley开发而成。
它本身有一个虚拟时钟,所有的仿真都由离散事件驱动的。
目前NS2可以用于仿真各种不同的IP网,已经实现的一些仿真有网络传输协议,比如TCP和UDP, 流量产生器,比如FTP, Telnet, Web CBR和VBR;路由队列管理机制,比如Droptail, RED和CBQ;路由算法,比如AODV、DSDV、DSR等无线路由协议。
NS2也为进行局域网的仿真而实现了多播以及一些MAC 子层协议。
3.实验内容和步骤•打开虚拟机播放器VMware Player•打开播放Ubuntu虚拟机镜像(Ubuntu.vmx)•登录系统后,打开控制台Terminal输入下列命令:•cd Desktop/EXP/•ns 4-circle.tcl•模拟运行完毕后,动画演示器NAM自动打开,播放动画,观察模拟过程。
4.实验结论(a)截取NAM动画演示结果。
网络分析与测试实验
XXX XXXXXXXX 网络工程2010-2班
实验二使用NS2模拟有线网络
一、实验目的
深入学习NS2的使用方法,学习使用NS2模拟有线网络的开发方法。
二、实验内容
(1)构建有线网络的基本拓扑;
(2)配置网络节点、链路和协议的参数;
(3)使用Tcl脚本语言描述配置信息;
(4)实现有线网络的模拟,分析不同配置下的输出结果。
三、实验步骤
1.构建有线网络的基本拓扑
2. 这个网络拓扑定义了6个节点,每个节点之间的连接设置成双工格式,在0,1节点设置两个UDP发送节点,在4,5节点设置两个agent 接收节点,设置传送的数据包大小为1500,然后再在UDP连接中定义一个数据流量发送器(包括它的包的大小、速率大小、停止时间和开始时间),最后定义一个finish函数来完成清理现场的工作,进而完成网络节点、链路和协议的参数的配置。
3.tcl的源程序:
set val(stop) 5.0 ;# time of simulation end #Create a ns simulator
set ns [new Simulator]
#Open the NS trace file
set tracefile [open out.tr w]
$ns trace-all $tracefile
#Open the NAM trace file
set namfile [open out.nam w]
$ns namtrace-all $namfile
#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]
#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 $n4 $n3 2.0Mb 10ms DropTail
$ns queue-limit $n4 $n3 10
$ns duplex-link $n3 $n2 1.0Mb 20ms DropTail
$ns queue-limit $n3 $n2 10
$ns duplex-link $n3 $n5 2.0Mb 10ms DropTail
$ns queue-limit $n3 $n5 10
#Give node position (for NAM)
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n4 $n3 orient left-down
$ns duplex-link-op $n3 $n2 orient left
$ns duplex-link-op $n3 $n5 orient right-down
#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
#Setup a UDP connection
set udp1 [new Agent/UDP]
$ns attach-agent $n1 $udp1
set null3 [new Agent/Null]
$ns attach-agent $n5 $null3
$ns connect $udp1 $null3
$udp1 set packetSize_ 1500
#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"
#Setup a CBR Application over UDP connection set cbr1 [new Application/Traffic/CBR]
$cbr1 attach-agent $udp1
$cbr1 set packetSize_ 1500
$cbr1 set rate_ 1.0Mb
$cbr1 set random_ null
$ns at 2.0 "$cbr1 start"
$ns at 3.0 "$cbr1 stop"
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam out.nam &
exit 0
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)" $ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run
4.在cygwin中运行startwin.bat,如下图:
5.打开新建的有线网络配置文件wired.tcl
6.运行结果如下图:
7.分析运行结果:
1)在S=1s时,节点0到节点4的数据流量启动,如下图:
2)在S=2s后,节点1到节点5的数据流量启动,如下图:
3)在S=3s后,节点1到节点5的数据传输停止
4)在S=4s后,节点0停止向节点4传输数据
四、实验体会
经过第一次安装NS2的实验,已经对NS2有了一定的了解。
在此基础上,我认真研究了NS2的原理与基本应用,对它的使用有了一定的了解,同时也能理解一些简单的tcl 脚本的配置。
之后,我通过一些资料,成功地完成了这次实验。