Hello everyone,
I am trying to run wireless video transmission analysis using myevalvid on ns2.35 using the Fedora virtual machine made by Smallko for my thesis.
The ns2.35 along with the myevalvid agent is preinstalled on the virtual machine. The scripts for the simulation is also there, so I suppose I should be able to run it without any edit.
I ran the wired simulation (file name wired.tcl) without modifications again and again, it always ran fine and gives the right result.
But when I tried to run the wireless simulation, it always result in this error:
Code:
[ns235@localhost myevalvid]$ ns wireless.tcl
can't read "opt(0)": no such element in array
while executing
"set loss_model $opt(0)"
(file "wireless.tcl" line 12)
This is the script:
Code:
proc getopt {argc argv} {
global opt
lappend optlist nn
for {set i 0} {$i < $argc} {incr i} {
set opt($i) [lindex $argv $i]
}
}
getopt $argc $argv
#loss_model: 0 for uniform distribution, 1 for GE model
set loss_model $opt(0)
set pGG $opt(1)
set pBB $opt(2)
set pG $opt(3)
set pB $opt(4)
#===================================
# Simulation parameters setup
#===================================
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) 2 ;# number of mobilenodes
set val(rp) AODV ;# routing protocol
set val(x) 500 ;# X dimension of topography
set val(y) 500 ;# Y dimension of topography
set val(stop) 50.0 ;# time of simulation end
Mac/802_11 set dataRate_ 2Mb
Mac/802_11 set basicRate_ 1Mb
#===================================
# 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
set chan [new $val(chan)];#Create wireless channel
#===================================
# Mobile node parameter setup
#===================================
$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) \
-channel $chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace OFF \
-macTrace ON \
-movementTrace OFF
#===================================
# Nodes Definition
#===================================
#Create 3 nodes
set n0 [$ns node]
$n0 set X_ 200
$n0 set Y_ 400
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
$n1 set X_ 300
$n1 set Y_ 400
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20
set n0if_ [$n0 set netif_(0)]
$n0if_ set-error-level $pGG $pBB $pG $pB $loss_model
set n1if_ [$n1 set netif_(0)]
$n1if_ set-error-level $pGG $pBB $pG $pB $loss_model
#===================================================
set max_fragmented_size 1024
#8 bytes:UDP header, 12 bytes: RTP header
set packetSize [expr $max_fragmented_size+20]
set src_udp1 [new Agent/my_UDP]
$src_udp1 set packetSize_ $packetSize
$src_udp1 set_filename wireless_sd
set dst_udp1 [new Agent/myEvalvid_Sink]
$ns attach-agent $n0 $src_udp1
$ns attach-agent $n1 $dst_udp1
$ns connect $src_udp1 $dst_udp1
$dst_udp1 set_filename wireless_rd
set original_file_name foreman_qcif.st
set trace_file_name video1.dat
set original_file_id [open $original_file_name r]
set trace_file_id [open $trace_file_name w]
set pre_time 0
while {[eof $original_file_id] == 0} {
gets $original_file_id current_line
scan $current_line "%d%s%d%d%f" no_ frametype_ length_ tmp1_ tmp2_
set time [expr int(($tmp2_ - $pre_time)*1000000.0)]
if { $frametype_ == "I" } {
set type_v 1
set prio_p 0
}
if { $frametype_ == "P" } {
set type_v 2
set prio_p 0
}
if { $frametype_ == "B" } {
set type_v 3
set prio_p 0
}
if { $frametype_ == "H" } {
set type_v 1
set prio_p 0
}
puts $trace_file_id "$time $length_ $type_v $prio_p $max_fragmented_size"
set pre_time $tmp2_
}
close $original_file_id
close $trace_file_id
set end_sim_time $tmp2_
puts "$end_sim_time"
set trace_file [new Tracefile]
$trace_file filename $trace_file_name
set video1 [new Application/Traffic/myEvalvid]
$video1 attach-agent $src_udp1
$video1 attach-tracefile $trace_file
$ns at 0.5 "$video1 start"
$ns at 30.0 "$video1 stop"
#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile src_udp1 dst_udp1
$ns flush-trace
close $tracefile
$src_udp1 closefile
$dst_udp1 closefile
puts "simulation completed"
exit 0
}
for {set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "\$n$i reset"
}
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run
I have looked everywhere and the suggested solution for similar problem is to reduce the number of nodes by 1. I have tried it and it doesn't solve the error.
Please help me with solving this. I'm a newbie to both coding and NS but I am willing to learn.
Thank you.