NS2网络仿真的过程可以总结为:
1、初始化
    创建ns simulator
    创建.tr文件(记录仿真结果)
    创建.nam文件(记录仿真过程)
    设置结束函数
    设置仿真中所需的参数
2、创建仿真拓扑
    创建节点
    创建并设置链路
    设置链路各链路在nam中的排列方式
3、创建流量
    探测流量:向网络中添加的额外流量,通过对这些流量进行统计分析可以获得端到端性能参数,在ns2中可以通过设置CBR、UDP、TCP等形式的流量实现。
    背景流量:用于模拟网络中已经存在的流量,可以有TCP、UDP、短时TCP等多种形式。(添加准则:尽量能够反映实际网络中流量的特性)
4、设置步骤
    设置流量的产生、结束
5、结束仿真

我们可以对照下面的例子来看看仿真过程:

#Create a simulator object
set ns [new Simulator]#Define different colors for data flows
$ns color 1 Blue
$ns color 2 Red#Open the nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf#Define a 'finish' procedure
proc finish {} {global ns nf$ns flush-trace#Close the trace fileclose $nf#Execute nam on the trace fileexec nam out.nam &exit 0
}#Create four nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]#Create links between the nodes
$ns duplex-link $n0 $n2 1Mb 10ms DropTail
$ns duplex-link $n1 $n2 1Mb 10ms DropTail
$ns duplex-link $n3 $n2 1Mb 10ms SFQ$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#Monitor the queue for the link between node 2 and node 3
$ns duplex-link-op $n2 $n3 queuePos 0.5#Create a UDP agent and attach it to node n0
set udp0 [new Agent/UDP]
$udp0 set class_ 1
$ns attach-agent $n0 $udp0# Create a CBR traffic source and attach it to udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0#Create a UDP agent and attach it to node n1
set udp1 [new Agent/UDP]
$udp1 set class_ 2
$ns attach-agent $n1 $udp1# Create a CBR traffic source and attach it to udp1
set cbr1 [new Application/Traffic/CBR]
$cbr1 set packetSize_ 500
$cbr1 set interval_ 0.005
$cbr1 attach-agent $udp1#Create a Null agent (a traffic sink) and attach it to node n3
set null0 [new Agent/Null]
$ns attach-agent $n3 $null0#Connect the traffic sources with the traffic sink
$ns connect $udp0 $null0
$ns connect $udp1 $null0#Schedule events for the CBR agents
$ns at 0.5 "$cbr0 start"
$ns at 1.0 "$cbr1 start"
$ns at 4.0 "$cbr1 stop"
$ns at 4.5 "$cbr0 stop"
#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 "finish"#Run the simulation
$ns run

该例子运行结果如下:

NS2网络仿真的过程相关推荐

  1. Windows平台下NS2网络仿真环境的搭建

    NS2(Network Simulator 2) 是一种针对网络技术的源代码公开的.免费的软件模拟平台,研究人员使用它可以很容易的进行网络技术的开发,而且发展到今天,它所包含的模块几乎涉及到了网络技术 ...

  2. ns2安装详细过程与网络仿真

    ns2安装详细过程与网络仿真 博客分类: Networks TclLinuxUnixGCCVC++ 简单的说,NS-2是一个网络模拟器,所以经常被用到网络课的教学中. NS-2是OpenSource的 ...

  3. Ns2简单有限网络仿真实验

    Ns2简单有限网络仿真实验 1.编写Otcl脚本文件yy.tcl 2.终端:ns yy.tcl即可进行仿真 注意:在 建立一条UDP的联机时,不要忘记添加 $ns attach-agent $n3 $ ...

  4. VM15.5.0+Ubuntu16.04.6+ns2.35仿真平台

    VM15.5.0+Ubuntu16.04.6+ns2.35仿真平台 步骤一.安装虚拟机:VMware® Workstation 15 Pro(版本15.5.0) (1)下载虚拟机应用程序 (2)双击运 ...

  5. 网络仿真软件性能比较

    [导读]网络仿真技术是一种通过建立网络设备和网络链路的统计模型, 并模拟网络流量的传输, 从而获取网络设计或优化所需要的网络性能数据的仿真技术.由于仿真不是基于数学计算, 而是基于统计模型,因此,统计 ...

  6. NS-3网络仿真平台搭建及可视化

    面向5G车联网仿真平台的搭建 本博客是基于SRTP(面向5G车联网仿真平台设计与开发)而搭建的"面向5G车联网的网络仿真平台",以供大家学习使用. 目录 前言概述 准备工作 下载n ...

  7. Alevin——虚拟网络仿真平台

    Alevin--虚拟网络仿真平台 摘要: 抽象网络虚拟化被看作是未来互联网的一种实现技术.在此背景下,目前已有文献介绍了许多虚拟网络嵌入算法.本文讨论了一个评估这些算法的开源框架.本文描述了该框架提供 ...

  8. 陈旿 计算机网络视频,一种新的实时半实物网络仿真方法

    仿真方法的应用最早可追溯到1773年,法国自然学家用仿真方法做物理实验估计π值.经过200多年的发展,仿真技术已经成为科学实验的有效手段,对科学技术的发展起到了巨大的推动作用.1992年美国提出22项 ...

  9. NS3网络仿真项目(二)——入门指南

    官网给出NS3的资料主要分为以下几种: 1. NS3入手指南(Tutorial) 主要介绍如何下载.安装.以及简单的功能.实例程序讲解 2. NS3使用手册(Manual) 主要介绍NS3仿真器的结构 ...

最新文章

  1. Creating a LINQ Enabled ASP.NET Web application template using C#.[转]
  2. Facebook 正在研究新型 AI 系统,以自我视角与世界进行交互
  3. Apache 编译安装
  4. 转: 常见加密算法分,用途,原理以及比较
  5. python答案公众号_大学慕课用Python玩转数据答案查题公众号
  6. STM32开发 -- 地球坐标系(WGS84),火星坐标系(GCJ02), 百度坐标系(BD09)坐标转换
  7. qhfl-5 redis 简单操作
  8. ultra edit ftp帐号管理导入导出方法
  9. LeetCode 1566. 重复至少 K 次且长度为 M 的模式
  10. 这些产品大咖的实战心得,学会了可以帮你跨过很多坑
  11. list ilist java_C#中IList与List区别
  12. 计算机审计操作实验目的,计算机审计实验报告 满分原创!!.docx
  13. 友元函数的访问权限和注意事项
  14. 被称为“Google 最大黑科技”,开发谷歌大脑,这位 AI 掌门人到底有多牛?
  15. 第三模块 商务写作的“5步法”
  16. 微软人工智能公开课.md
  17. Android 读取Txt文件内容
  18. Android:安卓学习笔记之共享元素的简单理解和使用
  19. 放大器为什么会被限幅?原因所在!
  20. Pytorch——如何创建一个tensor与索引和切片(一)

热门文章

  1. 微信{errcode:48001,errmsg:api unauthorized, hints: [ req_id: 1QoCla0699ns81 ]}
  2. php scada,scada系统是什么
  3. Promise is a promise
  4. Swing中如何实现二级联动下拉列表
  5. dmp标签_[重磅推荐]你必须知道的京准通DMP知识!
  6. 常见HTTP状态码(200,304,404等)
  7. 【计量经济学】异方差性
  8. 创意电子学-小知识:研究继电器
  9. 高等数学(第七版)同济大学 总习题九(后10题) 个人解答
  10. 软考--快速掌握操作系统的PV操作