2 * Copyright (c) 2016 Cisco Systems, Inc. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.lispflowmapping.neutron;
11 import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
12 import org.opendaylight.lispflowmapping.neutron.mappingmanager.HostInformationManager;
13 import org.opendaylight.lispflowmapping.neutron.mappingmanager.PortData;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.InstanceIdType;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.binding.rev150712.PortBindingExtension;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIpsKey;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
24 * Lisp Service implementation of NeutronPortAware API Creation of a new port
25 * results adding the mapping for the port's IP addresses to the port's host_ip
26 * in the mapping service. Currently the NetronPort object does not carry the
27 * required information to achieve the port's host_ip. Once such extension is
28 * available this class shall be updated.
30 * @author Vina Ermagan
33 public class PortDataProcessor implements DataProcessor<Port> {
34 private static final Logger LOG = LoggerFactory.getLogger(PortDataProcessor.class);
36 // The implementation for each of these services is resolved by the OSGi
38 private volatile ILispNeutronService lispNeutronService;
40 private final HostInformationManager hostInformationManager = HostInformationManager.getInstance();
42 public PortDataProcessor(ILispNeutronService lispNeutronService) {
43 this.lispNeutronService = lispNeutronService;
47 public void create(Port port) {
48 // TODO Consider adding Port MAC -> Port fixed IP in MS
49 // host_ip exists in MS
51 LOG.debug("Neutron Port Created : " + port.toString());
53 final String hostId = port.augmentation(PortBindingExtension.class).getHostId();
55 LOG.error("Adding new Neutron port to lisp mapping service failed. Port does not have a HostID. Port: {}",
60 Map<FixedIpsKey, FixedIps> fixedIPs = port.nonnullFixedIps();
61 if (fixedIPs != null && fixedIPs.size() > 0) {
63 for (FixedIps ip : fixedIPs.values()) {
65 // TODO Add check/support for IPv6.
66 // Get subnet for this port, based on v4 or v6 decide address
68 eidAddress = getEid(port, ip);
69 PortData portData = new PortData(port.getUuid().getValue(), eidAddress);
70 hostInformationManager.addHostRelatedInfo(hostId, portData);
74 LOG.info("Neutron Port Created: Port name: "
77 + (port.getFixedIps() != null ? port.getFixedIps().values().iterator().next()
78 : "No Fixed IP assigned"));
81 private Eid getEid(Port port, FixedIps ip) {
82 InstanceIdType vni = new InstanceIdType(hostInformationManager
83 .getInstanceId(port.getTenantId().getValue()));
84 return LispAddressUtil.asIpv4PrefixEid(ip.getIpAddress().getIpv4Address(), vni);
88 public void update(Port port) {
90 final String hostId = port.augmentation(PortBindingExtension.class).getHostId();
92 LOG.error("Updating port to lisp mapping service failed. Port does not have a HostID. Port: {}",
97 Map<FixedIpsKey, FixedIps> fixedIPs = port.getFixedIps();
98 if (fixedIPs != null && fixedIPs.size() > 0) {
100 for (FixedIps ip : fixedIPs.values()) {
102 eidAddress = getEid(port, ip);
104 PortData portData = new PortData(port.getUuid().getValue(), eidAddress);
105 hostInformationManager.addHostRelatedInfo(hostId, portData);
109 LOG.info("Neutron Port updated: Port name: "
112 + (port.getFixedIps() != null ? port.getFixedIps().values().iterator().next()
113 : "No Fixed IP assigned"));
114 LOG.debug("Neutron Port Updated : " + port.toString());
118 public void delete(Port port) {
119 // TODO if port ips existed in MapServer, delete them. Else, log error.
121 LOG.info("Neutron Port Deleted: Port name: "
124 + (port.getFixedIps() != null ? port.getFixedIps().values().iterator().next()
125 : "No Fixed IP assigned"));
126 LOG.debug("Neutron Port Deleted : " + port.toString());
128 Map<FixedIpsKey, FixedIps> fixedIPs = port.getFixedIps();
129 if (fixedIPs != null && fixedIPs.size() > 0) {
132 for (FixedIps ip : fixedIPs.values()) {
134 // TODO Add check/support for IPv6.
135 // Get subnet for this port, based on v4 or v6 decide address
138 eidAddress = LispAddressUtil.asIpv4PrefixEid(ip.getIpAddress().getIpv4Address().getValue() + "/32");
139 lispNeutronService.getMappingDbService().removeMapping(LispUtil.buildRemoveMappingInput(eidAddress));
141 LOG.info("Neutron Port mapping deleted from lisp: "
142 + " Port Fixed IP: " + ip + "Port host IP: ");