@Override public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<NshEntry> id, @Nonnull final NshEntry dataAfter, @Nonnull final WriteContext writeContext) throws WriteFailedException { LOG.debug("Creating nsh entry: iid={} dataAfter={}", id, dataAfter); try { final int newEntryIndex = nshAddDelEntry(true, id, dataAfter, ~0 /* value not present */, writeContext.getMappingContext()); // Add nsh entry name <-> vpp index mapping to the naming context: nshEntryContext.addName(newEntryIndex, dataAfter.getName(), writeContext.getMappingContext()); LOG.debug("Successfully created nsh entry(id={]): iid={} dataAfter={}", newEntryIndex, id, dataAfter); } catch (VppBaseCallException e) { throw new WriteFailedException.CreateFailedException(id, dataAfter, e); } }
@Override public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<NshMap> id, @Nonnull final NshMap dataAfter, @Nonnull final WriteContext writeContext) throws WriteFailedException { LOG.debug("Creating nsh map: iid={} dataAfter={}", id, dataAfter); try { final int newMapIndex = nshAddDelMap(true, id, dataAfter, ~0 /* value not present */, writeContext.getMappingContext()); // Add nsh map name <-> vpp index mapping to the naming context: nshMapContext.addName(newMapIndex, dataAfter.getName(), writeContext.getMappingContext()); LOG.debug("Successfully created nsh map(id={]): iid={} dataAfter={}", newMapIndex, id, dataAfter); } catch (VppBaseCallException e) { throw new WriteFailedException.CreateFailedException(id, dataAfter, e); } }
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()); }
/** * Retrieve name for mapping stored provided mappingContext instance. If not present, artificial name will be * generated. * * @param index index of a mapped item * @param mappingContext mapping context providing context data for current transaction * * @return name mapped to provided index */ @Nonnull public synchronized String getName(final int index, @Nonnull final MappingContext mappingContext) { if (!containsName(index, mappingContext)) { final String artificialName = getArtificialName(index); addName(index, artificialName, mappingContext); } final Optional<Mappings> read = mappingContext.read(namingContextIid.child(Mappings.class)); checkState(read.isPresent(), "Mapping for index: %s is not present. But should be", index); return read.get().getMapping().stream() .filter(mapping -> mapping.getIndex().equals(index)) .collect(SINGLE_ITEM_COLLECTOR).getName(); }
private void createTap(final InstanceIdentifier<Tap> id, final String swIfName, final Tap tap, final WriteContext writeContext) throws VppBaseCallException, WriteTimeoutException { LOG.debug("Setting tap interface: {}. Tap: {}", swIfName, tap); final CompletionStage<TapConnectReply> tapConnectFuture = getFutureJVpp().tapConnect(getTapConnectRequest(tap.getTapName(), tap.getMac(), tap.getDeviceInstance())); final TapConnectReply reply = TranslateUtils.getReplyForWrite(tapConnectFuture.toCompletableFuture(), id); LOG.debug("Tap set successfully for: {}, tap: {}", swIfName, tap); // Add new interface to our interface context interfaceContext.addName(reply.swIfIndex, swIfName, writeContext.getMappingContext()); }
interfaceNamingContext.addName(elt.swIfIndex, TranslateUtils.toString(elt.interfaceName), mappingCtx);
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); }
@Override public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<BridgeDomain> id, @Nonnull final BridgeDomain dataBefore, @Nonnull final WriteContext ctx) throws WriteFailedException { LOG.debug("writeCurrentAttributes: id={}, current={}, ctx={}", id, dataBefore, ctx); final String bdName = dataBefore.getName(); try { int index; if (bdContext.containsIndex(bdName, ctx.getMappingContext())) { index = bdContext.getIndex(bdName, ctx.getMappingContext()); } else { // FIXME we need the bd index to be returned by VPP or we should have a counter field // (maybe in context similar to artificial name) // Here we assign the next available ID from bdContext's perspective index = 1; while (bdContext.containsName(index, ctx.getMappingContext())) { index++; } } addOrUpdateBridgeDomain(id, index, dataBefore); bdContext.addName(index, bdName, ctx.getMappingContext()); } catch (VppBaseCallException e) { LOG.warn("Failed to create bridge domain", e); throw new WriteFailedException.CreateFailedException(id, dataBefore, e); } }
private void createGreTunnel(final InstanceIdentifier<Gre> id, final String swIfName, final Gre gre, final WriteContext writeContext) throws VppBaseCallException, WriteTimeoutException { final byte isIpv6 = (byte) (isIpv6(gre) ? 1 : 0); final InetAddress srcAddress = InetAddresses.forString(getAddressString(gre.getSrc())); final InetAddress dstAddress = InetAddresses.forString(getAddressString(gre.getDst())); int outerFibId = gre.getOuterFibId().intValue(); LOG.debug("Setting gre tunnel for interface: {}. Gre: {}", swIfName, gre); final CompletionStage<GreAddDelTunnelReply> greAddDelTunnelReplyCompletionStage = getFutureJVpp().greAddDelTunnel(getGreTunnelRequest((byte) 1 /* is add */, srcAddress.getAddress(), dstAddress.getAddress(), outerFibId, isIpv6)); final GreAddDelTunnelReply reply = TranslateUtils.getReplyForWrite(greAddDelTunnelReplyCompletionStage.toCompletableFuture(), id); LOG.debug("Gre tunnel set successfully for: {}, gre: {}", swIfName, gre); if(interfaceContext.containsName(reply.swIfIndex, writeContext.getMappingContext())) { // VPP keeps gre tunnels present even after they are delete(reserving ID for next tunnel) // This may cause inconsistencies in mapping context when configuring tunnels like this: // 1. Add tunnel 2. Delete tunnel 3. Read interfaces (reserved mapping e.g. gre_tunnel0 -> 6 // will get into mapping context) 4. Add tunnel (this will add another mapping with the same // reserved ID and context is invalid) // That's why a check has to be performed here removing mapping gre_tunnel0 -> 6 mapping and storing // new name for that ID final String formerName = interfaceContext.getName(reply.swIfIndex, writeContext.getMappingContext()); LOG.debug("Removing updated mapping of a gre tunnel, id: {}, former name: {}, new name: {}", reply.swIfIndex, formerName, swIfName); interfaceContext.removeName(formerName, writeContext.getMappingContext()); } // Add new interface to our interface context interfaceContext.addName(reply.swIfIndex, swIfName, writeContext.getMappingContext()); }
interfaceNamingContext.addName(reply.swIfIndex, swIfName, writeContext.getMappingContext());
interfaceNamingContext.addName(reply.swIfIndex, swIfName, writeContext.getMappingContext());