<!doctype html public "-//w3c//dtd html 4.0 transitional//en">

Simulation of Networks

 

Guidelines for the ns network simulator tool on Windows platform

  1. Introduction
  2. Windows Download
  3. Installation
  4. Program Execution
  5. Verification
  6. Documentation
  7. Tutorial
  8. Examples of application
  9. Editor program
  10. Brief overview of the Tcl language

 

Introduction

 

ns is an event-driven network simulator that has been developed at University of California Berkeley. The simulation engine of ns is implemented in C++ and uses the Object oriented version of Tool Command Language (OTcl) as its front-end. Accessing the ns library through this front-end is thus possible with commands or scripts that are written in the Tcl language.

 

With an interpreter style of code execution, the ns program interprets each line of user script in a Tcl program during execution time and produces the output in the form of a formatted text file.  Post-processing is performed in order to filter particular data throughout the simulation time. Tools are required, such as gnuplot as to create graphs or nam as to display an animated visualization of the ns simulations.

 

Ns works best under unix/linux – there is a windows version that you can play with on your home pc, it is useful for learning ns, but doesn’t work as well as it should. However, there is some windows-based information below, as well as some generic ns stuff.

The main page of ns is at:

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

The main page of nam is at:

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

The ns mailing list archive is at:

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

 

Windows Download

 

ns - binary windows version

 http://www.isi.edu/nsnam/dist/binary/ns-2.1b9a-win32.exe

nam - binary windows version

 http://www.isi.edu/nsnam/dist/binary/nam-1.0a11a-win32.exe

Tcl/Tk

http://aspn.activestate.com/ASPN/Downloads/ActiveTcl/

gnuplot - windows version

 ftp://ftp.cc.monash.edu.au/pub/gnuplot/gnuplot-3.7.2.tar.gz

 


Installation

 

For ns and nam:

  1. Double-click these download files, which can be self-extracting, to start installation.
  2. Input a folder (directory) for the extracted files when prompted.

For gnuplot :

  1. Extract all files to a new directory, such as c:\gnuplot.

 

Program Execution

·         Open an MS-DOS   window.

·        Change to the directory that keeps your own ns programs by typing a DOS command such as "cd  my_directory".

·        Type a command like "c:\ns2\ns  my_program.tcl" to activate the ns program in the c:\ns2\ directory for executing your program (my_program.tcl) in the current directory.

·        To avoid this cumbersome form of command, the DOS command "path" should be issued once at the DOS prompt.
For example:

·        path =%path%;c:\ns2\;c:\nam\;c:\gnuplot\gp37w16

Then, a command to activate either ns program or tools becomes:

·        ns my_program.tcl or

·        nam my_nam.out

·        wgnuplot my_gnuplot_srcipt.gp

 

Verification

·        Copy the example script file of simple.tcl and run ns with it as input.

·        The following should appear on the DOS window:

 

Trace files opened…
Topology defined…
CBR traffic flow over UDP connection between nodes 0 and 3…
CBR traffic starts at time 1.0 sec…
CBR traffic flow over UDP connection between nodes 3 and 1…

CBR traffic starts at time 1.1 sec…
ftp traffic flow over TCP connection between nodes 0 and 3…
ftp traffic starts at time 1.2 sec and finishes at time 1.35 sec…
Simulation complete

 

In order to view an animation of the simulation results:

·        run nam with the file out.nam as input.

·        A nam window like the picture below should pop up. A circle represents a node and a line represents a link.

·        Press the run button, and you will see an animation of the simulation - with many packets being transported on the link at various times as specified by the ns script.

 

 

Documentation

·        The 350-page ns-documentation is available in html, postscript or pdf format at 
http://www.isi.edu/nsnam/ns/ns-documentation.html

·        The user guide for gnuplot is available at 
ftp://ftp.dartmouth.edu/pub/gnuplot

 

Tutorial

·        For a novice, it is strongly recommended to read Marc Greis 's ns tutorial, which is available at http://www.isi.edu/nsnam/ns/tutorial/index.html

·        Homework in the subject of computer networks at various universities, e.g.:

·        CS 268: Computer Networks in Computer Science Department of UC-Bekeley 
[Spring 97]  http://www-mash.cs.berkeley.edu/cs268-s97/ 
[Spring 98]  http://www-mash.cs.berkeley.edu/cs268-s98/

·        http://www.docs.uu.se/~perg/course/datakom2/it98/tcpsims_lab.html

 

Examples of application

·        Lots of examples and ns applications in various fields of computer network and telecommunication can be found in the directory \ns2-1b5\tcl\ex of the full souce-code version of ns.

 

 Editor Program

·        Any text-based editor can be used to edit the tcl files.

 

Brief overview of the Tcl language

 

Tcl command

Meaning

Remarks

Assignment statement

set a 1

assign variable a with value of 1 
(or a = 1)

No previous variable declaration is required.

set b $a

assign the value from variable a to (newly-created) variable b

Since variable a is already declared, this variable should be accessed with the $ sign.

Arithmetic statement

set c [expr 1 / 3.0]

Assign the result from expression 1 / 3.0 to the variable c

 

Print statement

puts "Hello"

Display message "Hello" on the screen.

 

puts $b

Display the value of variable b on the screen.

 

puts $f "Hello"

Print message "Hello" to the f variable

In this case, f is a file variable and should be declared in the previous part of program with the command:
  set f [open myfile.txt w] 
Don't forget to close this file with the command:
  close $f 

Comment statement

# bla bla ...

All characters following the # sign are treated as comments

Possible to lead with the semicolon sign and put at end of line for comment operation on that line.

IF-ELSE statement

If { $a == 1 } { 
    puts "EQ" 
} else { 
    puts "NEQ" 
}

Check whether variable a is equal to 1, if yes display EQ, otherwise display NEQ.

 

Procedure/Function statement

proc my_sum { v1 v2 } { 
    set result [expr $v1+$v2] 
    return $result 
}

The procedure named my_sum requires 2 variables (i.e. v1 and v2).
The operation inside this procedure is to add these two values and return the result of operation.
Format of the call might be in form such as:
  set d  [my_sum 10 20]
or
  puts  [my_sum 10 20]

 

 


W. Suntorn wsuntorn@swin.edu.au 22 Nov 1999
Updated: David Everitt deveritt@it.usyd.edu.au 29 August 2002