@Override public Ipv6InterfaceIdentifier parseTlvBody(final ByteBuf value) { return new Ipv6InterfaceIdentifier(Ipv6Util.addressForByteBuf(value)); }
/** * From string ipAddress creates an InetAddress and puts it into ByteBuf. * @param ipAddress Ipv6 address * @return ByteBuf with filled in bytes from ipAddress */ public static ByteBuf byteBufForAddress(final Ipv6Address ipAddress) { return Unpooled.wrappedBuffer(bytesForAddress(ipAddress)); }
static ByteBuf serializeIpv6EroCase(final Boolean loose, final Ipv6Address address) { final ByteBuf buffer = Unpooled.buffer(); Ipv4EroParser.serializeEroFlags(buffer, loose); buffer.writeBytes(Ipv6Util.byteBufForAddress(address)); return buffer; } }
static Ipv6Prefix parseIpv6Prefix(final ByteBuf nlri) { final int bitLength = nlri.readUnsignedByte(); nlri.readUnsignedByte(); // FIXME: this does not look right if bitLenght % Byte.SIZE != 0 return Ipv6Util.prefixForBytes(ByteArray.readBytes(nlri, bitLength / Byte.SIZE), bitLength); } }
/** * Converts Ipv6Prefix to byte array. Prefix length at the beginning. * Prefix bytes are trimmed from the end to match prefix length. * * @param prefix Ipv6Prefix to be converted * @return byte array with the prefix length at the beginning * * @deprecated This is inefficient, refactor code to use {@link #bytesForAddress(Ipv6Address)} or * {@link ByteBufWriteUtil#writeMinimalPrefix(Ipv6Prefix, ByteBuf)}. */ @Deprecated public static byte[] bytesForPrefixBegin(final Ipv6Prefix prefix) { final byte[] addrWithPrefix = bytesForPrefix(prefix); return Ipv4Util.prefixedBytes(addrWithPrefix[IPV6_LENGTH], addrWithPrefix); }
@Override public Subobject parseSubobject(final ByteBuf buffer, final boolean loose) throws PCEPDeserializerException { Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); final SubobjectBuilder builder = new SubobjectBuilder(); builder.setLoose(loose); if (buffer.readableBytes() != CONTENT_LENGTH) { throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";"); } final int length = buffer.getUnsignedByte(PREFIX_F_OFFSET); final IpPrefixBuilder prefix = new IpPrefixBuilder().setIpPrefix(new IpPrefix(Ipv6Util.prefixForBytes(ByteArray.readBytes(buffer, Ipv6Util.IPV6_LENGTH), length))); builder.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(prefix.build()).build()); return builder.build(); }
/** * Writes IPv6 prefix if not null, otherwise writes zeros to the * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 17. * * @param ipv6Prefix * IPv6 prefix to be written to the output. Prefix is written in * the last byte. * @param output * ByteBuf, where ipv6Prefix or zeros are written. */ public static void writeIpv6Prefix(final Ipv6Prefix ipv6Prefix, final ByteBuf output) { if (ipv6Prefix != null) { output.writeBytes(Ipv6Util.bytesForPrefix(ipv6Prefix)); } else { output.writeZero(IPV6_PREFIX_BYTE_LENGTH); } }
@Override public Ipv6InterfaceIdentifier parseTlvBody(final ByteBuf value) { return new Ipv6InterfaceIdentifier(Ipv6Util.addressForByteBuf(value)); }
/** * Writes IPv6 address if not null, otherwise writes zeros to the * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 16. * * @param ipv6Address * IPv6 address to be written to the output. * @param output * ByteBuf, where ipv6Address or zeros are written. */ public static void writeIpv6Address(final Ipv6Address ipv6Address, final ByteBuf output) { if (ipv6Address != null) { output.writeBytes(Ipv6Util.bytesForAddress(ipv6Address)); } else { output.writeZero(Ipv6Util.IPV6_LENGTH); } }
@Override public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf byteAggregator) { Preconditions.checkArgument(extendedCommunity instanceof RedirectIpv6ExtendedCommunity, "The extended community %s is not RedirectIpv6ExtendedCommunity type.", extendedCommunity); final RedirectIpv6 redirectIpv6 = ((RedirectIpv6ExtendedCommunity) extendedCommunity).getRedirectIpv6(); byteAggregator.writeBytes(Ipv6Util.byteBufForAddress(redirectIpv6.getGlobalAdministrator())); ByteBufWriteUtil.writeUnsignedShort(redirectIpv6.getLocalAdministrator(), byteAggregator); }
@Override public Subobject parseSubobject(final ByteBuf buffer, final boolean mandatory) throws PCEPDeserializerException { Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); final SubobjectBuilder builder = new SubobjectBuilder(); builder.setMandatory(mandatory); if (buffer.readableBytes() != CONTENT6_LENGTH) { throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";"); } final int length = buffer.getUnsignedByte(PREFIX6_F_OFFSET); final IpPrefixBuilder prefix = new IpPrefixBuilder().setIpPrefix(new IpPrefix(Ipv6Util.prefixForBytes(ByteArray.readBytes(buffer, Ipv6Util.IPV6_LENGTH), length))); builder.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(prefix.build()).build()); buffer.skipBytes(PREFIX_F_LENGTH); builder.setAttribute(Attribute.forValue(buffer.readUnsignedByte())); return builder.build(); }
static void writePrefix(final Ipv6Prefix prefix, final ByteBuf output) { final byte[] bytes = Ipv6Util.bytesForPrefix(prefix); final byte prefixBits = bytes[Ipv6Util.IPV6_LENGTH]; output.writeByte(prefixBits); output.writeByte(0); output.writeBytes(bytes, 0, Ipv4Util.prefixBitsToBytes(Byte.toUnsignedInt(prefixBits))); }
private static IpAddress parseForwardingAddress(final ByteBuf value) { IpAddress fwdAddress = null; switch (value.readableBytes()) { case Ipv4Util.IP4_LENGTH: fwdAddress = new IpAddress(Ipv4Util.addressForByteBuf(value)); break; case Ipv6Util.IPV6_LENGTH: fwdAddress = new IpAddress(Ipv6Util.addressForByteBuf(value)); break; default: LOG.debug("Ignoring unsupported forwarding address length {}", value.readableBytes()); } return fwdAddress; }
static ByteBuf serializeOrigRouteIp(final IpAddress origRouteIp) { final ByteBuf body = Unpooled.buffer(); if (origRouteIp.getIpv4Address() != null) { body.writeByte(Ipv4Util.IP4_BITS_LENGTH); body.writeBytes(Ipv4Util.bytesForAddress(origRouteIp.getIpv4Address())); } else if (origRouteIp.getIpv6Address() != null) { body.writeByte(Ipv6Util.IPV6_BITS_LENGTH); body.writeBytes(Ipv6Util.bytesForAddress(origRouteIp.getIpv6Address())); } else { body.writeZero(ZERO_BYTE); } return body; } }
public static ByteBuf serializeSidValue(final SidLabelIndex tlv) { if (tlv instanceof Ipv6AddressCase) { return Ipv6Util.byteBufForAddress(((Ipv6AddressCase) tlv).getIpv6Address()); } else if (tlv instanceof LocalLabelCase) { return Unpooled.copyMedium(((LocalLabelCase) tlv).getLocalLabel().getValue().intValue() & LABEL_MASK); } else if (tlv instanceof SidCase) { return Unpooled.copyInt(((SidCase) tlv).getSid().intValue()); } return null; }
@Override public Subobject parseSubobject(final ByteBuf buffer) throws PCEPDeserializerException { Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); final SubobjectBuilder builder = new SubobjectBuilder(); if (buffer.readableBytes() != CONTENT_LENGTH) { throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";"); } final int length = buffer.getUnsignedByte(PREFIX_F_OFFSET); final IpPrefixBuilder prefix = new IpPrefixBuilder().setIpPrefix(new IpPrefix(Ipv6Util.prefixForBytes(ByteArray.readBytes(buffer, Ipv6Util.IPV6_LENGTH), length))); buffer.skipBytes(PREFIX_F_LENGTH); final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE); builder.setProtectionAvailable(flags.get(LPA_F_OFFSET)); builder.setProtectionInUse(flags.get(LPIU_F_OFFSET)); builder.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(prefix.build()).build()); return builder.build(); }
@Override public Object parseObject(final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException { Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); final PceIdBuilder builder = new PceIdBuilder(); builder.setIpAddress(new IpAddress(Ipv6Util.addressForByteBuf(buffer))); return builder.build(); }
private static void serializeForwardingAddress(final IpAddress forwardingAddress, final ByteBuf byteAggregator) { if (forwardingAddress != null) { final ByteBuf ospfBuf = Unpooled.buffer(); if (forwardingAddress.getIpv4Address() != null) { ospfBuf.writeBytes(Ipv4Util.bytesForAddress(forwardingAddress.getIpv4Address())); } else if (forwardingAddress.getIpv6Address() != null) { ospfBuf.writeBytes(Ipv6Util.bytesForAddress(forwardingAddress.getIpv6Address())); } TlvUtil.writeTLV(FORWARDING_ADDRESS, ospfBuf, byteAggregator); } } }
TlvUtil.writeTLV(TlvUtil.LOCAL_IPV6_ROUTER_ID, Ipv6Util.byteBufForAddress(nodeAttributes.getIpv6RouterId()), byteAggregator);
@Override public Object parseObject(final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException { Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); final PccIdReqBuilder builder = new PccIdReqBuilder(); builder.setIpAddress(new IpAddress(Ipv6Util.addressForByteBuf(buffer))); return builder.build(); }