Procedure calling in ns2

  • The calling procedure in tcl using the following command
  • Example-1: Without Arguments

    set ns [new Simulator] ;# Simulator instance
    $ns at 5.0 “add1”
    set a 10
    set b 15
    proc add1 {} {
    global a b ns
    set currentTime [$ns now]
    puts "Current Time=$currentTime"
    set value [expr $a+$b]
    puts "value = $value"
    }

  • Example-2: With Arguments Passing

    set ns [new Simulator] ;# Simulator instance
    $ns at 5.0 "add2 10 40" ;# Calling add2 at 5.0
    $ns at 12.0 "add2 10 50" ;# Calling add2 at 12.0
    proc add2 {p q} {
    global ns
    set result [expr $p*$q]
    puts "result=$result"
    }
    where,
    ns → Simulator instance
    global → Accessing the outside variable
    now → Return the current execution time of the procedure