You are on page 1of 4

Fr.

Conceicao Rodrigues College of Engineering


Department of Computer Engineering
Academic Term : July-Nov 2023-24

Class : T.E. (Computer B)


Subject Name: Computer network Lab
Subject Code : CSL 502
Experiment No 9

Date of performance 26 / 09 / 2023

Roll No 9539

Name of the Student Crystal Fernandes

AIM : To study about NS2 simulator and to create scenario of token ring protocols through
simulation

THEORY :
Network Simulator (Version 2), widely known as NS2, is simply an event driven simulation
tool that has proved useful in studying the dynamic nature of communication networks.
Simulation of wired as well as wireless network functions and protocols (e.g., routing
algorithms, TCP, UDP) can be done using NS2. In general, NS2 provides users with a way
of specifying such network protocols and simulating their corresponding behaviors. Due to
its flexibility and modular nature, NS2 has gained constant popularity in the networking
research community since its birth in 1989. Ever since, several revolutions and revisions
have marked the growing maturity of the tool, thanks to substantial contributions from the
players in the field. Among these are the University of California and Cornell University who
developed the REAL network simulator,1 the foundation which NS is based on. Since 1995
the Defense Advanced Research Projects Agency (DARPA) supported development of NS
through the Virtual Inter Network Testbed (VINT) project . Currently the National Science
Foundation (NSF) has joined the ride in development. Last but not the least, the group of
Researchers and developers in the community are constantly working to keep NS2 strong
and versatile.
BASIC ARCHITECTURE :
Figure shows the basic architecture of NS2. NS2 provides users with an executable
command ns which takes on input argument, the name of a Tcl simulation scripting file.
Users are feeding the name of a Tcl simulation script (which sets up a simulation) as an
input argument of an NS2 executable command ns. In most cases, a simulation trace
file is created, and is used to plot graph and/or to create animation. NS2 consists of two
key languages: C++ and Object-oriented Tool Command Language (OTcl). While the
C++ defines the internal mechanism (i.e., a backend) of the simulation objects, the OTcl
sets up simulation by assembling and configuring the objects as well as scheduling
discrete events (i.e., a frontend). The C++ and the OTcl are linked together using TclCL.
Mapped to a C++ object, variables in the OTcl domains are sometimes referred to as
handles. Conceptually, a handle (e.g., n as a Node handle) is just a string in the OTcl
domain, and does not contain any functionality. Instead, the functionality (e.g., receiving
a packet) is defined in the mapped C++ object (e.g., of class Connector). In the OTcl
domain, a handle acts as a frontend which interacts with users and other OTcl objects
What is Token Ring Protocol Token ring is a LAN protocol operating in the MAC layer.
Token ring is standardized as per IEEE 802.5. Token ring can operate at speeds of
4mbps and 16 mbps. The operation of token ring is as follows: When there is no traffic
on the network a simple 3-byte token circulates the ring. If the token is free (no reserved
by a station of higher priority as explained later) then the station may seize the token
and start sending the data frame. As the frame travels around the ring ach station
examines the destination address and is either forwarded (if the recipient is another
node) or copied. After copying4 bits of the last byte is changed. This packet then
continues around the ring till it reaches the originating station. After the frame makes a
round trip the sender receives the frame and releases a new token onto the ring.
CODE :
set ns [new Simulator]
$ns rtproto DV

set nf [open out.nam w]


$ns namtrace-all $nf
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exec nam out.nam
exit 0
}

#Creating Nodes
for {set i 0} {$i<7} {incr i} {
set n($i) [$ns node]
}

#Creating Links
for {set i 0} {$i<7} {incr i} {
$ns duplex-link $n($i) $n([expr ($i+1)%7]) 512Kb 5ms DropTail
}

$ns duplex-link-op $n(0) $n(1) queuePos 1


$ns duplex-link-op $n(0) $n(6) queuePos 1

#Creating UDP agent and attching to node 0


set udp0 [new Agent/UDP]
$ns attach-agent $n(0) $udp0

#Creating Null agent and attaching to node 3


set null0 [new Agent/Null]
$ns attach-agent $n(3) $null0

$ns connect $udp0 $null0

#Creating a CBR agent and attaching it to udp0


set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 1024
$cbr0 set interval_ 0.01
$cbr0 attach-agent $udp0
$ns rtmodel-at 0.4 down $n(2) $n(3)
$ns rtmodel-at 1.0 up $n(2) $n(3)

$ns at 0.01 "$cbr0 start"


$ns at 1.5 "$cbr0 stop"
$ns at 2.0 "finish"
$ns run

OUTPUT :

\
CONCLUSION : We implemented the star topology using NS2 network simulator and
understood its working.

You might also like