0% found this document useful (0 votes)
101 views6 pages

NS2 Network Simulator: Otcl Basics Links

This document discusses NS2, an open source network simulator written in C++ and OTcl. It can be used to simulate wired and wireless networks, implement network protocols, and model things like routing algorithms, traffic sources, and queue management. The document provides an example NS2 script that sets up a simple star topology network with 5 nodes, uses CBR traffic between two nodes, and runs the simulation for 5 seconds. Procedures in OTcl are also briefly explained.

Uploaded by

Dhruvisha Vasoya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
101 views6 pages

NS2 Network Simulator: Otcl Basics Links

This document discusses NS2, an open source network simulator written in C++ and OTcl. It can be used to simulate wired and wireless networks, implement network protocols, and model things like routing algorithms, traffic sources, and queue management. The document provides an example NS2 script that sets up a simple star topology network with 5 nodes, uses CBR traffic between two nodes, and runs the simulation for 5 seconds. Procedures in OTcl are also briefly explained.

Uploaded by

Dhruvisha Vasoya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Data Communication and networking[CE253] 18dcs133

REPORT

NS2 network simulator


DEVANG PATEL INSTITUTE OF ADVANCE RESEARCH AND TECHNOLOGY

Introduction

NS (Version 2) is an open source network simulation tool. It is an object oriented, discrete


event driven simulator written in C++ and Otcl. The primary use of NS is in network
researches to simulate various types of wired/wireless local and wide area networks; to
implement network protocols such as TCP and UDP, traffic source behavior such as FTP,
Telnet, Web, CBR and VBR, router queue management mechanism such as Drop Tail, RED
and CBQ, routing algorithms such as Dijkstra, and many more.Ns2 is written in C++ and Otcl
to separate the control and data path implementations.

Otcl basics
LINKS

Procedures
One can define new procedures with the proc command. The first argument to proc is the
name of the procedure and the second argument contains the list of the argument names to
that procedure. For instance a procedure that calculates the sum of two numbers can be
defined as follow

pg. 1
Data Communication and networking[CE253] 18dcs133

set a 5

set b 5

proc sum {a b} {
expr $a + $b
}

STARTING PROCEDURE

CODE

#Simulator is a class

set ns [new Simulator]

pg. 2
Data Communication and networking[CE253] 18dcs133

set nf [open out.nam w]

$ns namtrace-all $nf

proc finish {} {

global ns nf

$ns flush-trace

#Close the trace file

close $nf

#Executenam on the trace file

exec nam out.nam &

exit0}

#Create five nodes

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

set n4 [$ns node]

set n5 [$ns node]

#Change the shape of center node in a star topology

$n0 shape square

#Create links between the nodes

$ns duplex-link $n0 $n1 1Mb 10ms DropTail

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

$ns duplex-link $n0 $n3 1Mb 10ms DropTail

pg. 3
Data Communication and networking[CE253] 18dcs133

$ns duplex-link $n0 $n4 1Mb 10ms DropTail

$ns duplex-link $n0 $n5 1Mb 10ms DropTail

#Create a TCP agent and attach it to node n0

set tcp0 [new Agent/TCP]

$tcp0 set class_ 1

$ns attach-agent $n1 $tcp0

#Create a TCP Sink agent (a traffic sink) for TCP and attach it to node n3

set sink0 [new Agent/TCPSink]

$ns attach-agent $n3 $sink0

#Connect the traffic sources with the traffic sink

$ns connect $tcp0 $sink0

# Create a CBR traffic source and attach it to tcp0

set cbr0 [new Application/Traffic/CBR]

$cbr0 set packetSize_ 500

$cbr0 set interval_ 0.01

$cbr0 attach-agent $tcp0

#Schedule events for the CBR agents

$ns at 0.5 "$cbr0 start"

$ns at 4.5 "$cbr0 stop"

#Call the finish procedure after 5 seconds of simulation time

$ns at 5.0 "finish"

#Run the simulation

$ns run

pg. 4
Data Communication and networking[CE253] 18dcs133

Topology

Prepared by: Dhruvisha Vasoya

Submitted to: Drashti Garadharia

pg. 5
Data Communication and networking[CE253] 18dcs133

pg. 6

You might also like