Vous êtes sur la page 1sur 8

LAPORAN praktikum jaringan dan computer

SIMULASI NS2 THROUGHPUT

Oleh :
Rahmad Hidayat (14050874021)

JURUSAN TEKNIK ELEKTRO


FAKULTAS TEKNIK
UNIVERSITAS NEGERI SURABAYA
2015/2016

A. Script Simulasi
set ns [new Simulator]
#Define different colors for data flow (for nam)
$ns color 1 Blue
$ns color 2 Red
#membuka trace file
set tracefile1 [open out.tr w]
set winfile [open Winfile w]
$ns trace-all $tracefile1
set f0 [open FTP.tr w]
set f1 [open CBR.tr w]

#membuka open trace file


set namfile [open out.nam w]
$ns namtrace-all $namfile
#Define a 'finish' procedure
proc finish {} {
global ns tracefile1 namfile f0 f1
$ns flush-trace
close $tracefile1
close $namfile
close $f0
close $f1
exec nam out.nam &
exec xgraph FTP.tr CBR.tr -geometry 800x400 &
exit 0
}
#membuat 6 node
set n0 [$ns node]

set n1 [$ns node]


set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
set n6 [$ns node]
#memberi hubungan untuk setiap node
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns duplex-link $n2 $n6 0.3Mb 100ms DropTail
$ns duplex-link $n6 $n3 0.1Mb 100ms DropTail
$ns duplex-link $n3 $n4 5Mb 40ms DropTail
$ns duplex-link $n3 $n5 5Mb 30ms DropTail
#memberi posisi pada node
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n6 orient right
$ns duplex-link-op $n6 $n3 orient right
$ns duplex-link-op $n3 $n4 orient right-up
$ns duplex-link-op $n3 $n5 orient right-down
#Set Queue Size of link
$ns queue-limit $n2 $n6 10
$ns queue-limit $n6 $n3 2
proc attach-expoo-traffic { node sink size burst idle rate } {
#Get an instance of the simulator
set ns [Simulator instance]
#Create a UDP agent and attach it to the node
set source [new Agent/UDP]
$ns attach-agent $node $source

#Create an Expoo traffic agent and set its configuration parameters


set traffic [new Application/Traffic/Exponential]
$traffic set packetSize_ $size
$traffic set burst_time_ $burst
$traffic set idle_time_ $idle
$traffic set rate_ $rate
# Attach traffic source to the traffic generator
$traffic attach-agent $source
#Connect the source and the sink
$ns connect $source $sink
return $traffic
}
set sink0 [new Agent/LossMonitor]
set sink1 [new Agent/LossMonitor]
$ns attach-agent $n4 $sink0
$ns attach-agent $n5 $sink1

set source0 [attach-expoo-traffic $n0 $sink0 200 2s 1s 100]


set source1 [attach-expoo-traffic $n1 $sink1 200 2s 1s 100]

proc record {} {
global sink0 sink1 f0 f1
#Get an instance of the simulator
set ns [Simulator instance]
#Set the time after which the procedure should be called again
set time 0.5
#How many bytes have been received by the traffic sinks?
set bw0 [$sink0 set bytes_]

set bw1 [$sink1 set bytes_]


#Get the current time
set now [$ns now]
#Calculate the bandwidth (in MBit/s) and write it to the files
puts $f0 "$now [expr $bw0/$time/8]"
puts $f1 "$now [expr $bw1/$time/8]"
#Reset the bytes_ values on the traffic sinks
$sink0 set bytes_ 0
$sink1 set bytes_ 0
#Re-schedule the procedure
$ns at [expr $now+$time] "record"}
#Set 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
#Setup UDP connection
set udp [new Agent/UDP]
$ns attach-agent $n1 $udp
set null [new Agent/Null]
$ns attach-agent $n5 $null
$ns connect $udp $null
$udp set fid 2

#Setup a CBR over UDP connection


set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set packetSize_ 1000
$cbr set rate_ 0.01Mb
$cbr set random_ false
$ns at 0.1 "$cbr start"
$ns at 1.0 "$ftp start"
$ns at 124.0 "$ftp stop"
$ns at 124.5 "$cbr stop"
$ns at 0.0 "record"
$ns at 1.0 "$source0 start"
$ns at 0.1 "$source1 start"
$ns at 124 "$source0 stop"
$ns at 124.5 "$source1 stop"
$ns at 125 "finish"
# Procedure for plotting window size. Gets as arguments the name
# of the tcp source node (called "tcpSource") and of 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

B. Perhitungan dari throughput


Paket data yang dikirim/persatuan waktu:
N0 ke n2 = 2mb/10ms=2000/0,01=200000bit/8=25000byte
N1 ke n2 = 2mb/10ms=2000/0,01=200000bit/8=25000byte
N2 ke n6=0,3mb/100ms=300/0,1=3000bit/8=375byte
N6 ke n3=0,1mb/100ms=100/0,1=1000bit/8=125byte
N3 ke n4=5mb/40ms=5000/0,04=125000bit/8=15625byte
N3 ke n5=5mb/30ms=5000/0,03=166666bit/8=20833,3byte

B. Hasil Simulasi Dalam Bentuk Grafik

C. Hasil simulasi Dalam Bnetuk Grafik

Keterangan : Grafik Throughput CBR (Hijau) Dan FTP


(Merah)

Vous aimerez peut-être aussi