-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththesis_utils.py
96 lines (82 loc) · 3.82 KB
/
thesis_utils.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
85
86
87
88
89
90
91
92
93
94
95
96
#from scipy.stats import zipf
def get_node_IPs_from_as_file():
f = open(r'C:/Users/Colleen/Documents/thesis/GNRS-DOS/as-listing.txt')
for line in f:
splitLine = line.split(" ")
print(splitLine[1]+":5000")
f.close()
# parses per-message level server log, outputs csv for excel
def parse_server_log():
f = open(r'C:/Users/Colleen/Documents/thesis/GNRS-DOS/4attackfreq_july29/gnrsd_target.log')
out = open(r'C:/Users/Colleen/Documents/thesis/GNRS-DOS/4attackfreq_july29/server_log.csv', 'w')
out.write(" , date,rtt(ns),GUID,type,seq#,success/fail\n ,") # first line is de-dented in excel csv
lastLine = None
for line in f:
if "0.000 per second" in line or "Outstanding responses: 0" in line or "DEBUG" in line:
lastLine = None
continue #skip this line
# date , time, seconds, log level, nothing, NioDatagramAcceptor-1/TraceClient,
# - , ns time, GUID, ->, INR, REQ#/[SUCCESS||FAILED]
else:
splitLine = line.split(" ")
if lastLine != None:
splitLine = [lastLine] + splitLine
lastLine = None
elif len(splitLine) == 1 and ("==Lookups==" in splitLine[0] or "==Inserts==" in splitLine[0]):
lastLine = splitLine[0]
continue
for chunk in splitLine:
if "," in chunk:
chunk = chunk.replace(",","")
# if chunk == "INFO" or chunk == "-" or chunk == "->" or chunk == "" or chunk == "NioDatagramAcceptor-1/TraceClient":
# continue
# if "[" in chunk:
# chunk = chunk.replace("[", "")
# chunk = chunk.replace("]","")
# if "ns]" in chunk:
# chunk = chunk.replace("ns]", "")
# chunk = chunk.replace(",", "")
#if "," in chunk:
# continue # skip timestamp
#if "/" in chunk:
# chunk = chunk.replace("#", "") #get rid of number sign
# splitChunk = chunk.split("/")
# chunk = splitChunk[0] + "," + splitChunk[1]
out.write(chunk)
out.write(",")
f.close()
# parses per-message level client log, outputs csv for excel
def parse_client_log():
f = open(r'C:/Users/Colleen/Documents/thesis/GNRS-DOS/results/client.log')
out = open(r'C:/Users/Colleen/Documents/thesis/GNRS-DOS/results/client_log.csv', 'w')
out.write(" , date,rtt(ns),GUID,type,seq#,success/fail\n ,") # first line is de-dented in excel csv
for line in f:
splitLine = line.split(" ")
# date , time, seconds, log level, nothing, NioDatagramAcceptor-1/TraceClient,
# - , ns time, GUID, ->, INR, REQ#/[SUCCESS||FAILED]
if len(splitLine) == 11: #formatted like a individual message log
for chunk in splitLine:
if chunk == "INFO" or chunk == "-" or chunk == "->" or chunk == "" or chunk == "NioDatagramAcceptor-1/TraceClient":
continue
if "[" in chunk:
chunk = chunk.replace("[", "")
if "ns]" in chunk:
chunk = chunk.replace("ns]", "")
chunk = chunk.replace(",", "")
if "," in chunk:
continue # skip timestamp
if "/" in chunk:
chunk = chunk.replace("#", "") #get rid of number sign
splitChunk = chunk.split("/")
chunk = splitChunk[0] + "," + splitChunk[1]
out.write(chunk)
out.write(",")
f.close()
### ZIPF ###
def get_zipf(num_samples):
N = 1000 # number of GUIDs
k = 0 # rank of GUID
a = 1.02 # skewness
q = 100 # flatness
r = zipf.rvs(a, size=num_samples)
print(r)