11
Wired and wireless example T S PRADEEP KUMAR VIT University – Chennai Campus http://www.pradeepkumar.org [email protected] www.facebook.com/tspradeep 1

Wired and Wireless Examples in ns2

Embed Size (px)

Citation preview

Page 1: Wired and Wireless Examples in ns2

WiredandwirelessexampleTSPRADEEPKUMAR

VITUniversity–ChennaiCampushttp://[email protected]

www.facebook.com/tspradeep

�1

Page 2: Wired and Wireless Examples in ns2

WiredExample

�2

Page 3: Wired and Wireless Examples in ns2

WiredExample….• Thisnetworkconsistsof4nodes(n0,n1,n2,n3)asshowninabovefigure.

• Theduplexlinksbetweenn0andn2,andn1andn2have2Mbpsofbandwidthand10msofdelay.

• Theduplexlinkbetweenn2andn3has1.7Mbpsofbandwidthand20msofdelay.

• EachnodeusesaDropTailqueue,ofwhichthemaximumsizeis10.

�3

Page 4: Wired and Wireless Examples in ns2

WiredExample….#Createasimulatorobjectsetns[newSimulator]

#OpentheNAMtracefilesetnf[openout.namw]$nsnamtrace-all$nf

#colorfordataflow$nscolor1red$nscolor2blue

#Createfournodessetn0[$nsnode]setn1[$nsnode]setn2[$nsnode]setn3[$nsnode]

�4

Page 5: Wired and Wireless Examples in ns2

WiredExample….#Definea'finish'procedureprocfinish{}{globalnsnf$nsflush-trace#ClosetheNAMtracefileclose$nf#ExecuteNAMonthetracefileexecnamout.nam&exit0}

�5

Page 6: Wired and Wireless Examples in ns2

WiredExample….#Createlinksbetweenthenodes$nsduplex-link$n0$n22Mb10msDropTail$nsduplex-link$n1$n22Mb10msDropTail$nsduplex-link$n2$n31.7Mb20msDropTail

#SetQueueSizeoflink(n2-n3)to10$nsqueue-limit$n2$n310

#Givenodeposition(forNAM)$nsduplex-link-op$n0$n2orientright-down$nsduplex-link-op$n1$n2orientright-up$nsduplex-link-op$n2$n3orientright

#Monitorthequeueforlink(n2-n3).(forNAM)$nsduplex-link-op$n2$n3queuePos0.5

�6

Page 7: Wired and Wireless Examples in ns2

WiredExample….#SetupaTCPconnectionsettcp[newAgent/TCP]$tcpsetclass_2$nsattach-agent$n0$tcpsetsink[newAgent/TCPSink]$nsattach-agent$n3$sink$nsconnect$tcp$sink$tcpsetfid_1

�7

Page 8: Wired and Wireless Examples in ns2

WiredExample….#SetupaFTPoverTCPconnectionsetftp[newApplication/FTP]$ftpattach-agent$tcp$ftpsettype_FTP

#SetupaUDPconnectionsetudp[newAgent/UDP]$nsattach-agent$n1$udpsetnull[newAgent/Null]$nsattach-agent$n3$null$nsconnect$udp$null$udpsetfid_2 �8

Page 9: Wired and Wireless Examples in ns2

WiredExample….#SetupaCBRoverUDPconnectionsetcbr[newApplication/Traffic/CBR]$cbrattach-agent$udp$cbrsettype_CBR$cbrsetpacket_size_1000$cbrsetrate_1mb$cbrsetrandom_false

�9

Page 10: Wired and Wireless Examples in ns2

WiredExample….#ScheduleeventsfortheCBRandFTPagents$nsat0.1"$cbrstart"$nsat1.0"$ftpstart"$nsat4.0"$ftpstop"$nsat4.5"$cbrstop"

#Detachtcpandsinkagents(notreallynecessary)$nsat4.5"$nsdetach-agent$n0$tcp;$nsdetach-agent$n3$sink"

#Callthefinishprocedureafter5secondsofsimulationtime$nsat5.0"finish"

#PrintCBRpacketsizeandintervalputs"CBRpacketsize=[$cbrsetpacket_size_]"puts"CBRinterval=[$cbrsetinterval_]"

#Runthesimulation$nsrun

�10

Page 11: Wired and Wireless Examples in ns2

Output

�11