+
+ /**
+ * Test for correct serialization of Ipv4Address match entry
+ */
+ @Test
+ public void testIpv6Flabel() {
+ Match match = buildIpv6FLabelMatch(0x0f9e8dL, false, null);
+
+ ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
+ MatchSerializer.encodeMatch(match, out);
+
+ Assert.assertEquals("Wrong type", 1, out.readUnsignedShort());
+ out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
+ Assert.assertEquals("Wrong class", 0x8000, out.readUnsignedShort());
+ Assert.assertEquals("Wrong field and mask", 28<<1, out.readUnsignedByte());
+ out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
+ byte[] label = new byte[4];
+ out.readBytes(label);
+
+ LOG.debug("label: "+ByteBufUtils.bytesToHexString(label));
+ Assert.assertArrayEquals("Wrong ipv6FLabel", new byte[]{0, 0x0f, (byte) 0x9e, (byte) 0x8d}, label);
+ }
+
+ /**
+ * Test for correct serialization of Ipv4Address match entry with mask
+ */
+ @Test
+ public void testIpv6FlabelWithMask() {
+ Match match = buildIpv6FLabelMatch(0x0f9e8dL, true, new byte[]{0, 0x0c, 0x7b, 0x6a});
+
+ ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
+ MatchSerializer.encodeMatch(match, out);
+
+ Assert.assertEquals("Wrong type", 1, out.readUnsignedShort());
+ out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
+ Assert.assertEquals("Wrong class", 0x8000, out.readUnsignedShort());
+ Assert.assertEquals("Wrong field and mask", 28<<1 | 1, out.readUnsignedByte());
+ out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
+ byte[] labelAndMask = new byte[8];
+ out.readBytes(labelAndMask);
+
+ LOG.debug("label: "+ByteBufUtils.bytesToHexString(labelAndMask));
+ Assert.assertArrayEquals("Wrong ipv6FLabel", new byte[]{0, 0x0f, (byte) 0x9e, (byte) 0x8d, 0, 0x0c, 0x7b, 0x6a}, labelAndMask);
+ }
+
+ /**
+ * Test for correct serialization of Ipv4Address match entry with wrong mask
+ */
+ @Test
+ public void testIpv6FlabelWithMaskBad() {
+ Match match = buildIpv6FLabelMatch(0x0f9e8dL, true, new byte[]{0x0c, 0x7b, 0x6a});
+
+ ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
+
+ try {
+ MatchSerializer.encodeMatch(match, out);
+ Assert.fail("incorrect length of mask ignored");
+ } catch (IllegalArgumentException e) {
+ //expected
+ }
+ }
+
+ /**
+ * @param labelValue ipv6 flow label
+ * @param hasMask
+ * @param mask ipv6 flow label mask
+ * @return
+ */
+ private static Match buildIpv6FLabelMatch(long labelValue, boolean hasMask, byte[] mask) {
+ MatchBuilder builder = new MatchBuilder();
+ builder.setType(OxmMatchType.class);
+ List<MatchEntries> entries = new ArrayList<>();
+ MatchEntriesBuilder entriesBuilder = new MatchEntriesBuilder();
+ entriesBuilder.setOxmClass(OpenflowBasicClass.class);
+ entriesBuilder.setOxmMatchField(Ipv6Flabel.class);
+ entriesBuilder.setHasMask(hasMask);
+ Ipv6FlabelMatchEntryBuilder ip6FLabelBuilder = new Ipv6FlabelMatchEntryBuilder();
+ ip6FLabelBuilder.setIpv6Flabel(new Ipv6FlowLabel(labelValue));
+ entriesBuilder.addAugmentation(Ipv6FlabelMatchEntry.class, ip6FLabelBuilder.build());
+ MaskMatchEntryBuilder maskBuilder = new MaskMatchEntryBuilder();
+ maskBuilder.setMask(mask);
+ entriesBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build());
+ entries.add(entriesBuilder.build());
+ builder.setMatchEntries(entries);
+ Match match = builder.build();
+ return match;
+ }
+
+