@Nonnull static <T extends Identifier> List<T> getAllIpv4AddressIds( final Optional<IpAddressDetailsReplyDump> dumpOptional, @Nonnull final Function<Ipv4AddressNoZone, T> keyConstructor) { if (dumpOptional.isPresent() && dumpOptional.get().ipAddressDetails != null) { return dumpOptional.get().ipAddressDetails.stream() .map(detail -> keyConstructor.apply(TranslateUtils.arrayToIpv4AddressNoZone(detail.ip))) .collect(Collectors.toList()); } else { return Collections.emptyList(); } }
static Optional<IpAddressDetails> findIpAddressDetailsByIp( final Optional<IpAddressDetailsReplyDump> dump, @Nonnull final Ipv4AddressNoZone ip) { checkNotNull(ip, "ip address should not be null"); if (dump.isPresent() && dump.get().ipAddressDetails != null) { final List<IpAddressDetails> details = dump.get().ipAddressDetails; return Optional.of(details.stream() .filter(singleDetail -> ip.equals(TranslateUtils.arrayToIpv4AddressNoZone(singleDetail.ip))) .collect(RWUtils.singleItemCollector())); } return Optional.absent(); }
/** * Converts byte array to {@link Ipv4Prefix} with specified prefixLength */ public static Ipv4Prefix arrayToIpv4Prefix(final byte[] address, byte prefixLength) { Ipv4AddressNoZone addressPart = arrayToIpv4AddressNoZone(address); return new Ipv4Prefix(addressPart.getValue().concat("/").concat(String.valueOf(prefixLength))); }
/** * Converts array bytes to {@link IpAddress} */ @Nonnull public static IpAddress arrayToIpAddress(boolean isIpv6, byte[] ip) { if (isIpv6) { return new IpAddress(arrayToIpv6AddressNoZone(ip)); } else { return new IpAddress(arrayToIpv4AddressNoZone(ip)); } }
@Override public void readCurrentAttributes(@Nonnull InstanceIdentifier<Address> id, @Nonnull AddressBuilder builder, @Nonnull ReadContext ctx) throws ReadFailedException { LOG.debug("Reading attributes for sub-interface address: {}", id); final String subInterfaceName = getSubInterfaceName(id); final int subInterfaceIndex = interfaceContext.getIndex(subInterfaceName, ctx.getMappingContext()); final Optional<IpAddressDetailsReplyDump> dumpOptional = dumpAddresses(getFutureJVpp(), id, subInterfaceName, subInterfaceIndex, ctx); final Optional<IpAddressDetails> ipAddressDetails = findIpAddressDetailsByIp(dumpOptional, id.firstKeyOf(Address.class).getIp()); if (ipAddressDetails.isPresent()) { final IpAddressDetails detail = ipAddressDetails.get(); builder.setIp(TranslateUtils.arrayToIpv4AddressNoZone(detail.ip)) .setSubnet(new PrefixLengthBuilder().setPrefixLength(Short.valueOf(detail.prefixLength)).build()); if (LOG.isDebugEnabled()) { LOG.debug("Attributes for {} sub-interface (id={}) address {} successfully read: {}", subInterfaceName, subInterfaceIndex, id, builder.build()); } } }
@Override public void readCurrentAttributes(@Nonnull InstanceIdentifier<Address> id, @Nonnull AddressBuilder builder, @Nonnull ReadContext ctx) throws ReadFailedException { LOG.debug("Reading attributes for interface address: {}", id); final String interfaceName = id.firstKeyOf(Interface.class).getName(); final int interfaceIndex = interfaceContext.getIndex(interfaceName, ctx.getMappingContext()); final Optional<IpAddressDetailsReplyDump> dumpOptional = dumpAddresses(getFutureJVpp(), id, interfaceName, interfaceIndex, ctx); final Optional<IpAddressDetails> ipAddressDetails = findIpAddressDetailsByIp(dumpOptional, id.firstKeyOf(Address.class).getIp()); if (ipAddressDetails.isPresent()) { final IpAddressDetails detail = ipAddressDetails.get(); builder.setIp(TranslateUtils.arrayToIpv4AddressNoZone(detail.ip)) .setSubnet(new PrefixLengthBuilder().setPrefixLength(Short.valueOf(detail.prefixLength)).build()); if (LOG.isDebugEnabled()) { LOG.debug("Attributes for {} interface (id={}) address {} successfully read: {}", interfaceName, interfaceIndex, id, builder.build()); } } }