Ok, I'm going to tell you how I exactly do it. You  need 2 files: an script 
file and a .tcl file. In the script file, which is a simple text  file with 
execute access (to run it just type ./script in the linux command  line), write 
something like:
  
 # ----------------- script  
----------------------------------------------------------------------------------
 for parameter1 in 0 1 2 3 4
do
    for parameter2 in 10.0 15.0
     do
        ns myfile.tcl -parameter1 $parameter1 -parameter2  $parameter2
    done
done
 # ----------------- end script  
------------------------------------------------------------------------------
  
  
 In myfile.tcl, you must add the 'getopt'  procedure:
  
 # ----------------- myfile.tcl   ------------------------------------------
  
 #  =====================================
#  Define Options
#  ======================================
set  opt(chan) Channel/WirelessChannel
set opt(prop)  Propagation/TwoRayGround
set opt(netif) Phy/WirelessPhy
set opt(mac)  Mac/802_11
set opt(ifq) CMUPriQueue ;# Queue/DropTail/PriQueue
set opt(ll)  LL
set opt(ant) Antenna/OmniAntenna
set opt(x) X ;# X dimension of the  topography
set opt(y) Y ;# Y dimension of the topography
set opt(ifqlen)  10 ;# max packet in ifq
set opt(seed) 0.4 
set opt(tr) FTrace.tr ;# trace  file
set opt(adhocRouting) DSR
set opt(nn) Nbnode ;# how many nodes are  simulated
set opt(cp) "../Scenarios de trafic/CBR/Ftraf" 
set opt(sc)  "../Scenarios de mobilite/FMob" 
set opt(stop) Time ;# simulation  time
  
 set opt(parameter1) 0    ;# default  value
 set opt(parameter2) 10.0    ;# default  value
  
 #  ======================================
#  Procedures
#  ======================================
 proc getopt {argc argv} {
    gloval opt
    lappend optlist  parameter1 parameter2
    for {set i 0} {$i < $argc} {incr i} {
         set arg [lindex $argv $i]
         if {[string range $arg 0 0] != "-"}  continue
        set name [string range $arg 1 end]
        set opt($name)  [lindex $argv [expr $i+1]]     ;# here the values of 
opt(parameter1) and  opt(parameter2) 
                                                                              
;# are asigned and you can use them in the Main Program
     }
}


#  ==================================
# Main  Program
#  =================================
#  Initialize Global Variables
# create simulator instance
set ns_ [new  Simulator]

# set wireless channel, radio-model and topography  objects
set wtopo [new Topography]

# create trace object for ns and  nam
set tracefd [open $opt(tr) w]
$ns_ trace-all $tracefd

set  namtrace [open FNam.nam w]
$ns_ namtrace-all-wireless $namtrace $opt(x)  $opt(y)

# use new trace file format
$ns_ use-newtrace 

# define  topology
$wtopo load_flatgrid $opt(x) $opt(y)

# Create God
set god_  [create-god $opt(nn)]
# create channel #1 and #2
set chan_1_ [new  $opt(chan)]
set chan_2_ [new $opt(chan)]

# define how node should be  created
#global node setting
$ns_ node-config -adhocRouting  $opt(adhocRouting) \
-llType $opt(ll) \
-macType $opt(mac) \
-ifqType  $opt(ifq) \
-ifqLen $opt(ifqlen) \
-antType $opt(ant) \
-propType  $opt(prop) \
-phyType $opt(netif) \
-topoInstance $wtopo \
-agentTrace  ON \
-routerTrace ON \
-macTrace ON \
-movementTrace OFF \
-channel  $chan_1_

# Create the specified number of nodes [$opt(nn)] and "attach"  them
# to the channel. 
for {set i 0} {$i < $opt(nn) } {incr i}  {
set node_($i) [$ns_ node] 
$node_($i) random-motion 0 ;# disable random  motion
}

