You are on page 1of 24

Sungkyunkwan University

NS Simulator for beginners

Chapter 2. ns Simulator Preliminaries 2007-04-14 Jeonghoon Park hypnos2000@skku.edu

Copyright 2000-2006 Networking Laboratory

Contents
Initialization and termination Definition of a network of links and nodes Agents and applications Scheduling events Visualisation: using nam Tracing Random variables

NS Simulator

Networking Laboratory 2/24

Initialization and termination


An ns simulation starts with the command

Creating output files (trace files or nam files)

NS Simulator

Networking Laboratory 3/24

Initialization 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.

NS Simulator

Networking Laboratory 4/24

Definition of a network of links and nodes


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

NS Simulator

Networking Laboratory 5/24

Definition of a network of links and nodes


Form of a simplex link

Duplex link is constructed from two parallel simplex links.

NS Simulator

Networking Laboratory 6/24

Definition of a network of links and nodes


Defining nodes, links and assigning queue size

NS Simulator

Networking Laboratory 7/24

Agents and applications


FTP over TCP

NS Simulator

Networking Laboratory 8/24

Agents and applications


CBR over UDP

NS Simulator

Networking Laboratory 9/24

Scheduling 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.
NS Simulator Networking Laboratory 10/24

Visualisation: using nam


Giving node position (for NAM)

NS Simulator

Networking Laboratory 11/24

Tracing
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.
NS Simulator Networking Laboratory 12/24

Tracing
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
NS Simulator Networking Laboratory 13/24

Tracing
Example

Tracing a subset of events

NS Simulator

Networking Laboratory 14/24

Random 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.
NS Simulator Networking Laboratory 15/24

Random variables

NS Simulator

Networking Laboratory 16/24

Random variables

NS Simulator

Networking Laboratory 17/24

Random variables

NS Simulator

Networking Laboratory 18/24

Sungkyunkwan University

NS Simulator for beginners

Chapter 3. How to work with trace files 2007-04-14 Jeonghoon Park hypnos2000@skku.edu

NS Simulator

Copyright 2000-2006 Networking Laboratory Networking Laboratory 19/24

Processing data files with awk


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

NS Simulator

Networking Laboratory 20/24

Using grep
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 tcp packets 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

NS Simulator

Networking Laboratory 21/24

Plotting with gnuplot


(: http://kldp.org/KoreanDoc/html/GnuPlot-KLDP/)

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

NS Simulator

Networking Laboratory 22/24

Plotting with gnuplot


Example

NS Simulator

Networking Laboratory 23/24

Plotting with xgraph


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

NS Simulator

Networking Laboratory 24/24

You might also like