无法在ns2中运行tcl脚本

时间:2017-01-15 17:33:54

标签: tcl ns2

当我尝试在ns2.34中运行我自己的tcl脚本(10.tcl)时,它给了我这个错误。

couldn't read file "/home/bony/ns-2.34/ns-allinone-2.34/ns-2.34.aodv":
no such file or directory
            while executing
        "source.orig /home/bony/ns-2.34/ns-allinone-2.34/ns-2.34.aodv"
            ("uplevel" body line 1)
            invoked from within
        "uplevel source.orig [list $fileName]"
            invoked from within
        "if [$instance_ is_http_url $fileName] {
        set buffer [$instance_ read_url $fileName]
        uplevel eval $buffer
        } else {
        uplevel source.orig [list $fileName]
        ..."
            (procedure "source" line 8)
        invoked from within
    "$ns_ $path.$valrp"
        (file "10.tcl" line 20)

这是我正在使用的10.tcl代码。当我尝试在Fedora中的ns2中运行这个10.tcl文件时,它给了我上面的错误。

#===================================
#     Simulation parameters setup
#===================================
set ns_ source
set path /home/bony/ns-2.34/ns-allinone-2.34/ns-2.34
set val(chan)   Channel/WirelessChannel    ;# channel type
set val(prop)   Propagation/TwoRayGround   ;# radio-propagation model
set val(netif)  Phy/WirelessPhy            ;# network interface type
set val(mac)    Mac/802_11                 ;# MAC type
set val(ifq)    Queue/DropTail/PriQueue    ;# interface queue type
set val(ll)     LL                         ;# link layer type
set val(ant)    Antenna/OmniAntenna        ;# antenna model
set val(ifqlen) 50                         ;# max packet in ifq
set val(nn)     10                         ;# number of mobilenodes
set valrp       aodv                   ;# routing protocol
set val(x)      943                        ;# X dimension of topography
set val(y)      567                        ;# Y dimension of topography
set val(stop)   20.0                       ;# time of simulation end
set speed       10
$ns_ $path.$valrp

set packet_size 512;#packetsize
#===================================
#        Initialization        
#===================================
#Create a ns simulator
set ns [new Simulator]

#Setup topography object
set topo       [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)

#Open the NS trace file
set tracefile [open out.tr w]
$ns trace-all $tracefile

#Open the NAM trace file
set namfile [open out.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $val(x) $val(y)
set chan [new $val(chan)];#Create wireless channel

#===================================
#     Mobile node parameter setup
#===================================
$ns node-config -adhocRouting  $valrp \
                -llType        $val(ll) \
                -macType       $val(mac) \
                -ifqType       $val(ifq) \
                -ifqLen        $val(ifqlen) \
                -antType       $val(ant) \
                -propType      $val(prop) \
                -phyType       $val(netif) \
                -channel       $chan \
                -topoInstance  $topo \
                -agentTrace    ON \
                -routerTrace   ON \
                -macTrace      ON \
                -movementTrace ON

#===================================
#        Nodes Definition        
#===================================
#Create 10 nodes
set n(0) [$ns node]
$n(0) set X_ 284
$n(0) set Y_ 380
$n(0) set Z_ 0.0

 $ns initial_node_pos $n(0) 20
set n(1) [$ns node]
$n(1) set X_ 343
$n(1) set Y_ 195
$n(1) set Z_ 0.0

 $ns initial_node_pos $n(1) 20
set n(2) [$ns node]
$n(2) set X_ 411
$n(2) set Y_ 308
$n(2) set Z_ 0.0

 $ns initial_node_pos $n(2) 20
set n(3) [$ns node]
$n(3) set X_ 468
$n(3) set Y_ 460
$n(3) set Z_ 0.0

 $ns initial_node_pos $n(3) 20
set n(4) [$ns node]
$n(4) set X_ 567
$n(4) set Y_ 363
$n(4) set Z_ 0.0

 $ns initial_node_pos $n(4) 20
set n(5) [$ns node]
$n(5) set X_ 586
$n(5) set Y_ 194
$n(5) set Z_ 0.0

 $ns initial_node_pos $n(5) 20
set n(6) [$ns node]
$n(6) set X_ 698
$n(6) set Y_ 343
$n(6) set Z_ 0.0

 $ns initial_node_pos $n(6) 20
set n(7) [$ns node]
$n(7) set X_ 698
$n(7) set Y_ 467
$n(7) set Z_ 0.0

 $ns initial_node_pos $n(7) 20
set n(8) [$ns node]
$n(8) set X_ 783
$n(8) set Y_ 186
$n(8) set Z_ 0.0

 $ns initial_node_pos $n(8) 20
set n(9) [$ns node]
$n(9) set X_ 843
$n(9) set Y_ 361
$n(9) set Z_ 0.0

 $ns initial_node_pos $n(9) 20


for {set i 0} { $i < $val(nn)} {incr i} {

set tcp($i) [new Agent/TCP]

$ns attach-agent $n($i) $tcp($i)
set sink($i) [new Agent/LossMonitor]

$ns attach-agent $n($i) $sink($i)

}
#===================================
#        Agents Definition        
#===================================

#===================================
#        Applications Definition        
#===================================
proc attach-CBR-traffic { node sink size interval } {

#Get an instance of the simulator

   set ns [Simulator instance]

#Create a CBR  agent and attach it to the node

   set cbr [new Agent/CBR]

   $ns attach-agent $node $cbr

   $cbr set packetSize_ $size

   $cbr set interval_ .05

#Attach CBR source to sink;

   $ns connect $cbr $sink

   return $cbr
}
set cbr00 [attach-CBR-traffic $n(0) $sink(9) 512 $interval]
$ns at 1.21 "$cbr00 start"


$ns at 0.86 "$n(0) add-mark MARK darkgreen square"  


$ns at 0.86 "$n(0) label Sender"


$ns at 0.86 "$n(9) add-mark MARK magenta circle"  


$ns at 0.86 "$n(9) label Receiver"

for {set i 0} {$i < $val(nn) } {incr i} {

set timemin 1
set timemax 10
    set timemaxFactor [expr [expr $timemax + 1] - $timemin]
    set timevalue [expr int([expr rand() * 100])]
    set timevalue [expr [expr $timevalue % $timemaxFactor] + $timemin]


set xmin 500
set xmax 1200
    set xmaxFactor [expr [expr $xmax + 1] - $xmin]
    set xvalue [expr int([expr rand() * 100])]
    set xvalue [expr [expr $xvalue % $xmaxFactor] + $xmin]


set ymin 50
set ymax 800
    set ymaxFactor [expr [expr $ymax + 1] - $ymin]
    set yvalue [expr int([expr rand() * 100])]
    set yvalue [expr [expr $yvalue % $ymaxFactor] + $ymin]


$ns at $timevalue "$n($i) setdest $xvalue $yvalue $speed"
}
#===================================
#        Termination        
#===================================
#Define a 'finish' procedure
proc finish {} {
    global ns tracefile namfile
    $ns flush-trace
    close $tracefile
    close $namfile
exec sed -i "/d -t /d" out.nam
    exec nam out.nam &
exec awk -f pdf.awk out.tr > Results
exec awk -f e2edelay.awk out.tr >> Results
exec awk -f throughput.awk out.tr >> Results
exec awk -f control_overhead.awk out.tr >> Results
    exit 0
}
for {set i 0} {$i < $val(nn) } { incr i } {
    $ns at $val(stop) "\$n($i) reset"
}
$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

0 个答案:

没有答案