Skip to content

Commit

Permalink
Fits gym to vnf-bd and vnf-pp new models
Browse files Browse the repository at this point in the history
gym-player saves vnf-br csv file by default

Signed-off-by: Raphael Vicente Rosa <[email protected]>
  • Loading branch information
raphaelvrosa committed Sep 13, 2019
1 parent 495ea9e commit 044be41
Show file tree
Hide file tree
Showing 42 changed files with 2,289 additions and 13,532 deletions.
30 changes: 19 additions & 11 deletions gym/agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,24 @@ def cfg_acts(self):
}
self.actuator.cfg(cfg)

def origin(self):
feats = self.identity.get('features')
host = feats.get('environment').get('host')
identity = self.identity.get('uuid')

org = {
"id": identity,
"host": host,
"role": "agent",
}
return org

def snapshot(self, _id, evals):
logger.info('Snapshot')
snapshot = Snapshot(id=_id)
origin = self.origin()
snapshot.set('origin', origin)
snapshot.set('evaluations', evals)
feats = self.identity.get('features')
host = feats.get('environment').get('host')
identity = self.identity.get('identity')
snapshot.set('host', host)
snapshot.set('component', identity)
snapshot.set('role', 'agent')
logger.debug(snapshot.to_json())
return snapshot

Expand All @@ -54,11 +62,11 @@ def evaluations(self, evals):
for eval_id,(ack,runner_id,out) in evals.items():
evaluation = Evaluation(id=eval_id)
if ack:
evaluation.set('type', 'prober')
evaluation.set('tool', runner_id)
evaluation.set('metrics', out)
if type(out) is list:
evaluation.set('series', True)
evaluation.set('source', out.get("source", None))
evaluation.set('timestamp', out.get("timestamp", None))
evaluation.set('metrics', out.get("metrics", None))
# if type(out) is list:
# evaluation.set('series', True)
else:
error = Error(data=out)
evaluation.set('error', error)
Expand Down
40 changes: 36 additions & 4 deletions gym/agent/probers/prober.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def stop_process(self, timeout):
logger.info('stopping process after %s', timeout)
if self.process:
#if process stop, usually server, so waits one second more
time.sleep(timeout+1)
time.sleep(timeout)
self.process.kill()
logger.info('process stopped %s', self.process.pid)
self.process = None
Expand Down Expand Up @@ -89,6 +89,10 @@ def __init__(self, id, name, parameters, metrics):
self.name = name
self.parameters = parameters
self.metrics = metrics
self._type = "prober"
self._call = ""
self._tstart = None
self._tstop = None
self._output = {}
self._command = None
self._default_params = Prober.PARAMS
Expand Down Expand Up @@ -123,6 +127,22 @@ def serialize(self, opts):
logger.info("serialize option not found %s", k)
return options

def source(self):
source = {
"id": self.id,
"type": self._type,
"name": self.name,
"call": self._call,
}
return source

def timestamp(self):
ts = {
"start": self._tstart,
"stop": self._tstop,
}
return ts

def probe(self, opts):
cmd = []
cmd.append(self._command)
Expand All @@ -133,19 +153,31 @@ def probe(self, opts):
return

cmd.extend(opts)

self._call = " ".join(cmd)

self._tstart = datetime.now().strftime('%Y-%m-%dT%H:%M:%S.%fZ')
ret, out, err = self._processor.start_process(cmd, stop, timeout)
self._tstop = datetime.now().strftime('%Y-%m-%dT%H:%M:%S.%fZ')

output = out.decode('UTF-8')
error = err.decode('UTF-8')

if ret == 0:
logger.info("process executed %s", ret)
self._output = self.parser(output)
metrics = self.parser(output)
elif stop and ret == -9:
logger.info("process executed and stopped %s", ret)
self._output = self.parser(output)
metrics = self.parser(output)
else:
logger.info("process error %s, %s", output, error)
self._output = {"error": error}
metrics = {"error": error}

self._output = {
"metrics": metrics,
"timestamp": self.timestamp(),
"source": self.source(),
}

def to_json(self, value):
return json.dumps(value, sort_keys=True, indent=4)
Expand Down
32 changes: 20 additions & 12 deletions gym/agent/probers/prober_iperf.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,35 @@ def options(self, opts):
return opts, stop, timeout

def parser(self, out):
eval = {}
_eval = []

