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.ovsdb.openstack.netvirt.translator.NeutronNetwork;
12 import org.opendaylight.ovsdb.openstack.netvirt.translator.NeutronPort;
13 import org.opendaylight.ovsdb.openstack.netvirt.translator.NeutronSubnet;
14 import org.opendaylight.ovsdb.openstack.netvirt.translator.Neutron_IPs;
15 import org.opendaylight.ovsdb.openstack.netvirt.translator.crud.INeutronNetworkCRUD;
16 import org.opendaylight.ovsdb.openstack.netvirt.translator.crud.INeutronPortCRUD;
17 import org.opendaylight.ovsdb.openstack.netvirt.translator.crud.INeutronSubnetCRUD;
19 import java.util.AbstractMap;
20 import java.util.List;
23 public class NeutronCacheUtils {
26 * Look up in the NeutronPortsCRUD cache and return the MAC address for a corresponding IP address
27 * @param neutronPortsCache Reference to port cache to get existing port related data. This interface
28 * basically read data from the md-sal data store.
29 * @param subnetID subnet to which given port is attached
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) {
38 List<NeutronPort> allPorts = neutronPortsCache.getAllPorts();
39 for (NeutronPort port : allPorts) {
40 List<Neutron_IPs> fixedIPs = port.getFixedIPs();
41 if (fixedIPs != null && !fixedIPs.isEmpty()) {
42 for (Neutron_IPs ip : fixedIPs) {
43 if (ip.getIpAddress().equals(ipAddr) && ip.getSubnetUUID().equals(subnetID)) {
44 return port.getMacAddress();
53 * Look up in the NeutronNetworkCRUD cache and NeutronSubnetCRUD cache for
54 * extracting the provider segmentation_type and segmentation_id
55 * @param neutronNetworkCache Reference to neutron network cache to get existing network related data.
56 * This interface basically read data from the md-sal data store.
57 * @param neutronSubnetCache Reference to neutron subnet cache to get existing subnet related data.
58 * This interface basically read data from the md-sal data store.
59 * @param subnetID Subnet UUID
60 * @return {Type: ID} pair for that subnet ID
62 public static Map.Entry<String,String> getProviderInformation(INeutronNetworkCRUD neutronNetworkCache,
63 INeutronSubnetCRUD neutronSubnetCache, String subnetID) {
65 String networkID = null;
67 List<NeutronSubnet> allSubnets = neutronSubnetCache.getAllSubnets();
68 for (NeutronSubnet subnet: allSubnets) {
69 if (subnet.getID().equals(subnetID)) {
70 networkID = subnet.getNetworkUUID();
74 if (networkID == null) {
78 List<NeutronNetwork> allNetworks = neutronNetworkCache.getAllNetworks();
79 for (NeutronNetwork network: allNetworks) {
80 if (network.getID().equals(networkID)) {
81 return new AbstractMap.SimpleEntry<>(
82 network.getProviderNetworkType(), network.getProviderSegmentationID());