1 # Copyright (c) 2014 Openstack Foundation
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # 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, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
17 from neutron.agent.l3 import dvr_fip_ns
18 from neutron.agent.l3 import dvr_snat_ns
21 # TODO(Carl) Following constants retained to increase SNR during refactoring
22 SNAT_INT_DEV_PREFIX = dvr_snat_ns.SNAT_INT_DEV_PREFIX
23 SNAT_NS_PREFIX = dvr_snat_ns.SNAT_NS_PREFIX
26 class AgentMixin(object):
27 def __init__(self, host):
29 self._fip_namespaces = weakref.WeakValueDictionary()
30 super(AgentMixin, self).__init__(host)
32 def get_fip_ns(self, ext_net_id):
33 # TODO(Carl) is this necessary? Code that this replaced was careful to
34 # convert these to string like this so I preserved that.
35 ext_net_id = str(ext_net_id)
37 fip_ns = self._fip_namespaces.get(ext_net_id)
38 if fip_ns and not fip_ns.destroyed:
41 fip_ns = dvr_fip_ns.FipNamespace(ext_net_id,
45 self._fip_namespaces[ext_net_id] = fip_ns
49 def get_ports_by_subnet(self, subnet_id):
50 return self.plugin_rpc.get_ports_by_subnet(self.context, subnet_id)
52 def _update_arp_entry(self, context, payload, action):
53 router_id = payload['router_id']
54 ri = self.router_info.get(router_id)
58 arp_table = payload['arp_table']
59 ip = arp_table['ip_address']
60 mac = arp_table['mac_address']
61 subnet_id = arp_table['subnet_id']
63 ri._update_arp_entry(ip, mac, subnet_id, action)
65 def add_arp_entry(self, context, payload):
66 """Add arp entry into router namespace. Called from RPC."""
67 self._update_arp_entry(context, payload, 'add')
69 def del_arp_entry(self, context, payload):
70 """Delete arp entry from router namespace. Called from RPC."""
71 self._update_arp_entry(context, payload, 'delete')
73 def fipnamespace_delete_on_ext_net(self, context, ext_net_id):
74 """Delete fip namespace after external network removed."""
75 fip_ns = self.get_fip_ns(ext_net_id)
76 if fip_ns.agent_gateway_port and not fip_ns.destroyed: