Introduction to NS-2

Preview:

DESCRIPTION

Introduction to NS-2. Xiaohua Tian Illinois Institute of Technology. What is NS-2 ?. NS is a event driven network simulator that simulates variety of IP networks NS implements Network Protocols : TCP, UDP Traffic behavior : FTP, Telnet, CBR, VBR - PowerPoint PPT Presentation

Citation preview

Introduction to NS-2

Xiaohua Tian Illinois Institute of Technology

What is NS-2 ?

NS is a event driven network simulator that simulates variety of IP networks

NS implements Network Protocols : TCP, UDP Traffic behavior : FTP, Telnet, CBR, VBR Router Queue Management : Drop Tail, RED, CBQ Routing algorithms : Dijkstra Adhoc routing, Sensor Networks Multicasting , MAC layer protocols Wired, Wireless, Satellite

NS-2 Software Structure NS simulator is based on 2 languages

C++ Used to implement the protocols For example implementation of Mac 802.11 in ~ns/ns-2.30/m

ac/802_11.[cc,h] Advantage

Reduce packet and event processing time

Otcl Used to configure the topology, the nodes, the channel, to sc

hedule the eventsAdvantage

Easy to change model and re-runFlexible for integration

C++ and Otcl Duality C++ and Otcl Duality

Architectural View of NS

General Simulation Process

NS usersAdd or modifyC++ classes

RecompileNS

Write Otclscripts

Run NSAnalyze

simulationresults

Finalresults

Modify Otclscripts

Modify C++codes

Installation (windows environment)

1. Install cygwin:

www.cygwin.com

Cygwin installation

Cygwin installation

Cygwin installation

Cygwin installation

Cygwin installation

Cygwin installation

Cygwin installation

2. NS-2.30 installation

copy the ns-allinone-2.30.tar.gz (from Blackboard) file in your Cygwin home directory (typically something like C:\cygwin\home\John)

Launch Cygwin, a command line window should appear. Type the following commands:

gzip -d -c ns-allinone-2.30.tar.gz | tar xvf – (or use winrar to unpack the package)

cd ns-allinone-2.30 ./install

2. Environment variable config

Environment variable config

Environment variable config

Environment variable config Path:  C:\cygwin\home\username\ns-allino

ne-2.30\bin;

TCL_LIBRARY:  C:\cygwin\home\username\ns-allinone-2.30\tcl8.4.13

LD_LIBRARY_PATH:    C:\cygwin\home\username\ns-allinone-2.30\otcl-1.12

3. Steps to set up the simulation

Initialize the simulator Define files for output (tracing) Set up the topology Set up the “agents” Set up the traffic between the nodes Start the simulation Analyze the trace files to compute the

parameters of interest

Setting Up Variables

Initialize the Simulator set ns_ [new Simulator]

Setup Trace File set tracefile [open simple.tr w]

$ns_ trace-all $tracefile

Setup NAM trace file set namfile [open out.nam w]

$ns_ namtrace-all $namfile

Set up the topology

Create 2 nodes n0 and n1set n0 [$ns_ node]

Set n1 [$ns_ node]

Create Duplex-Link between n0 and n1

$ns_ duplex-link $n0 $n1 2Mb 10ms DropTail

n0 n1

2Mb of Capacity

Bi-directional link

10ms Propagation Delay

Setup traffic flow

Setup a TCP connectionSet tcp [new Agent/TCP]

$ns_ attach-agent $n0 $tcp

Set sink [new Agent/TCPSink]

$ns_ attach-agent $n1 $sink

$ns_ connect $tcp $sink

Setup a FTP over TCPSet ftp [new Application/FTP]

$ftp attach-agent $tcp

n0 n1

TCP

FTP

Sink

Set Stop Time and Start Simulation

$ns_ at 0.1 “$ftp start”$ns_ at 10.0 “$ftp stop”$ns_ at 10.1 “finish”$ns run // Starting simulation

// Define a Finish procedureProc finish {} {

global ns_ tracefile namfile$ns_ flush-traceclose $tracefileclose $namfileexec nam out.nam & // Calling NAMexit 0

}

Running the Script and Using NAM

ns filename.tcl The simulation will generate the trace file simple.tr NAM can be run in 2 ways

Inside TCL file “ exec nam out.nam &” Outside TCL file “ nam out.nam”

NAM Screenshot

Trace Files

Working with Trace Files

To compute Throughput, Jitter, End to End DelayProcess trace files with any of these utilities

1) AWK2) GREP3) PERL

To plot the graph 1) gnuplot2) xgraph

In Tcl : exec xgraph out.tr &Out Tcl : xgraph out.tr

Screenshot of XGRAPH

Conclusion

References

http://www.cygwin.com/ http://www.isi.edu/nsnam/ns/ns-docu

mentation.htmlContains the NS manual detailed documentation of the source code

http://nile.wpi.edu/NS/

Recommended