Networks II NS2 tutorialProjects - PowerPoint PPT Presentation

1 / 64
About This Presentation
Title:

Networks II NS2 tutorialProjects

Description:

Networks II NS2 tutorialProjects – PowerPoint PPT presentation

Number of Views:160
Avg rating:3.0/5.0
Slides: 65
Provided by: raghu1
Category:

less

Transcript and Presenter's Notes

Title: Networks II NS2 tutorialProjects


1
Networks II ---NS-2 tutorial/Projects
  • Dustin Jiang
  • 06/07/02

The materials are modified from 5th VINT/NS
simulation tutorial/workshop
2
Outline
  • NS2 Overview
  • NS2 Fundamentals
  • Project I overview

3
What is NS2
  • Discrete event simulator
  • Packet-level
  • Link layer and up
  • Wired and wireless
  • Platforms
  • Most UNIX and UNIX-like systems
  • Window 95/98/NT
  • (Emulation only for FreeBSD for now)

4
Functionality of ns2
5
Resources
  • Tcl (Tool Command Language)
  • http//dev.scriptics.com/scripting
  • OTcl (MIT Object Tcl)
  • gammaotcl/doc/tutorial.html (in distribution)
  • ns manual
  • Included in distribution gamma2ns/doc
  • http//www.isi.edu/nsnam/ns/ns-documentation.html
  • ns tutorial
  • http//perform.wpi.edu/NS/

6
Part I Fundamentals
7
ns Architecture
  • Object-oriented (C, OTcl)
  • C for data
  • Per packet action
  • OTcl for control
  • Periodic or triggered action

8
OTcl and C The Duality
Pure OTcl objects
Pure C objects
C/OTcl split objects
C
OTcl
ns
9
Extending Tcl Interpreter
  • OTcl object-oriented Tcl
  • TclCL C and OTcl linkage
  • Discrete event scheduler
  • Data network components
  • Link layer and up
  • Emulation support

Tcl
C/C
ns-2
10
Hello World - Batch Mode
  • simple.tcl
  • set ns new Simulator
  • ns at 1 puts \Hello World!\
  • ns at 1.5 exit
  • ns run
  • swallow 74 ns simple.tcl
  • Hello World!
  • swallow 75

11
Basic tcl
  • Command arg1 arg2 arg3
  • set a 43
  • set b 27
  • proc test a b
  • set c expr a b
  • set d expr expr a - b c
  • for set k 0 k lt 10 incr k
  • if k lt 5
  • puts k lt 5, pow expr pow(d, k)
  • else
  • puts k gt 5, mod expr d k
  • test 43 27

12
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

13
Elements of ns-2
  • Create the event scheduler
  • Turn on tracing
  • Create network
  • Setup routing
  • Insert errors
  • Create transport connection
  • Create traffic
  • Transmit application-level data

14
Creating Event Scheduler
  • Create event scheduler
  • set ns new Simulator
  • Schedule events
  • ns at lttimegt lteventgt
  • lteventgt any legitimate ns/tcl commands
  • ns at 1.0 ftp start
  • Start scheduler
  • ns run

15
Tracing
  • Trace packets on all links
  • Open the NAM trace file Open the Trace file
  • set nf open out.nam w set tf open
    out.tr w
  • ns namtrace-all nf ns
    trace-all tf
  • Must appear immediately after creating scheduler
  • Turn on tracing on specific links
  • ns trace-queue n0 n1
  • ns namtrace-queue n0 n1

16
Creating Network
  • Nodes
  • set n0 ns node
  • set n1 ns node
  • Links and queuing
  • ns duplex-link n0 n1 ltbandwidthgt ltdelaygt
    ltqueue_typegt
  • ltqueue_typegt DropTail, RED, CBQ, FQ, SFQ, DRR
  • ns duplex-link-op no n1 OPTIONS

n0
n1
17
Setup Routing
  • Unicast
  • ns rtproto lttypegt
  • lttypegt Static, Session, DV, cost, multi-path
  • Multicast
  • ns multicast (right after new Simulator)
  • ns mrtproto lttypegt
  • lttypegt CtrMcast, DM, ST, BST

