一、 课程设计目的
掌握网络模拟工具NS2的使用,学习基本的网络模拟方法。
二、 课程设计内容
协议模拟
工具:NS2,awk,shell,perl等;
要求:掌握NS2网络模拟的基本流程;
内容:NS2网络模拟基本流程
编写TCL脚本,搭建如下图所示的一个网络,共6个节点,其中2、3节点用做ftp服务器和客户端,4、5节点用做cbr流量的源和目的,而0、1节点用做转发设备。各节点间的链路属性见图。
模拟时间设为13秒钟,在0.1秒开始产生cbr流量,在1.0秒开发发送发ftp流量;8.0秒ftp流量结束,12.0秒cbr流量结束。编写脚本(可用shell,awk,或perl等)分析模拟日志文件,统计每0.5s内0、1节点间链路通过的分组数以及字节数。
三、 设计与实现过程
1.仿真脚本代码与详细注解
#Create a simulator object
set ns [new Simulator]
#Define different colors for data flows (for NAM)
$ns color 1 Blue
$ns color 2 Red
#Open the NAM trace file
set nf [open out.nam w]
$ns namtrace-all $nf
#Open the Trace file
set tf [open out.tr w]
$ns trace-all $tf
#Define a 'finish' procedure
proc finish {} {
global ns nf tf
$ns flush-trace
close $nf
close $tf
exec nam out.nam &