How to create dynamic data transfer between nodes using TCP in ns2

Description

The network topology has been created using duplex link between the nodes. The communication between the nodes is established in a random fashion using “rand” function. The most commonly used protocol in wired network is Transport Control Protocol (TCP). Test3.tcl demonstrates the dynamic data transmission in which the traffic between sender and receiver is established dynamically. Internet traffic is the instance of the above scenario.

# Filename: test3.tcl

# —————-ESTABLISHING COMMUNICATION ————-#

#————–TCP CONNECTION BETWEEN NODES—————#
$ns at 0.0 "Tranmission"
proc Tranmission {} {
global C ROU R ns

set now [$ns now]
set time 0.75
set x [expr round(rand()*4)];if {$x==0} {set x 2}
set y [expr round(rand()*4)];if {$y==0} {set y 3}

set tcp1 [$ns create-connection TCP $C($x) TCPSink $R($y) 1]
$ns at $now "$ns trace-annotate \"Time: $now Pkt Transfer between Client($x) Receiver($y)..\""
$tcp1 set class_ 1
$tcp1 set maxcwnd_ 16
$tcp1 set packetsize_ 4000
$tcp1 set fid_ 1
set ftp1 [$tcp1 attach-app FTP]
$ftp1 set interval_ .005
$ns at $now "$ftp1 start"
$ns at [expr $now+$time] "$ftp1 stop"
$ns at [expr $now+$time] "Tranmission"
}

At time 0.75s

Dynamic data transfer creation between nodes using TCP in ns2

At time 1.5s

Dynamic data transfer creation between nodes using TCP in ns2