Page 1
ApplicationsApplicationsApplicationsApplicationsApplicationsApplicationsApplicationsApplications
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 1ed
pared
Prepa
PPook: T. Iss
yby
at rw
atcatcacacacacaca
Teplicalicalicalicalicalicalica
ulya
kul
sariy
a
Issa
Page 2
Outline• Application Overview
Timer• Timer• Two Derived Classes
– Traffic Generator– Simulated Application– Simulated Application
• Summary
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 2ed
y
pared
Prepa
PPook: T. Iss
p
by
Apat
erwat
ses
Teeeratori
ulya
kul
sariy
a
Issa
Page 3
A Two Node NetworkA Two Node NetworkA li iApplication
Source Agent Sink Agent
packetn0 n1
Link: Connecting Nodes
Buffer ManagementAgent:
Packet Creation andD Node:
A computer host + A router
gDestruction
Application: Demand Indication
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 3
A router
P
ed cket
paredDe
n: icatioare
d
Prepa
ook: T. Iss
pa
yby
AgentCr
at
erwatwa
Teeee
ulya
kul
k
sariy
ark
Issa
Page 4
Applicationd d d• Indicate user demand
• Two NS2 Applicationpp1. Traffic generator
– Conform to a predefined scheduleConform to a predefined schedule– E.G., CBR
2. Simulated applications– Create demand as if the application is– Create demand as if the application is
running– E.G. FTP
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 4
E.G., FTP
P
d
edde
are
e dening
.G. F
Prepa
ook: T. Iss
E.G.,yby
d app
at rw
atdefin
Tee
edef
ulya
kul
sariy
a
Issa
Page 5
NS2 Implementation• C++ Class Application
S ns/ pps/ pp h• See ~ns/apps/app.h,cc• Main variables: agent_g _
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 5PPrepook: T. Iss
at _
wat_
ulya
kul
sariy
a
Issa
Page 6
Functions of Class ApplicationFunctions of Class Application• send(nbytes): Tell TL to send out nbytes ofsend(nbytes): Tell TL to send out nbytes of
data ( agent_->sendmsg(nbyte) )
• recv(nbytes): Invoked by an agent; Be ( y ) y ginformed that nbytes are received.
• resume(): Invoked by sending agent when it h s s t t ll its p k tshas sent out all its packets
• start(): start the applicationst p(): st p th ppli ti n
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 6
• stop(): stop the applicationdIn
t
paredt out
(): stp():
Prepa
ook: T. Iss
op(): yI
byhat nbvoke
at
Teenvo
ulak
ultio
ariycati
out n
Iss
outbyte)
Page 7
OTcl Commands of Class Applicationpp
• start{}: start the applicationstart{}: start the application• stop{}: stop the application• attach-agent{$agent}: create a
two way connection to $agenttwo-way connection to $agent
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 7ed
pared
Prepa
PPook: T. Iss
n
by
conntppl
erwaappl
e app
Teent{$ag
ulya
kul
sariy
aAppl
Issap
Page 8
OTcl Commands A li ti tt h tApplication:: attach-agent
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.8
PrepPPook: T. Iss
Te
ulya
kul
t
ariyagent
Page 9
Outline• Application Overview
Timer• Timer• Two Derived Classes
– Traffic Generator– Simulated Application– Simulated Application
• Summary
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 9ed
y
pared
Prepa
PPook: T. Iss
p
by
Apat
erwat
ses
Teeeratori
ulya
kul
sariy
a
Issa
Page 10
Timer
• Timer is similar to a Scheduler.I f i h S h d l• In fact, it uses the Scheduler.
• It provides interface toIt provides interface to – Schedule events,– Reschedule events, and
Cancel events– Cancel events.
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 10edev
pared
el ev
Prepa
PPook: T. Iss
ybydule e
Teeat
a S
rwathe S
erfanterfvents
ulya
kul
sariy
a
Issa
Sche
Page 11
Timer Life Cycle
Active
• Active or Idle• Public functions
– sched(delay) or resched(delay)• start the timer• Wait till the timer expires• Take expiration action by invoking exire(e)
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 11
Take expiration action by invoking exire(e)– cancel() go back to Idle.
PrepPPook: T. Issed
elay
paredrt the
Wait tiTake
epaTak
– cancyby
tions)
t
TeeTee
ulya
kul
sariy
a
Is
Page 12
Expiration ActionD fi d i f ti i ( )• Defined in function expire(e)
• E G Timer� MyTimerE.G., Timer � MyTimer
• Print out “MyTimer has just y jexpired!!”
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 12ed
ut
paredred!!”
Prepa
PPook: T. Iss
by“M
tTime
rwaTim
ulya
kul
sariy
aiIss
aexpir
Page 13
Outline• Application Overview
Timer• Timer• Two Derived Classes
– Traffic Generator– Simulated Application– Simulated Application
• Summary
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 13ed
y
pared
Prepa
PPook: T. Iss
p
by
Apat
erwat
ses
Teeeratori
ulya
kul
sariy
a
Issa
Page 14
T ffi G n tTrafficGenerator
• Generate traffic based on a predefined schedule p f
• E.G., CBRC Cl T ffi G• C++ Class TrafficGenerator
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 14
paPrep
aPPook: T. Iss
at
erwat
G
TeeficGe
ulya
kul
sariy
ar
Issa
on a
Page 15
TrafficGeneratorff• Class declaration
Used to create packet arrival time
Packet size
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 15
p
PPrepook: T. Iss
ulya
kul
sariy
a
Issa
Page 16
Traffic Timer• Class TrafficTimer derives from
class Timerclass Timer– Key variable: tgen_– Key function: expire(e)
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 16PPrepook: T. Iss
at rw
ate(e)
ulya
kul
sariy
afrom
Issa
Page 17
Traffic GeneratorTraffic GeneratorTrafficGenerator
• Relationship to trafficRelationship to traffic timerE l f k tgen_
timer_• Example of packet
generatorTrafficGenerator::timeout()
g
size_
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 17nextPkttime_
_
P
ed
paredareararze_ar
Prepa
ook: T. Iss
epnextP
_
Pr
yyby
by
att terw
attt
TeecGeneraT
ulya
kul
riya
sariyari
yr
sasa
ficGen
IIssIssa
ss
Page 18
Traffic Timer Life CycleTraffic Timer Life Cycle
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 18PPrepook: T. Iss
ulya
kul
cle
riyaycle
Page 19
Class CBR TrafficClass CBR_Traffic
• C++: CBR Traffic� OTcl:C++: CBR_Traffic � OTcl: Application/Traffic/CBRF l / l/ b ff h• File: ~ns/tool/cbr_traffic.h,cc
• Key variables:Key variables:
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 19
Q: Where do we set the default values? ( ~ns/tcl/lib/ns-default.tcl )
PPrepook: T. Iss
paWhere
at
Bff
erwattraff
Tee
ulya
kul
sariy
a
Issal:
R
Page 20
Si l t d A li tiSimulated Application
• Run as if the application is running• Interact with agent (function resume())• Interact with agent (function resume())• E.G. FTP,
– Instprocs/OTcl commands• attach-agent{agent}: Associate with an agent
t t{} St t t f i fil ith i fi it i• start{}: Start transferring a file with infinite size • stop{}: Stop the FTP
– Note: the connecting agent will send data onlyNote: the connecting agent will send data only when its congestion window allows
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 20
paredd
Se cothe c
n its c
Prepa
PPook: T. Iss
ytby rt t
op the
at
sctio
erwaunctio
Teecommaagent}:
ulya
kul
sariy
aon
Issa
runn
Page 21
Outline• Application Overview
Timer• Timer• Two Derived Classes
– Traffic Generator– Simulated Application– Simulated Application
• Summary
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 21ed
y
pared
Prepa
PPook: T. Iss
p
by
Apat
erwat
ses
Teeeratori
ulya
kul
sariy
a
Issa
Page 22
SSummaryA li ti Th i• Applications: The main purpose =
( Indicate user demand )( )• Timer
h d l h d l l– schedule, reschedule, cancel– Timeout ( expiration action )
• Two derived classes– Traffic generator (e g CBR )– Traffic generator (e.g., CBR )– Simulated application (e.g., FTP )
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 22dgen
pare
c genulated
Prepa
PPook: T. Iss
y
p
byd claat
erwat)
l
Teeed
T
ulepirati
ulya
kul
sariy
a
Issaurpos
Page 23
Related Files• ~ns/apps/app.h,cc• ~ns/tool/trafgen.h,ccfg ,• ~ns/tool/cbr_traffic.h,cc
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 23ed
pared
Prepa
PPook: T. Iss
yby
at c
erwatfic.h,
Tee
ulya
kul
sariy
a
Issa