+ All Categories
Home > Documents > Computer Communications - CSCI 551 CS551 NS...

Computer Communications - CSCI 551 CS551 NS...

Date post: 28-Jul-2020
Category:
Upload: others
View: 7 times
Download: 0 times
Share this document with a friend
64
CS551 NS Tutorial Slides Developed by: John Heidemann [email protected] USC/ISI 1 Computer Communications - CSCI 551 Copyright © William C. Cheng
Transcript
Page 1: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

CS551NS Tutorial

Slides Developed by:

John [email protected]

USC/ISI1

Computer Communications - CSCI 551

Copyright © William C. Cheng

Page 2: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

simple model

a discrete event simulator

2

ns-2, the network simulator

Computer Communications - CSCI 551

Copyright © William C. Cheng

wired, wireless, satellite

focused on modeling network protocols

TCP, UDP, multicast, unicast

web, telnet, ftp

ad hoc routing, sensor networks

infrastructure: stats, tracing, error models, etc.

Page 3: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

support networking research and education

3

ns goals

Computer Communications - CSCI 551

Copyright © William C. Cheng

protocol design, traffic studies, etc.

protocol comparison

provide a collaborative environment

freely distributed, open source

share code, protocols, models, etc.

allow easy comparision of similar protocols

increase confidence in results

more people look at models in more situations

experts develop models

multiple levels of detail in one simulator

Page 4: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

Began as REAL in 1989

4

ns history

Computer Communications - CSCI 551

Copyright © William C. Cheng

ns by Floyd and McCanne at LBL

ns-2 by McCanne and the VINT project (LBL, PARC, UCB,

USC/ISI)

currently maintained at USC/ISI, with input from Floyd et al.

Page 5: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

ns, the simulator itself

5

"ns" components

Computer Communications - CSCI 551

Copyright © William C. Cheng

visualize ns (or other) output

nam, the Network AniMator

GUI input simple ns scenarios

traffic and topology generators

pre-processing:

simple trace analysis, often in Awk, Perl, or Tcl

post-processing:

Page 6: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

web, FTP, telnet, constant-bit rate, Real Audio

Traffic models and applications:

6

ns models

Computer Communications - CSCI 551

Copyright © William C. Cheng

unicast: TCP (Reno, Vegas, etc.), UDP

Transport protocols:

multicast: SRM

wired routing, ad hoc rtg and directed diffusion

Routing and queueing:

queueing protocols: RED, drop-tail, etc.

wired (point-to-point, LANs), wireless (multiple

propagation models), satellite

Physical media:

Page 7: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

platforms: basically all Unix and Windows

7

ns status

Computer Communications - CSCI 551

Copyright © William C. Cheng

size: about 200k loc each C++ and Tcl, 350 page manual

user-base: >1k institutions, >10k users

releases about every 6 months, plus daily snapshots

Page 8: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

Concepts

8

Outlines

Computer Communications - CSCI 551

Copyright © William C. Cheng

Essentials

Getting Started

Fundamental tcl, otcl and ns

Page 9: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

simulator has list of events

model world as events

9

Discrete Event Simulation

Computer Communications - CSCI 551

Copyright © William C. Cheng

process: take next one, run it, until done

each event happens in an instant of virtual (simulated)

time, but takes an arbitrary amount of real time

ns uses simple model: single thread of control => no locking

or race conditions to worry about (very easy)

Page 10: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

10

Discrete Event Examples

Computer Communications - CSCI 551

Copyright © William C. Cheng

A B

Consider two nodeson an Ethernet: simple

queuingmodel:

t=1:

t=1.01: LAN dequeues pktand triggers B

A enqueues pkt on LAN

detailedCSMA/CDmodel:

t=1.0:

t=1.005: A’s NIC concludes cs,starts tx

A sends pkt to NICA’s NIC starts carrier sense

t=1.006: B’s NIC begins reciving pkt

t=1.01: B’s NIC concludes pktB’s NIC passes pkt to app

