[ns] What's wrong with that code?
giantpassos
giantpassos at ig.com.br
Mon Jan 22 08:34:11 PST 2007
Hi everybody,
Could someone show me the errors in this source code.
Regards,
Diego Passos.
# ====================================================================
# Define Node Configuration paramaters
#====================================================================
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) 11 ;# number of mobilenodes
set val(rp) DSDV ;# routing protocol
set val(x) 1000 ;# X dimension of the
topography
set val(y) 1000 ;# Y dimension of the
topography
Mac/802_11 set RTSThreshold_ 3000
Mac/802_11 set basicRate_ 1Mb
Mac/802_11 set dataRate_ 2Mb
# *** Initialize Simulator ***
set ns [new Simulator]
# *** Initialize Trace file ***
set tracefd [open out.tr w]
$ns trace-all $tracefd
# *** Initialize Network Animator ***
set namtrace [open out.nam w]
$ns namtrace-all-wireless $namtrace $val(x) $val(y)
# *** set up topography object ***
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
# Create General Operations Director (GOD) object. It is used to store
global information about the state of the environment, network, or nodes
that an
# omniscent observer would have, but that should not be made known to any
participant in the simulation.
create-god $val(nn)
# configure nodes
$ns node-config -adhocRouting $val(rp) \
-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 ON \
-macTrace OFF \
-movementTrace OFF
for {set i 0} {$i < $val(nn) } {incr i} {
set node_($i) [$ns node]
$node_($i) random-motion 0 ;# disable random motion
}
$node_(0) set X_ 500.0
$node_(0) set Y_ 500.0
$node_(0) set Z_ 0.0
$ns initial_node_pos $node_(0) 20
for {set i 1} {$i < $val(nn)} {incr i} {
$node_($i) set X_ [expr (400+30*$i)]
$node_($i) set Y_ 400
$node_($i) set Z_ 0.0
$ns initial_node_pos $node_($i) 20
set agent($i) [new Agent/UDP] ;# Create TCP Agent
$agent($i) set prio_ [expr ($i)] ;# Set Its priority to 0
$ns attach-agent $node_(0) $agent($i) ;# Attach Agent to source node
set sink($i) [new Agent/LossMonitor] ;# Create Loss Monitor Sink in orde
to be able to trace the number obytes received
$ns attach-agent $node_($i) $sink($i) ;# Attach Agent to sink node
$ns connect $agent($i) $sink($i) ;# Connect the nodes
set app($i) [new Application/Traffic/CBR] ;# Create Constant Bit Rate
application
$app($i) set packetSize_ 512 ;# Set Packet Size to 512 bytes
$app($i) set rate_ 512Kb ;# Set CBR rate to 200
Kbits/sec
$app($i) attach-agent $agent($i) ;# Attach Application to agent
}
# Function To record Statistcis (Bit Rate, Delay, Drop)
for {set i 1} {$i < $val(nn)} {incr i} {
set t($i) [open throughput$i.tr w]
set d($i) [open delay$i.tr w]
set l($i) [open loss$i.tr w]
}
for {set i 1} {$i < $val(nn)} {incr i} {
set holdtime($i) 0
set holdseq($i) 0
set holdrate($i) 0
}
proc record {} {
set val(nn) 11
for {set i 1} {$i < $val(nn)} {incr i} {
global holdtime($i)
global holdseq($i)
global holdrate($i)
global t($i)
global d($i)
global l($i)
global sink($i)
}
set ns [Simulator instance]
set time 0.9 ;#Set Sampling Time to 0.9 Sec
for {set i 1} {$i < $val(nn)} {incr i} {
set bw($i) [$sink($i) set bytes_]
set nl($i) [$sink($i) set nlost_]
set lt($i) [$sink($i) set lastPktTime_]
set np($i) [$sink($i) set npkts_]
}
set now [$ns now]
for {set i 1} {$i < $val(nn)} {incr i} {
# Record Bit Rate in Trace Files
puts $t($i) "$now [expr ((($bw($i)+$holdrate($i))*8)/2*$time*1000000)]"
# Record Packet Loss Rate in File
puts $l($i) "$now [expr ($nl($i)/$time)]"
if { $bw($i) > $holdseq($i) } {
puts $d($i) "$now [expr (($lt($i) - $holdtime($i))/($np($i)
- $holdseq($i)))]"
} else {
puts $d($i) "$now [expr (($lt($i) - $holdseq($i)))]"
}
}
# Reset Variables
for {set i 1} {$i < $val(nn)} {incr i} {
$sink($i) set bytes_ 0
$sink($i) set nlost_ 0
}
for {set i 1} {$i < $val(nn)} {incr i} {
set holdtime($i) lt($i)
set holdseq($i) np($i)
set holdrate($i) bw($i)
}
$ns at [expr $now+$time] "record" ;# Schedule Record after $time interval
sec
}
$ns at 0.0 "record"
for {set i 1} {$i < $val(nn) } {incr i} {
$ns at 0.0 "$app($i) start"
}
# Stop Simulation at Time 80 sec
$ns at 80.0 "stop"
# Reset Nodes at time 80 sec
for {set i 0} {$i < $val(nn) } {incr i} {
$ns at 80.0 "$node_($i) reset";
}
# Exit Simulatoion at Time 80.01 sec
$ns at 80.1 "puts \"NS EXITING...\" ; $ns halt"
proc stop {} {
global ns tracefd
set val(nn) 11
for {set i 1} {$i < $val(nn)} {incr i} {
global t($i)
global d($i)
global l($i)
}
# Plot Recorded Statistics
exec xgraph throughput1.tr throughput2.tr throughput3.tr throughput4.tr
throughput5.tr throughput6.tr throughput7.tr throughput8.tr throughput9.tr
throughput10.tr -geometry 800x400 &
exec delay1.tr delay2.tr delay3.tr delay4.tr delay5.tr delay6.tr delay7.tr
delay8.tr delay9.tr delay10.tr -geometry 800x400 &
exec loss1.tr loss2.tr loss3.tr loss4.tr loss5.tr loss6.tr loss7.tr
loss8.tr loss9.tr loss10.tr -geometry 800x400 &
# Reset Trace File
$ns flush-trace
close $tracefd
exit 0
}
puts "Starting Simulation..."
$ns run
More information about the Ns-users
mailing list