0% found this document useful (0 votes)
37 views7 pages

ns2 File

The document describes three experiments involving network simulation using the ns-2 simulator: 1. The first experiment involves creating two nodes and connecting them with a duplex link. 2. The second experiment builds on this by creating a program to generate multiple nodes in a loop and connect them in a specified topology. 3. The third experiment builds a slightly more complex three node network with agents, applications and data transfer between nodes. It also defines colors, labels and orientations for the nodes and links.

Uploaded by

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

ns2 File

The document describes three experiments involving network simulation using the ns-2 simulator: 1. The first experiment involves creating two nodes and connecting them with a duplex link. 2. The second experiment builds on this by creating a program to generate multiple nodes in a loop and connect them in a specified topology. 3. The third experiment builds a slightly more complex three node network with agents, applications and data transfer between nodes. It also defines colors, labels and orientations for the nodes and links.

Uploaded by

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

Experiment : 5

Objective : Write a program for making node


set ns [new Simulator]

set nf [open example1.nam w]

$ns namtrace-all $nf

set n0 [$ns node]

set n1 [$ns node]

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

proc finish {} {

global ns nf

$ns flush-trace

close $nf

exec nam example1.nam &

exit 0

$ns at 5.0 "finish"

$ns run
Result:

Experiment : 6

Objective : Write a program for creating multiple node


set ns [new Simulator]

set nf [open example3.nam w]


$ns namtrace-all $nf

set node 6

for {set i 0} {$i < $node} {incr i} {

set n_($i) [$ns node]

$ns duplex-link $n_(0) $n_(1) 1Mb 10ms DropTail

$ns duplex-link $n_(2) $n_(1) 1Mb 10ms DropTail

$ns duplex-link $n_(3) $n_(1) 1Mb 10ms DropTail

$ns duplex-link $n_(4) $n_(1) 1Mb 10ms DropTail

$ns duplex-link $n_(5) $n_(3) 1mb 10ms DropTail

proc finish {} {

global ns nf

$ns flush-trace

close $nf

exec nam example3.nam &

exit 0

$ns at 5.0 "finish"

$ns run

Result:
set ns [new Simulator]

$ns color 1 blue

set nt [open example4.tr w]

$ns trace-all $nt

set nf [open example4.nam w]

$ns namtrace-all $nf

set n0 [$ns node]


set n1 [$ns node]

set n2 [$ns node]

$ns at 0.0 "$n0 color blue"

$ns at 0.0 "$n1 color green"

$ns at 0.0 "$n2 color brown"

$ns at 0.0 "$n0 label server"

$ns at 0.0 "$n1 label router"

$ns at 0.0 "$n2 label client"

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

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

$ns duplex-link-op $n0 $n1 orient right

$ns duplex-link-op $n1 $n2 orient right

#------------Data Transfer between Nodes----------------#

# Defining a transport agent for sending

set tcp [new Agent/TCP]

# Attaching transport agent to sender node

$ns attach-agent $n0 $tcp


# Defining a transport agent for receiving

set sink [new Agent/TCPSink]

# Attaching transport agent to receiver node

$ns attach-agent $n2 $sink

#Connecting sending and receiving transport agents

$ns connect $tcp $sink

#Defining Application instance

set ftp [new Application/FTP]

# Attaching transport agent to application agent

$ftp attach-agent $tcp

# Setting flow color

$tcp set fid_ 1

# data packet generation starting time

$ns at 0.10 "$ftp start"

# data packet generation ending time

$ns at 4.0 "$ftp stop"


proc finish {} {

global ns nf nt

$ns flush-trace

close $nf

close $nt

exec nam example4.nam &

exit 0

$ns at 5.0 "finish"

$ns run

Result:

You might also like