Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # инициализация NS2
- set ns [new Simulator]
- set nf [open out.nam w]
- $ns namtrace-all $nf
- set f [open out.tr w]
- $ns trace-all $f
- proc finish {} {
- global ns f nf
- $ns flush-trace
- close $f
- close $nf
- exec nam out.nam &
- exit 0
- }
- #=======================
- set N 4
- set red_node [$ns node]
- set target_node [$ns node]
- for {set i 0} {$i < $N } {incr i} {
- set n($i) [$ns node]
- }
- #=======================
- $ns duplex-link $red_node $target_node $N\\Mb 20ms RED
- $ns queue-limit $red_node $target_node [expr $N * 10 ]
- #=======================
- for {set i 0} {$i < $N } {incr i} {
- $ns duplex-link $n($i) $red_node 1Mb 10ms DropTail
- }
- #=======================
- set sink [new Agent/TCPSink]
- $ns attach-agent $target_node $sink
- set null [new Agent/Null]
- $ns attach-agent $target_node $null
- #=======================
- set udp [$ns create-connection UDP $n(0) Null $target_node 0]
- set cbr [new Application/Traffic/CBR]
- $cbr attach-agent $udp
- $cbr set packetSize_ 1024
- $cbr set rate_ 1Mbps
- #=======================
- for {set i 1} {$i < $N} {incr i} {
- set tcp($i) [$ns create-connection TCP/Reno $n($i) TCPSink $target_node 0]
- set ftp($i) [$tcp($i) attach-source FTP]
- }
- #=======================
- for {set i 1} {$i < $N} {incr i} {
- $ns at 0.0 "$ftp($i) start"
- }
- $ns at 0.0 "$cbr start"
- $ns at 5.0 "finish"
- $ns run
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement