[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ns] problem with record procedure



hi all
when i try to run the following tcl file, i allways get the error:

ns: record: can't read "null(0)": no such variable
    while executing
"$null($i) set bytes_"
    (procedure "record" line 5)
    invoked from within
"record"


what's wrong with the file?please help me
thanks lorenz
the file looks like:

# ======================================================================
# Define options
# ======================================================================

set val(chan)       Channel/WirelessChannel
set val(prop)       Propagation/TwoRayGround
set val(netif)      Phy/WirelessPhy
set val(mac)        Mac/802_11
set val(ifq)        Queue/DropTail/PriQueue
set val(ll)         LL
set val(ant)        Antenna/OmniAntenna
set val(x)              200  ;# X dimension of the topography
set val(y)              200   ;# Y dimension of the topography
set val(ifqlen)         50            ;# max packet in ifq
set val(seed)           0.0
set val(adhocRouting)   DSR
set val(nn)             5            ;# how many nodes are simulated
set val(stop)           20        ;# simulation time

# =====================================================================
# Main Program
# ======================================================================

#
# Initialize Global Variables
#

# create simulator instance

set ns		[new Simulator]

# setup topography object

set topo	[new Topography]

# create trace object for ns and nam

set tracefd	[open 1v3tr.tr w]
set namtrace    [open 1v3nam.nam w]
for {set i 0} {$i < $val(nn)} {incr i} {
    set f($i)   [open out($i).tr w]
    }
$ns trace-all $tracefd
$ns namtrace-all-wireless $namtrace $val(x) $val(y)

#Define a 'finish' procedure
proc finish {} {
        global ns tracefd f0 f1 f2 f3 f4
        $ns flush-trace
	#Close the trace file
        close $tracefd
        for {set i 0} {$i < $val(nn)} {incr i} {
            close f($i)
            }
        exec xgraph -bb -m -y nb(pkts/bytes) -x time out(0).tr out(1).tr 
out(2).tr out(3).tr out(4).tr -geometry 1000x500 &
	#Execute nam on the trace file
        exec nam 1c1nam.nam &
        exit 0
}

# define topology
$topo load_flatgrid $val(x) $val(y)

#
# Create God
#
set god [create-god $val(nn)]

#
# define how node should be created
#

#global node setting

$ns node-config -adhocRouting $val(adhocRouting) \
                 -llType $val(ll) \
                 -macType $val(mac) \
                 -ifqType $val(ifq) \
                 -ifqLen $val(ifqlen) \
                 -antType $val(ant) \
                 -propType $val(prop) \
                 -phyType $val(netif) \
                 -channelType $val(chan) \
		 -topoInstance $topo \
		 -agentTrace ON \
                 -routerTrace OFF \
                 -macTrace OFF

#
#  Create the specified number of nodes [$val(nn)] and "attach" them
#  to the channel.

for {set i 0} {$i < $val(nn) } {incr i} {
	set node_($i) [$ns node]
	$node_($i) random-motion 0		;# disable random motion

}
#
# Provide initial (X,Y, for now Z=0) co-ordinates for mobilenodes
for {set i 0} {$i < $val(nn) } {incr i} {
    $node_($i) set X_ 100*$i
    $node_($i) set Y_ 100*$i
    $node_($i) set Z_ 0.0
}

#


#
for {set i 0} {$i < $val(nn)*($val(nn)-1) } {incr i} {
    set udp($i) [new Agent/CBR/UDP]
    $ns attach-agent $node_([expr $i%$val(nn)]) $udp($i)
}

for {set i 0} {$i < $val(nn) } {incr i } {
    set null($i) [new Agent/LossMonitor]
    $ns attach-agent $node_($i) $null($i)
}

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

    for {set j 0} {$j < ($val(nn)-1) } {incr j} {
	$ns connect $udp([expr ($i+$j*($val(nn)))]) $null([expr 
($i+$j+1)%$val(nn)])}}

for {set i 0} {$i < $val(nn)*($val(nn)-1) } {incr i} {
    set exp($i) [new Application/Traffic/Exponential]
    $exp($i) set packetSize_ 500
    $exp($i) set burst_time_ 3
    $exp($i) set idle_time_ 1
    $exp($i) set rate_ 1000
    $exp($i) attach-agent $udp([expr ($i)%$val(nn)])}


for {set i 0} {$i < $val(nn)*($val(nn)-1) } {incr i} {
    $ns at 5.0 "$exp($i) start" }



# Define node initial position in nam

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

    # 20 defines the node size in nam, must adjust it according to your 
scenario
    # The function must be called after mobility model is defined

    $ns initial_node_pos $node_($i) 20
}

proc record {} {
	global null(0) null(1) null(2) null(3) null(4) f(0) f(1) f(2) f(3) f(4)
	set time 0.1
	for {set i 0} {$i < 5} {incr i} {
	    set bw($i) [$null($i) set bytes_]
	    }
	set now [$ns now]
	for {set i 0} {$i < 5} {incr i} {
	    puts $f($i) "$now [expr $bw($i)/$time*8/1000000]"
	    $null($i) set bytes_ 0
	    }
	$ns at [expr $now+$time] "record"
}


$ns at 0.0 "record"

#Call the finish procedure after 5 seconds of simulation time
$ns at 20 "finish"

#
# Tell nodes when the simulation ends
#
for {set i 0} {$i < $val(nn) } {incr i} {
    $ns at $val(stop).0 "$node_($i) reset";
}

$ns at  $val(stop).0002 "puts \"NS EXITING...\" ; $ns halt"


puts "Starting Simulation..."
$ns run






_________________________________________________________________
Downloaden Sie MSN Explorer kostenlos unter http://explorer.msn.de/intl.asp