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
22 from conf import settings
28 class VswitchControllerPVVP(IVswitchController):
29 """VSwitch controller for PVVP 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, traffic):
38 """Initializes up the prerequisites for the PVVP 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 = "PVVP"
46 self._traffic = traffic.copy()
47 self._logger.debug('Creation using ' + str(self._vswitch_class))
50 """ Sets up the switch for PVVP
52 self._logger.debug('Setup using ' + str(self._vswitch_class))
57 bridge = settings.getValue('VSWITCH_BRIDGE_NAME')
58 self._vswitch.add_switch(bridge)
60 (_, phy1_number) = self._vswitch.add_phy_port(bridge)
61 (_, phy2_number) = self._vswitch.add_phy_port(bridge)
62 (_, vport1_number) = self._vswitch.add_vport(bridge)
63 (_, vport2_number) = self._vswitch.add_vport(bridge)
64 (_, vport3_number) = self._vswitch.add_vport(bridge)
65 (_, vport4_number) = self._vswitch.add_vport(bridge)
67 self._vswitch.del_flow(bridge)
69 # configure flows according to the TC definition
70 flow_template = _FLOW_TEMPLATE.copy()
71 if self._traffic['flow_type'] == 'IP':
72 flow_template.update({'dl_type':'0x0800', 'nw_src':self._traffic['l3']['srcip'],
73 'nw_dst':self._traffic['l3']['dstip']})
75 flow1 = add_ports_to_flow(flow_template, phy1_number,
77 flow2 = add_ports_to_flow(flow_template, vport2_number,
79 flow3 = add_ports_to_flow(flow_template, vport4_number,
81 self._vswitch.add_flow(bridge, flow1)
82 self._vswitch.add_flow(bridge, flow2)
83 self._vswitch.add_flow(bridge, flow3)
85 if self._traffic['bidir']:
86 flow4 = add_ports_to_flow(flow_template, phy2_number,
88 flow5 = add_ports_to_flow(flow_template, vport3_number,
90 flow6 = add_ports_to_flow(flow_template, vport1_number,
92 self._vswitch.add_flow(bridge, flow4)
93 self._vswitch.add_flow(bridge, flow5)
94 self._vswitch.add_flow(bridge, flow6)
101 """Tears down the switch created in setup().
103 self._logger.debug('Stop using ' + str(self._vswitch_class))
109 def __exit__(self, type_, value, traceback):
112 def get_vswitch(self):
113 """See IVswitchController for description
117 def get_ports_info(self):
118 """See IVswitchController for description
120 self._logger.debug('get_ports_info using ' + str(self._vswitch_class))
121 return self._vswitch.get_ports(settings.getValue('VSWITCH_BRIDGE_NAME'))
123 def dump_vswitch_flows(self):
124 """See IVswitchController for description
126 self._vswitch.dump_flows(settings.getValue('VSWITCH_BRIDGE_NAME'))