Vous êtes sur la page 1sur 22

Ex. No. : 1 To establish local area network and assigning IP addresses Refer record Ex. No.

: 2 Implementation of Error Detecting Codes -CompletedEx. No. : 3 Study of IP subnet Refer record Ex. No. : 4 - Ethernet LAN protocol Aim : To Simulate an Ethernet LAN using 6 nodes. Algorithm : Create a simulator object. Define different colors for data flows (for NAM) Open a nam trace file and define finish procedure then close the trace file, and execute nam on trace file. Create six nodes that forms a network numbered from 0 to 5 Create duplex links between the nodes and add Orientation to the nodes for setting a LAN topology Setup queue between n(2) and n(3) and monitor the queue Set error model on link n(2) and n(3) and insert the error model Setup TCP Connection between n(0) and n(4) Apply FTP Application over TCP Setup UDP Connection between n(1) and n(5) Apply CBR Traffic over UDP Schedule events and calculate Throughput (number of packets received/time taken for simulation)

Program : #Create Simulator set ns [new Simulator] #Use colors to differentiate the traffic $ns color 1 Blue $ns color 2 Red #Open trace and NAM trace file set ntrace [open prog5.tr w] $ns trace-all $ntrace set namfile [open prog5.nam w] $ns namtrace-all $namfile #Finish Procedure proc Finish {} { global ns ntrace namfile #Dump all trace data and close the files $ns flush-trace close $ntrace close $namfile #Execute the nam animation file exec nam prog5.nam &

#Calculate the throughput = (number of packets received/time taken for simulation) set TcpSize [exec grep "^r" prog5.tr | grep "tcp" | tail -n 1 | cut -d " " -f 6] set numTcp [exec grep "^r" prog5.tr | grep -c "tcp"] set tcpTime 123.0 set UdpSize [exec grep "^r" prog5.tr | grep "cbr" | tail -n 1 | cut -d " " -f 6] set numUdp [exec grep "^r" prog5.tr | grep -c "cbr"] set udpTime 124.4 puts "The throughput of FTP is" puts "[expr ($numTcp*$TcpSize)/$tcpTime] bytes per second" puts "The throughput of CBR is" puts "[expr ($numUdp*$UdpSize)/$udpTime] bytes per second" exit 0 } #Create 6 nodes for {set i 0} {$i < 6} {incr i} { set n($i) [$ns node] } #Create duplex links between the nodes $ns duplex-link $n(0) $n(2) 2Mb 10ms DropTail $ns duplex-link $n(1) $n(2) 2Mb 10ms DropTail $ns simplex-link $n(2) $n(3) 0.3Mb 100ms DropTail $ns simplex-link $n(3) $n(2) 0.3Mb 100ms DropTail #Node n(3), n(4) and n(5) are considered in a LAN set lan [$ns newLan "$n(3) $n(4) $n(5)" 0.5Mb 40ms LL Queue/DropTail MAC/802_3 Channel] #Orientation to the nodes $ns duplex-link-op $n(0) $n(2) orient right-down $ns duplex-link-op $n(1) $n(2) orient right-up $ns simplex-link-op $n(2) $n(3) orient right #Setup queue between n(2) and n(3) and monitor the queue $ns queue-limit $n(2) $n(3) 20 $ns simplex-link-op $n(2) $n(3) queuePos 0.5 #Set error model on link n(2) and n(3) and insert the error model set loss_module [new ErrorModel] $loss_module ranvar [new RandomVariable/Uniform] $loss_module drop-target [new Agent/Null] $ns lossmodel $loss_module $n(2) $n(3) #Setup TCP Connection between n(0) and n(4) set tcp0 [new Agent/TCP/Newreno] $tcp0 set fid_ 1 $tcp0 set window_ 8000 $tcp0 set packetSize_ 552 $ns attach-agent $n(0) $tcp0 set sink0 [new Agent/TCPSink/DelAck] $ns attach-agent $n(4) $sink0 $ns connect $tcp0 $sink0 #Apply FTP Application over TCP set ftp0 [new Application/FTP] $ftp0 set type_ FTP $ftp0 attach-agent $tcp0

#Setup UDP Connection between n(1) and n(5) set udp0 [new Agent/UDP] $udp0 set fid_ 2 $ns attach-agent $n(1) $udp0 set null0 [new Agent/Null] $ns attach-agent $n(5) $null0 $ns connect $udp0 $null0 #Apply CBR Traffic over UDP set cbr0 [new Application/Traffic/CBR] $cbr0 set type_ CBR $cbr0 set packetSize_ 1000 $cbr0 set rate_ 0.1Mb $cbr0 set random_ false $cbr0 attach-agent $udp0 #Schedule events $ns at 0.1 "$cbr0 start" $ns at 1.0 "$ftp0 start" $ns at 124.0 "$ftp0 stop" $ns at 124.5 "$cbr0 stop" $ns at 125.0 "Finish" #Run Simulation $ns run Output: #ns prog5.tcl The throughput of FTP is 72556.097560975613 bytes per second The throughput of CBR is 37363.34405144694 bytes per second Ex. No. : 5 - To create scenario and study the performance of CSMA/CD protocol simulation Aim: To study and simulate the CSMA/CD protocol. Algorithm : Create a simulator object. Define different colors for data flows (for NAM) and nodes Label the nodes Open a nam trace file and define finish procedure then close the trace file, and execute nam on trace file. Create six nodes that forms a network numbered from 0 to 5 Create duplex links between the nodes and add Orientation to the nodes for setting a LAN topology Setup TCP Connection between n(0) and n(2) , n(1) and n(2) , n(1) and n(0) , n(0) and n(1) and apply FTP Application over TCP Schedule events to achieve CSMA/CD scenario

