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"
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 但是里面的内容不能变