Friday, July 13, 2018

How To Utilisation Physical Care For Inwards Ns2

Procedure inwards Ns2:

A physical care for is a small-scale slice of code that is used to perform exactly about specific chore similar runni How to Create Procedure inwards Ns2

A physical care for is a small-scale slice of code that is used to perform exactly about specific chore similar running, closing too executing etc. This slice of code is called at halt of the program. Below yous tin sack run across the code for a physical care for that ordinarily used inwards unproblematic ns Program.

Example of Procedure:

# Define a ‘finish’ procedure
proc complete {} {
          global ns tracefile1 namfile
          $ns flush-trace
          #Close the NAM delineate file
          close $tracefile1
          #Close the NAM file
          close $namfile
          #Execute NAM on the delineate file
          exec nam out.nam &
          exit 0
}

Program Explanation:

proc complete {} {

The give-and-take “proc” is used to declare physical care for too “finish” is the mention of the procedure. So nosotros declare a physical care for amongst mention complete without whatever arguments. You tin sack every 2nd good declare physical care for amongst arguments. You tin sack run across the event below at the halt of the post.


global ns tracefile1 namfile

If yous convey travel unproblematic ns programs earlier thence yous must live on familiar amongst
Nam-file too trace-file but if non thence don’t worry yous tin sack banking concern jibe it here.
Simple wired too wireless ns2 Programs code
Here amongst the assistance of give-and-take global, nosotros tell to the physical care for that the variable nosotros using hither is declared exterior the procedure.

$ns flush-trace
“flush-trace” volition dump the traces on the respective files.

close $tracefile1 too close $namfile
The unopen ascendancy merely closes both nam-file too trace-file that nosotros define at the root of the ns programme code.

exec nam out.nam &
The give-and-take “exec” is used to execute the nam programme for visualization that nosotros created at the root of the program.

exit 0
The ascendancy cash inwards one's chips volition halt the application too supply the expose 0 every 2nd condition to the system. Zero is the default for a build clean exit. Other values tin sack live on used to tell that it is an cash inwards one's chips because something fails.

$ns at 125.0 "finish"
At the halt of the program, nosotros volition telephone phone the physical care for “finish” that nosotros created early on too specify at what fourth dimension the final result should occur. For example, volition live on used to telephone phone “finish" at fourth dimension 125 sec.

Reference Site:
1) http://nile.wpi.edu/NS/
2) http://www.ece.ubc.ca/%7Eteerawat/NS2.htm

Sharing is caring ... Don't forget to portion it amongst friends