Program: #send packets one by one

set ns [new Simulator] $ns color 1 Green foreach i " 0 1 2 3 4 5 " { set n$i [$ns node] } $n0 color "purple" $n1 color "purple" $n2 color "violet" $n3 color "violet" $n4 color "chocolate" $n5 color "chocolate" $n0 shape box ; $n1 shape box ; $n2 shape box ; $n3 shape box ; $n4 shape box ; $n5 shape box ; $ns at 0.0 "$n0 label SYS1" $ns at 0.0 "$n1 label SYS2" $ns at 0.0 "$n2 label SYS3" $ns at 0.0 "$n3 label SYS4" $ns at 0.0 "$n4 label SYS5" $ns at 0.0 "$n5 label SYS6" set nf [open csma.nam w] $ns namtrace-all $nf set f [open csma.tr w] $ns trace-all $f $ns duplex-link $n0 $n2 0.1Mb 20ms DropTail $ns duplex-link-op $n0 $n2 orient right-down $ns queue-limit $n0 $n2 5 $ns duplex-link $n1 $n2 0.1Mb 20ms DropTail $ns duplex-link-op $n1 $n2 orient right-up $ns duplex-link $n2 $n3 0.1Mb 20ms DropTail $ns duplex-link-op $n2 $n3 orient right $ns duplex-link $n3 $n4 0.1Mb 20ms DropTail $ns duplex-link-op $n3 $n4 orient right-up $ns duplex-link $n3 $n5 0.1Mb 20ms DropTail $ns duplex-link-op $n3 $n5 orient right-down Agent/TCP set nam_tracevar_ true set tcp [new Agent/TCP] $tcp set window_ 1 $tcp set maxcwnd_ 1 $tcp set fid_ 1 $ns attach-agent $n0 $tcp set sink [new Agent/TCPSink] $ns attach-agent $n2 $sink $ns connect $tcp $sink set ftp [new Application/FTP] $ftp attach-agent $tcp set tcp1 [new Agent/TCP] $tcp1 set window_ 1 $tcp1 set maxcwnd_ 1 $tcp1 set fid_ 1 $ns attach-agent $n1 $tcp1

