2014-10-10 91 views
0

這是我的代碼爲SFQ.tcl。當我在大學計算機上執行時,此代碼運行完美,當我試圖在計算機上運行它時,它給了我一些錯誤。如果任何人都可以告訴我錯誤在哪裏。其它的在安裝ns2。由於當我鍵入納秒它顯示我%但是當我嘗試運行的程序把它給錯誤ns2代碼未運行給出一些錯誤無法找出錯誤

#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

替換該行 集VAL(停止)60.0;應#creating新模擬器集NS [新模擬器]

與 下面線,

組VAL(停止)60.0; set ns [new Simulator]

#用於在tcl中做評論