a3aad0fc7ed24c8a04298e5accd9f054694c05c6
[openstack-build/neutron-build.git] / neutron / plugins / ml2 / drivers / openvswitch / agent / openflow / native / br_phys.py
1 # Copyright (C) 2014,2015 VA Linux Systems Japan K.K.
2 # Copyright (C) 2014,2015 YAMAMOTO Takashi <yamamoto at valinux co jp>
3 # All Rights Reserved.
4 #
5 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
6 #    not use this file except in compliance with the License. You may obtain
7 #    a copy of the License at
8 #
9 #         http://www.apache.org/licenses/LICENSE-2.0
10 #
11 #    Unless required by applicable law or agreed to in writing, software
12 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 #    License for the specific language governing permissions and limitations
15 #    under the License.
16
17 from neutron.plugins.ml2.drivers.openvswitch.agent.common import constants
18 from neutron.plugins.ml2.drivers.openvswitch.agent.openflow.native \
19     import br_dvr_process
20 from neutron.plugins.ml2.drivers.openvswitch.agent.openflow.native \
21     import ovs_bridge
22
23
24 class OVSPhysicalBridge(ovs_bridge.OVSAgentBridge,
25                         br_dvr_process.OVSDVRProcessMixin):
26     """openvswitch agent physical bridge specific logic."""
27
28     # Used by OVSDVRProcessMixin
29     dvr_process_table_id = constants.DVR_PROCESS_VLAN
30     dvr_process_next_table_id = constants.LOCAL_VLAN_TRANSLATION
31
32     def setup_default_table(self):
33         self.delete_flows()
34         self.install_normal()
35
36     @staticmethod
37     def _local_vlan_match(ofp, ofpp, port, lvid):
38         return ofpp.OFPMatch(in_port=port, vlan_vid=lvid | ofp.OFPVID_PRESENT)
39
40     def provision_local_vlan(self, port, lvid, segmentation_id, distributed):
41         table_id = constants.LOCAL_VLAN_TRANSLATION if distributed else 0
42         (_dp, ofp, ofpp) = self._get_dp()
43         match = self._local_vlan_match(ofp, ofpp, port, lvid)
44         if segmentation_id is None:
45             actions = [ofpp.OFPActionPopVlan()]
46         else:
47             vlan_vid = segmentation_id | ofp.OFPVID_PRESENT
48             actions = [ofpp.OFPActionSetField(vlan_vid=vlan_vid)]
49         actions += [ofpp.OFPActionOutput(ofp.OFPP_NORMAL, 0)]
50         self.install_apply_actions(table_id=table_id,
51                                    priority=4,
52                                    match=match,
53                                    actions=actions)
54
55     def reclaim_local_vlan(self, port, lvid):
56         (_dp, ofp, ofpp) = self._get_dp()
57         match = self._local_vlan_match(ofp, ofpp, port, lvid)
58         self.delete_flows(match=match)
59
60     def add_dvr_mac_vlan(self, mac, port):
61         self.install_output(table_id=constants.DVR_NOT_LEARN_VLAN,
62             priority=2, eth_src=mac, port=port)
63
64     def remove_dvr_mac_vlan(self, mac):
65         # REVISIT(yamamoto): match in_port as well?
66         self.delete_flows(table_id=constants.DVR_NOT_LEARN_VLAN,
67             eth_src=mac)