Sie sind auf Seite 1von 19

NS2Tutorial

KameswariChebrolu Dept.ofComputerScienceandEngineering, IITBombay

MotivationforSimulations

Cheapdoesnotrequirecostlyequipment Complexscenarioscanbeeasilytested Resultscanbequicklyobtainedmoreideascan betestedinasmallertimeframe Therealthingisn'tyetavailable Controlledexperimentalconditions

Repeatabilityhelpsaiddebugging

Disadvantages:Realsystemstoocomplexto model

FeaturesofNS2

Protocols:TCP,UDP,HTTP,Routingalgorithms, MACetc TrafficModels:CBR,VBR,Webetc ErrorModels:Uniform,burstyetc Misc:Radiopropagation,Mobilitymodels,Energy Models TopologyGenerationtools Visualizationtools(NAM),Tracing

NSisanobjectorienteddiscreteeventsimulator

NSStructure

Simulatormaintainslistofeventsandexecutesoneeventafter another Singlethreadofcontrol:nolockingorraceconditions Protocolsmostly Fasttorun,morecontrol Creatingscenarios,extensionstoC++protocols fasttowriteandchange

BackendisC++eventscheduler

FrontendisoTCL

Variables: Arrays: Printing:

setx1 sety$x

TCLtutorial

seta(0)1 puts$a(0)\n setz=[expr$y+5]

ArithmeticExpression:

ControlStructures: if{$z==6}then{putsCorrect!}

for{seti=0}{$i<5}{incri}{ puts$i*$iequals[expr$i*$i] }

Procedures:

procsum{ab}{ return[expr$a+$b] }

NSprogrammingStructure

Createtheeventscheduler Turnontracing Createnetworktopology Createtransportconnections Generatetraffic Inserterrors

CreatingEventScheduler

Createeventscheduler:setns[newsimulator] Scheduleanevent:$nsat<time><event>

eventisanylegitimatens/tclfunction
$nsat5.0finish procfinish{}{ globalnsnf close$nf execnamout.nam& exit0 }

StartScheduler
$nsrun

Allpackettrace

Tracing

$nstraceall[openout.trw] <event><time><from><to><pkt><size> <flowid><src><dst><seqno><aseqno> +0.5101cbr50000.01.002 0.5101cbr50000.01.002 r0.51401cbr50000.01.000

Variabletrace

setpar[openoutput/param.trw] $tcpattach$par $tcptracecwnd_ $tcptracemaxseq_ $tcptracertt_

TracingandAnimation

NetworkAnimator

setnf[openout.namw] $nsnamtraceall$nf procfinish{}{ globalnsnf close$nf execnamout.nam& exit0 }

Creatingtopology

Twonodesconnectedbyalink Creatingnodes
setn0[$nsnode] setn1[$nsnode]

Creatinglinkbetweennodes

$ns<link_type>$n0$n1<bandwidth><delay> <queuetype>

$nsduplexlink$n0$n11Mb10msDropTail

Sendingdata

CreateUDPagent

setudp0[newAgent/UDP] $nsattachagent$n0$udp0 setcbr0[newApplication/Traffic/CBR] $cbr0setpacketSize_500 $cbr0setinterval_0.005 $cbr0attachagent$udp0 setnull0[newAgent/Null] $nsattachagent$n1$null0

CreateCBRtrafficsourceforfeedingintoUDPagent

Createtrafficsink

Sendingdata

Connecttwoagents
$nsconnect$udp0$null0

Startandstopofdata
$nsat0.5$cbr0start $nsat4.5$cbr0stop

CreatingTCPConnections

CreateTCPagentandattachittothenode
settcp0[newAgent/TCP] $nsattachagent$n0$tcp0

CreateaNullAgentandattachittothenode
setnull0[newAgent/TCPSink] $nsattachagent$n1$null0

Connecttheagents

$nsconnect$tcp0$null0

TrafficontopofTCP

FTP
setftp[newApplication/FTP] $ftpattachagent$tcp0

Telnet
settelnet[newApplication/Telnet] $telnetattachagent$tcp0

IntroducingErrors

CreatingErrorModule
seterr[newErrorModel] $errunitpkt_ $errsetrate_0.01 $errranvar[newRandomVariable/Uniform] $errdroptarget[newAgent/Null]

InsertingErrorModule
$nslossmodel$err$n0$n1

Examples

UDPScript Tracing(wired,wireless,tcp) TCPwithoutLoss TCPwithLoss

NSInternals
n0
Port Classifier Addr Classifier entry_ Application/FTP dst_=1.0 Agent/TCP Linkn0n1

n1
Port Classifier Addr Classifier entry_ dst_=0.0 Agent/TCPSink

0 1

1 0

Linkn1n0

Summary

Simulatorshelpineasyverificationofprotocols inlesstime,money NSofferssupportforsimulatingavarietyof protocolsuitesandscenarios FrontendisoTCL,backendisC++ NSisanongoingeffortofresearchand development

ReferenceMaterial

http://www.isi.edu/nsnam/ns/

MarcGreis'tutorial JaeChungtutorial Nsmanual