计算机网络实验:Lab4 使用ns2进行网络模拟

Lab 4: Using NS

实验过程

  • 编写tcl脚本
  • 使用ns运行tcl脚本模拟网络,并利用nam生成动画
  • 解析上一步产生的trace数据,计算丢包率
  • 使用解析后的数据画图
  • 分析原理

实验环境

Linux Ubuntu 18.04 with bash

安装依赖

sudo apt-get install ns2 (ns)
sudo apt-get install tcl (tclsh)
sudo apt-get install nam (nam)
sudo apt-get install original-awk (awk)
sudo apt-get install gnuplot-qt

开始实验

编写tcl脚本

set ns [new Simulator]

#open a nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf

#open a trace file
set tf [open out.tr w]
$ns trace-all $tf

#finish procedure
proc finish {} {
 global ns nf tf
 $ns flush-trace
 close $nf
 close $tf
 exec nam out.nam &
 exit 0
}

#create nodes
set node(http) [$ns node]
set node(rtp) [$ns node]
set node(recv) [$ns node]

#create links
$ns duplex-link $node(http) $node(recv) 0.9Mb 10ms DropTail
$ns duplex-link $node(rtp) $node(recv) 0.9Mb 10ms DropTail

#set queue size
$ns queue-limit $node(http) $node(recv) 10
$ns queue-limit $node(rtp) $node(recv) 10

#relayout nodes
$ns duplex-link-op $node(http) $node(recv)
  • 3
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值