@Override
    public byte[] serialize() {
        byte[] payloadData = null;
        if (this.payload != null) {
            this.payload.setParent(this);
            payloadData = this.payload.serialize();
        }

        int headerLength = FIXED_HEADER_LENGTH + integrityCheck.length;
        int payloadLength = 0;
        if (payloadData != null) {
            payloadLength = payloadData.length;
        }

        final byte[] data = new byte[headerLength + payloadLength];
        final ByteBuffer bb = ByteBuffer.wrap(data);

        bb.put(this.nextHeader);
        bb.put(this.payloadLength);
        bb.putShort((short) 0);
        bb.putInt(this.securityParamIndex);
        bb.putInt(this.sequence);
        bb.put(this.integrityCheck, 0, integrityCheck.length);

        if (payloadData != null) {
            bb.put(payloadData);
        }

        if (this.parent != null && this.parent instanceof IExtensionHeader) {
            ((IExtensionHeader) this.parent).setNextHeader(IPv6.PROTOCOL_AH);
        }
        return data;
    }
@Test
    public void testSerialize() {
        Authentication auth = new Authentication();
        auth.setNextHeader((byte) 0x11);
        auth.setPayloadLength((byte) 0x02);
        auth.setSecurityParamIndex(0x13572468);
        auth.setSequence(0xffff00);
        auth.setIngegrityCheck(icv);
        auth.setPayload(udp);

        assertArrayEquals(auth.serialize(), bytePacket);
    }