set sink1 [new Agent/TCPSink] $ns attach-agent $n2 $sink1 $ns connect $tcp1 $sink1 set ftp1 [new Application/FTP] $ftp1 attach-agent $tcp1 set tcp2 [new Agent/TCP] $tcp2 set window_ 1 $tcp2 set maxcwnd_ 1 $tcp2 set fid_ 1 $ns attach-agent $n1 $tcp2 set sink2 [new Agent/TCPSink] $ns attach-agent $n0 $sink2 $ns connect $tcp2 $sink2 set ftp2 [new Application/FTP] $ftp2 attach-agent $tcp2 set tcp3 [new Agent/TCP] $tcp3 set window_ 1 $tcp3 set maxcwnd_ 1 $tcp3 set fid_ 1 $ns attach-agent $n0 $tcp3 set sink3 [new Agent/TCPSink] $ns attach-agent $n1 $sink3 $ns connect $tcp3 $sink3 set ftp3 [new Application/FTP] $ftp3 attach-agent $tcp3 $ns at 0.05 "$ftp start" $ns at 0.071 "$ns queue-limit $n2 $n0 0" $ns at 0.10 "$ns queue-limit $n2 $n0 5" $ns at 0.09 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n2 $sink" $ns at 0.25 "finish" $ns at 0.05 "$ftp1 start" $ns at 0.072 "$ns queue-limit $n2 $n1 0" $ns at 0.10 "$ns queue-limit $n2 $n1 5" $ns at 0.09 "$ns detach-agent $n1 $tcp1 ; $ns detach-agent $n2 $sink1" $ns at 0.25 "finish" $ns at 0.10 "$ftp2 start" $ns at 0.13 "$ns detach-agent $n0 $tcp2 ; $ns detach-agent $n1 $sink2" $ns at 0.25 "finish" $ns at 0.12 "$ftp3 start" $ns at 0.14 "$ns detach-agent $n1 $tcp1 ; $ns detach-agent $n0 $sink3" $ns at 0.25 "finish" $ns at 0.0 "$ns trace-annotate \"CSMA/CA\"" $ns at 0.05 "$ns trace-annotate \"FTP starts at 0.01\"" $ns at 0.05 "$ns trace-annotate \"Send Packet_1 from SYS1 to SYS0 and Packet_2 from SYS0 to SYS1 \"" $ns at 0.073 "$ns trace-annotate \"Collision Occurs so 2 Packets are lossed\"" $ns at 0.10 "$ns trace-annotate \"Retransmit Packet_1 from SYS1 to SYS0 \"" $ns at 0.12 "$ns trace-annotate \"Retransmit Packet_2 from SYS0 to SYS1 \"" $ns at 0.20 "$ns trace-annotate \"FTP stops\"" proc finish {} { global ns nf $ns flush-trace close $nf puts "filtering..."

#exec tclsh ../bin/namfilter.tcl csma.nam #puts "running nam..." exec nam csma.nam & exit 0 } $ns run

Ex. No. : 6A - Token bus protocol: To create scenario and study the performance of token bus through simulation Aim : To Study The Performance Of Token Bus Using Ns2 Simulation Algorithm : Create a simulator object , set Bandwidth 0.5 MB and packet size 700 Define different colors for data flows (for NAM) Create seven nodes that forms a network numbered from 0 to 6 and label the nodes for identifying sender and receiver Open a nam trace file and define finish procedure then close the trace file, and execute nam on trace file. Create duplex links between the nodes and add Orientation to the nodes for setting a LAN topology Setup TCP Connection between some nodes and apply FTP Application over TCP Setup UDP Connection between some other nodes and apply CBR Application over UDP Schedule events to achieve Token bus scenario and view graph for the throughput calculated

Program: set ns [new Simulator] set Bandwidth "0.5Mb" set packetsize 700 set intval 0.004 $ns color 1 magenta $ns color 2 seagreen $ns color 3 deepskyblue $ns color 4 brown $ns color 5 salmon foreach i "0 1 2 3 4 5 6" { set n$i [$ns node] } $n0 color "navy" $n1 color "salmon" $n2 color "seagreen" $n3 color "deepskyblue" $n4 color "steel blue" $n5 color "steel blue"

$n6 color "steel blue" $ns at 0.0 "$n0 label Sender" $ns at 0.0 "$n1 label Receiver1" $ns at 0.0 "$n2 label Receiver2" $ns at 0.0 "$n3 label Receiver3" set nf [open tokenbus.nam w] $ns namtrace-all $nf set f [open tokenbus.tr w] $ns trace-all $f $ns duplex-link $n0 $n5 $Bandwidth 30ms DropTail $ns duplex-link $n5 $n2 $Bandwidth 30ms DropTail $ns duplex-link $n4 $n1 $Bandwidth 30ms DropTail $ns duplex-link $n4 $n5 $Bandwidth 30ms DropTail $ns duplex-link $n5 $n6 $Bandwidth 30ms DropTail $ns duplex-link $n6 $n3 $Bandwidth 30ms DropTail $ns duplex-link-op $n0 $n5 orient down $ns duplex-link-op $n5 $n2 orient down $ns duplex-link-op $n4 $n1 orient down $ns duplex-link-op $n4 $n5 orient right $ns duplex-link-op $n5 $n6 orient right $ns duplex-link-op $n6 $n3 orient down $ns queue-limit $n4 $n5 10 set tcp1 [new Agent/TCP] $ns attach-agent $n0 $tcp1 $tcp1 set fid_ 1 ; set tcp2 [new Agent/TCP] $ns attach-agent $n1 $tcp2 $tcp2 set fid_ 1 ; set tcp3 [new Agent/TCP] $ns attach-agent $n2 $tcp3 $tcp3 set fid_ 1 ; set tcp4 [new Agent/TCP] $ns attach-agent $n3 $tcp4 $tcp4 set fid_ 1 ; set tcp5 [new Agent/TCP] $ns attach-agent $n0 $tcp5 $tcp5 set fid_ 1 ; set tcp6 [new Agent/TCP] $ns attach-agent $n1 $tcp6 $tcp6 set fid_ 1 ; set tcp7 [new Agent/TCP] $ns attach-agent $n2 $tcp7 $tcp7 set fid_ 1 ; set tcp8 [new Agent/TCP] $ns attach-agent $n3 $tcp8 $tcp8 set fid_ 1 ; set tcp9 [new Agent/TCP] $ns attach-agent $n0 $tcp9 $tcp9 set fid_ 1 ; set tcp10 [new Agent/TCP] $ns attach-agent $n1 $tcp10 $tcp10 set fid_ 1 ; set tcp11 [new Agent/TCP] $ns attach-agent $n2 $tcp11

$tcp11 set fid_ 1 ; set tcp12 [new Agent/TCP] $ns attach-agent $n3 $tcp12 $tcp12 set fid_ 1 ; set sink1 [new Agent/TCPSink] $ns attach-agent $n1 $sink1 set sink2 [new Agent/TCPSink] $ns attach-agent $n2 $sink2 set sink3 [new Agent/TCPSink] $ns attach-agent $n3 $sink3 set sink4 [new Agent/TCPSink] $ns attach-agent $n0 $sink4 set sink5 [new Agent/TCPSink] $ns attach-agent $n1 $sink5 set sink6 [new Agent/TCPSink] $ns attach-agent $n2 $sink6 set sink7 [new Agent/TCPSink] $ns attach-agent $n3 $sink7 set sink8 [new Agent/TCPSink] $ns attach-agent $n0 $sink8 set sink9 [new Agent/TCPSink] $ns attach-agent $n1 $sink9 set sink10 [new Agent/TCPSink] $ns attach-agent $n2 $sink10 set sink11 [new Agent/TCPSink] $ns attach-agent $n3 $sink11 set sink12 [new Agent/TCPSink] $ns attach-agent $n0 $sink12 $ns connect $tcp1 $sink1 $ns connect $tcp2 $sink2 $ns connect $tcp3 $sink3 $ns connect $tcp4 $sink4 $ns connect $tcp5 $sink5 $ns connect $tcp6 $sink6 $ns connect $tcp7 $sink7 $ns connect $tcp8 $sink8 $ns connect $tcp9 $sink9 $ns connect $tcp10 $sink10 $ns connect $tcp11 $sink11 $ns connect $tcp12 $sink12 set ftp1 [new Application/FTP] $ftp1 attach-agent $tcp1 set ftp2 [new Application/FTP] $ftp2 attach-agent $tcp2 set ftp3 [new Application/FTP] $ftp3 attach-agent $tcp3 set ftp4 [new Application/FTP] $ftp4 attach-agent $tcp4 set ftp5 [new Application/FTP] $ftp5 attach-agent $tcp5 set ftp6 [new Application/FTP] $ftp6 attach-agent $tcp6 set ftp7 [new Application/FTP] $ftp7 attach-agent $tcp7 set ftp8 [new Application/FTP] $ftp8 attach-agent $tcp8 set ftp9 [new Application/FTP] $ftp9 attach-agent $tcp9 set ftp10 [new Application/FTP] $ftp10 attach-agent $tcp10 set ftp11 [new Application/FTP] $ftp11 attach-agent $tcp11

set ftp12 [new Application/FTP] $ftp12 attach-agent $tcp12 set udp0 [new Agent/UDP] $ns attach-agent $n1 $udp0 $udp0 set fid_ 2 ; $tcp7 set fid_ 4 ; set cbr0 [new Application/Traffic/CBR] $cbr0 attach-agent $udp0 set null0 [new Agent/Null] $ns attach-agent $n3 $null0 $ns connect $udp0 $null0 $cbr0 set packetSize_ $packetsize $cbr0 set interval_ $intval set udp1 [new Agent/UDP] $ns attach-agent $n3 $udp1 $udp1 set fid_ 2 ; $tcp8 set fid_ 4 ; set cbr1 [new Application/Traffic/CBR] $cbr1 attach-agent $udp1 set null1 [new Agent/Null] $ns attach-agent $n0 $null1 $ns connect $udp1 $null1 $cbr1 set packetSize_ $packetsize $cbr1 set interval_ $intval set udp2 [new Agent/UDP] $ns attach-agent $n3 $udp2 $udp2 set fid_ 3 ; $tcp12 set fid_ 4; set cbr2 [new Application/Traffic/CBR] $cbr2 attach-agent $udp2 set null2 [new Agent/Null] $ns attach-agent $n0 $null2 $ns connect $udp2 $null2 $cbr2 set packetSize_ $packetsize $cbr2 set interval_ $intval $ns at 0.05 "$ftp1 start" $ns at 0.13 "$ns detach-agent $n0 $tcp1;$ns detach-agent $n1 $sink1" $ns at 3.0 "finish" $ns at 0.14 "$ftp2 start" $ns at 0.20 "$ns detach-agent $n1 $tcp2;$ns detach-agent $n2 $sink2" $ns at 3.0 "finish" $ns at 0.23 "$ftp3 start" $ns at 0.30 "$ns detach-agent $n2 $tcp3;$ns detach-agent $n3 $sink3" $ns at 3.0 "finish" $ns at 0.33 "$ftp4 start" $ns at 0.40 "$ns detach-agent $n3 $tcp4;$ns detach-agent $n0 $sink4" $ns at 3.0 "finish" $ns at 0.42 "$ftp5 start" $ns at 0.50 "$ns detach-agent $n0 $tcp5;$ns detach-agent $n1 $sink5" $ns at 3.0 "finish" $ns at 0.51 "$ftp6 start" $ns at 0.60 "$ns detach-agent $n1 $tcp6;$ns detach-agent $n2 $sink6" $ns at 3.0 "finish" $ns at 0.62 "$ftp7 start"

$ns at 0.69 "$ns detach-agent $n2 $tcp7;$ns detach-agent $n3 $sink7" $ns at 3.0 "finish" $ns at 0.725 "$ftp8 start" $ns at 0.78 "$ns detach-agent $n3 $tcp8;$ns detach-agent $n0 $sink8" $ns at 3.0 "finish" $ns at 0.83 "$ftp9 start" $ns at 0.90 "$ns detach-agent $n0 $tcp9;$ns detach-agent $n1 $sink9" $ns at 3.0 "finish" $ns at 0.93 "$ftp10 start" $ns at 1.0 "$ns detach-agent $n1 $tcp10;$ns detach-agent $n2 $sink10" $ns at 3.0 "finish" $ns at 1.03 "$ftp11 start" $ns at 1.1 "$ns detach-agent $n2 $tcp11;$ns detach-agent $n3 $sink11" $ns at 3.0 "finish" $ns at 1.13 "$ftp12 start" $ns at 1.2 "$ns detach-agent $n3 $tcp12;$ns detach-agent $n0 $sink12" $ns at 3.0 "finish" $ns at 0.621 "$cbr0 start" $ns at 0.69 "$cbr0 stop" $ns at 0.726 "$cbr1 start" $ns at 0.78 "$cbr1 stop" $ns at 1.131 "$cbr2 start" $ns at 1.2 "$cbr2 stop" proc finish {} { global ns nf $ns flush-trace close $nf exec awk { { if(($1=="-" && $5=="tcp") || ($1=="-" && $5=="cbr")) { print $2 "\t" $11 } } } tokenbus.tr > throughput.data puts "filtering..." exec nam tokenbus.nam & exec xgraph throughput.data & exit 0 } $ns run Ex. No. : 6B - Token ring protocol Aim: To study and simulate the TOKEN RING protocol. Algorithm : Create a simulator object , set Bandwidth 1 MB and packet size 700 Define different colors for data flows (for NAM) Create seven nodes that forms a network numbered from 0 to 6 and label the nodes for identifying sender and receiver Open a nam trace file and define finish procedure then close the trace file, and

execute nam on trace file. Create duplex links between the nodes and add Orientation to the nodes for setting a LAN topology Setup TCP Connection between some nodes and apply FTP Application over TCP Setup UDP Connection between some other nodes and apply CBR Application over UDP Schedule events to achieve Token ring scenario and view graph for the throughput calculated

Program : set ns [new Simulator] set Bandwidth "1Mb" set paketsize 700 set intval 0.004 set nf [open out.nam w] $ns namtrace-all $nf set f [open out.tr w] $ns trace-all $f set old_data 0 proc finish {} { global ns nf $ns flush-trace close $nf exec awk { { if($1=="-"&& $5=="cbr") { print $2"\t"$11 } } } out.tr > throughput.data exec nam out.nam & exec xgraph throughput.data & exit 0 } for {set i 0} {$i < 6} {incr i} { set n($i) [$ns node] } $ns color 1 purple $ns color 2 green $ns color 3 darkgreen for {set i 0} {$i < 6} {incr i} { $ns duplex-link $n($i) $n([expr ($i+1)%6]) $Bandwidth 10ms DropTail } set tcp1 [new Agent/TCP] $ns attach-agent $n(0) $tcp1 $tcp1 set fid_ 1 ; set sink1 [new Agent/TCPSink] $ns attach-agent $n(3) $sink1 $ns connect $tcp1 $sink1 set ftp1 [new Application/FTP] $ftp1 attach-agent $tcp1 set tcp2 [new Agent/TCP] $ns attach-agent $n(3) $tcp2

$tcp2 set fid_ 1 ; set sink2 [new Agent/TCPSink] $ns attach-agent $n(5) $sink2 $ns connect $tcp2 $sink2 set ftp2 [new Application/FTP] $ftp2 attach-agent $tcp2 set tcp3 [new Agent/TCP] $ns attach-agent $n(5) $tcp3 $tcp3 set fid_ 1 ; set sink3 [new Agent/TCPSink] $ns attach-agent $n(2) $sink3 $ns connect $tcp3 $sink3 set ftp3 [new Application/FTP] $ftp3 attach-agent $tcp3 set tcp4 [new Agent/TCP] $ns attach-agent $n(2) $tcp4 $tcp4 set fid_ 1 ; set sink4 [new Agent/TCPSink] $ns attach-agent $n(4) $sink4 $ns connect $tcp4 $sink4 set ftp4 [new Application/FTP] $ftp4 attach-agent $tcp4 set tcp5 [new Agent/TCP] $ns attach-agent $n(4) $tcp5 $tcp5 set fid_ 1 ; set sink5 [new Agent/TCPSink] $ns attach-agent $n(0) $sink5 $ns connect $tcp5 $sink5 set ftp5 [new Application/FTP] $ftp5 attach-agent $tcp5 set udp0 [new Agent/UDP] $ns attach-agent $n(5) $udp0 $udp0 set fid_ 3 ; $tcp3 set fid_ 2 ; set cbr0 [new Application/Traffic/CBR] $cbr0 set interval_ $intval $cbr0 attach-agent $udp0 set null0 [new Agent/Null] $ns attach-agent $n(2) $null0 $ns connect $udp0 $null0 $ns at 0.1 "$ftp1 start" $ns at 0.125 "$ns detach-agent $n(0) $tcp1; $ns detach-agent $n(3) $sink1" $ns at 1.0 "finish" $ns at 0.131 "$ftp2 start" $ns at 0.14 "$ns detach-agent $n(3) $tcp2; $ns detach-agent $n(5) $sink2" $ns at 1.0 "finish" $ns at 0.157 "$ftp3 start" $ns at 0.185 "$ns detach-agent $n(5) $tcp3; $ns detach-agent $n(2) $sink3" $ns at 1.0 "finish" $ns at 0.19 "$ftp4 start" $ns at 0.21 "$ns detach-agent $n(2) $tcp4; $ns detach-agent $n(4) $sink4" $ns at 1.0 "finish" $ns at 0.211 "$ftp5 start" $ns at 0.22 "$ns detach-agent $n(4) $tcp5; $ns detach-agent $n(0) $sink5"

$ns at 1.0 "finish" $ns at 0.157 "$cbr0 start" #$ns rtmodel-at 1.0 down $n(1) $n(2) #$ns rtmodel-at 2.0 up $n(1) $n(2) $ns at 0.185 "$cbr0 stop" $ns at 1.0 "finish" $ns run

Ex. No. : 7 - Wireless LAN protocols Aim : To study a 3-node example for ad-hoc simulation with DSDV Algorithm : Define node options Create a simulator object Create seven nodes that forms a network numbered from 0 to 6 and label the nodes for identifying sender and receiver Open a nam trace file and define finish procedure then close the trace file, and execute nam on trace file. set up topography object Create 3 mobilenodes ,attach them to the channel and configure the nodes Provide initial location of mobilenodes and set up the options for movement of nodes . Set a TCP connection between node_(0) and node_(1) Print the window size Define node initial position in nam, define the node size for nam Tell nodes about the simulation ending time End nam and the simulation Program : # Define options set val(chan) Channel/WirelessChannel ;# channel type set val(prop) Propagation/TwoRayGround ;# radio-propagation model set val(netif) Phy/WirelessPhy ;# network interface type set val(mac) Mac/802_11 ;# MAC type set val(ifq) Queue/DropTail/PriQueue ;# interface queue type set val(ll) LL ;# link layer type set val(ant) Antenna/OmniAntenna ;# antenna model set val(ifqlen) 50 ;# max packet in ifq set val(nn) 3 ;# number of mobilenodes set val(rp) DSDV ;# routing protocol set val(x) 500 ;# X dimension of topography set val(y) 400 ;# Y dimension of topography set val(stop) 150 ;# time of simulation end set ns [new Simulator] set tracefd [open simple11.tr w] set windowVsTime2 [open win11.tr w] set namtrace [open simwrls1.nam w] $ns trace-all $tracefd

$ns namtrace-all-wireless $namtrace $val(x) $val(y) # set up topography object set topo [new Topography] $topo load_flatgrid $val(x) $val(y) create-god $val(nn) # Create nn mobilenodes [$val(nn)] and attach them to the channel. # configure the nodes $ns node-config -adhocRouting $val(rp) \ -llType $val(ll) \ -macType $val(mac) \ -ifqType $val(ifq) \ -ifqLen $val(ifqlen) \ -antType $val(ant) \ -propType $val(prop) \ -phyType $val(netif) \ -channelType $val(chan) \ -topoInstance $topo \ -agentTrace ON \ -routerTrace ON \ -macTrace OFF \ -movementTrace ON for {set i 0} {$i < $val(nn) } { incr i } { set node_($i) [$ns node] } # Provide initial location of mobilenodes $node_(0) set X_ 5.0 $node_(0) set Y_ 5.0 $node_(0) set Z_ 0.0 $node_(1) set X_ 490.0 $node_(1) set Y_ 285.0 $node_(1) set Z_ 0. $node_(2) set X_ 150.0 $node_(2) set Y_ 240.0 $node_(2) set Z_ 0.0 # Generation of movements $ns at 10.0 "$node_(0) setdest 250.0 250.0 3.0" $ns at 15.0 "$node_(1) setdest 45.0 285.0 5.0" $ns at 110.0 "$node_(0) setdest 480.0 300.0 5.0" # Set a TCP connection between node_(0) and node_(1) set tcp [new Agent/TCP/Newreno] $tcp set class_ 2 set sink [new Agent/TCPSink] $ns attach-agent $node_(0) $tcp $ns attach-agent $node_(1) $sink $ns connect $tcp $sink set ftp [new Application/FTP] $ftp attach-agent $tcp $ns at 10.0 "$ftp start" # Printing the window size proc plotWindow {tcpSource file} { global ns set time 0.01 set now [$ns now] set cwnd [$tcpSource set cwnd_]

puts $file "$now $cwnd" $ns at [expr $now+$time] "plotWindow $tcpSource $file" } $ns at 10.1 "plotWindow $tcp $windowVsTime2" # Define node initial position in nam for {set i 0} {$i < $val(nn)} { incr i } { # 30 defines the node size for nam $ns initial_node_pos $node_($i) 30 } # Telling nodes when the simulation ends for {set i 0} {$i < $val(nn) } { incr i } { $ns at $val(stop) "$node_($i) reset"; } # ending nam and the simulation $ns at $val(stop) "$ns nam-end-wireless $val(stop)" $ns at $val(stop) "stop" $ns at 150.01 "puts \"end simulation\" ; $ns halt" proc stop {} { global ns tracefd namtrace $ns flush-trace close $tracefd close $namtrace } $ns run Ex. No. : 8 - Implementation and study of stop and wait protocol Aim : To implement and study stop and wait protocol in normal situation Algorithm : Create a simulator object Create two nodes that forms a network numbered from 0 to 1 and label the nodes for identifying sender and receiver Open a nam trace file and define finish procedure then close the trace file, and execute nam on trace file. Create duplex links between the nodes and add Orientation to the nodes for setting a LAN topology Setup TCP Connection between nodes and apply FTP Application over TCP Schedule events to achieve stop and wait scenario Program : # stop and wait protocol in normal situation # features : labeling, annotation, nam-graph, and window size monitoring set ns [new Simulator] set n0 [$ns node] set n1 [$ns node] $ns at 0.0 "$n0 label Sender" $ns at 0.0 "$n1 label Receiver" set nf [open A1-stop-n-wait.nam w] $ns namtrace-all $nf set f [open A1-stop-n-wait.tr w] $ns trace-all $f $ns duplex-link $n0 $n1 0.2Mb 200ms DropTail $ns duplex-link-op $n0 $n1 orient right $ns queue-limit $n0 $n1 10 Agent/TCP set nam_tracevar_ true

set tcp [new Agent/TCP] $tcp set window_ 1 $tcp set maxcwnd_ 1 $ns attach-agent $n0 $tcp set sink [new Agent/TCPSink] $ns attach-agent $n1 $sink $ns connect $tcp $sink set ftp [new Application/FTP] $ftp attach-agent $tcp $ns add-agent-trace $tcp tcp $ns monitor-agent-trace $tcp $tcp tracevar cwnd_ $ns at 0.1 "$ftp start" $ns at 3.0 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n1 $sink" $ns at 3.5 "finish" $ns at 0.0 "$ns trace-annotate \"Stop and Wait with normal operation\"" $ns at 0.05 "$ns trace-annotate \"FTP starts at 0.1\"" $ns at 0.11 "$ns trace-annotate \"Send Packet_0\"" $ns at 0.35 "$ns trace-annotate \"Receive Ack_0\"" $ns at 0.56 "$ns trace-annotate \"Send Packet_1\"" $ns at 0.79 "$ns trace-annotate \"Receive Ack_1\"" $ns at 0.99 "$ns trace-annotate \"Send Packet_2\"" $ns at 1.23 "$ns trace-annotate \"Receive Ack_2 \"" $ns at 1.43 "$ns trace-annotate \"Send Packet_3\"" $ns at 1.67 "$ns trace-annotate \"Receive Ack_3\"" $ns at 1.88 "$ns trace-annotate \"Send Packet_4\"" $ns at 2.11 "$ns trace-annotate \"Receive Ack_4\"" $ns at 2.32 "$ns trace-annotate \"Send Packet_5\"" $ns at 2.55 "$ns trace-annotate \"Receive Ack_5 \"" $ns at 2.75 "$ns trace-annotate \"Send Packet_6\"" $ns at 2.99 "$ns trace-annotate \"Receive Ack_6\"" $ns at 3.1 "$ns trace-annotate \"FTP stops\"" proc finish {} { global ns nf $ns flush-trace close $nf puts "filtering..." exec tclsh ../ns-allinone-2.1b5/nam-1.0a7/bin/namfilter.tcl A1-stop-n-wait.nam puts "running nam..." exec nam A1-stop-n-wait.nam & exit 0 } $ns run

