Ipv6NaDecoder { public Ipv6NaDecoder(final byte[] packetData) { this.data = Arrays.copyOf(packetData, packetData.length); } Ipv6NaDecoder(final byte[] packetData); NeighborAdvertisePacket decode();  }
@Test public void testIpv6NaDecoder() throws UnknownHostException, BufferException { byte[] inputPayload = buildPacket( "33 33 00 00 00 02", "08 00 27 FE 8F 95", "86 DD", "60 00 00 00", "00 20", "3A", "FF", "20 01 0D B8 00 00 00 00 00 00 00 00 00 00 00 01", "FF 02 00 00 00 00 00 00 00 00 00 01 FF 00 00 02", "88", "00", "5E 94", "00 00 00 00", "20 01 0D B8 00 00 00 00 00 00 00 00 00 00 00 02", "02", "01", "08 00 27 FE 8F 95" ); NeighborAdvertisePacket expectedNa = new NeighborAdvertisePacketBuilder() .setDestinationMac(MacAddress.getDefaultInstance("33:33:00:00:00:02")) .setSourceMac(MacAddress.getDefaultInstance("08:00:27:fe:8f:95")) .setEthertype(EtherTypes.IPv6.intValue()).setVersion((short) 6).setFlowLabel(0L).setIpv6Length(0x0020) .setNextHeader((short) 0x3A).setHopLimit((short) 0xFF) .setSourceIpv6(Ipv6Address.getDefaultInstance("2001:db8:0:0:0:0:0:1")) .setDestinationIpv6(Ipv6Address.getDefaultInstance("ff02:0:0:0:0:1:ff00:2")) .setIcmp6Type(Icmpv6Type.NEIGHBOR_ADVERTISEMENT.getValue()).setIcmp6Code((short) 0) .setIcmp6Chksum(0x5E94).setFlags(0L) .setTargetAddress(Ipv6Address.getDefaultInstance("2001:db8:0:0:0:0:0:2")).setOptionType((short) 2) .setTargetAddrLength((short) 1).setTargetLlAddress(new MacAddress("08:00:27:fe:8f:95")).build(); assertEquals(expectedNa, new Ipv6NaDecoder(inputPayload).decode()); inputPayload = buildPacket( "33 33 00 00 00 02", "08 00 27 FE 8F 95", "86 DD", "60 00 00 00", "00 20", "3A", "FF", "20 01 0D B8 00 00 00 00 00 00 00 00 00 00 00 01", "FF 02 00 00 00 00 00 00 00 00 00 01 FF 00 00 02", "88", "00", "5E 95", "00 00 00 00", "20 01 0D B8 00 00 00 00 00 00 00 00 00 00 00 02", "02", "01", "08 00 27 FE 8F 95" ); assertNotEquals(expectedNa, new Ipv6NaDecoder(inputPayload).decode()); inputPayload = buildPacket( "33 33 00 00 00 02", "08 00 27 FE 8F 95", "86 DD", "60 00 00 00", "00 20", "3A", "FF", "20 01 0D B8 00 00 00 00 00 00 00 00 00 00 00 01", "FF 02 00 00 00 00 00 00 00 00 00 01 FF 00 00 02", "87", "00", "5E 94", "00 00 00 00", "20 01 0D B8 00 00 00 00 00 00 00 00 00 00 00 02", "02", "01", "08 00 27 FE 8F 95" ); assertNotEquals(expectedNa, new Ipv6NaDecoder(inputPayload).decode()); final byte[] invalidInputPayload = buildPacket( "33 33 00 00 00 02", "08 00 27 FE 8F 95", "86 DD", "60 00 00 00", "00 20", "3A" ); assertThrows(BufferException.class, () -> { new Ipv6NaDecoder(invalidInputPayload).decode(); }); }