Page 11: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

11

Discrete Event Scheduler

Computer Communications - CSCI 551

Copyright © William C. Cheng

List: simple linked list, order-preserving, O(N)

Four types of scheduler:

time_, uid_, next_, handler_

time_, uid_, next_, handler_

handler_->handle()

Dispatch

RescheduleInsert

Dequeue

EventQueue

Head_

Heap: O(logN)

Calendar: hash-based, fastest, default, O(1)

Real-time: subclass of list, sync with real-time, O(N)

Page 12: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

lots of code reuse (ex. TCP + TCP variants)

Object oriented:

12

ns Software Structure: objectorientation

Computer Communications - CSCI 551

Copyright © William C. Cheng

NsObject: has recv() method

Some important objects:

Connector: has target() and drop()

BiConnector: uptarget() & downtarget()

Page 13: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

fast to run, detailed, complete control

Uses two languages

13

ns Software Structure: C++ and Otcl

Computer Communications - CSCI 551

Copyright © William C. Cheng

C++ for packet-processing

simulation setup, configuration, occasional actions

OTcl for control

fast to write and change

pros: trade-off running vs. writing speed,

powerful/documented config language

cons: two languages to learn and debug in

Page 14: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

14

OTcl and C++: The Duality

Computer Communications - CSCI 551

Copyright © William C. Cheng

ns

C++ OTcl

Pure C++objects

Pure OTclobjects

C++/OTcl split objects

OTcl (object variant of Tcl) and C++ share class hierarchy

TclCL is glue library that makes it easy to share functions,

variables, etc.

Page 15: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

Concepts

Essentials

Getting Started

Fundamental tcl, otcl and ns

15

Outlines

Computer Communications - CSCI 551

Copyright © William C. Cheng

Page 16: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

download ns-allinone (if you have your own machine,

do not build this on USC servers)

16

Installation and Documentation

Computer Communications - CSCI 551

Copyright © William C. Cheng

http://www.isi.edu/nsnam/ns/

includes Tcl, OTcl, TclCL, ns, nam, etc.

mailing list: [email protected]

documentation (see url above)

Marc Gries tutorial

ns manual

run ns and nam on ISD machines:

~csci551/ns

~csci551/nam

Page 17: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

set ns [new Simulator]$ns at 1 "puts \"Hello World!\""$ns at 1.5 "exit"$ns run

simple.tcl:

17

Hello World

Computer Communications - CSCI 551

Copyright © William C. Cheng

nunki 74% ~csci551/ns simple.tclHello World!nunki 75%

Simulator *ns=new Simulator;

ns->at(1, "puts \"Hello World!\"");ns->at(1.5, "exit");ns->run();

Think C++:

Page 18: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

create a simulator, put in var ns

set ns [new Simulator]

18

Hello World, Deconstructed

Computer Communications - CSCI 551

Copyright © William C. Cheng

schedule an event at time t=1 to print HW

$ns at 1 "puts \"Hello World!\""

and exit at a later time

$ns at 1.5 "exit"

run time simulator

$ns run

Page 19: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

Concepts

Essentials

Getting Started

Fundamental tcl, otcl and ns

19

Outlines

Computer Communications - CSCI 551

Copyright © William C. Cheng

Page 20: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

set x 10puts "x is $x"

variables:

20

Basic Tcl

Computer Communications - CSCI 551

Copyright © William C. Cheng

set y [pow x 2]set y [expr x*x]

functions and expressions:

if {$x > 0} { return $x }else { return [expr -$x] }while { $x > 0 } { puts $x incr x -1}

control flow:

proc pow {x n} { if {$n == 1} { return $x } set part [pow x [expr $n-1]] return [expr $x*$part]}

procedures:

Also lists, associative arrays, etc.

can use a real programminglanguage to build networktopologies, traffic models, etc.

Page 21: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

21

Basic otcl

Computer Communications - CSCI 551

Copyright © William C. Cheng

