### Question:
ConnectedDevicesService implements IService, IInputTranslator { @VisibleForTesting ArpPacketData deserializeArp(Ethernet eth, SwitchId switchId, long cookie) { try { List<Integer> vlans = new ArrayList<>(); IPacket payload = EthernetPacketToolbox.extractPayload(eth, vlans); if (payload instanceof ARP) { return new ArpPacketData((ARP) payload, vlans); } } catch (Exception exception) { logger.info("Could not deserialize ARP packet {} on switch {}. Cookie {}. Deserialization failure: {}", eth, switchId, Cookie.toString(cookie), exception.getMessage(), exception); return null; } logger.info("Got invalid ARP packet: {} on switch {}. Cookie {}", eth, switchId, cookie); return null; }  @Override Command makeCommand(CommandContext context, OfInput input); @Override void setup(FloodlightModuleContext context);  }### Answer:
@Test public void deserializeArpTest() throws PacketParsingException { Ethernet ethernet = buildEthernet(srcAndDstMacAddresses, ethTypeToByteArray(EthType.ARP), arpPacket); ArpPacketData data = service.deserializeArp(ethernet, null, 0); assertNotNull(data); assertTrue(data.getVlans().isEmpty()); assertEquals(buildArpPacket(arpPacket), data.getArp()); }
@Test public void deserializeArpWithVlanTest() throws PacketParsingException { short vlan = 1234; Ethernet ethernet = buildEthernet(srcAndDstMacAddresses, ethTypeToByteArray(EthType.VLAN_FRAME), shortToByteArray(vlan), ethTypeToByteArray(EthType.ARP), arpPacket); ArpPacketData data = service.deserializeArp(ethernet, null, 0); assertNotNull(data); assertEquals(1, data.getVlans().size()); assertEquals(Integer.valueOf(vlan), data.getVlans().get(0)); assertEquals(buildArpPacket(arpPacket), data.getArp()); }
@Test public void deserializeArpWithTwoVlanTest() throws PacketParsingException { short innerVlan = 1234; short outerVlan = 2345; Ethernet ethernet = buildEthernet(srcAndDstMacAddresses, ethTypeToByteArray(EthType.VLAN_FRAME), shortToByteArray(outerVlan), ethTypeToByteArray(EthType.VLAN_FRAME), shortToByteArray(innerVlan), ethTypeToByteArray(EthType.ARP), arpPacket); ArpPacketData data = service.deserializeArp(ethernet, null, 0); assertNotNull(data); assertEquals(2, data.getVlans().size()); assertEquals(Integer.valueOf(outerVlan), data.getVlans().get(0)); assertEquals(Integer.valueOf(innerVlan), data.getVlans().get(1)); assertEquals(buildArpPacket(arpPacket), data.getArp()); }
@Test public void deserializeArpWithQinQVlansTest() throws PacketParsingException { short vlan1 = 1234; short vlan2 = 2345; short vlan3 = 4000; Ethernet ethernet = buildEthernet(srcAndDstMacAddresses, ethTypeToByteArray(EthType.Q_IN_Q), shortToByteArray(vlan1), ethTypeToByteArray(EthType.BRIDGING), shortToByteArray(vlan2), ethTypeToByteArray(EthType.VLAN_FRAME), shortToByteArray(vlan3), ethTypeToByteArray(EthType.ARP), arpPacket); ArpPacketData data = service.deserializeArp(ethernet, null, 0); assertNotNull(data); assertEquals(3, data.getVlans().size()); assertEquals(Integer.valueOf(vlan1), data.getVlans().get(0)); assertEquals(Integer.valueOf(vlan2), data.getVlans().get(1)); assertEquals(Integer.valueOf(vlan3), data.getVlans().get(2)); assertEquals(buildArpPacket(arpPacket), data.getArp()); }