-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.py
84 lines (60 loc) · 1.68 KB
/
parser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Created for 289 project-2
# Pass the tracefile as an argument while running this parser.
import re
from sys import argv
i=0
delay=0
sent=0
recv=0
time0=0
tim1=0
t1=0
sentdict = dict()
recvdict = dict()
delaylist = []
file = open(argv[1],'r')
data = file.readlines()
for line in data:
sline = line.split(" ")
try:
if sline[0] == 's' or sline[1]=='s' :
if sline[3]=='AGT' or sline[4]=='AGT':
if sline[7]=='cbr' or sline[8]=='cbr':
sent +=1
else:
continue
elif sline[0] == 'r' or sline[1]=='r':
if sline[3]=='AGT' or sline[4]=='AGT':
if sline[7] == 'cbr' or sline[8] == 'cbr':
recv +=1
else:
continue
except:
continue
#pecentage of packet deliverd
perdelievered = float(recv)/float(sent)*100
#delay
for line in data:
sline = line.split(" ")
if sline[3] == 'AGT':
if sline[7] == 'cbr' or sline[8] == 'cbr':
if sline[0]=='s':
#seq=sline[6]
if sline[6] not in sentdict.keys():
sentdict[sline[6]]= sline[1]
elif sline[0]=='r':
if sline[6] not in recvdict.keys():
recvdict[sline[6]]= sline[1]
for item in sentdict.keys():
if item in recvdict.keys():
delaylist.append(float(recvdict[item]) - float(sentdict[item]))
i =0
delay1 = 0
for delay in delaylist:
delay1 += delay
i+=1
print "Number of packets sent:- ",sent
print "Number of packets received:- ", recv
print "Percentage of packet delivered:- ", perdelievered
#print delaylist
print "Average delay:- ",delay1/i