diff options
Diffstat (limited to 'framework/src/onos/apps/vtn')
2 files changed, 32 insertions, 0 deletions
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/virtualport/VirtualPortService.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/virtualport/VirtualPortService.java index 05ebccf9..0a3ea2cd 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/virtualport/VirtualPortService.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/virtualport/VirtualPortService.java @@ -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. */ diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/virtualport/impl/VirtualPortManager.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/virtualport/impl/VirtualPortManager.java index 926809c9..c45373b9 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/virtualport/impl/VirtualPortManager.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/virtualport/impl/VirtualPortManager.java @@ -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()); } |