SungkyunkwanSungkyunkwan UniversityUniversity
Copyright 2000-2006 Networking Laboratory
NS Simulator for beginnersNS Simulator for beginners
Chapter 2. ns Simulator Preliminaries
2007-04-14
Jeonghoon Park
Networking Laboratory 2/24NS Simulator
ContentsContents
� Initialization and termination
� Definition of a network of links and nodes
� Agents and applications
� Scheduling events
� Visualisation: using nam
� Tracing
� Random variables
Networking Laboratory 3/24NS Simulator
Initialization and terminationInitialization and termination
� An ns simulation starts with the command
� Creating output files (trace files or nam files)
Networking Laboratory 4/24NS Simulator
Initialization and terminationInitialization and termination
� The termination of the program
� At the end of the ns program we should call the procedure “finish”and specify at what time the termination should occur.
Networking Laboratory 5/24NS Simulator
Definition of a network of links and Definition of a network of links and nodesnodes
� Definition of a node
� Definition of a link
� In NS, an output queue of a node is implemented as a part of each link whose input is that node.
� Definition of the buffer capacity of the queue related to each link
Networking Laboratory 6/24NS Simulator
Definition of a network of links and Definition of a network of links and nodesnodes
� Form of a simplex link
� Duplex link is constructed from two parallel simplex links.
Networking Laboratory 7/24NS Simulator
Definition of a network of links and Definition of a network of links and nodesnodes
� Defining nodes, links and assigning queue size
Networking Laboratory 8/24NS Simulator
Agents and applicationsAgents and applications
� FTP over TCP
Networking Laboratory 9/24NS Simulator
Agents and applicationsAgents and applications
� CBR over UDP
Networking Laboratory 10/24NS Simulator
Scheduling eventsScheduling events
� The Tcl script defines when event should occur.� Format
� Examples
� The scheduler is started when running ns, i.e. through the command $ns run.
Networking Laboratory 11/24NS Simulator
VisualisationVisualisation: using : using namnam
� Giving node position (for NAM)
Networking Laboratory 12/24NS Simulator
TracingTracing
� Tracing objects in a simplex link
� EnqT registers information concerning a packet that arrives and is queued at the input queue of the link.
� DrpT handles the information concerning the dropped packet.� DeqT registers information at the instant the packet is dequed.� RecvT gives us information about packets that have been received
at the output of the link.
Networking Laboratory 13/24NS Simulator
TracingTracing
� Structure of trace files
� Event: event type.� r: receive (at the output of the link)
� +: enqueued
� -: dequeued
� d: dropped
� Time: the time at which the events occurs.
� From node: givens the input node of the link at which the events occurs.
� To node: fives the output node of the link at which the events occurs.
� Pkt id: unique id of the packet
Networking Laboratory 14/24NS Simulator
TracingTracing
� Example
� Tracing a subset of events
Networking Laboratory 15/24NS Simulator
Random variablesRandom variables
� Seeds and generators� The seed value of 0 results in the generation of a new random
variable each time we run the simulation.
� In contrast, if we use other seeds then each time we run the simulation, the same sequence of random variables that are generated in a simulation will be generated.
� Creating random variables� Creating a new generator
� When actually creating a random variable, we have to define its distribution type and its parameters.
Networking Laboratory 16/24NS Simulator
Random variablesRandom variables
Networking Laboratory 17/24NS Simulator
Random variablesRandom variables
Networking Laboratory 18/24NS Simulator
Random variablesRandom variables
Networking Laboratory 19/24NS Simulator
SungkyunkwanSungkyunkwan UniversityUniversity
Copyright 2000-2006 Networking Laboratory
NS Simulator for beginnersNS Simulator for beginners
Chapter 3. How to work with trace files
2007-04-14
Jeonghoon Park
Networking Laboratory 20/24NS Simulator
Processing data files with Processing data files with awkawk
� The awk utility allows us to do simple operations on data files.� Averaging the value of a given column, summing or multiplying
term by term between several columns, all data reformatting tastks.
� Examples� Averaging the values in column 4 of a file
� Obtaining the standard deviation of column 4 of a file
Networking Laboratory 21/24NS Simulator
Using Using grepgrep
� The grep command allows us to ‘filter’ a file.
� Example� Output traces in ns may contain all types packets that go through
all links and we may be interested only in the data concerning tcppackets that went from node 0 to node 2.
� We may wish to obtain a file containing all lines of tr1.tr begin with the letter r.
� If we wish to make a file of all the lines that begin with “s” and have later “tcp 1020” we should type
Networking Laboratory 22/24NS Simulator
Plotting with Plotting with gnuplotgnuplot
� Example
� Produce a curve that is smaller than the default.
� Produce points that are larger than the defaults.
� Tells gnuplot where to put the ‘key’
� Restricts the range of the x axis.
� Superimposes three curves in a single figure
(참고: http://kldp.org/KoreanDoc/html/GnuPlot-KLDP/)
Networking Laboratory 23/24NS Simulator
Plotting with Plotting with gnuplotgnuplot
� Example
Networking Laboratory 24/24NS Simulator
Plotting with Plotting with xgraphxgraph� Xgraph is a plotting utility that is provided by ns.� Some options in xgraph
� Title: -t “title”� Size: -geometry xsize x ysize� Title for axis: -x “xtitle” –y “ytitle”� Color of text and grid: -v
� Example