Ex. No. : 8b - Implementation and study of stop and wait protocol with packet loss Aim : To implement and study stop and wait protocol with packet loss Algorithm : Create a simulator object Create two nodes that forms a network numbered from 0 to 1 and label the nodes for identifying sender and receiver

Open a nam trace file and define finish procedure then close the trace file, and execute nam on trace file. Create duplex links between the nodes and add Orientation to the nodes for setting a LAN topology Setup TCP Connection between nodes and apply FTP Application over TCP Schedule events to achieve stop and wait scenario Program: # features : labeling, annotation, nam-graph, and window size monitoring set ns [new Simulator] set n0 [$ns node] set n1 [$ns node] $ns at 0.0 "$n0 label Sender" $ns at 0.0 "$n1 label Receiver" set nf [open out.nam w] $ns namtrace-all $nf set f [open out.tr w] $ns trace-all $f $ns duplex-link $n0 $n1 0.2Mb 200ms DropTail $ns duplex-link-op $n0 $n1 orient right $ns duplex-link-op $n0 $n1 queuePos 0.5 $ns queue-limit $n0 $n1 10 Agent/TCP set nam_tracevar_ true set tcp [new Agent/TCP] $tcp set window_ 2 $tcp set maxcwnd_ 1 $ns attach-agent $n0 $tcp set sink [new Agent/TCPSink] $ns attach-agent $n1 $sink $ns connect $tcp $sink set ftp [new Application/FTP] $ftp attach-agent $tcp $ns add-agent-trace $tcp tcp $ns monitor-agent-trace $tcp $tcp tracevar cwnd_ $ns at 0.1 "$ftp start" $ns at 1.3 "$ns queue-limit $n0 $n1 0" $ns at 1.5 "$ns queue-limit $n0 $n1 10" $ns at 3.0 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n1 $sink" $ns at 3.5 "finish" $ns at 0.0 "$ns trace-annotate \"Stop and Wait with Packet Loss\""