Class Person# constructor:Person instproc init {age} { $self instvar age_ set age_ $age}# method:Person instproc greet {} { $self instvar age_ puts "$age_ years old: How are you doing?"}# subclass:Class Kid -superclass PersonKid instproc greet {} { $self instvar age_ puts "$age_ years old kid: What’s up, dude?"}

set a [new Person 45]set b [new Kid 15]$a greet$b greet

can easily make variations of existing things (TCP, TCP/Reno)⇒

Page 22: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

Creating the event scheduler

22

Basic ns-2

Computer Communications - CSCI 551

Copyright © William C. Cheng

Creating network

Setting up routes

Creating transport connection

Inserting errors

Create traffic

[Turn on tracing]

Page 23: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

Create scheduler

23

Creating Event Scheduler

Computer Communications - CSCI 551

Copyright © William C. Cheng

Schedule event

$ns at <time> <event>

set ns [new Simulator]

<event>: any legitimate ns/tcl commands

Start scheduler

$ns run

Page 24: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

set n0 [$ns node]

Nodes

24

Creating Network

Computer Communications - CSCI 551

Copyright © William C. Cheng

set n1 [$ns node]

$ns duplex-link $n0 $n1 <bandwidth> <delay> <queue_type>

Links & Queuing

<queue_type>: DropTail, RED, CBQ, FQ, SFQ, DRR

Page 25: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

$ns rtproto <type>

Unicast

25

Computing routes

Computer Communications - CSCI 551

Copyright © William C. Cheng

<type>: Static, Session, DV, cost, multi-path

$ns multicast

Multicast

right after [new Simulator]

$ns mrtproto <type>

<type>: CtrMcast, DM, ST, BST

Page 26: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

TCP, UDP, etc.

simple two layers: transport and app

26

Traffic

Computer Communications - CSCI 551

Copyright © William C. Cheng

transports:

ftp, telnet, etc.

applications: (agents)

Page 27: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

$ns attach-agent $n0 $usrc

set usrc [new Agent/UDP]

source and sink

27

Creating Connection: UDP

Computer Communications - CSCI 551

Copyright © William C. Cheng

set udst [new Agent/NULL]

connect them to nodes, then each other

$ns attach-agent $n1 $udst

$ns connect $usrc $udst

Page 28: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

$ns attach-agent $n0 $tsrc

set tsrc [new Agent/TCP]

source and sink

set tdst [new Agent/TCPSink]

connect to nodes and each other

$ns attach-agent $n1 $tdst

$ns connect $tsrc $tdst

28

Creating Connection: TCP

Computer Communications - CSCI 551

Copyright © William C. Cheng

Page 29: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

set ftp [new Application/FTP]

FTP

29

Creating Traffic: On Top of TCP

Computer Communications - CSCI 551

Copyright © William C. Cheng

$ftp attach-agent $tsrc

$ns at <time> "$ftp start"

set telnet [new Application/Telnet]

Telnet

$telnet attach-agent $tsrc

Page 30: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

set src [new Application/Traffic/CBR]

CBR

30

Creating Traffic: On Top of UDP

Computer Communications - CSCI 551

Copyright © William C. Cheng

set src [new Application/Traffic/Exponential]

Exponential or Pareto on-off

set src [new Application/Traffic/Pareto]

Page 31: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

Binary format

set tfile [new Tracefile]

Trace driven

31

Creating Traffic: Trace Driven

Computer Communications - CSCI 551

Copyright © William C. Cheng

$tfile filename <file>

set src [new Application/Traffic/Trace]

$src attach-tracefile $tfile

<file>:

inter-packet time (msec) and packet size (byte)

Page 32: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

no addresses, just global variables

more abstract (much simpler):

32

Compare to Real World

Computer Communications - CSCI 551

Copyright © William C. Cheng

connect them rather than name lookup/bind/listen/accept

set tsrc2 [new Agent/TCP/Newreno]

easy to change implementation

