X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openstack%2Fnet-virt%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fovsdb%2Fopenstack%2Fnetvirt%2FNeutronCacheUtils.java;fp=openstack%2Fnet-virt%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fovsdb%2Fopenstack%2Fnetvirt%2FNeutronCacheUtils.java;h=3b893d9a385679df74aa75ac38ff94338645aad5;hb=f2870c93f4e0f4e448ac73fbded218cd84c3fc2d;hp=0000000000000000000000000000000000000000;hpb=b9694f5f24e4bfde00dabba09b231bcc324a7215;p=ovsdb.git diff --git a/openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/NeutronCacheUtils.java b/openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/NeutronCacheUtils.java new file mode 100755 index 000000000..3b893d9a3 --- /dev/null +++ b/openstack/net-virt/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/NeutronCacheUtils.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2014 SDN Hub, LLC. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Authors : Srini Seetharaman + */ + +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 java.util.Iterator; +import java.util.List; + +public class NeutronCacheUtils { + + /** + * Look up in the NeutronPortsCRUD cache and return the MAC address for a corresponding IP address + * @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) { + List fixedIPs; + Iterator fixedIPIterator; + Neutron_IPs ip; + + List allPorts = neutronPortsCache.getAllPorts(); + Iterator i = allPorts.iterator(); + while (i.hasNext()) { + NeutronPort port = i.next(); + fixedIPs = port.getFixedIPs(); + if (fixedIPs != null && fixedIPs.size() > 0) { + fixedIPIterator = fixedIPs.iterator(); + while (fixedIPIterator.hasNext()) { + ip = fixedIPIterator.next(); + if (ip.getIpAddress().equals(ipAddr)) + return port.getMacAddress(); + } + } + } + return null; + } +}