@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); } }
@Override protected void configure() { // TODO HONEYCOMB-207 workaround: if (!isEnabled()) { LOG.info("VppNshModule is disabled. Skipping module configuration."); return; } LOG.info("Configuring VppNsh module"); // Naming contexts bind(NamingContext.class) .annotatedWith(Names.named("nsh-entry-context")) .toInstance(new NamingContext("nsh-entry-", "nsh-entry-context")); bind(NamingContext.class) .annotatedWith(Names.named("nsh-map-context")) .toInstance(new NamingContext("nsh-map-", "nsh-map-context")); // Bind to Plugin's JVPP. bind(FutureJVppNsh.class).toProvider(JVppNshProvider.class).in(Singleton.class); // Below are classes picked up by HC framework Multibinder.newSetBinder(binder(), WriterFactory.class).addBinding().to(VppNshWriterFactory.class); Multibinder.newSetBinder(binder(), ReaderFactory.class).addBinding().to(VppNshReaderFactory.class); Multibinder.newSetBinder(binder(), DataTreeInitializer.class).addBinding().to(VppNshInitializer.class); LOG.info("NSH module successfully configured"); }
final String nshName = nshEntryContext.getName(detail.entryIndex, context.getMappingContext()); LOG.debug("vppstate.NshEntryCustomizer.getAllIds: nName={}", nshName); allIds.add(new NshEntryKey(nshName));
/** * 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 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()); }
@Override public void deleteCurrentAttributes(@Nonnull InstanceIdentifier<Neighbor> id, @Nonnull Neighbor dataBefore, @Nonnull WriteContext writeContext) throws WriteFailedException { checkNotNull(dataBefore, "Cannot delete null neighbour"); checkArgument(id.firstKeyOf(Interface.class) != null, "No parent interface key found"); LOG.debug("Processing request for Neigbour delete"); String interfaceName = id.firstKeyOf(Interface.class).getName(); MappingContext mappingContext = writeContext.getMappingContext(); checkState(interfaceContext.containsIndex(interfaceName, mappingContext), "Mapping does not contains mapping for provider interface name %s", interfaceName); LOG.debug("Parent interface[{}] index found", interfaceName); try { addDelNeighbourAndReply(id, false, interfaceContext.getIndex(interfaceName, mappingContext), dataBefore); LOG.info("Neighbour {} successfully deleted", id); } catch (VppBaseCallException e) { throw new WriteFailedException.DeleteFailedException(id, 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()); }
@Override public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<L2> id, @Nonnull final L2 dataBefore, @Nonnull final L2 dataAfter, @Nonnull final WriteContext writeContext) throws WriteFailedException { final String subInterfaceName = getSubInterfaceName(id); final int subInterfaceIndex = interfaceContext.getIndex(subInterfaceName, writeContext.getMappingContext()); // TODO handle update properly (if possible) setL2(id, subInterfaceIndex, subInterfaceName, dataAfter, writeContext); }
if (!nshMapContext.containsIndex(mapName, ctx.getMappingContext())) { LOG.debug("Could not find nsh map {} in the naming context", mapName); return; request.mapIndex = nshMapContext.getIndex(mapName, ctx.getMappingContext()); checkState(interfaceContext.containsName(nshMapDetails.swIfIndex, ctx.getMappingContext()), "Mapping does not contains mapping for provider interface Index "); final String interfaceName = interfaceContext.getName(nshMapDetails.swIfIndex, ctx.getMappingContext()); builder.setEncapIfName(interfaceName);
.map((elt) -> { if (!interfaceNamingContext.containsName(elt.swIfIndex, mappingCtx)) { interfaceNamingContext.addName(elt.swIfIndex, TranslateUtils.toString(elt.interfaceName), mappingCtx); interfaceNamingContext.getName(elt.swIfIndex, mappingCtx), elt.interfaceName, elt.swIfIndex); .map(index -> new InterfaceKey(interfaceNamingContext.getName(index, context.getMappingContext()))) .collect(Collectors.toList());
@Override public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<NshEntry> id, @Nonnull final NshEntry dataBefore, @Nonnull final WriteContext writeContext) throws WriteFailedException { LOG.debug("Removing nsh entry: iid={} dataBefore={}", id, dataBefore); final String entryName = dataBefore.getName(); checkState(nshEntryContext.containsIndex(entryName, writeContext.getMappingContext()), "Removing nsh entry {}, but index could not be found in the nsh entry context", entryName); final int entryIndex = nshEntryContext.getIndex(entryName, writeContext.getMappingContext()); try { nshAddDelEntry(false, id, dataBefore, entryIndex, writeContext.getMappingContext()); // Remove deleted interface from interface context: nshEntryContext.removeName(dataBefore.getName(), writeContext.getMappingContext()); LOG.debug("Successfully removed nsh entry(id={]): iid={} dataAfter={}", entryIndex, id, dataBefore); } catch (VppBaseCallException e) { throw new WriteFailedException.DeleteFailedException(id, e); } }
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<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); } }
@Nonnull final ReadContext ctx) throws ReadFailedException { final int ifaceId = interfaceContext.getIndex(ifaceName, ctx.getMappingContext()); final BridgeDomainSwIfDetails bdSwIfDetails = bdForInterface.get(); final BridgeBasedBuilder bbBuilder = new BridgeBasedBuilder(); bbBuilder.setBridgeDomain(bridgeDomainContext.getName(bdSwIfDetails.bdId, ctx.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()); }
/** * 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(); }
TranslateUtils.getReplyForWrite(vxlanAddDelTunnelReplyCompletionStage.toCompletableFuture(), id); LOG.debug("Vxlan tunnel set successfully for: {}, vxlan: {}", swIfName, vxlan); if (interfaceNamingContext.containsName(reply.swIfIndex, writeContext.getMappingContext())) { final String formerName = interfaceNamingContext.getName(reply.swIfIndex, writeContext.getMappingContext()); LOG.debug("Removing updated mapping of a vxlan tunnel, id: {}, former name: {}, new name: {}", reply.swIfIndex, formerName, swIfName); interfaceNamingContext.removeName(formerName, writeContext.getMappingContext()); interfaceNamingContext.addName(reply.swIfIndex, swIfName, writeContext.getMappingContext());
@Override public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<L2> id, @Nonnull final L2 dataAfter, @Nonnull final WriteContext writeContext) throws WriteFailedException { final String subInterfaceName = getSubInterfaceName(id); final int subInterfaceIndex = interfaceContext.getIndex(subInterfaceName, writeContext.getMappingContext()); setL2(id, subInterfaceIndex, subInterfaceName, dataAfter, writeContext); }
@Override public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<NshMap> id, @Nonnull final NshMap dataBefore, @Nonnull final WriteContext writeContext) throws WriteFailedException { LOG.debug("Removing nsh map: iid={} dataBefore={}", id, dataBefore); final String mapName = dataBefore.getName(); checkState(nshMapContext.containsIndex(mapName, writeContext.getMappingContext()), "Removing nsh map {}, but index could not be found in the nsh map context", mapName); final int mapIndex = nshMapContext.getIndex(mapName, writeContext.getMappingContext()); try { nshAddDelMap(false, id, dataBefore, mapIndex, writeContext.getMappingContext()); // Remove deleted interface from interface context: nshMapContext.removeName(dataBefore.getName(), writeContext.getMappingContext()); LOG.debug("Successfully removed nsh map(id={]): iid={} dataAfter={}", mapIndex, id, dataBefore); } catch (VppBaseCallException e) { throw new WriteFailedException.DeleteFailedException(id, e); } }
@Override public void writeCurrentAttributes(@Nonnull InstanceIdentifier<Neighbor> id, @Nonnull Neighbor dataAfter, @Nonnull WriteContext writeContext) throws WriteFailedException { checkNotNull(dataAfter, "Cannot write null neighbour"); checkArgument(id.firstKeyOf(Interface.class) != null, "No parent interface key found"); LOG.debug("Processing request for Neigbour write"); String interfaceName = id.firstKeyOf(Interface.class).getName(); MappingContext mappingContext = writeContext.getMappingContext(); checkState(interfaceContext.containsIndex(interfaceName, mappingContext), "Mapping does not contains mapping for provider interface name ".concat(interfaceName)); LOG.debug("Parent interface index found"); try { addDelNeighbourAndReply(id, true, interfaceContext.getIndex(interfaceName, mappingContext), dataAfter); LOG.info("Neighbour successfully written"); } catch (VppBaseCallException e) { throw new WriteFailedException.CreateFailedException(id, dataAfter, e); } }