2 # Copyright 2016 Cisco Systems, Inc. All rights reserved.
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
20 from service_chain import ServiceChain
21 from traffic_client import TrafficClient
24 class ChainRunner(object):
25 """Run selected chain, collect results and analyse them."""
27 def __init__(self, config, clients, cred, specs, factory, notifier=None):
29 self.clients = clients
31 self.factory = factory
32 self.chain_name = self.config.service_chain
35 TORClass = factory.get_tor_class(self.config.tor.type, self.config.no_tor_access)
36 except AttributeError:
37 raise Exception("Requested TOR class '{}' was not found.".format(self.config.tor.type))
39 self.clients['tor'] = TORClass(self.config.tor.switches)
40 self.clients['traffic'] = TrafficClient(config, notifier)
41 self.chain = ServiceChain(config, clients, cred, specs, factory, notifier)
43 LOG.info('ChainRunner initialized.')
47 Run a chain, collect and analyse results.
51 self.clients['traffic'].start_traffic_generator()
52 self.clients['traffic'].set_macs()
54 return self.chain.run()
58 if not self.config.no_cleanup:
59 LOG.info('Cleaning up...')
61 LOG.info('Clean up skipped.')
63 for client in ['traffic', 'tor']:
65 self.clients[client].close()
66 except Exception as e:
73 LOG.error('Cleanup not finished.')
75 def get_version(self):
77 'Traffic Generator': self.clients['traffic'].get_version(),
78 'TOR': self.clients['tor'].get_version(),
81 versions.update(self.chain.get_version())