public static void test() throws Exception {

		// #########################################################################################
		System.out.println("Testing packet serialization:");
		/**
		 * Foreach packet class, create an instance, serialize it and
		 * unserialize it. Packet class and a random sequence number must be
		 * correct in addition to some specific data
		 */
		int i = 0;
		while (true) {
			// Packet send
			Packet packetSend = Packet.getPacketById((byte) i);

			if (packetSend == null) {
				break;
			}

			// Fill package
			packetSend.setSequenceNumber((int) (Math.random() * 100));
			packetSend.setSender((Inet4Address)InetAddress.getByName("128.128.128.128"));

			// Packet specific data
			if (packetSend instanceof KeepAlivePacket) {
				((KeepAlivePacket) packetSend).setData(KeepAlivePacket.PONG);
			} else if (packetSend instanceof DataPacket) {
				byte[] b = { 0, 1, 2, 3, 4, 5, 0, 42 };
				((DataPacket) packetSend).setData(b);
			}
			/* Can be ignored: packetSend instanceof CTSPacket */
			else if (packetSend instanceof RTSPacket) {
				((RTSPacket) packetSend).setAddress((Inet4Address)InetAddress.getByName("localhost"));
				((RTSPacket) packetSend).setSizeToSend(32);
			}
			else if (packetSend instanceof ConfigPacket) {
				((ConfigPacket) packetSend).setKey(ConfigPacket.Setting.FIX_LAMBDA);
				((ConfigPacket) packetSend).setValue(ConfigPacket.FALSE);
			}
			else if (packetSend instanceof StatsPacket) {
				((StatsPacket) packetSend).setLambda(64);
				((StatsPacket) packetSend).setQueueSize(32);
			}

			// serialization
			byte[] b = packetSend.serialize();

			// dump packet
			System.out.println("Packet " + packetSend.getClass() + ": " + bytesToHex(b));

			// Packet receive
			Packet packetReceive = Packet.getPacket(b);

			// Test if received packet equals send packet
			if (b.equals(packetReceive.serialize())) {
				throw new Exception("ERROR: Packet received: " + bytesToHex(packetReceive.serialize()));
			}
			i++;
		}

		// #########################################################################################

	}