What is ns2?
NS separates the data path implementation from control path implementations. In order to reduce packet and event processing time (not simulation time), the event scheduler and the basic network component objects in the data path are written and compiled using C++.
Characteristics of languages in ns2:
- It’s easy to use
- It’s flexible for integration
- Allows a fast development
- It’s free
- It provide a graphique platforms
Sample ns2 code:
In this section we learn about how to define if condition and loop conditions in ns2 tcl and also the procedure of arithmetic operation in tcl programming
#create a procedure Proc test{} { set a 11 set b 23 set c [expr $a + $b] set d [expr [expr $a - $b] * $c] puts “c = $c d = $d” for {set k 0} {$k , 10} {incr k} { if {$k < 5} { puts “k < 5, pow = [expr pow($d,$k)]” }else { Puts “k >=5, mod = [expr $d % $k]” } } } #calling procedure test //if conditions If {expression}{ <execute some commands> } else { <execute commands> } ///loop conditions For {set i o} {$i < 5} {incr i} { <execute commands> }
Journal Support for NS2 Projects: