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

Change-Id: I3cd6c1ce43f33315f6b73342c6f6393376fff8de
This commit is contained in:
Phaneendra Manda 2016-07-15 19:47:51 +05:30 committed by Jonathan Hart
parent 65040997b2
commit bd09d6e07e
3 changed files with 32 additions and 0 deletions

View File

@ -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;
@ -51,6 +52,11 @@ public class VirtualPortAdapter implements VirtualPortService {
return null;
}
@Override
public VirtualPort getPort(MacAddress mac) {
return null;
}
@Override
public Collection<VirtualPort> getPorts() {
return null;

View File

@ -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;
@ -54,6 +55,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.
*

View File

@ -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";
@ -163,6 +165,21 @@ implements VirtualPortService {
return vPorts.get(0);
}
@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);