package org.opendaylight.ovsdb.openstack.netvirt;
-import org.opendaylight.controller.networkconfig.neutron.INeutronPortCRUD;
-import org.opendaylight.controller.networkconfig.neutron.NeutronPort;
-import org.opendaylight.controller.networkconfig.neutron.Neutron_IPs;
+import org.opendaylight.neutron.spi.INeutronNetworkCRUD;
+import org.opendaylight.neutron.spi.INeutronPortCRUD;
+import org.opendaylight.neutron.spi.INeutronSubnetCRUD;
+import org.opendaylight.neutron.spi.NeutronNetwork;
+import org.opendaylight.neutron.spi.NeutronPort;
+import org.opendaylight.neutron.spi.NeutronSubnet;
+import org.opendaylight.neutron.spi.Neutron_IPs;
+
+import java.util.AbstractMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
public class NeutronCacheUtils {
* @param ipAddr IP address of a member or VM
* @return MAC address registered with that IP address
*/
- public static String getMacAddress(INeutronPortCRUD neutronPortsCache, String ipAddr) {
- if (ipAddr == null)
+ public static String getMacAddress(INeutronPortCRUD neutronPortsCache, String subnetID, String ipAddr) {
+ if (ipAddr == null || subnetID == null) {
return null;
+ }
List<Neutron_IPs> fixedIPs;
Iterator<Neutron_IPs> fixedIPIterator;
fixedIPIterator = fixedIPs.iterator();
while (fixedIPIterator.hasNext()) {
ip = fixedIPIterator.next();
- if (ip.getIpAddress().equals(ipAddr))
+ if (ip.getIpAddress().equals(ipAddr) && ip.getSubnetUUID().equals(subnetID)) {
return port.getMacAddress();
+ }
}
}
}
return null;
}
+
+ /**
+ * Look up in the NeutronNetworkCRUD cache and NeutronSubnetCRUD cache for
+ * extracting the provider segmentation_type and segmentation_id
+ * @param subnetID Subnet UUID
+ * @return {Type: ID} pair for that subnet ID
+ */
+ public static Map.Entry<String,String> getProviderInformation(INeutronNetworkCRUD neutronNetworkCache,
+ INeutronSubnetCRUD neutronSubnetCache, String subnetID) {
+
+ String networkID = null;
+
+ List<NeutronSubnet> allSubnets = neutronSubnetCache.getAllSubnets();
+ for (NeutronSubnet subnet: allSubnets) {
+ if (subnet.getID().equals(subnetID)) {
+ networkID = subnet.getNetworkUUID();
+ break;
+ }
+ }
+ if (networkID == null) {
+ return null;
+ }
+
+ List<NeutronNetwork> allNetworks = neutronNetworkCache.getAllNetworks();
+ for (NeutronNetwork network: allNetworks) {
+ if (network.getID().equals(networkID)) {
+ Map.Entry<String,String> entry = new AbstractMap.SimpleEntry<String, String>(
+ network.getProviderNetworkType(), network.getProviderSegmentationID());
+ return entry;
+ }
+ }
+ return null;
+ }
}