0% found this document useful (0 votes)
2 views10 pages

Lab 4

The document outlines a lab exercise for creating and simulating three different network topologies (Hybrid, Line, and Star) using Ns2 for 100 seconds. It includes code snippets for each topology that set up nodes, duplex links, TCP agents, and FTP applications, while measuring throughput and packet loss. The simulation results are intended to be plotted in graphs for analysis.

Uploaded by

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

Lab 4

The document outlines a lab exercise for creating and simulating three different network topologies (Hybrid, Line, and Star) using Ns2 for 100 seconds. It includes code snippets for each topology that set up nodes, duplex links, TCP agents, and FTP applications, while measuring throughput and packet loss. The simulation results are intended to be plotted in graphs for analysis.

Uploaded by

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

106121018

NETWORKS LAB-EXERCISE 4

Creating and simulating three different network topologies in Ns2 for 100 seconds,
measuring throughput and packet loss and plotting the result in graph.

1) Hybrid

Code:
set noOfNodes 10
set noOfNodes2 20

set ns [new Simulator]

set tr [open hybrid20.tr w ]


$ns trace-all $tr

set ftr [open out.nam w ]


$ns namtrace-all $ftr

proc finish { } {
global tr ftr ns
$ns flush-trace
close $tr
close $ftr
exec nam out.nam &
exit 0
}

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


106121018

set n($i) [ $ns node]


}

for {set i 1} {$i<$noOfNodes} {incr i} {


$ns duplex-link $n(0) $n($i) 1Mb 10ms DropTail
}

for {set i [expr $noOfNodes-1]} {$i<[expr $noOfNodes2-1]} {incr i} {


$ns duplex-link $n($i) $n([expr $i+1]) 1Mb 10ms DropTail
}

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


if { $i % 2 == 0 } {
set tcp($i) [new Agent/TCP]
$ns attach-agent $n($i) $tcp($i)
} else {
set sink($i) [new Agent/TCPSink]
$ns attach-agent $n($i) $sink($i)
}
}

for {set i 1} {$i<$noOfNodes2} {incr i} {


if { $i % 2 != 0 } {
$ns connect $sink($i) $tcp([expr $i-1])
set ftp([expr $i-1]) [new Application/FTP]
$ftp([expr $i-1]) attach-agent $tcp([expr $i-1])
$ns at 0.$i "$ftp([expr $i-1]) start"
}
106121018

$ns queue-limit $n(0) $n(1) 10


$ns queue-limit $n(0) $n(2) 10
$ns queue-limit $n(12) $n(13) 10
$ns queue-limit $n(16) $n(17) 10
# $ns queue-limit $n(22) $n(23) 10

$ns at 3.0 "finish"

$ns run

Graphs:
106121018

===========================================================================
2) Line
Code:
set noOfNodes 25

set ns [new Simulator]

set tr [open line25.tr w ]


$ns trace-all $tr

set ftr [open out.nam w ]


$ns namtrace-all $ftr

proc finish { } {
global tr ftr ns
106121018

$ns flush-trace
close $tr
close $ftr
exec nam out.nam &
exit 0
}

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


set n($i) [ $ns node ]
}

for {set i 0} {$i<[expr $noOfNodes-1]} {incr i} {


$ns duplex-link $n($i) $n([expr $i+1]) 1Mb 10ms DropTail
}

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


if { $i % 2 == 0 } {
set tcp($i) [new Agent/TCP]
$ns attach-agent $n($i) $tcp($i)
} else {
set sink($i) [new Agent/TCPSink]
$ns attach-agent $n($i) $sink($i)
}
}

for {set i 1} {$i<$noOfNodes} {incr i} {


if { $i % 2 != 0 } {
$ns connect $sink($i) $tcp([expr $i-1])
106121018

set ftp([expr $i-1]) [new Application/FTP]


$ftp([expr $i-1]) attach-agent $tcp([expr $i-1])
$ns at 0.$i "$ftp([expr $i-1]) start"
}
}

$ns queue-limit $n(2) $n(3) 10


$ns queue-limit $n(6) $n(7) 10
$ns queue-limit $n(12) $n(13) 10
$ns queue-limit $n(16) $n(17) 10
$ns queue-limit $n(22) $n(23) 10

$ns connect $sink(1) $tcp(4)

$ns at 3.0 "finish"

$ns run

Graphs:
106121018

========================================================================

3) Star
Code:

set noOfNodes 10

set ns [new Simulator]

set tr [open star10.tr w ]


$ns trace-all $tr

set ftr [open out.nam w ]


$ns namtrace-all $ftr

proc finish { } {
global tr ftr ns
106121018

$ns flush-trace
close $tr
close $ftr
exec nam out.nam &
exit 0
}

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


set n($i) [ $ns node ]
}

for {set i 1} {$i<$noOfNodes} {incr i} {


$ns duplex-link $n(0) $n($i) 1Mb 10ms DropTail
}

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


if { $i % 2 == 0 } {
set tcp($i) [new Agent/TCP]
$ns attach-agent $n($i) $tcp($i)
} else {
set sink($i) [new Agent/TCPSink]
$ns attach-agent $n($i) $sink($i)
}
}

for {set i 1} {$i<$noOfNodes} {incr i} {


if { $i % 2 != 0 } {
$ns connect $sink($i) $tcp([expr $i-1])
106121018

set ftp([expr $i-1]) [new Application/FTP]


$ftp([expr $i-1]) attach-agent $tcp([expr $i-1])
$ns at 0.$i "$ftp([expr $i-1]) start"
}
}

$ns queue-limit $n(2) $n(0) 3


$ns connect $sink(3) $tcp(2)
$ns queue-limit $n(6) $n(0) 3
$ns connect $sink(7) $tcp(6)

$ns at 3.0 "finish"

$ns run

Graphs
106121018

You might also like