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/settings/flows_settings.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/settings/flows_settings.py')
-rwxr-xr-x | vstf/vstf/controller/settings/flows_settings.py | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/vstf/vstf/controller/settings/flows_settings.py b/vstf/vstf/controller/settings/flows_settings.py new file mode 100755 index 00000000..b2bec625 --- /dev/null +++ b/vstf/vstf/controller/settings/flows_settings.py @@ -0,0 +1,122 @@ +#!/usr/bin/env python +# -*- coding: utf8 -*- +# author: wly +# date: 2015-09-18 +# see license for license details + +import logging + +import vstf.controller.settings.settings as sets + +LOG = logging.getLogger(__name__) + + +class FlowsSettings(sets.Settings): + def __init__(self, path="/etc/vstf/perf/", + filename="sw_perf.flownodes-settings", + mode=sets.SETS_SINGLE): + self._check_actors = {'namespaces', 'senders', 'receivers', 'watchers'} + self._nocheck_actors = {"cpu_listens"} + super(FlowsSettings, self).__init__(path, filename, mode) + + def _register_func(self): + super(FlowsSettings, self)._register_func() + for actor in self._check_actors: + actor = actor.encode() + func_name = "add_%s" % actor + setattr(self, func_name, self._adding_file(func_name, self._mset, self._fset, actor, self._check_add)) + func_name = "madd_%s" % actor + setattr(self, func_name, self._adding_memory(func_name, self._mset, actor, self._check_add)) + + for actor in self._nocheck_actors: + actor = actor.encode() + func_name = "add_%s" % actor + setattr(self, func_name, self._adding_file(func_name, self._mset, self._fset, actor)) + func_name = "madd_%s" % actor + setattr(self, func_name, self._adding_memory(func_name, self._mset, actor)) + + LOG.debug(self.__dict__.keys()) + + def clear_all(self): + actors = self._check_actors | self._nocheck_actors + for actor in actors: + func_name = "set_%s" % actor + func = getattr(self, func_name) + func([]) + + def mclear_all(self): + actors = self._check_actors | self._nocheck_actors + for actor in actors: + func_name = "mset_%s" % actor + func = getattr(self, func_name) + func([]) + + def _check_add(self, value): + flows = ['agent', 'dev'] + if not isinstance(value, dict): + raise Exception("type is error: %s" % (str(value))) + for flow in flows: + if flow not in value.keys(): + raise Exception("keys[%s] is missing: %s" % (flow, str(value))) + + items = ["ip", "namespace", "mac", "iface", "bdf"] + for item in items: + if item not in value['dev'].keys(): + raise Exception("keys[%s] is error: %s" % (item, str(value))) + + +def unit_test(): + from vstf.common.log import setup_logging + setup_logging(level=logging.DEBUG, log_file="/var/log/vstf/vstf-flows-settings.log", clevel=logging.INFO) + + flows_settings = FlowsSettings() + LOG.info(flows_settings.settings) + + flows_settings.clear_all() + flows_settings.set_flows(2) + LOG.info(flows_settings.settings) + + flow_1 = { + "agent": "192.168.188.14", + "dev": { + "ip": "192.168.1.100", + "namespace": "vstf-space-1", + "mac": "90:e2:ba:20:1f:d8", + "iface": "eth4", + "bdf": "04:00.0" + } + } + flow_2 = { + "agent": "192.168.188.14", + "dev": { + "ip": "192.168.1.101", + "namespace": "vstf-space-2", + "mac": "90:e2:ba:20:1f:d9", + "iface": "p57p2", + "bdf": "04:00.1" + } + } + + flows_settings.add_senders(flow_1) + flows_settings.add_senders(flow_2) + flows_settings.add_receivers(flow_2) + flows_settings.add_receivers(flow_1) + + flows_settings.add_watchers(flow_1) + flows_settings.add_watchers(flow_2) + + flows_settings.add_namespaces(flow_1) + flows_settings.add_namespaces(flow_2) + + cpu = { + "agent": "192.168.188.16", + "affctl":{ + "policy": 2 + } + } + flows_settings.add_cpu_listens(cpu) + LOG.info(flows_settings.settings) + + +if __name__ == '__main__': + unit_test() |