2 * Copyright (C) 2014 SDN Hub, LLC.
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 * Authors : Srini Seetharaman
11 package org.opendaylight.ovsdb.openstack.netvirt;
13 import org.opendaylight.neutron.spi.INeutronNetworkCRUD;
14 import org.opendaylight.neutron.spi.INeutronPortCRUD;
15 import org.opendaylight.neutron.spi.INeutronSubnetCRUD;
16 import org.opendaylight.neutron.spi.NeutronNetwork;
17 import org.opendaylight.neutron.spi.NeutronPort;
18 import org.opendaylight.neutron.spi.NeutronSubnet;
19 import org.opendaylight.neutron.spi.Neutron_IPs;
21 import java.util.AbstractMap;
22 import java.util.Iterator;
23 import java.util.List;
26 public class NeutronCacheUtils {
29 * Look up in the NeutronPortsCRUD cache and return the MAC address for a corresponding IP address
30 * @param ipAddr IP address of a member or VM
31 * @return MAC address registered with that IP address
33 public static String getMacAddress(INeutronPortCRUD neutronPortsCache, String subnetID, String ipAddr) {
34 if (ipAddr == null || subnetID == null)
37 List<Neutron_IPs> fixedIPs;
38 Iterator<Neutron_IPs> fixedIPIterator;
41 List<NeutronPort> allPorts = neutronPortsCache.getAllPorts();
42 Iterator<NeutronPort> i = allPorts.iterator();
44 NeutronPort port = i.next();
45 fixedIPs = port.getFixedIPs();
46 if (fixedIPs != null && fixedIPs.size() > 0) {
47 fixedIPIterator = fixedIPs.iterator();
48 while (fixedIPIterator.hasNext()) {
49 ip = fixedIPIterator.next();
50 if (ip.getIpAddress().equals(ipAddr) && ip.getSubnetUUID().equals(subnetID))
51 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)
79 List<NeutronNetwork> allNetworks = neutronNetworkCache.getAllNetworks();
80 for (NeutronNetwork network: allNetworks) {
81 if (network.getID().equals(networkID)) {
82 Map.Entry<String,String> entry = new AbstractMap.SimpleEntry<String, String>(
83 network.getProviderNetworkType(), network.getProviderSegmentationID());