Listing 2. TCP Script

set ns [new Simulator]
set nf [open tcpweb.nam w]
$ns namtrace-all $nf
set allchan [open all.tr.tcp w]
$ns trace-all $allchan
proc finish {} {
    global ns nf allchan
    $ns flush-trace
    close $nf
    close $allchan

exec nam tcpweb.nam &
exit 0}

set false      0
set true       1
$ns rtproto DV

set macon [$ns node]
set jurancon [$ns node]
set lrmon3 [$ns node]
set lmcrt0 [$ns node]
set lmcrt1 [$ns node]
set jacob2 [$ns node]
$ns duplex-link $macon $jurancon .5Mb 30ms DropTail
$ns duplex-link $jurancon $lrmon3 .5Mb 30ms DropTail
$ns duplex-link $lrmon3 $lmcrt0 .5Mb 30ms DropTail
$ns duplex-link $lrmon3 $lmcrt1 .5Mb 30ms DropTail
$ns duplex-link $lmcrt0 $jacob2 .5Mb 30ms DropTail
$ns duplex-link $lmcrt0 $lmcrt1 .5Mb 30ms DropTail

set server [new Http/Server $ns $jacob2]
set client [new Http/Client $ns $macon]
set cache [new Http/Cache $ns $lmcrt1]

# Create page pool as a central page generator. Use PagePool/Math

set pgp [new PagePool/Math]
set tmp [new RandomVariable/Constant]
$tmp set val_ 4096  ## average page size;
$pgp ranvar-size $tmp
set tmp [new RandomVariable/Exponential]
$tmp set avg_ 6 ## average page age;
$pgp ranvar-age $tmp
$server set-page-generator $pgp
set tmp [new RandomVariable/Exponential]
$tmp set avg_ 0.5 ## average request interval;
$client set-interval-generator $tmp
$client set-page-generator $pgp

# Schedule events

$ns rtmodel-at 3 down $lrmon3 $lmcrt1
$ns rtmodel-at 7 up $lrmon3 $lmcrt1
set startTime 1
set finishTime 9
$ns at $startTime "start-connection"
$ns at $finishTime "finish"
$ns at 10 "finish2"
proc start-connection {} {
                global ns server cache client
                $client connect $cache
                $cache connect $server
                $client start-session $cache $server}
proc finish2 {} {
                global ns log
                $ns flush-trace
                flush $log
                close $log}
$ns at 22 "finish"
$ns run