1 # Copyright (C) 2014,2015 VA Linux Systems Japan K.K.
2 # Copyright (C) 2014,2015 YAMAMOTO Takashi <yamamoto at valinux co jp>
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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
17 from ryu.lib.packet import ether_types
18 from ryu.lib.packet import icmpv6
19 from ryu.lib.packet import in_proto
22 class OVSDVRProcessMixin(object):
23 """Common logic for br-tun and br-phys' DVR_PROCESS tables.
25 Inheriters should provide self.dvr_process_table_id and
26 self.dvr_process_next_table_id.
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,
35 def install_dvr_process_ipv4(self, vlan_tag, gateway_ip):
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,
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)
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,
58 def install_dvr_process_ipv6(self, vlan_tag, gateway_mac):
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,
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)
73 def _dvr_process_in_match(ofp, ofpp, vlan_tag, vif_mac):
74 return ofpp.OFPMatch(vlan_vid=vlan_tag | ofp.OFPVID_PRESENT,
78 def _dvr_process_out_match(ofp, ofpp, vlan_tag, vif_mac):
79 return ofpp.OFPMatch(vlan_vid=vlan_tag | ofp.OFPVID_PRESENT,
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,
90 match = self._dvr_process_out_match(ofp, ofpp,
91 vlan_tag=vlan_tag, vif_mac=vif_mac)
93 ofpp.OFPActionSetField(eth_src=dvr_mac_address),
96 ofpp.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, actions),
97 ofpp.OFPInstructionGotoTable(
98 table_id=self.dvr_process_next_table_id),
100 self.install_instructions(table_id=table_id,
103 instructions=instructions)
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)