[951] | 1 | |
---|
| 2 | # this is a python script that parse the dualtest output into a vector of words to be used later. |
---|
| 3 | |
---|
| 4 | # it is the same process as serverudpsingle in the below box. |
---|
| 5 | ############################################### |
---|
| 6 | import re |
---|
| 7 | result = open('result.txt').readlines() |
---|
| 8 | length1 = len(result) |
---|
| 9 | import pdb |
---|
| 10 | for i in range(0, length1): |
---|
| 11 | result[i] = result[i].replace('- ', '-') |
---|
| 12 | result[i] = result[i].replace('/ ', '/') |
---|
| 13 | result[i] = result[i].replace('[','[ ') |
---|
| 14 | result[i] = result[i].replace(']',' ]') |
---|
| 15 | result[i] = result[i].replace(':',' :') |
---|
| 16 | result[i] = result[i].replace('(','( ') |
---|
| 17 | result[i] = result[i].replace(')',' )') |
---|
| 18 | for i in range(0, length1): |
---|
| 19 | result[i] = result[i].replace('-', ' ') |
---|
| 20 | result[i] = result[i].replace('/', ' ') |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | ################################################# |
---|
| 24 | |
---|
| 25 | # When checking the result of dual test, it was found that output was not parsed the same way but in possible 4 ways. |
---|
| 26 | # first i defined the number of output lines to be 20. |
---|
| 27 | start = 0 |
---|
| 28 | end = 20 |
---|
| 29 | ############################################################################################################################################################# |
---|
| 30 | # I found the outputs of iperf are not always arranged in the same format. Sometimes, server report was before client report that usually is after client report. |
---|
| 31 | # So i had to find the way the python will recognize the pattern and parse the data we need to give to the matlab. |
---|
| 32 | # it is very fundamental method. I checked a specific line's size that tells if it is the server report or client report. IN UDP server report, |
---|
| 33 | # the line contains words 'jitter, transfer, loss,total packet'. Client one contains only 'transfer bandwidth'. So i checked the size of the line. If it was |
---|
| 34 | # big, python assumeed it was a server report. It is always good to check with your eyes by running bunch of iperf -s -d at the terminal and see the pattern. |
---|
| 35 | ########################################################################################################################################################### |
---|
| 36 | |
---|
| 37 | if(len(result[12]) > 60): |
---|
| 38 | j = 13 |
---|
| 39 | elif(len(result[12]) < 60): |
---|
| 40 | if( result[17].find('Server')) != -1: |
---|
| 41 | j= 16 |
---|
| 42 | else: |
---|
| 43 | j = 17 |
---|
| 44 | ### the remainder from division of i and 20 (the number of lines) is the line where the information is stored. |
---|
| 45 | for i in range(start, end+1): |
---|
| 46 | if (i%20) == 11: |
---|
| 47 | f = open('ptmp.txt','a') |
---|
| 48 | f.write(str(result[i])+'\n') |
---|
| 49 | f.close() |
---|
| 50 | elif (i%20) == 10: |
---|
| 51 | f = open('dual_ptmp.txt','a') |
---|
| 52 | f.write(str(result[i])+'\n') |
---|
| 53 | f.close() |
---|
| 54 | elif (i%20) == j: |
---|
| 55 | f = open('rtmp.txt','a') |
---|
| 56 | f.write(str(result[i])+ '\n') |
---|
| 57 | f.close() |
---|
| 58 | elif (i%20) == 19: |
---|
| 59 | f = open('dual_rtmp.txt','a') |
---|
| 60 | f.write(str(result[i])+ '\n') |
---|
| 61 | f.close() |
---|
| 62 | |
---|
| 63 | |
---|
| 64 | ############################################################################## |
---|
| 65 | # from this line, python separates the sentence into words and store the words |
---|
| 66 | # into a vector, and save them into separate files, portadd and repnum. |
---|
| 67 | # Matlab deals with vectors better and it makes |
---|
| 68 | # the matlab users very convenient. |
---|
| 69 | ############################################################################### |
---|
| 70 | o = open('ptmp.txt').readlines() |
---|
| 71 | for i in range(0, len(o)): |
---|
| 72 | portadd = o[i] |
---|
| 73 | q = re.split('\s+', str(portadd)) |
---|
| 74 | s = open('portadd.txt','a') |
---|
| 75 | for j in range(0, len(q)): |
---|
| 76 | s.write(str(q[j])+'\n') |
---|
| 77 | s.close() |
---|
| 78 | |
---|
| 79 | f = open('rtmp.txt').readlines() |
---|
| 80 | for i in range(0, len(f)): |
---|
| 81 | repnum = f[i] |
---|
| 82 | p = re.split('\s+', str(repnum)) |
---|
| 83 | s = open('repnum.txt','a') |
---|
| 84 | for j in range(0, len(p)): |
---|
| 85 | s.write(str(p[j])+'\n') |
---|
| 86 | s.close() |
---|
| 87 | |
---|
| 88 | |
---|
| 89 | a = open('dual_rtmp.txt').readlines() |
---|
| 90 | for i in range(0, len(a)): |
---|
| 91 | d_repnum = a[i] |
---|
| 92 | r = re.split('\s+', str(d_repnum)) |
---|
| 93 | s = open('dual_repnum.txt','a') |
---|
| 94 | for j in range(0, len(r)): |
---|
| 95 | s.write(str(r[j])+'\n') |
---|
| 96 | s.close() |
---|
| 97 | |
---|
| 98 | t = open('dual_ptmp.txt').readlines() |
---|
| 99 | for i in range(0, len(t)): |
---|
| 100 | d_portadd = t[i] |
---|
| 101 | q = re.split('\s+', str(d_portadd)) |
---|
| 102 | s = open('dual_portadd.txt','a') |
---|
| 103 | for j in range(0, len(q)): |
---|
| 104 | s.write(str(q[j])+'\n') |
---|
| 105 | s.close() |
---|