30
Introduction to NS-2 Xiaohua Tian Illinois Institute of Te chnology

Introduction to NS-2

  • Upload
    navid

  • View
    46

  • Download
    0

Embed Size (px)

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

Page 1: Introduction to NS-2

Introduction to NS-2

Xiaohua Tian Illinois Institute of Technology

Page 2: Introduction to NS-2

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

Page 3: Introduction to NS-2

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

Page 4: Introduction to NS-2

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

Architectural View of NS

Page 5: Introduction to NS-2

General Simulation Process

NS usersAdd or modifyC++ classes

RecompileNS

Write Otclscripts

Run NSAnalyze

simulationresults

Finalresults

Modify Otclscripts

Modify C++codes

Page 6: Introduction to NS-2

Installation (windows environment)

1. Install cygwin:

www.cygwin.com

Page 7: Introduction to NS-2

Cygwin installation

Page 8: Introduction to NS-2

Cygwin installation

Page 9: Introduction to NS-2

Cygwin installation

Page 10: Introduction to NS-2

Cygwin installation

Page 11: Introduction to NS-2

Cygwin installation

Page 12: Introduction to NS-2

Cygwin installation

Page 13: Introduction to NS-2

Cygwin installation

Page 14: Introduction to NS-2

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

Page 15: Introduction to NS-2

2. Environment variable config

Page 16: Introduction to NS-2

Environment variable config

Page 17: Introduction to NS-2

Environment variable config

Page 18: Introduction to NS-2

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

Page 19: Introduction to NS-2

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

Page 20: Introduction to NS-2

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

Page 21: Introduction to NS-2

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

Page 22: Introduction to NS-2

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

Page 23: Introduction to NS-2

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

}

Page 24: Introduction to NS-2

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”

Page 25: Introduction to NS-2

NAM Screenshot

Page 26: Introduction to NS-2

Trace Files

Page 27: Introduction to NS-2

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

Page 28: Introduction to NS-2

Screenshot of XGRAPH

Page 29: Introduction to NS-2

Conclusion

Page 30: Introduction to NS-2

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/