15
NS-2 Workshop Worasitipon Thomkort ( Instructor )

ns2-training material

Embed Size (px)

Citation preview

Page 1: ns2-training material

NS-2 WorkshopWorasitipon Thomkort ( Instructor )

Page 2: ns2-training material

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.

Page 3: ns2-training material

What we need ?

N S 2 - W o r k s h o p

System Environment

Document & Material

Tools & Developer kits

Yourself

Page 4: ns2-training material

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

Page 5: ns2-training material

What we need ?

N S 2 - W o r k s h o p

Document & Manual

NS2 Document NS2 Group / Google

C++ (OOP) / Tcl

Page 6: ns2-training material

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

Page 7: ns2-training material

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.

Page 8: ns2-training material

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

Page 9: ns2-training material

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

Page 10: ns2-training material

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

Page 11: ns2-training material

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

Page 12: ns2-training material

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

Page 13: ns2-training material

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

Page 14: ns2-training material

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;

}

Page 15: ns2-training material

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