Skip to content

Commit

Permalink
Merge pull request #1 from 5genesis/parallel_fix
Browse files Browse the repository at this point in the history
Parallel fix
  • Loading branch information
NaniteBased authored Oct 19, 2020
2 parents fb63a11 + ac911e1 commit 57b66df
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 25 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
**19/10/2020** [Version 1.0.6]

- Fix result parsing when parallel is explicitly set to 1

**20/04/2020** [Version 1.0.5]

- Allow setting the reporting interval (-i)
Expand Down
34 changes: 16 additions & 18 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
iPerf.Initialize(data['IPERF_PATH'])


def errorResponse(message, error):
print(f'{message}: {error}')
return jsonify({'Status': 'Error', 'Message': message, 'Error': f'{error}'}), 403


@app.route('/Iperf', methods=['POST'])
@app.route('/Iperf/<pathParameters>', methods=['GET'])
def Iperf(pathParameters: str = ""):
Expand All @@ -25,9 +30,7 @@ def Iperf(pathParameters: str = ""):
if iPerfConfig.formatValidation(pathParameters):
parameters = pathParameters[1:-1].split(',')
else:
print(f'Wrong parameters format')
return jsonify({'Status': 'Error', 'Message': f'Error executing iPerf',
'Error': 'Wrong parameters format.'}), 403
return errorResponse('Error executing iPerf', 'Wrong parameter format')

for param in parameters:
if '-c' in param:
Expand All @@ -36,49 +39,44 @@ def Iperf(pathParameters: str = ""):
iPerf.Iperf(parameters)
return jsonify({'Status': 'Success', 'Message': f'Successfully executed iPerf {mode}'})

except RuntimeError as error:
print(f'{error}')
return jsonify({'Status': 'Error', 'Message': f'Error executing iPerf {mode}', 'Error': f'{error}'}), 403
except Exception as error:
return errorResponse(f'Error executing iPerf {mode}', error)


@app.route('/Close', methods=['GET'])
def Close():
try:
iPerf.Close()
return jsonify({'Status': 'Success', 'Message': 'Successfully closed iPerf'})
except RuntimeError as error:
print(f'{error}')
return jsonify({'Status': 'Error', 'Message': 'Error closing iPerf', 'Error': f'{error}'}), 403
except Exception as error:
return errorResponse('Error closing iPerf', error)


@app.route('/LastRawResult', methods=['GET'])
def LastRawResult():
try:
return jsonify({'Status': 'Success', 'Message': 'Successfully retrieved last raw result',
'Result': iPerf.LastRawResult()})
except RuntimeError as error:
print(f'{error}')
return jsonify({'Status': 'Error', 'Message': 'Error retrieving last raw result', 'Error': f'{error}'}), 403
except Exception as error:
return errorResponse('Error retrieving last raw result', error)


@app.route('/LastJsonResult', methods=['GET'])
def LastJsonResult():
try:
return jsonify({'Status': 'Success', 'Message': 'Successfully retrieved last json result',
'Result': iPerf.LastJsonResult()})
except RuntimeError as error:
print(f'{error}')
return jsonify({'Status': 'Error', 'Message': 'Error retrieving last json result', 'Error': f'{error}'}), 403
except Exception as error:
return errorResponse('Error retrieving last json result', error)


@app.route('/LastError', methods=['GET'])
def LastError():
try:
return jsonify({'Status': 'Success', 'Message': 'Successfully retrieved last error',
'Error': iPerf.LastError()})
except RuntimeError as error:
print(f'{error}')
return jsonify({'Status': 'Error', 'Message': 'Error retrieving last error', 'Error': f'{error}'}), 403
except Exception as error:
return errorResponse('Error retrieving last error', error)


@app.route('/StartDateTime', methods=['GET'])
Expand Down
5 changes: 3 additions & 2 deletions iperfExecutor/iperfConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,21 @@ def parseParameters(cls, parameters: List[str]) -> Dict:

@classmethod
def shortenParameters(cls, parameters: Dict) -> Dict:
print(parameters)
print(f'Received parameters: {parameters}')
shortParameters = parameters
for param in parameters.keys():
if param in cls.longParameters.keys():
value = shortParameters[param]
shortParameters.pop(param)
shortParameters[cls.longParameters[param]] = value

print(shortParameters)
print(f'Shorted parameters: {shortParameters}')
return shortParameters

@classmethod
def parseIperfResult(cls, line: str, protocol: str, parallelEnabled: bool, startTime: datetime, interval: int):
print(line)

pattern = r'\[(.*)] *(\d+(\.\d+)?) *- *(\d+(\.\d+)?) *sec *(\d+(\.\d+)?) *MBytes *(\d+(\.\d+)?) *Mbits/sec(.*)?'
udpPattern = r' *(\d+(\.\d+)?) *ms *\d+ */ *\d+ \((\d+(\.\d+)?)%\) *'
jsonResult = {}
Expand Down
16 changes: 11 additions & 5 deletions iperfExecutor/iperfExecutor.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,15 @@ def execute(cls, parametersDict: Dict) -> None:
else:
protocol = 'TCP'

# 'P' parameter must be after client host and port
if '-P' in parametersDict.keys():
parallelEnabled = True
moveToLast = parametersDict.pop('-P')
parametersDict['-P'] = moveToLast
# 'P' parameter must be after client host and port, move it to the last key
parallelCount = int(parametersDict.pop('-P'))
parametersDict['-P'] = str(parallelCount)

# Even if 'P' is set, iPerf will ignore it when < 2
parallelEnabled = (parallelCount > 1)
else:
parallelCount = 1
parallelEnabled = False

parameters = []
Expand All @@ -108,7 +111,10 @@ def execute(cls, parametersDict: Dict) -> None:
parameters.append(value)

params = [cls.executable, *parameters]
print(params)

print(f'Final CLI parameters: {params}')
print(f'Protocol: {protocol}; Parallel: {parallelEnabled} (Count: {parallelCount}); Interval: {interval}')

Thread(target=cls.async_task, args=(params, protocol, parallelEnabled, interval)).start()
return None

Expand Down

0 comments on commit 57b66df

Please sign in to comment.