$ns at 0.05 "$ns trace-annotate \"FTP starts at 0.1\"" $ns at 0.11 "$ns trace-annotate \"Send Packet_0\"" $ns at 0.35 "$ns trace-annotate \"Receive Ack_0\"" $ns at 0.56 "$ns trace-annotate \"Send Packet_1\"" $ns at 0.79 "$ns trace-annotate \"Receive Ack_1\"" $ns at 0.99 "$ns trace-annotate \"Send Packet_2\"" $ns at 1.23 "$ns trace-annotate \"Receive Ack_2 \"" $ns at 1.43 "$ns trace-annotate \"Lost Packet_3\"" $ns at 1.5 "$ns trace-annotate \"Waiting for Ack_3\"" $ns at 2.43 "$ns trace-annotate \"Send Packet_3 again (cause of timeout)\"" $ns at 2.67 "$ns trace-annotate \"Receive Ack_3\"" $ns at 2.88 "$ns trace-annotate \"Send Packet_4\"" $ns at 3.1 "$ns trace-annotate \"FTP stops\""

proc finish {} { global ns nf $ns flush-trace close $nf puts "filtering..." exec tclsh namfilter.tcl out.nam puts "running nam..." exec nam out.nam & exit 0 } $ns run

Ex. No. : 9 - Implementation and study of Sliding window protocol Aim : To implement and study sliding window protocol Algorithm : Create a simulator object Create two nodes that forms a network numbered from 0 to 1 and label the nodes for identifying sender and receiver Open a nam trace file and define finish procedure then close the trace file, and execute nam on trace file. Create duplex links between the nodes and add Orientation to the nodes for setting a LAN topology Setup TCP Connection between nodes and apply FTP Application over TCP Add the queue limits for the nodes Schedule events to achieve sliding window protocol scenario

