@Test public void testDeserialize() throws Exception { ARP arp = deserializer.deserialize(byteHeader, 0, byteHeader.length); assertEquals(ARP.HW_TYPE_ETHERNET, arp.getHardwareType()); assertEquals(ARP.PROTO_TYPE_IP, arp.getProtocolType()); assertEquals(hwAddressLength, arp.getHardwareAddressLength()); assertEquals(protoAddressLength, arp.getProtocolAddressLength()); assertEquals(ARP.OP_REPLY, arp.getOpCode()); assertTrue(Arrays.equals(srcMac.toBytes(), arp.getSenderHardwareAddress())); assertTrue(Arrays.equals(srcIp.toOctets(), arp.getSenderProtocolAddress())); assertTrue(Arrays.equals(targetMac.toBytes(), arp.getTargetHardwareAddress())); assertTrue(Arrays.equals(targetIp.toOctets(), arp.getTargetProtocolAddress())); }
@Override public IPacket deserialize(final byte[] data, final int offset, final int length) { final ByteBuffer bb = ByteBuffer.wrap(data, offset, length); this.hardwareType = bb.getShort(); this.protocolType = bb.getShort(); this.hardwareAddressLength = bb.get(); this.protocolAddressLength = bb.get(); this.opCode = bb.getShort(); this.senderHardwareAddress = new byte[0xff & this.hardwareAddressLength]; bb.get(this.senderHardwareAddress, 0, this.senderHardwareAddress.length); this.senderProtocolAddress = new byte[0xff & this.protocolAddressLength]; bb.get(this.senderProtocolAddress, 0, this.senderProtocolAddress.length); this.targetHardwareAddress = new byte[0xff & this.hardwareAddressLength]; bb.get(this.targetHardwareAddress, 0, this.targetHardwareAddress.length); this.targetProtocolAddress = new byte[0xff & this.protocolAddressLength]; bb.get(this.targetProtocolAddress, 0, this.targetProtocolAddress.length); return this; }
ARP extends BasePacket { @Override public IPacket deserialize(final byte[] data, final int offset, final int length) { final ByteBuffer bb = ByteBuffer.wrap(data, offset, length); this.hardwareType = bb.getShort(); this.protocolType = bb.getShort(); this.hardwareAddressLength = bb.get(); this.protocolAddressLength = bb.get(); this.opCode = bb.getShort(); this.senderHardwareAddress = new byte[0xff & this.hardwareAddressLength]; bb.get(this.senderHardwareAddress, 0, this.senderHardwareAddress.length); this.senderProtocolAddress = new byte[0xff & this.protocolAddressLength]; bb.get(this.senderProtocolAddress, 0, this.senderProtocolAddress.length); this.targetHardwareAddress = new byte[0xff & this.hardwareAddressLength]; bb.get(this.targetHardwareAddress, 0, this.targetHardwareAddress.length); this.targetProtocolAddress = new byte[0xff & this.protocolAddressLength]; bb.get(this.targetProtocolAddress, 0, this.targetProtocolAddress.length); return this; } }
ARP extends BasePacket { @Override public IPacket deserialize(final byte[] data, final int offset, final int length) { final ByteBuffer bb = ByteBuffer.wrap(data, offset, length); this.hardwareType = bb.getShort(); this.protocolType = bb.getShort(); this.hardwareAddressLength = bb.get(); this.protocolAddressLength = bb.get(); this.opCode = bb.getShort(); this.senderHardwareAddress = new byte[0xff & this.hardwareAddressLength]; bb.get(this.senderHardwareAddress, 0, this.senderHardwareAddress.length); this.senderProtocolAddress = new byte[0xff & this.protocolAddressLength]; bb.get(this.senderProtocolAddress, 0, this.senderProtocolAddress.length); this.targetHardwareAddress = new byte[0xff & this.hardwareAddressLength]; bb.get(this.targetHardwareAddress, 0, this.targetHardwareAddress.length); this.targetProtocolAddress = new byte[0xff & this.protocolAddressLength]; bb.get(this.targetProtocolAddress, 0, this.targetProtocolAddress.length); return this; }  }
ARP extends BasePacket { @Override public IPacket deserialize(final byte[] data, final int offset, final int length) { final ByteBuffer bb = ByteBuffer.wrap(data, offset, length); this.hardwareType = bb.getShort(); this.protocolType = bb.getShort(); this.hardwareAddressLength = bb.get(); this.protocolAddressLength = bb.get(); this.opCode = bb.getShort(); this.senderHardwareAddress = new byte[0xff & this.hardwareAddressLength]; bb.get(this.senderHardwareAddress, 0, this.senderHardwareAddress.length); this.senderProtocolAddress = new byte[0xff & this.protocolAddressLength]; bb.get(this.senderProtocolAddress, 0, this.senderProtocolAddress.length); this.targetHardwareAddress = new byte[0xff & this.hardwareAddressLength]; bb.get(this.targetHardwareAddress, 0, this.targetHardwareAddress.length); this.targetProtocolAddress = new byte[0xff & this.protocolAddressLength]; bb.get(this.targetProtocolAddress, 0, this.targetProtocolAddress.length); return this; }  short getHardwareType(); ARP setHardwareType(final short hwType); short getProtocolType(); ARP setProtocolType(final short protoType); byte getHardwareAddressLength(); ARP setHardwareAddressLength(final byte hwAddressLength); byte getProtocolAddressLength(); ARP setProtocolAddressLength(final byte protoAddressLength); short getOpCode(); ARP setOpCode(final short op); byte[] getSenderHardwareAddress(); ARP setSenderHardwareAddress(final byte[] senderHWAddress); byte[] getSenderProtocolAddress(); ARP setSenderProtocolAddress(final byte[] senderProtoAddress); ARP setSenderProtocolAddress(final int address); byte[] getTargetHardwareAddress(); ARP setTargetHardwareAddress(final byte[] targetHWAddress); byte[] getTargetProtocolAddress(); boolean isGratuitous(); ARP setTargetProtocolAddress(final byte[] targetProtoAddress); ARP setTargetProtocolAddress(final int address); @Override byte[] serialize(); @Override IPacket deserialize(final byte[] data, final int offset,
                               final int length); @Override int hashCode(); @Override boolean equals(final Object obj); static Ethernet buildArpReply(Ip4Address srcIp, MacAddress srcMac,
            Ethernet request); static Deserializer<ARP> deserializer(); @Override String toString(); }
