Monday, 15 December 2014

3 way handshaking protocol using NS2

set ns [new Simulator]

$ns color 1 Blue

set tr [open 3way.tr w]
$ns trace-all $tr
# NAM file
set nf [open 3way.nam w]
$ns namtrace-all $nf

# finish procedure
proc finish {} {
 global ns nf tr
 $ns flush-trace
 close $nf
 close $tr
 exec nam 3way.nam &
 exit 0
}


# create nodes
set n0 [$ns node]
set n1 [$ns node]



$ns duplex-link $n0 $n1 1Mb 100ms DropTail

# create TCP agents
set src [new Agent/TCP/FullTcp]
set sink [new Agent/TCP/FullTcp]

$ns attach-agent $n0 $src
$ns attach-agent $n1 $sink

$ns connect $src $sink

# set up TCP-level connections
$sink listen
#$src set window_ 100

# create traffic generator
set ftp0 [new Application/FTP]
$ftp0 attach-agent $src
$ftp0 set class_ 1

# run NS
$ns at 0.5 "$ftp0 start"
$ns at 5.0 "finish"
$ns run

No comments:

Post a Comment