pkt_gen: STC - Imix Genome Support
[vswitchperf.git] / core / vswitch_controller_p2p.py
1 # Copyright 2015-2018 Intel Corporation., Tieto
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #   http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 """VSwitch controller for Physical to Physical deployment
16 """
17 from core.vswitch_controller import IVswitchController
18 from conf import settings
19
20 class VswitchControllerP2P(IVswitchController):
21     """VSwitch controller for P2P deployment scenario.
22
23     Attributes:
24         _vswitch_class: The vSwitch class to be used.
25         _vswitch: The vSwitch object controlled by this controller
26         _deployment_scenario: A string describing the scenario to set-up in the
27             constructor.
28     """
29     def __init__(self, deployment, vswitch_class, traffic):
30         """See IVswitchController for general description
31         """
32         super().__init__(deployment, vswitch_class, traffic)
33         self._bridge = settings.getValue('VSWITCH_BRIDGE_NAME')
34
35     def setup(self):
36         """Sets up the switch for p2p.
37         """
38         self._logger.debug('Setup using %s', str(self._vswitch_class))
39
40         try:
41             self._vswitch.start()
42
43             self._vswitch.add_switch(self._bridge)
44
45             (port1, _) = self._vswitch.add_phy_port(self._bridge)
46             (port2, _) = self._vswitch.add_phy_port(self._bridge)
47
48             self._vswitch.add_connection(self._bridge, port1, port2, self._traffic)
49             self._vswitch.add_connection(self._bridge, port2, port1, self._traffic)
50
51         except:
52             self._vswitch.stop()
53             raise
54
55     def stop(self):
56         """Tears down the switch created in setup().
57         """
58         self._logger.debug('Stop using %s', str(self._vswitch_class))
59         self._vswitch.stop()
60
61     def get_ports_info(self):
62         """See IVswitchController for description
63         """
64         self._logger.debug('get_ports_info  using %s', str(self._vswitch_class))
65         return self._vswitch.get_ports(self._bridge)
66
67     def dump_vswitch_connections(self):
68         """See IVswitchController for description
69         """
70         self._vswitch.dump_connections(self._bridge)