NS2 SIMULATOR CODE

  • Network Simulator 2 is focused for modeling network protocols
  • From Ns2 we can evolve fundamentals of network performance
  • A package of tools that simulates networks behavior

Ns-nam interface:

  • Color
  • Node manipulation
  • Link manipulation
  • Topology layout
  • Protocol state
  • Misc

Ns Features:

  • Areas in wired domain
  • LAN
  • Multicast
  • Full TCP
  • Applications like web-mining
  • Diffserv/intserv
  • Wireless domain
  • Mobile IP
  • Satellite networking
  • Ad hoc routing
  • Sensor networks
  • Emulator
  • Connect simulator in real time network
  • Send and receive live packets

Components of NS2:

  • Ns
  • Nam
  • Xgraph
  • Pre-processing
  • Post-processing

NS-2 Generic Script Structure:

  • Create Simulator object
  • [Turn on tracing]
  • Create topology
  • [Setup packet loss, link dynamics]
  • Create routing agents
  • Create application and/or traffic sources
  • Post-processing (nam)
  • Start simulation

Visualization tools in NS2:

  • Nam-1(Packet level animation)
  • Xgraph

 

NS2 Simulator CODE:

# Create a dumbbell topology
$ns duplex-link $s(0) $n(0) 1Mb 5ms DropTail
$ns duplex-link $s(1) $n(0) 1Mb 5ms DropTail

$ns duplex-link $n(0) $n(1) 1Mb 20ms RED/myRIO
$ns duplex-link $n(1) $n(2) 700Kb 25ms RED/myRIO

$ns duplex-link $n(2) $r(0) 1Mb 5ms DropTail
$ns duplex-link $n(2) $r(1) 1Mb 5ms DropTail

# Load a size-aware classifier to node 0
set cls [new Classifier/Hash/SizeAware 128]
$cls set default_ -1
$cls set flowlen_thr_ 5
$cls set refresh_intv_ 2
$cls set dynamic_update_ 0
set n(0) [node_with_classifier $cls]