#Tao mo phong set ns [new Simulator] #xuat ra Nam set nf [open mophong1.nam w] $ns namtrace-all $nf #mo file Trace file set tf [open mophong1.tr w] $ns trace-all $tf #Dinh nghia thu tuc "finish" proc finish {} { global ns nf tf $ns flush-trace close $nf close $tf exec nam mophong1.nam & exit 0 } #So do ket noi mang # R1--------R3 R7 # \ / # \ / # R5--------R6 # / \ # / \ # / R8 # R2--------R4 # #Tao 8 nut mang IP set R1 [$ns node] set R2 [$ns node] set R3 [$ns node] set R4 [$ns node] set R5 [$ns node] set R6 [$ns node] set R7 [$ns node] set R8 [$ns node] #Khai bao link $ns duplex-link $R1 $R3 1M 30ms DropTail $ns duplex-link $R2 $R4 1M 30sm DropTail $ns duplex-link $R3 $R5 0.3M 20ms DropTail $ns duplex-link $R4 $R5 0.3M 20ms DropTail $ns simplex-link $R5 $R6 0.5Mb 70ms DropTail $ns simplex-link $R6 $R5 0.5Mb 70ms DropTail $ns duplex-link $R6 $R7 1M 30ms DropTail $ns duplex-link $R6 $R8 1M 30ms DropTail #ve so do tren Nam $ns duplex-link-op $R1 $R3 orient right $ns duplex-link-op $R2 $R4 orient right $ns duplex-link-op $R3 $R5 orient right-down $ns duplex-link-op $R4 $R5 orient right-up $ns simplex-link-op $R5 $R6 orient right $ns simplex-link-op $R6 $R5 orient left $ns duplex-link-op $R6 $R7 orient right-up $ns duplex-link-op $R6 $R8 orient right-down #Set Queue Size of link (R5-R6) to 10 $ns queue-limit $R5 $R6 10 #Monitor the queue for link (R5-R6). (for NAM) $ns simplex-link-op $R5 $R6 queuePos 0.5 #Setup a TCP connection set tcp [new Agent/TCP/Newreno] $ns attach-agent $R1 $tcp set sink [new Agent/TCPSink/DelAck] $ns attach-agent $R7 $sink $ns connect $tcp $sink $tcp set fid_ 1 $tcp set window_ 8000 $tcp set packetSize_ 552 #Setup a FTP over TCP connection set ftp [new Application/FTP] $ftp attach-agent $tcp $ftp set type_ FTP #Setup a UDP connection set udp [new Agent/UDP] $ns attach-agent $R2 $udp set null [new Agent/Null] $ns attach-agent $R8 $null $ns connect $udp $null $udp set fid_ 2 $ns color 1 Blue $ns color 2 Red #Setup a CBR over UDP connection set cbr [new Application/Traffic/CBR] $cbr attach-agent $udp $cbr set type_ CBR $cbr set packet_size_ 1000 $cbr set rate_ 0.01mb $cbr set random_ false $ns at 0.1 "$ftp start" $ns at 1.0 "$cbr start" $ns at 5.0 "$cbr stop" $ns at 5.0 "$ftp stop" $ns at 5.5 "finish" $ns run