-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest2.py
68 lines (55 loc) · 1.75 KB
/
test2.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
import os
import sys
import matplotlib.pyplot as plt
class TraceStringFormat:
def __init__(self, line):
self.event = line[0]
self.time = float(line[1])
self.fromNode = int(line[2])
self.toNode = int(line[3])
self.type = line[4]
self.size = int(line[5])
self.flags = FlagsFormat(line[6])
self.flowID = int(line[7])
self.source = line[8]
self.destination = line[9]
self.sequenceNumber = int(line[10])
self.packetID = int(line[11])
class FlagsFormat:
def __init__(self, flags):
self.flag1 = flags[0]
self.flag2 = flags[1]
self.flag3 = flags[2]
self.flag4 = flags[3]
self.flag5 = flags[4]
self.flag6 = flags[5]
self.flag7 = flags[6]
traceList = []
with open('iz.tr', 'r') as inputFile: # open file
while True:
line = inputFile.readline().strip('\n').split(' ') # readline and split
if (line == ['']): # check end of file
break
traceString = TraceStringFormat(line) # format line
traceList.append(traceString) # add formatted line to list
x, y = [], []
total_sent_packets = 0
total_received_packets = 0
for packet in traceList:
if packet.type == "tcp" or packet.type == "ack":
if packet.event == "+":
total_sent_packets += 1
elif packet.event == "r":
total_received_packets += 1
x.append(packet.time)
y.append(total_received_packets/total_sent_packets*100)
# plotting the points
plt.plot(x, y)
# naming the x axis
plt.xlabel('Zaman')
# naming the y axis
plt.ylabel('Paket Teslim Oranı (%)')
# giving a title to my graph
plt.title('Paket Teslim Oranı (PDF) Dağılımı')
# function to show the plot
plt.show()