Improve unit test coverage 32/10132/2
authorMichal Polkorab <michal.polkorab@pantheon.sk>
Tue, 19 Aug 2014 13:45:29 +0000 (15:45 +0200)
committerMichal Polkorab <michal.polkorab@pantheon.sk>
Wed, 27 Aug 2014 08:28:14 +0000 (10:28 +0200)
Change-Id: I374bcf2c76a4a3b6cba441dc0c0570be7855d8a9
Signed-off-by: Michal Polkorab <michal.polkorab@pantheon.sk>
42 files changed:
openflow-protocol-api/src/test/java/org/opendaylight/openflowjava/protocol/api/connection/TlsConfigurationImplTest.java [new file with mode: 0644]
openflow-protocol-api/src/test/java/org/opendaylight/openflowjava/protocol/api/keys/extensibility/KeysTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/connection/ChannelOutboundQueueTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/connection/ResponseExpectedRpcListenerTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/connection/SimpleRpcListenerTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DeserializationFactoryTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/TypeToClassMapInitializerTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/SerializationFactoryTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpOpSerializerTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpShaSerializerTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpSpaSerializerTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpThaSerializerTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpTpaSerializerTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmEthDstSerializerTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmEthSrcSerializerTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmEthTypeSerializerTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIcmpv4CodeSerializerTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIcmpv4TypeSerializerTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIcmpv6CodeSerializerTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIcmpv6TypeSerializerTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpDscpSerializerTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpProtoSerializerTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv4DstSerializerTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv4SrcSerializerTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6ExtHdrSerializerTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6NdSllSerializerTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6NdTllSerializerTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmMetadataSerializerTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmMplsBosSerializerTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmMplsLabelSerializerTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmMplsTcSerializerTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmPbbIsidSerializerTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmSctpDstSerializerTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmSctpSrcSerializerTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmTcpDstSerializerTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmTcpSrcSerializerTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmTunnelIdSerializerTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmUdpDstSerializerTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmUdpSrcSerializerTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmVlanPcpSerializerTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmVlanVidSerializerTest.java [new file with mode: 0644]
util/src/test/java/org/opendaylight/openflowjava/util/ByteBufUtilsTest.java

diff --git a/openflow-protocol-api/src/test/java/org/opendaylight/openflowjava/protocol/api/connection/TlsConfigurationImplTest.java b/openflow-protocol-api/src/test/java/org/opendaylight/openflowjava/protocol/api/connection/TlsConfigurationImplTest.java
new file mode 100644 (file)
index 0000000..9816c25
--- /dev/null
@@ -0,0 +1,40 @@
+/*\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.api.connection;\r
+\r
+import static org.junit.Assert.*;\r
+\r
+import org.junit.Test;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.KeystoreType;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.PathType;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class TlsConfigurationImplTest {\r
+\r
+    /**\r
+     * Test correct TlsConfigurationImpl creation\r
+     */\r
+    @Test\r
+    public void test() {\r
+        TlsConfigurationImpl config = new TlsConfigurationImpl(KeystoreType.JKS,\r
+                "user/dir", PathType.CLASSPATH, KeystoreType.PKCS12, "/var/lib", PathType.PATH);\r
+        assertEquals("Wrong keystore location", "/var/lib", config.getTlsKeystore());\r
+        assertEquals("Wrong truststore location", "user/dir", config.getTlsTruststore());\r
+        assertEquals("Wrong keystore type", KeystoreType.PKCS12, config.getTlsKeystoreType());\r
+        assertEquals("Wrong truststore type", KeystoreType.JKS, config.getTlsTruststoreType());\r
+        assertEquals("Wrong keystore path type", PathType.PATH, config.getTlsKeystorePathType());\r
+        assertEquals("Wrong truststore path type", PathType.CLASSPATH, config.getTlsTruststorePathType());\r
+        assertEquals("Wrong certificate password", "opendaylight", config.getCertificatePassword());\r
+        assertEquals("Wrong keystore password", "opendaylight", config.getKeystorePassword());\r
+        assertEquals("Wrong truststore password", "opendaylight", config.getTruststorePassword());\r
+    }\r
+}
\ No newline at end of file
index 0093e9c83fc8efb05d65f06fd0481e5c6eda6a6d..5b464af2c20940eb1d742f86473ca18a0fc9f6d8 100644 (file)
@@ -7,13 +7,18 @@ import org.opendaylight.openflowjava.protocol.api.keys.ActionDeserializerKey;
 import org.opendaylight.openflowjava.protocol.api.keys.ActionSerializerKey;
 import org.opendaylight.openflowjava.protocol.api.keys.InstructionDeserializerKey;
 import org.opendaylight.openflowjava.protocol.api.keys.InstructionSerializerKey;
