ns2代码没有运行给出一些错误无法弄清楚错误

时间:2014-10-10 08:29:26

标签: ns2

这是我的SFQ.tcl代码。当我在大学计算机上执行时,当我试图在我的计算机上运行它时,这个代码运行得很完美,它给了我一些错误。如果有人能告诉我错误在哪里,请。还有它在安装ns2。当我输入ns时,它会显示%,但是当我尝试运行程序时会出现错误

#Simulation Time 
set val(stop)   60.0;  #Creating New Simulator set ns [new Simulator]  
set tracefile [open out.tr w] 
$ns trace-all $tracefile 
set namfile [open out.nam w] 
$ns namtrace-all $namfile 

#Create 6 nodes 
set n0 [$ns node] 
set n1 [$ns node] 
set n2 [$ns node] 
set n3 [$ns node] 
set n4 [$ns node] 
set n5 [$ns node] 

#Create links between nodes With specific Bandwidth, Delay, Queue Type & 
Queue Size 

$ns duplex-link $n0 $n2 10.0Mb 10ms SFQ 
$ns queue-limit $n0 $n2 50 
$ns duplex-link $n1 $n2 10.0Mb 10ms SFQ 
$ns queue-limit $n1 $n2 50 
$ns duplex-link $n3 $n4 10.0Mb 10ms SFQ 
$ns queue-limit $n3 $n4 50 
$ns duplex-link $n3 $n5 10.0Mb 10ms SFQ 
$ns queue-limit $n3 $n5 50 
$ns duplex-link $n2 $n3 5.0Mb 10ms SFQ 
$ns queue-limit $n2 $n3 50 



#Give node position  

$ns duplex-link-op $n0 $n2 orient right-down 
$ns duplex-link-op $n1 $n2 orient right-up 
$ns duplex-link-op $n3 $n4 orient right-up 
$ns duplex-link-op $n3 $n5 orient right-down 
$ns duplex-link-op $n2 $n3 orient right 


#Creating TCP Agent set tcp [new Agent/TCP] $tcp set class_ 2 
#Attaching TCP Agent On n0 
$ns attach-agent $n0 $tcp #Creating TCP sink  set sink [new Agent/TCPSink] 
#Attaching TCP Sink On n4 
$ns attach-agent $n4 $sink 
#Connecting TCP to Simulator  
$ns connect $tcp $sink 
$tcp set fid_ 1 
#Setting Packet Size of TCP 
$tcp set packetSize_ 1500 

#Creating FTP Application set ftp [new Application/FTP] 
#Attaching FTP to TCP 
$ftp attach-agent $tcp 
$ftp set type_ FTP 



#Creating UDP Agent set udp1 [new Agent/UDP] #Attaching UDP Agent On n1 
$ns attach-agent $n1 $udp1 
#Creating Null for UDP Agent set null [new Agent/Null] 
#Attaching Null On n5 
$ns attach-agent $n5 $null 
$ns connect $udp1 $null 
$udp1 set fid_ 2 


#Setting Queue Monitor to Monitor the Drop packets and Drop Bytes And Various Other Things 
set qmon1 [$ns monitor-queue $n0 $n2 [open n0n1.out w] 0.1]; 
[$ns link $n0 $n2] queue-sample-timeout; 

set qmon2 [$ns monitor-queue $n1 $n2 [open n1n2.out w] 0.1]; 
[$ns link $n1 $n2] queue-sample-timeout; 

set qmon3 [$ns monitor-queue $n2 $n3 [open n2n3.out w] 0.1]; 
[$ns link $n2 $n3] queue-sample-timeout; 

set qmon4 [$ns monitor-queue $n3 $n4 [open n3n4.out w] 0.1]; 
[$ns link $n3 $n4] queue-sample-timeout; 
set qmon5 [$ns monitor-queue $n3 $n5 [open n3n5.out w] 0.1]; 
[$ns link $n3 $n5] queue-sample-timeout; 



#Creating CBR Application set cbr1 [new Application/Traffic/CBR] 
#Attaching CBR to UDP Agent 
$cbr1 attach-agent $udp1 $cbr1 set type_ CBR 
#Setting CBR Packet Size 
$cbr1 set packetSize_ 1500 
#Setting CBR Rate 
$cbr1 set rate_ 0.05Mb 
$cbr1 set random_ false 

#Start And Stop For Application 

$ns at 0.1 "$cbr1 start" 
$ns at 1.0 "$ftp start" 
$ns at 59.0 "$ftp stop" 
$ns at 59.5 "$cbr1 stop" 

#Finish Procedure 
 proc finish {} { 

    global ns tracefile namfile 

    $ns flush-trace 
     close $tracefile 
     close $namfile 
     exec nam out.nam & 
     exit 0 

} 

$ns at $val(stop) "$ns nam-end-wireless $val(stop)" 
$ns at $val(stop) "finish" 
$ns at $val(stop) "puts \"done\" ; $ns halt" 
$ns run 

我收到这样的错误

can't read "ns": no such variable
    while executing
"$ns node"
    invoked from within
"set n0 [$ns node] "
    (file "SFQ.tcl" line 9)

1 个答案:

答案 0 :(得分:1)

替换此行 设定val(停止)60.0; #Creating New Simulator set ns [new Simulator]

与 在线下,

设定val(停止)60.0;  设置ns [新模拟器]

#used在tcl

中做评论