Program :

# sliding window mechanism with some features # such as labeling, annotation, nam-graph, and window size monitoring set ns [new Simulator] set n0 [$ns node] set n1 [$ns node] $ns at 0.0 "$n0 label Sender" $ns at 0.0 "$n1 label Receiver" set nf [open out.nam w] $ns namtrace-all $nf set f [open out.tr w] $ns trace-all $f $ns duplex-link $n0 $n1 0.2Mb 200ms DropTail $ns duplex-link-op $n0 $n1 orient right $ns queue-limit $n0 $n1 10 Agent/TCP set nam_tracevar_ true set tcp [new Agent/TCP] $tcp set windowInit_ 4 $tcp set maxcwnd_ 4 $ns attach-agent $n0 $tcp set sink [new Agent/TCPSink] $ns attach-agent $n1 $sink $ns connect $tcp $sink set ftp [new Application/FTP] $ftp attach-agent $tcp $ns add-agent-trace $tcp tcp $ns monitor-agent-trace $tcp $tcp tracevar cwnd_ $ns at 0.1 "$ftp start" $ns at 3.0 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n1 $sink" $ns at 3.5 "finish" $ns at 0.0 "$ns trace-annotate \"Sliding Window with window size 4 (normal operation)\"" $ns at 0.05 "$ns trace-annotate \"FTP starts at 0.1\"" $ns at 0.56 "$ns trace-annotate \"Send Packet_0,1,2,3\"" $ns at 0.79 "$ns trace-annotate \"Receive Ack_0,1,2,3\"" $ns at 0.99 "$ns trace-annotate \"Send Packet_4,5,6,7\"" $ns at 1.23 "$ns trace-annotate \"Receive Ack_4,5,6,7\"" $ns at 1.43 "$ns trace-annotate \"Send Packet_8,9,10,11\"" $ns at 1.67 "$ns trace-annotate \"Receive Ack_8,9,10,11 \""

