lishuai
Committed by Ray Milkey

[ONOS-3188] Add the method: Returns the virtualPort associated with the

fixedIP.

Change-Id: I4f66287a4186cc103070c9182dae64f81fcd6488
......@@ -18,6 +18,7 @@ package org.onosproject.vtnrsc.virtualport;
import java.util.Collection;
import org.onosproject.net.DeviceId;
import org.onosproject.vtnrsc.FixedIp;
import org.onosproject.vtnrsc.TenantId;
import org.onosproject.vtnrsc.TenantNetworkId;
import org.onosproject.vtnrsc.VirtualPort;
......@@ -44,6 +45,14 @@ public interface VirtualPortService {
VirtualPort getPort(VirtualPortId virtualPortId);
/**
* Returns the virtualPort associated with the fixedIP.
*
* @param fixedIP the fixedIP identifier
* @return virtualPort.
*/
VirtualPort getPort(FixedIp fixedIP);
/**
* Returns the collection of the currently known virtualPort.
* @return collection of VirtualPort.
*/
......
......@@ -17,9 +17,12 @@ package org.onosproject.vtnrsc.virtualport.impl;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
......@@ -68,6 +71,7 @@ public class VirtualPortManager implements VirtualPortService {
private static final String TENANTID_NOT_NULL = "TenantId cannot be null";
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";
protected Map<VirtualPortId, VirtualPort> vPortStore;
protected ApplicationId appId;
......@@ -125,6 +129,25 @@ public class VirtualPortManager implements VirtualPortService {
}
@Override
public VirtualPort getPort(FixedIp fixedIP) {
checkNotNull(fixedIP, FIXEDIP_NOT_NULL);
List<VirtualPort> vPorts = new ArrayList<>();
vPortStore.values().stream().forEach(p -> {
Iterator<FixedIp> fixedIps = p.fixedIps().iterator();
while (fixedIps.hasNext()) {
if (fixedIps.next().equals(fixedIP)) {
vPorts.add(p);
break;
}
}
});
if (vPorts.size() == 0) {
return null;
}
return vPorts.get(0);
}
@Override
public Collection<VirtualPort> getPorts() {
return Collections.unmodifiableCollection(vPortStore.values());
}
......