18
Creating Connection UDP
  • 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

UDP
null
n0
n1
19
Creating Traffic On Top of UDP
  • CBR
  • set src new Application/Traffic/CBR
  • src attach-agent udp0
  • Exponential or Pareto on-off
  • set src new Application/Traffic/Exponential
  • set src new Application/Traffic/Pareto
  • src attach-agent udp0

CBR
UDP
null
n0
n1
20
Creating Connection TCP
  • 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

TCP
sink
n0
n1
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

FTP
TCP
sink
n0
n1
22
Post-processing general trace file
cat out.tr grep " 2 3 cbr " grep r column
1 10 awk 'dif 2 - old2 if(dif0) dif
1 if(dif gt 0) printf("d\tf\n", 2, (1 -
old1) / dif) old1 1 old2 2' gt
jitter.txt
23
Post-processing NAM trace file
  • Event -t time -s from d to p pType e pSize -c
    flowId -i uid a flowId -x source destination
    seqNo flag sname
  • C Ecn Echo P priority A congestion window
    reducded E Congestion Experiented F fast
    start tcp-fs and tcp-int M Ecn-capable-transpor
    t
  • r -t 0.156112 -s 1 -d 2 -p tcp -e 1000 -c 2 -i
    177 -a 2 -x 1.0 5.0 52 ------- null
  • -t 0.156112 -s 2 -d 3 -p tcp -e 1000 -c 2 -i
    177 -a 2 -x 1.0 5.0 52 ------- null
  • d -t 0.156112 -s 2 -d 3 -p tcp -e 1000 -c 2 -i
    177 -a 2 -x 1.0 5.0 52 ------- null
  • r -t 0.156184 -s 3 -d 4 -p tcp -e 1000 -c 1 -i
    101 -a 1 -x 0.0 4.0 33 ------- null
  • -t 0.156184 -s 4 -d 3 -p ack -e 40 -c 1 -i 184
    -a 1 -x 4.0 0.0 33 ------- null
  • - -t 0.156184 -s 4 -d 3 -p ack -e 40 -c 1 -i 184
    -a 1 -x 4.0 0.0 33 ------- null

24
Summary Generic Script Structure
  • 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

25
Visualization Tools
  • nam-1 (Network AniMator Version 1)
  • Packet-level animation
  • Well supported by ns
  • xgraph
  • Conversion from ns trace to xgraph format

26
nam
  • Basic visualization
  • Topology layout
  • Animation control
  • Synchronous replay
  • Fine-tune layout
  • TCP/SRM visualization
  • Editor generate ns simulation scripts

27
ns?nam Interface
  • Color
  • Node manipulation
  • Link manipulation
  • Topology layout
  • Protocol state
  • Misc

28
nam Interface Color
  • Color mapping
  • ns color 40 red
  • ns color 41 blue
  • ns color 42 chocolate
  • Color ? flow id association
  • tcp0 set fid_ 40 red packets
  • tcp1 set fid_ 41 blue packets

29
nam Interface Nodes
  • Color
  • node color red
  • Shape (cant be changed after sim starts)
  • node shape box circle, box, hexagon
  • Marks (concentric shapes)
  • ns at 1.0 n0 add-mark m0 blue box
  • ns at 2.0 n0 delete-mark m0
  • Label (single string)
  • ns at 1.1 n0 label \web cache 0\

30
nam Interfaces Links
  • Color
  • ns duplex-link-op n0 n1 color "green"
  • Label
  • ns duplex-link-op n0 n1 label "abced"
  • Dynamics (automatically handled)
  • ns rtmodel Deterministic 2.0 0.9 0.1 n0 n1
  • Asymmetric links not allowed

31
nam Interface Topo 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

32
nam Interface Protocol State
  • Monitor values of agent variables
  • ns add-agent-trace srm0 srm_agent0
  • ns monitor-agent-trace srm0
  • srm0 tracevar C1_
  • srm0 tracevar C2_
  • ns delete-agent-trace tcp1

33
nam Interface Misc
  • Annotation
  • Add textual explaination to your sim
  • ns at 3.5 "ns trace-annotate \packet drop\"
  • Set animation rate
  • ns at 0.0 "ns set-animation-rate 0.1ms"

