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 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 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; }
private CreateVhostUserIf getCreateVhostUserIfRequest(final VhostUser vhostUser) { CreateVhostUserIf request = new CreateVhostUserIf(); request.isServer = TranslateUtils.booleanToByte(VhostUserRole.Server.equals(vhostUser.getRole())); request.sockFilename = vhostUser.getSocket().getBytes(); request.renumber = 0; // TODO request.customDevInstance = 0; // TODO request.useCustomMac = 0; request.macAddress = new byte[]{}; return request; }
private ModifyVhostUserIf getModifyVhostUserIfRequest(final VhostUser vhostUser, final int swIfIndex) { ModifyVhostUserIf request = new ModifyVhostUserIf(); request.isServer = TranslateUtils.booleanToByte(VhostUserRole.Server.equals(vhostUser.getRole())); request.sockFilename = vhostUser.getSocket().getBytes(); request.renumber = 0; // TODO request.customDevInstance = 0; // TODO request.swIfIndex = swIfIndex; return request; }
private static ClassifyAddDelSession getClassifyAddDelSessionRequest(final boolean isAdd, @Nonnull final ClassifySession classifySession, final int tableIndex, final int hitNextIndex, final int opaqueIndex) { ClassifyAddDelSession request = new ClassifyAddDelSession(); request.isAdd = booleanToByte(isAdd); request.tableIndex = tableIndex; request.hitNextIndex = hitNextIndex; request.opaqueIndex = opaqueIndex; // default 0: request.advance = classifySession.getAdvance(); request.match = DatatypeConverter.parseHexBinary(classifySession.getMatch().getValue().replace(":", "")); return request; }
@Override public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<SubInterface> id, @Nonnull final SubInterface dataBefore, @Nonnull final SubInterface dataAfter, @Nonnull final WriteContext writeContext) throws WriteFailedException { if (Objects.equals(dataBefore.isEnabled(), dataAfter.isEnabled())) { LOG.debug("No state update will be performed. Ignoring config"); return; // TODO shouldn't we throw exception here (if there will be dedicated L2 customizer)? } final String subIfaceName = getSubInterfaceName(id.firstKeyOf(Interface.class).getName(), Math.toIntExact(dataAfter.getIdentifier())); try { setInterfaceState(id, interfaceContext.getIndex(subIfaceName, writeContext.getMappingContext()), booleanToByte(dataAfter.isEnabled())); } catch (VppBaseCallException e) { LOG.warn("Failed to update interface state for: interface if={}, enabled: {}", subIfaceName, booleanToByte(dataAfter.isEnabled())); throw new WriteFailedException.UpdateFailedException(id, dataBefore, dataAfter, e); } }
private ClassifyAddDelTable getClassifyAddDelTableRequest(final boolean isAdd, final int tableIndex, @Nonnull final ClassifyTable table, final int missNextIndex, @Nonnull final MappingContext ctx) { final ClassifyAddDelTable request = new ClassifyAddDelTable(); request.isAdd = booleanToByte(isAdd); request.tableIndex = tableIndex; // mandatory, all u32 values are permitted: request.nbuckets = table.getNbuckets().intValue(); request.memorySize = table.getMemorySize().intValue(); request.skipNVectors = table.getSkipNVectors().intValue(); // mandatory request.missNextIndex = missNextIndex; final String nextTable = table.getNextTable(); if (isAdd && nextTable != null) { request.nextTableIndex = classifyTableContext.getTableIndex(nextTable, ctx); } else { request.nextTableIndex = ~0; // value not specified } request.mask = DatatypeConverter.parseHexBinary(table.getMask().getValue().replace(":", "")); checkArgument(request.mask.length % 16 == 0, "Number of mask bytes must be multiple of 16."); request.matchNVectors = request.mask.length / 16; return request; } }
private NshAddDelMap getNshAddDelMapRequest(final boolean isAdd, final int mapIndex, @Nonnull final NshMap map, @Nonnull final MappingContext ctx) { final NshAddDelMap request = new NshAddDelMap(); request.isAdd = booleanToByte(isAdd); request.nspNsi = (map.getNsp().intValue()<<8) | map.getNsi(); request.mappedNspNsi = (map.getMappedNsp().intValue()<<8) | map.getMappedNsi(); if (map.getEncapType() == VxlanGpe.class) { request.nextNode = 2; } checkState(interfaceContext.containsIndex(map.getEncapIfName(), ctx), "Mapping does not contains mapping for provider interface Name ".concat(map.getEncapIfName())); request.swIfIndex = interfaceContext.getIndex(map.getEncapIfName(), ctx); return request; } }
throws VppBaseCallException, WriteTimeoutException { final InputAclSetInterface request = new InputAclSetInterface(); request.isAdd = booleanToByte(isAdd); request.swIfIndex = ifIndex; request.l2TableIndex = ~0; // skip
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); }
private void setOuterTag(final CreateSubif request, final Tag outerTag) { checkState(SVlan.class == outerTag.getDot1qTag().getTagType(), "Service Tag expected at index 0"); final Dot1qTag.VlanId vlanId = outerTag.getDot1qTag().getVlanId(); request.outerVlanId = dot1qVlanIdToShort(vlanId.getDot1qVlanId()); request.outerVlanIdAny = booleanToByte(Dot1qTag.VlanId.Enumeration.Any.equals(vlanId.getEnumeration())); }
private void setInnerTag(final CreateSubif request, final Tag innerTag) { checkState(CVlan.class == innerTag.getDot1qTag().getTagType(), "Customer Tag expected at index 1"); final Dot1qTag.VlanId vlanId = innerTag.getDot1qTag().getVlanId(); request.innerVlanId = dot1qVlanIdToShort(vlanId.getDot1qVlanId()); request.innerVlanIdAny = booleanToByte(Dot1qTag.VlanId.Enumeration.Any.equals(vlanId.getEnumeration())); }
break; request.dot1Ad = booleanToByte(_802dot1ad.class == subInterface.getVlanType()); booleanToByte(matchType instanceof VlanTagged && ((VlanTagged) matchType).isMatchExactTags()); request.defaultSub = booleanToByte(matchType instanceof Default);
@Nonnull final MappingContext ctx) { final NshAddDelEntry request = new NshAddDelEntry(); request.isAdd = booleanToByte(isAdd);
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; } }
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); } }
private L2InterfaceVlanTagRewrite getTagRewriteRequest(final int swIfIndex, final Rewrite rewrite) { final L2InterfaceVlanTagRewrite request = new L2InterfaceVlanTagRewrite(); request.swIfIndex = swIfIndex; request.pushDot1Q = booleanToByte(_802dot1q.class == rewrite.getVlanType()); final List<PushTags> pushTags = rewrite.getPushTags(); final Short popTags = rewrite.getPopTags(); final int numberOfTagsToPop = popTags == null ? 0 : popTags.intValue(); final int numberOfTagsToPush = pushTags == null ? 0 : pushTags.size(); request.vtrOp = TagRewriteOperation.get(numberOfTagsToPop, numberOfTagsToPush).ordinal(); if (numberOfTagsToPush > 0) { for (final PushTags tag : pushTags) { if (tag.getIndex() == 0) { request.tag1 = tag.getDot1qTag().getVlanId().getValue(); } else { request.tag2 = tag.getDot1qTag().getVlanId().getValue(); } } } LOG.debug("Generated tag rewrite request: {}", ReflectionToStringBuilder.toString(request)); return request; }