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/ 7
CN LAB:05
Name:Satya sundar Mishra
Roll:121cs0187
Q1. #Create a simulator object
set ns [new Simulator]
#Define different colors for data flows (for NAM) $ns color 1 Blue $ns color 2 Red $ns color 3 Green #Open the NAM trace file set nf [open out5.nam w] $ns namtrace-all $nf #Define a 'finish' procedure proc finish {} { global ns nf $ns flush-trace #Close the NAM trace file close $nf #Execute NAM on the trace file exec nam out5.nam & exit 0 } #Create five nodes set n1 [$ns node] set n2 [$ns node] set n3 [$ns node] set n4 [$ns node] set n5 [$ns node] #Create links between the nodes $ns duplex-link $n1 $n2 1Mb 10ms DropTail $ns duplex-link $n5 $n2 1Mb 10ms DropTail $ns duplex-link $n3 $n2 1Mb 10ms DropTail $ns duplex-link $n4 $n2 1Mb 10ms DropTail #Set Queue Size of link (n2-n4) to 10 $ns queue-limit $n2 $n4 10 #Give node position (for NAM) $ns duplex-link-op $n1 $n2 orient right-down $ns duplex-link-op $n5 $n2 orient right $ns duplex-link-op $n3 $n2 orient right-up $ns duplex-link-op $n2 $n4 orient right #Monitor the queue for the link between node 2 and node 4 $ns duplex-link-op $n2 $n4 queuePos 0.5 #Create a UDP agent and attach it to node n5 set udp5 [new Agent/UDP] $udp5 set class_ 1 $ns attach-agent $n5 $udp5 # Create a CBR traffic source and attach it to udp5 set cbr5 [new Application/Traffic/CBR] $cbr5 set packetSize_ 500 $cbr5 set interval_ 0.005 $cbr5 attach-agent $udp5 #Setup a TCP connection at node 1 set tcp1 [new Agent/TCP] $tcp1 set class_ 2 $ns attach-agent $n1 $tcp1 set sink [new Agent/TCPSink] $ns attach-agent $n4 $sink $ns connect $tcp1 $sink $tcp1 set fid_ 2 #Setup a FTP over TCP connection at node 1 set ftp1 [new Application/FTP] $ftp1 attach-agent $tcp1 $ftp1 set type_ FTP #Setup a TCP connection at node 3 set tcp3 [new Agent/TCP] $tcp3 set class_ 3 $ns attach-agent $n3 $tcp3 set sink [new Agent/TCPSink] $ns attach-agent $n4 $sink $ns connect $tcp3 $sink $tcp3 set fid_ 3 #Setup a FTP over TCP connection at node 3 set ftp3 [new Application/FTP] $ftp3 attach-agent $tcp3 $ftp3 set type_ FTP #Create a Null agent (a traffic sink) and attach it to node n4 set null0 [new Agent/Null] $ns attach-agent $n4 $null0 #Connect the traffic sources with the traffic sink $ns connect $udp5 $null0 #Schedule events for the CBR agents and FTP agents $ns at 0.1 "$cbr5 start" $ns at 1.0 "$ftp1 start" $ns at 1.5 "$ftp3 start" $ns at 3.0 "$ftp3 stop" $ns at 4.0 "$ftp1 stop" $ns at 5.0 "$cbr5 stop" #Call the finish procedure after 5 seconds of simulation time $ns at 5.0 "finish" #Run the simulation $ns run OUTPUT: Q2. #Create a simulator object set ns [new Simulator] #Define different colors for data flows (for NAM) $ns color 1 Blue #Open the NAM trace file set nf [open out6.nam w] $ns namtrace-all $nf #Define a 'finish' procedure proc finish {} { global ns nf $ns flush-trace #Close the NAM trace file close $nf #Execute NAM on the trace file exec nam out6.nam & exit 0 } #Create five nodes set n1 [$ns node] set n2 [$ns node] set n3 [$ns node] set n4 [$ns node] set n5 [$ns node] set n6 [$ns node] set n7 [$ns node] #Create links between the nodes $ns duplex-link $n1 $n2 1Mb 10ms DropTail $ns duplex-link $n2 $n3 1Mb 10ms DropTail $ns duplex-link $n3 $n4 1Mb 10ms DropTail $ns duplex-link $n1 $n7 1Mb 10ms DropTail $ns duplex-link $n7 $n6 1Mb 10ms DropTail $ns duplex-link $n6 $n5 1Mb 10ms DropTail $ns duplex-link $n5 $n4 1Mb 10ms DropTail #Set Queue Size of link (n2-n4) to 10 $ns queue-limit $n1 $n2 10 $ns queue-limit $n2 $n3 10 $ns queue-limit $n3 $n4 10 $ns queue-limit $n1 $n7 10 $ns queue-limit $n7 $n6 10 $ns queue-limit $n6 $n5 10 $ns queue-limit $n5 $n4 10 #Give node position (for NAM) $ns duplex-link-op $n1 $n2 orient right-down $ns duplex-link-op $n2 $n3 orient down $ns duplex-link-op $n3 $n4 orient down $ns duplex-link-op $n1 $n7 orient left-down $ns duplex-link-op $n7 $n6 orient down $ns duplex-link-op $n6 $n5 orient down $ns duplex-link-op $n5 $n4 orient right #Monitor the queue for the link between node 2 and node 4 $ns duplex-link-op $n3 $n4 queuePos 0.5 #Create a UDP agent and attach it to node n5 set udp1 [new Agent/UDP] $udp1 set class_ 1 $ns attach-agent $n1 $udp1 # Create a CBR traffic source and attach it to udp5 set cbr1 [new Application/Traffic/CBR] $cbr1 set packetSize_ 500 $cbr1 set interval_ 0.005 $cbr1 attach-agent $udp1 #Create a Null agent (a traffic sink) and attach it to node n4 set null0 [new Agent/Null] $ns attach-agent $n4 $null0 #Connect the traffic sources with the traffic sink $ns connect $udp1 $null0 #Schedule events for the CBR agents and FTP agents $ns at 0.1 "$cbr1 start" $ns at 1.0 "$cbr1 start" $ns at 1.5 "$cbr1 start" $ns at 3.0 "$cbr1 stop" $ns at 4.0 "$cbr1 stop" $ns at 5.0 "$cbr1 stop" #Call the finish procedure after 5 seconds of simulation time $ns at 5.0 "finish" #Run the simulation $ns run