Committed by
Ray Milkey
[ONOS-3188] Add the method: Returns the virtualPort associated with the
fixedIP. Change-Id: I4f66287a4186cc103070c9182dae64f81fcd6488
Showing
2 changed files
with
32 additions
and
0 deletions
| ... | @@ -18,6 +18,7 @@ package org.onosproject.vtnrsc.virtualport; | ... | @@ -18,6 +18,7 @@ package org.onosproject.vtnrsc.virtualport; |
| 18 | import java.util.Collection; | 18 | import java.util.Collection; |
| 19 | 19 | ||
| 20 | import org.onosproject.net.DeviceId; | 20 | import org.onosproject.net.DeviceId; |
| 21 | +import org.onosproject.vtnrsc.FixedIp; | ||
| 21 | import org.onosproject.vtnrsc.TenantId; | 22 | import org.onosproject.vtnrsc.TenantId; |
| 22 | import org.onosproject.vtnrsc.TenantNetworkId; | 23 | import org.onosproject.vtnrsc.TenantNetworkId; |
| 23 | import org.onosproject.vtnrsc.VirtualPort; | 24 | import org.onosproject.vtnrsc.VirtualPort; |
| ... | @@ -44,6 +45,14 @@ public interface VirtualPortService { | ... | @@ -44,6 +45,14 @@ public interface VirtualPortService { |
| 44 | VirtualPort getPort(VirtualPortId virtualPortId); | 45 | VirtualPort getPort(VirtualPortId virtualPortId); |
| 45 | 46 | ||
| 46 | /** | 47 | /** |
| 48 | + * Returns the virtualPort associated with the fixedIP. | ||
| 49 | + * | ||
| 50 | + * @param fixedIP the fixedIP identifier | ||
| 51 | + * @return virtualPort. | ||
| 52 | + */ | ||
| 53 | + VirtualPort getPort(FixedIp fixedIP); | ||
| 54 | + | ||
| 55 | + /** | ||
| 47 | * Returns the collection of the currently known virtualPort. | 56 | * Returns the collection of the currently known virtualPort. |
| 48 | * @return collection of VirtualPort. | 57 | * @return collection of VirtualPort. |
| 49 | */ | 58 | */ | ... | ... |
| ... | @@ -17,9 +17,12 @@ package org.onosproject.vtnrsc.virtualport.impl; | ... | @@ -17,9 +17,12 @@ package org.onosproject.vtnrsc.virtualport.impl; |
| 17 | 17 | ||
| 18 | import static com.google.common.base.Preconditions.checkNotNull; | 18 | import static com.google.common.base.Preconditions.checkNotNull; |
| 19 | 19 | ||
| 20 | +import java.util.ArrayList; | ||
| 20 | import java.util.Arrays; | 21 | import java.util.Arrays; |
| 21 | import java.util.Collection; | 22 | import java.util.Collection; |
| 22 | import java.util.Collections; | 23 | import java.util.Collections; |
| 24 | +import java.util.Iterator; | ||
| 25 | +import java.util.List; | ||
| 23 | import java.util.Map; | 26 | import java.util.Map; |
| 24 | import java.util.stream.Collectors; | 27 | import java.util.stream.Collectors; |
| 25 | 28 | ||
| ... | @@ -68,6 +71,7 @@ public class VirtualPortManager implements VirtualPortService { | ... | @@ -68,6 +71,7 @@ public class VirtualPortManager implements VirtualPortService { |
| 68 | private static final String TENANTID_NOT_NULL = "TenantId cannot be null"; | 71 | private static final String TENANTID_NOT_NULL = "TenantId cannot be null"; |
| 69 | private static final String NETWORKID_NOT_NULL = "NetworkId cannot be null"; | 72 | private static final String NETWORKID_NOT_NULL = "NetworkId cannot be null"; |
| 70 | private static final String DEVICEID_NOT_NULL = "DeviceId cannot be null"; | 73 | private static final String DEVICEID_NOT_NULL = "DeviceId cannot be null"; |
| 74 | + private static final String FIXEDIP_NOT_NULL = "FixedIp cannot be null"; | ||
| 71 | 75 | ||
| 72 | protected Map<VirtualPortId, VirtualPort> vPortStore; | 76 | protected Map<VirtualPortId, VirtualPort> vPortStore; |
| 73 | protected ApplicationId appId; | 77 | protected ApplicationId appId; |
| ... | @@ -125,6 +129,25 @@ public class VirtualPortManager implements VirtualPortService { | ... | @@ -125,6 +129,25 @@ public class VirtualPortManager implements VirtualPortService { |
| 125 | } | 129 | } |
| 126 | 130 | ||
| 127 | @Override | 131 | @Override |
| 132 | + public VirtualPort getPort(FixedIp fixedIP) { | ||
| 133 | + checkNotNull(fixedIP, FIXEDIP_NOT_NULL); | ||
| 134 | + List<VirtualPort> vPorts = new ArrayList<>(); | ||
| 135 | + vPortStore.values().stream().forEach(p -> { | ||
| 136 | + Iterator<FixedIp> fixedIps = p.fixedIps().iterator(); | ||
| 137 | + while (fixedIps.hasNext()) { | ||
| 138 | + if (fixedIps.next().equals(fixedIP)) { | ||
| 139 | + vPorts.add(p); | ||
| 140 | + break; | ||
| 141 | + } | ||
| 142 | + } | ||
| 143 | + }); | ||
| 144 | + if (vPorts.size() == 0) { | ||
| 145 | + return null; | ||
| 146 | + } | ||
| 147 | + return vPorts.get(0); | ||
| 148 | + } | ||
| 149 | + | ||
| 150 | + @Override | ||
| 128 | public Collection<VirtualPort> getPorts() { | 151 | public Collection<VirtualPort> getPorts() { |
| 129 | return Collections.unmodifiableCollection(vPortStore.values()); | 152 | return Collections.unmodifiableCollection(vPortStore.values()); |
| 130 | } | 153 | } | ... | ... |
-
Please register or login to post a comment