Sliding Window  ns script


# sliding window protocol in congestion
# features : labeling, annotation, nam-graph, and window size monitoring

set ns [new Simulator]

$ns color 1 red

$ns trace-all [open B4-sliding-window-loss.tr w]
$ns namtrace-all [open B4-sliding-window-loss.nam w]

### build topology with 6 nodes
proc build_topology { ns } {

 global node_

 set node_(s1) [$ns node]
        set node_(s2) [$ns node]
        set node_(r1) [$ns node]
        set node_(r2) [$ns node]
        set node_(s3) [$ns node]
        set node_(s4) [$ns node]

        $node_(s2) color "red"
        $node_(s4) color "red"

        $node_(r1) color "blue"
        $node_(r2) color "blue"
 $node_(r1) shape "rectangular"
        $node_(r2) shape "rectangular"

        $ns at 0.0 "$node_(s1) label Sliding-W-sender"
        $ns at 0.0 "$node_(s2) label CBR-sender"
        $ns at 0.0 "$node_(s3) label Sliding-W-receiver"
        $ns at 0.0 "$node_(s4) label CBR-receiver"

 $ns duplex-link $node_(s1) $node_(r1) 0.5Mb 50ms DropTail
        $ns duplex-link $node_(s2) $node_(r1) 0.5Mb 50ms DropTail
        $ns duplex-link $node_(r1) $node_(r2) 0.5Mb 50ms DropTail
        $ns duplex-link $node_(r2) $node_(s3) 0.5Mb 50ms DropTail
        $ns duplex-link $node_(r2) $node_(s4) 0.5Mb 50ms DropTail

 $ns queue-limit $node_(r1) $node_(r2) 10
        $ns queue-limit $node_(r2) $node_(r1) 10

 $ns duplex-link-op $node_(s1) $node_(r1) orient right-down
        $ns duplex-link-op $node_(s2) $node_(r1) orient right-up
        $ns duplex-link-op $node_(r1) $node_(r2) orient right
        $ns duplex-link-op $node_(r2) $node_(s3) orient right-up
        $ns duplex-link-op $node_(r2) $node_(s4) orient right-down

        $ns duplex-link-op $node_(r1) $node_(r2) queuePos 0.5
        $ns duplex-link-op $node_(r2) $node_(r1) queuePos 0.5

}

build_topology $ns

Agent/TCP set nam_tracevar_ true

### sliding-window protocol between s1 and s3 (Black)

set tcp [$ns create-connection TCP $node_(s1) TCPSink $node_(s3) 0]

set ftp [$tcp attach-app FTP]

$ns add-agent-trace $tcp tcp
$ns monitor-agent-trace $tcp
$tcp tracevar cwnd_
$tcp tracevar ssthresh_

### CBR traffic between s2 and s4 (Red)
set cbr [$ns create-connection CBR $node_(s2) Null $node_(s4) 1]
$cbr set fid_ 1

proc finish {} {

 global ns
 $ns flush-trace

 puts "filtering..."
 exec tclsh ../ns-allinone-2.1b5/nam-1.0a7/bin/namfilter.tcl B4-sliding-window-loss.nam
 puts "running nam..."
 exec nam B4-sliding-window-loss.nam &
 exit 0
}

### set operations
$ns at 0.1 "$ftp start"
$ns at 2.35 "$ftp stop"
$ns at 0.1 "$cbr start"
$ns at 2.35 "$cbr stop"
$ns at 3.0 "finish"

### add annotations
$ns at 0.0 "$ns trace-annotate \"Sliding Window with packet loss    \""

$ns run