Run Time Arguments in ns2

  • The number of arguments in the network varies dynamically during the runtime by using the following command
  • Example1:

    if {$argc != 1}
    {
    error "\nCommand: ns filename.tcl \n\n "
    }
    set total_nodes [lindex $argv 0]</li>
    </ul>
    where,

    $argc → number of run time arguments

    lindex $argv 0 → value of the number of nodes

  • Example2:

    if {$argc != 2}
    {
    Error "\nCommand: ns filename.tcl \n\n "
    }
    set total_nodes [lindex $argv 0] ;# 1st run time argument
    set communication range [lindex $argv 1] ;# 2nd run time argument
    where,
    argc -> number of run time arguments.
    lindex $argv 0 → value of the number of nodes
    lindex $argv 1 → value of the communication range