Professional Documents
Culture Documents
LAB4
LAB4
NETWORKS LAB 4
Q1. Simulate any 3 topologies (of which one must be hybrid topology) with N
nodes for 100secs. The nodes are numbered sequentially starting from 1. In all the
topologies, the odd numbered stations are sources and even numbered nodes are
destinations. Assume that all source nodes transmit the fixed size data packets from
the start of the simulation till the end of the simulation.
a) Ring Topology
# Create a new NS2 simulation instance
set ns [new Simulator]
# Set simulation time to 100 seconds
$ns at 100.0 "finish"
# Create a ring topology with N nodes
set N 10 ;
for {set i 1} {$i <= $N} {incr i} {
set node($i) [$ns node]
}
# Define link properties
set bw 1Mbps ;# Bandwidth
set delay 10ms ;# Propagation delay
# Create links to form a ring
for {set i 1} {$i <= $N} {incr i} {
$ns duplex-link $node($i) $node([expr ($i % $N) + 1]) $bw $delay
DropTail
}
# Generate traffic from odd-numbered nodes to even-numbered
nodes
Vivek Kumar 106121146
b) Mesh Topology
set ns [new Simulator]
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
}
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
$ns duplex-link $n1 $n2 1Mb 10ms DropTail
$ns duplex-link $n2 $n3 1Mb 10ms DropTail
$ns duplex-link $n3 $n0 1Mb 10ms DropTail
$ns duplex-link $n0 $n4 1Mb 10ms DropTail
$ns duplex-link $n1 $n4 1Mb 10ms DropTail
$ns duplex-link $n2 $n4 1Mb 10ms DropTail
$ns duplex-link $n3 $n4 1Mb 10ms DropTail
Vivek Kumar 106121146
c) Star Topology
set ns [new Simulator]
$ns color 1 blue
$ns color 2 red
set lim 9
set nf [open star.nam w]
$ns namtrace-all $nf
set f [open star.tr w]
$ns trace-all $f
proc finish {} {
global ns nf f
$ns flush-trace
close $nf
close $f
exec nam star.nam &
exit 0
}
for {set i 0} {$i<$lim} {incr i} {
set n($i) [$ns node]
}
for {set i 1} {$i<$lim} {incr i} {
$ns duplex-link $n(0) $n($i) 4Mb 10ms SFQ
}
106121094
Vivek Kumar 106121146