package org.opendaylight.groupbasedpolicy.renderer.util;
import java.util.List;
+import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.absolute.location.LocationType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.absolute.location.location.type.ExternalLocationCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.absolute.location.location.type.InternalLocationCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.relative.location.RelativeLocations;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import com.google.common.base.Optional;
// hiding default public constructor
private EndpointLocationUtils() {}
- public static ImmutableMultimap<InstanceIdentifier<?>, AddressEndpointLocation> resolveEndpointsByAbsoluteNodeLocation(
+ /**
+ * Resolves address endpoint locations by nodes. Address endpoint should have either an absolute location or a
+ * relative location which reflects multihome endpoints.
+ */
+ public static ImmutableMultimap<InstanceIdentifier<?>, AddressEndpointLocation> resolveEndpointsByExternalNodeLocation(
@Nullable List<AddressEndpointLocation> addressEndpointLocations) {
if (addressEndpointLocations == null) {
return ImmutableMultimap.of();
Optional<InstanceIdentifier<?>> potentialAbsIntNodeLocation = resolveAbsoluteInternalNodeLocation(epLoc);
if (potentialAbsIntNodeLocation.isPresent()) {
resultBuilder.put(potentialAbsIntNodeLocation.get(), epLoc);
- } else {
- Optional<InstanceIdentifier<?>> potentialAbsExtNodeMpLocation =
- resolveAbsoluteExternalNodeMountPointLocation(epLoc);
- if (potentialAbsExtNodeMpLocation.isPresent()) {
- resultBuilder.put(potentialAbsExtNodeMpLocation.get(), epLoc);
+ continue;
+ }
+ Optional<InstanceIdentifier<?>> potentialAbsExtNodeMpLocation =
+ resolveAbsoluteExternalNodeMountPointLocation(epLoc);
+ if (potentialAbsExtNodeMpLocation.isPresent()) {
+ resultBuilder.put(potentialAbsExtNodeMpLocation.get(), epLoc);
+ continue;
+ }
+ Optional<List<InstanceIdentifier<?>>> potentialRelExtNodeMpLocation =
+ resolveRelativeExternalNodeMountPointLocation(epLoc);
+ if (potentialRelExtNodeMpLocation.isPresent()) {
+ for (InstanceIdentifier<?> iid : potentialRelExtNodeMpLocation.get()) {
+ resultBuilder.put(iid, epLoc);
}
}
}
return Optional.absent();
}
+ public static Optional<List<InstanceIdentifier<?>>> resolveRelativeExternalNodeMountPointLocation(
+ AddressEndpointLocation epLoc) {
+ RelativeLocations relativeLocations = epLoc.getRelativeLocations();
+ if (relativeLocations != null) {
+ List<InstanceIdentifier<?>> mountPoints = relativeLocations.getExternalLocation()
+ .stream()
+ .map(externalLocation -> externalLocation.getExternalNodeMountPoint())
+ .collect(Collectors.toList());
+ return (mountPoints.isEmpty()) ? Optional.absent() : Optional.of(mountPoints);
+ }
+ return Optional.absent();
+ }
+
public static Optional<InstanceIdentifier<?>> resolveAbsoluteNodeLocation(AddressEndpointLocation epLoc) {
if (epLoc.getAbsoluteLocation() == null) {
return Optional.absent();