0% found this document useful (0 votes)
59 views9 pages

Registration ID SP18-BCS-064 Name: Talha Shakil

The document describes a network simulation setup that creates 11 nodes connected in a topology and simulates FTP and CBR traffic between nodes over various time periods. It defines routing protocols, trace files, link properties, and endpoints. The simulation fails and reestablishes links between certain nodes to test routing behavior.

Uploaded by

Ali Saleem
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)
59 views9 pages

Registration ID SP18-BCS-064 Name: Talha Shakil

The document describes a network simulation setup that creates 11 nodes connected in a topology and simulates FTP and CBR traffic between nodes over various time periods. It defines routing protocols, trace files, link properties, and endpoints. The simulation fails and reestablishes links between certain nodes to test routing behavior.

Uploaded by

Ali Saleem
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/ 9

Registration ID: SP18-BCS-064

Name: TALHA SHAKIL

Code:
#Creating new simulator

set ns [new Simulator]

#Distance Vector Routing Protocol

$ns rtproto DV

set nf [open 064.nam w]

$ns namtrace-all $nf

#Open Trace File

set tf [open tracefile.tr w]

$ns trace-all $tf

#Open new files according to endpoints

for {set a 0} {$a < 5} {incr a} {

set f$a [open out$a.tr w]

# Creating Colors

$ns color 1 Green

$ns color 2 Black

$ns color 3 Blue

$ns color 4 Brown


#Creating Nodes

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

set n$i [$ns node]

#Creating Link

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

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

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

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

$ns duplex-link $n3 $n6 2Mb 10ms DropTail

$ns duplex-link $n3 $n4 2Mb 10ms DropTail

$ns duplex-link $n4 $n5 2Mb 10ms DropTail

$ns duplex-link $n5 $n6 2Mb 10ms DropTail

$ns duplex-link $n6 $n7 2Mb 10ms DropTail

$ns duplex-link $n6 $n8 2Mb 10ms DropTail

$ns duplex-link $n7 $n8 2Mb 10ms DropTail

$ns duplex-link $n7 $n9 2Mb 10ms DropTail

$ns duplex-link $n7 $n10 2Mb 10ms DropTail

$ns duplex-link $n9 $n10 2Mb 10ms DropTail

#Set Queue size for link for nam

$ns queue-limit $n1 $n0 10

$ns queue-limit $n2 $n0 10

$ns queue-limit $n3 $n0 10

$ns queue-limit $n4 $n0 10

$ns queue-limit $n3 $n6 10

$ns queue-limit $n3 $n4 10


$ns queue-limit $n4 $n5 10

$ns queue-limit $n5 $n6 10

$ns queue-limit $n6 $n7 10

$ns queue-limit $n6 $n8 10

$ns queue-limit $n7 $n8 10

$ns queue-limit $n7 $n9 10

$ns queue-limit $n7 $n10 10

$ns queue-limit $n9 $n10 10

#Give node position for nam

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

$ns duplex-link-op $n2 $n0 orient right-up

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

$ns duplex-link-op $n4 $n0 orient right-down

$ns duplex-link-op $n3 $n6 orient right-up

$ns duplex-link-op $n3 $n4 orient right

$ns duplex-link-op $n4 $n5 orient right-down

$ns duplex-link-op $n5 $n6 orient right-down

$ns duplex-link-op $n6 $n7 orient right-up

$ns duplex-link-op $n6 $n8 orient right

$ns duplex-link-op $n7 $n8 orient right

$ns duplex-link-op $n7 $n9 orient right-down

$ns duplex-link-op $n7 $n10 orient right-up

$ns duplex-link-op $n9 $n10 orient right-up

#Monitor the queue for links for nam

$ns duplex-link-op $n1 $n0 queuePos 0.5

$ns duplex-link-op $n2 $n0 queuePos 0.5

$ns duplex-link-op $n3 $n0 queuePos 0.5


$ns duplex-link-op $n4 $n0 queuePos 0.5

$ns duplex-link-op $n3 $n6 queuePos 0.5

$ns duplex-link-op $n3 $n4 queuePos 0.5

$ns duplex-link-op $n4 $n5 queuePos 0.5

$ns duplex-link-op $n5 $n6 queuePos 0.5

$ns duplex-link-op $n6 $n7 queuePos 0.5

$ns duplex-link-op $n6 $n8 queuePos 0.5

$ns duplex-link-op $n7 $n8 queuePos 0.5

$ns duplex-link-op $n7 $n9 queuePos 0.5

$ns duplex-link-op $n7 $n10 queuePos 0.5

$ns duplex-link-op $n9 $n10 queuePos 0.5

#Creation of Protocols

set tcp [new Agent/TCP]

$ns attach-agent $n1 $tcp

set tcp1 [new Agent/TCP]

$ns attach-agent $n2 $tcp1

set udp [new Agent/UDP]

$ns attach-agent $n7 $udp

set udp1 [new Agent/UDP]

$ns attach-agent $n8 $udp1

#Creation of traffic
set ftp [new Application/FTP]

$ftp attach-agent $tcp

$ftp set type_ FTP

set ftp1 [new Application/FTP]

$ftp1 attach-agent $tcp1

$ftp1 set type_ FTP

set cbr [new Application/Traffic/CBR]

$cbr attach-agent $udp

$cbr set packet_size_ 1000

set cbr1 [new Application/Traffic/CBR]

$cbr1 attach-agent $udp1

$cbr1 set packet_size_ 1000

#Procedure for xgraph

proc traffic {} {

global sink sink1 null null1 f0 f1 f2 f3

set ns [Simulator instance]

set time 0.5

set now [$ns now]

set bw0 [$sink set bytes_]

set bw1 [$sink1 set bytes_]

set bw2 [$null set bytes_]

set bw3 [$null1 set bytes_]


puts $f0 "$now [expr $bw0/$time*8/1000000]"

puts $f1 "$now [expr $bw1/$time*8/1000000]"

puts $f2 "$now [expr $bw2/$time*8/1000000]"

puts $f3 "$now [expr $bw3/$time*8/1000000]"

$sink set bytes_ 0

$sink1 set bytes_ 0

$null set bytes_ 0

$null1 set bytes_ 0

$ns at [expr $now+$time] "traffic"

#Creating Colors:

$tcp set fid_ 1

$tcp1 set fid_ 2

$udp set fid_ 3

$udp1 set fid_ 4

#Setting endpoint

set sink [new Agent/TCPSink]

$ns attach-agent $n8 $sink

set sink1 [new Agent/TCPSink]

$ns attach-agent $n9 $sink1

set null [new Agent/LossMonitor]

$ns attach-agent $n0 $null

set null1 [new Agent/LossMonitor]

$ns attach-agent $n4 $null1


$ns connect $tcp $sink

$ns connect $tcp1 $sink1

$ns connect $udp $null

$ns connect $udp1 $null1

#Finish Procedure

proc finish {} {

global ns nf tf

$ns flush-trace

close $nf

close $tf

exec nam 064.nam &

exit 0

#Modifying Nodes

$ns at 0.0 "$n0 color blue"

$ns at 0.0 "$n1 color brown"

$ns at 0.0 "$n2 color red"

$ns at 0.0 "$n3 color darkblue"

$ns at 0.0 "$n4 color brown"

$ns at 0.0 "$n5 color green"

$ns at 0.0 "$n6 color darkblue"

$ns at 0.0 "$n7 color red"

$ns at 0.0 "$n8 color brown"

$ns at 0.0 "$n9 color green"


$ns at 0.0 "traffic"

$ns at 0.5 "$ftp start"

$ns at 8.5 "$ftp stop"

$ns at 1.0 "$ftp1 start"

$ns at 8.5 "$ftp1 stop"

$ns at 1.5 "$cbr start"

$ns at 8.5 "$cbr stop"

$ns at 2.0 "$cbr1 start"

$ns at 8.5 "$cbr1 stop"

#Failing link b/w node4 & node5 and node7 & node8

$ns rtmodel-at 4.5 down $n4 $n5

$ns rtmodel-at 5.5 down $n7 $n8

#Establishing link b/w node4 & node5 and node7 & node8

$ns rtmodel-at 5.5 up $n4 $n5

$ns rtmodel-at 6.5 up $n7 $n8

$ns at 9.0 "finish"

# Run Simulation

$ns run
Image:

Xgraph:

You might also like