add support of analyzing tcpdump for UDP and offloading

also bug fix, and use new standard MB, KB, Bytes conversion,
This commit is contained in:
HappyZ 2017-02-22 06:15:39 -08:00
parent 710fbcea30
commit c798645414
2 changed files with 31 additions and 14 deletions

View File

@ -37,11 +37,14 @@ def checkFiles(folderpath, timestamp):
if __name__ == "__main__": if __name__ == "__main__":
DEBUG = True DEBUG = True
logger = EmptyLogger("App", isDebugging=DEBUG, printout=True) logger = EmptyLogger("App", isDebugging=DEBUG, printout=True)
remoteIP = '192.168.10.1' # remoteIP = '128.111.68.220'
remoteIP = '192.168.2.1'
# sizeOptions = [1, 5, 10, 20, 50, 100] # MB # sizeOptions = [1, 5, 10, 20, 50, 100] # MB
sizeOptions = [None] # MB sizeOptions = [None] # MB
# folder = sys.argv[1] # folder = sys.argv[1]
folder = './models/test2/' # folder = './models/bypass/120MBps/'
folder = '/Users/yanzi/GDrive/UCSB/Projects/Offloading_2017/Data/' +\
'initial_comparison/udp_mtu20k/160Mbps'
# check if is folder # check if is folder
if os.path.isdir(folder): if os.path.isdir(folder):
files = [x for x in os.listdir(folder) if '.cpuRaw' in x] files = [x for x in os.listdir(folder) if '.cpuRaw' in x]
@ -63,17 +66,21 @@ if __name__ == "__main__":
logger.debug(status) logger.debug(status)
for size_limit in sizeOptions: for size_limit in sizeOptions:
if size_limit is not None: if size_limit is not None:
size_limit = size_limit * 1024 * 1024 size_limit = size_limit * 1000 * 1000
# myAnalyzer.clean_up_cpu() # myAnalyzer.clean_up_cpu()
# myAnalyzer.clean_up_net() # myAnalyzer.clean_up_net()
# parse wifi # parse wifi
if 'tcpdump' in status: if 'tcpdump' in status:
logger.debug('reading tcpdump...') logger.debug('reading tcpdump...')
if 'bypass' in folder:
myfilter = ""
else:
myfilter = "host {0}".format(remoteIP)
myAnalyzer.read_wifi_log( myAnalyzer.read_wifi_log(
status['tcpdump'], status['tcpdump'],
size_limit=size_limit, size_limit=size_limit,
fp_sslogger=status['ss'], fp_sslogger=status['ss'],
tcpdump_filter="host {0}".format(remoteIP)) tcpdump_filter=myfilter)
logger.debug('analyzing tcpdump...') logger.debug('analyzing tcpdump...')
myAnalyzer.parse_wifi_energy() myAnalyzer.parse_wifi_energy()
# parse cpu # parse cpu

View File

