private static Optional<IpAddressDetailsReplyDump> dumpAddressFromOperationalData( @Nonnull final FutureJVppCore futureJVppCore, @Nonnull final InstanceIdentifier<?> id, final int interfaceIndex) throws VppBaseCallException, ReadTimeoutException { LOG.debug("Dumping Ipv4 addresses for interface id={}", interfaceIndex); final IpAddressDump dumpRequest = new IpAddressDump(); dumpRequest.isIpv6 = 0; dumpRequest.swIfIndex = interfaceIndex; return Optional.fromNullable( TranslateUtils.getReplyForRead(futureJVppCore.ipAddressDump(dumpRequest).toCompletableFuture(), id)); }
private void createClassifySession(@Nonnull final InstanceIdentifier<?> id, @Nonnull final ClassifyAddDelSession request) throws VppBaseCallException, WriteTimeoutException { final CompletionStage<ClassifyAddDelSessionReply> cs = futureJVppCore.classifyAddDelSession(request); TranslateUtils.getReplyForWrite(cs.toCompletableFuture(), id); }
@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(); } }
public static IpAddress reverseAddress(@Nonnull final IpAddress address) { //arrayToIpAdddress internaly reverts order return arrayToIpAddress(isIpv6(address), ipAddressToArray(address)); } }
public static <REP extends JVppReply<?>> REP getReplyForRead(@Nonnull Future<REP> future, @Nonnull final InstanceIdentifier<?> replyType, @Nonnegative final int timeoutInSeconds) throws VppBaseCallException, ReadTimeoutException { try { return getReply(future, timeoutInSeconds); } catch (TimeoutException e) { throw new ReadTimeoutException(replyType, e); } }
public static <REP extends JVppReply<?>> REP getReplyForWrite(@Nonnull Future<REP> future, @Nonnull final InstanceIdentifier<?> replyType, @Nonnegative final int timeoutInSeconds) throws VppBaseCallException, WriteTimeoutException { try { return getReply(future, timeoutInSeconds); } catch (TimeoutException e) { throw new WriteTimeoutException(replyType, e); } }
private void addDelNeighbourAndReply(InstanceIdentifier<Neighbor> id, boolean add, int parentInterfaceIndex, Neighbor data) throws VppBaseCallException, WriteTimeoutException { IpNeighborAddDel request = new IpNeighborAddDel(); request.isAdd = TranslateUtils.booleanToByte(add); request.isIpv6 = 0; request.isStatic = 1; request.dstAddress = TranslateUtils.ipv4AddressNoZoneToArray(data.getIp()); request.macAddress = TranslateUtils.parseMac(data.getLinkLayerAddress().getValue()); request.swIfIndex = parentInterfaceIndex; //TODO if it is necessary for future use ,make adjustments to be able to set vrfid //request.vrfId TranslateUtils.getReplyForWrite(getFutureJVpp().ipNeighborAddDel(request).toCompletableFuture(), id); } }
static void addDelAddress(@Nonnull final FutureJVppCore futureJVppCore, final boolean add, final InstanceIdentifier<?> id, @Nonnegative final int ifaceId, @Nonnull final Ipv4AddressNoZone address, @Nonnegative final byte prefixLength) throws VppBaseCallException, WriteTimeoutException { checkArgument(prefixLength > 0, "Invalid prefix length"); checkNotNull(address, "address should not be null"); final byte[] addressBytes = TranslateUtils.ipv4AddressNoZoneToArray(address); final CompletionStage<SwInterfaceAddDelAddressReply> swInterfaceAddDelAddressReplyCompletionStage = futureJVppCore.swInterfaceAddDelAddress( getSwInterfaceAddDelAddressRequest(ifaceId, TranslateUtils.booleanToByte(add) /* isAdd */, (byte) 0 /* isIpv6 */, (byte) 0 /* delAll */, prefixLength, addressBytes)); TranslateUtils.getReplyForWrite(swInterfaceAddDelAddressReplyCompletionStage.toCompletableFuture(), id); }
private BridgeDomainAddDelReply addOrUpdateBridgeDomain(@Nonnull final InstanceIdentifier<BridgeDomain> id, final int bdId, @Nonnull final BridgeDomain bd) throws VppBaseCallException, WriteTimeoutException { final BridgeDomainAddDelReply reply; final BridgeDomainAddDel request = new BridgeDomainAddDel(); request.bdId = bdId; request.flood = booleanToByte(bd.isFlood()); request.forward = booleanToByte(bd.isForward()); request.learn = booleanToByte(bd.isLearn()); request.uuFlood = booleanToByte(bd.isUnknownUnicastFlood()); request.arpTerm = booleanToByte(bd.isArpTermination()); request.isAdd = ADD_OR_UPDATE_BD; reply = TranslateUtils.getReplyForWrite(getFutureJVpp().bridgeDomainAddDel(request).toCompletableFuture(), id); LOG.debug("Bridge domain {} (id={}) add/update successful", bd.getName(), bdId); return reply; }
@Override public void readCurrentAttributes(@Nonnull InstanceIdentifier<Version> id, @Nonnull final VersionBuilder builder, @Nonnull final ReadContext context) throws ReadFailedException { try { // Execute with timeout final CompletionStage<ShowVersionReply> showVersionFuture = getFutureJVpp().showVersion(new ShowVersion()); final ShowVersionReply reply = TranslateUtils.getReplyForRead(showVersionFuture.toCompletableFuture(), id); builder.setBranch(TranslateUtils.toString(reply.version)); builder.setName(TranslateUtils.toString(reply.program)); builder.setBuildDate(TranslateUtils.toString(reply.buildDate)); builder.setBuildDirectory(TranslateUtils.toString(reply.buildDirectory)); } catch (VppBaseCallException e) { throw new ReadFailedException(id, e); } }
private L2FibAddDel createL2FibRequest(final L2FibEntry entry, final int bdId, final int swIfIndex, boolean isAdd) { final L2FibAddDel request = new L2FibAddDel(); request.mac = macToLong(entry.getPhysAddress().getValue()); request.bdId = bdId; request.swIfIndex = swIfIndex; request.isAdd = booleanToByte(isAdd); if (isAdd) { request.staticMac = booleanToByte(entry.isStaticConfig()); request.filterMac = booleanToByte(L2FibFilter.class == entry.getAction()); } return request; }
private BdIpMacAddDel createRequest(final ArpTerminationTableEntry entry, final int bdId, boolean isAdd) { final BdIpMacAddDel request = new BdIpMacAddDel(); request.bdId = bdId; request.isAdd = booleanToByte(isAdd); request.macAddress = TranslateUtils.parseMac(entry.getPhysAddress().getValue()); final IpAddress ipAddress = entry.getIpAddress(); if (ipAddress.getIpv6Address() != null) { // FIXME: vpp does not support ipv6 in arp-termination table (based on analysis of l2_bd.c) throw new UnsupportedOperationException("IPv6 address for ARP termination table is not supported yet"); } request.ipAddress = TranslateUtils.ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(ipAddress.getIpv4Address())); return request; } }
public static final byte[] ipAddressToArray(IpAddress address) { checkNotNull(address, "Cannot resolve null adddress"); if (isIpv6(address)) { return ipv6AddressNoZoneToArray(new Ipv6AddressNoZone(address.getIpv6Address())); } else { return ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(address.getIpv4Address())); } }
/** * 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)); } }
/** * Converts {@link IpAddress} to array representing {@link Ipv4Address} or {@link Ipv6Address} */ public static byte[] ipAddressToArray(boolean isIpv6, @Nonnull IpAddress address) { checkNotNull(address, "Cannot convert null Address"); if (isIpv6) { return ipv6AddressNoZoneToArray(new Ipv6AddressNoZone(address.getIpv6Address())); } else { return ipv4AddressNoZoneToArray(new Ipv4AddressNoZone(address.getIpv4Address())); } }
/** * Transform Ipv4 address to a byte array acceptable by VPP. VPP expects incoming byte array to be in the same order * as the address. * * @return byte array with address bytes */ public static byte[] ipv4AddressNoZoneToArray(final Ipv4AddressNoZone ipv4Addr) { return ipv4AddressNoZoneToArray(ipv4Addr.getValue()); }
public static <REP extends JVppReply<?>> REP getReply(@Nonnull Future<REP> future, @Nonnegative final int timeoutInSeconds) throws TimeoutException, VppBaseCallException { try { checkArgument(timeoutInSeconds > 0, "Timeout cannot be < 0"); return future.get(timeoutInSeconds, TimeUnit.SECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IllegalStateException("Interrupted", e); } catch (ExecutionException e) { // Execution exception could generally contains any exception // when using exceptions instead of return codes just rethrow it for processing on corresponding place if (e instanceof ExecutionException && (e.getCause() instanceof VppBaseCallException)) { throw (VppBaseCallException) (e.getCause()); } throw new IllegalStateException(e); } }
@Override public void readCurrentAttributes(@Nonnull final InstanceIdentifier<BridgeDomain> id, @Nonnull final BridgeDomainBuilder builder, @Nonnull final ReadContext context) throws ReadFailedException { LOG.debug("vppstate.BridgeDomainCustomizer.readCurrentAttributes: id={}, builderbuilder={}, context={}", id, builder, context); final BridgeDomainKey key = id.firstKeyOf(id.getTargetType()); LOG.debug("vppstate.BridgeDomainCustomizer.readCurrentAttributes: key={}", key); final int bdId = bdContext.getIndex(key.getName(), context.getMappingContext()); LOG.debug("vppstate.BridgeDomainCustomizer.readCurrentAttributes: bdId={}", bdId); BridgeDomainDetailsReplyDump reply; BridgeDomainDetails bridgeDomainDetails; final BridgeDomainDump request = new BridgeDomainDump(); request.bdId = bdContext.getIndex(key.getName(), context.getMappingContext()); try { reply = getFutureJVpp().bridgeDomainDump(request).toCompletableFuture().get(); bridgeDomainDetails = Iterables.getOnlyElement(reply.bridgeDomainDetails); } catch (Exception e) { LOG.debug("Unable to read bridge domain: {}", key.getName(), e); return; } logBridgeDomainDetails(bridgeDomainDetails); builder.setName(key.getName()); builder.setArpTermination(byteToBoolean(bridgeDomainDetails.arpTerm)); builder.setFlood(byteToBoolean(bridgeDomainDetails.flood)); builder.setForward(byteToBoolean(bridgeDomainDetails.forward)); builder.setLearn(byteToBoolean(bridgeDomainDetails.learn)); builder.setUnknownUnicastFlood(byteToBoolean(bridgeDomainDetails.uuFlood)); }
/** * Converts byte array to {@link Ipv6Prefix} with specified prefixLength */ public static Ipv6Prefix arrayToIpv6Prefix(final byte[] address, byte prefixLength) { Ipv6AddressNoZone addressPart = arrayToIpv6AddressNoZone(address); return new Ipv6Prefix(addressPart.getValue().concat("/").concat(String.valueOf(prefixLength))); }
private void createSubInterface(final InstanceIdentifier<SubInterface> id, @Nonnull final String superIfName, @Nonnull final SubInterface subInterface, final WriteContext writeContext) throws VppBaseCallException, WriteTimeoutException { final int superIfIndex = interfaceContext.getIndex(superIfName, writeContext.getMappingContext()); final CompletionStage<CreateSubifReply> createSubifReplyCompletionStage = getFutureJVpp().createSubif(getCreateSubifRequest(subInterface, superIfIndex)); final CreateSubifReply reply = TranslateUtils.getReplyForWrite(createSubifReplyCompletionStage.toCompletableFuture(), id); setInterfaceState(id, reply.swIfIndex, booleanToByte(subInterface.isEnabled())); interfaceContext.addName(reply.swIfIndex, getSubInterfaceName(superIfName, Math.toIntExact(subInterface.getIdentifier())), writeContext.getMappingContext()); LOG.debug("Sub interface created successfully for: {}, subInterface: {}", superIfName, subInterface); }