set tsrc3 [new Agent/TCP/Vegas]

Page 33: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

Creating Error Module

33

Inserting Errors

Computer Communications - CSCI 551

Copyright © William C. Cheng

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 34: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

Trace packets on all links into test.out

$ns trace-all [open test.out w]

34

Tracing

Computer Communications - CSCI 551

Copyright © William C. Cheng

<event> <time> <from> <to> <pkt> <size>--<flowid> <src> <dst>

<seqno> <aseqno>

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

Trace packets on all links in nam-1 format

$ns namtrace-all [open test.nam w]

<event> can be + for enqueue, - for dequeue, r for receive, d for drop,

and e for error

Page 35: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

35

Plumbing: Packet Flow

Computer Communications - CSCI 551

Copyright © William C. Cheng

entry_

0

1

0

Agent/TCPAddr

Classifier

PortClassifier

Application/FTP

dst_=1.0

Link n0-n1

entry_

0

1

0

Agent/TCPAddr

Classifier

PortClassifier

dst_=0.0

Link n1-n0

n0 n1

Page 36: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

36

Plumbing: Packet Flow

Computer Communications - CSCI 551

Copyright © William C. Cheng

entry_

0

1

0

Agent/TCPAddr

Classifier

PortClassifier

Application/FTP

dst_=1.0

Link n0-n1

entry_

0

1

0

Agent/TCPAddr

Classifier

PortClassifier

dst_=0.0

Link n1-n0

n0 n1

Page 37: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

37

Plumbing: Packet Flow

Computer Communications - CSCI 551

Copyright © William C. Cheng

entry_

0

1

0

Agent/TCPAddr

Classifier

PortClassifier

Application/FTP

dst_=1.0

Link n0-n1

entry_

0

1

0

Agent/TCPAddr

Classifier

PortClassifier

dst_=0.0

Link n1-n0

n0 n1

Page 38: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

38

Plumbing: Packet Flow

Computer Communications - CSCI 551

Copyright © William C. Cheng

entry_

0

1

0

Agent/TCPAddr

Classifier

PortClassifier

Application/FTP

dst_=1.0

Link n0-n1

entry_

0

1

0

Agent/TCPAddr

Classifier

PortClassifier

dst_=0.0

Link n1-n0

n0 n1

Page 39: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

39

Plumbing: Packet Flow

Computer Communications - CSCI 551

Copyright © William C. Cheng

entry_

0

1

0

Agent/TCPAddr

Classifier

PortClassifier

Application/FTP

dst_=1.0

Link n0-n1

entry_

0

1

0

Agent/TCPAddr

Classifier

PortClassifier

dst_=0.0

Link n1-n0

n0 n1

Page 40: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

40

Plumbing: Packet Flow

Computer Communications - CSCI 551

Copyright © William C. Cheng

entry_

0

1

0

Agent/TCPAddr

Classifier

PortClassifier

Application/FTP

dst_=1.0

Link n0-n1

entry_

0

1

0

Agent/TCPAddr

Classifier

PortClassifier

dst_=0.0

Link n1-n0

n0 n1

Page 41: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

41

Plumbing: Packet Flow

Computer Communications - CSCI 551

Copyright © William C. Cheng

entry_

0

1

0

Agent/TCPAddr

Classifier

PortClassifier

Application/FTP

dst_=1.0

Link n0-n1

entry_

0

1

0

Agent/TCPAddr

Classifier

PortClassifier

dst_=0.0

Link n1-n0

n0 n1

Page 42: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

42

Plumbing: Packet Flow

Computer Communications - CSCI 551

Copyright © William C. Cheng

entry_

0

1

0

Agent/TCPAddr

Classifier

PortClassifier

Application/FTP

dst_=1.0

Link n0-n1

entry_

0

1

0

Agent/TCPAddr

Classifier

PortClassifier

dst_=0.0

Link n1-n0

n0 n1

Page 43: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

43

Plumbing: Packet Flow