@ -299,7 +299,12 @@ class EnergyAnalyzer():
'Flags \[([\w\.]+)\], ack (\d+),', 'Flags \[([\w\.]+)\], ack (\d+),',
# SYN/SYNACK or FIN/FINACK packet, with one seq # SYN/SYNACK or FIN/FINACK packet, with one seq
'([\d\.]+) IP ([\d\.]+) \> ([\d\.]+): ' + '([\d\.]+) IP ([\d\.]+) \> ([\d\.]+): ' +
'Flags \[([\w\.]+)\], seq (\d+),'] 'Flags \[([\w\.]+)\], seq (\d+),',
# UDP
'([\d\.]+) IP ([\d\.]+) \> ([\d\.]+): ' +
'UDP, length (\d+)',
# offloading
'([\d\.]+) IP0 bad-hlen 0']
with open(fp_tcpdump, 'rU') as f: with open(fp_tcpdump, 'rU') as f:
content = f.readlines() content = f.readlines()
firstLine = True firstLine = True
@ -325,7 +330,12 @@ class EnergyAnalyzer():
# else: # else:
# data_type = 'seq' # data_type = 'seq'
data_len = 0 data_len = 0
if len(tmp) > 5: if len(tmp) > 5 or pattern_i > 2:
if pattern_i == 3: # UDP
data_len = int(tmp[3])
elif pattern_i == 4: # offloading
data_len = 1488
else:
data_len = int(tmp[5]) - int(tmp[4]) data_len = int(tmp[5]) - int(tmp[4])
total_bytes += data_len total_bytes += data_len
# self.logger.debug("{0}".format(total_bytes)) # self.logger.debug("{0}".format(total_bytes))
@ -538,8 +548,8 @@ class EnergyAnalyzer():
f.write(',wifi_energy(mJ),wifi_time(s),avg_wifi_pwr(mW),' + f.write(',wifi_energy(mJ),wifi_time(s),avg_wifi_pwr(mW),' +
'wifi_active_energy(mJ),wifi_idle_energy(mJ)') 'wifi_active_energy(mJ),wifi_idle_energy(mJ)')
f.write('\n') f.write('\n')
f.write('{0:.2f},'.format(self.data_size / 1048576.0)) f.write('{0:.2f},'.format(self.data_size / 1000000.0))
f.write('{0:.2f},'.format(self.wifi_avg_thrpt / 1048576.0 * 8)) f.write('{0:.2f},'.format(self.wifi_avg_thrpt / 1000000.0 * 8))
f.write('{0:.8f},{1:.8f},{2:.8f},'.format( f.write('{0:.8f},{1:.8f},{2:.8f},'.format(
total_energy, total_time, avg_power)) total_energy, total_time, avg_power))
f.write('{0:.8f}'.format(self.avg_log_freq)) f.write('{0:.8f}'.format(self.avg_log_freq))
@ -588,7 +598,7 @@ class EnergyAnalyzer():
# now generate instant wifi thrpt # now generate instant wifi thrpt
if wifi and self.output_path is not None: if wifi and self.output_path is not None:
fn = "{0}/result_wifi_instant_{1:.2f}MB{2}.csv".format( fn = "{0}/result_wifi_instant_{1:.2f}MB{2}.csv".format(
self.output_path, self.data_size / 1048576.0, f_suffix) self.output_path, self.data_size / 1000000.0, f_suffix)
f = open(fn, 'wb') f = open(fn, 'wb')
# description # description
f.write('#time(s),time_delta(s),throughput(Mbps)\n') f.write('#time(s),time_delta(s),throughput(Mbps)\n')
@ -597,7 +607,7 @@ class EnergyAnalyzer():
self.wifi_instant_thrpt[i][0], self.wifi_instant_thrpt[i][0],
self.wifi_instant_thrpt[i][0] - self.wifi_instant_thrpt[i][0] -
self.wifi_instant_thrpt[0][0], self.wifi_instant_thrpt[0][0],
self.wifi_instant_thrpt[i][1] / 1048576.0 * 8)) self.wifi_instant_thrpt[i][1] / 1000000.0 * 8))
# f.write('{0:.2f},{1:.2f},{2:.2f}\n'.format( # f.write('{0:.2f},{1:.2f},{2:.2f}\n'.format(
# self.wifi_instant_thrpt[-1][0], # self.wifi_instant_thrpt[-1][0],
# self.wifi_instant_thrpt[-1][0] - # self.wifi_instant_thrpt[-1][0] -
@ -609,7 +619,7 @@ class EnergyAnalyzer():
# now generate instant cpu # now generate instant cpu
if cpu and self.output_path is not None: if cpu and self.output_path is not None:
fn = "{0}/result_cpu_instant_{1:.2f}MB{2}.csv".format( fn = "{0}/result_cpu_instant_{1:.2f}MB{2}.csv".format(
self.output_path, self.data_size / 1048576.0, f_suffix) self.output_path, self.data_size / 1000000.0, f_suffix)
f = open(fn, 'wb') f = open(fn, 'wb')
# description # description
num_of_cores = len(self.instant_freqs[0]) num_of_cores = len(self.instant_freqs[0])
@ -646,7 +656,7 @@ if __name__ == "__main__":
output_path="./models/test2/") output_path="./models/test2/")
myObj.read_wifi_log( myObj.read_wifi_log(
tcpdumpFile, tcpdumpFile,
size_limit=None, # 1024*1024*90, size_limit=None, # 1000*1000*90,
fp_sslogger=ssFile, tcpdump_filter="host 192.168.10.1") fp_sslogger=ssFile, tcpdump_filter="host 192.168.10.1")
myObj.parse_wifi_energy() myObj.parse_wifi_energy()
myObj.read_cpu_log( myObj.read_cpu_log(