# Simple example of pre-Van Jacobson TCP


set ns [new Simulator]

set vj_ss false

# Set ns color indices
$ns color 0 blue
$ns color 1 red
$ns color 2 white

# Create 3 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]

# Set node colors and shapes
$n0 shape hexagon
$n0 color red
$n0 label server
$n2 shape hexagon
$n2 color blue

# Open trace files
set nf [open pre-vj.nam w]
$ns namtrace-all $nf

# Create 2 duplex links
$ns duplex-link $n0 $n1 1Mb 50ms DropTail
$ns duplex-link $n1 $n2 0.55Mb 50ms DropTail

# Set Node 1's queue size to 4
$ns queue-limit $n1 $n2 4

# Orient the nodes; show the queue
$ns duplex-link-op $n0 $n1 orient 10deg
$ns duplex-link-op $n1 $n2 orient 10deg
$ns duplex-link-op $n1 $n2 queuePos 0.5

# Create sender TCP agent at Node 0; set receiver advertised window to 8
set tcpSender [new Agent/TCP]
$tcpSender set slow_start_ $vj_ss
$tcpSender set colored_rtx_ 0
$tcpSender set window_ 64
$tcpSender set class_ 0
$tcpSender set packetSize_ 1000
$tcpSender set window_ 12
$ns attach-agent $n0 $tcpSender

# Create CBR agent for TCP sender; set packet size to 1000 bytes, at 1 Mbps
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $tcpSender
$cbr set packet_size_ 1000
$cbr set rate_ 1Mbps
$cbr set maxpkts_ 100

# Create receiver TCP agent at Node 0
set tcpReceiver [new Agent/TCPSink]
$ns attach-agent $n2 $tcpReceiver

# Connect the two TCP agents
$ns connect $tcpSender $tcpReceiver

# Run the simulation
$ns at 0.1 "$cbr start"
$ns at 20 "finish"

proc finish {} {
#    global ns nf f
    global ns nf
    $ns flush-trace
#    close $f
    close $nf

    puts "running nam..."
    exec nam out.nam &
    exit 0
}

$ns run
