diff options
author | Yiting.Li <liyiting@huawei.com> | 2015-12-22 17:11:12 -0800 |
---|---|---|
committer | Yiting.Li <liyiting@huawei.com> | 2015-12-22 17:11:12 -0800 |
commit | 8f1101df131a4d3e03b377738507d88b745831c0 (patch) | |
tree | 73f140474fcec2a77c85a453f6946957ca0742d1 /vstf/vstf/controller/sw_perf/model.py | |
parent | 1a24ebbda3f95600c0e7d5ed8661317a8ff7e265 (diff) |
Upload the contribution of vstf as bottleneck network framework.
End to End Performance test
JIRA:BOTTLENECK-29
Change-Id: Ib2c553c8b60d6cda9e7a7b52b737c9139f706ebd
Signed-off-by: Yiting.Li <liyiting@huawei.com>
Diffstat (limited to 'vstf/vstf/controller/sw_perf/model.py')
-rwxr-xr-x | vstf/vstf/controller/sw_perf/model.py | 190 |
1 files changed, 190 insertions, 0 deletions
diff --git a/vstf/vstf/controller/sw_perf/model.py b/vstf/vstf/controller/sw_perf/model.py new file mode 100755 index 00000000..672daade --- /dev/null +++ b/vstf/vstf/controller/sw_perf/model.py @@ -0,0 +1,190 @@ +#!/usr/bin/python +# -*- coding: utf8 -*- +# author: +# date: +# see license for license details + +import logging + +from vstf.controller.fabricant import Fabricant +from vstf.controller.sw_perf.raw_data import RawDataProcess +from vstf.common import perfmark as mark + +LOG = logging.getLogger(__name__) + + +class NetDeviceMgr(Fabricant): + @classmethod + def add(cls, dst, conn, dev): + self = cls(dst, conn) + LOG.info(dev) + ret = self.config_dev(netdev=dev) + LOG.info(ret) + + @classmethod + def remove(cls, dst, conn, dev): + self = cls(dst, conn) + LOG.info(dev) + ret = self.recover_dev(netdev=dev) + LOG.info(ret) + + @classmethod + def clear(cls, dst, conn): + self = cls(dst, conn) + self.clean_all_namespace() + + +class Actor(Fabricant): + def __init__(self, dst, conn, tool, params): + super(Actor, self).__init__(dst, conn) + self._tool = tool + self._params = params + self._data = {} + + def __repr__(self): + repr_dict = self.__dict__ + repr_keys = list(repr_dict.keys()) + repr_keys.sort() + return '%s(%s)' % (self.__class__.__name__, ', '.join(['%s=%r' % (k, repr_dict[k]) for k in repr_keys])) + + +class Sender(Actor): + def start(self, pktsize, **kwargs): + LOG.info("Sender.start") + if 'ratep' in kwargs and kwargs['ratep']: + self._params['ratep'] = kwargs['ratep'] + self._params['size'] = pktsize + + ret, info = self.perf_run( + operation="start", + action="send", + tool=self._tool, + params=self._params + ) + LOG.info(ret) + if ret: + raise Exception(info) + LOG.info(info) + print ret + + def stop(self): + LOG.info(self._params) + rets = self.perf_run( + operation="stop", + action="send", + tool=self._tool, + params={} + ) + LOG.info(rets) + minlatency, avglatency, maxlatency = 0, 0, 0 + count = 0 + for (ret, info) in rets: + if ret: + raise Exception(info) + if self.is_data() and ret == 0: + count += 1 + minlatency += info[mark.minLatency] + avglatency += info[mark.avgLatency] + maxlatency += info[mark.maxLatency] + count = 1 if not count else count + self._data[mark.minLatency] = minlatency / count + self._data[mark.avgLatency] = avglatency / count + self._data[mark.maxLatency] = maxlatency / count + + print rets + + def is_data(self): + if '_lat' in self._params['protocol']: + return True + return False + + def result(self): + return self._data + + +class Receiver(Actor): + def start(self, **kwargs): + LOG.info("Receiver.start") + ret, info = self.perf_run( + operation="start", + action="receive", + tool=self._tool, + params=self._params + ) + LOG.info(ret) + if ret: + raise Exception(info) + LOG.info(info) + return ret + + def stop(self): + LOG.info("Receiver.stop") + ret, info = self.perf_run( + operation="stop", + action="receive", + tool=self._tool, + params=self._params + ) + LOG.info(ret) + if ret: + raise Exception(info) + LOG.info(info) + return ret + + +class NicWatcher(Fabricant): + def __init__(self, dst, conn, params): + super(NicWatcher, self).__init__(dst, conn) + self._params = params + self._pid = None + self._data = {} + + def start(self): + print "NicWatcher.start" + self._pid = self.run_vnstat(device=self._params["iface"], namespace=self._params["namespace"]) + print self._pid + + def stop(self): + print "NicWatcher.stop" + if self._pid: + data = self.kill_vnstat(pid=self._pid) + self._data = RawDataProcess.process(data) + print "---------------------------------" + print self._data + print "---------------------------------" + + def result(self, **kwargs): + return self._data + + +class CpuWatcher(Fabricant): + def __init__(self, dst, conn): + super(CpuWatcher, self).__init__(dst, conn) + self._pid = None + self._data = {} + + def start(self): + print "CpuWatcher.start" + self._pid = self.run_cpuwatch() + print self._pid + + def stop(self): + print "CpuWatcher.stop" + if self._pid: + print self._pid + data = self.kill_cpuwatch(pid=self._pid) + self._data = RawDataProcess.process(data) + print "---------------------------------" + print self._data + print "---------------------------------" + + def result(self, **kwargs): + return self._data + + +def unit_test(): + pass + + +if __name__ == '__main__': + unit_test() |