@Test public void testDeserialize() throws Exception { IPv4 ipv4 = deserializer.deserialize(headerBytes, 0, headerBytes.length); assertEquals(version, ipv4.getVersion()); assertEquals(headerLength, ipv4.getHeaderLength()); assertEquals(diffServ, ipv4.getDiffServ()); assertEquals(totalLength, ipv4.getTotalLength()); assertEquals(identification, ipv4.getIdentification()); assertEquals(flags, ipv4.getFlags()); assertEquals(fragmentOffset, ipv4.getFragmentOffset()); assertEquals(ttl, ipv4.getTtl()); assertEquals(protocol, ipv4.getProtocol()); assertEquals(checksum, ipv4.getChecksum()); assertEquals(sourceAddress, ipv4.getSourceAddress()); assertEquals(destinationAddress, ipv4.getDestinationAddress()); assertTrue(ipv4.isTruncated()); }
@Override public IPacket deserialize(final byte[] data, final int offset, final int length) { final ByteBuffer bb = ByteBuffer.wrap(data, offset, length); short sscratch; this.version = bb.get(); this.headerLength = (byte) (this.version & 0xf); this.version = (byte) (this.version >> 4 & 0xf); this.diffServ = bb.get(); this.totalLength = bb.getShort(); this.identification = bb.getShort(); sscratch = bb.getShort(); this.flags = (byte) (sscratch >> 13 & 0x7); this.fragmentOffset = (short) (sscratch & 0x1fff); this.ttl = bb.get(); this.protocol = bb.get(); this.checksum = bb.getShort(); this.sourceAddress = bb.getInt(); this.destinationAddress = bb.getInt(); if (this.headerLength > 5) { final int optionsLength = (this.headerLength - 5) * 4; this.options = new byte[optionsLength]; bb.get(this.options); } if (this.totalLength != length) { this.isTruncated = true; } else { this.isTruncated = false; } Deserializer<? extends IPacket> deserializer; if (IPv4.PROTOCOL_DESERIALIZER_MAP.containsKey(this.protocol)) { deserializer = IPv4.PROTOCOL_DESERIALIZER_MAP.get(this.protocol); } else { deserializer = Data.deserializer(); } try { this.payload = deserializer.deserialize(data, bb.position(), bb.limit() - bb.position()); this.payload.setParent(this); } catch (DeserializationException e) { return this; } return this; }
IPv4 extends BasePacket { @Override public IPacket deserialize(final byte[] data, final int offset, final int length) { final ByteBuffer bb = ByteBuffer.wrap(data, offset, length); short sscratch; this.version = bb.get(); this.headerLength = (byte) (this.version & 0xf); this.version = (byte) (this.version >> 4 & 0xf); this.diffServ = bb.get(); this.totalLength = bb.getShort(); this.identification = bb.getShort(); sscratch = bb.getShort(); this.flags = (byte) (sscratch >> 13 & 0x7); this.fragmentOffset = (short) (sscratch & 0x1fff); this.ttl = bb.get(); this.protocol = bb.get(); this.checksum = bb.getShort(); this.sourceAddress = bb.getInt(); this.destinationAddress = bb.getInt(); if (this.headerLength > 5) { final int optionsLength = (this.headerLength - 5) * 4; this.options = new byte[optionsLength]; bb.get(this.options); } if (this.totalLength != length) { this.isTruncated = true; } else { this.isTruncated = false; } Deserializer<? extends IPacket> deserializer; if (IPv4.PROTOCOL_DESERIALIZER_MAP.containsKey(this.protocol)) { deserializer = IPv4.PROTOCOL_DESERIALIZER_MAP.get(this.protocol); } else { deserializer = Data.deserializer(); } try { this.payload = deserializer.deserialize(data, bb.position(), bb.limit() - bb.position()); this.payload.setParent(this); } catch (DeserializationException e) { return this; } return this; } }
IPv4 extends BasePacket { @Override public IPacket deserialize(final byte[] data, final int offset, final int length) { final ByteBuffer bb = ByteBuffer.wrap(data, offset, length); short sscratch; this.version = bb.get(); this.headerLength = (byte) (this.version & 0xf); this.version = (byte) (this.version >> 4 & 0xf); this.diffServ = bb.get(); this.totalLength = bb.getShort(); this.identification = bb.getShort(); sscratch = bb.getShort(); this.flags = (byte) (sscratch >> 13 & 0x7); this.fragmentOffset = (short) (sscratch & 0x1fff); this.ttl = bb.get(); this.protocol = bb.get(); this.checksum = bb.getShort(); this.sourceAddress = bb.getInt(); this.destinationAddress = bb.getInt(); if (this.headerLength > 5) { final int optionsLength = (this.headerLength - 5) * 4; this.options = new byte[optionsLength]; bb.get(this.options); } if (this.totalLength != length) { this.isTruncated = true; } else { this.isTruncated = false; } Deserializer<? extends IPacket> deserializer; if (IPv4.PROTOCOL_DESERIALIZER_MAP.containsKey(this.protocol)) { deserializer = IPv4.PROTOCOL_DESERIALIZER_MAP.get(this.protocol); } else { deserializer = Data.deserializer(); } try { this.payload = deserializer.deserialize(data, bb.position(), bb.limit() - bb.position()); this.payload.setParent(this); } catch (DeserializationException e) { return this; } return this; } IPv4(); }
IPv4 extends BasePacket { @Override public IPacket deserialize(final byte[] data, final int offset, final int length) { final ByteBuffer bb = ByteBuffer.wrap(data, offset, length); short sscratch; this.version = bb.get(); this.headerLength = (byte) (this.version & 0xf); this.version = (byte) (this.version >> 4 & 0xf); this.diffServ = bb.get(); this.totalLength = bb.getShort(); this.identification = bb.getShort(); sscratch = bb.getShort(); this.flags = (byte) (sscratch >> 13 & 0x7); this.fragmentOffset = (short) (sscratch & 0x1fff); this.ttl = bb.get(); this.protocol = bb.get(); this.checksum = bb.getShort(); this.sourceAddress = bb.getInt(); this.destinationAddress = bb.getInt(); if (this.headerLength > 5) { final int optionsLength = (this.headerLength - 5) * 4; this.options = new byte[optionsLength]; bb.get(this.options); } if (this.totalLength != length) { this.isTruncated = true; } else { this.isTruncated = false; } Deserializer<? extends IPacket> deserializer; if (IPv4.PROTOCOL_DESERIALIZER_MAP.containsKey(this.protocol)) { deserializer = IPv4.PROTOCOL_DESERIALIZER_MAP.get(this.protocol); } else { deserializer = Data.deserializer(); } try { this.payload = deserializer.deserialize(data, bb.position(), bb.limit() - bb.position()); this.payload.setParent(this); } catch (DeserializationException e) { return this; } return this; } IPv4(); byte getVersion(); IPv4 setVersion(final byte version); byte getHeaderLength(); byte getDscp(); IPv4 setDscp(byte dscp); byte getEcn(); IPv4 setEcn(byte ecn); byte getDiffServ(); IPv4 setDiffServ(final byte diffServ); short getTotalLength(); short getIdentification(); boolean isTruncated(); void setTruncated(final boolean isTruncated); IPv4 setIdentification(final short identification); byte getFlags(); IPv4 setFlags(final byte flags); short getFragmentOffset(); IPv4 setFragmentOffset(final short fragmentOffset); byte getTtl(); IPv4 setTtl(final byte ttl); byte getProtocol(); IPv4 setProtocol(final byte protocol); short getChecksum(); IPv4 setChecksum(final short checksum); @Override void resetChecksum(); int getSourceAddress(); IPv4 setSourceAddress(final int sourceAddress); IPv4 setSourceAddress(final String sourceAddress); int getDestinationAddress(); IPv4 setDestinationAddress(final int destinationAddress); IPv4 setDestinationAddress(final String destinationAddress); byte[] getOptions(); IPv4 setOptions(final byte[] options); @Override byte[] serialize(); @Override IPacket deserialize(final byte[] data, final int offset,
                               final int length); static int toIPv4Address(final String ipAddress); static int toIPv4Address(final byte[] ipAddress); static String fromIPv4Address(final int ipAddress); static String fromIPv4AddressCollection(
            final Collection<Integer> ipAddresses); static byte[] toIPv4AddressBytes(final String ipAddress); static byte[] toIPv4AddressBytes(final int ipAddress); @Override int hashCode(); @Override boolean equals(final Object obj); static Deserializer<IPv4> deserializer(); @Override String toString(); }
