/** * 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()); }
private static byte[] toMatchValue(final Ipv4Prefix ipv4Prefix) { final String[] split = ipv4Prefix.getValue().split("/"); final byte[] addressBytes = ipv4AddressNoZoneToArray(split[0]); final byte[] mask = toByteMask(Byte.valueOf(split[1])); for (int i = 0; i < addressBytes.length; ++i) { addressBytes[i] &= mask[i]; } return addressBytes; }
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); }
/** * 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())); } }
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())); } }
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); } }