50
1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: http://networks.cs.ucdavis.edu/ ~lijian/289I/

1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

  • View
    219

  • Download
    2

Embed Size (px)

Citation preview

Page 1: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

1

Network Simulator (NS-2) Tutorial

These slides can be downloaded from:

http://networks.cs.ucdavis.edu/~lijian/289I/

Page 2: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

2

Agenda

What Is NS? Elements of Simulation NS Architecture NS Internals Summary

Page 3: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

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

Page 4: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

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

Page 5: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

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)

Page 6: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

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

Page 7: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

7

Visualization Tools

nam-1 (Network AniMator Version 1)- Packet-level animation

- Well supported by ns

xgraph- Conversion from ns trace to xgraph format

Page 8: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

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/

Page 9: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

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

Page 10: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

10

Agenda

What Is NS? Elements of Simulation NS Architecture NS Internals Summary

Page 11: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

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

Page 12: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

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

Page 13: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

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

Page 14: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

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

Page 15: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

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

Page 16: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

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

Page 17: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

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>]

Page 18: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

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

Page 19: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

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

Page 20: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

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]

Page 21: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

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

Page 22: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

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)

Page 23: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

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

Page 24: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

24

Agenda

Detour ends.

What Is NS? Elements of Simulation NS Architecture NS Internals Summary

Page 25: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

25

NS Architecture

Object-oriented (C++, OTcl) Scalability + Extensibility

- Control/”data” separation

- Split C++/OTcl object

Modular approach- Fine-grained object composition

Detour ends.

Page 26: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

26

C++/OTcl Split Objects

C++ OTcl

Pure C++objects

Pure OTclobjects

C++/OTcl split objects

NS

100K 70K

Page 27: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

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

Page 28: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

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

Page 29: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

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

Page 30: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

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++

Page 31: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

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

Page 32: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

32

Agenda

What Is NS? Elements of Simulation NS Architecture NS Internals Summary

Page 33: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

33

NS Internals

Discrete event scheduler Network topology Routing Transport Packet flow Packet format Application

Page 34: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

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

Page 35: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

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_

Page 36: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

36

Network Topology: Link

n0 n1

enqT_ queue_ deqT_

drophead_ drpT_

link_ ttl_

n1 entry_

head_

tracing simplex link

duplex link

Page 37: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

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_

Page 38: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

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

Page 39: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

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

Page 40: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

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

Page 41: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

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

Page 42: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

42

Packet Format

header

dataip header

tcp header

rtp header

trace header

cmn header

...

ts_

ptype_

uid_

size_

iface_

Page 43: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

43

Abstract the Real Wireless World

Packet headers Mobile node Wireless channel Forwarding and routing Visualization

Page 44: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

44

Wireless Packet Format

header

data

ts_

ptype_

uid_

size_

iface_

IP header

......

cmn header

LL

MAC 802_11

......

ARP Wireless headers

Page 45: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

45

Mobile Node Abstraction

Location- Coordinates (x,y,z)

Movement- Speed, direction, starting/ending location, time ...

Page 46: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

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_

Page 47: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

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

Page 48: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

48

Agenda

What Is NS? Elements of Simulation NS Architecture NS Internals Summary

Page 49: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

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

Page 50: 1 Network Simulator (NS-2) Tutorial These slides can be downloaded from: lijian/289I

50

References

http://www.isi.edu/nsnam/dist/ns-workshop00-new/ http://www.isi.edu/nsnam/ns/