# Define node movement model
puts "Loading connection  pattern..."
source $opt(cp)

# Define traffic model
puts "Loading  scenario file..."
source $opt(sc)

# Define node initial position in  nam
for {set i 0} {$i < $opt(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
}

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

# tell nam the simulation stop time
#$ns_ at $opt(stop)  "$ns_ nam-end-wireless $opt(stop)"
$ns_ at $opt(stop) "stop"
$ns_ at  $opt(stop).000000001 "puts \"NS EXITING...\" ; $ns_ halt"

proc stop {}  {
global ns_ tracefd namtrace
$ns_ flush-trace
close $tracefd
close  $namtrace

exec rm -f FText.txt
exec touch FText.txt

exec awk {  
{
if (($1 == "s") || ($1 == "f") || ($1 == "d") || ($1 ==  "r"))
{
if ($41 == "") { print $1,$2, $3, $19, "/", "/", "0" }
else {  print $1, $2, $3, $19, $35, $40, $41 }
}
} 
} FTrace.tr >  FText.txt

puts "running nam..."
exec nam FNam.nam &

exit  0
}

puts "Starting Simulation..."
$ns_ run

  
 # ----------------- end myfile.tcl  --------------------
 
 


molo badji <[EMAIL PROTECTED]> escribió: Hi,
   
  I try to do what you said but always a problem. The program called 
Exp_DSR.tcl is correct and Ì introduce the procedure proc getopt {argc argv}. 
The following script is the problem now. I call him TousExp_DSR.tcl and when I 
execute it like this : ns TousExp_DSR.tcl I had this error message :
   
    warning: using backward compatibility mode

    (ns cmd line 1)
    invoked from within
    .........
    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 "ns" line 2)
    (SplitObject unknown line 2)
    invoked from within

   
    That’s the script TousExp_DSR.tcl
   

  set scdeb "../rep/Scen-mob-50-20-"
  set cpdeb "../rep2/Scen-Cbr-50-1.0-"
  set trdeb  "Scen-50-"
   
    for {set pause 0} {$pause < 700} {set pause [expr $pause + 100]} {
    set scint "${scdeb}$pause-600-500x500."
    for {set trafic 10} {$trafic < 50} {set trafic [expr $trafic + 10]} {
      set cp "${cpdeb}$trafic-1.0-4"
      for {set nbexp 1} {$nbexp < 6} {incr nbexp} {
          set sc "${scint}$nbexp"
          set ext "${trdeb}$pause-$nbexp.txt"
          set na "${trdeb)}$pause-$nbexp.nam"
          set tr "${trdeb}$pause-$nbexp.tr"
          
            ns Exp_Dsr.tcl -cp $cp -sc $sc -tr $tr -na $na
            
        }
    }
}
   

  

Miguel Sepulcre Ribes <[EMAIL PROTECTED]> a écrit :
  
You  could run a script like:
for parameter1 in 0 1 2 3 4
do
for parameter2 in 10.0 15.0
do
ns myfile.tcl -parameter1 $parameter1 -parameter2 $parameter2
done
done
Don't forget to add the parameters that you want to be modified in your .tcl 
file:
proc getopt {argc argv} {
gloval val
lappend optlist parameter1 parameter2
for {set i 0} {$i < $argc} {incr i} {
set arg [lindex $argv $i]
if {[string range $arg 0 0] != "-"} continue
set name [string range $arg 1 end]
set val($name) [lindex $argv [expr $i+1]] 
}
}




molo badji escribió: 
Hello,

Could someone help me in explaining how to create a script which execute many 
simulation of a protocol of ad hoc networj with differents mobility and traffic 
model files. For exemple I have this script and I want to write a TCL script 
which permits to execute this script many times in changing only parameters 
like X, Y, FTrace.tr, Nbnode,  FTraf, FMob, FNam.nam, Time, FTest.txt.

Thanks in advance.

Molo.

