Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Create a simulator object
- set ns [new Simulator]
- #Define different colors for data flows (for NAM)
- $ns color 1 Blue
- $ns color 2 Red
- #Open the NAM trace file
- set nf [open out.nam w]
- $ns namtrace-all $nf
- #Define a 'finish' procedure
- proc finish {} {
- global ns nf
- $ns flush-trace
- #Close the NAM trace file
- close $nf
- #Execute NAM on the trace file
- exec nam out.nam &
- exit 0
- }
- #create four nodes
- set n0 [$ns node]
- set n1 [$ns node]
- set n2 [$ns node]
- set n3 [$ns node]
- #set labels of nodes
- $n0 label TCP
- $n1 label SINK
- #create the links
- $ns duplex-link $n0 $n1 2Mb 5ms DropTail
- $ns duplex-link $n2 $n3 2Mb 5ms DropTail
- $ns duplex-link $n0 $n3 1.5Mb 15ms RED
- $ns duplex-link $n2 $n1 1.5Mb 15ms RED
- #setting queue size of link (n0-n1) to 20
- $ns queue-limit $n0 $n1 20
- #adjust position of the nodes
- $ns duplex-link-op $n0 $n1 orient right
- $ns duplex-link-op $n0 $n3 orient right-down
- $ns duplex-link-op $n2 $n3 orient right
- $ns duplex-link-op $n2 $n1 orient right-up
- #Monitor the queue for link (n0-n1)
- $ns duplex-link-op $n0 $n1 queuePos 1
- #setup TCP agents
- set tcp0 [new Agent/TCP]
- $ns attach-agent $n0 $tcp0
- set tcp1 [new Agent/TCP]
- $ns attach-agent $n2 $tcp1
- set tcp2 [new Agent/TCP]
- $ns attach-agent $n0 $tcp2
- set tcp3 [new Agent/TCP]
- $ns attach-agent $n2 $tcp3
- #make connections
- set sink0 [new Agent/TCPSink]
- $ns attach-agent $n1 $sink0
- $ns connect $tcp0 $sink0
- set sink1 [new Agent/TCPSink]
- $ns attach-agent $n1 $sink1
- $ns connect $tcp1 $sink1
- set sink2 [new Agent/TCPSink]
- $ns attach-agent $n3 $sink2
- $ns connect $tcp2 $sink2
- set sink3 [new Agent/TCPSink]
- $ns attach-agent $n3 $sink3
- $ns connect $tcp3 $sink3
- #Setup FTP over TCP connection
- set ftp0 [new Application/FTP]
- $ftp0 attach-agent $tcp0
- set ftp1 [new Application/FTP]
- $ftp1 attach-agent $tcp1
- set ftp2 [new Application/FTP]
- $ftp2 attach-agent $tcp2
- set ftp3 [new Application/FTP]
- $ftp3 attach-agent $tcp3
- #Schedule events for FTP agents
- $ns at 0.1 "$ftp0 start"
- $ns at 5.0 "$ftp0 stop"
- $ns at 0.1 "$ftp1 start"
- $ns at 5.0 "$ftp1 stop"
- #Call the finish procedure after 5 seconds of simulation time
- $ns at 5.0 "finish"
- #Run the simulation
- $ns run
Add Comment
Please, Sign In to add comment