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
18 from service_chain import ServiceChain
20 from traffic_client import TrafficClient
23 class ChainRunner(object):
24 """Run selected chain, collect results and analyse them."""
26 def __init__(self, config, clients, cred, specs, factory, notifier=None):
28 self.clients = clients
30 self.factory = factory
31 self.chain_name = self.config.service_chain
34 TORClass = factory.get_tor_class(self.config.tor.type, self.config.no_tor_access)
35 except AttributeError:
36 raise Exception("Requested TOR class '{}' was not found.".format(self.config.tor.type))
38 self.clients['tor'] = TORClass(self.config.tor.switches)
39 self.clients['traffic'] = TrafficClient(config, notifier)
40 self.chain = ServiceChain(config, clients, cred, specs, factory, notifier)
42 LOG.info('ChainRunner initialized.')
46 Run a chain, collect and analyse results.
50 self.clients['traffic'].start_traffic_generator()
51 self.clients['traffic'].set_macs()
53 return self.chain.run()
57 if not self.config.no_cleanup:
58 LOG.info('Cleaning up...')
60 LOG.info('Clean up skipped.')
62 for client in ['traffic', 'tor']:
64 self.clients[client].close()
65 except Exception as e:
72 LOG.error('Cleanup not finished.')
74 def get_version(self):
76 'Traffic Generator': self.clients['traffic'].get_version(),
77 'TOR': self.clients['tor'].get_version(),
80 versions.update(self.chain.get_version())