@Ignore @Test public void testDecodeAddIpv6() throws Exception { byte[] payload = new byte[500]; payload[0] = 0; payload[3] = 2; payload[4] = 0; payload[5] = 0; payload[6] = 1; Attribute attr = AttributeFactory.decode(payload); assertNotNull(attr); }
protected static Attribute decode(byte[] array) throws AttributeLengthException, AddressLengthException, UnknownNodeIdException, UnknownPrefixException, TlvNotFoundException, UnknownHostException, AttributeVariantException { Flags flags = getFlags(array[0]); AttributeVariant variant = AttributeVariant.NonCompact; if (flags.isCompact()) { variant = AttributeVariant.Compact; if (flags.isExtendedLength()) { variant = AttributeVariant.CompactExtendedLength; } } AttributeType type = AttributeType.Unspecified; int length = 0; byte[] value = new byte[length]; switch (variant) { case Compact: type = AttributeType.forValue(ArraysUtil.bytes2int(ArraysUtil.readBytes(array, 1, 1))); length = ArraysUtil.bytes2int(ArraysUtil.readBytes(array, 2, 1)); if (length < 0 || 255 < length) { throw new AttributeLengthException(); } if (Configuration.SET_COMPOSITION_ATTRIBUTE_COMPACT_NO_RESERVED_FIELDS) { value = ArraysUtil.readBytes(array, 3, length); length += 3; break; } value = ArraysUtil.readBytes(array, 4, length); length += 4; break; case CompactExtendedLength: type = AttributeType.forValue(ArraysUtil.bytes2int(ArraysUtil.readBytes(array, 1, 1))); length = ArraysUtil.bytes2int(ArraysUtil.readBytes(array, 2, 2)); if (length < 256 || 4084 < length) { throw new AttributeLengthException(); } value = ArraysUtil.readBytes(array, 4, length); length += 4; break; case NonCompact: type = AttributeType.forValue(ArraysUtil.bytes2int(ArraysUtil.readBytes(array, 1, 3))); length = ArraysUtil.bytes2int(ArraysUtil.readBytes(array, 4, 4)); if (length < 0 || 4080 < length) { throw new AttributeLengthException(); } value = ArraysUtil.readBytes(array, 8, length); length += 8; break; default: variant = AttributeVariant.None; } return decode(flags, variant, type, length, value); }
AttributeFactory { protected static Attribute decode(byte[] array) throws AttributeLengthException, AddressLengthException, UnknownNodeIdException, UnknownPrefixException, TlvNotFoundException, UnknownHostException, AttributeVariantException { Flags flags = getFlags(array[0]); AttributeVariant variant = AttributeVariant.NonCompact; if (flags.isCompact()) { variant = AttributeVariant.Compact; if (flags.isExtendedLength()) { variant = AttributeVariant.CompactExtendedLength; } } AttributeType type = AttributeType.Unspecified; int length = 0; byte[] value = new byte[length]; switch (variant) { case Compact: type = AttributeType.forValue(ArraysUtil.bytes2int(ArraysUtil.readBytes(array, 1, 1))); length = ArraysUtil.bytes2int(ArraysUtil.readBytes(array, 2, 1)); if (length < 0 || 255 < length) { throw new AttributeLengthException(); } if (Configuration.SET_COMPOSITION_ATTRIBUTE_COMPACT_NO_RESERVED_FIELDS) { value = ArraysUtil.readBytes(array, 3, length); length += 3; break; } value = ArraysUtil.readBytes(array, 4, length); length += 4; break; case CompactExtendedLength: type = AttributeType.forValue(ArraysUtil.bytes2int(ArraysUtil.readBytes(array, 1, 1))); length = ArraysUtil.bytes2int(ArraysUtil.readBytes(array, 2, 2)); if (length < 256 || 4084 < length) { throw new AttributeLengthException(); } value = ArraysUtil.readBytes(array, 4, length); length += 4; break; case NonCompact: type = AttributeType.forValue(ArraysUtil.bytes2int(ArraysUtil.readBytes(array, 1, 3))); length = ArraysUtil.bytes2int(ArraysUtil.readBytes(array, 4, 4)); if (length < 0 || 4080 < length) { throw new AttributeLengthException(); } value = ArraysUtil.readBytes(array, 8, length); length += 8; break; default: variant = AttributeVariant.None; } return decode(flags, variant, type, length, value); } }
AttributeFactory { protected static Attribute decode(byte[] array) throws AttributeLengthException, AddressLengthException, UnknownNodeIdException, UnknownPrefixException, TlvNotFoundException, UnknownHostException, AttributeVariantException { Flags flags = getFlags(array[0]); AttributeVariant variant = AttributeVariant.NonCompact; if (flags.isCompact()) { variant = AttributeVariant.Compact; if (flags.isExtendedLength()) { variant = AttributeVariant.CompactExtendedLength; } } AttributeType type = AttributeType.Unspecified; int length = 0; byte[] value = new byte[length]; switch (variant) { case Compact: type = AttributeType.forValue(ArraysUtil.bytes2int(ArraysUtil.readBytes(array, 1, 1))); length = ArraysUtil.bytes2int(ArraysUtil.readBytes(array, 2, 1)); if (length < 0 || 255 < length) { throw new AttributeLengthException(); } if (Configuration.SET_COMPOSITION_ATTRIBUTE_COMPACT_NO_RESERVED_FIELDS) { value = ArraysUtil.readBytes(array, 3, length); length += 3; break; } value = ArraysUtil.readBytes(array, 4, length); length += 4; break; case CompactExtendedLength: type = AttributeType.forValue(ArraysUtil.bytes2int(ArraysUtil.readBytes(array, 1, 1))); length = ArraysUtil.bytes2int(ArraysUtil.readBytes(array, 2, 2)); if (length < 256 || 4084 < length) { throw new AttributeLengthException(); } value = ArraysUtil.readBytes(array, 4, length); length += 4; break; case NonCompact: type = AttributeType.forValue(ArraysUtil.bytes2int(ArraysUtil.readBytes(array, 1, 3))); length = ArraysUtil.bytes2int(ArraysUtil.readBytes(array, 4, 4)); if (length < 0 || 4080 < length) { throw new AttributeLengthException(); } value = ArraysUtil.readBytes(array, 8, length); length += 8; break; default: variant = AttributeVariant.None; } return decode(flags, variant, type, length, value); }  }
AttributeFactory { protected static Attribute decode(byte[] array) throws AttributeLengthException, AddressLengthException, UnknownNodeIdException, UnknownPrefixException, TlvNotFoundException, UnknownHostException, AttributeVariantException { Flags flags = getFlags(array[0]); AttributeVariant variant = AttributeVariant.NonCompact; if (flags.isCompact()) { variant = AttributeVariant.Compact; if (flags.isExtendedLength()) { variant = AttributeVariant.CompactExtendedLength; } } AttributeType type = AttributeType.Unspecified; int length = 0; byte[] value = new byte[length]; switch (variant) { case Compact: type = AttributeType.forValue(ArraysUtil.bytes2int(ArraysUtil.readBytes(array, 1, 1))); length = ArraysUtil.bytes2int(ArraysUtil.readBytes(array, 2, 1)); if (length < 0 || 255 < length) { throw new AttributeLengthException(); } if (Configuration.SET_COMPOSITION_ATTRIBUTE_COMPACT_NO_RESERVED_FIELDS) { value = ArraysUtil.readBytes(array, 3, length); length += 3; break; } value = ArraysUtil.readBytes(array, 4, length); length += 4; break; case CompactExtendedLength: type = AttributeType.forValue(ArraysUtil.bytes2int(ArraysUtil.readBytes(array, 1, 1))); length = ArraysUtil.bytes2int(ArraysUtil.readBytes(array, 2, 2)); if (length < 256 || 4084 < length) { throw new AttributeLengthException(); } value = ArraysUtil.readBytes(array, 4, length); length += 4; break; case NonCompact: type = AttributeType.forValue(ArraysUtil.bytes2int(ArraysUtil.readBytes(array, 1, 3))); length = ArraysUtil.bytes2int(ArraysUtil.readBytes(array, 4, 4)); if (length < 0 || 4080 < length) { throw new AttributeLengthException(); } value = ArraysUtil.readBytes(array, 8, length); length += 8; break; default: variant = AttributeVariant.None; } return decode(flags, variant, type, length, value); }  static Attribute createCapabilities(Version version); static Attribute createHoldTime(int holdTimeMin); static Attribute createHoldTime(int holdTimeMin, int holdTimeMax); static Attribute createIpv4AddPrefix(List<IpPrefix> prefixes, byte flags); static Attribute createIpv4DeletePrefix(List<IpPrefix> prefixes, byte flags); static Attribute createIpv6AddPrefix(List<IpPrefix> prefixes, byte flags); static Attribute createIpv6DeletePrefix(List<IpPrefix> prefixes, byte flags); static Attribute createPeerSequence(List<NodeId> nodesIds); static Attribute createSourceGroupTag(int sgt); static Attribute createSxpNodeId(NodeId nodeId); static byte[] encodeCapability(Capabilities capability); }
AttributeFactory { protected static Attribute decode(byte[] array) throws AttributeLengthException, AddressLengthException, UnknownNodeIdException, UnknownPrefixException, TlvNotFoundException, UnknownHostException, AttributeVariantException { Flags flags = getFlags(array[0]); AttributeVariant variant = AttributeVariant.NonCompact; if (flags.isCompact()) { variant = AttributeVariant.Compact; if (flags.isExtendedLength()) { variant = AttributeVariant.CompactExtendedLength; } } AttributeType type = AttributeType.Unspecified; int length = 0; byte[] value = new byte[length]; switch (variant) { case Compact: type = AttributeType.forValue(ArraysUtil.bytes2int(ArraysUtil.readBytes(array, 1, 1))); length = ArraysUtil.bytes2int(ArraysUtil.readBytes(array, 2, 1)); if (length < 0 || 255 < length) { throw new AttributeLengthException(); } if (Configuration.SET_COMPOSITION_ATTRIBUTE_COMPACT_NO_RESERVED_FIELDS) { value = ArraysUtil.readBytes(array, 3, length); length += 3; break; } value = ArraysUtil.readBytes(array, 4, length); length += 4; break; case CompactExtendedLength: type = AttributeType.forValue(ArraysUtil.bytes2int(ArraysUtil.readBytes(array, 1, 1))); length = ArraysUtil.bytes2int(ArraysUtil.readBytes(array, 2, 2)); if (length < 256 || 4084 < length) { throw new AttributeLengthException(); } value = ArraysUtil.readBytes(array, 4, length); length += 4; break; case NonCompact: type = AttributeType.forValue(ArraysUtil.bytes2int(ArraysUtil.readBytes(array, 1, 3))); length = ArraysUtil.bytes2int(ArraysUtil.readBytes(array, 4, 4)); if (length < 0 || 4080 < length) { throw new AttributeLengthException(); } value = ArraysUtil.readBytes(array, 8, length); length += 8; break; default: variant = AttributeVariant.None; } return decode(flags, variant, type, length, value); }  static Attribute createCapabilities(Version version); static Attribute createHoldTime(int holdTimeMin); static Attribute createHoldTime(int holdTimeMin, int holdTimeMax); static Attribute createIpv4AddPrefix(List<IpPrefix> prefixes, byte flags); static Attribute createIpv4DeletePrefix(List<IpPrefix> prefixes, byte flags); static Attribute createIpv6AddPrefix(List<IpPrefix> prefixes, byte flags); static Attribute createIpv6DeletePrefix(List<IpPrefix> prefixes, byte flags); static Attribute createPeerSequence(List<NodeId> nodesIds); static Attribute createSourceGroupTag(int sgt); static Attribute createSxpNodeId(NodeId nodeId); static byte[] encodeCapability(Capabilities capability); static final byte COMPACT; static final byte OPTIONAL_COMPACT; static final byte NONTRANSITIVE_COMPACT; }