@Override
    public Object clone() {

        Class<? extends BasePacket> packetClass = this.getClass();
        Method[] allMethods = packetClass.getDeclaredMethods();

        Method deserializerFactory = null;
        for (Method m : allMethods) {
            String mname = m.getName();
            if (mname.equals("deserializer")) {
                deserializerFactory = m;
                break;
            }
        }

        if (deserializerFactory == null) {
            throw new IllegalStateException("No Deserializer found for " + packetClass.getName());
        }

        byte[] data = serialize();
        try {
            Deserializer deserializer = (Deserializer) deserializerFactory.invoke(this);
            return deserializer.deserialize(data, 0, data.length);
        } catch (IllegalAccessException | InvocationTargetException | DeserializationException ex) {
            throw new IllegalStateException(ex);
        }

    }
@Test
    public void testClone() {
        Ethernet p1 = new Ethernet();
        p1.sourceMACAddress = MacAddress.ONOS;
        p1.destinationMACAddress = MacAddress.ZERO;
        p1.payload = new Data("xyzzy".getBytes());
        BasePacket copy1 = (BasePacket) p1.clone();
        assertThat(p1, equalTo(copy1));
    }