$ns at 1.88 "$ns trace-annotate \"Send Packet_12,13,14,15\"" $ns at 2.11 "$ns trace-annotate \"Receive Ack_12,13,14,15\"" $ns at 2.32 "$ns trace-annotate \"Send Packet_16,17,18,19\"" $ns at 2.56 "$ns trace-annotate \"Receive Ack_16,17,18,19\"" $ns at 2.76 "$ns trace-annotate \"Send Packet_20,21,22,23\"" $ns at 3.00 "$ns trace-annotate \"Receive Ack_23\"" $ns at 3.1 "$ns trace-annotate \"FTP stops\"" proc finish {} { global ns $ns flush-trace # puts "filtering..." exec tclsh namfilter.tcl out.nam puts "running nam..." exec nam out.nam & exit 0 } $ns run

Ex. No. : 10 - Implementation of distance vector routing algorithm Aim : To implement and study distance vector routing algorithm Algorithm : Create a simulator object and specify the simulator to use dynamic routing or Link state routing Open a nam trace file and define finish procedure then close the trace file, and execute nam on trace file. Create seven nodes that forms a network numbered from 0 to 6 Create duplex links between the nodes and add Orientation to the nodes for setting a LAN topology Setup UDP Connection between nodes 0 and 3 and apply CBR Application over UDP Label the nodes 0 and 3 as Source and destination Schedule route model and events to achieve distance vector routing algorithm Program : #distvect.tcl set ns [new Simulator] #Tell the simulator to use dynamic routing $ns rtproto DV #Open the nam trace file set nf [open out.nam w] $ns namtrace-all $nf #Define finish procedure proc finish {} { global ns nf $ns flush-trace

#Close the trace file close $nf #Execute nam on the trace file exec nam a out.nam & exit 0 } #Create seven nodes for {set i 0} {$i < 7} {incr i} { set n($i) [$ns node] } #Create links between the nodes for {set i 0} {$i < 7} {incr i} { $ns duplex-link $n($i) $n([expr ($i+1)%7]) 1Mb 10ms DropTail } #Create a UDP agent and attach it to node n(0) set udp0 [new Agent/UDP] $ns attach-agent $n(0) $udp0 #Create a CBR traffic source and attach it to udp0 set cbr0 [new Application/Traffic/CBR] $cbr0 set packetSize_ 500 $cbr0 set interval_ 0.005 $cbr0 attach-agent $udp0 set null0 [new Agent/Null] $ns attach-agent $n(3) $null0 $ns connect $udp0 $null0 $ns at 0.0 "$n(0) label Source" $ns at 0.0 "$n(3) label Destination" $ns at 0.5 "$cbr0 start" $ns rtmodel-at 1.0 down $n(1) $n(2) $ns rtmodel-at 2.0 up $n(1) $n(2) $ns at 4.5 "$cbr0 stop" $ns at 5.0 "finish" $ns run Ex. No. : 11 - Implementation of Link state routing algorithm Aim : To implement and study Link state routing algorithm Algorithm : Create a simulator object and specify the simulator to use Link state routing Open a nam trace file and define finish procedure then close the trace file, and execute nam on trace file. Create seven nodes that forms a network numbered from 0 to 6 Create duplex links between the nodes and add Orientation to the nodes for setting a LAN topology Setup UDP Connection between nodes 0 and 3 and apply CBR Application over UDP Label the nodes 0 and 3 as Source and destination Schedule route model and events to achieve Link state routing algorithm #linkstate.tcl set ns [new Simulator] #Tell the simulator to use dynamic routing $ns rtproto LS

#Open the nam trace file set nf [open out.nam w] $ns namtrace-all $nf #Define finish procedure proc finish {} { global ns nf $ns flush-trace #Close the trace file close $nf #Execute nam on the trace file exec nam a out.nam & exit 0 } #Create seven nodes for {set i 0} {$i < 7} {incr i} { set n($i) [$ns node] } #Create links between the nodes for {set i 0} {$i < 7} {incr i} { $ns duplex-link $n($i) $n([expr ($i+1)%7]) 1Mb 10ms DropTail } #Create a UDP agent and attach it to node n(0) set udp0 [new Agent/UDP] $ns attach-agent $n(0) $udp0 #Create a CBR traffic source and attach it to udp0 set cbr0 [new Application/Traffic/CBR] $cbr0 set packetSize_ 500 $cbr0 set interval_ 0.005 $cbr0 attach-agent $udp0 set null0 [new Agent/Null] $ns attach-agent $n(3) $null0 $ns connect $udp0 $null0 $ns at 0.0 "$n(0) label Source" $ns at 0.0 "$n(3) label Destination" $ns at 0.5 "$cbr0 start" $ns rtmodel-at 1.0 down $n(1) $n(2) $ns rtmodel-at 2.0 up $n(1) $n(2) $ns at 4.5 "$cbr0 stop" $ns at 5.0 "finish" $ns run Ex. No. : 12 - Implementation of Data encryption and decryption -- Completed --

Vous aimerez peut-être aussi