Phaneendra Manda
Committed by Jonathan Hart

[ONOS-4895] Add a method to get VirtualPort based on mac

Change-Id: I3cd6c1ce43f33315f6b73342c6f6393376fff8de
......@@ -20,6 +20,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onosproject.net.DeviceId;
import org.onosproject.vtnrsc.FixedIp;
import org.onosproject.vtnrsc.TenantId;
......@@ -52,6 +53,11 @@ public class VirtualPortAdapter implements VirtualPortService {
}
@Override
public VirtualPort getPort(MacAddress mac) {
return null;
}
@Override
public Collection<VirtualPort> getPorts() {
return null;
}
......
......@@ -18,6 +18,7 @@ package org.onosproject.vtnrsc.virtualport;
import java.util.Collection;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onosproject.event.ListenerService;
import org.onosproject.net.DeviceId;
import org.onosproject.vtnrsc.FixedIp;
......@@ -55,6 +56,14 @@ public interface VirtualPortService extends ListenerService<VirtualPortEvent, Vi
VirtualPort getPort(FixedIp fixedIP);
/**
* Returns the virtualPort associated with the mac address.
*
* @param mac the mac address
* @return virtualPort.
*/
VirtualPort getPort(MacAddress mac);
/**
* Returns the virtualPort associated with the networkId and ip.
*
* @param networkId the TenantNetworkId identifier
......
......@@ -31,6 +31,7 @@ import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onlab.util.KryoNamespace;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
......@@ -79,6 +80,7 @@ implements VirtualPortService {
private static final String NETWORKID_NOT_NULL = "NetworkId cannot be null";
private static final String DEVICEID_NOT_NULL = "DeviceId cannot be null";
private static final String FIXEDIP_NOT_NULL = "FixedIp cannot be null";
private static final String MAC_NOT_NULL = "Mac address cannot be null";
private static final String IP_NOT_NULL = "Ip cannot be null";
private static final String EVENT_NOT_NULL = "event cannot be null";
......@@ -164,6 +166,21 @@ implements VirtualPortService {
}
@Override
public VirtualPort getPort(MacAddress mac) {
checkNotNull(mac, MAC_NOT_NULL);
List<VirtualPort> vPorts = new ArrayList<>();
vPortStore.values().stream().forEach(p -> {
if (p.macAddress().equals(mac)) {
vPorts.add(p);
}
});
if (vPorts.size() == 0) {
return null;
}
return vPorts.get(0);
}
@Override
public VirtualPort getPort(TenantNetworkId networkId, IpAddress ip) {
checkNotNull(networkId, NETWORKID_NOT_NULL);
checkNotNull(ip, IP_NOT_NULL);
......