An Introduction to NS2 - PowerPoint PPT Presentation

1 / 54
About This Presentation
Title:

An Introduction to NS2

Description:

... old mom: How are you doing?' Class Kid -superclass Mom ... puts '$age_ years old kid: What's up, dude?' set mom [new Mom] $mom set age_ 45. set kid [new Kid] ... – PowerPoint PPT presentation

Number of Views:234
Avg rating:3.0/5.0
Slides: 55
Provided by: csU45
Category:
Tags: introduction | mom | new | ns2 | oldest

less

Transcript and Presenter's Notes

Title: An Introduction to NS2


1
An Introduction to NS-2
  • Gayatri Swamynathan
  • CS 276 TA

some slides are from a presentation by Haobo Yu
Nader Salehi, USC/ISI
2
NS-2 Learning Resources
  • TA web page for 276
  • http//www.cs.ucsb.edu/gayatri/ta/cs276.html
  • Installation instructions
  • Using related tools (nam, xgraph, etc)
  • NS-2 official website and documentation
  • Tutorials to get you started
  • Sample coding exercises

3
Roadmap For Todays Lecture
  • ns Primer
  • Extending ns

4
Part I ns Primer
5
What is ns?
  • Object-oriented, discrete event-driven network
    simulator
  • Written in C and OTcl
  • By VINT Virtual InterNet Testbed

6
ns Architecture
  • Separate data path and control path
    implementations.

7
What is ns?
  • Object-oriented, discrete event-driven network
    simulator
  • Written in C and OTcl
  • By VINT Virtual InterNet Testbed

8
ns Architecture
  • Separate data path and control path
    implementations.

9
ns Architecture
10
Hello World Interactive mode
  • bash-shell ns
  • set ns new Simulator
  • _o3
  • ns at 1 puts \Hello World!\
  • 1
  • ns at 1.5 exit
  • 2
  • ns run
  • Hello World!
  • bash-shell

11
Hello World Batch mode
  • simple.tcl
  • set ns new Simulator
  • ns at 1 puts \Hello World!\
  • ns at 1.5 exit
  • ns run
  • bash-shell ns simple.tcl
  • Hello World!
  • bash-shell

12
Basic Tcl ex-tcl.tcl
13
Basic OTcl
Class Mom Mom instproc greet self instvar
age_ puts age_ years old mom How are you
doing? Class Kid -superclass Mom Kid instproc
greet self instvar age_ puts age_ years
old kid Whats up, dude?
set mom new Mom mom set age_ 45 set kid new
Kid kid set age_ 15 mom greet kid greet
14
NS-2 Generic Script Structure
  • Create Simulator object
  • Turn on tracing
  • Create topology
  • Setup packet loss, link dynamics
  • Create routing agents
  • Create application and/or traffic sources
  • Post-processing procedures (i.e. nam)
  • Start simulation

15
Step1 Create Simulator Object
  • Create event scheduler
  • set ns new Simulator

16
Step2 Tracing
  • Insert immediately after scheduler!
  • Trace packets on all links
  • set nf open out.nam w
  • ns trace-all nf
  • ns namtrace-all nf

17
Step2 Tracing
18
NS-2 Generic Script Structure
  • Create Simulator object
  • Turn on tracing
  • Create topology
  • Setup packet loss, link dynamics
  • Create routing agents
  • Create application and/or traffic sources
  • Post-processing procedures (i.e. nam)
  • Start simulation

19
Step 3 Create network
  • Two nodes, One link

20
Step 3 Create Network
n0
  • Nodes
  • set n0 ns node
  • set n1 ns node
  • Links and queuing
  • ns duplex-link n0 n1 1Mb 10ms RED
  • ns duplex-link n0 n1 ltbandwidthgt ltdelaygt
    ltqueue_typegt
  • ltqueue_typegt DropTail, RED, etc.

n1
21
Creating a larger topology
  • for set i 0 i lt 7 incr i
  • set n(i) ns node
  • for set i 0 i lt 7 incr i
  • ns duplex-link n(i) n(expr (i1)7) 1Mb
    10ms RED

22
NS-2 Generic Script Structure
  • Create Simulator object
  • Turn on tracing
  • Create topology
  • Setup packet loss, link dynamics
  • Create routing agents
  • Create application and/or traffic sources
  • Post-processing procedures (i.e. nam)
  • Start simulation

23
Step 4 Network Dynamics
  • Link failures
  • Hooks in routing module to reflect routing
    changes
  • ns rtmodel-at lttimegt updown n0 n1
  • For example
  • ns rtmodel-at 1.0 down n0 n1
  • ns rtmodel-at 2.0 up n0 n1

24
Step 5 Creating UDP connection
  • set udp new Agent/UDP
  • set null new Agent/Null
  • ns attach-agent n0 udp
  • ns attach-agent n1 null
  • ns connect udp null

25
Step 6 Creating Traffic (On Top of UDP)
  • CBR
  • set cbr new Application/Traffic/CBR
  • cbr set packetSize_ 500
  • cbr set interval_ 0.005
  • cbr attach-agent udp

26
Creating TCP connection
  • set tcp new Agent/TCP
  • set tcpsink new Agent/TCPSink
  • ns attach-agent n0 tcp
  • ns attach-agent n1 tcpsink
  • ns connect tcp tcpsink

27
Step 6 Creating Traffic (On Top of TCP)
  • FTP
  • set ftp new Application/FTP
  • ftp attach-agent tcp
  • Telnet
  • set telnet new Application/Telnet
  • telnet attach-agent tcp

28
Recall Generic Script Structure
  • set ns new Simulator
  • Turn on tracing
  • Create topology
  • Setup packet loss, link dynamics
  • Create agents
  • Create application and/or traffic sources
  • Post-processing procedures (i.e. nam)
  • Start simulation

29
Post-Processing Procedures
  • Add a 'finish' procedure that closes the trace
    file and starts nam.
  • proc finish
  • global ns nf
  • ns flush-trace
  • close nf
  • exec nam out.nam
  • exit 0

30
Run Simulation
  • Schedule Events
  • ns at lttimegt lteventgt
  • lteventgt any legitimate ns/tcl commands
  • ns at 0.5 "cbr start"
  • ns at 4.5 "cbr stop
  • Call finish
  • ns at 5.0 "finish"
  • Run the simulation
  • ns run

31
Recall Generic Script Structure
  • set ns new Simulator
  • Turn on tracing
  • Create topology
  • Setup packet loss, link dynamics
  • Create routing agents
  • Create application and/or traffic sources
  • Post-processing procedures (i.e. nam)
  • Start simulation

32
Visualization Tools
  • nam-1 (Network AniMator Version 1)
  • Packet-level animation
  • Well supported by ns
  • xgraph
  • Simulation results

33
(No Transcript)
34
nam Interface Nodes
  • Color
  • node color red
  • Shape (cant be changed after sim starts)
  • node shape box (circle, box, hexagon)
  • Label (single string)
  • ns at 1.1 n0 label \web cache 0\

35
nam Interfaces Links
  • Color
  • ns duplex-link-op n0 n1 color "green"
  • Label
  • ns duplex-link-op n0 n1 label backbone"

36
nam Interface Topology Layout
  • Manual layout specify everything
  • ns duplex-link-op n(0) n(1) orient right
  • ns duplex-link-op n(1) n(2) orient right
  • ns duplex-link-op n(2) n(3) orient right
  • ns duplex-link-op n(3) n(4) orient 60deg
  • If anything missing ? automatic layout

37
Simulation Example
38
Examples
39
Part II Extending ns
40
OTcl and C The Duality
Pure OTcl objects
Pure C objects
C/OTcl split objects
C
OTcl
ns
41
TclObject Hierarchy and Shadowing
C class hierarchy
OTcl class hierarchy
TclObject
TclObject
Agent
Agent
TcpAgent
Agent/TCP
tcp
_o123
Agent/TCP OTcl shadow object
Agent/TCP C object
42
Extending ns
  • In OTcl
  • In C

43
Extending ns in OTcl
  • If you dont want to compile
  • source your changes in your sim scripts
  • Modifying exisiting code
  • Recompile
  • Adding new files
  • Change Makefile (NS_TCL_LIB),
  • Update tcl/lib/ns-lib.tcl
  • Recompile

44
Add Your Changes into ns
ns-allinone
TK8.0
OTcl
tclcl
Tcl8.0
ns-2
nam-1
C code
...
tcl
mcast
lib
ex
test
...
mysrc
examples
validation tests
msg.tcl
OTcl code
45
Extending ns in C
  • Modifying code
  • make depend
  • Recompile
  • Adding code in new files
  • Change Makefile
  • make depend
  • Recompile

46
OTcl Linkage
  • Lets create a new agent MyAgent
  • Dummy agent
  • Derived from the Agent class

47
Step 1 Export C class to OTcl
48
Step 2 Export C class variables to OTcl
  • set the default value for the variables in the
  • "ns-2/tcl/lib/ns-lib.tcl" file

49
Step 3 Export C Object Control Commands to
OTcl
50
Step 4 Execute an OTcl command from C.
51
Step 5 Compile
  • Save above code as ex-linkage.cc
  • Open "Makefile", add "ex-linkage.o" at the end of
    object file list.
  • Re-compile NS using the "make" command.

52
Step 5 Run and Test MyAgent
53
Step 5 Run and Test MyAgent
54
Roadmap For Todays Lecture
  • ns Primer
  • Extending ns
Write a Comment
User Comments (0)
About PowerShow.com