1 network simulator (ns-2) tutorial these slides can be downloaded from: lijian/289i
Post on 22-Dec-2015
219 views
TRANSCRIPT
1
Network Simulator (NS-2) Tutorial
These slides can be downloaded from:
http://networks.cs.ucdavis.edu/~lijian/289I/
2
Agenda
What Is NS? Elements of Simulation NS Architecture NS Internals Summary
3
What is NS
Discrete event simulator Packet-level Protocol stack
- Link layer and up for wired networks;
- Physical layer and up for wireless networks
Wired and wireless(both local and satellite)
Detour
4
History and Status
Now part of VINT(Virtual InterNet Testbed) project
- Columbia NEST --> UCB REAL --> NS-1 --> NS-2 Users from approximately
- 600 institutes
- 50 countries Releases
- Periodic releases (currently 2.1b9, April 2002)
- Nightly snapshots (probably compiles and works, but “unstable”)
- Available from: USC/ISI, UC Berkeley, UK mirror
5
Platforms
Most UNIX and UNIX-like systemsFreeBSD or *BSDLinuxSun Solaris HP, SGI
Window 95/98/NT- Some work, some does not
(Emulation only for FreeBSD for now)
6
Functionality of NS
Wired world- Point-to-point link, LAN
- Unicast/multicast routing
- Transport
- Application layer Wireless
- Mobile IP
- Ad hoc routing Tracing, visualization, various utilities
7
Visualization Tools
nam-1 (Network AniMator Version 1)- Packet-level animation
- Well supported by ns
xgraph- Conversion from ns trace to xgraph format
8
Getting Started
NS official site:- http://www.isi.edu/nsnam/ns/
A painless tutorial by Marc Greis:- http://www.isi.edu/nsnam/ns/tutorial/index.html
Another good tutorial from WPI- http://nile.wpi.edu/NS/
9
Getting Help & Reference
Building NS- http://www.isi.edu/nsnam/ns/ns-build.html
NS user mailing list- http://mailman.isi.edu/mailman/listinfo/ns-users
NS manual- http://www.isi.edu/nsnam/ns/ns-documentation.html
10
Agenda
What Is NS? Elements of Simulation NS Architecture NS Internals Summary
11
Elements of Simulation
Create the event scheduler [Turn on tracing] Create network Setup routing [Insert errors] Create traffic Start simulation Post-process trace
Detour
12
Creating Event Scheduler
Create event scheduler- set ns [new Simulator]
Schedule events- $ns at <time> <event>
- <event>: any legitimate ns/tcl commands
Start scheduler- $ns run
13
Tracing
Trace packets on all links- $ns trace-all [open test.out w]
<event> <time> <from> <to> <pkt> <size> -- <fid> <src> <dst> <seq> <attr><event> <time> <from> <to> <pkt> <size> -- <fid> <src> <dst> <seq> <attr>
+ 1 0 2 cbr 210 ------- 0 0.0 3.1 0 0+ 1 0 2 cbr 210 ------- 0 0.0 3.1 0 0
- 1 0 2 cbr 210 ------- 0 0.0 3.1 0 0- 1 0 2 cbr 210 ------- 0 0.0 3.1 0 0
r 1.00234 0 2 cbr 210 ------- 0 0.0 3.1 0 0r 1.00234 0 2 cbr 210 ------- 0 0.0 3.1 0 0
Trace packets on all links in nam-1 format- $ns namtrace-all [open test.nam w]
Turn on tracing on specific links- $ns trace-queue $n0 $n1
- $ns namtrace-queue $n0 $n1
Must appear immediately after creating scheduler
14
Creating Network
Nodes- set n0 [$ns node]
- set n1 [$ns node]
Links and queuing- $ns duplex-link $n0 $n1 <bandwidth> <delay> <queue_type>
- <queue_type>: DropTail, RED, CBQ, FQ, SFQ, DRR
15
Creating Network: LAN
LAN- $ns make-lan <node_list> <bandwidth> <delay> <ll_type>
<ifq_type> <mac_type> <channel_type>
- <ll_type>: LL
- <ifq_type>: Queue/DropTail,
- <mac_type>: MAC/802_3
- <channel_type>: Channel
16
Inserting Errors
Creating Error Module- set loss_module [new ErrorModel]
- $loss_module set rate_ 0.01
- $loss_module unit pkt
- $loss_module ranvar [new RandomVariable/Uniform]
- $loss_module drop-target [new Agent/Null]
Inserting Error Module- $ns lossmodel $loss_module $n0 $n1
17
Network Dynamics
Link failures- Hooks in routing module to reflect routing changes
Four models$ns rtmodel Trace <config_file> $n0 $n1$ns rtmodel Trace <config_file> $n0 $n1
$ns rtmodel Exponential {<params>} $n0 $n1$ns rtmodel Exponential {<params>} $n0 $n1
$ns rtmodel Deterministic {<params>} $n0 $n1$ns rtmodel Deterministic {<params>} $n0 $n1
$ns rtmodel-at <time> up|down $n0 $n1$ns rtmodel-at <time> up|down $n0 $n1
Parameter list[<start>] <up_interval> <down_interval> [<finish>][<start>] <up_interval> <down_interval> [<finish>]
18
Setup Routing
Unicast- $ns rtproto <type>
- <type>: Static, Session, DV, cost, multi-path
Multicast- $ns multicast (right after [new Simulator])
- $ns mrtproto <type>
- <type>: CtrMcast, DM, ST, BST
19
Creating Connection: UDP or TCP
UDP- set udp [new Agent/UDP]
- set null [new Agent/Null]
- $ns attach-agent $n0 $udp
- $ns attach-agent $n1 $null
- $ns connect $udp $null
TCP- set tcp [new Agent/TCP]
- set tcpsink [new Agent/TCPSink]
- $ns attach-agent $n0 $tcp
- $ns attach-agent $n1 $tcpsink
- $ns connect $tcp $tcpsink
20
Creating Traffic: On Top of UDP
CBR- set src [new Application/Traffic/CBR]
Exponential or Pareto on-off- set src [new Application/Traffic/Exponential]
- set src [new Application/Traffic/Pareto]
21
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
22
Creating Traffic: Trace Driven
Trace driven- set tfile [new Tracefile]
- $tfile filename <file>
- set src [new Application/Traffic/Trace]
- $src attach-tracefile $tfile
<file>:- Binary format (native!)
- inter-packet time (msec) and packet size (byte)
23
Application-Level Simulation
Features- Build on top of existing transport protocol
- Transmit user data, e.g., HTTP header
Two different solutions- TCP: Application/TcpApp
- UDP: Agent/Message
24
Agenda
Detour ends.
What Is NS? Elements of Simulation NS Architecture NS Internals Summary
25
NS Architecture
Object-oriented (C++, OTcl) Scalability + Extensibility
- Control/”data” separation
- Split C++/OTcl object
Modular approach- Fine-grained object composition
Detour ends.
26
C++/OTcl Split Objects
C++ OTcl
Pure C++objects
Pure OTclobjects
C++/OTcl split objects
NS
100K 70K
27
C++/OTcl Linkage
Root of ns-2 object hierarchy
bind(): link variable values between C++ and OTcl TclObject
command(): link OTcl methods to C++ implementations
TclClass Create and initialize TclObject’s
Tcl C++ methods to access Tcl interpreter
TclCommand Standalone global commands
EmbeddedTcl ns script initialization
28
TclObject: Hierarchy and Shadowing
TclObject
Agent
Agent/TCP
Agent/TCP OTcl shadow object
_o123Agent/TCP C++
object
*tcp
TclObject
Agent
TcpAgent
OTcl classhierarchy
C++ classhierarchy
29
The Merit of OTcl
Program size, complexity
C/C++ OTcl
Smoothly adjust the granularity of scripting to balance extensibility and performance
With complete compatibility with existing simulation scripts
high low
split objects
30
Scalability vs Flexibility
It’s tempting to write all-OTcl simulation- Benefit: quick prototyping
- Cost: memory + runtime
Solution- Control the granularity of your split object by migrating
methods from OTcl to C++
31
Object Granularity Tips
Functionality- Per-packet processing C++
- Hooks, frequently changing code OTcl
Data management- Complex/large data structure C++
- One-time configuration variables OTcl
32
Agenda
What Is NS? Elements of Simulation NS Architecture NS Internals Summary
33
NS Internals
Discrete event scheduler Network topology Routing Transport Packet flow Packet format Application
34
Discrete Event Scheduler
time_, uid_, next_, handler_
head_ ->head_ ->
Three types of schedulers- List: simple linked list, order-preserving, O(N)
- Heap: O(logN)
- Calendar: hash-based, fastest, O(1)
handler_ -> handle()
time_, uid_, next_, handler_
reschedule
insert
35
Network Topology: Node
n0 n1
Addr Classifier
Port Classifier
classifier_
dmux_
entry_
Node entry
Unicast Node
Multicast Classifier
classifier_
dmux_
entry_
Node entry
Multicast Node
multiclassifier_
36
Network Topology: Link
n0 n1
enqT_ queue_ deqT_
drophead_ drpT_
link_ ttl_
n1 entry_
head_
tracing simplex link
duplex link
37
Routing
n0 n1
Addr Classifier
Port Classifier
classifier_
dmux_
entry_
Node entry 0
1 enqT_ queue_ deqT_
drophead_ drpT_
link_ ttl_
n1 entry_
head_
38
Routing (con’t)
n0 n1
Addr Classifier
Port Classifier
classifier_
dmux_
entry_
0
1
Addr Classifier
Port Classifier
classifier_
dmux_
entry_
1
0Link n0-n1
Link n1-n0
39
Transport
0
1
n0 n1
Addr Classifier
Port Classifier
classifier_
dmux_
entry_
0 Agent/TCP
agents_
Addr Classifier
Port Classifier
classifier_
dmux_
entry_
1
0Link n0-n1
Link n1-n0
0 Agent/TCPSinkagents_
dst_=1.0 dst_=0.0
40
Application: Traffic Generator
0
1
n0 n1
Addr Classifier
Port Classifier
classifier_
dmux_
entry_
0 Agent/TCP
agents_
Addr Classifier
Port Classifier
classifier_
dmux_
entry_
1
0Link n0-n1
Link n1-n0
0 Agent/TCPSink
agents_
dst_=1.0 dst_=0.0Application/FTP
41
Plumbing: Packet Flow
0
1
n0 n1
Addr Classifier
Port Classifier
entry_
0 Agent/TCP Addr Classifier
Port Classifier
entry_
1
0Link n0-n1
Link n1-n0
0 Agent/TCPSink
dst_=1.0 dst_=0.0Application/FTP
42
Packet Format
header
dataip header
tcp header
rtp header
trace header
cmn header
...
ts_
ptype_
uid_
size_
iface_
43
Abstract the Real Wireless World
Packet headers Mobile node Wireless channel Forwarding and routing Visualization
44
Wireless Packet Format
header
data
ts_
ptype_
uid_
size_
iface_
IP header
......
cmn header
LL
MAC 802_11
......
ARP Wireless headers
45
Mobile Node Abstraction
Location- Coordinates (x,y,z)
Movement- Speed, direction, starting/ending location, time ...
46
Portrait of A Mobile Node
Node
ARP
Propagation and antenna models MobileNode
LL
MAC
PHY
LL
CHANNEL
LL
MAC
PHY
Classifier: Forwarding
Agent: Protocol EntityNode Entry
LL: Link layer object
IFQ: Interface queue
MAC: Mac object
PHY: Net interface
protocolagent
routingagent
addrclassifier
portclassifier
255
IFQIFQ
defaulttarget_
47
Wireless Channel
Duplicate packets to all mobile nodes attached to the channel except the sender
It is the receiver’s responsibility to decide if it will accept the packet
- Collision is handled at individual receiver
- O(N2) messages grid keeper
48
Agenda
What Is NS? Elements of Simulation NS Architecture NS Internals Summary
49
Summary
What can we do with NS? Architectural overview of NS
- split C++/OTcl Object
Inside NS- node, link, routing, tcp, app, wireless extension
- how it works
50
References
http://www.isi.edu/nsnam/dist/ns-workshop00-new/ http://www.isi.edu/nsnam/ns/