Experiment 4: Using Free Open Source Software tools for network simulation



Using Free Open Source Software tools for network simulation – I Preliminary usage of the tool ns-2 Simulate telnet and ftp between N sources – N sinks (N = 1, 2, 3). Evaluate the effect of increasing data rate on congestion.


At the end of this experiment students will be able to:

  1. Understand the algorithm
  2. Write the TCL scrip fo the given scenario
  3. Simulate the scenario using NAM
  4. Write the the AWK scrip for analyzing the scenario data


An Otcl program experiment-4.tcl used to simulate the network in problem.  A simulation is defined by a Tcl program. To simulate a four node point-to-point network the links are connected as: n0-n2,n1-n2 and n2-n3. Hence this network consists of 4 nodes (n0,n1,n2,n3) as shown in the figure below. Nodes 0 and 1 have a bandwidth of 2Mb with a delay of 10ms and node 2 and 3 have a bandwidth of 1Mb with a delay of 10ms. There are duplex links existing between nodes 0 and 2 and nodes 1 and 2. Nodes 2 and 3 are connected using simplex links. TCP agent is applied between nodes 0 and 3 and UDP agent between nodes 1 and 3. Once the links are set, a Drop Tail queue, of size 10 is set for each node and the FTP traffic is attached to the TCP connections and Telnet is attached to the UDP part of the connection. Once both the links and the queue size are set the timing for the Telnet to start is set at 0.5 and is made to stop at 24.5. Similarly the timing for FTP is set at 0.5 and is made to stop at 24.5 and thus the events are scheduled. The simulation is run via the ns run command, and continues until there are no more events to be processed. The total running time for the whole simulation is 25.

TCL Script 

 #create Simulator

set ns [new Simulator]

#Open Trace and NAM Trace File

set ntrace [open ex3.tr w]

$ns trace-all $ntrace

set namfile [open ex3.nam w]

$ns namtrace-all $namfile

#Finish Procedure

proc Finish {} {

global ns ntrace namfile

#Dump all trace data and close the files

$ns flush-trace

close $ntrace

close $namfile

#Execute the nam animation file

exec nam ex3.nam &

exit 0


$ns color 1 Blue

$ns color 2 Red

#Create four nodes

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

#Create links between the nodes

$ns duplex-link $n0 $n2 2Mb 10ms DropTail

$ns duplex-link $n1 $n2 2Mb 10ms DropTail

$ns simplex-link $n2 $n3 1Mb 10ms DropTail

$ns simplex-link $n3 $n2 1Mb 10ms DropTail

#Set queue size and Monitor the queue

$ns queue-limit $n0 $n2 10

$ns simplex-link-op $n0 $n2 queuePos 0.5

#Set TCP Connection between n0 and n3

set tcp0 [new Agent/TCP]

$ns attach-agent $n0 $tcp0

set sink0 [new Agent/TCPSink]

$ns attach-agent $n3 $sink0

$ns connect $tcp0 $sink0

$tcp0 set fid_ 1

#Attach FTP Application over TCP

set ftp0 [new Application/FTP]

$ftp0 attach-agent $tcp0

$ftp0 set type_ FTP

#Set TCP Connection between n1 and n3

set tcp1 [new Agent/TCP]

$ns attach-agent $n1 $tcp1

set sink1 [new Agent/TCPSink]

$ns attach-agent $n3 $sink1

$ns connect $tcp1 $sink1

$tcp1 set fid_ 2

#Attach Telnet Application over UDP

set telnet [new Application/Telnet]

$telnet attach-agent $tcp1

$telnet set type_ Telnet

#Schedule Events

$ns at 0.5 “$telnet start”

$ns at 0.5 “$ftp0 start”

$ns at 24.5 “$telnet stop”

$ns at 24.5 “$ftp0 stop”

$ns at 25.0 “Finish”

$ns run

Figure 4.1: Network Simulator output

AWK Script

An awk-script given below is used to calculate the amount of throughput of FTP and Telnet.











pkttype= $5;




if(event == “r” &&pkttype == “tcp” &&fromnode == “0.0” &&tonode == “3.0”)



tcpSize1 = pktsize;


            if(event == “r” &&pkttype == “tcp” &&fromnode == “1.0” &&tonode == “3.1”)



tcpSize2 = pktsize;






throughputtcp1= totaltcp1/24; # because simulation time is 24.5  0.5 = 24

throughputtcp2= totaltcp2/24; # because simulation time is 24.5 0.5 = 24

printf(“\n\nThe Throughput of FTP application is %d \n”, throughputtcp1);

printf(“\n\nThe Throughput of TELNET application is %d \n\n”, throughputtcp2);


Figure 4.2: AWK output

VIVA Questions:-

(i) What are the four files on the NS2 simulator?
The four files include the .tcl file, the .awk file, the .tr file and the nam file.
(ii) What is the use of a tr file?
The tr file is mainly used to analyse our data.
(iii) What does $1,$2,….. indicate in the awk file?
The $1, $2,…. indicate the columns that represent different events in the ex3.tr file.
(iv) How do we increase the throughput?
The throughput is increased by decreasing the bandwidth.

Updated: April 6, 2020 — 5:32 am

Leave a Reply

Your email address will not be published. Required fields are marked *

care4you © 2020 Connect On Facebook DMCA.com Protection Status