lines = [line for line in out.split('\n') if line.strip()]
if len(lines) == 7:
bandwidth = lines[-1].split(' ')[-2]
units = lines[-1].split(' ')[-1]
eval = {
'bandwidth': {
'value': float(bandwidth),
'units': units,
}
m = {
"name": "throughput",
"series": False,
"type": "float",
"unit": units,
"value": float(bandwidth),
}
_eval = [m]

elif len(lines) == 11 or len(lines) == 8:
bandwidth = lines[-1].split(' ')[-13]
units = lines[-1].split(' ')[-12]
eval = {
'bandwidth':{
'value': float(bandwidth),
'units': units,
}

m = {
"name": "throughput",
"series": False,
"type": "float",
"unit": units,
"value": float(bandwidth),
}
return eval
_eval = [m]

return _eval


if __name__ == '__main__':
Expand Down
75 changes: 70 additions & 5 deletions gym/agent/probers/prober_iperf3.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def __init__(self):
parameters=ProberIperf3.PARAMETERS,
metrics=ProberIperf3.METRICS)
self._command = 'iperf3'
self._server = False

def options(self, opts):
options = self.serialize(opts)
Expand All @@ -42,10 +43,12 @@ def options(self, opts):

if server:
opts.extend( ['-c', server] )
time.sleep(0.5)
time.sleep(1)

if not client or client == 'false' or client == 'False':
opts.extend( ['-s'] )
stop = True
self._server = True

port = options.get('-p', '9030')
opts.extend( ['-p', port] )
Expand All @@ -54,6 +57,9 @@ def options(self, opts):
if timeout and not stop:
opts.extend( ['-t', str(timeout)] )
timeout = 0

if stop:
timeout += 2

proto = options.get('-u', None)
if proto == 'udp':
Expand All @@ -69,19 +75,78 @@ def options(self, opts):
return opts, stop, timeout

def parser(self, out):
_eval = {}
_eval = []
try:
out = json.loads(out)
except ValueError:
logger.debug('iperf3 json output could not be decoded')
out = {}
else:
end = out.get("end", None)

if end:
if 'sum_sent' in end:
_eval = end.get('sum_sent')
if 'sum' in end:
_eval = end.get('sum')
_values = end.get('sum_sent')
elif 'sum' in end:
_values = end.get('sum')
else:
_values = {}

if not self._server and _values:

m1 = {
"name": "bits_per_second",
"series": False,
"type": "float",
"unit": "bits_per_second",
"value": float(_values.get("bits_per_second")),
}

m2 = {
"name": "jitter_ms",
"series": False,
"type": "float",
"unit": "ms",
"value": float(_values.get("jitter_ms")),
}

m3 = {
"name": "bytes",
"series": False,
"type": "int",
"unit": "bytes",
"value": int(_values.get("bytes")),
}


m4 = {
"name": "lost_packets",
"series": False,
"type": "int",
"unit": "packets",
"value": int(_values.get("lost_packets")),
}

m5 = {
"name": "lost_percent",
"series": False,
"type": "float",
"unit": "%",
"value": float(_values.get("lost_percent")),
}

m6 = {
"name": "packets",
"series": False,
"type": "int",
"unit": "packets",
"value": int(_values.get("packets")),
}


_eval = [m1, m2, m3, m4, m5, m6]


finally:
return _eval

Expand Down
57 changes: 44 additions & 13 deletions gym/agent/probers/prober_ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,50 @@ def parser(self, out):
pkt_loss = loss_line[-3][0]
pkt_loss_units = loss_line[-3][-1]

_eval = {
'latency':{
'rtt_min': float(rtts[0]),
'rtt_avg': float(rtts[1]),
'rtt_max': float(rtts[2]),
'rtt_mdev': float(rtts[3]),
'units': rtt_units},
'frame_loss':{
'frames': float(loss_line[0]),
'frame_loss': float(pkt_loss),
'units': pkt_loss_units,
}
}


m1 = {
"name": "rtt_min",
"series": False,
"type": "float",
"unit": rtt_units,
"value": float(rtts[0].replace(",", ".")),
}

m2 = {
"name": "rtt_avg",
"series": False,
"type": "float",
"unit": rtt_units,
"value": float(rtts[1].replace(",", ".")),
}

m3 = {
"name": "rtt_max",
"series": False,
"type": "float",
"unit": rtt_units,
"value": float(rtts[2].replace(",", ".")),
}

m4 = {
"name": "rtt_mdev",
"series": False,
"type": "float",
"unit": rtt_units,
"value": float(rtts[3].replace(",", ".")),
}

m5 = {
"name": "frame_loss",
"series": False,
"type": "float",
"unit": pkt_loss_units,
"value": float(pkt_loss),
}

_eval = [m1, m2, m3, m4, m5]

return _eval


Expand Down
30 changes: 25 additions & 5 deletions gym/agent/probers/prober_tcpreplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,36 @@ def filepath(self, filename):
return _filepath

def parser(self, output):
eval_info = None
_eval = []
lines = output.split('\n')
if len(lines) > 1:
actual = [line for line in lines if 'Actual' in line]
actual_info = actual.pop().split()
eval_info = {
'packets': int(actual_info[1]),
'time': float(actual_info[-2]),

# eval_info = {
# 'packets': int(actual_info[1]),
# 'time': float(actual_info[-2]),
# }

m1 = {
"name": "packets",
"series": False,
"type": "int",
"unit": "packets",
"value": int(actual_info[1]),
}

m2 = {
"name": "time",
"series": False,
"type": "float",
"unit": "seconds",
"value": float(actual_info[-2]),
}
return eval_info

_eval = [m1, m2]

return _eval


if __name__ == '__main__':
Expand Down
Loading

0 comments on commit 044be41

Please sign in to comment.