From 7caf7a6be0fae6b341181b3e6286372e2e93b4b8 Mon Sep 17 00:00:00 2001 From: Martin Klozik Date: Fri, 11 Dec 2015 14:29:18 +0000 Subject: testcase: scalability - configurable installation of flows to the vswitch Stream specific flows can be pre-installed into the vswitch based on the value of testcase specific configuration option "Pre-installed Flows". In case, it is set to 'Yes', then specific flow for each stream will be inserted into the switch. Otherwise only generic flows will be installed. Default value of "Pre-installed Flows" is set to 'No'. Its value can be overridden by CLI parameter pre-installed_flows. This configuration parameter is an enhancement of "MultiSream" feature and it is ignored if "MultiStream" is disabled. Python module 'netaddr' is required by this implementation and it has been added to requirements.txt file. Change-Id: I8a17577a702bf2be2753134eb203b936a87fc2e5 JIRA: VSPERF-83 Signed-off-by: Martin Klozik Reviewed-by: Maryam Tahhan Reviewed-by: Brian Castelli --- src/ovs/ofctl.py | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) (limited to 'src/ovs') diff --git a/src/ovs/ofctl.py b/src/ovs/ofctl.py index c052f85c..9d16ef76 100644 --- a/src/ovs/ofctl.py +++ b/src/ovs/ofctl.py @@ -34,6 +34,8 @@ _OVS_OFCTL_BIN = os.path.join(settings.getValue('OVS_DIR'), 'utilities', _OVS_BRIDGE_NAME = settings.getValue('VSWITCH_BRIDGE_NAME') +_CACHE_FILE_NAME = '/tmp/vsperf_flows_cache' + class OFBase(object): """Add/remove/show datapaths using ``ovs-ofctl``. """ @@ -103,6 +105,7 @@ class OFBridge(OFBase): super(OFBridge, self).__init__(timeout) self.br_name = br_name self._ports = {} + self._cache_file = None # context manager @@ -121,7 +124,7 @@ class OFBridge(OFBase): # helpers - def run_ofctl(self, args, check_error=False): + def run_ofctl(self, args, check_error=False, timeout=None): """Run ``ovs-ofctl`` with supplied arguments. :param args: Arguments to pass to ``ovs-ofctl`` @@ -129,8 +132,9 @@ class OFBridge(OFBase): :return: None """ + tmp_timeout = self.timeout if timeout == None else timeout cmd = ['sudo', _OVS_OFCTL_BIN, '-O', 'OpenFlow13', '--timeout', - str(self.timeout)] + args + str(tmp_timeout)] + args return tasks.run_task( cmd, self.logger, 'Running ovs-ofctl...', check_error) @@ -233,7 +237,7 @@ class OFBridge(OFBase): # flow mangement - def add_flow(self, flow): + def add_flow(self, flow, cache='off'): """Add flow to bridge. :param flow: Flow description as a dictionary @@ -241,14 +245,32 @@ class OFBridge(OFBase): :return: None """ + # insert flows from cache into OVS if needed + if cache == 'flush': + if self._cache_file == None: + self.logger.error('flow cache flush called, but nothing is cached') + return + self.logger.debug('flows cached in %s will be added to the bridge', _CACHE_FILE_NAME) + self._cache_file.close() + self._cache_file = None + self.run_ofctl(['add-flows', self.br_name, _CACHE_FILE_NAME], timeout=600) + return + if not flow.get('actions'): self.logger.error('add flow requires actions') return - self.logger.debug('add flow') _flow_key = flow_key(flow) self.logger.debug('key : %s', _flow_key) - self.run_ofctl(['add-flow', self.br_name, _flow_key]) + + # insert flow to the cache or OVS + if cache == 'on': + # create and open cache file if needed + if self._cache_file == None: + self._cache_file = open(_CACHE_FILE_NAME, 'w') + self._cache_file.write(_flow_key + '\n') + else: + self.run_ofctl(['add-flow', self.br_name, _flow_key]) def del_flow(self, flow): """Delete flow from bridge. @@ -274,7 +296,7 @@ class OFBridge(OFBase): """Dump all flows from bridge. """ self.logger.debug('dump flows') - self.run_ofctl(['dump-flows', self.br_name]) + self.run_ofctl(['dump-flows', self.br_name], timeout=120) # # helper functions -- cgit 1.2.3-korg