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 deleteVhostUserIf(final InstanceIdentifier<VhostUser> id, final String swIfName, final VhostUser vhostUser, final WriteContext writeContext) throws VppBaseCallException, WriteTimeoutException { LOG.debug("Deleting vhost user interface: name={}, vhostUser={}", swIfName, vhostUser); final CompletionStage<DeleteVhostUserIfReply> deleteVhostUserIfReplyCompletionStage = getFutureJVpp().deleteVhostUserIf(getDeleteVhostUserIfRequest(interfaceContext.getIndex(swIfName, writeContext.getMappingContext()))); TranslateUtils.getReplyForWrite(deleteVhostUserIfReplyCompletionStage.toCompletableFuture(), id); LOG.debug("Vhost user interface deleted successfully for: {}, vhostUser: {}", swIfName, vhostUser); // Remove interface from our interface context interfaceContext.removeName(swIfName, writeContext.getMappingContext()); }
private void setTagRewrite(final InstanceIdentifier<Rewrite> id, final String ifname, final Rewrite rewrite, final WriteContext writeContext) throws VppBaseCallException, WriteTimeoutException { final int swIfIndex = interfaceContext.getIndex(ifname, writeContext.getMappingContext()); LOG.debug("Setting tag rewrite for interface {}(id=): {}", ifname, swIfIndex, rewrite); final CompletionStage<L2InterfaceVlanTagRewriteReply> replyCompletionStage = getFutureJVpp().l2InterfaceVlanTagRewrite(getTagRewriteRequest(swIfIndex, rewrite)); TranslateUtils.getReplyForWrite(replyCompletionStage.toCompletableFuture(), id); LOG.debug("Tag rewrite for interface {}(id=) set successfully: {}", ifname, swIfIndex, rewrite); }
private void createVhostUserIf(final InstanceIdentifier<VhostUser> id, final String swIfName, final VhostUser vhostUser, final WriteContext writeContext) throws VppBaseCallException, WriteTimeoutException { LOG.debug("Creating vhost user interface: name={}, vhostUser={}", swIfName, vhostUser); final CompletionStage<CreateVhostUserIfReply> createVhostUserIfReplyCompletionStage = getFutureJVpp().createVhostUserIf(getCreateVhostUserIfRequest(vhostUser)); final CreateVhostUserIfReply reply = TranslateUtils.getReplyForWrite(createVhostUserIfReplyCompletionStage.toCompletableFuture(), id); LOG.debug("Vhost user interface created successfully for: {}, vhostUser: {}", swIfName, vhostUser); // Add new interface to our interface context interfaceContext.addName(reply.swIfIndex, swIfName, writeContext.getMappingContext()); }
private void deleteTap(final InstanceIdentifier<Tap> id, final String swIfName, final int index, final Tap dataBefore, final WriteContext writeContext) throws VppBaseCallException, WriteTimeoutException { LOG.debug("Deleting tap interface: {}. Tap: {}", swIfName, dataBefore); final CompletionStage<TapDeleteReply> vxlanAddDelTunnelReplyCompletionStage = getFutureJVpp().tapDelete(getTapDeleteRequest(index)); TranslateUtils.getReplyForWrite(vxlanAddDelTunnelReplyCompletionStage.toCompletableFuture(), id); LOG.debug("Tap deleted successfully for: {}, tap: {}", swIfName, dataBefore); // Remove deleted interface from interface context interfaceContext.removeName(swIfName, writeContext.getMappingContext()); }
/** * 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)); } }
/** * Validate expected interface type */ @Override public final void writeCurrentAttributes(@Nonnull final InstanceIdentifier<D> id, @Nonnull final D dataAfter, @Nonnull final WriteContext writeContext) throws WriteFailedException { checkProperInterfaceType(writeContext, id); writeInterface(id, dataAfter, writeContext); }
/** * 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()); }
TagRewriteOperation(final int popTags) { this.code = this.ordinal(); this.popTags = UnsignedBytes.checkedCast(popTags); }
private void checkProperInterfaceType(@Nonnull final WriteContext writeContext, @Nonnull final InstanceIdentifier<D> id) { final InstanceIdentifier<Interface> ifcTypeFromIid = id.firstIdentifierOf(Interface.class); checkArgument(ifcTypeFromIid != null, "Instance identifier does not contain {} type", Interface.class); checkArgument(id.firstKeyOf(Interface.class) != null, "Instance identifier does not contain keyed {} type", Interface.class); final Optional<Interface> interfaceConfig = writeContext.readAfter(ifcTypeFromIid); checkState(interfaceConfig.isPresent(), "Unable to get Interface configuration for an interface: %s currently being updated", ifcTypeFromIid); IllegalInterfaceTypeException .checkInterfaceType(interfaceConfig.get(), getExpectedInterfaceType()); }
/** * Remove mapping from current context * * @param name name of a mapped item * @param mappingContext mapping context providing context data for current transaction */ public synchronized void removeName(final String name, final MappingContext mappingContext) { mappingContext.delete(getMappingIid(name)); }
private static long macToLong(final String macAddress) { final byte[] mac = parseMac(macAddress); return Longs.fromBytes(mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], (byte) 0, (byte) 0); } }
static boolean isInterfaceOfType(final Class<? extends InterfaceType> ifcType, final SwInterfaceDetails cachedDetails) { return ifcType.equals(getInterfaceType(TranslateUtils.toString(cachedDetails.interfaceName))); } }
private void setPopTags(final RewriteBuilder builder, final TagRewriteOperation operation) { final byte numberOfTagsToPop = operation.getPopTags(); if (numberOfTagsToPop != 0) { builder.setPopTags(Short.valueOf(numberOfTagsToPop)); } }
/** * Get mapped name for the interface. Best effort only! The mapping might not yet be stored in context * data tree (write transaction is still in progress and context changes have not been committed yet, or * VPP sends the notification before it returns create request(that would store mapping)). * <p/> * In case mapping is not available, index is used as name. TODO inconsistent behavior, maybe just use indices ? */ private InterfaceNameOrIndex getIfcName(final SwInterfaceSetFlagsNotification swInterfaceSetFlagsNotification) { final Optional<String> optionalName = interfaceContext.getNameIfPresent(swInterfaceSetFlagsNotification.swIfIndex, mappingContext); return optionalName.isPresent() ? new InterfaceNameOrIndex(optionalName.get()) : new InterfaceNameOrIndex((long) swInterfaceSetFlagsNotification.swIfIndex); }
private void modifyVhostUserIf(final InstanceIdentifier<VhostUser> id, final String swIfName, final VhostUser vhostUser, final WriteContext writeContext) throws VppBaseCallException, WriteTimeoutException { LOG.debug("Updating vhost user interface: name={}, vhostUser={}", swIfName, vhostUser); final CompletionStage<ModifyVhostUserIfReply> modifyVhostUserIfReplyCompletionStage = getFutureJVpp() .modifyVhostUserIf(getModifyVhostUserIfRequest(vhostUser, interfaceContext.getIndex(swIfName, writeContext.getMappingContext()))); TranslateUtils.getReplyForWrite(modifyVhostUserIfReplyCompletionStage.toCompletableFuture(), id); LOG.debug("Vhost user interface updated successfully for: {}, vhostUser: {}", swIfName, vhostUser); }
/** * Check whether mapping is present for name. * * @param name name of a mapped item * @param mappingContext mapping context providing context data for current transaction * * @return true if present, false otherwise */ public synchronized boolean containsIndex(final String name, final MappingContext mappingContext) { return mappingContext.read(getMappingIid(name)).isPresent(); }
/** * Add mapping to current context * * @param index index of a mapped item * @param name name of a mapped item * @param mappingContext mapping context providing context data for current transaction */ public synchronized void addName(final int index, final String name, final MappingContext mappingContext) { final KeyedInstanceIdentifier<Mapping, MappingKey> mappingIid = getMappingIid(name); mappingContext.put(mappingIid, new MappingBuilder().setIndex(index).setName(name).build()); }