#5, First Floor, 4th Street , Dr. Subbarayan Nagar, Kodambakkam, Chennai-600 024 pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

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.

Sample Code

# 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"
}


Screenshots

At time 0.75s

At time 1.5s