IPv4 extends BasePacket { @Override public IPacket deserialize(final byte[] data, final int offset, final int length) { final ByteBuffer bb = ByteBuffer.wrap(data, offset, length); short sscratch; this.version = bb.get(); this.headerLength = (byte) (this.version & 0xf); this.version = (byte) (this.version >> 4 & 0xf); this.diffServ = bb.get(); this.totalLength = bb.getShort(); this.identification = bb.getShort(); sscratch = bb.getShort(); this.flags = (byte) (sscratch >> 13 & 0x7); this.fragmentOffset = (short) (sscratch & 0x1fff); this.ttl = bb.get(); this.protocol = bb.get(); this.checksum = bb.getShort(); this.sourceAddress = bb.getInt(); this.destinationAddress = bb.getInt(); if (this.headerLength > 5) { final int optionsLength = (this.headerLength - 5) * 4; this.options = new byte[optionsLength]; bb.get(this.options); } if (this.totalLength != length) { this.isTruncated = true; } else { this.isTruncated = false; } Deserializer<? extends IPacket> deserializer; if (IPv4.PROTOCOL_DESERIALIZER_MAP.containsKey(this.protocol)) { deserializer = IPv4.PROTOCOL_DESERIALIZER_MAP.get(this.protocol); } else { deserializer = Data.deserializer(); } try { this.payload = deserializer.deserialize(data, bb.position(), bb.limit() - bb.position()); this.payload.setParent(this); } catch (DeserializationException e) { return this; } return this; } IPv4(); byte getVersion(); IPv4 setVersion(final byte version); byte getHeaderLength(); byte getDscp(); IPv4 setDscp(byte dscp); byte getEcn(); IPv4 setEcn(byte ecn); byte getDiffServ(); IPv4 setDiffServ(final byte diffServ); short getTotalLength(); short getIdentification(); boolean isTruncated(); void setTruncated(final boolean isTruncated); IPv4 setIdentification(final short identification); byte getFlags(); IPv4 setFlags(final byte flags); short getFragmentOffset(); IPv4 setFragmentOffset(final short fragmentOffset); byte getTtl(); IPv4 setTtl(final byte ttl); byte getProtocol(); IPv4 setProtocol(final byte protocol); short getChecksum(); IPv4 setChecksum(final short checksum); @Override void resetChecksum(); int getSourceAddress(); IPv4 setSourceAddress(final int sourceAddress); IPv4 setSourceAddress(final String sourceAddress); int getDestinationAddress(); IPv4 setDestinationAddress(final int destinationAddress); IPv4 setDestinationAddress(final String destinationAddress); byte[] getOptions(); IPv4 setOptions(final byte[] options); @Override byte[] serialize(); @Override IPacket deserialize(final byte[] data, final int offset,
                               final int length); static int toIPv4Address(final String ipAddress); static int toIPv4Address(final byte[] ipAddress); static String fromIPv4Address(final int ipAddress); static String fromIPv4AddressCollection(
            final Collection<Integer> ipAddresses); static byte[] toIPv4AddressBytes(final String ipAddress); static byte[] toIPv4AddressBytes(final int ipAddress); @Override int hashCode(); @Override boolean equals(final Object obj); static Deserializer<IPv4> deserializer(); @Override String toString(); static final byte PROTOCOL_ICMP; static final byte PROTOCOL_IGMP; static final byte PROTOCOL_TCP; static final byte PROTOCOL_UDP; static final byte PROTOCOL_PIM; static final Map<Byte, Deserializer<? extends IPacket>> PROTOCOL_DESERIALIZER_MAP; }