سلام دوستان. من تازه با Ns2 کار میکنم. برنامه یا مثال پروسیجر را نوشتم و روی سیستم اجرا هم شد. اما نمیدانم چرا برنامه زیر بنام ns_simple.tcl اجرا نمیشه و چندین خط خطا می دهد. برنامه و خطاها را در زیر می آورم. بخاطر چپ نویس شدن در این متن علامت $ ها و # ها یا کروشه ها جابجا شده اند. اما در متن برنامه صحیح هستند. همچنین در دایرکتوری ns-2,31 برنامه را اجرا میکنم. ممنون از راهنمایی که مکنید.
کد:
#Create a simulator object set ns [new Simulator] #Define different colors for data flows (for NAM) $ns color 1 Blue $ns color 2 Red
#Open the NAM trace file set nf [open out.nam w] $ns namtrace-all $nf #Define a ‘finish’ procedure proc finish { } { global ns nf $ns flush-trace #Close the NAM trace file close $nf #Execute NAM on the trace file exec nam out.nam & exit 0 } #Create four nodes set n0 [$ns node] set n1 [$ns node] set n2 [$ns node] set n3 [$ns node] #Create links between the nodes $ns duplex-link $n0 $n2 2Mb 10ms DropTail $ns duplex-link $n1 $n2 2Mb 10ms DropTail $ns duplex-link $n2 $n3 1.7Mb 20ms DropTail #Set queue Size of link (n2-n3) to 10 $ns queue-limit $n2 $n3 10 #Give node position (for NAM) $ns duplex-link-op $n0 $n2 orient right-down $ns duplex-link-op $n1 $n2 orient right-up $ns duplex-link-op $n2 $n3 orient right #Monitor the queue for link (n2-n3). (for NAM) $ns duplex-link-op $n0 $n2 queuePos 0.5 #Setup a TCP connection set tcp [new Agent/TCP] $tcp set class_ 2 $ns attach-agent $n0 $tcp set sink [new Agent/TCPSink] $ns attach-agent $n3 $sink $ns connect $tcp $sink $tcp set fid_ 1 #Setup a FTP over TCP connection set ftp [new Application/FTP] $ftp attach-agent $tcp $ftp set type_ FTP #setup a UDP connection set udp [new Agent/UDP] $ns attach-agent $n1 $udp set null [new Agent/Null] $ns attach-agent $n3 $null $ns connect $udp $null $udp set fid_ 2 #Setup a CBR over UDP connection set cbr [new Application/Traffic/CBR] $cbr attach-agent $udp $cbr set type_ CBR $cbr set packet_size_ 1000 $cbr set rate_ 1mb $cbr set random_ false #Schadule events for the CBR and FTP agents $ns at 0.1 "$cbr start" $ns at 1.0 "$ftp start" $ns at 4 "$ftp stop" $ns at 4.5 "$cbr stop" #Detach tcp and sink agents (not really necessary) $ns at 4.5 “$ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink” #Call the finish procedure after 5 seconds of simulation time $ns at 5.0 "finish" #Print CBR packet size and intervl puts "CBR packet size = [$cbr set packet_size_]" puts "CBR interval = [$cbr set interval]" #Run the simulation $ns run
پیغامهای خطایی که میدهد به این صورت است:
کد:
(_o5 cmd line 1)
invoked from within
"_o5 cmd at 4.5 “_o3 detach-agent _o10 _o82"
invoked from within
"catch "$self cmd $args" ret"
invoked from within
"if [catch "$self cmd $args" ret] {
set cls [$self info class]
global errorInfo
set savedInfo $errorInfo
error "error when calling class $cls: $args" $..."
(procedure "_o5" line 2)
(SplitObject unknown line 2)
invoked from within
"_o5 at 4.5 “_o3 detach-agent _o10 _o82"
("eval" body line 1)
invoked from within
"eval $scheduler_ at $args"
(procedure "_o3" line 3)
(Simulator at line 3)
invoked from within
"$ns at 4.5 “$ns detach-agent $n0 $tcp "
(file "ns-simple.tcl" line 84)
user@user-VB:~/ns-allinone-2.31/ns-2.31$