34
xgraph
  • The xgraph program draws a graph on an X display
    given data read from either data files.
  • To run it xgraph dataFileName
  • You can save the hardcopy of the graph as a
    postscript file.
  • Xgraph is available on gamma/usr/local/ns-allinon
    e-2.1b8a/bin/xgraph

35
xgraph
  • Format of the input data file
  • Device Postscript
  • Disposition To File
  • FileOrDev /usr/tmp/hpgl.out
  • TitleText Sample Xgraph Data
  • "Alpha
  • -5 29
  • -4.9 27.91
  • -------
  • 5 19
  • Notes a blank line is required between two data
    sets.
  • "Beta
  • -5 33
  • -4.9 31.81
  • -4.8 30.64
  • ------

36
A simulation example
ftp
W32
tcp
sink
n0
n4
5Mb, 15ms
n2
n3
10Mb,2ms
10Mb,2ms
n1
n5
sink
tcp
ftp
W32
37
(No Transcript)
38
(No Transcript)
39
Part II Project I overview
40
Outline
  • Queue management mechanisms
  • TCP flavors
  • Project assignments
  • Project options and schedule

41
Fair queue
  • Queue maintained at each output port
  • Packet placed in queue for its flow
  • Round robin servicing
  • Skip empty queues
  • Can have weighted fair queuing

42
RED Overview
  • Detects congestion using avg. queue size
  • Drop probability is a function of the avg. queue
    size. min_th, max_th, p_max
  • No bias against bursty traffic
  • No global synchronization
  • A flows drop rate is proportional to its share
    of the bandwidth through the gateway

43
RED Approach
  • RED queue management, roughly
  • for each packet arrival
  • calculate the new average queue size avg
  • if min_th lt avg gtmax_th
  • calculate probability pa
  • with probability pa
  • mark/drop the arriving packet
  • else if max_th lt avg
  • drop the arriving packet
  • Variables
  • avg average queue size
  • Pa packet marking/dropping probability
  • Parameters
  • Min_th minimum threshold for queue
  • Max_th maximum threshold for queue

44
RED Drawbacks
  • There is no TCP-awareness
  • Dropping packets from flows in proportion to
    their bandwidth doesnt result in fair sharing.
    e.g Fast link vs. a Slow link
  • Does not consider the number of flows
  • Discrimination against
  • Large RTT flows w.r.t. Small RTT flows
  • Adaptive flows w.r.t. Non-adaptive flows

45
SRED Stabilized RED
  • Avg. Q size is not used for drop probability
  • Does statistical estimation of active flows
  • Drop probability is
    f (instantaneous Q size, active flows)
  • Stabilizes buffer occupation at a level
    independent of the number of active flows
  • Identifies misbehaving flows

46
SRED Approach
  • Hit(t) 0 if no hit 1 if hit
  • Hit frequency P at an instant t is defined as
    P(t) (1
    a)P(t 1) a Hit(t), 0 lt a lt 1
  • a p/M, p is overwrite prob, M is flow table
    size
  • psred(q) pmax if B/3 lt q lt B,
  • pmax/4 if B/6 lt q lt B/3,
  • 0 if 0 lt q lt B/6


  • pzap psred(q) min (1, 1/(256 P(t))2)

47
FRED Flow RED
  • Uses per-active-flow accounting
  • Each flows loss rate depends on the flows
    buffer use
  • Protects adaptive flows
  • Isolates non-adaptive greedy flows
  • Uses the RED approach with modifications

48
FRED Approach
  • Maintain a flow-state table, one entry per active
    flow with fields qleni and strikei
  • Parameters minq, maxq, avgcq
  • Identify non-adaptive flows as
  • qleni gt maxq
  • avg gt maxth qleni gt 2 avgcq
  • qleni gt avgcq strike gt 1
  • Drop only from robust flows qleni gt minq

49
Comparison of various queue policies
  • Fairness over time or over traffic load
  • Average queue length over time or over traffic
    load
  • Queue delay over time or over traffic load
  • Packet less ratio over time or over traffic load
  • Link utilization over time or over traffic load
  • FQ (Fair Queue)
  • RED Random Early Detection
  • One of the following
  • SRED Stabilized RED
  • FRED
  • REM
  • BLUE
  • AVQ Active Virtual Queue
  • Or any kind of adaptive queue management scheme.

