Amazing technological breakthrough possible @S-Logix pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to call the procedure 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