Set lock_path correctly.
[openstack-build/neutron-build.git] / neutron / plugins / ml2 / drivers / openvswitch / agent / openflow / native / br_dvr_process.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 ryu.lib.packet import ether_types
18 from ryu.lib.packet import icmpv6
19 from ryu.lib.packet import in_proto
20
21
22 class OVSDVRProcessMixin(object):
23     """Common logic for br-tun and br-phys' DVR_PROCESS tables.
24
25     Inheriters should provide self.dvr_process_table_id and
26     self.dvr_process_next_table_id.
27     """
28
29     @staticmethod
30     def _dvr_process_ipv4_match(ofp, ofpp, vlan_tag, gateway_ip):
31         return ofpp.OFPMatch(vlan_vid=vlan_tag | ofp.OFPVID_PRESENT,
32                              eth_type=ether_types.ETH_TYPE_ARP,
33                              arp_tpa=gateway_ip)
34
35     def install_dvr_process_ipv4(self, vlan_tag, gateway_ip):
36         # block ARP
37         (_dp, ofp, ofpp) = self._get_dp()
38         match = self._dvr_process_ipv4_match(ofp, ofpp,
39             vlan_tag=vlan_tag, gateway_ip=gateway_ip)
40         self.install_drop(table_id=self.dvr_process_table_id,
41                           priority=3,
42                           match=match)
43
44     def delete_dvr_process_ipv4(self, vlan_tag, gateway_ip):
45         (_dp, ofp, ofpp) = self._get_dp()
46         match = self._dvr_process_ipv4_match(ofp, ofpp,
47             vlan_tag=vlan_tag, gateway_ip=gateway_ip)
48         self.delete_flows(table_id=self.dvr_process_table_id, match=match)
49
50     @staticmethod
51     def _dvr_process_ipv6_match(ofp, ofpp, vlan_tag, gateway_mac):
52         return ofpp.OFPMatch(vlan_vid=vlan_tag | ofp.OFPVID_PRESENT,
53                              eth_type=ether_types.ETH_TYPE_IPV6,
54                              ip_proto=in_proto.IPPROTO_ICMPV6,
55                              icmpv6_type=icmpv6.ND_ROUTER_ADVERT,
56                              eth_src=gateway_mac)
57
58     def install_dvr_process_ipv6(self, vlan_tag, gateway_mac):
59         # block RA
60         (_dp, ofp, ofpp) = self._get_dp()
61         match = self._dvr_process_ipv6_match(ofp, ofpp,
62             vlan_tag=vlan_tag, gateway_mac=gateway_mac)
63         self.install_drop(table_id=self.dvr_process_table_id, priority=3,
64                           match=match)
65
66     def delete_dvr_process_ipv6(self, vlan_tag, gateway_mac):
67         (_dp, ofp, ofpp) = self._get_dp()
68         match = self._dvr_process_ipv6_match(ofp, ofpp,
69             vlan_tag=vlan_tag, gateway_mac=gateway_mac)
70         self.delete_flows(table_id=self.dvr_process_table_id, match=match)
71
72     @staticmethod
73     def _dvr_process_in_match(ofp, ofpp, vlan_tag, vif_mac):
74         return ofpp.OFPMatch(vlan_vid=vlan_tag | ofp.OFPVID_PRESENT,
75                              eth_dst=vif_mac)
76
77     @staticmethod
78     def _dvr_process_out_match(ofp, ofpp, vlan_tag, vif_mac):
79         return ofpp.OFPMatch(vlan_vid=vlan_tag | ofp.OFPVID_PRESENT,
80                              eth_src=vif_mac)
81
82     def install_dvr_process(self, vlan_tag, vif_mac, dvr_mac_address):
83         (_dp, ofp, ofpp) = self._get_dp()
84         match = self._dvr_process_in_match(ofp, ofpp,
85                                            vlan_tag=vlan_tag, vif_mac=vif_mac)
86         table_id = self.dvr_process_table_id
87         self.install_drop(table_id=table_id,
88                           priority=2,
89                           match=match)
90         match = self._dvr_process_out_match(ofp, ofpp,
91                                             vlan_tag=vlan_tag, vif_mac=vif_mac)
92         actions = [
93             ofpp.OFPActionSetField(eth_src=dvr_mac_address),
94         ]
95         instructions = [
96             ofpp.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, actions),
97             ofpp.OFPInstructionGotoTable(
98                 table_id=self.dvr_process_next_table_id),
99         ]
100         self.install_instructions(table_id=table_id,
101                                   priority=1,
102                                   match=match,
103                                   instructions=instructions)
104
105     def delete_dvr_process(self, vlan_tag, vif_mac):
106         (_dp, ofp, ofpp) = self._get_dp()
107         table_id = self.dvr_process_table_id
108         match = self._dvr_process_in_match(ofp, ofpp,
109                                            vlan_tag=vlan_tag, vif_mac=vif_mac)
110         self.delete_flows(table_id=table_id, match=match)
111         match = self._dvr_process_out_match(ofp, ofpp,
112                                             vlan_tag=vlan_tag, vif_mac=vif_mac)
113         self.delete_flows(table_id=table_id, match=match)