@Test public void testSerialize() { IPv6 ipv6 = new IPv6(); ipv6.setPayload(udp); ipv6.setVersion((byte) 6); ipv6.setTrafficClass((byte) 0x93); ipv6.setFlowLabel(0x13579); ipv6.setNextHeader(IPv6.PROTOCOL_UDP); ipv6.setHopLimit((byte) 32); ipv6.setSourceAddress(SOURCE_ADDRESS); ipv6.setDestinationAddress(DESTINATION_ADDRESS); assertArrayEquals(ipv6.serialize(), bytePacket); }
@Override public byte[] serialize() { byte[] payloadData = null; if (this.payload != null) { this.payload.setParent(this); payloadData = this.payload.serialize(); } this.payloadLength = 0; if (payloadData != null) { this.payloadLength = (short) payloadData.length; } final byte[] data = new byte[FIXED_HEADER_LENGTH + payloadLength]; final ByteBuffer bb = ByteBuffer.wrap(data); bb.putInt((this.version & 0xf) << 28 | (this.trafficClass & 0xff) << 20 | this.flowLabel & 0xfffff); bb.putShort(this.payloadLength); bb.put(this.nextHeader); bb.put(this.hopLimit); bb.put(this.sourceAddress, 0, Ip6Address.BYTE_LENGTH); bb.put(this.destinationAddress, 0, Ip6Address.BYTE_LENGTH); if (payloadData != null) { bb.put(payloadData); } return data; }
IPv6 extends BasePacket implements IExtensionHeader { @Override public byte[] serialize() { byte[] payloadData = null; if (this.payload != null) { this.payload.setParent(this); payloadData = this.payload.serialize(); } this.payloadLength = 0; if (payloadData != null) { this.payloadLength = (short) payloadData.length; } final byte[] data = new byte[FIXED_HEADER_LENGTH + payloadLength]; final ByteBuffer bb = ByteBuffer.wrap(data); bb.putInt((this.version & 0xf) << 28 | (this.trafficClass & 0xff) << 20 | this.flowLabel & 0xfffff); bb.putShort(this.payloadLength); bb.put(this.nextHeader); bb.put(this.hopLimit); bb.put(this.sourceAddress, 0, Ip6Address.BYTE_LENGTH); bb.put(this.destinationAddress, 0, Ip6Address.BYTE_LENGTH); if (payloadData != null) { bb.put(payloadData); } return data; } }
IPv6 extends BasePacket implements IExtensionHeader { @Override public byte[] serialize() { byte[] payloadData = null; if (this.payload != null) { this.payload.setParent(this); payloadData = this.payload.serialize(); } this.payloadLength = 0; if (payloadData != null) { this.payloadLength = (short) payloadData.length; } final byte[] data = new byte[FIXED_HEADER_LENGTH + payloadLength]; final ByteBuffer bb = ByteBuffer.wrap(data); bb.putInt((this.version & 0xf) << 28 | (this.trafficClass & 0xff) << 20 | this.flowLabel & 0xfffff); bb.putShort(this.payloadLength); bb.put(this.nextHeader); bb.put(this.hopLimit); bb.put(this.sourceAddress, 0, Ip6Address.BYTE_LENGTH); bb.put(this.destinationAddress, 0, Ip6Address.BYTE_LENGTH); if (payloadData != null) { bb.put(payloadData); } return data; } IPv6(); }
IPv6 extends BasePacket implements IExtensionHeader { @Override public byte[] serialize() { byte[] payloadData = null; if (this.payload != null) { this.payload.setParent(this); payloadData = this.payload.serialize(); } this.payloadLength = 0; if (payloadData != null) { this.payloadLength = (short) payloadData.length; } final byte[] data = new byte[FIXED_HEADER_LENGTH + payloadLength]; final ByteBuffer bb = ByteBuffer.wrap(data); bb.putInt((this.version & 0xf) << 28 | (this.trafficClass & 0xff) << 20 | this.flowLabel & 0xfffff); bb.putShort(this.payloadLength); bb.put(this.nextHeader); bb.put(this.hopLimit); bb.put(this.sourceAddress, 0, Ip6Address.BYTE_LENGTH); bb.put(this.destinationAddress, 0, Ip6Address.BYTE_LENGTH); if (payloadData != null) { bb.put(payloadData); } return data; } IPv6(); byte getVersion(); IPv6 setVersion(final byte version); byte getTrafficClass(); IPv6 setTrafficClass(final byte trafficClass); int getFlowLabel(); IPv6 setFlowLabel(final int flowLabel); @Override byte getNextHeader(); @Override IPv6 setNextHeader(final byte nextHeader); byte getHopLimit(); IPv6 setHopLimit(final byte hopLimit); byte[] getSourceAddress(); IPv6 setSourceAddress(final byte[] sourceAddress); byte[] getDestinationAddress(); IPv6 setDestinationAddress(final byte[] destinationAddress); @Override byte[] serialize(); @Override IPacket deserialize(final byte[] data, final int offset,
                               final int length); @Override int hashCode(); @Override boolean equals(final Object obj); static Deserializer<IPv6> deserializer(); @Override String toString(); }
IPv6 extends BasePacket implements IExtensionHeader { @Override public byte[] serialize() { byte[] payloadData = null; if (this.payload != null) { this.payload.setParent(this); payloadData = this.payload.serialize(); } this.payloadLength = 0; if (payloadData != null) { this.payloadLength = (short) payloadData.length; } final byte[] data = new byte[FIXED_HEADER_LENGTH + payloadLength]; final ByteBuffer bb = ByteBuffer.wrap(data); bb.putInt((this.version & 0xf) << 28 | (this.trafficClass & 0xff) << 20 | this.flowLabel & 0xfffff); bb.putShort(this.payloadLength); bb.put(this.nextHeader); bb.put(this.hopLimit); bb.put(this.sourceAddress, 0, Ip6Address.BYTE_LENGTH); bb.put(this.destinationAddress, 0, Ip6Address.BYTE_LENGTH); if (payloadData != null) { bb.put(payloadData); } return data; } IPv6(); byte getVersion(); IPv6 setVersion(final byte version); byte getTrafficClass(); IPv6 setTrafficClass(final byte trafficClass); int getFlowLabel(); IPv6 setFlowLabel(final int flowLabel); @Override byte getNextHeader(); @Override IPv6 setNextHeader(final byte nextHeader); byte getHopLimit(); IPv6 setHopLimit(final byte hopLimit); byte[] getSourceAddress(); IPv6 setSourceAddress(final byte[] sourceAddress); byte[] getDestinationAddress(); IPv6 setDestinationAddress(final byte[] destinationAddress); @Override byte[] serialize(); @Override IPacket deserialize(final byte[] data, final int offset,
                               final int length); @Override int hashCode(); @Override boolean equals(final Object obj); static Deserializer<IPv6> deserializer(); @Override String toString(); static final byte FIXED_HEADER_LENGTH; static final byte PROTOCOL_TCP; static final byte PROTOCOL_UDP; static final byte PROTOCOL_ICMP6; static final byte PROTOCOL_HOPOPT; static final byte PROTOCOL_ROUTING; static final byte PROTOCOL_FRAG; static final byte PROTOCOL_ESP; static final byte PROTOCOL_AH; static final byte PROTOCOL_DSTOPT; static final Map<Byte, Deserializer<? extends IPacket>> PROTOCOL_DESERIALIZER_MAP; }