ns2 Tutorial, part 2 - PowerPoint PPT Presentation

About This Presentation
Title:

ns2 Tutorial, part 2

Description:

ns2 Tutorial, part 2 – PowerPoint PPT presentation

Number of Views:68
Avg rating:3.0/5.0
Slides: 18
Provided by: poll170
Learn more at: http://nms.lcs.mit.edu
Category:
Tags: ns2 | part | polly | tutorial

less

Transcript and Presenter's Notes

Title: ns2 Tutorial, part 2


1
ns-2 Tutorial, part 2
  • Dave Anderson, Xiaowei Yang
  • (Modified from Polly Huangs slides)

2
Outline
  • Ns-2 internals
  • script -gt internal structure
  • How to Extend ns

3
Script Code
  • Create a topology
  • Set ns new Simulator
  • set n0 ns node
  • set n1 ns node
  • ns duplex-link n0 n1 1Mb 10ms DropTail
  • Add Transport agents
  • set tcp new Agent/TCP
  • ns attach-agent n0 tcp
  • set tcpsink new Agent/TCPSink
  • ns attach-agent n1 tcpsink
  • tcp connect tcpsink
  • Add application
  • set ftp new Application/FTP
  • ftp attach-agent tcp

Create a schedule ns at 0.5 "ftp start" ns
at 4.5 "ftp stop" Run the simulation ns run
FTP
TCP
1Mb
n0
n1
10ms
4
Discrete Event-Driven Simulator
time_, uid_, next_, handler_
head_ -gt
handler_ -gt handle()
insert
time_, uid_, next_, handler_
ns at 0.5 ftp start ns at 4.5 ftp
stop ns run
5
Ns Node
set n0 ns node set n1 ns node
6
Network Topology - Link
ns duplex-link n0 n1 1Mb 10ms DropTail
7
Routing
Link n0-n1
8
Transport
n0
n1
Port Classifier
Port Classifier
Addr Classifier
Addr Classifier
0
0
agents_
dmux_
dmux_
Link n0-n1
entry_
entry_
classifier_
classifier_
Link n1-n0
set tcp new Agent/TCP ns attach-agent n0 tcp
9
Application
n0
n1
Port Classifier
Port Classifier
Addr Classifier
Agent/TCP
Addr Classifier
Agent/TCPSink
0
0
agents_
agents_
dmux_
dmux_
Link n0-n1
entry_
entry_
classifier_
classifier_
Link n1-n0
set ftp new Application/FTP tcp attach-agent
ftp
10
Packet Flow
n0
n1
Port Classifier
Port Classifier
Application/FTP
Addr Classifier
Agent/TCP
Addr Classifier
Agent/TCPSink
0
0
Link n0-n1
entry_
entry_
Link n1-n0
11
Packet Format
header
data
12
Extending ns-2 Simulator
13
otcl and C The Duality
C
otcl
  • C for data
  • per packet action
  • otcl for control
  • periodic or triggered action

14
Adding New Classes
procedures
variables
otcl
C
15
TclClass
Static class TcpClass public TclClass
public TcpClass() TclClass(Agent/Echo)
TclObject create(int, const charconst)
return (new EchoAgent()) class_echo
16
TclObject bind()
  • C
  • EchoAgentTcpAgent()
  • bind(msglen_, len_)
  • otcl
  • Agent/Echo set msglen_ 50

17
TclObject command()
  • C
  • Int EchoAgentcommand(int argc, const
    charconst argv)
  • if (argc 2)
  • if (strcmp(argv1, send) 0)
  • send()
  • return(TCL_OK)
  • else if (strcmp(argv1, recv) 0)
  • send()
  • return(TCL_OK)
  • return (Agentcommand(argc, argv)
  • otcl
  • set echo new Agent/Echo
  • echo send
Write a Comment
User Comments (0)
About PowerShow.com