Skip to content

Commit 61cd98f

Browse files
committed
Added missing files
1 parent 53beda1 commit 61cd98f

3 files changed

Lines changed: 247 additions & 0 deletions

File tree

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import json
2+
import os
3+
import re
4+
import sys
5+
6+
7+
fileid = sys.argv[1]
8+
filedir = os.getcwd()
9+
10+
11+
def get_list_of_filenames():
12+
file_list = []
13+
for file in os.listdir(filedir):
14+
if file.startswith("tcptesttrafficclient") and file.endswith("%s.txt" % (fileid)):
15+
file_list.append(file)
16+
return file_list
17+
18+
19+
def process_files(file_list):
20+
out = {}
21+
for file in file_list:
22+
out[file] = get_test_results(file)
23+
return out
24+
25+
26+
def get_test_results(file):
27+
"""
28+
For a given test output file, return a tuple of the following format
29+
(bandwidth_loss dict wth keys interval_time, transferred, bandwidth,
30+
jitter, loss_datagram, total_datagram, loss_percent)
31+
"""
32+
33+
bandwidth_stats = \
34+
{'interval_time': '', # NOQA
35+
'transferred': '', # NOQA
36+
'bandwidth': '', # NOQA
37+
'retr': ''} # NOQA
38+
reportflag = False
39+
f = open(file, 'r')
40+
for line in f:
41+
if "- - " in line:
42+
reportflag = True
43+
if "[ ID]" in line and reportflag:
44+
report = f.next()
45+
report_data = report.split(']')[1].split(' ')
46+
# also want packets transmitted, packets received, % packet loss
47+
if str(report_data[2]) == 'sec':
48+
interval_time = str(report_data[1]) + " " + str(report_data[2])
49+
transferred = str(report_data[3])
50+
bandwidth = str(report_data[4])
51+
if report_data[5] == '':
52+
retr = str(report_data[5]) + str(report_data[6]) # NOQA
53+
else:
54+
retr = str(report_data[5])
55+
else:
56+
interval_time = str(report_data[1])
57+
transferred = str(report_data[2])
58+
bandwidth = str(report_data[3])
59+
if report_data[4] == '':
60+
retr = str(report_data[4]) + str(report_data[5]) # NOQA
61+
else:
62+
retr = str(report_data[4])
63+
64+
bandwidth_stats = \
65+
{'interval_time': interval_time, # NOQA
66+
'transferred': transferred, # NOQA
67+
'bandwidth': bandwidth, # NOQA
68+
'retr': retr} # NOQA
69+
70+
test_results = {'bandwidth_stats': bandwidth_stats}
71+
72+
return test_results
73+
74+
75+
def main():
76+
file_list = get_list_of_filenames()
77+
script_output = process_files(file_list)
78+
json_output = json.JSONEncoder().encode(script_output)
79+
# sample output
80+
# {'test.txt': ({'packet_loss': '0%'},
81+
# {'rtt_min': '4.3', 'rtt_avg': '5.5', 'rtt_max': '6.3'})}
82+
print json_output
83+
84+
if __name__ == '__main__':
85+
main()
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import json
2+
import os
3+
import re
4+
import sys
5+
6+
7+
fileid = sys.argv[1]
8+
filedir = os.getcwd()
9+
10+
11+
def get_list_of_filenames():
12+
file_list = []
13+
for file in os.listdir(filedir):
14+
if file.startswith("udptesttrafficclient") and file.endswith("%s.txt" % (fileid)):
15+
file_list.append(file)
16+
return file_list
17+
18+
19+
def process_files(file_list):
20+
out = {}
21+
for file in file_list:
22+
out[file] = get_test_results(file)
23+
return out
24+
25+
26+
def get_test_results(file):
27+
"""
28+
For a given test output file, return a tuple of the following format
29+
(bandwidth_loss dict wth keys interval_time, transferred, bandwidth,
30+
jitter, loss_datagram, total_datagram, loss_percent)
31+
"""
32+
bandwidth_stats = \
33+
{'interval_time': '', # NOQA
34+
'transferred': '', # NOQA
35+
'bandwidth': '', # NOQA
36+
'jitter': '', # NOQA
37+
'loss_datagram': '', # NOQA
38+
'total_datagram': '', # NOQA
39+
'loss_percent': ''}
40+
41+
reportflag = False
42+
f = open(file, 'r')
43+
44+
for line in f:
45+
if "- - " in line:
46+
reportflag = True
47+
if "[ ID]" in line and reportflag:
48+
report = f.next()
49+
report_data = report.split(']')[1].split(' ')
50+
# also want packets transmitted, packets received, % packet loss
51+
datagram = report.split('/')[2]
52+
total_datagram = datagram.split('(')[0]
53+
loss_percent = datagram.split('(')[1].split('%')[0]
54+
if str(report_data[2]) == 'sec':
55+
interval_time =str(report_data[1]) + " " + str(report_data[2])
56+
loss_datagram = report_data[6].split('/')[0]
57+
else:
58+
interval_time =str(report_data[1])
59+
loss_datagram = report_data[5].split('/')[0]
60+
bandwidth_stats = \
61+
{'interval_time': interval_time, # NOQA
62+
'transferred': str(report_data[3]), # NOQA
63+
'bandwidth': str(report_data[4]), # NOQA
64+
'jitter': str(report_data[5]), # NOQA
65+
'loss_datagram': str(loss_datagram), # NOQA
66+
'total_datagram': str(total_datagram), # NOQA
67+
'loss_percent': str(loss_percent)}
68+
69+
test_results = {'bandwidth_stats': bandwidth_stats}
70+
71+
return test_results
72+
73+
74+
def main():
75+
file_list = get_list_of_filenames()
76+
script_output = process_files(file_list)
77+
json_output = json.JSONEncoder().encode(script_output)
78+
# sample output
79+
# {'test.txt': ({'packet_loss': '0%'},
80+
# {'rtt_min': '4.3', 'rtt_avg': '5.5', 'rtt_max': '6.3'})}
81+
print json_output
82+
83+
if __name__ == '__main__':
84+
main()
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import json
2+
import os
3+
import re
4+
import sys
5+
6+
7+
fileid = sys.argv[1]
8+
filedir = os.getcwd()
9+
10+
11+
def get_list_of_filenames():
12+
file_list = []
13+
for file in os.listdir(filedir):
14+
if file.startswith("test") and file.endswith("%s.txt" % (fileid)):
15+
file_list.append(file)
16+
return file_list
17+
18+
19+
def process_files(file_list):
20+
out = {}
21+
for file in file_list:
22+
out[file] = get_test_results(file)
23+
return out
24+
25+
26+
def get_test_results(file):
27+
"""
28+
For a given test output file, return a tuple of the following format
29+
(packet_loss dict wth keys packet_loss,
30+
rtt dictionary with keys, rtt_min, rtt_avg, rtt_max)
31+
"""
32+
f = open(file, 'r')
33+
34+
rtt_regex = ".*= (?P<rtt_min>[0-9]+\.[0-9]+)/" \
35+
"(?P<rtt_avg>[0-9]+\.[0-9]+)/" \
36+
"(?P<rtt_max>[0-9]+\.[0-9]+) ms"
37+
38+
packet_loss_regex = "(?P<packets_sent>[0-9]+) packets transmitted, " \
39+
"(?P<packets_received>[0-9]+) packets received," \
40+
" (?P<packet_loss>[0-9]+)%.*"
41+
42+
for line in f:
43+
if "loss" in line:
44+
# also want packets transmitted, packets received, % packet loss
45+
packet_stats_match = re.match(packet_loss_regex, line)
46+
47+
packet_stats = \
48+
{'packets_transmitted': int(packet_stats_match.group('packets_sent')), # NOQA
49+
'packets_received': int(packet_stats_match.group('packets_received')), # NOQA
50+
'packet_loss': int(packet_stats_match.group('packet_loss'))}
51+
52+
if "round-trip" in line:
53+
match_results = re.match(rtt_regex, line)
54+
if (match_results is not None):
55+
rtt_min = match_results.group('rtt_min')
56+
rtt_avg = match_results.group('rtt_avg')
57+
rtt_max = match_results.group('rtt_max')
58+
59+
rtt = {'rtt_min': rtt_min,
60+
'rtt_avg': rtt_avg,
61+
'rtt_max': rtt_max}
62+
63+
test_results = {'packet_stats': packet_stats, 'rtt': rtt}
64+
65+
return test_results
66+
67+
68+
def main():
69+
file_list = get_list_of_filenames()
70+
script_output = process_files(file_list)
71+
json_output = json.JSONEncoder().encode(script_output)
72+
# sample output
73+
{'test.txt': ({'packet_loss': '0%'},
74+
{'rtt_min': '4.3', 'rtt_avg': '5.5', 'rtt_max': '6.3'})}
75+
print json_output
76+
77+
if __name__ == '__main__':
78+
main()

0 commit comments

Comments
 (0)