Title: Part 7: Network Simulation
1Part 7 Network Simulation
- Overview
- fundamentals of discrete event simulation
- analyzing simulation outputs
- ns-2 simulation
- Motivation
- Learn fundamentals of evaluating network
performance via simulation
2What is simulation?
system boundary
system under study (has deterministic rules
governing its behavior)
exogenous inputs to system (the environment)
real life
observer
3Why Simulation?
- goal study system performance, operation
- real-system not available, is complex/costly or
dangerous (eg space simulations, flight
simulations) - quickly evaluate design alternatives (eg
different system configurations) - evaluate complex functions for which closed form
formulas or numerical techniques not available
4Simulation advantages/drawbacks
- advantages
- save lives, money
- find bugs (in design) in advance
- generality over analytic/numerical techniques
- detail can simulate system details at arbitrary
level - drawbacks
- caution does model reflect reality
- large scale systems lots of resources to
simulate (especially acurrately simulate) - may be slow (computationally expensive 1 min
real time could be hours of simulated time) - art determining right level of model complexity
- statistical uncertainty in results
5The evaluation spectrum
- Numerical models
- Simulation
- Emulation
- Prototype
- Operational system
6Programming a simulation
- What s in a simulation program?
- simulated time internal (to simulation program)
variable that keeps track of simualted time - system state variables maintained by
simulation program define system state - e.g., may track number (possibly order) of
packets in queue, current value of retransmission
timer - events points in time when system changes state
- each event has associate event time
- e.g., arrival of packet to queue, departure from
queue - precisely at these points in time that simulation
must take action (change state and may cause new
future events) - model for time between events (probabilistic)
caused by external environment
7Discrete Event Simulation
- simulation program maintains and updates list of
future events event list - simulator structure
initialize event list
get next (nearest future) event from event list
- Need
- well defined set of events
- for each event simulated system action, updating
of event list
time event time
process event (change state values, add/delete
future events from event list
update statistics
n
done?
8Simulation example
- processes arrive (avg. interrarrival time 1/ l)
for execution (avg. execution time 1/m) on
dual-processor system - arriving customer joins CPU queue with smallest
number of waiting processes
m1
l
m2
- state of system size of each queue
- system events
- job arrivals
- service time completions
- define performance measure to be gathered
9Simulation example
- Simulator actions on arrival event
- if a queue empty place job in service (pick
one of empty queues), determine its service time
(a random number drawn from service time
distribution) add future event onto event list
for job completion, set number of jobs in queue
to 1 - if both queues full increment dropped
packets, ignore arrival - else find which queue to place job in
(shortest, with ties broken randomly), increment
number in queue where queued - create event for next arrival (generate
interarrival time) stick event on event list
10Simulation example
- Simulator actions on departure event
- Remove event, update simulation time, update
performance statistics - decrement counter of number of jobs in queue
- If (number of jobs in queue gt 0) put next job
into service schedule a completion event
(generate service time for job) -
-
-
11Simulation example
- Simulator initialization
- event list
- state variables
Code walkthrough
12Gathering Performance Statistics
- avg delay at queue i record Dij delay of
customer j at queue i. Let Ni be customers
passing through queue i
- throughput at queue i, gi
- Average queue length at i
Littles Law
13Analyzing Output Results
- Each time we run simulation, (using different
random number streams), we will get different
output results!
distribution of random numbers to be used during
simulation (interarrival, service times)
14Analyzing Output Results
- W2,n delay of nth departing customer from queue
2
15Analyzing Output Results
- each run shows variation in customer delay
- one run different from next
- statistical characterization of delay must be
made - expected delay of nth customer
- behavior as n approaches infinity
- average of n customers
16Transient Behavior
- simulation outputs that depend on initial
condition (i.e., output value changes when
initial conditions change) are called transient
characteristics - early part of simulation
- later part of simulation less dependent on
initial conditions - Example of transient characteristics?
-
-
-
17Effect of initial conditions
- Histogram of delay of 20th customer, given
initially empty (1000 runs)
- Histogram of delay of 20th customer, given
non-empty conditions
18Steady state behavior
- Output results may converge to limiting steady
state value if simulation run long enough
avg delay of packets n, n10
avg of 5 simulations
- want to discard statistics gathered during
transient phase, e.g., ignore first n0
measurements of delay at queue 2
- Pick n0 so that statistic is approximately
- the same for different random number
- streams and remains same as n increases
19Confidence Intervals
- run simulation get estimate V1 as estimate of
performance metrics of interest - repeat simulation M times (each with new set of
random numbers), get V2, VM all different! - which of V1, VM is right?
20Confidence Intervals
- Can not get perfect estimate of true mean, m,
with finite samples - Look for bounds find c1 and c2 such that
- Probability(c1 lt m lt c2) 1 a
- c1,c2 confidence interval
- 100(1-a) confidence level
- One approach for finding c1, c2 (suppose a.1)
- take k samples (e.g., k independent simulation
runs) - sort
- find largest value is smallest 5 -gt c1
- find smallest value in largest 5 -gt c2
21Confidence Intervals Central Limit Thm
- Central Limit Theorem If samples V1, VM
independent and from same population with
population mean m and standard deviation s, then
sample mean
is approximately normally distributed with mean u
and standard deviation
22Confidence Intervals .. more
- Still dont know population standard deviation.
So we estimate it using sample (observed)
standard deviation
- Given we can now find upper and lower
tails of normal distributions containing a100 of
the mass
23Confidence Intervals .. the recipe
- Given samples V1, VM, (e.g., having repeated
simulation M times), compute
95 confidence interval
24Interpretation of Confidence Interval
- If we calculate confidence intervals as in
recipe, 95 of the confidence intervals thus
computed will contain the true (unknown)
population mean.
25ns-2, the network simulator
- Our goal
- flavor of ns simple example, modification,
execution and trace analysis
- discrete event simulator
- modeling network protocols
- wired, wireless, satellite
- TCP, UDP, multicast, unicast
- web, telnet, ftp
- ad hoc, sensor nets
- infrastructure stats, tracing, error models,
etc. - prepackaged protocols and modules, or create your
own
26ns components
- ns, the simulator itself (this is all well have
time for) - nam, the Network AniMator
- visualize ns (or other) output
- GUI input simple ns scenarios
- pre-processing
- traffic and topology generators
- post-processing
- simple trace analysis, often in Awk, Perl, or Tcl
- tutorial http//www.isi.edu/nsnam/ns/tutorial/ind
ex.html - ns by example http//nile.wpi.edu/NS/
27ns Software Structure C and Otcl
- Uses two languages
- C for packet-processing
- fast to run, detailed, complete control
- OTcl for control our focus
- simulation setup, configuration, occasional
actions - fast to write and change
28Basic ns-2
- Creating the event scheduler
- Creating network
- Computing routes
- Creating connection
- Creating traffic
- Inserting errors
- Tracing
29Creating Event Scheduler
- Create scheduler
- set ns new Simulator
- Schedule event
- ns at lttimegt lteventgt
- lteventgt any legitimate ns/tcl commands
- Start scheduler
- ns run
30Creating Network
- Nodes
- set n0 ns node
- set n1 ns node
- Links connect together two nodes
- ns duplex-link n0 n1 ltbandwidthgt ltdelaygt
ltqueue_typegt - ltqueue_typegt DropTail, RED, CBQ, FQ, SFQ, DRR
31Inserting 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
32Computing routes
- 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
33Traffic
- simple two layers transport and app
- transports
- TCP, UDP, etc.
- sources, sinks
- transport protocol instances attached to nodes
- applications (agents)
- ftp, telnet, etc.
- application instances attached to transport
protocol instances
34Creating Connection UDP
- source and sink
- set usrc new Agent/UDP
- set udst new Agent/NULL
- connect them to nodes, then each other
- ns attach-agent n0 usrc
- ns attach-agent n1 udst
- ns connect usrc udst
35Creating Connection TCP
- source and sink
- set tsrc new Agent/TCP
- set tdst new Agent/TCPSink
- connect to nodes and each other
- ns attach-agent n0 tsrc
- ns attach-agent n1 tdst
- ns connect tsrc tdst
36Creating Traffic On Top of TCP
- FTP
- set ftp new Application/FTP
- ftp attach-agent tsrc
- ns at lttimegt ftp start
- Telnet
- set telnet new Application/Telnet
- telnet attach-agent tsrc
37Creating 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
38Tracing
- Trace packets on all links into test.out
- ns trace-all open test.out w
- lteventgt lttimegt ltfromgt lttogt ltpktgt ltsizegt--ltflowidgt
ltsrcgt ltdstgt ltseqnogt ltaseqnogt - 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
packet type
packet flags
seq number
time
packet ID
- enqueue
- dequeue
- r receive
- d drop
packet length
flow ID
source dest addresses
nodes involved in this event
39Tracing
- trace packets on all links in nam-1 format
- ns namtrace-all open test.nam w
- post-process traces (e.g., using AWK) to
determine performance
40Walk-through example
ftp/tcp source
ftp/tcp dest
acks
CBR/udp source
CBR/udp source
1 Mbps full duplex 10 msec prop delay 5 packet
buffer