ARP extends BasePacket { @Override public IPacket deserialize(final byte[] data, final int offset, final int length) { final ByteBuffer bb = ByteBuffer.wrap(data, offset, length); this.hardwareType = bb.getShort(); this.protocolType = bb.getShort(); this.hardwareAddressLength = bb.get(); this.protocolAddressLength = bb.get(); this.opCode = bb.getShort(); this.senderHardwareAddress = new byte[0xff & this.hardwareAddressLength]; bb.get(this.senderHardwareAddress, 0, this.senderHardwareAddress.length); this.senderProtocolAddress = new byte[0xff & this.protocolAddressLength]; bb.get(this.senderProtocolAddress, 0, this.senderProtocolAddress.length); this.targetHardwareAddress = new byte[0xff & this.hardwareAddressLength]; bb.get(this.targetHardwareAddress, 0, this.targetHardwareAddress.length); this.targetProtocolAddress = new byte[0xff & this.protocolAddressLength]; bb.get(this.targetProtocolAddress, 0, this.targetProtocolAddress.length); return this; }  short getHardwareType(); ARP setHardwareType(final short hwType); short getProtocolType(); ARP setProtocolType(final short protoType); byte getHardwareAddressLength(); ARP setHardwareAddressLength(final byte hwAddressLength); byte getProtocolAddressLength(); ARP setProtocolAddressLength(final byte protoAddressLength); short getOpCode(); ARP setOpCode(final short op); byte[] getSenderHardwareAddress(); ARP setSenderHardwareAddress(final byte[] senderHWAddress); byte[] getSenderProtocolAddress(); ARP setSenderProtocolAddress(final byte[] senderProtoAddress); ARP setSenderProtocolAddress(final int address); byte[] getTargetHardwareAddress(); ARP setTargetHardwareAddress(final byte[] targetHWAddress); byte[] getTargetProtocolAddress(); boolean isGratuitous(); ARP setTargetProtocolAddress(final byte[] targetProtoAddress); ARP setTargetProtocolAddress(final int address); @Override byte[] serialize(); @Override IPacket deserialize(final byte[] data, final int offset,
                               final int length); @Override int hashCode(); @Override boolean equals(final Object obj); static Ethernet buildArpReply(Ip4Address srcIp, MacAddress srcMac,
            Ethernet request); static Deserializer<ARP> deserializer(); @Override String toString(); static final short HW_TYPE_ETHERNET; static final short PROTO_TYPE_IP; static final short OP_REQUEST; static final short OP_REPLY; static final short OP_RARP_REQUEST; static final short OP_RARP_REPLY; static final short INITIAL_HEADER_LENGTH; }