NS2 Program Based on TCP

CODE

# Create a ns object
set ns [new Simulator]

$ns color 1 Blue
$ns color 2 Red

# Open the Trace files
set TraceFile [open outtcp.tr w]
$ns trace-all $TraceFile

# Open the NAM trace file
set NamFile [open outtcp.nam w]
$ns namtrace-all $NamFile

# 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]

$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns duplex-link $n2 $n3 0.25Mb 100ms DropTail # bottleneck link
$ns duplex-link $n3 $n4 2Mb 10ms DropTail
$ns duplex-link $n3 $n5 2Mb 10ms DropTail

$ns queue-limit $n2 $n3 20

$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n3 orient right
$ns duplex-link-op $n3 $n4 orient right-up
$ns duplex-link-op $n3 $n5 orient right-down

#TCP N0 and N4
set tcp1 [new Agent/TCP/Newreno]
$ns attach-agent $n0 $tcp1

set sink1 [new Agent/TCPSink/DelAck]
$ns attach-agent $n4 $sink1

$ns connect $tcp1 $sink1

$tcp1 set fid_ 1
$tcp1 set window_ 8000
$tcp1 set packetSize_ 600

#TCP N0 and N4
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1
$ftp1 set type_ FTP

#TCP N1 and N5
set tcp2 [new Agent/TCP/Newreno]
$ns attach-agent $n1 $tcp2

set sink2 [new Agent/TCPSink/DelAck]
$ns attach-agent $n5 $sink2

$ns connect $tcp2 $sink2

$tcp2 set fid_ 2
$tcp2 set window_ 8000
$tcp2 set packetSize_ 600

#FTP TCP N1 and N5
set ftp2 [new Application/FTP]
$ftp2 attach-agent $tcp2
$ftp2 set type_ FTP

$ns at 0.1 "$ftp1 start"
$ns at 10.0 "$ftp2 start"
$ns at 50.0 "$ftp1 stop"
$ns at 45.0 "$ftp2 stop"

proc finish {} {
        global ns TraceFile NamFile
        $ns flush-trace
        close $TraceFile
        close $NamFile
        exec nam outtcp.nam &
        exit 0
}
$ns at 60.0 "finish"
$ns run

OUTPUT


Contact:
Mobile: +91-7276355704
WhatsApp: +91-7276355704
Email: roshanphelonde@rediffmail.com
Share:

Total Pageviews

CONTACT US

Prof. Roshan P. Helonde
Mobile: +917276355704
WhatsApp: +917276355704
Email: roshanphelonde@rediffmail.com

Enter Project Title

Popular Projects

All Archive

Contact Form

Name

Email *

Message *