Bug 2756 - Match model update
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / serialization / match / OxmIpv6NdSllSerializerTest.java
index a3e4ff63a9490699dc0252c575f0a027ee055180..d625317cc616327984eeb19f7e50c5dfab53c83d 100644 (file)
-/*\r
- * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-\r
-package org.opendaylight.openflowjava.protocol.impl.serialization.match;\r
-\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertTrue;\r
-import io.netty.buffer.ByteBuf;\r
-import io.netty.buffer.PooledByteBufAllocator;\r
-\r
-import org.junit.Assert;\r
-import org.junit.Test;\r
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;\r
-import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;\r
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MacAddressMatchEntry;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MacAddressMatchEntryBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntry;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaskMatchEntryBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6NdSll;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder;\r
-\r
-/**\r
- * @author michal.polkorab\r
- *\r
- */\r
-public class OxmIpv6NdSllSerializerTest {\r
-\r
-    OxmIpv6NdSllSerializer serializer = new OxmIpv6NdSllSerializer();\r
-\r
-    /**\r
-     * Test correct serialization\r
-     */\r
-    @Test\r
-    public void testSerialize() {\r
-        MatchEntriesBuilder builder = prepareMatchEntry(false, "00:01:02:03:04:05");\r
-        \r
-        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
-        serializer.serialize(builder.build(), buffer);\r
-\r
-        checkHeader(buffer, false);\r
-        byte[] address = new byte[6];\r
-        buffer.readBytes(address);\r
-        Assert.assertArrayEquals("Wrong address", new byte[]{0, 1, 2, 3, 4, 5}, address);\r
-        assertTrue("Unexpected data", buffer.readableBytes() == 0);\r
-    }\r
-\r
-    /**\r
-     * Test correct header serialization\r
-     */\r
-    @Test\r
-    public void testSerializeHeader() {\r
-        MatchEntriesBuilder builder = prepareHeader(false);\r
-        \r
-        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
-        serializer.serializeHeader(builder.build(), buffer);\r
-\r
-        checkHeader(buffer, false);\r
-        assertTrue("Unexpected data", buffer.readableBytes() == 0);\r
-    }\r
-\r
-    /**\r
-     * Test correct oxm-class return value\r
-     */\r
-    @Test\r
-    public void testGetOxmClassCode() {\r
-        assertEquals("Wrong oxm-class", OxmMatchConstants.OPENFLOW_BASIC_CLASS, serializer.getOxmClassCode());\r
-    }\r
-\r
-    /**\r
-     * Test correct oxm-field return value\r
-     */\r
-    @Test\r
-    public void getOxmFieldCode() {\r
-        assertEquals("Wrong oxm-class", OxmMatchConstants.IPV6_ND_SLL, serializer.getOxmFieldCode());\r
-    }\r
-\r
-    /**\r
-     * Test correct value length return value\r
-     */\r
-    @Test\r
-    public void testGetValueLength() {\r
-        assertEquals("Wrong value length", EncodeConstants.MAC_ADDRESS_LENGTH, serializer.getValueLength());\r
-    }\r
-\r
-    private static MatchEntriesBuilder prepareMatchEntry(boolean hasMask, String value) {\r
-        MatchEntriesBuilder builder = prepareHeader(hasMask);\r
-        if (hasMask) {\r
-            MaskMatchEntryBuilder maskBuilder = new MaskMatchEntryBuilder();\r
-            maskBuilder.setMask(new byte[]{15, 15, 0, 0, 10, 10});\r
-            builder.addAugmentation(MaskMatchEntry.class, maskBuilder.build());\r
-        }\r
-        MacAddressMatchEntryBuilder macBuilder = new MacAddressMatchEntryBuilder();\r
-        macBuilder.setMacAddress(new MacAddress(value));\r
-        builder.addAugmentation(MacAddressMatchEntry.class, macBuilder.build());\r
-        return builder;\r
-    }\r
-\r
-    private static MatchEntriesBuilder prepareHeader(boolean hasMask) {\r
-        MatchEntriesBuilder builder = new MatchEntriesBuilder();\r
-        builder.setOxmClass(OpenflowBasicClass.class);\r
-        builder.setOxmMatchField(Ipv6NdSll.class);\r
-        builder.setHasMask(hasMask);\r
-        return builder;\r
-    }\r
-\r
-    private static void checkHeader(ByteBuf buffer, boolean hasMask) {\r
-        assertEquals("Wrong oxm-class", OxmMatchConstants.OPENFLOW_BASIC_CLASS, buffer.readUnsignedShort());\r
-        short fieldAndMask = buffer.readUnsignedByte();\r
-        assertEquals("Wrong oxm-field", OxmMatchConstants.IPV6_ND_SLL, fieldAndMask >>> 1);\r
-        assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);\r
-        assertEquals("Wrong length", EncodeConstants.MAC_ADDRESS_LENGTH, buffer.readUnsignedByte());\r
-    }\r
+/*
+ * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowjava.protocol.impl.serialization.match;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.PooledByteBufAllocator;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv6NdSll;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6NdSllCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv6.nd.sll._case.Ipv6NdSllBuilder;
+
+/**
+ * @author michal.polkorab
+ *
+ */
+public class OxmIpv6NdSllSerializerTest {
+
+    OxmIpv6NdSllSerializer serializer = new OxmIpv6NdSllSerializer();
+
+    /**
+     * Test correct serialization
+     */
+    @Test
+    public void testSerialize() {
+        MatchEntryBuilder builder = prepareMatchEntry("00:01:02:03:04:05");
+
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();
+        serializer.serialize(builder.build(), buffer);
+
+        checkHeader(buffer, false);
+        byte[] address = new byte[6];
+        buffer.readBytes(address);
+        Assert.assertArrayEquals("Wrong address", new byte[]{0, 1, 2, 3, 4, 5}, address);
+        assertTrue("Unexpected data", buffer.readableBytes() == 0);
+    }
+
+    /**
+     * Test correct header serialization
+     */
+    @Test
+    public void testSerializeHeader() {
+        MatchEntryBuilder builder = prepareHeader(false);
+
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();
+        serializer.serializeHeader(builder.build(), buffer);
+
+        checkHeader(buffer, false);
+        assertTrue("Unexpected data", buffer.readableBytes() == 0);
+    }
+
+    /**
+     * Test correct oxm-class return value
+     */
+    @Test
+    public void testGetOxmClassCode() {
+        assertEquals("Wrong oxm-class", OxmMatchConstants.OPENFLOW_BASIC_CLASS, serializer.getOxmClassCode());
+    }
+
+    /**
+     * Test correct oxm-field return value
+     */
+    @Test
+    public void getOxmFieldCode() {
+        assertEquals("Wrong oxm-class", OxmMatchConstants.IPV6_ND_SLL, serializer.getOxmFieldCode());
+    }
+
+    /**
+     * Test correct value length return value
+     */
+    @Test
+    public void testGetValueLength() {
+        assertEquals("Wrong value length", EncodeConstants.MAC_ADDRESS_LENGTH, serializer.getValueLength());
+    }
+
+    private static MatchEntryBuilder prepareMatchEntry(String value) {
+        MatchEntryBuilder builder = prepareHeader(false);
+        Ipv6NdSllCaseBuilder casebuilder = new Ipv6NdSllCaseBuilder();
+        Ipv6NdSllBuilder valueBuilder = new Ipv6NdSllBuilder();
+        valueBuilder.setMacAddress(new MacAddress(value));
+        casebuilder.setIpv6NdSll(valueBuilder.build());
+        builder.setMatchEntryValue(casebuilder.build());
+        return builder;
+    }
+
+    private static MatchEntryBuilder prepareHeader(boolean hasMask) {
+        MatchEntryBuilder builder = new MatchEntryBuilder();
+        builder.setOxmClass(OpenflowBasicClass.class);
+        builder.setOxmMatchField(Ipv6NdSll.class);
+        builder.setHasMask(hasMask);
+        return builder;
+    }
+
+    private static void checkHeader(ByteBuf buffer, boolean hasMask) {
+        assertEquals("Wrong oxm-class", OxmMatchConstants.OPENFLOW_BASIC_CLASS, buffer.readUnsignedShort());
+        short fieldAndMask = buffer.readUnsignedByte();
+        assertEquals("Wrong oxm-field", OxmMatchConstants.IPV6_ND_SLL, fieldAndMask >>> 1);
+        assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);
+        assertEquals("Wrong length", EncodeConstants.MAC_ADDRESS_LENGTH, buffer.readUnsignedByte());
+    }
 }
\ No newline at end of file