网络分析与测试实验2_使用NS2模拟有线网络

合集下载

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网络仿真实验实验目的:通过修改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的案例使用

一个简单的网络模拟器NS的案例使用

网络模拟器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的基本功能和用法,让您了解如何使用这个强大的工具来开展网络仿真和探索。

第一部分: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等。

网络仿真器NS-2及其一个应用实例

网络仿真器NS-2及其一个应用实例

NS- 2 是 一个具有仿真事件驱 动、网 络构件 对象库 和网络 配
置模块库的 Otcl 脚本解释器。NS- 2 中编译 类对象通过 Otcl
连接建立了与之对应的解释类对象, 这样用户 可以在 Otcl 空
间能够方便地对 C+ + 对象的 函数和 变量进 行修改与 配置, 充分体现了仿真器的一致和灵活性。 2. 3 NS- 2 的功能模块
本文要介绍的是目前应用较 为广泛的 网络仿 真软件 NS - 2( Network Simulator) , 它是由 UC Berkely 大学开 发的一个 基 于事件驱动的仿真器。它能近乎真实地模 拟网络环 境, 让 我 们可以在各个层次上模拟网络的运行。
2 NS- 2 结构和功能
2. 1 NS- 2 简介 NS- 2 是 面向对象的, 基 于离散 事件驱 动的网 络环境 模
3) 链路( Link) : 由 多个组 件复 合而成, 用来 连接 网络 节 点。所有的链路都是以队列的形式来管理 分组的到 达、离 开 和丢弃。在链路中增加了 Trace/ EnqT 、Trace/ DeqT、Trace/ DrpT 以及 Tracer/ RecvT 等对象可以跟踪每个数据包到达、进入、离 开队列以及被丢弃的时间; 还可以用队列监视 器( Queue Mon itor) 来监测队列长度和平均队长的变化情况。
用户使用 NS- 2 实现tcl 源 程序来初始 化一个事 件 调度器, 定义网络拓扑结构, 配置业务源, 确定 发送和接受 传 输数据包的时间, 然后启动 NS- 2 仿真器。
2) 运行仿真程序。 3) 仿真结果分析: 程序运行 结束后, 用户根据记录 模拟数 据的文档, 利用 NS- 2 中的可视化仿真软件 NAM 动态 查看仿 真的运 行过 程、观察 跟 踪数 据, 或 使用 Linux 中的 Xgraph 或 Windows 下的 Origin 等软件将结果转换成带有坐标的平面图。

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。

NS2仿真与网络实验教学

NS2仿真与网络实验教学

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仿真实验分析报告

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)。

网络分析与测试实验
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 脚本的配置。

之后,我通过一些资料,成功地完成了这次实验。

相关文档
最新文档