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

        int headerLength = FIXED_HEADER_LENGTH + routingData.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.headerExtLength);
        bb.put(this.routingType);
        bb.put(this.segmentsLeft);
        bb.put(this.routingData, 0, routingData.length);

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

        if (this.parent != null && this.parent instanceof IExtensionHeader) {
            ((IExtensionHeader) this.parent).setNextHeader(IPv6.PROTOCOL_ROUTING);
        }
        return data;
    }
@Test
    public void testSerialize() {
        Routing routing = new Routing();
        routing.setNextHeader((byte) 0x11);
        routing.setHeaderExtLength((byte) 0x02);
        routing.setRoutingType((byte) 0x00);
        routing.setSegmntsLeft((byte) 0x03);
        routing.setRoutingData(routingData);
        routing.setPayload(udp);

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