You are on page 1of 15

Ex.

No: Date: CBR OVER TCP Aim: To implement the routing protocol CBR over TCP using ns2. Alogrithm:

create a new simulator. Set the color for data flows in NAM. Open the trace file and NAM file in write mode. In the finish function flush the trace file and execute the nam file. Create a node for corresponding network path. Create the link between the nodes set the duplex link and speed,time. Set the position for nodes and set the queue. Set up TCP connection. Set the cbr and file start and stop timing Start ns packet,start sending time and ending time.

PROGRAM.tcl set ns [new Simulator] #Define different colors for data flows (for NAM) $ns color 1 Blue $ns color 2 Red #Open the NAM trace file set nf [open out.nam w] $ns namtrace-all $nf #Define a 'finish' procedure proc finish {} { global ns nf $ns flush-trace close $nf exec nam out.nam & exit 0 } set n0 [$ns node] set n1 [$ns node] $ns duplex-link $n0 $n1 1Mb 10ms DropTail set tcp0 [ new Agent/TCP ] $ns attach-agent $n0 $tcp0 set cbr0 [new Application/Traffic/CBR] $cbr0 set packetSize_ 500 $cbr0 set interval_ 0.005 $cbr0 attach-agent $tcp0 set sink0 [ new Agent/TCPSink ] $ns attach-agent $n1 $sink0 $ns connect $tcp0 $sink0 $ns at 0.5 "$cbr0 start" $ns at 4.5 "$cbr0 stop"

$ns at 5.0 "finish" $ns run

RESULT: Thus the CBR over TCP simulation is performed successfully

Ex. No:

Date: ROUTING PROTOCOL TCP/UDP Aim: To implement the routing protocol TCP/UDP using ns2. Alogrithm:

create a new simulator. Set the color for dataflows in nam. Open the trace file and NAM file in write mode. In the finish function flush the trace file and execute the nam file. Create a node for corresponding network path. Create the link between the nodes set the duplex link and speed,time. Set the position for nodes and set the queue. Set up TCP and UDP connection. Set the CBR and FTP, file start and stop timing Start ns packet,start sending time and ending time.

PROGRAM.tcl set ns [new Simulator] #Define different colors for data flows (for NAM) $ns color 1 Blue $ns color 2 Red #Open the NAM trace file set file2 [open out.nam w] $ns namtrace-all $file2 #Define a 'finish' procedure proc finish {} { global ns file2 $ns flush-trace close $file2 exec nam out.nam & exit 0 } #Create six nodes set n0 [$ns node] 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 $n0 $n2 2Mb 10ms DropTail $ns duplex-link $n1 $n2 2Mb 10ms DropTail $ns simplex-link $n2 $n3 0.3Mb 100ms DropTail $ns simplex-link $n3 $n2 0.3Mb 100ms DropTail

$ns duplex-link $n3 $n4 0.5Mb 40ms DropTail $ns duplex-link $n3 $n5 0.5Mb 30ms DropTail #Give node position (for NAM) $ns duplex-link-op $n0 $n2 orient right-down $ns duplex-link-op $n1 $n2 orient right-up $ns simplex-link-op $n2 $n3 orient right $ns simplex-link-op $n3 $n2 orient left $ns duplex-link-op $n3 $n4 orient right-up $ns duplex-link-op $n3 $n5 orient right-down #Setup a TCP connection set tcp [new Agent/TCP] $ns attach-agent $n0 $tcp set sink [new Agent/TCPSink] $ns attach-agent $n4 $sink $ns connect $tcp $sink $tcp set fid_ 1 $tcp set window_ 8000 $tcp set packetSize_ 552 #Setup a FTP over TCP connection set ftp [new Application/FTP] $ftp attach-agent $tcp $ftp set type_ FTP #Setup a UDP connection set udp [new Agent/UDP] $ns attach-agent $n1 $udp set null [new Agent/Null] $ns attach-agent $n5 $null $ns connect $udp $null $udp set fid_ 2 #Setup a CBR over UDP connection set cbr [new Application/Traffic/CBR] $cbr attach-agent $udp $cbr set type_ CBR $cbr set packet_size_ 1000 $cbr set rate_ 0.01mb $cbr set random_ false $ns at 0.1 "$cbr start" $ns at 1.0 "$ftp start" $ns at 124.0 "$ftp stop" $ns at 124.5 "$cbr stop" $ns at 125.0 "finish" $ns run

RESULT: Thus the FTP/CBR over TCP/UDP simulation is performed successfully.

Ex. No:

STUDY PERFORMANCE OF TCP

Date:

Simulation of FTP over TCP using Distance vector routing


Aim: To implement the simulation of FTP over TCP using distance vector routing. Alogrithm:

create a new simulator. Set the color for dataflows in nam. Open the trace file and NAM file in write mode. In the finish function flush the trace file and execute the nam file. set the Distance Vector routing. Create a node for corresponding network path. Create the link between the nodes set the duplex link and speed,time. Set the position for nodes and set the queue. Set up TCP connection. Set the FTP and file start and stop timing Start ns packet,start sending time and ending time.

