1 # Copyright 2015 Intel Corporation.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 """VSwitch controller for Physical to VM to Physical deployment
20 from core.vswitch_controller import IVswitchController
21 from vswitches.utils import add_ports_to_flow
28 class VswitchControllerPVP(IVswitchController):
29 """VSwitch controller for PVP deployment scenario.
32 _vswitch_class: The vSwitch class to be used.
33 _vswitch: The vSwitch object controlled by this controller
34 _deployment_scenario: A string describing the scenario to set-up in the
37 def __init__(self, vswitch_class, bidir=False):
38 """Initializes up the prerequisites for the PVP deployment scenario.
40 :vswitch_class: the vSwitch class to be used.
42 self._logger = logging.getLogger(__name__)
43 self._vswitch_class = vswitch_class
44 self._vswitch = vswitch_class()
45 self._deployment_scenario = "PVP"
47 self._logger.debug('Creation using ' + str(self._vswitch_class))
50 """ Sets up the switch for pvp
52 self._logger.debug('Setup using ' + str(self._vswitch_class))
57 self._vswitch.add_switch(BRIDGE_NAME)
59 (_, phy1_number) = self._vswitch.add_phy_port(BRIDGE_NAME)
60 (_, phy2_number) = self._vswitch.add_phy_port(BRIDGE_NAME)
61 (_, vport1_number) = self._vswitch.add_vport(BRIDGE_NAME)
62 (_, vport2_number) = self._vswitch.add_vport(BRIDGE_NAME)
64 self._vswitch.del_flow(BRIDGE_NAME)
65 flow1 = add_ports_to_flow(_FLOW_TEMPLATE, phy1_number,
67 flow2 = add_ports_to_flow(_FLOW_TEMPLATE, vport2_number,
69 self._vswitch.add_flow(BRIDGE_NAME, flow1)
70 self._vswitch.add_flow(BRIDGE_NAME, flow2)
73 flow3 = add_ports_to_flow(_FLOW_TEMPLATE, phy2_number,
75 flow4 = add_ports_to_flow(_FLOW_TEMPLATE, vport1_number,
77 self._vswitch.add_flow(BRIDGE_NAME, flow3)
78 self._vswitch.add_flow(BRIDGE_NAME, flow4)
85 """Tears down the switch created in setup().
87 self._logger.debug('Stop using ' + str(self._vswitch_class))
93 def __exit__(self, type_, value, traceback):
96 def get_vswitch(self):
97 """See IVswitchController for description
101 def get_ports_info(self):
102 """See IVswitchController for description
104 self._logger.debug('get_ports_info using ' + str(self._vswitch_class))
105 return self._vswitch.get_ports(BRIDGE_NAME)