+import org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey;
+import org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey;
 import org.opendaylight.openflowjava.protocol.api.keys.experimenter.ExperimenterActionDeserializerKey;
 import org.opendaylight.openflowjava.protocol.api.keys.experimenter.ExperimenterActionSerializerKey;
 import org.opendaylight.openflowjava.protocol.api.keys.experimenter.ExperimenterInstructionDeserializerKey;
 import org.opendaylight.openflowjava.protocol.api.keys.experimenter.ExperimenterInstructionSerializerKey;
 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Experimenter;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.ExperimenterActionSubType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;
 
 /**
  * @author michal.polkorab
@@ -39,7 +44,12 @@ public class KeysTest {
         Assert.assertEquals(instructionDeserializerKey, experimenterInstructionDeserializerKey);
         Assert.assertEquals(instructionDeserializerKey.hashCode(), experimenterInstructionDeserializerKey.hashCode());
         
-        
+        MatchEntryDeserializerKey matchKey = new MatchEntryDeserializerKey(EncodeConstants.OF13_VERSION_ID,
+                OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ARP_OP);
+        MatchEntryDeserializerKey matchKey2 = new MatchEntryDeserializerKey(EncodeConstants.OF13_VERSION_ID,
+                OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ARP_OP);
+        Assert.assertEquals(matchKey, matchKey2);
+        Assert.assertEquals(matchKey.hashCode(), matchKey2.hashCode());
     }
 
     /**
@@ -61,10 +71,17 @@ public class KeysTest {
         ExperimenterInstructionSerializerKey experimenterInstructionSerializerKey = new ExperimenterInstructionSerializerKey(EncodeConstants.OF13_VERSION_ID, 1L);
         Assert.assertEquals(instructionSerializerKey, experimenterInstructionSerializerKey);
         Assert.assertEquals(instructionSerializerKey.hashCode(), experimenterInstructionSerializerKey.hashCode());
+
+        MatchEntrySerializerKey<OpenflowBasicClass, InPort> matchKey = new MatchEntrySerializerKey<>(
+                EncodeConstants.OF10_VERSION_ID, OpenflowBasicClass.class, InPort.class);
+        MatchEntrySerializerKey<OpenflowBasicClass, InPort> matchKey2 = new MatchEntrySerializerKey<>(
+                EncodeConstants.OF10_VERSION_ID, OpenflowBasicClass.class, InPort.class);
+        Assert.assertEquals(matchKey, matchKey2);
+        Assert.assertEquals(matchKey.hashCode(), matchKey2.hashCode());
     }
     
     private static class ExpSubType extends ExperimenterActionSubType {
-        
+        // empty class - only used in test for comparation
     }
 
 }
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/connection/ChannelOutboundQueueTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/connection/ChannelOutboundQueueTest.java
new file mode 100644 (file)
index 0000000..060072d
--- /dev/null
@@ -0,0 +1,52 @@
+/*\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.connection;\r
+\r
+import io.netty.channel.Channel;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.mockito.Mock;\r
+import org.mockito.MockitoAnnotations;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class ChannelOutboundQueueTest {\r
+\r
+    @Mock Channel channel;\r
+\r
+    /**\r
+     * Initialize mocks\r
+     */\r
+    public ChannelOutboundQueueTest() {\r
+        MockitoAnnotations.initMocks(this);\r
+    }\r
+\r
+    /**\r
+     * Test incorrect queue creation handling\r
+     */\r
+    @Test(expected=IllegalArgumentException.class)\r
+    public void testIncorrectQueueCreation() {\r
+        new ChannelOutboundQueue(channel, 0);\r
+    }\r
+\r
+    /**\r
+     * Test correct enqueue handling\r
+     */\r
+    @Test\r
+    public void testEnqueue() {\r
+        ChannelOutboundQueue queue = new ChannelOutboundQueue(channel, 1);\r
+        boolean enqueued = queue.enqueue(new SimpleRpcListener("INPUT", "Failed to send INPUT"));\r
+        Assert.assertTrue("Enqueue problem", enqueued);\r
+        enqueued = queue.enqueue(new SimpleRpcListener("INPUT", "Failed to send INPUT"));\r
+        Assert.assertFalse("Enqueue problem", enqueued);\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/connection/ResponseExpectedRpcListenerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/connection/ResponseExpectedRpcListenerTest.java
new file mode 100644 (file)
index 0000000..a535c08
--- /dev/null
@@ -0,0 +1,130 @@
+/*\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.connection;\r
+\r
+import static org.junit.Assert.fail;\r
+\r
+import java.util.Collections;\r
+import java.util.concurrent.ExecutionException;\r
+import java.util.concurrent.TimeUnit;\r
+import java.util.concurrent.TimeoutException;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.opendaylight.controller.sal.common.util.Rpcs;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInputBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;\r
+import org.opendaylight.yangtools.yang.common.RpcError;\r
+import org.opendaylight.yangtools.yang.common.RpcError.ErrorSeverity;\r
+import org.opendaylight.yangtools.yang.common.RpcResult;\r
+\r
+import com.google.common.cache.Cache;\r
+import com.google.common.cache.CacheBuilder;\r
+import com.google.common.cache.RemovalListener;\r
+import com.google.common.cache.RemovalNotification;\r
+import com.google.common.util.concurrent.SettableFuture;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class ResponseExpectedRpcListenerTest {\r
+\r
+    private static final RemovalListener<RpcResponseKey, ResponseExpectedRpcListener<?>> REMOVAL_LISTENER =\r
+            new RemovalListener<RpcResponseKey, ResponseExpectedRpcListener<?>>() {\r
+        @Override\r
+        public void onRemoval(\r
+                final RemovalNotification<RpcResponseKey, ResponseExpectedRpcListener<?>> notification) {\r
+            notification.getValue().discard();\r
+        }\r
+    };\r
+    private static final int RPC_RESPONSE_EXPIRATION = 1;\r
+    private Cache<RpcResponseKey, ResponseExpectedRpcListener<?>> responseCache  = CacheBuilder.newBuilder()\r
+            .concurrencyLevel(1)\r
+            .expireAfterWrite(RPC_RESPONSE_EXPIRATION, TimeUnit.MINUTES)\r
+            .removalListener(REMOVAL_LISTENER).build();\r
+\r
+    /**\r
+     * Test object creation\r
+     */\r
+    @Test(expected=NullPointerException.class)\r
+    public void testCreation() {\r
+        RpcResponseKey key = new RpcResponseKey(12345L, BarrierOutput.class.getName());\r
+        new ResponseExpectedRpcListener<>("MESSAGE", "Failed to send message", null, key);\r
+    }\r
+\r
+    /**\r
+     * Test object creation\r
+     */\r
+    @Test(expected=NullPointerException.class)\r
+    public void testCreation2() {\r
+        RpcResponseKey key = new RpcResponseKey(12345L, BarrierOutput.class.getName());\r
+        new ResponseExpectedRpcListener<>("MESSAGE", "Failed to send message", responseCache, null);\r
+    }\r
+\r
+    /**\r
+     * Test object creation\r
+     */\r
+    @Test\r
+    public void testDiscard() {\r
+        RpcResponseKey key = new RpcResponseKey(12345L, BarrierOutput.class.getName());\r
+        ResponseExpectedRpcListener<OfHeader> listener =\r
+                new ResponseExpectedRpcListener<>("MESSAGE", "Failed to send message", responseCache, key);\r
+        listener.discard();\r
+        RpcError rpcError = ConnectionAdapterImpl.buildRpcError("Failed to send message",\r
+                ErrorSeverity.ERROR, "check switch connection", new TimeoutException("Request timed out"));\r
+        SettableFuture<RpcResult<?>> result = SettableFuture.create();\r
+        result.set(Rpcs.getRpcResult(false, null, Collections.singletonList(rpcError)));\r
+        try {\r
+            Assert.assertEquals("Wrong result", result.get().getErrors().iterator().next().getMessage(),\r
+                    listener.getResult().get().getErrors().iterator().next().getMessage());\r
+            Assert.assertEquals("Wrong result", result.get().getResult(), listener.getResult().get().getResult());\r
+            Assert.assertEquals("Wrong result", result.get().isSuccessful(), listener.getResult().get().isSuccessful());\r
+        } catch (InterruptedException | ExecutionException e) {\r
+            fail("Problem accessing result");\r
+        }\r
+    }\r
+\r
+    /**\r
+     * Test object creation\r
+     */\r
+    @Test\r
+    public void testCompleted() {\r
+        RpcResponseKey key = new RpcResponseKey(12345L, BarrierOutput.class.getName());\r
+        ResponseExpectedRpcListener<OfHeader> listener =\r
+                new ResponseExpectedRpcListener<>("MESSAGE", "Failed to send message", responseCache, key);\r
+        BarrierInputBuilder barrierBuilder = new BarrierInputBuilder();\r
+        BarrierInput barrierInput = barrierBuilder.build();\r
+        listener.completed(barrierInput);\r
+        SettableFuture<RpcResult<?>> result = SettableFuture.create();\r
+        result.set(Rpcs.getRpcResult(true, barrierInput, Collections.<RpcError>emptyList()));\r
+        try {\r
+            Assert.assertEquals("Wrong result", result.get().getErrors(), listener.getResult().get().getErrors());\r
+            Assert.assertEquals("Wrong result", result.get().getResult(), listener.getResult().get().getResult());\r
+            Assert.assertEquals("Wrong result", result.get().isSuccessful(), listener.getResult().get().isSuccessful());\r
+        } catch (InterruptedException | ExecutionException e) {\r
+            fail("Problem accessing result");\r
+        }\r
+    }\r
+\r
+    /**\r
+     * Test object creation\r
+     */\r
+    @Test\r
+    public void testOperationSuccessful() {\r
+        RpcResponseKey key = new RpcResponseKey(12345L, BarrierOutput.class.getName());\r
+        ResponseExpectedRpcListener<OfHeader> listener =\r
+                new ResponseExpectedRpcListener<>("MESSAGE", "Failed to send message", responseCache, key);\r
+        listener.operationSuccessful();\r
+        ResponseExpectedRpcListener<?> present = responseCache.getIfPresent(key);\r
+        Assert.assertEquals(present, listener);\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/connection/SimpleRpcListenerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/connection/SimpleRpcListenerTest.java
new file mode 100644 (file)
index 0000000..db9d689
--- /dev/null
@@ -0,0 +1,57 @@
+/*\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.connection;\r
+\r
+import static org.junit.Assert.fail;\r
+\r
+import java.util.Collections;\r
+import java.util.concurrent.ExecutionException;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.opendaylight.controller.sal.common.util.Rpcs;\r
+import org.opendaylight.yangtools.yang.common.RpcError;\r
+import org.opendaylight.yangtools.yang.common.RpcResult;\r
+\r
+import com.google.common.util.concurrent.SettableFuture;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class SimpleRpcListenerTest {\r
+\r
+    /**\r
+     * Test SimpleRpcListener creation\r
+     */\r
+    @Test\r
+    public void test() {\r
+        SimpleRpcListener listener = new SimpleRpcListener("MESSAGE", "Failed to send message");\r
+        Assert.assertEquals("Wrong message", "MESSAGE", listener.takeMessage());\r
+        Assert.assertEquals("Wrong message", listener, listener.takeListener());\r
+    }\r
+\r
+    /**\r
+     * Test rpc success\r
+     */\r
+    @Test\r
+    public void testSuccessfulRpc() {\r
+        SimpleRpcListener listener = new SimpleRpcListener("MESSAGE", "Failed to send message");\r
+        listener.operationSuccessful();\r
+        SettableFuture<RpcResult<?>> result = SettableFuture.create();\r
+        result.set(Rpcs.getRpcResult(true, null, Collections.<RpcError>emptyList()));\r
+        try {\r
+            Assert.assertEquals("Wrong result", result.get().getErrors(), listener.getResult().get().getErrors());\r
+            Assert.assertEquals("Wrong result", result.get().getResult(), listener.getResult().get().getResult());\r
+            Assert.assertEquals("Wrong result", result.get().isSuccessful(), listener.getResult().get().isSuccessful());\r
+        } catch (InterruptedException | ExecutionException e) {\r
+            fail("Problem accessing result");\r
+        }\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DeserializationFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DeserializationFactoryTest.java
new file mode 100644 (file)
index 0000000..d456332
--- /dev/null
@@ -0,0 +1,56 @@
+/*\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.deserialization;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+import io.netty.buffer.ByteBuf;\r
+import io.netty.buffer.PooledByteBufAllocator;\r
+\r
+import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class DeserializationFactoryTest {\r
+\r
+    /**\r
+     * Test deserializer lookup & deserialization\r
+     */\r
+    @Test\r
+    public void test() {\r
+        DeserializerRegistryImpl registry = new DeserializerRegistryImpl();\r
+        registry.init();\r
+        DeserializationFactory factory = new DeserializationFactory();\r
+        factory.setRegistry(registry);\r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        buffer.writeByte(0);\r
+        buffer.writeShort(EncodeConstants.OFHEADER_SIZE);\r
+        buffer.writeInt(1234);\r
+        factory.deserialize(buffer, EncodeConstants.OF13_VERSION_ID);\r
+        assertEquals("Deserialization failed", 0, buffer.readableBytes());\r
+    }\r
+\r
+    /**\r
+     * Test deserializer lookup & deserialization\r
+     */\r
+    @Test(expected=NullPointerException.class)\r
+    public void testNotExistingDeserializer() {\r
+        DeserializerRegistryImpl registry = new DeserializerRegistryImpl();\r
+        registry.init();\r
+        DeserializationFactory factory = new DeserializationFactory();\r
+        factory.setRegistry(registry);\r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        buffer.writeByte(0);\r
+        buffer.writeShort(EncodeConstants.OFHEADER_SIZE);\r
+        buffer.writeInt(1234);\r
+        factory.deserialize(buffer, (short) 0);\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/TypeToClassMapInitializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/TypeToClassMapInitializerTest.java
new file mode 100644 (file)
index 0000000..84d318f
--- /dev/null
@@ -0,0 +1,80 @@
+/*\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.deserialization;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncOutput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigOutput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class TypeToClassMapInitializerTest {\r
+\r
+    private Map<TypeToClassKey, Class<?>> messageClassMap;\r
+\r
+    /**\r
+     * Tests correct map initialization\r
+     */\r
+    @Test\r
+    public void test() {\r
+        messageClassMap = new HashMap<>();\r
+        TypeToClassMapInitializer.initializeTypeToClassMap(messageClassMap);\r
+        short version = EncodeConstants.OF10_VERSION_ID;\r
+        assertEquals("Wrong class", HelloMessage.class, messageClassMap.get(new TypeToClassKey(version, 0)));\r
+        assertEquals("Wrong class", ErrorMessage.class, messageClassMap.get(new TypeToClassKey(version, 1)));\r
+        assertEquals("Wrong class", EchoRequestMessage.class, messageClassMap.get(new TypeToClassKey(version, 2)));\r
+        assertEquals("Wrong class", EchoOutput.class, messageClassMap.get(new TypeToClassKey(version, 3)));\r
+        assertEquals("Wrong class", ExperimenterMessage.class, messageClassMap.get(new TypeToClassKey(version, 4)));\r
+        assertEquals("Wrong class", GetFeaturesOutput.class, messageClassMap.get(new TypeToClassKey(version, 6)));\r
+        assertEquals("Wrong class", GetConfigOutput.class, messageClassMap.get(new TypeToClassKey(version, 8)));\r
+        assertEquals("Wrong class", PacketInMessage.class, messageClassMap.get(new TypeToClassKey(version, 10)));\r
+        assertEquals("Wrong class", FlowRemovedMessage.class, messageClassMap.get(new TypeToClassKey(version, 11)));\r
+        assertEquals("Wrong class", PortStatusMessage.class, messageClassMap.get(new TypeToClassKey(version, 12)));\r
+        assertEquals("Wrong class", MultipartReplyMessage.class, messageClassMap.get(new TypeToClassKey(version, 17)));\r
+        assertEquals("Wrong class", BarrierOutput.class, messageClassMap.get(new TypeToClassKey(version, 19)));\r
+        assertEquals("Wrong class", GetQueueConfigOutput.class, messageClassMap.get(new TypeToClassKey(version, 21)));\r
+        version = EncodeConstants.OF13_VERSION_ID;\r
+        assertEquals("Wrong class", HelloMessage.class, messageClassMap.get(new TypeToClassKey(version, 0)));\r
+        assertEquals("Wrong class", ErrorMessage.class, messageClassMap.get(new TypeToClassKey(version, 1)));\r
+        assertEquals("Wrong class", EchoRequestMessage.class, messageClassMap.get(new TypeToClassKey(version, 2)));\r
+        assertEquals("Wrong class", EchoOutput.class, messageClassMap.get(new TypeToClassKey(version, 3)));\r
+        assertEquals("Wrong class", ExperimenterMessage.class, messageClassMap.get(new TypeToClassKey(version, 4)));\r
+        assertEquals("Wrong class", GetFeaturesOutput.class, messageClassMap.get(new TypeToClassKey(version, 6)));\r
+        assertEquals("Wrong class", GetConfigOutput.class, messageClassMap.get(new TypeToClassKey(version, 8)));\r
+        assertEquals("Wrong class", PacketInMessage.class, messageClassMap.get(new TypeToClassKey(version, 10)));\r
+        assertEquals("Wrong class", FlowRemovedMessage.class, messageClassMap.get(new TypeToClassKey(version, 11)));\r
+        assertEquals("Wrong class", PortStatusMessage.class, messageClassMap.get(new TypeToClassKey(version, 12)));\r
+        assertEquals("Wrong class", MultipartReplyMessage.class, messageClassMap.get(new TypeToClassKey(version, 19)));\r
+        assertEquals("Wrong class", BarrierOutput.class, messageClassMap.get(new TypeToClassKey(version, 21)));\r
+        assertEquals("Wrong class", GetQueueConfigOutput.class, messageClassMap.get(new TypeToClassKey(version, 23)));\r
+        assertEquals("Wrong class", RoleRequestOutput.class, messageClassMap.get(new TypeToClassKey(version, 25)));\r
+        assertEquals("Wrong class", GetAsyncOutput.class, messageClassMap.get(new TypeToClassKey(version, 27)));\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/SerializationFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/SerializationFactoryTest.java
new file mode 100644 (file)
index 0000000..9c170f8
--- /dev/null
@@ -0,0 +1,60 @@
+/*\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;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+import io.netty.buffer.ByteBuf;\r
+import io.netty.buffer.PooledByteBufAllocator;\r
+\r
+import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;\r
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class SerializationFactoryTest {\r
+\r
+    /**\r
+     * Test serializer lookup & serialization\r
+     */\r
+    @Test\r
+    public void test() {\r
+        SerializerRegistry registry = new SerializerRegistryImpl();\r
+        registry.init();\r
+        SerializationFactory factory = new SerializationFactory();\r
+        factory.setSerializerTable(registry);\r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        HelloInputBuilder helloBuilder = new HelloInputBuilder();\r
+        helloBuilder.setVersion((short) EncodeConstants.OF10_VERSION_ID);\r
+        helloBuilder.setXid(123456L);\r
+        helloBuilder.setElements(null);\r
+        factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, buffer, helloBuilder.build());\r
+        assertEquals("Serialization failed", EncodeConstants.OFHEADER_SIZE, buffer.readableBytes());\r
+    }\r
+\r
+    /**\r
+     * Test serializer not found scenario\r
+     */\r
+    @Test(expected=IllegalArgumentException.class)\r
+    public void testNotExistingSerializer() {\r
+        SerializerRegistry registry = new SerializerRegistryImpl();\r
+        registry.init();\r
+        SerializationFactory factory = new SerializationFactory();\r
+        factory.setSerializerTable(registry);\r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        HelloInputBuilder helloBuilder = new HelloInputBuilder();\r
+        helloBuilder.setVersion((short) EncodeConstants.OF10_VERSION_ID);\r
+        helloBuilder.setXid(123456L);\r
+        helloBuilder.setElements(null);\r
+        factory.messageToBuffer((short) 0, buffer, helloBuilder.build());\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpOpSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpOpSerializerTest.java
new file mode 100644 (file)
index 0000000..78b15e9
--- /dev/null
@@ -0,0 +1,109 @@
+/*\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.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.opendaylight.openflow.augments.rev131002.OpCodeMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OpCodeMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.ArpOp;\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 OxmArpOpSerializerTest {\r
+\r
+    OxmArpOpSerializer serializer = new OxmArpOpSerializer();\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerialize() {\r
+        MatchEntriesBuilder builder = prepareArpOpMatchEntry(1402);\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, false);\r
+        assertEquals("Wrong value", 1402, buffer.readUnsignedShort());\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 = prepareArpOpHeader(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.ARP_OP, 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.SIZE_OF_SHORT_IN_BYTES, serializer.getValueLength());\r
+    }\r
+\r
+    private static MatchEntriesBuilder prepareArpOpMatchEntry(int value) {\r
+        MatchEntriesBuilder builder = prepareArpOpHeader(false);\r
+        OpCodeMatchEntryBuilder opBuilder = new OpCodeMatchEntryBuilder();\r
+        opBuilder.setOpCode(value);\r
+        builder.addAugmentation(OpCodeMatchEntry.class, opBuilder.build());\r
+        return builder;\r
+    }\r
+\r
+    private static MatchEntriesBuilder prepareArpOpHeader(boolean hasMask) {\r
+        MatchEntriesBuilder builder = new MatchEntriesBuilder();\r
+        builder.setOxmClass(OpenflowBasicClass.class);\r
+        builder.setOxmMatchField(ArpOp.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.ARP_OP, fieldAndMask >>> 1);\r
+        assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);\r
+        assertEquals("Wrong length", EncodeConstants.SIZE_OF_SHORT_IN_BYTES, buffer.readUnsignedByte());\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpShaSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpShaSerializerTest.java
new file mode 100644 (file)
index 0000000..c23b9db
--- /dev/null
@@ -0,0 +1,159 @@
+/*\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.ArpTha;\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 OxmArpShaSerializerTest {\r
+\r
+    OxmArpThaSerializer serializer = new OxmArpThaSerializer();\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerializeWithoutMask() {\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 serialization\r
+     */\r
+    @Test\r
+    public void testSerializeWithMask() {\r
+        MatchEntriesBuilder builder = prepareMatchEntry(true, "00:01:02:03:04:0A");\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, true);\r
+        \r
+        byte[] address = new byte[6];\r
+        buffer.readBytes(address);\r
+        Assert.assertArrayEquals("Wrong address", new byte[]{0, 1, 2, 3, 4, 10}, address);\r
+        byte[] tmp = new byte[6];\r
+        buffer.readBytes(tmp);\r
+        Assert.assertArrayEquals("Wrong mask", new byte[]{15, 15, 0, 0, 10, 10}, tmp);\r
+        assertTrue("Unexpected data", buffer.readableBytes() == 0);\r
+    }\r
+\r
+    /**\r
+     * Test correct header serialization\r
+     */\r
+    @Test\r
+    public void testSerializeHeaderWithoutMask() {\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 header serialization\r
+     */\r
+    @Test\r
+    public void testSerializeHeaderWithMask() {\r
+        MatchEntriesBuilder builder = prepareHeader(true);\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serializeHeader(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, true);\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.ARP_THA, 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(ArpTha.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.ARP_THA, fieldAndMask >>> 1);\r
+        assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);\r
+        if (hasMask) {\r
+            assertEquals("Wrong length", 2 * EncodeConstants.MAC_ADDRESS_LENGTH, buffer.readUnsignedByte());\r
+        } else {\r
+            assertEquals("Wrong length", EncodeConstants.MAC_ADDRESS_LENGTH, buffer.readUnsignedByte());\r
+        }\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpSpaSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpSpaSerializerTest.java
new file mode 100644 (file)
index 0000000..7af95a1
--- /dev/null
@@ -0,0 +1,159 @@
+/*\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.inet.types.rev100924.Ipv4Address;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntryBuilder;\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.ArpSpa;\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 OxmArpSpaSerializerTest {\r
+\r
+    OxmArpSpaSerializer serializer = new OxmArpSpaSerializer();\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerializeWithoutMask() {\r
+        MatchEntriesBuilder builder = prepareMatchEntry(false, "10.0.0.1");\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, false);\r
+        byte[] address = new byte[4];\r
+        buffer.readBytes(address);\r
+        Assert.assertArrayEquals("Wrong address", new byte[]{10, 0, 0, 1}, address);\r
+        assertTrue("Unexpected data", buffer.readableBytes() == 0);\r
+    }\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerializeWithMask() {\r
+        MatchEntriesBuilder builder = prepareMatchEntry(true, "120.121.122.0");\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, true);\r
+        \r
+        byte[] address = new byte[4];\r
+        buffer.readBytes(address);\r
+        Assert.assertArrayEquals("Wrong address", new byte[]{120, 121, 122, 0}, address);\r
+        byte[] tmp = new byte[4];\r
+        buffer.readBytes(tmp);\r
+        Assert.assertArrayEquals("Wrong mask", new byte[]{15, 15, 0, 0}, tmp);\r
+        assertTrue("Unexpected data", buffer.readableBytes() == 0);\r
+    }\r
+\r
+    /**\r
+     * Test correct header serialization\r
+     */\r
+    @Test\r
+    public void testSerializeHeaderWithoutMask() {\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 header serialization\r
+     */\r
+    @Test\r
+    public void testSerializeHeaderWithMask() {\r
+        MatchEntriesBuilder builder = prepareHeader(true);\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serializeHeader(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, true);\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.ARP_SPA, 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.SIZE_OF_INT_IN_BYTES, 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});\r
+            builder.addAugmentation(MaskMatchEntry.class, maskBuilder.build());\r
+        }\r
+        Ipv4AddressMatchEntryBuilder addressBuilder = new Ipv4AddressMatchEntryBuilder();\r
+        addressBuilder.setIpv4Address(new Ipv4Address(value));\r
+        builder.addAugmentation(Ipv4AddressMatchEntry.class, addressBuilder.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(ArpSpa.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.ARP_SPA, fieldAndMask >>> 1);\r
+        assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);\r
+        if (hasMask) {\r
+            assertEquals("Wrong length", EncodeConstants.SIZE_OF_LONG_IN_BYTES, buffer.readUnsignedByte());\r
+        } else {\r
+            assertEquals("Wrong length", EncodeConstants.SIZE_OF_INT_IN_BYTES, buffer.readUnsignedByte());\r
+        }\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpThaSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpThaSerializerTest.java
new file mode 100644 (file)
index 0000000..714d697
--- /dev/null
@@ -0,0 +1,159 @@
+/*\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.ArpSha;\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 OxmArpThaSerializerTest {\r
+\r
+    OxmArpShaSerializer serializer = new OxmArpShaSerializer();\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerializeWithoutMask() {\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 serialization\r
+     */\r
+    @Test\r
+    public void testSerializeWithMask() {\r
+        MatchEntriesBuilder builder = prepareMatchEntry(true, "00:01:02:03:04:0A");\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, true);\r
+        \r
+        byte[] address = new byte[6];\r
+        buffer.readBytes(address);\r
+        Assert.assertArrayEquals("Wrong address", new byte[]{0, 1, 2, 3, 4, 10}, address);\r
+        byte[] tmp = new byte[6];\r
+        buffer.readBytes(tmp);\r
+        Assert.assertArrayEquals("Wrong mask", new byte[]{15, 15, 0, 0, 10, 10}, tmp);\r
+        assertTrue("Unexpected data", buffer.readableBytes() == 0);\r
+    }\r
+\r
+    /**\r
+     * Test correct header serialization\r
+     */\r
+    @Test\r
+    public void testSerializeHeaderWithoutMask() {\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 header serialization\r
+     */\r
+    @Test\r
+    public void testSerializeHeaderWithMask() {\r
+        MatchEntriesBuilder builder = prepareHeader(true);\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serializeHeader(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, true);\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.ARP_SHA, 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(ArpSha.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.ARP_SHA, fieldAndMask >>> 1);\r
+        assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);\r
+        if (hasMask) {\r
+            assertEquals("Wrong length", 2 * EncodeConstants.MAC_ADDRESS_LENGTH, buffer.readUnsignedByte());\r
+        } else {\r
+            assertEquals("Wrong length", EncodeConstants.MAC_ADDRESS_LENGTH, buffer.readUnsignedByte());\r
+        }\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpTpaSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmArpTpaSerializerTest.java
new file mode 100644 (file)
index 0000000..8a68a4c
--- /dev/null
@@ -0,0 +1,159 @@
+/*\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.inet.types.rev100924.Ipv4Address;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntryBuilder;\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.ArpTpa;\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 OxmArpTpaSerializerTest {\r
+\r
+    OxmArpTpaSerializer serializer = new OxmArpTpaSerializer();\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerializeWithoutMask() {\r
+        MatchEntriesBuilder builder = prepareMatchEntry(false, "10.0.0.1");\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, false);\r
+        byte[] address = new byte[4];\r
+        buffer.readBytes(address);\r
+        Assert.assertArrayEquals("Wrong address", new byte[]{10, 0, 0, 1}, address);\r
+        assertTrue("Unexpected data", buffer.readableBytes() == 0);\r
+    }\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerializeWithMask() {\r
+        MatchEntriesBuilder builder = prepareMatchEntry(true, "120.121.122.0");\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, true);\r
+        \r
+        byte[] address = new byte[4];\r
+        buffer.readBytes(address);\r
+        Assert.assertArrayEquals("Wrong address", new byte[]{120, 121, 122, 0}, address);\r
+        byte[] tmp = new byte[4];\r
+        buffer.readBytes(tmp);\r
+        Assert.assertArrayEquals("Wrong mask", new byte[]{15, 15, 0, 0}, tmp);\r
+        assertTrue("Unexpected data", buffer.readableBytes() == 0);\r
+    }\r
+\r
+    /**\r
+     * Test correct header serialization\r
+     */\r
+    @Test\r
+    public void testSerializeHeaderWithoutMask() {\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 header serialization\r
+     */\r
+    @Test\r
+    public void testSerializeHeaderWithMask() {\r
+        MatchEntriesBuilder builder = prepareHeader(true);\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serializeHeader(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, true);\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.ARP_TPA, 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.SIZE_OF_INT_IN_BYTES, 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});\r
+            builder.addAugmentation(MaskMatchEntry.class, maskBuilder.build());\r
+        }\r
+        Ipv4AddressMatchEntryBuilder addressBuilder = new Ipv4AddressMatchEntryBuilder();\r
+        addressBuilder.setIpv4Address(new Ipv4Address(value));\r
+        builder.addAugmentation(Ipv4AddressMatchEntry.class, addressBuilder.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(ArpTpa.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.ARP_TPA, fieldAndMask >>> 1);\r
+        assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);\r
+        if (hasMask) {\r
+            assertEquals("Wrong length", EncodeConstants.SIZE_OF_LONG_IN_BYTES, buffer.readUnsignedByte());\r
+        } else {\r
+            assertEquals("Wrong length", EncodeConstants.SIZE_OF_INT_IN_BYTES, buffer.readUnsignedByte());\r
+        }\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmEthDstSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmEthDstSerializerTest.java
new file mode 100644 (file)
index 0000000..3f0d683
--- /dev/null
@@ -0,0 +1,159 @@
+/*\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.EthDst;\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 OxmEthDstSerializerTest {\r
+\r
+    OxmEthDstSerializer serializer = new OxmEthDstSerializer();\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerializeWithoutMask() {\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 serialization\r
+     */\r
+    @Test\r
+    public void testSerializeWithMask() {\r
+        MatchEntriesBuilder builder = prepareMatchEntry(true, "00:01:02:03:04:0A");\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, true);\r
+        \r
+        byte[] address = new byte[6];\r
+        buffer.readBytes(address);\r
+        Assert.assertArrayEquals("Wrong address", new byte[]{0, 1, 2, 3, 4, 10}, address);\r
+        byte[] tmp = new byte[6];\r
+        buffer.readBytes(tmp);\r
+        Assert.assertArrayEquals("Wrong mask", new byte[]{15, 15, 0, 0, 10, 10}, tmp);\r
+        assertTrue("Unexpected data", buffer.readableBytes() == 0);\r
+    }\r
+\r
+    /**\r
+     * Test correct header serialization\r
+     */\r
+    @Test\r
+    public void testSerializeHeaderWithoutMask() {\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 header serialization\r
+     */\r
+    @Test\r
+    public void testSerializeHeaderWithMask() {\r
+        MatchEntriesBuilder builder = prepareHeader(true);\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serializeHeader(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, true);\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.ETH_DST, 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(EthDst.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.ETH_DST, fieldAndMask >>> 1);\r
+        assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);\r
+        if (hasMask) {\r
+            assertEquals("Wrong length", 2 * EncodeConstants.MAC_ADDRESS_LENGTH, buffer.readUnsignedByte());\r
+        } else {\r
+            assertEquals("Wrong length", EncodeConstants.MAC_ADDRESS_LENGTH, buffer.readUnsignedByte());\r
+        }\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmEthSrcSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmEthSrcSerializerTest.java
new file mode 100644 (file)
index 0000000..4aed8e1
--- /dev/null
@@ -0,0 +1,159 @@
+/*\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.EthSrc;\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 OxmEthSrcSerializerTest {\r
+\r
+    OxmEthSrcSerializer serializer = new OxmEthSrcSerializer();\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerializeWithoutMask() {\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 serialization\r
+     */\r
+    @Test\r
+    public void testSerializeWithMask() {\r
+        MatchEntriesBuilder builder = prepareMatchEntry(true, "00:01:02:03:04:0A");\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, true);\r
+        \r
+        byte[] address = new byte[6];\r
+        buffer.readBytes(address);\r
+        Assert.assertArrayEquals("Wrong address", new byte[]{0, 1, 2, 3, 4, 10}, address);\r
+        byte[] tmp = new byte[6];\r
+        buffer.readBytes(tmp);\r
+        Assert.assertArrayEquals("Wrong mask", new byte[]{15, 15, 0, 0, 10, 10}, tmp);\r
+        assertTrue("Unexpected data", buffer.readableBytes() == 0);\r
+    }\r
+\r
+    /**\r
+     * Test correct header serialization\r
+     */\r
+    @Test\r
+    public void testSerializeHeaderWithoutMask() {\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 header serialization\r
+     */\r
+    @Test\r
+    public void testSerializeHeaderWithMask() {\r
+        MatchEntriesBuilder builder = prepareHeader(true);\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serializeHeader(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, true);\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.ETH_SRC, 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(EthSrc.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.ETH_SRC, fieldAndMask >>> 1);\r
+        assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);\r
+        if (hasMask) {\r
+            assertEquals("Wrong length", 2 * EncodeConstants.MAC_ADDRESS_LENGTH, buffer.readUnsignedByte());\r
+        } else {\r
+            assertEquals("Wrong length", EncodeConstants.MAC_ADDRESS_LENGTH, buffer.readUnsignedByte());\r
+        }\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmEthTypeSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmEthTypeSerializerTest.java
new file mode 100644 (file)
index 0000000..23f3249
--- /dev/null
@@ -0,0 +1,111 @@
+/*\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.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.opendaylight.openflow.augments.rev131002.EthTypeMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthTypeMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthType;\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 OxmEthTypeSerializerTest {\r
+\r
+    OxmEthTypeSerializer serializer = new OxmEthTypeSerializer();\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerialize() {\r
+        MatchEntriesBuilder builder = prepareEthTypeMatchEntry(65535);\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, false);\r
+        assertEquals("Wrong value", 65535, buffer.readUnsignedShort());\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 = prepareEthTypeHeader(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.ETH_TYPE, 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.SIZE_OF_SHORT_IN_BYTES, serializer.getValueLength());\r
+    }\r
+\r
+    \r
+    private static MatchEntriesBuilder prepareEthTypeMatchEntry(int type) {\r
+        MatchEntriesBuilder builder = prepareEthTypeHeader(false);\r
+        EthTypeMatchEntryBuilder typeBuilder = new EthTypeMatchEntryBuilder();\r
+        typeBuilder.setEthType(new EtherType(type));\r
+        builder.addAugmentation(EthTypeMatchEntry.class, typeBuilder.build());\r
+        return builder;\r
+    }\r
+\r
+    private static MatchEntriesBuilder prepareEthTypeHeader(boolean hasMask) {\r
+        MatchEntriesBuilder builder = new MatchEntriesBuilder();\r
+        builder.setOxmClass(OpenflowBasicClass.class);\r
+        builder.setOxmMatchField(EthType.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.ETH_TYPE, fieldAndMask >>> 1);\r
+        assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);\r
+        assertEquals("Wrong length", EncodeConstants.SIZE_OF_SHORT_IN_BYTES, buffer.readUnsignedByte());\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIcmpv4CodeSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIcmpv4CodeSerializerTest.java
new file mode 100644 (file)
index 0000000..69dbad6
--- /dev/null
@@ -0,0 +1,110 @@
+/*\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.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.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Code;\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 OxmIcmpv4CodeSerializerTest {\r
+\r
+    OxmIcmpv4CodeSerializer serializer = new OxmIcmpv4CodeSerializer();\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerialize() {\r
+        MatchEntriesBuilder builder = prepareIcmpv4CodeMatchEntry((short) 200);\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, false);\r
+        assertEquals("Wrong value", 200, buffer.readUnsignedByte());\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 = prepareIcmpv4CodeHeader(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.ICMPV4_CODE, 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.SIZE_OF_BYTE_IN_BYTES, serializer.getValueLength());\r
+    }\r
+\r
+    \r
+    private static MatchEntriesBuilder prepareIcmpv4CodeMatchEntry(short value) {\r
+        MatchEntriesBuilder builder = prepareIcmpv4CodeHeader(false);\r
+        Icmpv4CodeMatchEntryBuilder icmpv4Builder = new Icmpv4CodeMatchEntryBuilder();\r
+        icmpv4Builder.setIcmpv4Code(value);\r
+        builder.addAugmentation(Icmpv4CodeMatchEntry.class, icmpv4Builder.build());\r
+        return builder;\r
+    }\r
+\r
+    private static MatchEntriesBuilder prepareIcmpv4CodeHeader(boolean hasMask) {\r
+        MatchEntriesBuilder builder = new MatchEntriesBuilder();\r
+        builder.setOxmClass(OpenflowBasicClass.class);\r
+        builder.setOxmMatchField(Icmpv4Code.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.ICMPV4_CODE, fieldAndMask >>> 1);\r
+        assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);\r
+        assertEquals("Wrong length", EncodeConstants.SIZE_OF_BYTE_IN_BYTES, buffer.readUnsignedByte());\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIcmpv4TypeSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIcmpv4TypeSerializerTest.java
new file mode 100644 (file)
index 0000000..3b9d210
--- /dev/null
@@ -0,0 +1,110 @@
+/*\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.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.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Type;\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 OxmIcmpv4TypeSerializerTest {\r
+\r
+    OxmIcmpv4TypeSerializer serializer = new OxmIcmpv4TypeSerializer();\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerialize() {\r
+        MatchEntriesBuilder builder = prepareIcmpv4TypeMatchEntry((short) 128);\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, false);\r
+        assertEquals("Wrong value", 128, buffer.readUnsignedByte());\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 = prepareIcmpv4TypeHeader(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.ICMPV4_TYPE, 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.SIZE_OF_BYTE_IN_BYTES, serializer.getValueLength());\r
+    }\r
+\r
+    \r
+    private static MatchEntriesBuilder prepareIcmpv4TypeMatchEntry(short value) {\r
+        MatchEntriesBuilder builder = prepareIcmpv4TypeHeader(false);\r
+        Icmpv4TypeMatchEntryBuilder icmpv4Builder = new Icmpv4TypeMatchEntryBuilder();\r
+        icmpv4Builder.setIcmpv4Type(value);\r
+        builder.addAugmentation(Icmpv4TypeMatchEntry.class, icmpv4Builder.build());\r
+        return builder;\r
+    }\r
+\r
+    private static MatchEntriesBuilder prepareIcmpv4TypeHeader(boolean hasMask) {\r
+        MatchEntriesBuilder builder = new MatchEntriesBuilder();\r
+        builder.setOxmClass(OpenflowBasicClass.class);\r
+        builder.setOxmMatchField(Icmpv4Type.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.ICMPV4_TYPE, fieldAndMask >>> 1);\r
+        assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);\r
+        assertEquals("Wrong length", EncodeConstants.SIZE_OF_BYTE_IN_BYTES, buffer.readUnsignedByte());\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIcmpv6CodeSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIcmpv6CodeSerializerTest.java
new file mode 100644 (file)
index 0000000..ed3089c
--- /dev/null
@@ -0,0 +1,109 @@
+/*\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.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.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Code;\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 OxmIcmpv6CodeSerializerTest {\r
+\r
+    OxmIcmpv6CodeSerializer serializer = new OxmIcmpv6CodeSerializer();\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerialize() {\r
+        MatchEntriesBuilder builder = prepareIcmpv6CodeMatchEntry((short) 101);\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, false);\r
+        assertEquals("Wrong value", 101, buffer.readUnsignedByte());\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 = prepareIcmpv6CodeHeader(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.ICMPV6_CODE, 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.SIZE_OF_BYTE_IN_BYTES, serializer.getValueLength());\r
+    }\r
+\r
+    private static MatchEntriesBuilder prepareIcmpv6CodeMatchEntry(short value) {\r
+        MatchEntriesBuilder builder = prepareIcmpv6CodeHeader(false);\r
+        Icmpv6CodeMatchEntryBuilder icmpv6Builder = new Icmpv6CodeMatchEntryBuilder();\r
+        icmpv6Builder.setIcmpv6Code(value);\r
+        builder.addAugmentation(Icmpv6CodeMatchEntry.class, icmpv6Builder.build());\r
+        return builder;\r
+    }\r
+\r
+    private static MatchEntriesBuilder prepareIcmpv6CodeHeader(boolean hasMask) {\r
+        MatchEntriesBuilder builder = new MatchEntriesBuilder();\r
+        builder.setOxmClass(OpenflowBasicClass.class);\r
+        builder.setOxmMatchField(Icmpv6Code.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.ICMPV6_CODE, fieldAndMask >>> 1);\r
+        assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);\r
+        assertEquals("Wrong length", EncodeConstants.SIZE_OF_BYTE_IN_BYTES, buffer.readUnsignedByte());\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIcmpv6TypeSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIcmpv6TypeSerializerTest.java
new file mode 100644 (file)
index 0000000..2c2a60e
--- /dev/null
@@ -0,0 +1,110 @@
+/*\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.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.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Type;\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 OxmIcmpv6TypeSerializerTest {\r
+\r
+    OxmIcmpv6TypeSerializer serializer = new OxmIcmpv6TypeSerializer();\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerialize() {\r
+        MatchEntriesBuilder builder = prepareIcmpv6TypeMatchEntry((short) 123);\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, false);\r
+        assertEquals("Wrong value", 123, buffer.readUnsignedByte());\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 = prepareIcmpv6TypeHeader(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.ICMPV6_TYPE, 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.SIZE_OF_BYTE_IN_BYTES, serializer.getValueLength());\r
+    }\r
+\r
+    \r
+    private static MatchEntriesBuilder prepareIcmpv6TypeMatchEntry(short value) {\r
+        MatchEntriesBuilder builder = prepareIcmpv6TypeHeader(false);\r
+        Icmpv6TypeMatchEntryBuilder icmpv6Builder = new Icmpv6TypeMatchEntryBuilder();\r
+        icmpv6Builder.setIcmpv6Type(value);\r
+        builder.addAugmentation(Icmpv6TypeMatchEntry.class, icmpv6Builder.build());\r
+        return builder;\r
+    }\r
+\r
+    private static MatchEntriesBuilder prepareIcmpv6TypeHeader(boolean hasMask) {\r
+        MatchEntriesBuilder builder = new MatchEntriesBuilder();\r
+        builder.setOxmClass(OpenflowBasicClass.class);\r
+        builder.setOxmMatchField(Icmpv6Type.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.ICMPV6_TYPE, fieldAndMask >>> 1);\r
+        assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);\r
+        assertEquals("Wrong length", EncodeConstants.SIZE_OF_BYTE_IN_BYTES, buffer.readUnsignedByte());\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpDscpSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpDscpSerializerTest.java
new file mode 100644 (file)
index 0000000..34d9a9f
--- /dev/null
@@ -0,0 +1,110 @@
+/*\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.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.inet.types.rev100924.Dscp;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DscpMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DscpMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpDscp;\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 OxmIpDscpSerializerTest {\r
+\r
+    OxmIpDscpSerializer serializer = new OxmIpDscpSerializer();\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerialize() {\r
+        MatchEntriesBuilder builder = prepareIpDscpMatchEntry((short) 58);\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, false);\r
+        assertEquals("Wrong value", 58, buffer.readUnsignedByte());\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 = prepareIpDscpHeader(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.IP_DSCP, 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.SIZE_OF_BYTE_IN_BYTES, serializer.getValueLength());\r
+    }\r
+\r
+    private static MatchEntriesBuilder prepareIpDscpMatchEntry(short value) {\r
+        MatchEntriesBuilder builder = prepareIpDscpHeader(false);\r
+        DscpMatchEntryBuilder dscpBuilder = new DscpMatchEntryBuilder();\r
+        dscpBuilder.setDscp(new Dscp(value));\r
+        builder.addAugmentation(DscpMatchEntry.class, dscpBuilder.build());\r
+        return builder;\r
+    }\r
+\r
+    private static MatchEntriesBuilder prepareIpDscpHeader(boolean hasMask) {\r
+        MatchEntriesBuilder builder = new MatchEntriesBuilder();\r
+        builder.setOxmClass(OpenflowBasicClass.class);\r
+        builder.setOxmMatchField(IpDscp.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.IP_DSCP, fieldAndMask >>> 1);\r
+        assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);\r
+        assertEquals("Wrong length", EncodeConstants.SIZE_OF_BYTE_IN_BYTES, buffer.readUnsignedByte());\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpProtoSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpProtoSerializerTest.java
new file mode 100644 (file)
index 0000000..fbeb425
--- /dev/null
@@ -0,0 +1,109 @@
+/*\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.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.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ProtocolNumberMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpProto;\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 OxmIpProtoSerializerTest {\r
+\r
+    OxmIpProtoSerializer serializer = new OxmIpProtoSerializer();\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerialize() {\r
+        MatchEntriesBuilder builder = prepareMatchEntry((short) 123);\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, false);\r
+        assertEquals("Wrong value", 123, buffer.readUnsignedByte());\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.IP_PROTO, 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.SIZE_OF_BYTE_IN_BYTES, serializer.getValueLength());\r
+    }\r
+\r
+    private static MatchEntriesBuilder prepareMatchEntry(short value) {\r
+        MatchEntriesBuilder builder = prepareHeader(false);\r
+        ProtocolNumberMatchEntryBuilder protoBuilder = new ProtocolNumberMatchEntryBuilder();\r
+        protoBuilder.setProtocolNumber(value);\r
+        builder.addAugmentation(ProtocolNumberMatchEntry.class, protoBuilder.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(IpProto.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.IP_PROTO, fieldAndMask >>> 1);\r
+        assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);\r
+        assertEquals("Wrong length", EncodeConstants.SIZE_OF_BYTE_IN_BYTES, buffer.readUnsignedByte());\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv4DstSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv4DstSerializerTest.java
new file mode 100644 (file)
index 0000000..00c3dc8
--- /dev/null
@@ -0,0 +1,159 @@
+/*\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.inet.types.rev100924.Ipv4Address;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntryBuilder;\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.Ipv4Dst;\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 OxmIpv4DstSerializerTest {\r
+\r
+    OxmIpv4DstSerializer serializer = new OxmIpv4DstSerializer();\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerializeWithoutMask() {\r
+        MatchEntriesBuilder builder = prepareMatchEntry(false, "10.0.0.1");\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, false);\r
+        byte[] address = new byte[4];\r
+        buffer.readBytes(address);\r
+        Assert.assertArrayEquals("Wrong address", new byte[]{10, 0, 0, 1}, address);\r
+        assertTrue("Unexpected data", buffer.readableBytes() == 0);\r
+    }\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerializeWithMask() {\r
+        MatchEntriesBuilder builder = prepareMatchEntry(true, "120.121.122.0");\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, true);\r
+        \r
+        byte[] address = new byte[4];\r
+        buffer.readBytes(address);\r
+        Assert.assertArrayEquals("Wrong address", new byte[]{120, 121, 122, 0}, address);\r
+        byte[] tmp = new byte[4];\r
+        buffer.readBytes(tmp);\r
+        Assert.assertArrayEquals("Wrong mask", new byte[]{15, 15, 0, 0}, tmp);\r
+        assertTrue("Unexpected data", buffer.readableBytes() == 0);\r
+    }\r
+\r
+    /**\r
+     * Test correct header serialization\r
+     */\r
+    @Test\r
+    public void testSerializeHeaderWithoutMask() {\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 header serialization\r
+     */\r
+    @Test\r
+    public void testSerializeHeaderWithMask() {\r
+        MatchEntriesBuilder builder = prepareHeader(true);\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serializeHeader(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, true);\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.IPV4_DST, 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.SIZE_OF_INT_IN_BYTES, 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});\r
+            builder.addAugmentation(MaskMatchEntry.class, maskBuilder.build());\r
+        }\r
+        Ipv4AddressMatchEntryBuilder addressBuilder = new Ipv4AddressMatchEntryBuilder();\r
+        addressBuilder.setIpv4Address(new Ipv4Address(value));\r
+        builder.addAugmentation(Ipv4AddressMatchEntry.class, addressBuilder.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(Ipv4Dst.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.IPV4_DST, fieldAndMask >>> 1);\r
+        assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);\r
+        if (hasMask) {\r
+            assertEquals("Wrong length", EncodeConstants.SIZE_OF_LONG_IN_BYTES, buffer.readUnsignedByte());\r
+        } else {\r
+            assertEquals("Wrong length", EncodeConstants.SIZE_OF_INT_IN_BYTES, buffer.readUnsignedByte());\r
+        }\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv4SrcSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv4SrcSerializerTest.java
new file mode 100644 (file)
index 0000000..5b2834b
--- /dev/null
@@ -0,0 +1,159 @@
+/*\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.inet.types.rev100924.Ipv4Address;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntryBuilder;\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.Ipv4Src;\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 OxmIpv4SrcSerializerTest {\r
+\r
+    OxmIpv4SrcSerializer serializer = new OxmIpv4SrcSerializer();\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerializeWithoutMask() {\r
+        MatchEntriesBuilder builder = prepareMatchEntry(false, "10.0.0.1");\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, false);\r
+        byte[] address = new byte[4];\r
+        buffer.readBytes(address);\r
+        Assert.assertArrayEquals("Wrong address", new byte[]{10, 0, 0, 1}, address);\r
+        assertTrue("Unexpected data", buffer.readableBytes() == 0);\r
+    }\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerializeWithMask() {\r
+        MatchEntriesBuilder builder = prepareMatchEntry(true, "120.121.122.0");\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, true);\r
+        \r
+        byte[] address = new byte[4];\r
+        buffer.readBytes(address);\r
+        Assert.assertArrayEquals("Wrong address", new byte[]{120, 121, 122, 0}, address);\r
+        byte[] tmp = new byte[4];\r
+        buffer.readBytes(tmp);\r
+        Assert.assertArrayEquals("Wrong mask", new byte[]{15, 15, 0, 0}, tmp);\r
+        assertTrue("Unexpected data", buffer.readableBytes() == 0);\r
+    }\r
+\r
+    /**\r
+     * Test correct header serialization\r
+     */\r
+    @Test\r
+    public void testSerializeHeaderWithoutMask() {\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 header serialization\r
+     */\r
+    @Test\r
+    public void testSerializeHeaderWithMask() {\r
+        MatchEntriesBuilder builder = prepareHeader(true);\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serializeHeader(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, true);\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.IPV4_SRC, 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.SIZE_OF_INT_IN_BYTES, 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});\r
+            builder.addAugmentation(MaskMatchEntry.class, maskBuilder.build());\r
+        }\r
+        Ipv4AddressMatchEntryBuilder addressBuilder = new Ipv4AddressMatchEntryBuilder();\r
+        addressBuilder.setIpv4Address(new Ipv4Address(value));\r
+        builder.addAugmentation(Ipv4AddressMatchEntry.class, addressBuilder.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(Ipv4Src.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.IPV4_SRC, fieldAndMask >>> 1);\r
+        assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);\r
+        if (hasMask) {\r
+            assertEquals("Wrong length", EncodeConstants.SIZE_OF_LONG_IN_BYTES, buffer.readUnsignedByte());\r
+        } else {\r
+            assertEquals("Wrong length", EncodeConstants.SIZE_OF_INT_IN_BYTES, buffer.readUnsignedByte());\r
+        }\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6ExtHdrSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6ExtHdrSerializerTest.java
new file mode 100644 (file)
index 0000000..1983b1d
--- /dev/null
@@ -0,0 +1,157 @@
+/*\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.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.augments.rev131002.PseudoFieldMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PseudoFieldMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Ipv6ExthdrFlags;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Exthdr;\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 OxmIpv6ExtHdrSerializerTest {\r
+\r
+    OxmIpv6ExtHdrSerializer serializer = new OxmIpv6ExtHdrSerializer();\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerializeWithMask() {\r
+        MatchEntriesBuilder builder = prepareIpv6ExtHdrMatchEntry(false,\r
+                new Ipv6ExthdrFlags(true, false, true, false, true, false, true, false, true));\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, false);\r
+        assertEquals("Wrong value", 358, buffer.readUnsignedShort());\r
+        assertTrue("Unexpected data", buffer.readableBytes() == 0);\r
+    }\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerializeWithoutMask() {\r
+        MatchEntriesBuilder builder = prepareIpv6ExtHdrMatchEntry(true,\r
+                new Ipv6ExthdrFlags(false, true, false, true, false, true, false, true, false));\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, true);\r
+        assertEquals("Wrong value", 153, buffer.readUnsignedShort());\r
+        byte[] tmp = new byte[2];\r
+        buffer.readBytes(tmp);\r
+        Assert.assertArrayEquals("Wrong mask", new byte[]{0, 15}, tmp);\r
+        assertTrue("Unexpected data", buffer.readableBytes() == 0);\r
+    }\r
+\r
+    /**\r
+     * Test correct header serialization\r
+     */\r
+    @Test\r
+    public void testSerializeHeaderWithoutMask() {\r
+        MatchEntriesBuilder builder = prepareIpv6ExtHdrHeader(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 header serialization\r
+     */\r
+    @Test\r
+    public void testSerializeHeaderWithMask() {\r
+        MatchEntriesBuilder builder = prepareIpv6ExtHdrHeader(true);\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serializeHeader(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, true);\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_EXTHDR, 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.SIZE_OF_SHORT_IN_BYTES, serializer.getValueLength());\r
+    }\r
+\r
+    \r
+    private static MatchEntriesBuilder prepareIpv6ExtHdrMatchEntry(boolean hasMask, Ipv6ExthdrFlags flags) {\r
+        MatchEntriesBuilder builder = prepareIpv6ExtHdrHeader(hasMask);\r
+        if (hasMask) {\r
+            MaskMatchEntryBuilder maskBuilder = new MaskMatchEntryBuilder();\r
+            maskBuilder.setMask(new byte[]{0, 15});\r
+            builder.addAugmentation(MaskMatchEntry.class, maskBuilder.build());\r
+        }\r
+        PseudoFieldMatchEntryBuilder pseudoBuilder = new PseudoFieldMatchEntryBuilder();\r
+        pseudoBuilder.setPseudoField(flags);\r
+        builder.addAugmentation(PseudoFieldMatchEntry.class, pseudoBuilder.build());\r
+        return builder;\r
+    }\r
+\r
+    private static MatchEntriesBuilder prepareIpv6ExtHdrHeader(boolean hasMask) {\r
+        MatchEntriesBuilder builder = new MatchEntriesBuilder();\r
+        builder.setOxmClass(OpenflowBasicClass.class);\r
+        builder.setOxmMatchField(Ipv6Exthdr.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_EXTHDR, fieldAndMask >>> 1);\r
+        assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);\r
+        if (hasMask) {\r
+            assertEquals("Wrong length", EncodeConstants.SIZE_OF_INT_IN_BYTES, buffer.readUnsignedByte());\r
+        } else {\r
+            assertEquals("Wrong length", EncodeConstants.SIZE_OF_SHORT_IN_BYTES, buffer.readUnsignedByte());\r
+        }\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6NdSllSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6NdSllSerializerTest.java
new file mode 100644 (file)
index 0000000..a3e4ff6
--- /dev/null
@@ -0,0 +1,120 @@
+/*\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
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6NdTllSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmIpv6NdTllSerializerTest.java
new file mode 100644 (file)
index 0000000..017652d
--- /dev/null
@@ -0,0 +1,120 @@
+/*\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.Ipv6NdTll;\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 OxmIpv6NdTllSerializerTest {\r
+\r
+    OxmIpv6NdTllSerializer serializer = new OxmIpv6NdTllSerializer();\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_TLL, 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(Ipv6NdTll.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_TLL, fieldAndMask >>> 1);\r
+        assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);\r
+        assertEquals("Wrong length", EncodeConstants.MAC_ADDRESS_LENGTH, buffer.readUnsignedByte());\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmMetadataSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmMetadataSerializerTest.java
new file mode 100644 (file)
index 0000000..e8e53f1
--- /dev/null
@@ -0,0 +1,158 @@
+/*\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.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.augments.rev131002.MetadataMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Metadata;\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 OxmMetadataSerializerTest {\r
+\r
+    OxmMetadataSerializer serializer = new OxmMetadataSerializer();\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerializeWithoutMask() {\r
+        MatchEntriesBuilder builder = prepareMatchEntry(false, new byte[]{0, 1, 2, 3, 4, 5, 6, 7});\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, false);\r
+        byte[] address = new byte[8];\r
+        buffer.readBytes(address);\r
+        Assert.assertArrayEquals("Wrong address", new byte[]{0, 1, 2, 3, 4, 5, 6, 7}, address);\r
+        assertTrue("Unexpected data", buffer.readableBytes() == 0);\r
+    }\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerializeWithMask() {\r
+        MatchEntriesBuilder builder = prepareMatchEntry(true, new byte[]{8, 9, 10, 11, 12, 13, 14, 15});\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, true);\r
+        \r
+        byte[] address = new byte[8];\r
+        buffer.readBytes(address);\r
+        Assert.assertArrayEquals("Wrong address", new byte[]{8, 9, 10, 11, 12, 13, 14, 15}, address);\r
+        byte[] tmp = new byte[8];\r
+        buffer.readBytes(tmp);\r
+        Assert.assertArrayEquals("Wrong mask", new byte[]{30, 30, 25, 25, 15, 15, 0, 0}, tmp);\r
+        assertTrue("Unexpected data", buffer.readableBytes() == 0);\r
+    }\r
+\r
+    /**\r
+     * Test correct header serialization\r
+     */\r
+    @Test\r
+    public void testSerializeHeaderWithoutMask() {\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 header serialization\r
+     */\r
+    @Test\r
+    public void testSerializeHeaderWithMask() {\r
+        MatchEntriesBuilder builder = prepareHeader(true);\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serializeHeader(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, true);\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.METADATA, 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.SIZE_OF_LONG_IN_BYTES, serializer.getValueLength());\r
+    }\r
+\r
+    private static MatchEntriesBuilder prepareMatchEntry(boolean hasMask, byte[] value) {\r
+        MatchEntriesBuilder builder = prepareHeader(hasMask);\r
+        if (hasMask) {\r
+            MaskMatchEntryBuilder maskBuilder = new MaskMatchEntryBuilder();\r
+            maskBuilder.setMask(new byte[]{30, 30, 25, 25, 15, 15, 0, 0});\r
+            builder.addAugmentation(MaskMatchEntry.class, maskBuilder.build());\r
+        }\r
+        MetadataMatchEntryBuilder metadataBuilder = new MetadataMatchEntryBuilder();\r
+        metadataBuilder.setMetadata(value);\r
+        builder.addAugmentation(MetadataMatchEntry.class, metadataBuilder.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(Metadata.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.METADATA, fieldAndMask >>> 1);\r
+        assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);\r
+        if (hasMask) {\r
+            assertEquals("Wrong length", 2 * EncodeConstants.SIZE_OF_LONG_IN_BYTES, buffer.readUnsignedByte());\r
+        } else {\r
+            assertEquals("Wrong length", EncodeConstants.SIZE_OF_LONG_IN_BYTES, buffer.readUnsignedByte());\r
+        }\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmMplsBosSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmMplsBosSerializerTest.java
new file mode 100644 (file)
index 0000000..27c5d50
--- /dev/null
@@ -0,0 +1,110 @@
+/*\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.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.opendaylight.openflow.augments.rev131002.BosMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.BosMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsBos;\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 OxmMplsBosSerializerTest {\r
+\r
+    OxmMplsBosSerializer serializer = new OxmMplsBosSerializer();\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerialize() {\r
+        MatchEntriesBuilder builder = prepareMplsBosMatchEntry(true);\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, false);\r
+        assertEquals("Wrong value", 1, buffer.readUnsignedByte());\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 = prepareMplsBosHeader(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.MPLS_BOS, 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.SIZE_OF_BYTE_IN_BYTES, serializer.getValueLength());\r
+    }\r
+\r
+    \r
+    private static MatchEntriesBuilder prepareMplsBosMatchEntry(boolean bos) {\r
+        MatchEntriesBuilder builder = prepareMplsBosHeader(false);\r
+        BosMatchEntryBuilder bosBuilder = new BosMatchEntryBuilder();\r
+        bosBuilder.setBos(bos);\r
+        builder.addAugmentation(BosMatchEntry.class, bosBuilder.build());\r
+        return builder;\r
+    }\r
+\r
+    private static MatchEntriesBuilder prepareMplsBosHeader(boolean hasMask) {\r
+        MatchEntriesBuilder builder = new MatchEntriesBuilder();\r
+        builder.setOxmClass(OpenflowBasicClass.class);\r
+        builder.setOxmMatchField(MplsBos.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.MPLS_BOS, fieldAndMask >>> 1);\r
+        assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);\r
+        assertEquals("Wrong length", EncodeConstants.SIZE_OF_BYTE_IN_BYTES, buffer.readUnsignedByte());\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmMplsLabelSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmMplsLabelSerializerTest.java
new file mode 100644 (file)
index 0000000..77e07f8
--- /dev/null
@@ -0,0 +1,109 @@
+/*\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.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.opendaylight.openflow.augments.rev131002.MplsLabelMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsLabelMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsLabel;\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 OxmMplsLabelSerializerTest {\r
+\r
+    OxmMplsLabelSerializer serializer = new OxmMplsLabelSerializer();\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerialize() {\r
+        MatchEntriesBuilder builder = prepareMplsLabelMatchEntry(168535);\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, false);\r
+        assertEquals("Wrong value", 168535, buffer.readUnsignedInt());\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 = prepareMplsLabelHeader(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.MPLS_LABEL, 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.SIZE_OF_INT_IN_BYTES, serializer.getValueLength());\r
+    }\r
+\r
+    private static MatchEntriesBuilder prepareMplsLabelMatchEntry(long label) {\r
+        MatchEntriesBuilder builder = prepareMplsLabelHeader(false);\r
+        MplsLabelMatchEntryBuilder labelBuilder = new MplsLabelMatchEntryBuilder();\r
+        labelBuilder.setMplsLabel(label);\r
+        builder.addAugmentation(MplsLabelMatchEntry.class, labelBuilder.build());\r
+        return builder;\r
+    }\r
+\r
+    private static MatchEntriesBuilder prepareMplsLabelHeader(boolean hasMask) {\r
+        MatchEntriesBuilder builder = new MatchEntriesBuilder();\r
+        builder.setOxmClass(OpenflowBasicClass.class);\r
+        builder.setOxmMatchField(MplsLabel.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.MPLS_LABEL, fieldAndMask >>> 1);\r
+        assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);\r
+        assertEquals("Wrong length", EncodeConstants.SIZE_OF_INT_IN_BYTES, buffer.readUnsignedByte());\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmMplsTcSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmMplsTcSerializerTest.java
new file mode 100644 (file)
index 0000000..8a387b6
--- /dev/null
@@ -0,0 +1,109 @@
+/*\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.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.opendaylight.openflow.augments.rev131002.TcMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TcMatchEntryBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.MplsTc;\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 OxmMplsTcSerializerTest {\r
+\r
+    OxmMplsTcSerializer serializer = new OxmMplsTcSerializer();\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerialize() {\r
+        MatchEntriesBuilder builder = prepareMplsTcMatchEntry((short) 16);\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, false);\r
+        assertEquals("Wrong value", 16, buffer.readUnsignedByte());\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 = prepareMplsTcHeader(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.MPLS_TC, 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.SIZE_OF_BYTE_IN_BYTES, serializer.getValueLength());\r
+    }\r
+\r
+    private static MatchEntriesBuilder prepareMplsTcMatchEntry(short value) {\r
+        MatchEntriesBuilder builder = prepareMplsTcHeader(false);\r
+        TcMatchEntryBuilder tcBuilder = new TcMatchEntryBuilder();\r
+        tcBuilder.setTc(value);\r
+        builder.addAugmentation(TcMatchEntry.class, tcBuilder.build());\r
+        return builder;\r
+    }\r
+\r
+    private static MatchEntriesBuilder prepareMplsTcHeader(boolean hasMask) {\r
+        MatchEntriesBuilder builder = new MatchEntriesBuilder();\r
+        builder.setOxmClass(OpenflowBasicClass.class);\r
+        builder.setOxmMatchField(MplsTc.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.MPLS_TC, fieldAndMask >>> 1);\r
+        assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);\r
+        assertEquals("Wrong length", EncodeConstants.SIZE_OF_BYTE_IN_BYTES, buffer.readUnsignedByte());\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmPbbIsidSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmPbbIsidSerializerTest.java
new file mode 100644 (file)
index 0000000..974ecb7
--- /dev/null
@@ -0,0 +1,154 @@
+/*\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.opendaylight.openflow.augments.rev131002.IsidMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.IsidMatchEntryBuilder;\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.OpenflowBasicClass;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.PbbIsid;\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 OxmPbbIsidSerializerTest {\r
+\r
+    OxmPbbIsidSerializer serializer = new OxmPbbIsidSerializer();\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerializeWithMask() {\r
+        MatchEntriesBuilder builder = preparePbbIsidMatchEntry(false, 12345);\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, false);\r
+        assertEquals("Wrong value", 12345, buffer.readUnsignedMedium());\r
+        assertTrue("Unexpected data", buffer.readableBytes() == 0);\r
+    }\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerializeWithoutMask() {\r
+        MatchEntriesBuilder builder = preparePbbIsidMatchEntry(true, 6789);\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, true);\r
+        assertEquals("Wrong value", 6789, buffer.readUnsignedMedium());\r
+        byte[] tmp = new byte[3];\r
+        buffer.readBytes(tmp);\r
+        Assert.assertArrayEquals("Wrong mask", new byte[]{0, 15, 10}, tmp);\r
+        assertTrue("Unexpected data", buffer.readableBytes() == 0);\r
+    }\r
+\r
+    /**\r
+     * Test correct header serialization\r
+     */\r
+    @Test\r
+    public void testSerializeHeaderWithoutMask() {\r
+        MatchEntriesBuilder builder = preparePbbIsidHeader(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 header serialization\r
+     */\r
+    @Test\r
+    public void testSerializeHeaderWithMask() {\r
+        MatchEntriesBuilder builder = preparePbbIsidHeader(true);\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serializeHeader(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, true);\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.PBB_ISID, 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.SIZE_OF_3_BYTES, serializer.getValueLength());\r
+    }\r
+\r
+    \r
+    private static MatchEntriesBuilder preparePbbIsidMatchEntry(boolean hasMask, long value) {\r
+        MatchEntriesBuilder builder = preparePbbIsidHeader(hasMask);\r
+        if (hasMask) {\r
+            MaskMatchEntryBuilder maskBuilder = new MaskMatchEntryBuilder();\r
+            maskBuilder.setMask(new byte[]{0, 15, 10});\r
+            builder.addAugmentation(MaskMatchEntry.class, maskBuilder.build());\r
+        }\r
+        IsidMatchEntryBuilder isidBuilder = new IsidMatchEntryBuilder();\r
+        isidBuilder.setIsid(value);\r
+        builder.addAugmentation(IsidMatchEntry.class, isidBuilder.build());\r
+        return builder;\r
+    }\r
+\r
+    private static MatchEntriesBuilder preparePbbIsidHeader(boolean hasMask) {\r
+        MatchEntriesBuilder builder = new MatchEntriesBuilder();\r
+        builder.setOxmClass(OpenflowBasicClass.class);\r
+        builder.setOxmMatchField(PbbIsid.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.PBB_ISID, fieldAndMask >>> 1);\r
+        assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);\r
+        if (hasMask) {\r
+            assertEquals("Wrong length", 2 * EncodeConstants.SIZE_OF_3_BYTES, buffer.readUnsignedByte());\r
+        } else {\r
+            assertEquals("Wrong length", EncodeConstants.SIZE_OF_3_BYTES, buffer.readUnsignedByte());\r
+        }\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmSctpDstSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmSctpDstSerializerTest.java
new file mode 100644 (file)
index 0000000..606696c
--- /dev/null
@@ -0,0 +1,110 @@
+/*\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.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.inet.types.rev100924.PortNumber;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntryBuilder;\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.SctpDst;\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 OxmSctpDstSerializerTest {\r
+\r
+    OxmSctpDstSerializer serializer = new OxmSctpDstSerializer();\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerialize() {\r
+        MatchEntriesBuilder builder = prepareMatchEntry(4096);\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, false);\r
+        assertEquals("Wrong value", 4096, buffer.readUnsignedShort());\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.SCTP_DST, 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.SIZE_OF_SHORT_IN_BYTES, serializer.getValueLength());\r
+    }\r
+\r
+    private static MatchEntriesBuilder prepareMatchEntry(int value) {\r
+        MatchEntriesBuilder builder = prepareHeader(false);\r
+        PortMatchEntryBuilder portBuilder = new PortMatchEntryBuilder();\r
+        portBuilder.setPort(new PortNumber(value));\r
+        builder.addAugmentation(PortMatchEntry.class, portBuilder.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(SctpDst.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.SCTP_DST, fieldAndMask >>> 1);\r
+        assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);\r
+        assertEquals("Wrong length", EncodeConstants.SIZE_OF_SHORT_IN_BYTES, buffer.readUnsignedByte());\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmSctpSrcSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmSctpSrcSerializerTest.java
new file mode 100644 (file)
index 0000000..a28c60f
--- /dev/null
@@ -0,0 +1,110 @@
+/*\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.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.inet.types.rev100924.PortNumber;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntryBuilder;\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.SctpSrc;\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 OxmSctpSrcSerializerTest {\r
+\r
+    OxmSctpSrcSerializer serializer = new OxmSctpSrcSerializer();\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerialize() {\r
+        MatchEntriesBuilder builder = prepareMatchEntry(4096);\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, false);\r
+        assertEquals("Wrong value", 4096, buffer.readUnsignedShort());\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.SCTP_SRC, 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.SIZE_OF_SHORT_IN_BYTES, serializer.getValueLength());\r
+    }\r
+\r
+    private static MatchEntriesBuilder prepareMatchEntry(int value) {\r
+        MatchEntriesBuilder builder = prepareHeader(false);\r
+        PortMatchEntryBuilder portBuilder = new PortMatchEntryBuilder();\r
+        portBuilder.setPort(new PortNumber(value));\r
+        builder.addAugmentation(PortMatchEntry.class, portBuilder.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(SctpSrc.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.SCTP_SRC, fieldAndMask >>> 1);\r
+        assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);\r
+        assertEquals("Wrong length", EncodeConstants.SIZE_OF_SHORT_IN_BYTES, buffer.readUnsignedByte());\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmTcpDstSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmTcpDstSerializerTest.java
new file mode 100644 (file)
index 0000000..fb56055
--- /dev/null
@@ -0,0 +1,110 @@
+/*\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.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.inet.types.rev100924.PortNumber;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntryBuilder;\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.TcpDst;\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 OxmTcpDstSerializerTest {\r
+\r
+    OxmTcpDstSerializer serializer = new OxmTcpDstSerializer();\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerialize() {\r
+        MatchEntriesBuilder builder = prepareMatchEntry(4096);\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, false);\r
+        assertEquals("Wrong value", 4096, buffer.readUnsignedShort());\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.TCP_DST, 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.SIZE_OF_SHORT_IN_BYTES, serializer.getValueLength());\r
+    }\r
+\r
+    private static MatchEntriesBuilder prepareMatchEntry(int value) {\r
+        MatchEntriesBuilder builder = prepareHeader(false);\r
+        PortMatchEntryBuilder portBuilder = new PortMatchEntryBuilder();\r
+        portBuilder.setPort(new PortNumber(value));\r
+        builder.addAugmentation(PortMatchEntry.class, portBuilder.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(TcpDst.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.TCP_DST, fieldAndMask >>> 1);\r
+        assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);\r
+        assertEquals("Wrong length", EncodeConstants.SIZE_OF_SHORT_IN_BYTES, buffer.readUnsignedByte());\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmTcpSrcSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmTcpSrcSerializerTest.java
new file mode 100644 (file)
index 0000000..9e53264
--- /dev/null
@@ -0,0 +1,110 @@
+/*\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.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.inet.types.rev100924.PortNumber;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntryBuilder;\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.TcpSrc;\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 OxmTcpSrcSerializerTest {\r
+\r
+    OxmTcpSrcSerializer serializer = new OxmTcpSrcSerializer();\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerialize() {\r
+        MatchEntriesBuilder builder = prepareMatchEntry(512);\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, false);\r
+        assertEquals("Wrong value", 512, buffer.readUnsignedShort());\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.TCP_SRC, 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.SIZE_OF_SHORT_IN_BYTES, serializer.getValueLength());\r
+    }\r
+\r
+    private static MatchEntriesBuilder prepareMatchEntry(int value) {\r
+        MatchEntriesBuilder builder = prepareHeader(false);\r
+        PortMatchEntryBuilder portBuilder = new PortMatchEntryBuilder();\r
+        portBuilder.setPort(new PortNumber(value));\r
+        builder.addAugmentation(PortMatchEntry.class, portBuilder.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(TcpSrc.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.TCP_SRC, fieldAndMask >>> 1);\r
+        assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);\r
+        assertEquals("Wrong length", EncodeConstants.SIZE_OF_SHORT_IN_BYTES, buffer.readUnsignedByte());\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmTunnelIdSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmTunnelIdSerializerTest.java
new file mode 100644 (file)
index 0000000..cd4029e
--- /dev/null
@@ -0,0 +1,158 @@
+/*\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.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.augments.rev131002.MetadataMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MetadataMatchEntryBuilder;\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.TunnelId;\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 OxmTunnelIdSerializerTest {\r
+\r
+    OxmTunnelIdSerializer serializer = new OxmTunnelIdSerializer();\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerializeWithoutMask() {\r
+        MatchEntriesBuilder builder = prepareMatchEntry(false, new byte[]{0, 1, 2, 3, 4, 5, 6, 7});\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, false);\r
+        byte[] address = new byte[8];\r
+        buffer.readBytes(address);\r
+        Assert.assertArrayEquals("Wrong address", new byte[]{0, 1, 2, 3, 4, 5, 6, 7}, address);\r
+        assertTrue("Unexpected data", buffer.readableBytes() == 0);\r
+    }\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerializeWithMask() {\r
+        MatchEntriesBuilder builder = prepareMatchEntry(true, new byte[]{8, 9, 10, 11, 12, 13, 14, 15});\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, true);\r
+        \r
+        byte[] address = new byte[8];\r
+        buffer.readBytes(address);\r
+        Assert.assertArrayEquals("Wrong address", new byte[]{8, 9, 10, 11, 12, 13, 14, 15}, address);\r
+        byte[] tmp = new byte[8];\r
+        buffer.readBytes(tmp);\r
+        Assert.assertArrayEquals("Wrong mask", new byte[]{30, 30, 25, 25, 15, 15, 0, 0}, tmp);\r
+        assertTrue("Unexpected data", buffer.readableBytes() == 0);\r
+    }\r
+\r
+    /**\r
+     * Test correct header serialization\r
+     */\r
+    @Test\r
+    public void testSerializeHeaderWithoutMask() {\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 header serialization\r
+     */\r
+    @Test\r
+    public void testSerializeHeaderWithMask() {\r
+        MatchEntriesBuilder builder = prepareHeader(true);\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serializeHeader(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, true);\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.TUNNEL_ID, 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.SIZE_OF_LONG_IN_BYTES, serializer.getValueLength());\r
+    }\r
+\r
+    private static MatchEntriesBuilder prepareMatchEntry(boolean hasMask, byte[] value) {\r
+        MatchEntriesBuilder builder = prepareHeader(hasMask);\r
+        if (hasMask) {\r
+            MaskMatchEntryBuilder maskBuilder = new MaskMatchEntryBuilder();\r
+            maskBuilder.setMask(new byte[]{30, 30, 25, 25, 15, 15, 0, 0});\r
+            builder.addAugmentation(MaskMatchEntry.class, maskBuilder.build());\r
+        }\r
+        MetadataMatchEntryBuilder metadataBuilder = new MetadataMatchEntryBuilder();\r
+        metadataBuilder.setMetadata(value);\r
+        builder.addAugmentation(MetadataMatchEntry.class, metadataBuilder.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(TunnelId.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.TUNNEL_ID, fieldAndMask >>> 1);\r
+        assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);\r
+        if (hasMask) {\r
+            assertEquals("Wrong length", 2 * EncodeConstants.SIZE_OF_LONG_IN_BYTES, buffer.readUnsignedByte());\r
+        } else {\r
+            assertEquals("Wrong length", EncodeConstants.SIZE_OF_LONG_IN_BYTES, buffer.readUnsignedByte());\r
+        }\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmUdpDstSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmUdpDstSerializerTest.java
new file mode 100644 (file)
index 0000000..4cf5558
--- /dev/null
@@ -0,0 +1,110 @@
+/*\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.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.inet.types.rev100924.PortNumber;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntryBuilder;\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.UdpDst;\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 OxmUdpDstSerializerTest {\r
+\r
+    OxmUdpDstSerializer serializer = new OxmUdpDstSerializer();\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerialize() {\r
+        MatchEntriesBuilder builder = prepareMatchEntry(2048);\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, false);\r
+        assertEquals("Wrong value", 2048, buffer.readUnsignedShort());\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.UDP_DST, 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.SIZE_OF_SHORT_IN_BYTES, serializer.getValueLength());\r
+    }\r
+\r
+    private static MatchEntriesBuilder prepareMatchEntry(int value) {\r
+        MatchEntriesBuilder builder = prepareHeader(false);\r
+        PortMatchEntryBuilder portBuilder = new PortMatchEntryBuilder();\r
+        portBuilder.setPort(new PortNumber(value));\r
+        builder.addAugmentation(PortMatchEntry.class, portBuilder.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(UdpDst.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.UDP_DST, fieldAndMask >>> 1);\r
+        assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);\r
+        assertEquals("Wrong length", EncodeConstants.SIZE_OF_SHORT_IN_BYTES, buffer.readUnsignedByte());\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmUdpSrcSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmUdpSrcSerializerTest.java
new file mode 100644 (file)
index 0000000..7348307
--- /dev/null
@@ -0,0 +1,110 @@
+/*\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.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.inet.types.rev100924.PortNumber;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntryBuilder;\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.UdpSrc;\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 OxmUdpSrcSerializerTest {\r
+\r
+    OxmUdpSrcSerializer serializer = new OxmUdpSrcSerializer();\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerialize() {\r
+        MatchEntriesBuilder builder = prepareMatchEntry(1024);\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, false);\r
+        assertEquals("Wrong value", 1024, buffer.readUnsignedShort());\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.UDP_SRC, 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.SIZE_OF_SHORT_IN_BYTES, serializer.getValueLength());\r
+    }\r
+\r
+    private static MatchEntriesBuilder prepareMatchEntry(int value) {\r
+        MatchEntriesBuilder builder = prepareHeader(false);\r
+        PortMatchEntryBuilder portBuilder = new PortMatchEntryBuilder();\r
+        portBuilder.setPort(new PortNumber(value));\r
+        builder.addAugmentation(PortMatchEntry.class, portBuilder.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(UdpSrc.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.UDP_SRC, fieldAndMask >>> 1);\r
+        assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);\r
+        assertEquals("Wrong length", EncodeConstants.SIZE_OF_SHORT_IN_BYTES, buffer.readUnsignedByte());\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmVlanPcpSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmVlanPcpSerializerTest.java
new file mode 100644 (file)
index 0000000..0ce0f64
--- /dev/null
@@ -0,0 +1,109 @@
+/*\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.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.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpMatchEntryBuilder;\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.VlanPcp;\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 OxmVlanPcpSerializerTest {\r
+\r
+    OxmVlanPcpSerializer serializer = new OxmVlanPcpSerializer();\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerialize() {\r
+        MatchEntriesBuilder builder = prepareVlanPcpMatchEntry((short) 42);\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, false);\r
+        assertEquals("Wrong value", 42, buffer.readUnsignedByte());\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 = prepareVlanPcpHeader(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.VLAN_PCP, 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.SIZE_OF_BYTE_IN_BYTES, serializer.getValueLength());\r
+    }\r
+\r
+    private static MatchEntriesBuilder prepareVlanPcpMatchEntry(short value) {\r
+        MatchEntriesBuilder builder = prepareVlanPcpHeader(false);\r
+        VlanPcpMatchEntryBuilder pcpBuilder = new VlanPcpMatchEntryBuilder();\r
+        pcpBuilder.setVlanPcp(value);\r
+        builder.addAugmentation(VlanPcpMatchEntry.class, pcpBuilder.build());\r
+        return builder;\r
+    }\r
+\r
+    private static MatchEntriesBuilder prepareVlanPcpHeader(boolean hasMask) {\r
+        MatchEntriesBuilder builder = new MatchEntriesBuilder();\r
+        builder.setOxmClass(OpenflowBasicClass.class);\r
+        builder.setOxmMatchField(VlanPcp.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.VLAN_PCP, fieldAndMask >>> 1);\r
+        assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);\r
+        assertEquals("Wrong length", EncodeConstants.SIZE_OF_BYTE_IN_BYTES, buffer.readUnsignedByte());\r
+    }\r
+}
\ No newline at end of file
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmVlanVidSerializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/match/OxmVlanVidSerializerTest.java
new file mode 100644 (file)
index 0000000..3e9bf62
--- /dev/null
@@ -0,0 +1,154 @@
+/*\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.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.augments.rev131002.VlanVidMatchEntry;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntryBuilder;\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.VlanVid;\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 OxmVlanVidSerializerTest {\r
+\r
+    OxmVlanVidSerializer serializer = new OxmVlanVidSerializer();\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerializeWithCfiBitSet() {\r
+        MatchEntriesBuilder builder = prepareVlanVidMatchEntry(false, true);\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, false);\r
+        assertEquals("Wrong value", 4596, buffer.readUnsignedShort());\r
+        assertTrue("Unexpected data", buffer.readableBytes() == 0);\r
+    }\r
+\r
+    /**\r
+     * Test correct serialization\r
+     */\r
+    @Test\r
+    public void testSerializeWithoutCfiBitSet() {\r
+        MatchEntriesBuilder builder = prepareVlanVidMatchEntry(true, false);\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serialize(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, true);\r
+        assertEquals("Wrong value", 500, buffer.readUnsignedShort());\r
+        byte[] tmp = new byte[2];\r
+        buffer.readBytes(tmp);\r
+        Assert.assertArrayEquals("Wrong mask", new byte[]{15, 15}, tmp);\r
+        assertTrue("Unexpected data", buffer.readableBytes() == 0);\r
+    }\r
+\r
+    /**\r
+     * Test correct header serialization\r
+     */\r
+    @Test\r
+    public void testSerializeHeaderWithoutMask() {\r
+        MatchEntriesBuilder builder = prepareVlanVidHeader(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 header serialization\r
+     */\r
+    @Test\r
+    public void testSerializeHeaderWithMask() {\r
+        MatchEntriesBuilder builder = prepareVlanVidHeader(true);\r
+        \r
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
+        serializer.serializeHeader(builder.build(), buffer);\r
+\r
+        checkHeader(buffer, true);\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.VLAN_VID, 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.SIZE_OF_SHORT_IN_BYTES, serializer.getValueLength());\r
+    }\r
+\r
+    private static MatchEntriesBuilder prepareVlanVidMatchEntry(boolean hasMask, boolean cfiBit) {\r
+        MatchEntriesBuilder builder = prepareVlanVidHeader(hasMask);\r
+        if (hasMask) {\r
+            MaskMatchEntryBuilder maskBuilder = new MaskMatchEntryBuilder();\r
+            maskBuilder.setMask(new byte[]{15, 15});\r
+            builder.addAugmentation(MaskMatchEntry.class, maskBuilder.build());\r
+        }\r
+        VlanVidMatchEntryBuilder vlanBuilder = new VlanVidMatchEntryBuilder();\r
+        vlanBuilder.setVlanVid(500);\r
+        vlanBuilder.setCfiBit(cfiBit);\r
+        builder.addAugmentation(VlanVidMatchEntry.class, vlanBuilder.build());\r
+        return builder;\r
+    }\r
+\r
+    private static MatchEntriesBuilder prepareVlanVidHeader(boolean hasMask) {\r
+        MatchEntriesBuilder builder = new MatchEntriesBuilder();\r
+        builder.setOxmClass(OpenflowBasicClass.class);\r
+        builder.setOxmMatchField(VlanVid.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.VLAN_VID, fieldAndMask >>> 1);\r
+        assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);\r
+        if (hasMask) {\r
+            assertEquals("Wrong length", EncodeConstants.SIZE_OF_INT_IN_BYTES, buffer.readUnsignedByte());\r
+        } else {\r
+            assertEquals("Wrong length", EncodeConstants.SIZE_OF_SHORT_IN_BYTES, buffer.readUnsignedByte());\r
+        }\r
+    }\r
+}
\ No newline at end of file
index e9c2d0c1b50b3ee205c8e2e39793befdb2767f96..6ca0e7b0dc4716dea87acc3577503fbf230b7ee0 100644 (file)
@@ -9,6 +9,7 @@
 package org.opendaylight.openflowjava.util;
 
 import io.netty.buffer.ByteBuf;
+import io.netty.buffer.PooledByteBufAllocator;
 import io.netty.buffer.UnpooledByteBufAllocator;
 
 import java.util.ArrayList;
@@ -18,7 +19,10 @@ import java.util.Map;
 
 import org.junit.Assert;
 import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.util.ByteBufUtils;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder;
 
 /**
  * @author michal.polkorab
@@ -219,15 +223,27 @@ public class ByteBufUtilsTest {
     public void testMacToBytes() {
         Assert.assertArrayEquals("Wrong byte array", new byte[]{0, 1, 2, 3, (byte) 255, 5},
                 ByteBufUtils.macAddressToBytes("00:01:02:03:FF:05"));
+        Assert.assertArrayEquals("Wrong byte array", new byte[]{11, 1, 2, 3, (byte) 255, 10},
+                ByteBufUtils.macAddressToBytes("0b:01:02:03:FF:0a"));
+    }
+
+    /**
+     * Test of {@link ByteBufUtils#macAddressToBytes(String)}
+     */
+    @Test(expected=IllegalArgumentException.class)
+    public void testMacToBytes2() {
+        Assert.assertArrayEquals("Wrong byte array", new byte[]{0, 1, 2, 3, (byte) 255, 5},
+                ByteBufUtils.macAddressToBytes("00:01:02:03:FF:0G"));
     }
 
     /**
      * Test of {@link ByteBufUtils#macAddressToString(byte[])}
      */
-    @Test
+    @Test(expected=IllegalArgumentException.class)
     public void testMacToString() {
         Assert.assertEquals("Wrong string decoded", "00:01:02:03:FF:05",
                 ByteBufUtils.macAddressToString(new byte[]{0, 1, 2, 3, (byte) 255, 5}));
+        ByteBufUtils.macAddressToString(new byte[]{0, 1, 2, 3, (byte) 255, 5, 6});
     }
 
     /**
@@ -252,4 +268,103 @@ public class ByteBufUtilsTest {
         Assert.assertEquals("Wrong data read", "04 05 06 07", ByteBufUtils.byteBufToHexString(buf));
     }
 
+    /**
+     * Buffer padding test
+     */
+    @Test
+    public void testPadBuffer() {
+        ByteBuf buf = PooledByteBufAllocator.DEFAULT.buffer();
+        ByteBufUtils.padBuffer(4, buf);
+        Assert.assertEquals("Wrong padding", 0, buf.readUnsignedInt());
+        ByteBufUtils.padBuffer(0, buf);
+        Assert.assertTrue("Wrong padding", buf.readableBytes() == 0);
+    }
+
+    /**
+     * Write OF header test
+     */
+    @Test
+    public void testWriteHeader() {
+        ByteBuf buf = PooledByteBufAllocator.DEFAULT.buffer();
+        HelloInputBuilder helloBuilder = new HelloInputBuilder();
+        helloBuilder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
+        helloBuilder.setXid(12345L);
+        helloBuilder.setElements(null);
+        HelloInput helloInput = helloBuilder.build();
+        ByteBufUtils.writeOFHeader((byte) 0, helloInput, buf, EncodeConstants.OFHEADER_SIZE);
+        Assert.assertEquals("Wrong version", EncodeConstants.OF13_VERSION_ID, buf.readUnsignedByte());
+        Assert.assertEquals("Wrong type", 0, buf.readUnsignedByte());
+        Assert.assertEquals("Wrong length", EncodeConstants.OFHEADER_SIZE, buf.readUnsignedShort());
+        Assert.assertEquals("Wrong xid", 12345, buf.readUnsignedInt());
+        Assert.assertTrue("Unexpected data", buf.readableBytes() == 0);
+    }
+
+    /**
+     * Fill bitmask test
+     */
+    @Test
+    public void testFillBitmask() {
+        Assert.assertEquals("Wrong bitmask", 0, ByteBufUtils.fillBitMask(0, false));
+        Assert.assertEquals("Wrong bitmask", 1, ByteBufUtils.fillBitMask(0, true));
+        Assert.assertEquals("Wrong bitmask", 3, ByteBufUtils.fillBitMask(0, true, true));
+        Assert.assertEquals("Wrong bitmask", 2, ByteBufUtils.fillBitMask(0, false, true));
+        Assert.assertEquals("Wrong bitmask", 1, ByteBufUtils.fillBitMask(0, true, false));
+        Assert.assertEquals("Wrong bitmask", 2, ByteBufUtils.fillBitMask(1, true, false));
+        Assert.assertEquals("Wrong bitmask", 4, ByteBufUtils.fillBitMask(1, false, true));
+        Assert.assertEquals("Wrong bitmask", 6, ByteBufUtils.fillBitMask(1, true, true));
+        Assert.assertEquals("Wrong bitmask", 0, ByteBufUtils.fillBitMask(1));
+    }
+
+    /**
+     * Test bytes to hex string
+     */
+    @Test
+    public void testBytesToHexString() {
+        byte[] array = new byte[]{10, 11, 12, 13, 14, 15, 16};
+        Assert.assertEquals("Wrong conversion", "0a 0b 0c 0d 0e 0f 10", ByteBufUtils.bytesToHexString(array));
+        byte[] empty = new byte[0];
+        Assert.assertEquals("Wrong conversion", "", ByteBufUtils.bytesToHexString(empty));
+    }
+
+    /**
+     * Test ipv4 address conversion
+     */
+    @Test(expected=IndexOutOfBoundsException.class)
+    public void testReadIpv4Address() {
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();
+        buffer.writeByte(10);
+        buffer.writeByte(20);
+        buffer.writeByte(30);
+        buffer.writeByte(40);
+        String ipv4Address = ByteBufUtils.readIpv4Address(buffer);
+        Assert.assertEquals("Wrong conversion", "10.20.30.40", ipv4Address);
+        Assert.assertTrue("Unexpected data", buffer.readableBytes() == 0);
+        
+        ByteBuf buffer2 = PooledByteBufAllocator.DEFAULT.buffer();
+        buffer.writeByte(10);
+        ipv4Address = ByteBufUtils.readIpv4Address(buffer2);
+    }
+
+    /**
+     * Test ipv6 address conversion
+     */
+    @Test(expected=IndexOutOfBoundsException.class)
+    public void testReadIpv6Address() {
+        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();
+        buffer.writeShort(10);
+        buffer.writeShort(65535);
+        buffer.writeShort(4096);
+        buffer.writeShort(0);
+        buffer.writeShort(1024);
+        buffer.writeShort(42);
+        buffer.writeShort(2568);
+        buffer.writeShort(45689);
+        String ipv4Address = ByteBufUtils.readIpv6Address(buffer);
+        Assert.assertEquals("Wrong conversion", "000A:FFFF:1000:0000:0400:002A:0A08:B279", ipv4Address);
+        Assert.assertTrue("Unexpected data", buffer.readableBytes() == 0);
+        
+        ByteBuf buffer2 = PooledByteBufAllocator.DEFAULT.buffer();
+        buffer.writeShort(10);
+        ipv4Address = ByteBufUtils.readIpv6Address(buffer2);
+    }
 }