PROGRAM.tcl set ns [new Simulator] #Define different colors for data flows (for NAM) $ns color 1 Blue $ns color 2 Red #Open the NAM trace file set file2 [open out.nam w] $ns namtrace-all $file2 #Define a 'finish' procedure proc finish {} { global nsfile2 $ns flush-trace close $file2 exec nam out.nam & exit 0 } # Next line should be commented out to have the static routing $ns rtproto DV #Create six nodes set n0 [$ns node] 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 $n0 $n1 0.3Mb 10ms DropTail $ns duplex-link $n1 $n2 0.3Mb 10ms DropTail $ns duplex-link $n2 $n3 0.3Mb 10ms DropTail $ns duplex-link $n1 $n4 0.3Mb 10ms DropTail $ns duplex-link $n3 $n5 0.5Mb 10ms DropTail $ns duplex-link $n4 $n5 0.5Mb 10ms DropTail #Give node position (for NAM) $ns duplex-link-op $n0 $n1 orient right $ns duplex-link-op $n1 $n2 orient right $ns duplex-link-op $n2 $n3 orient up $ns duplex-link-op $n1 $n4 orient up-left $ns duplex-link-op $n3 $n5 orient left-up $ns duplex-link-op $n4 $n5 orient right-up #Setup a TCP connection set tcp [new Agent/TCP] $ns attach-agent $n0 $tcp set sink [new Agent/TCPSink] $ns attach-agent $n5 $sink $ns connect $tcp $sink $tcp set fid_ 2 #Setup a FTP over TCP connection set ftp [new Application/FTP] $ftp attach-agent $tcp $ftp set type_ FTP $ns rtmodel-at 1.0 down $n1 $n4 $ns rtmodel-at 4.5 up $n1 $n4 $ns at 0.1 "$ftp start" $ns at 6.0 "finish" $ns run

OUTPUT:

Ex. No:

Date:

Simulation of FTP over TCP using Link state routing


Aim: To implement the simulation of FTP over TCP using link state routing. Alogrithm:

Create a new simulator. Set the color for data flows in nam. Open the trace file and NAM file in write mode. In the finish function flush the trace file and execute the nam file. set the link state routing Create a node for corresponding network path. Create the link between the nodes set the duplex link and speed,time. Set the position for nodes and set the queue. Set up TCP connection. Set the FTP and file start and stop timing Start ns packet, start sending time and ending time.

PROGRAM.tcl set ns [new Simulator] #Define different colors for data flows (for NAM) $ns color 1 Blue $ns color 2 Red #Open the NAM trace file set file2 [open out.nam w] $ns namtrace-all $file2 #Define a 'finish' procedure proc finish {} { global ns file2 $ns flush-trace close $file2 exec nam out.nam & exit 0 } # Next line should be commented out to have the static routing $ns rtproto LS #Create six nodes set n0 [$ns node] 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 $n0 $n1 0.3Mb 10ms DropTail $ns duplex-link $n1 $n2 0.3Mb 10ms DropTail $ns duplex-link $n2 $n3 0.3Mb 10ms DropTail $ns duplex-link $n1 $n4 0.3Mb 10ms DropTail $ns duplex-link $n3 $n5 0.5Mb 10ms DropTail $ns duplex-link $n4 $n5 0.5Mb 10ms DropTail #Give node position (for NAM) $ns duplex-link-op $n0 $n1 orient right $ns duplex-link-op $n1 $n2 orient right $ns duplex-link-op $n2 $n3 orient up $ns duplex-link-op $n1 $n4 orient up-left $ns duplex-link-op $n3 $n5 orient left-up $ns duplex-link-op $n4 $n5 orient right-up #Setup a TCP connection set tcp [new Agent/TCP/Newreno] $ns attach-agent $n0 $tcp set sink [new Agent/TCPSink/DelAck] $ns attach-agent $n5 $sink $ns connect $tcp $sink $tcp set fid_ 2 #Setup a FTP over TCP connection set ftp [new Application/FTP] $ftp attach-agent $tcp $ftp set type_ FTP $ns rtmodel-at 1.0 down $n1 $n4 $ns rtmodel-at 4.5 up $n1 $n4 $ns at 0.1 "$ftp start" $ns at 6.0 "finish" $ns run OUTPUT:

