2 * Copyright (c) 2014, 2015 SDN Hub, LLC. and others. 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
9 package org.opendaylight.ovsdb.openstack.netvirt;
11 import org.opendaylight.neutron.spi.INeutronNetworkCRUD;
12 import org.opendaylight.neutron.spi.INeutronPortCRUD;
13 import org.opendaylight.neutron.spi.INeutronSubnetCRUD;
14 import org.opendaylight.neutron.spi.NeutronNetwork;
15 import org.opendaylight.neutron.spi.NeutronPort;
16 import org.opendaylight.neutron.spi.NeutronSubnet;
17 import org.opendaylight.neutron.spi.Neutron_IPs;
19 import java.util.AbstractMap;
20 import java.util.Iterator;
21 import java.util.List;
24 public class NeutronCacheUtils {
27 * Look up in the NeutronPortsCRUD cache and return the MAC address for a corresponding IP address
28 * @param ipAddr IP address of a member or VM
29 * @return MAC address registered with that IP address
31 public static String getMacAddress(INeutronPortCRUD neutronPortsCache, String subnetID, String ipAddr) {
32 if (ipAddr == null || subnetID == null) {
36 List<Neutron_IPs> fixedIPs;
37 Iterator<Neutron_IPs> fixedIPIterator;
40 List<NeutronPort> allPorts = neutronPortsCache.getAllPorts();
41 Iterator<NeutronPort> i = allPorts.iterator();
43 NeutronPort port = i.next();
44 fixedIPs = port.getFixedIPs();
45 if (fixedIPs != null && fixedIPs.size() > 0) {
46 fixedIPIterator = fixedIPs.iterator();
47 while (fixedIPIterator.hasNext()) {
48 ip = fixedIPIterator.next();
49 if (ip.getIpAddress().equals(ipAddr) && ip.getSubnetUUID().equals(subnetID)) {
50 return port.getMacAddress();
59 * Look up in the NeutronNetworkCRUD cache and NeutronSubnetCRUD cache for
60 * extracting the provider segmentation_type and segmentation_id
61 * @param subnetID Subnet UUID
62 * @return {Type: ID} pair for that subnet ID
64 public static Map.Entry<String,String> getProviderInformation(INeutronNetworkCRUD neutronNetworkCache,
65 INeutronSubnetCRUD neutronSubnetCache, String subnetID) {
67 String networkID = null;
69 List<NeutronSubnet> allSubnets = neutronSubnetCache.getAllSubnets();
70 for (NeutronSubnet subnet: allSubnets) {
71 if (subnet.getID().equals(subnetID)) {
72 networkID = subnet.getNetworkUUID();
76 if (networkID == null) {
80 List<NeutronNetwork> allNetworks = neutronNetworkCache.getAllNetworks();
81 for (NeutronNetwork network: allNetworks) {
82 if (network.getID().equals(networkID)) {
83 Map.Entry<String,String> entry = new AbstractMap.SimpleEntry<String, String>(
84 network.getProviderNetworkType(), network.getProviderSegmentationID());