An Introduction to NSAn Introduction to NS22An Introduction to NSAn Introduction to NS22An Introduction to NSAn Introduction to NS22An Introduction to NSAn Introduction to NS22
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 1
PPreed
pared
repa
k: T. Issariyaku
yby
at rw
atuctiouctiuctiuctiuctiuctiucti
Tee
ucucucucucucuc
ulya
kul
sariy
a
Issa
Outline• Overview• InstallationInstallation• An Example• Incorporate C++ Modules into NS2
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 2
PPreed
pared
repa
k: T. Issariyaku
yby
at
erwat
TeeC++ Mo
ulya
kul
sariy
a
Issa
Overview: Network SimulationOverview: Network Simulation
3 i l i M i• 3 Simulation Main Steps1. Design
• Things to simulate• Assumptions
P f• Performance measure2. Simulation
• Network Configuration Phase• Simulation Phase
3 R l C il i3. Result Compilation• Debugging and Tracing
C t fTextbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
• Compute performance meaures3
P
d tio
paredComp
ebugC
Prepa
k: T. Issariyaku
Comyby
Confin Pha
at
erwat
Teeeasure
ulak
ulatio
sariyulati
Issa
Overview: NS2 ArchitectureOverview: NS2 Architecture
NS2 N t k Si l t 2• NS2 = Network Simulator 2• Consists of f
– C++: Internal mechanismOTcl: User interface– OTcl: User interface
– TclCL: Connecting C++ to OTcl
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 4
PPrek: T. I
y
at
erwatanism
face
Teerfaccting
ulak
ulure
sariyctur
2Issator 2
Overview: NS2 InvocationOverview: NS2 InvocationS• Syntax
>> ns [<filename>] [<args>]No argument: Enter NS2 environment– No argument: Enter NS2 environment
– <filename> = Tcl simulation script; Use OTcl programming lauguage
h l f l h l bl– In the Tcl file, <args> is stores in the internal variable ( $argv ).
• Example>> ns myfirst_ns.tcl 1 2 3y
– To retrieve the second input argument (2), execute( lindex $argv 1 )
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 5
PPreparee
d >> n
edtrieve t
repa
k: T. Issariyaku
yby
at
<aronmen
erwaronme
script;
Teeis sto
ulak
ultion
sariyatio
Issa
rgs>
Outline• Overview• InstallationInstallation• An Example• Incorporate C++ Modules into NS2
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 6
PPreed
pared
repa
k: T. Issariyaku
yby
at
erwat
TeeC++ Mo
ulya
kul
sariy
a
Issa
Installation: NS2Installation: NS21 G t NS2 b1. Go to NS2 web page:
– NS2 Webpage: http://www.isi.edu/nsnam/ns/– Download Link: http://www.isi.edu/nsnam/ns/ns-
b ld h l# ll 1p
build.html#allinone1.2. Get all-in-one package
– NS2, Tcl/Tk, OTcl, TclCLNS2, Tcl/Tk, OTcl, TclCL– NAM, Zlib, Xgraph
3. Unzip all the files4 Us th i st ll ti k “ /i st ll”4. Use the installation package “./install”• Follow the instruction• NS2 is designed for UnixNS2 is designed for Unix• For windows, also install Cygwin
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 7
PPrepar
d
ngneedesigne
ndows
repa
k: T. Issariyaku
yiby tio
struct
at
duedu/n
erwat
L
Tee
L
ulya
kul
sariy
a
Issa
/nsnam
Installation: CygwinInstallation: CygwinC i Li m l ti f i d s• Cygwin = Linux emulation for windows
1. Go to Cygwin Webpage: http://www.cygwin.com/2. Get the package3. Install the basic package3. Install the basic package4. Install the following additional packages:
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 8
PPrepk: T. Issariyaku
at
http:
rwat
ckag
Tee
ackowing
ulya
kul
sariy
ainiIss
afor wi//
Outline• Overview• InstallationInstallation• An Example• Incorporate C++ Modules into NS2
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 9
PPreed
pared
repa
k: T. Issariyaku
yby
at
erwat
TeeC++ Mo
ulya
kul
sariy
a
Issa
A Network Simulation ExampleA Network Simulation Example
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 10
Prepa
k: T. Issariyaku
ulak
ulmp
sariyxamp
ssa
Tcl Simulation Script• Filename “myfirst ns.tcl”
Tcl Simulation ScriptFilename myfirst_ns.tcl
• Create a simulator
• Create trace objects
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 11
Preped
k: T. Issariyaku
y
at
erwat
Teeobje
ulya
kul
t
sariy
apt
Issa
A Network Simulation ExampleA Network Simulation Example
• Define a “finish” proceduer
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 12
PPrepk: T. Issariyaku
t
ulak
ulmp
sariyxamp
Issa
duer
A Network Simulation ExampleA Network Simulation Example
• Create nodes
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 13
PPree
pared
repa
k: T. Issariyaku
at
ulak
ulmp
sariyxamp
Issa
A Network Simulation ExampleA Network Simulation Example
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 14
PPrepa
k: T. Issariyaku
yeeerweee
ulak
ulmp
sariyxamp
ssa
A Network Simulation ExampleA Network Simulation Example
• Connect node with “duplex” links
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 15
Preed
pared
repa
k: T. Issariyaku
at
ulak
ulmp
sariyxamp
Issa
ex” l
A Network Simulation ExampleA Network Simulation Example
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 16
P
ere
Prepa
k: T. Issariyaku
ybyeeerweee
ulak
ulmp
sariyxamp
ssa
A Network Simulation ExampleA Network Simulation Example
• Create a flow from n0 to n3– Create a UDP flowCreate a UDP flow
– Attach a CBR source to the UDP flow
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 17
ed a C
pared
Prepa
k: T. Issariyaku
byCB
at wat
ulak
ulmp
sariyxamp
Issa
o n3
A Network Simulation ExampleA Network Simulation Example
• Create a flow from n1 to n4– Create a TCP flowCreate a TCP flow
– Attach a FTP source to the TCP flowAttach a FTP source to the TCP flow
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 18
PPrepare
dda Fa F
repa
k: T. Issariyaku
byT
at wat
ulak
ulmp
sariyxamp
Issa
o n4
A Network Simulation ExampleA Network Simulation Example
• Schedule Events
• Start simulation
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 19
PPreed
m
pared
repa
k: T. Issariyaku
yby
ulatioat
Te
ulak
ulmp
sariyxamp
Issa
A Network Simulation ExampleA Network Simulation Example
• We are in step two of network simulationStep 1 = ( Design )p ( g )Step 3 = ( Result Compilation )
Sub-Step The part of the code1. (Network Configuration) (the rest of the codes ) 2. (Simulation ) ($ns run )( ) ( )3. ( ) ( )
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 20
PPreed
pared
repa
k: T. Issariyaku
yby guration
at
erwatlation
Tee
ulak
ulmp
sariyxamp
Issa
twork )
A Network Simulation Example• Results? � (files out.tr and out.nam )
p
{enque(+) deque(-) receive(r) drop(d)}Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
{enque(+),deque( ),receive(r),drop(d)}21
PPre
dpa
reenquea
repa
k: T. Issariyaku
{enqb
ulya
kul
mpl
sariy
and out.
p
ssa
Outline• Overview• InstallationInstallation• An Example• Incorporate C++ Modules into NS2
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 22
PPreed
pared
repa
k: T. Issariyaku
yby
at
erwat
TeeC++ Mo
ulya
kul
sariy
a
Issa
New Modules• NS2 Modules: C++ and OTcl
Di i• Directories:~ns ~tclcl
See Also: http://www-rp lip6 fr/ns-doc/ns226-doc/html/hierarchy htm
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008.
See Also: http://www-rp.lip6.fr/ns-doc/ns226-doc/html/hierarchy.htm23
P
eded
edpa
redredredso: ht
Prepk: T. Issariyaku
lso: hyyyby
bybyyyy
at ataterw
atatate wawa
rwrwTeeeeTTTeTTT
ulya
kul
sariy
a
Issa
New Modules• New Modules
– Need to recompile and links all NEWNeed to recompile and links all NEW modules
– Use make utility– Use make utility
• “Make” contains a set of things that will be done when “make” is executed from the command prompt.
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 24
PPrepare
d one
edthe c
repa
k: T. Issariyaku
ybyntaine w
td link
erwad lin
Teey
ulya
kul
sariy
a
Issa
Make UtilityMake Utility• Make usage
>> make [ f <filename>]>> make [-f <filename>]– Executed what specified in <filename>– <filename> is called a “file descriptor”<filename> is called a file descriptor– No file is given � use file “Makefile”
• File descriptor– Syntax
1 [ 2 ] [ d 1 d 2 ]<target1> [<target2> …] : [<dep1> <dep2> …]<command>
– Targets are remade if any of the dependency– Targets are remade if any of the dependencyis changed
– The change is specified in the command.
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 25
PPreed
coare
pared
s areanged
he cha
repa
k: T. Issariyaku
yby <targe
mman
t <desc
erwae des
file “M
Tee
ulya
kul
sariy
ae>]
Issaame>]
filena
Make UtilityMake Utility• Example
cc-o channel main.o, fade.o, model.o
Execute ( ) if ( ) is changed( ) g
main.o, fade.o, and/or model.o
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 26
PPrepare
repa
k: T. Issariyaku
wa
ulya
kul
sariy
a
ssa
ss
Make UtilityMake Utility• Example: Use variables OBJS and
COM
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 27
PPree
pared
repa
k: T. Issariyaku
ulya
kul
sariy
aBJS an
ssa
Makefile for NS2Makefile for NS2• Located in ~ns• Key components:Key components:
– INCLUDES = : DirectoryOBJ CC All NS2 bj fil– OBJ_CC = : All NS2 object files
– NS_TCL_LIB = : All NS2 OTcl files• Put your files in these three
componentscomponents
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 28
PPre
d
fnts
pare
nents
repa
k: T. Issariyaku
y
B
by
iles at
erwat
rectorNS2
Teell NS2B =
ulya
kul
sariy
a
Issa
M k fil f NS2: Ex mplMakefile for NS2: Example
Use *.o
Use “\” to separate lines
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 29
P
d
Prepk: T. Issariyaku
erwe
ulya
kul
pl
sariy
ample
ssa
Summary• NS2 consists of
– OTcl ( user interface ) and – C++ ( internal mechanism )
• Installation: NS2 + Cygwinyg• An Example• Make utility• Make utility
– INCLUDE: DirectoryOBJ CC C M d l– OBJ_CC: C++ Modules
– NS_TCL_LIB: OTcl Modules
Textbook: T. Issariyakul and E. Hossain, Introduction to Network Simulator NS2, Springer 2008. 30
Ppa
d
E: C
red
CC: C+_TCL_
Prepk: T. Issariyaku
pa
yby y
Direc
at d
erwatm )
Cyg
Tee
y
ulya
kul
sariy
asaIss
a
Top Related