Upload
worasitipon-thomkort
View
128
Download
0
Embed Size (px)
Citation preview
NS-2 WorkshopWorasitipon Thomkort ( Instructor )
Overall
N S 2 - W o r k s h o p
What is NS2 ?
What we need ?
How to program ?
Let’s do it.
What we need ?
N S 2 - W o r k s h o p
System Environment
Document & Material
Tools & Developer kits
Yourself
What we need ?
N S 2 - W o r k s h o p
NS2
Ubuntu 13 or above
( 2.35 support )
NS2.35 ( last version )
Gcc last
version
Recommended
System Environment
What we need ?
N S 2 - W o r k s h o p
Document & Manual
NS2 Document NS2 Group / Google
C++ (OOP) / Tcl
What we need ?
N S 2 - W o r k s h o p
Tools & Developer kits ( must )
Version control• bitbucket• github• etc
Code Editor• sublime text• vim• etc
Overall
N S 2 - W o r k s h o p
What is NS2 ?
What we need ?
How to program ?
Let’s do it.
How to Program ?
N S 2 - W o r k s h o p
How to program in NS2 ?
TCLC++
For simulation
AWKPython
Perl
output evaluation1 2
How to Program ?
N S 2 - W o r k s h o p
TCL Coding Style in NS2
1 2 3
Create a global NS objectset ns [ new simulator ]
Create nodeset n1 [ $ns node ]
Create links$ns duplex-link $n1 $n2 10Mb 2ms DropTail
Define an output trace fileset tr [ open path/out.tr w ]$ns trace-all $tr
How to Program ?
N S 2 - W o r k s h o p
TCL Coding Style in NS2
4
Create sender agents
Create receiver agents
Each application flow id
Link
ns2.35/tcl/lib/
ns-default.tcl
set udp [ new Agent/UDP ]$ns attach-agent $n1 $udp$udp set fid_ 1
set null [ new Agent/Null ]$ns attach-agent $n2 $null$ns connect $udp $null
How to Program ?
N S 2 - W o r k s h o p
TCL Coding Style in NS2
5Create an application traffic
Link
ns2.35/tcl/lib/
ns-default.tcl
Each application flow id
set car [ new Application/CBR ]$cbr set packetSize_ 160$cbr set rate_ 10Mb$cbr attach-agent $udp
How to Program ?
N S 2 - W o r k s h o p
How to create an application over agents ?
N1 UD1 2 3
How to Program ?
N S 2 - W o r k s h o p
TCL Coding Style in NS2
6
Create finish function & set simulation timeproc finish () {
global ns tr$ns flush-traceclose $fexit 0
}
$ns at 0 “cbr start”$ns at 30 “cbr stop”$ns run
How to Program ?
N S 2 - W o r k s h o p
AWK Coding Style in NS2
1 2 3
Define initial stateDefine data filter
Show me at the final
begin { i = 0;
}
{event = $1if ( event == “+” ) { }
}
end { function();print i;
}
How to Program ?
N S 2 - W o r k s h o p
Output Trace Files meaning
event time from to pkt type pkt size flag fid src des seq pid
+ 0 0 1 cbr 512 — 1 0 2 1 0
- 0 0 1 cbr 512 — 1 0 2 4 0
d 0.1 1 2 cbr 512 — 1 0 2 5 0
r 0.2 1 2 cbr 512 — 1 0 2 10 0