# =====================================================================
# Define Options
# ======================================================================
set opt(chan) Channel/WirelessChannel
set opt(prop) Propagation/TwoRayGround
set opt(netif) Phy/WirelessPhy
set opt(mac) Mac/802_11
set opt(ifq) CMUPriQueue ;# Queue/DropTail/PriQueue
set opt(ll) LL
set opt(ant) Antenna/OmniAntenna
set opt(x) X ;# X dimension of the topography
set opt(y) Y ;# Y dimension of the topography
set opt(ifqlen) 10 ;# max packet in ifq
set opt(seed) 0.4 
set opt(tr) FTrace.tr ;# trace file
set opt(adhocRouting) DSR
set opt(nn) Nbnode ;# how many nodes are simulated
set opt(cp) "../Scenarios de trafic/CBR/Ftraf" 
set opt(sc) "../Scenarios de mobilite/FMob" 
set opt(stop) Time ;# simulation time

#  ======================================================================
# Main Program
# ======================================================================
# Initialize Global Variables
# create simulator instance
set ns_ [new Simulator]

# set wireless channel, radio-model and topography objects
set wtopo [new Topography]

# create trace object for ns and nam
set tracefd [open $opt(tr) w]
$ns_ trace-all $tracefd

set namtrace [open FNam.nam w]
$ns_ namtrace-all-wireless $namtrace $opt(x) $opt(y)

# use new trace file format
$ns_ use-newtrace 

# define topology
$wtopo load_flatgrid $opt(x) $opt(y)

# Create God
set god_ [create-god $opt(nn)]
# create channel #1 and #2
set chan_1_ [new $opt(chan)]
set chan_2_ [new $opt(chan)]

# define how node should be created
#global node setting
$ns_ node-config -adhocRouting $opt(adhocRouting) \
-llType $opt(ll) \
-macType $opt(mac)  \
-ifqType $opt(ifq) \
-ifqLen $opt(ifqlen) \
-antType $opt(ant) \
-propType $opt(prop) \
-phyType $opt(netif) \
-topoInstance $wtopo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace OFF \
-channel $chan_1_

# Create the specified number of nodes [$opt(nn)] and "attach" them
# to the channel. 
for {set i 0} {$i < $opt(nn) } {incr i} {
set node_($i) [$ns_ node] 
$node_($i) random-motion 0 ;# disable random motion
}

# Define node movement model
puts "Loading connection pattern..."
source $opt(cp)

# Define traffic model
puts "Loading scenario file..."
source $opt(sc)

# Define node initial position in nam
for {set i 0} {$i < $opt(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
}

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

# tell nam the simulation stop time
#$ns_ at $opt(stop) "$ns_ nam-end-wireless $opt(stop)"
$ns_ at $opt(stop) "stop"
$ns_ at $opt(stop).000000001 "puts \"NS EXITING...\" ; $ns_ halt"

proc stop {} {
global ns_ tracefd namtrace
$ns_ flush-trace
close $tracefd
close $namtrace

exec rm -f FText.txt
exec touch FText.txt

exec awk { 
{
if (($1 == "s") || ($1 == "f") || ($1 == "d") || ($1 == "r"))
{
if ($41 == "") { print $1,$2, $3, $19, "/", "/", "0" }
else { print $1, $2, $3, $19, $35, $40, $41 }
}
} 
} FTrace.tr > FText.txt

puts "running nam..."
exec nam FNam.nam &

exit 0
}

puts "Starting Simulation..."
$ns_ run



---------------------------------
Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions ! 
Demandez à  ceux qui savent sur Yahoo! Questions/Réponses.



---------------------------------

LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y móviles desde 1 céntimo por minuto.
http://es.voice.yahoo.com

    

---------------------------------
 Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions !  
Demandez à ceux qui savent sur Yahoo! Questions/Réponses.

                
---------------------------------

LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y móviles desde 1 céntimo por minuto.
http://es.voice.yahoo.com

Reply via email to