50
TCP Agents
  • ns has several variants of TCP available
  • -- Agent/TCP a tahoe'' TCP sender
  • -- Agent/TCP/Reno a Reno'' TCP sender
  • -- Agent/TCP/NewReno Reno with a modification
  • -- Agent/TCP/Sack1 TCP with selective repeat
    (follows RFC2018)
  • -- Agent/TCP/Vegas TCP Vegas
  • -- Agent/TCP/Fack Reno TCP with forward
    acknowledge ment''
  • The oneway TCP receiving agents currently
    supported are
  • -- Agent/TCPSink TCP sink with one ACK per
    packet
  • -- Agent/TCPSink/DelAck TCP sink with
    configurable delay per ACK
  • -- Agent/TCPSink/Sack1 selective ACK sink
    (follows RFC2018)
  • -- Agent/TCPSink/Sack1/DelAck Sack1 with DelAck
  • The twoway experimental sender currently supports
    only a Reno form of TCP
  • -- Agent/TCP/FullTcp

51
TCP Flavors
  • TCP-Tahoe
  • W1 adaptation on congestion
  • TCP-Reno
  • WW/2 adaptation on fast retransmit, W1 on
    timeout
  • TCP-newReno
  • TCP-Reno intelligent fast recovery
  • TCP-Vegas, TCP-SACK

52
TCP Tahoe
  • Slow-start
  • Congestion control upon time-out or DUP-ACKs
  • When the sender receives 3 duplicate ACKs for the
    same sequence number, sender infers a loss
  • Congestion window reduced to 1 and slow-start
    performed again
  • Simple
  • Congestion control too aggressive

53
TCP Reno
  • Tahoe
  • Packet loss detected both through timeouts, and
    through DUP-ACKs
  • Sender reduces window by half, the ssthresh is
    set to half of current window, and congestion
    avoidance is performed (window increases only by
    1 every round-trip time)
  • Fast recovery ensures that pipe does not become
    empty
  • Window cut-down to 1 (and subsequent slow-start)
    performed only on time-out

54
TCP New-Reno
  • TCP-Reno with more intelligence during fast
    recovery
  • In TCP-Reno, the first partial ACK will bring the
    sender out of the fast recovery phase
  • Results in timeouts when there are multiple
    losses
  • In TCP New-Reno, partial ACK is taken as an
    indication of another lost packet (which is
    immediately retransmitted).
  • Sender comes out of fast recovery only after all
    outstanding packets (at the time of first loss)
    are ACKed

55
TCP SACK
  • TCP (Tahoe, Reno, and New-Reno) uses cumulative
    acknowledgements
  • When there are multiple losses, TCP Reno and
    New-Reno can retransmit only one lost packet per
    round-trip time
  • What about TCP-Tahoe?
  • SACK enables receiver to give more information
    to sender about received packets allowing sender
    to recover from multiple-packet losses faster and
    more efficiently

56
TCP SACK (Example)
  • Assume packets 5-25 are transmitted
  • Let packets 5, 12, and 18 be lost
  • Receiver sends back a CACK5, and
    SACK(6-11,13-17,19-25)
  • Sender knows that packets 5, 12, and 18 are lost
    and retransmits them immediately

57
Other TCP flavors
  • TCP Vegas
  • Uses round-trip time as an early-congestion-feedba
    ck mechanism
  • Reduces losses
  • TCP FACK
  • Intelligently uses TCP SACK information to
    optimize the fast recovery mechanism further

58
TCP Agent Parameters
  • Common configuration parameters and defaults for
    TCP agents
  • Agent/TCP set window 20 max bound on window
    size
  • Agent/TCP set windowInit 1 initial/reset
    value of cwnd
  • Agent/TCP set windowOption 1 cong avoid
    algorithm (1 standard)
  • Agent/TCP set windowConstant 4 used only when
    windowOption ! 1
  • Agent/TCP set windowThresh 0.002 used in
    computing averaged window
  • Agent/TCP set overhead 0 !0 adds random time
    between sends
  • Agent/TCP set ecn 0 TCP should react to ecn
    bit
  • Agent/TCP set packetSize 1000 packet size
    used by sender (bytes)
  • Agent/TCP set bugFix true see documentation
  • Agent/TCP set slowstartrestart true see
    documentation

