ns2 Tcl脚本程序解析

set ns [new Simulator]  ;#建立一个simulator对象


set tracefd [open no1.tr w]  ;#注意此处的no.1
$ns trace-all $tracefd
set namtracefd [open no1.nam w] ;#注意此处的no.1
$ns namtrace-all $namtracefd


proc finish {} {
     global ns tracefd namtracefd
     $ns flush-trace
     close $tracefd
     close $namtracefd
     exec nam no1.nam &   ;#注意此处no.1
     exit 0
}

#新建两个node(节点),分别复制n0 和n1
set n0 [$ns node]   
set n1 [$ns node]

#建立一条双向link(链路)  该链路的带宽为1Mbit/s  延迟为10ms  队列类型为DropTail
$ns duplex-link $n0 $n1 1Mb 10ms DropTail

#新建一个UDP Agent 并绑定到n0上
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0

#新建一个CBR的流量发生器 分组大小为500Byte 发送间隔为5ms 绑定到udp0上
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0

#新建一个Null Agent 并绑定到n1上,Null是数据接收器
set null0 [new Agent/Null]
$ns attach-agent $n1 $null0

#将udp0 和 null0 连接起来
$ns connect $udp0 $null0

#告知cbr0在0.5s时启动 在4.5s时停止
$ns at 0.5 "$cbr0 start"
$ns at 4.5 "$cbr0 stop"

#在5s时调用finish过程
$ns at 5.0 "finish"


$ns run


注意无论你给文件起**.tcl 但是里面的内容不能变

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值