NS-2 Workshop
Worasitipon 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 ?
TCL
C++
For simulation
AWK
Python
Perl
output evaluation
1 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 object
set ns [ new simulator ]
Create node
set n1 [ $ns node ]
Create links
$ns duplex-link $n1 $n2 10Mb 2ms DropTail
Define an output trace file
set 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
5
Create 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 UD
1 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 time
proc finish () {
global ns tr
$ns flush-trace
close $f
exit 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 state
Define data filter
Show me at the final
begin {
i = 0;
}
{
event = $1
if ( 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

ns2-training material

  • 1.
  • 2.
    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.
  • 3.
    What we need? N S 2 - W o r k s h o p System Environment Document & Material Tools & Developer kits Yourself
  • 4.
    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
  • 5.
    What we need? N S 2 - W o r k s h o p Document & Manual NS2 Document NS2 Group / Google C++ (OOP) / Tcl
  • 6.
    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
  • 7.
    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.
  • 8.
    How to Program? N S 2 - W o r k s h o p How to program in NS2 ? TCL C++ For simulation AWK Python Perl output evaluation 1 2
  • 9.
    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 object set ns [ new simulator ] Create node set n1 [ $ns node ] Create links $ns duplex-link $n1 $n2 10Mb 2ms DropTail Define an output trace file set tr [ open path/out.tr w ] $ns trace-all $tr
  • 10.
    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
  • 11.
    How to Program? N S 2 - W o r k s h o p TCL Coding Style in NS2 5 Create 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
  • 12.
    How to Program? N S 2 - W o r k s h o p How to create an application over agents ? N1 UD 1 2 3
  • 13.
    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 time proc finish () { global ns tr $ns flush-trace close $f exit 0 } $ns at 0 “cbr start” $ns at 30 “cbr stop” $ns run
  • 14.
    How to Program? N S 2 - W o r k s h o p AWK Coding Style in NS2 1 2 3 Define initial state Define data filter Show me at the final begin { i = 0; } { event = $1 if ( event == “+” ) { } } end { function(); print i; }
  • 15.
    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