Computer Communications - CSCI 551

Copyright © William C. Cheng

entry_

0

1

0

Agent/TCPAddr

Classifier

PortClassifier

Application/FTP

dst_=1.0

Link n0-n1

entry_

0

1

0

Agent/TCPAddr

Classifier

PortClassifier

dst_=0.0

Link n1-n0

n0 n1

Page 44: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

set ns [new Simulator]

# [Turn on tracing]

# Create topology

# Setup packet loss, link dynamics

# Create routing agents

# Create:

# - multicast groups

# - protocol agents

# - application and/or setup traffic sources

# Post-processing procs

# Start simulation

44

Summary: Generic ScriptStructure

Computer Communications - CSCI 551

Copyright © William C. Cheng

Page 45: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

Simple scenario with TCP and UDP connections

45

Example - TCP

Computer Communications - CSCI 551

Copyright © William C. Cheng

n0TCP

n4UDP

n15Mb2ms

n5UDPrecvr

n3TCPSink

n25Mb2ms1.5Mb

10ms

Page 46: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

#Create scheduler

set ns [new Simulator]

#Turn on tracing

set f [open out.tr w]

$ns trace-all $f

set nf [open out.nam w]

$ns namtrace-all $nf

Scheduler & tracing

46

TCP : Step 1

Computer Communications - CSCI 551

Copyright © William C. Cheng

Page 47: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

#create nodes

set n0 [$ns node]

set n1 [$ns node]

set n3 [$ns node]

set n4 [$ns node]

Create topology

47

TCP : Step 2

Computer Communications - CSCI 551

Copyright © William C. Cheng

Page 48: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

#create links

$ns duplex-link $n0 $n1 5Mb 2ms DropTail

$ns duplex-link $n1 $n2 1.5Mb 10ms DropTail

$ns duplex-link $n2 $n3 5Mb 2ms DropTail

$ns queue-limit $n1 $n2 25

$ns queue-limit $n2 $n1 25

48

TCP : Step 3

Computer Communications - CSCI 551

Copyright © William C. Cheng

Page 49: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

set tcp [new Agent/TCP]

set sink [new Agent/TCPSink]

$ns attach-agent $n0 $tcp

$ns attach-agent $n3 $sink

$ns connect $tcp $sink

Create TCP agents

49

TCP : Step 4

Computer Communications - CSCI 551

Copyright © William C. Cheng

Page 50: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

set ftp [new Application/FTP]

$ftp attach-agent $tcp

#start application traffic

$ns at 1.1 "$ftp start’

Attach traffic

50

TCP : Step 5

Computer Communications - CSCI 551

Copyright © William C. Cheng

Page 51: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

$ns at 2.0 "finish"

Proc finish {} {

global ns f

close $f

close $nf

puts "Running nam..."

exec nam out.nam &

exit 0

}

$ns run

End of simulation wrapper (as usual)

51

TCP : Step 6

Computer Communications - CSCI 551

Copyright © William C. Cheng

Page 52: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

Packet-level animation

Nam-1 (Network AniMator Version 1)

52

Viz Tools

Computer Communications - CSCI 551

Copyright © William C. Cheng

Well-supported by ns

Convert trace output into xgraph format

Xgraph

Page 53: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

Color

53

Ns-nam Interface

Computer Communications - CSCI 551

Copyright © William C. Cheng

Node manipulation

Link manipulation

Topology layout

Protocol state

Misc

Page 54: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

$ns color 40 red

$ns color 41 blue

$ns color 42 chocolate

Color mapping

54

Nam Interface: Color

Computer Communications - CSCI 551

Copyright © William C. Cheng

$tcp0 set fid_ 40 ;# red packets

$tcp1 set fid_ 41 ;# blue packets

Color ↔ flow id association

Page 55: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

$node color red

Color

55

Nam Interface: Nodes

Computer Communications - CSCI 551

Copyright © William C. Cheng

$node shape box ;# circle, box, hexagon

