Vous êtes sur la page 1sur 20

Network Simulation Using Ns2

Zaid Munir NUCES FAST, Lahore Campus

Adapted from Jianping Wang's slides

Network Simulator v2

Todays objective

What is network simulation? Why simulate? What is ns2? How to work in ns2, the basics Example

Real life computer networks


Very complex Can be as small as a two nodes Can even span up to millions of nodes

Internet Kisi baat se! Cost of failed experiment can be in millions per second

Experimentation with live networks


How to test and design?

Simulation

No danger of messing things up Can experiment with many radical ideas Verify the workability of a proposed algorithm

NS2

Discrete event simulator Works at packet level Support for many commonly used protocols

TCP, UDP, HTTP, FTP, IP

Can simulate wired and wireless networks Is primarily Unix based Uses TCL as scripting language Widely used in the research community

Ns2 explained

otcl: Object-oriented support tclcl: C++ and otcl linkage Discrete event scheduler Data components

Ns2 implementation

Why the need for two languages

C++

The actual implementation is done in C++ Manipulation

Bytes, packets, algorithms Comile, debug, correct, very slow process

Difficult to debug

Tcl

Quickly create many different scenarios Time to create and test scenarios is short

Basic tcl

proc test {} { set a 43 set b 27 set c [expr $a + $b] set d [expr [expr $a - $b] * $c] for {set k 0} {$k < 10} {incr k} { puts k = $k } }

Basic Otcl

Class mom mom instproc greet {} { $self instvar age_ puts $age_ years old mom: How are you doing? } Class kid -superclass mom kid instproc greet {} { $self instvar age_ puts $age_ years old kid: Whats up, dude? }

set a [new mom] $a set age_ 45 set b [new kid] $b set age_ 15 $a greet $b greet

Ns 2

Deals with all the layers Create network (physical layer) Create link and queue (data-link layer) Define routing protocol Create transport connection (transport layer) Create traffic (application layer) To test your scenario you can even insert errors

Our simulation scenario

First step

set ns [new Simulator]

Creating nodes and physical connections

set s1 [$ns node] set s2 [$ns node] set router [$ns node] set d [$ns node] $ns duplex-link $s1 $router 1.5Mb 15ms DropTail $ns duplex-link $s2 $router 1.5Mb 15ms DropTail $ns duplex-link $router $d 2Mb 15ms DropTail $ns queue-limit $s1 $router 50

Setting up the transport layer

set tcpSender1 [$ns create-connection TCP $s1 TCPSink $d 0] set tcpSender2 [$ns create-connection TCP $s2 TCPSink $d 1]

Setting up application layer


set ftp1 [new Application/FTP] $ftp1 attach-agent $tcpSender1 set ftp2 [new Application/FTP] $ftp2 attach-agent $tcpSender2

Controlling the events


$ns at 0.0 "$ftp1 start" $ns at 0.0 "$ftp2 start" $ns run

Ending the simulation


proc finish { } { puts "Complete."; exit 1 } $ns at 5.0 "finish"

How to know what happened?

Setting up trace files


set trace [open trace.tr w] $ns trace-all $trace

Refrences

http://www.cs.virginia.edu/~cs757/slidespdf/cs75 7-ns2-tutorial1.pdf http://sharpenyourteeth.net/downloads/tcl_ns2.pdf http://www.isi.edu/nsnam/ns/tutorial/

Vous aimerez peut-être aussi