59
TCP Agent Parameters
  • Agent/TCP set tcpTick 0.1 timer granularity
    in sec (.1 is NONST ANDARD)
  • Agent/TCP set maxrto 64 bound on RTO
    (seconds)
  • Agent/TCP set dupacks 0 duplicate ACK counter
  • Agent/TCP set ack 0 highest ACK received
  • Agent/TCP set cwnd 0 congestion window
    (packets)
  • Agent/TCP set awnd 0 averaged cwnd
    (experimental)
  • Agent/TCP set ssthresh 0 slowstat threshold
    (packets)
  • Agent/TCP set rtt 0 rtt sample
  • Agent/TCP set srtt 0 smoothed (averaged) rtt
  • Agent/TCP set rttvar 0 mean deviation of rtt
    samples
  • Agent/TCP set backoff 0 current RTO backoff
    factor
  • Agent/TCP set maxseq 0 max (packet) seq
    number sent

60
TCP Sink Agents
  • Sinks for oneway TCP senders
  • Types
  • -- standard sinks, delayedACK sinks, SACK sinks
  • Standard sinks
  • -- generate one ACK per packet received
  • -- ACK number overloaded in sequence number''
    packet field
  • DelayedACK sinks
  • -- same as standard, but with variable delay
    added between
  • -- time to delay ACKs specified in seconds
  • SACK sinks
  • ACKs
  • -- generates additional information for SACK
    capable sender
  • -- configurable maxSackBlocks parameter

61
TwoWay TCP (FullTCP'')
  • most TCP objects are oneway (and require a
    source/sink pair)
  • real TCP can be bidirectional
  • simultaneous two way data transfer alters TCP
    dynamics considerably
  • the TCP/FullTcp agent
  • -- follows closely to Reno'' TCP implementation
    in 4.4 BSD
  • -- byte oriented transfers
  • -- two way data supported
  • -- most of the connection establishment/teardown
  • -- symmetric only one agent type used for both
    sides

62
FullTCP Parameters
  • Parameters and defaults
  • Agent/TCP/FullTcp set segsperack 1 segs
    received before generating ACK
  • Agent/TCP/FullTcp set segsize 536 segment
    size (MSS size for bulk xfers)
  • Agent/TCP/FullTcp set tcprexmtthresh 3
    dupACKs thresh to trigger fast rexmt
  • Agent/TCP/FullTcp set iss 0 initial send
    sequence number
  • Agent/TCP/FullTcp set nodelay false disable
    senderside Nagle algorithm
  • Agent/TCP/FullTcp set dataonsyn false send
    data on initial SYN?
  • Agent/TCP/FullTcp set dupsegfix true avoid
    fast rxt due to dup segsacks
  • Agent/TCP/FullTcp set dupackreset false
    reset dupACK ctr on !0 len data seg s containing
    dup ACKs
  • Agent/TCP/FullTcp set interval 0.1 delayed
    ACK interval

63
Comparison of various TCP Flavors
  • Fairness over time and over traffic load
  • Responsiveness over time and over traffic load
  • Link utilization over time and over traffic load
  • Packet drop ratio over time and over traffic load
  • Packet retransmission ratio over time and over
    traffic load
  • Average queue size over time and over traffic
    load
  • Tahoe (TCP with the slow start, congestion
    avoidance, and fast retransmit algorithm)
  • Reno (Tahoe plus fast recovery algorithm)
  • New Reno with ECN
  • SACK (selective Acknowledgements)
  • FACK (forward Acknowledgements)
  • Rate-Halving with ECN

64
Topology
65
Final Report
  • Full implementation design
  • Comprehensive set of results
  • Two separated reports
  • Code
  • Refer to the project description on course
    website for more information.
Write a Comment
User Comments (0)
About PowerShow.com