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.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 neutronPortsCache Reference to port cache to get existing port related data. This interface
29 * basically read data from the md-sal data store.
30 * @param subnetID subnet to which given port is attached
31 * @param ipAddr IP address of a member or VM
32 * @return MAC address registered with that IP address
34 public static String getMacAddress(INeutronPortCRUD neutronPortsCache, String subnetID, String ipAddr) {
35 if (ipAddr == null || subnetID == null) {
39 List<Neutron_IPs> fixedIPs;
40 Iterator<Neutron_IPs> fixedIPIterator;
43 List<NeutronPort> allPorts = neutronPortsCache.getAllPorts();
44 Iterator<NeutronPort> i = allPorts.iterator();
46 NeutronPort port = i.next();
47 fixedIPs = port.getFixedIPs();
48 if (fixedIPs != null && fixedIPs.size() > 0) {
49 fixedIPIterator = fixedIPs.iterator();
50 while (fixedIPIterator.hasNext()) {
51 ip = fixedIPIterator.next();
52 if (ip.getIpAddress().equals(ipAddr) && ip.getSubnetUUID().equals(subnetID)) {
53 return port.getMacAddress();
62 * Look up in the NeutronNetworkCRUD cache and NeutronSubnetCRUD cache for
63 * extracting the provider segmentation_type and segmentation_id
64 * @param neutronNetworkCache Reference to neutron network cache to get existing network related data.
65 * This interface basically read data from the md-sal data store.
66 * @param neutronSubnetCache Reference to neutron subnet cache to get existing subnet related data.
67 * This interface basically read data from the md-sal data store.
68 * @param subnetID Subnet UUID
69 * @return {Type: ID} pair for that subnet ID
71 public static Map.Entry<String,String> getProviderInformation(INeutronNetworkCRUD neutronNetworkCache,
72 INeutronSubnetCRUD neutronSubnetCache, String subnetID) {
74 String networkID = null;
76 List<NeutronSubnet> allSubnets = neutronSubnetCache.getAllSubnets();
77 for (NeutronSubnet subnet: allSubnets) {
78 if (subnet.getID().equals(subnetID)) {
79 networkID = subnet.getNetworkUUID();
83 if (networkID == null) {
87 List<NeutronNetwork> allNetworks = neutronNetworkCache.getAllNetworks();
88 for (NeutronNetwork network: allNetworks) {
89 if (network.getID().equals(networkID)) {
90 Map.Entry<String,String> entry = new AbstractMap.SimpleEntry<String, String>(
91 network.getProviderNetworkType(), network.getProviderSegmentationID());