You are on page 1of 7

IT315

14IT066

Practical: 9
Aim : Simulate the below scenario and find out value of ?? i.e. there is no packet drop
prove it by supporting graph.

Set the following parameters for application traffic.


ftp0:

Packet size: 1000

Rate : 1

Interval: 150

CBR1:

Packet size: 1500

Rate : 0.05

Interval : 150

Total Simulation: 60 sec.

CSPIT 1
IT315
14IT066

Program:

set ns [new Simulator]

$ns color 1 Blue


$ns color 2 Red

set nf [open 14IT066.nam w]


$ns namtrace-all $nf
set tf [open 14IT066.tr w]
$ns trace-all $tf
proc finish {} {
global ns nf
global tf
$ns flush-trace
close $nf
close $tf
#exec nam 14IT066.nam &
exit 0
}
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]

#n0 to n2
$ns duplex-link $n0 $n2 10.0Mb 10ms SFQ
$ns queue-limit $n0 $n2 50
#n1 to n2
$ns duplex-link $n1 $n2 10.0Mb 10ms SFQ
$ns queue-limit $n1 $n2 50
#n2 to n3
$ns duplex-link $n2 $n3 5.0Mb 10ms SFQ
$ns queue-limit $n2 $n3 50
#n3 to n4
$ns duplex-link $n3 $n4 10.0Mb 10ms SFQ
$ns queue-limit $n3 $n4 50
#n3 to n5
$ns duplex-link $n3 $n5 10.0Mb 10ms SFQ
$ns queue-limit $n3 $n5 50

$ns duplex-link-op $n2 $n0 orient left-up


$ns duplex-link-op $n2 $n1 orient left-down
$ns duplex-link-op $n2 $n3 orient right
$ns duplex-link-op $n3 $n4 orient right-up

CSPIT 2
IT315
14IT066

$ns duplex-link-op $n3 $n5 orient right-down

set tcp [new Agent/TCP]


$ns attach-agent $n0 $tcp
$tcp set class_ 1

set ftp [new Application/FTP]


$ftp attach-agent $tcp
$ftp set type_ FTP
$ftp set packetSize_ 1000
$ftp set rate_ 1mb
$ftp set interval_ 150
$ftp set fid_ 1

set tcp0 [new Agent/TCP]


$ns attach-agent $n0 $tcp0
$tcp0 set class_ 2

set ftp0 [new Application/FTP]


$ftp0 attach-agent $tcp0
$ftp0 set type_ FTP
$ftp0 set packetSize_ 1000
$ftp0 set rate_ 1mb
$ftp0 set interval_ 150
$ftp0 set fid_ 2

set sink [new Agent/TCPSink]


$ns attach-agent $n4 $sink
$ns connect $tcp $sink

set sink0 [new Agent/TCPSink]


$ns attach-agent $n5 $sink0
$ns connect $tcp0 $sink0

$ns at 0.1 "$ftp start"


$ns at 1.0 "$ftp0 start"
$ns at 55 "$ftp0 stop"
$ns at 55.5 "$ftp stop"
$ns at 60.0 "finish"
$ns run

Output:

CSPIT 3
IT315
14IT066

AWK Script:
BEGIN{
a=0;
b=0;
}{
if( $1 == "r" ){
a=a+1;
}
else if( $1 == "d" ){
b=b+1;
}
}
END{
print "files received:" a;
print "files dropped:" b;
}

Output :

CSPIT 4
IT315
14IT066
Jitter.awk Script:

BEGIN {
recvdSize = 0
startTime = 1e6
stopTime = 0
r=0;
}
{
event = $1
time = $2
flow_id = $8
pkt_id = $12
pkt_size = $6
flow_t = $5

if (event == "+" || event == "s") {


if (time < startTime) {
startTime = time
}
sendTime[pkt_id] = time
this_flow = flow_t
}

if (event == "r" ) {
if (time > stopTime) {
stopTime = time

r++;
recvdSize += pkt_size

recvTime[pkt_id] = time
}

END {

delay = avg_delay = recvdNum = 0


for (i in recvTime) {
if (sendTime[i] == 0) {
printf("\nError in delay.awk: receiving a packet that wasn't sent
%g\n",i)
}
delay += recvTime[i] - sendTime[i]
recvdNum ++
}

CSPIT 5
IT315
14IT066
if (recvdNum != 0) {
avg_delay = delay / r
} else {
avg_delay = 0
}

jitter1 = 0
prev_time = delay = prev_delay = 0
prev_delay = -1
for (i=0; i<r; i++) {
if(recvTime[i] != 0) {
if(prev_time != 0) {
delay = recvTime[i] - prev_time
e2eDelay = recvTime[i] - sendTime[i]
if(delay < 0) delay = 0
if(prev_delay != -1) {
jitter1 += abs(e2eDelay - prev_e2eDelay)

}
prev_delay = delay
prev_e2eDelay = e2eDelay
}
prev_time = recvTime[i]

}
}
if (recvdNum != 0) {
jitter1 = jitter1*1000/r

printf("\n")
printf(" %15s: %f\n", "startTime", startTime)
printf(" %15s: %f\n", "stopTime", stopTime)
printf(" %15s: %g\n", "receivedPkts", r)
printf(" %15s: %g\n", "avgJitter[ms]", jitter1)

function abs(value) {
if (value < 0) value = 0-value
return value
}

CSPIT 6
IT315
14IT066
Output:

Xgraph file:

TitleText: Drop vs Queue


XUnitText: Queue Size
YUnitText: DropPackets

"SQF"

20 40
30 40
50 40
60 40
80 40

Xgraph:

Conclusion:
In this practical, weve learnt different type of queueing mechanism.

CSPIT 7

You might also like