Shape (can’t be changed after sim starts)

$ns at 1.0 "$n0 add-mark m0 blue box"

$ns at 2.0 "$n0 delete-mark m0"

Marks (concentric shapes)

$ns at 1.1 "$n0 label \"web cache 0 \""

Label (single string)

Page 56: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

$ns duplex-link-op $n0 $n1 color "green"

Color

56

Nam Interfaces: Links

Computer Communications - CSCI 551

Copyright © William C. Cheng

$ns duplex-link-op $n0 $n1 label "abced"

Label

$ns rtmodel Deterministic {2.0 0.9 0.1} $n0 $n1

Dynamics (automatically handled)

Asymmetric links not allowed

Page 57: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

$ns duplex-link-op $n(0) $n(1) orient right

$ns duplex-link-op $n(1) $n(2) orient right-up

$ns duplex-link-op $n(2) $n(3) orient down

$ns duplex-link-op $n(3) $n(4) orient 60deg

Manual layout: specify everything

57

Nam Interface: Topo Layout

Computer Communications - CSCI 551

Copyright © William C. Cheng

If anything missing -> automatic layout

Page 58: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

$ns add-agent-trace $srm0 srm_agent0

$ns monitor-agent-trace $srm0

$srm0 tracevar C1_

$srm0 tracevar C2_

# ... ...

$ns delete-agent-trace $tcp1

Monitor values of agent variables

58

Nam Interface: Protocol State

Computer Communications - CSCI 551

Copyright © William C. Cheng

Page 59: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

Add textual explanation to your sim

Annotation

59

Nam Interface: Misc

Computer Communications - CSCI 551

Copyright © William C. Cheng

$ns at 3.5 "$ns trace-annotate \"packet drop\""

Set animation rate

$ns at 0.0 "$ns set-animation-rate 0.1ms"

Page 60: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

Available as part of nam-1

Nam editor

60

Other Utilities in Ns

Computer Communications - CSCI 551

Copyright © William C. Cheng

Tcl debugger

For source and documentation, see

http://www.isi.edu/nsnam/ns/ns-debugging.html

Topology generator

http://www.isi.edu/nsnam/ns/ns-topogen.html

Scenario generator

http://www.isi.edu/nsnam/ns/ns-scengeneration.html

Page 61: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

LANs

Other areas in wired domain

61

Other Ns Features

Computer Communications - CSCI 551

Copyright © William C. Cheng

Diffserv

Multicast

Full TCP

Applications like web-caching

Ad hoc routing

Wireless domain

Mobile IP

Satellite networking

Directed diffusion (sensor networks)

Page 62: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

Connect simulator in a real network

Emulator

62

Other Ns Features

Computer Communications - CSCI 551

Copyright © William C. Cheng

Can receive and send out live packets from/into the real

world

Page 63: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

Ns distribution download

http://www.isi.edu/nsnam/ns/ns-build.html

63

Resources

Computer Communications - CSCI 551

Copyright © William C. Cheng

Installation problems and bug-fix

http://www.isi.edu/nsnam/ns/ns-problems.html

Ns-users mailing list

See http://www.isi.edu/nsnam/ns/ns-lists.html

Archives from above URL

[email protected]

Page 64: Computer Communications - CSCI 551 CS551 NS Tutorialmerlot.usc.edu/cs551-m05/lectures/tentative/04_ns-intro.pdfpros: trade-off running vs. writing speed, powerful/documented config

Marc Greis’ tutorial

http://www.isi.edu/nsnam/ns/tutorial

Practical programming in Tcl and Tk, Brent Welch

64

Resources (cont...)

Computer Communications - CSCI 551

Copyright © William C. Cheng

Ns-users archive

Ns-manual

http://www.isi.edu/nsnam/ns/nsdocumentation.html

Tcl (Tool Command Language)

http://dev.scriptics.com/scripting

Otcl (MIT Object Tcl)

~otcl/doc/tutorial.html (in distribution)


Recommended