+[student@lab1sys1 ~]$ cat TcpOutDV.tr + 0.00017 0 1 rtProtoDV 6 ------- 0 0.2 1.1 -1 0 - 0.00017 0 1 rtProtoDV 6 ------- 0 0.2 1.1 -1 0 ...... ...... + 5.997973 1 0 ack 40 ------- 1 5.0 0.0 52 222 - 5.997973 1 0 ack 40 ------- 1 5.0 0.0 52 222 [student@lab1sys1 ~]$ raw2xg -a TcpOutLS.tr > TcpOutLS.xg [student@lab1sys1 ~]$ raw2xg -a ...... + 5.99776 4 5 tcp 1040 ------- 1 0.0 5.0 181 366 - 5.99776 4 5 tcp 1040 ------- 1 0.0 5.0 181 366 [student@lab1sys1 ~]$ cat TcpOutLS.tr + 0.00017 0 1 rtProtoLS 100 ------- 0 0.2 1.1 -1 0 - 0.00017 0 1 rtProtoLS 100 ------- 0 0.2 1.1 -1 0 ...... TcpOutDV.tr > TcpOutDV.xg [student@lab1sys1 ~]$ xgraph -t "Performance of TCP" TcpOutDV.xg TcpOutLS.xg -geometry 800x400

RESULT: Thus the FTP over TCP using Distance vector routing and link state routing is implements and the performance is analysed successfully.

Ex. No: Date:

Simulation and Performance of CBR over UDP using Link state routing
Aim: To implement the simulation of CBR over UDP using link state routing. Alogrithm:

Create a new simulator. Set the color for data flows in nam. Open the trace file and NAM file in write mode. In the finish function flush the trace file and execute the nam file. set the link state routing Create a node for corresponding network path. Create the link between the nodes set the duplex link and speed,time. Set the position for nodes and set the queue. Set up UDP connection. Set the CBR and file start and stop timing Start ns packet, start sending time and ending time.

PROGRAM.tcl set ns [new Simulator] #Define different colors for data flows (for NAM) $ns color 1 Blue $ns color 2 Red #Open the NAM trace file set file2 [open out.nam w] $ns namtrace-all $file2 #Define a 'finish' procedure proc finish {} { global ns file2 $ns flush-trace close $file2 exec nam out.nam & exit 0 } # Next line should be commented out to have the static routing $ns rtproto LS #Create six nodes set n0 [$ns node] 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 $n0 $n2 2Mb 10ms DropTail $ns duplex-link $n1 $n2 2Mb 10ms DropTail $ns simplex-link $n2 $n3 0.3Mb 100ms DropTail $ns simplex-link $n3 $n2 0.3Mb 100ms DropTail $ns duplex-link $n3 $n4 0.5Mb 40ms DropTail $ns duplex-link $n3 $n5 0.5Mb 30ms DropTail #Give node position (for NAM) $ns duplex-link-op $n0 $n2 orient right-down $ns duplex-link-op $n1 $n2 orient right-up $ns simplex-link-op $n2 $n3 orient right $ns simplex-link-op $n3 $n2 orient left $ns duplex-link-op $n3 $n4 orient right-up $ns duplex-link-op $n3 $n5 orient right-down #Set Queue Size of link (n2-n3) to 10 $ns queue-limit $n2 $n3 20 #Setup a UDP connection set udp [new Agent/UDP] $ns attach-agent $n1 $udp set null [new Agent/Null] $ns attach-agent $n5 $null $ns connect $udp $null $udp set fid_ 2 #Setup a CBR over UDP connection set cbr [new Application/Traffic/CBR] $cbr attach-agent $udp $cbr set type_ CBR $cbr set packet_size_ 1000 $cbr set rate_ 0.01mb $cbr set random_ false $ns at 0.1 "$cbr start" $ns at 124.5 "$cbr stop" # next procedure gets two arguments: the name of the # tcp source node, will be called here "tcp", # and the name of output file. $ns at 125.0 "finish" $ns run

OUTPUT:

[student@lab1sys1 ~]$ cat UdpOutDV.tr + 0.00017 0 2 rtProtoDV 6 ------- 0 0.1 2.1 -1 0 - 0.00017 0 2 rtProtoDV 6 ------- 0 0.1 2.1 -1 0 ...... ...... - 124.822911 1 2 rtProtoDV 6 ------- 0 1.2 2.1 -1 802 r 124.832935 1 2 rtProtoDV 6 ------- 0 1.2 2.1 -1 802 [student@lab1sys1 ~]$ cat UdpOutLS.tr + 0.00017 0 2 rtProtoLS 100 ------- 0 0.1 2.1 -1 0 - 0.00017 0 2 rtProtoLS 100 ------- 0 0.1 2.1 -1 0 ...... ...... - 124.240667 3 5 cbr 1000 ------- 2 1.0 5.0 155 215 r 124.286667 3 5 cbr 1000 ------- 2 1.0 5.0 155 215 [student@lab1sys1 ~]$ raw2xg -a UdpOutLS.tr > UdpOutLS.xg [student@lab1sys1 ~]$ raw2xg -a UdpOutDV.tr > UdpOutDV.xg [student@lab1sys1 ~]$ xgraph -t "Performance of UDP" UdpOutDV.xg UdpOutLS.xg -geometry 800x400

RESULT: Thus the CBR over UDP using link state routing is implementd and the performance is analysed successfully.