Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set ns [new Simulator]
- #Define different colors for data flows (for NAM)
- $ns color 1 Blue
- $ns color 2 Red
- #Open the Trace files
- set tracefile1 [open out.tr w]
- set winfile [open WinFile w]
- $ns trace-all $tracefile1
- #open the NAM file
- set namefile [open out.nam w]
- $ns namtrace-all $namefile
- #Define a finish procedure
- proc finish {} {
- global ns tracefile1 namefile
- $ns flush-trace
- close $tracefile1
- close $namefile
- exec nam out.nam &
- exit 0
- }
- #create six nodes
- set n0 [$ns node]
- set n1 [$ns node]
- set n2 [$ns node]
- set n3 [$ns node]
- set n4 [$ns node]
- set n5 [$ns node]
- #create links between the nodes
- $ns duplex-link $n0 $n2 1024Mb 10ms DropTail
- $ns duplex-link $n1 $n2 2Mb 10ms DropTail
- $ns simplex-link $n2 $n3 1024Mb 100ms DropTail
- $ns simplex-link $n3 $n2 0.3Mb 100ms DropTail
- $ns duplex-link $n3 $n4 1024Mb 40ms DropTail
- $ns duplex-link $n3 $n5 0.5Mb 30ms DropTail
- #Give node position (for NAM)
- $ns duplex-link-op $n0 $n2 orient right-down
- $ns duplex-link-op $n1 $n2 orient right-up
- $ns simplex-link-op $n2 $n3 orient right
- $ns simplex-link-op $n3 $n2 orient left
- $ns duplex-link-op $n3 $n4 orient right-up
- $ns duplex-link-op $n3 $n5 orient right-down
- #set Queue Size of link (n2-n3) to 20
- $ns queue-limit $n2 $n3 20
- #setup a TCP connection
- set tcp [new Agent/TCP]
- $ns attach-agent $n0 $tcp
- set sink [new Agent/TCPSink]
- $ns attach-agent $n4 $sink
- $ns connect $tcp $sink
- $tcp set fid_ 1
- $tcp set packetSize_ 552
- #Setup a FTP over TCP connection
- set ftp [new Application/FTP]
- $ftp attach-agent $tcp
- $ns at 1.0 "$ftp start"
- $ns at 124.0 "$ftp stop"
- #procedure for plotting window size. Gets as arguments the name
- # of the tcp source code node (called "tcpSource") and of the output file
- proc plotWindow {tcpSource file} {
- global ns
- set time 0.1
- set now [$ns now]
- set cwnd [$tcpSource set cwnd_]
- puts $file "$now $cwnd"
- $ns at [expr $now+$time] "plotWindow $tcpSource $file"
- }
- $ns at 0.1 "plotWindow $tcp $winfile"
- $ns at 125.0 "finish"
- $ns run
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement