BUG-4283: experimenter msg support - deserialization part 13/28813/3
authorMichal Rehak <mirehak@cisco.com>
Thu, 22 Oct 2015 13:12:09 +0000 (15:12 +0200)
committerMichal Rehak <mirehak@cisco.com>
Wed, 28 Oct 2015 12:45:25 +0000 (13:45 +0100)
 - added support for symmetric and multipart experimenter message
   deserialization

Change-Id: Id0efd13f8f6254d55a30cd10871840d93174117a
Signed-off-by: Michal Rehak <mirehak@cisco.com>
21 files changed:
openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/DeserializerExtensionProvider.java
openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/keys/ExperimenterIdDeserializerKey.java
openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/keys/ExperimenterIdTypeDeserializerKey.java [new file with mode: 0644]
openflow-protocol-api/src/main/yang/openflow-protocol.yang
openflow-protocol-api/src/test/java/org/opendaylight/openflowjava/protocol/api/keys/experimenter/ExperimenterIdDeserializerKeyTest.java
openflow-protocol-api/src/test/java/org/opendaylight/openflowjava/protocol/api/keys/experimenter/ExperimenterIdTypeDeserializerKeyTest.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SwitchConnectionProviderImpl.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/connection/ConnectionAdapterImpl.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DeserializerRegistryImpl.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/MessageDeserializerInitializer.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ExperimenterMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10StatsReplyMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/VendorMessageFactory.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/SwitchConnectionProviderImpl02Test.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ExperimenterMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/VendorMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/multipart/MultipartReplyExperimenterTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/multipart/OF10StatsReplyExperimenterTest.java
openflowjava-util/src/main/java/org/opendaylight/openflowjava/util/ExperimenterDeserializerKeyFactory.java
openflowjava-util/src/test/java/org/opendaylight/openflowjava/util/ExperimenterDeserializerKeyFactoryTest.java

index b38b5cfacdbc46025cde504d678af2ce22b5ff41..b227453e627f982d188655cac2e66abee4b0b881 100644 (file)
@@ -14,8 +14,7 @@ import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdDeserialize
 import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterInstructionDeserializerKey;
 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandExperimenterCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueueProperty;
 
@@ -80,7 +79,7 @@ public interface DeserializerExtensionProvider {
      * @param deserializer deserializer instance
      */
     void registerExperimenterMessageDeserializer(ExperimenterIdDeserializerKey key,
-            OFDeserializer<ExperimenterMessage> deserializer);
+                                                 OFDeserializer<? extends ExperimenterDataOfChoice> deserializer);
 
     /**
      * Registers multipart-reply (stats) message deserializer
@@ -88,7 +87,7 @@ public interface DeserializerExtensionProvider {
      * @param deserializer deserializer instance
      */
     void registerMultipartReplyMessageDeserializer(ExperimenterIdDeserializerKey key,
-            OFDeserializer<MultipartReplyMessage> deserializer);
+                                                   OFDeserializer<? extends ExperimenterDataOfChoice> deserializer);
 
     /**
      * Registers multipart-reply table-features message deserializer
index dfc75a8efa18c7b903bffff0b0b9aec3b1f80945..8f66900d4f1c71f70077e4a7dc1f1a781139a6f7 100644 (file)
@@ -9,16 +9,16 @@
 package org.opendaylight.openflowjava.protocol.api.keys;
 
 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
-import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.DataContainer;
 
 /**
  * @author michal.polkorab
  *
  */
-public final class ExperimenterIdDeserializerKey extends MessageCodeKey
+public class ExperimenterIdDeserializerKey extends MessageCodeKey
         implements ExperimenterDeserializerKey {
 
-    private Long experimenterId;
+    private long experimenterId;
 
     /**
      * @param <E> type of target experimenter object
@@ -26,18 +26,21 @@ public final class ExperimenterIdDeserializerKey extends MessageCodeKey
      * @param experimenterId experimenter / vendor ID
      * @param objectClass class of created object
      */
-    public <E extends DataObject> ExperimenterIdDeserializerKey(short version,
-            Long experimenterId, Class<E> objectClass) {
+    public <E extends DataContainer> ExperimenterIdDeserializerKey(short version,
+                                                                   long experimenterId, Class<E> objectClass) {
         super(version, EncodeConstants.EXPERIMENTER_VALUE, objectClass);
         this.experimenterId = experimenterId;
     }
 
+    protected int hashCodeOfLong(long longValue) {
+        return (int) (longValue ^ (longValue >>> 32));
+    }
 
     @Override
     public int hashCode() {
         final int prime = 31;
         int result = super.hashCode();
-        result = prime * result + ((experimenterId == null) ? 0 : experimenterId.hashCode());
+        result = prime * result + hashCodeOfLong(experimenterId);
         return result;
     }
 
@@ -53,11 +56,7 @@ public final class ExperimenterIdDeserializerKey extends MessageCodeKey
             return false;
         }
         ExperimenterIdDeserializerKey other = (ExperimenterIdDeserializerKey) obj;
-        if (experimenterId == null) {
-            if (other.experimenterId != null) {
-                return false;
-            }
-        } else if (!experimenterId.equals(other.experimenterId)) {
+        if (experimenterId != other.experimenterId) {
             return false;
         }
         return true;
diff --git a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/keys/ExperimenterIdTypeDeserializerKey.java b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/keys/ExperimenterIdTypeDeserializerKey.java
new file mode 100644 (file)
index 0000000..cb88b1a
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowjava.protocol.api.keys;
+
+import org.opendaylight.yangtools.yang.binding.DataContainer;
+
+/**
+ * @author michal.polkorab
+ */
+public class ExperimenterIdTypeDeserializerKey extends ExperimenterIdDeserializerKey {
+
+    private long type;
+
+    /**
+     * @param msgVersion     protocol wire version
+     * @param experimenterId experimenter / vendor ID
+     * @param type           data type according to vendor implementation
+     * @param objectClass    class of object to be serialized
+     */
+    public <T extends DataContainer> ExperimenterIdTypeDeserializerKey(short msgVersion,
+                                                                       long experimenterId, long type, Class<T> objectClass) {
+        super(msgVersion, experimenterId, objectClass);
+        this.type = type;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result + hashCodeOfLong(type);
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (!super.equals(obj)) {
+            return false;
+        }
+        if (!(obj instanceof ExperimenterIdTypeDeserializerKey)) {
+            return false;
+        }
+        ExperimenterIdTypeDeserializerKey other = (ExperimenterIdTypeDeserializerKey) obj;
+        if (type != other.type) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public String toString() {
+        return super.toString() + "; type: " + type;
+    }
+}
\ No newline at end of file
index 84e78a5839f4090984ad8f6ffc8c3cf46d553161..7e42a2b9bf2d95837cb22ca16cb83c4ea961b1e6 100644 (file)
                     type binary;
                 }
             }
-            grouping experimenter {
-                reference "OFPT_EXPERIMENTER message in Openflow Switch 1.3 Spec";
-                /* Symmetric message */
-                uses ofHeader;
 
-                leaf experimenter {
-                    type oft:experimenter-id;
-                }
-                leaf exp_type {
-                    type uint32;
-                }
-            }
             grouping experimenter-core {
                 description "General experimenter message content suitable for symmetric and multipart message";
                 leaf experimenter {
                 choice experimenter-data-of-choice {
                     // to be augmented by vendors
                 }
-             }
+            }
             grouping experimenter-of-message {
                 reference "OFPT_EXPERIMENTER message in Openflow Switch 1.3 Spec";
                 /* Symmetric message */
                     }
                     case multipart-reply-experimenter-case {
                         container multipart-reply-experimenter {
-                            // empty body - used for experimenter augmentation
+                            uses experimenter-core;
                         }
                     }
                 }
                 /* Symmetric message */
             }
             notification experimenter-message {
-                uses experimenter;
+                description "Experimenter request message from device.";
+                uses experimenter-of-message;
                 reference "OFPT_EXPERIMENTER message in Openflow Switch 1.3 Spec";
                 // TODO:: does switch send this when understood experimenter msg from lib?
                 /* Symmetric message */
index eb71029a9bbea1da376a0c974e153da12093771d..d7f61084c4661890e7bfd9bacf3320c95e047b3e 100644 (file)
@@ -36,7 +36,7 @@ public class ExperimenterIdDeserializerKeyTest {
         key2 = new ExperimenterIdDeserializerKey(EncodeConstants.OF13_VERSION_ID, 42L, ExperimenterMessage.class);
         Assert.assertFalse("Wrong equals", key1.equals(key2));
         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
-        key2 = new ExperimenterIdDeserializerKey(EncodeConstants.OF10_VERSION_ID, null, ExperimenterMessage.class);
+        key2 = new ExperimenterIdDeserializerKey(EncodeConstants.OF10_VERSION_ID, 0L, ExperimenterMessage.class);
         Assert.assertFalse("Wrong equals", key1.equals(key2));
         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
         key2 = new ExperimenterIdDeserializerKey(EncodeConstants.OF10_VERSION_ID, 55L, ExperimenterMessage.class);
@@ -56,7 +56,7 @@ public class ExperimenterIdDeserializerKeyTest {
     @Test
     public void testEquals() {
         ExperimenterIdDeserializerKey key1 =
-                new ExperimenterIdDeserializerKey(EncodeConstants.OF10_VERSION_ID, null, ExperimenterMessage.class);
+                new ExperimenterIdDeserializerKey(EncodeConstants.OF10_VERSION_ID, 0L, ExperimenterMessage.class);
         Assert.assertTrue("Wrong equal to identical object.", key1.equals(key1));
         MessageCodeKey mk = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID,EncodeConstants.EXPERIMENTER_VALUE, ExperimenterMessage.class);
         Assert.assertFalse("Wrong equal to different class.", key1.equals(mk));
diff --git a/openflow-protocol-api/src/test/java/org/opendaylight/openflowjava/protocol/api/keys/experimenter/ExperimenterIdTypeDeserializerKeyTest.java b/openflow-protocol-api/src/test/java/org/opendaylight/openflowjava/protocol/api/keys/experimenter/ExperimenterIdTypeDeserializerKeyTest.java
new file mode 100644 (file)
index 0000000..7405b77
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowjava.protocol.api.keys.experimenter;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdSerializerKey;
+import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdTypeDeserializerKey;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage;
+
+/**
+ * @author michal.polkorab
+ */
+public class ExperimenterIdTypeDeserializerKeyTest {
+
+    /**
+     * Test ExperimenterIdTypeDeserializerKey equals and hashCode
+     */
+    @Test
+    public void testHashCodeAndEquals() {
+        ExperimenterIdTypeDeserializerKey key1 =
+                new ExperimenterIdTypeDeserializerKey(EncodeConstants.OF10_VERSION_ID, 42L, 1L, ExperimenterMessage.class);
+        ExperimenterIdTypeDeserializerKey key2 =
+                new ExperimenterIdTypeDeserializerKey(EncodeConstants.OF10_VERSION_ID, 42L, 1L, ExperimenterMessage.class);
+        Assert.assertTrue("Wrong equals", key1.equals(key2));
+        Assert.assertTrue("Wrong hashcode", key1.hashCode() == key2.hashCode());
+        key2 = new ExperimenterIdTypeDeserializerKey(EncodeConstants.OF13_VERSION_ID, 42L, 1L, ExperimenterMessage.class);
+        Assert.assertFalse("Wrong equals", key1.equals(key2));
+        Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
+        key2 = new ExperimenterIdTypeDeserializerKey(EncodeConstants.OF10_VERSION_ID, 55L, 1L, ExperimenterMessage.class);
+        Assert.assertFalse("Wrong equals", key1.equals(key2));
+        Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
+        key2 = new ExperimenterIdTypeDeserializerKey(EncodeConstants.OF10_VERSION_ID, 55L, 1L, null);
+        Assert.assertFalse("Wrong equals", key1.equals(key2));
+        Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
+        key2 = new ExperimenterIdTypeDeserializerKey(EncodeConstants.OF10_VERSION_ID, 55L, 1L, ErrorMessage.class);
+        Assert.assertFalse("Wrong equals", key1.equals(key2));
+        Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
+
+        key2 = new ExperimenterIdTypeDeserializerKey(EncodeConstants.OF10_VERSION_ID, 42L, 2L, ExperimenterMessage.class);
+        Assert.assertFalse("Wrong equals", key1.equals(key2));
+        Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
+    }
+
+    /**
+     * Test ExperimenterIdTypeDeserializerKey equals - additional test
+     */
+    @Test
+    public void testEquals() {
+        ExperimenterIdTypeDeserializerKey key1 =
+                new ExperimenterIdTypeDeserializerKey(EncodeConstants.OF10_VERSION_ID, 41L, 1L, ExperimenterMessage.class);
+        Assert.assertTrue("Wrong equal to identical object.", key1.equals(key1));
+        ExperimenterIdSerializerKey<?> mk = new ExperimenterIdSerializerKey<>(EncodeConstants.OF10_VERSION_ID, 42L, ExperimenterMessage.class);
+        Assert.assertFalse("Wrong equal to different class.", key1.equals(mk));
+        ExperimenterIdTypeDeserializerKey key2 =
+                new ExperimenterIdTypeDeserializerKey(EncodeConstants.OF10_VERSION_ID, 42L, 1L, ExperimenterMessage.class);
+        Assert.assertFalse("Wrong equal by experimenterId.", key1.equals(key2));
+
+        ExperimenterIdTypeDeserializerKey key3 =
+                new ExperimenterIdTypeDeserializerKey(EncodeConstants.OF10_VERSION_ID, 41L, 2L, ExperimenterMessage.class);
+        Assert.assertFalse("Wrong equal by type.", key1.equals(key3));
+    }
+
+}
\ No newline at end of file
index 5d6d26c2e306e5b46d663be8a77c07b3632c74b9..0217d1f28b081b60d1e0290f81b700e34948e3bf 100644 (file)
@@ -41,12 +41,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.T
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmClassBase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandExperimenterCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestExperimenterCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueueProperty;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeatureProperties;
 import org.slf4j.Logger;
@@ -223,13 +219,13 @@ public class SwitchConnectionProviderImpl implements SwitchConnectionProvider, C
 
     @Override
     public void registerExperimenterMessageDeserializer(ExperimenterIdDeserializerKey key,
-            OFDeserializer<ExperimenterMessage> deserializer) {
+                                                        OFDeserializer<? extends ExperimenterDataOfChoice> deserializer) {
         deserializerRegistry.registerDeserializer(key, deserializer);
     }
 
     @Override
     public void registerMultipartReplyMessageDeserializer(ExperimenterIdDeserializerKey key,
-            OFDeserializer<MultipartReplyMessage> deserializer) {
+                                                          OFDeserializer<? extends ExperimenterDataOfChoice> deserializer) {
         deserializerRegistry.registerDeserializer(key, deserializer);
     }
 
index cf2693c80276a4c587b3bc0f45d47af17d8078e5..4a2d0b9df76b344f1fc06263f238da701bd4fbac 100644 (file)
@@ -161,7 +161,7 @@ public class ConnectionAdapterImpl implements ConnectionFacade {
 
     @Override
     public Future<RpcResult<Void>> experimenter(final ExperimenterInput input) {
-        return sendToSwitchFuture(input, "experimenter sending failed");
+        return sendToSwitchFuture(input, "experimenter reply sending failed");
     }
 
     @Override
index 3479bcc01d6c70dad3b8f6fe88f88d5601cacf7c..bbbb0681519c86abf523a4bd57f3f87ba6322625 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization;
 
 import java.util.HashMap;
 import java.util.Map;
-
 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistryInjector;
 import org.opendaylight.openflowjava.protocol.api.extensibility.OFGeneralDeserializer;
index c82408bf794a90f091116fc875115f4d0b7f4b8a..37f3a71ff3f64fa008591e918cd1e0bd726d004b 100644 (file)
@@ -8,10 +8,12 @@
 package org.opendaylight.openflowjava.protocol.impl.deserialization;
 
 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.BarrierReplyMessageFactory;
 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.EchoReplyMessageFactory;
 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.EchoRequestMessageFactory;
 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.ErrorMessageFactory;
+import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.ExperimenterMessageFactory;
 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.FeaturesReplyMessageFactory;
 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.FlowRemovedMessageFactory;
 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.GetAsyncReplyMessageFactory;
@@ -34,12 +36,13 @@ import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.Pac
 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.PortStatusMessageFactory;
 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.QueueGetConfigReplyMessageFactory;
 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.RoleReplyMessageFactory;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.VendorMessageFactory;
 import org.opendaylight.openflowjava.protocol.impl.util.SimpleDeserializerRegistryHelper;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigOutput;
@@ -73,6 +76,7 @@ public final class MessageDeserializerInitializer {
         helper.registerDeserializer(1, null, ErrorMessage.class, new OF10ErrorMessageFactory());
         helper.registerDeserializer(2, null, EchoRequestMessage.class, new OF10EchoRequestMessageFactory());
         helper.registerDeserializer(3, null, EchoOutput.class, new OF10EchoReplyMessageFactory());
+        helper.registerDeserializer(4, null, ExperimenterMessage.class, new VendorMessageFactory());
         helper.registerDeserializer(6, null, GetFeaturesOutput.class, new OF10FeaturesReplyMessageFactory());
         helper.registerDeserializer(8, null, GetConfigOutput.class, new OF10GetConfigReplyMessageFactory());
         helper.registerDeserializer(10, null, PacketInMessage.class, new OF10PacketInMessageFactory());
@@ -87,6 +91,7 @@ public final class MessageDeserializerInitializer {
         helper.registerDeserializer(1, null, ErrorMessage.class, new ErrorMessageFactory());
         helper.registerDeserializer(2, null, EchoRequestMessage.class, new EchoRequestMessageFactory());
         helper.registerDeserializer(3, null, EchoOutput.class, new EchoReplyMessageFactory());
+        helper.registerDeserializer(4, null, ExperimenterMessage.class, new ExperimenterMessageFactory());
         helper.registerDeserializer(6, null, GetFeaturesOutput.class, new FeaturesReplyMessageFactory());
         helper.registerDeserializer(8, null, GetConfigOutput.class, new GetConfigReplyMessageFactory());
         helper.registerDeserializer(10, null, PacketInMessage.class, new PacketInMessageFactory());
index 269976ffa7da4db72c40b4fdd5e77f49139c7128..244b4bfa1a3a6f2d18cc6ecc7f7a0230fcb25718 100644 (file)
@@ -9,13 +9,15 @@
 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
 
 import io.netty.buffer.ByteBuf;
-
 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistryInjector;
 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.util.ExperimenterDeserializerKeyFactory;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessageBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice;
 
 /**
  * @author michal.polkorab
@@ -24,17 +26,26 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 public class ExperimenterMessageFactory implements OFDeserializer<ExperimenterMessage>,
         DeserializerRegistryInjector {
 
-    /** Experimenter ID index after version, message type and length were read */
-    private static final byte EXPERIMENTER_ID_INDEX = 4;
     private DeserializerRegistry deserializerRegistry;
 
     @Override
     public ExperimenterMessage deserialize(ByteBuf message) {
-        long expId = message.getUnsignedInt(message.readerIndex() + EXPERIMENTER_ID_INDEX);
-        OFDeserializer<ExperimenterMessage> deserializer = deserializerRegistry.getDeserializer(
+        final long xid = message.readUnsignedInt();
+        final long expId = message.readUnsignedInt();
+        final long expType = message.readUnsignedInt();
+
+        OFDeserializer<ExperimenterDataOfChoice> deserializer = deserializerRegistry.getDeserializer(
                 ExperimenterDeserializerKeyFactory.createExperimenterMessageDeserializerKey(
-                        EncodeConstants.OF13_VERSION_ID, expId));
-        return deserializer.deserialize(message);
+                        EncodeConstants.OF13_VERSION_ID, expId, expType));
+        final ExperimenterDataOfChoice vendorData = deserializer.deserialize(message);
+
+        ExperimenterMessageBuilder messageBld = new ExperimenterMessageBuilder()
+                .setVersion((short) EncodeConstants.OF13_VERSION_ID)
+                .setXid(xid)
+                .setExperimenter(new ExperimenterId(expId))
+                .setExpType(expType)
+                .setExperimenterDataOfChoice(vendorData);
+        return messageBld.build();
     }
 
     @Override
index b6e24b45dd44683b32b82563fd042fedaf6bfe1d..085a8565e42113ca7ba3f7b91ede1c176d6041d2 100644 (file)
@@ -9,11 +9,9 @@
 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
 
 import io.netty.buffer.ByteBuf;
-
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.List;
-
 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistryInjector;
 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
@@ -38,6 +36,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupCapabilities;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId;
@@ -61,6 +60,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsListBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDropCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDscpRemarkCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandExperimenterCase;
@@ -71,6 +71,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyDescCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyDescCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyExperimenterCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyExperimenterCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupCase;
@@ -97,6 +98,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableFeaturesCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.aggregate._case.MultipartReplyAggregateBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.desc._case.MultipartReplyDescBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.experimenter._case.MultipartReplyExperimenterBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlowBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStats;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStatsBuilder;
@@ -140,6 +142,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 
 /**
  * Translates MultipartReply messages
+ *
  * @author timotej.kubas
  * @author michal.polkorab
  */
@@ -189,38 +192,53 @@ public class MultipartReplyMessageFactory implements OFDeserializer<MultipartRep
         rawMessage.skipBytes(PADDING_IN_MULTIPART_REPLY_HEADER);
 
         switch (MultipartType.forValue(type)) {
-        case OFPMPDESC:  builder.setMultipartReplyBody(setDesc(rawMessage));
-                 break;
-        case OFPMPFLOW:  builder.setMultipartReplyBody(setFlow(rawMessage));
-                 break;
-        case OFPMPAGGREGATE:  builder.setMultipartReplyBody(setAggregate(rawMessage));
-                 break;
-        case OFPMPTABLE:  builder.setMultipartReplyBody(setTable(rawMessage));
-                 break;
-        case OFPMPPORTSTATS:  builder.setMultipartReplyBody(setPortStats(rawMessage));
-                 break;
-        case OFPMPQUEUE:  builder.setMultipartReplyBody(setQueue(rawMessage));
-                 break;
-        case OFPMPGROUP:  builder.setMultipartReplyBody(setGroup(rawMessage));
-                 break;
-        case OFPMPGROUPDESC:  builder.setMultipartReplyBody(setGroupDesc(rawMessage));
-                 break;
-        case OFPMPGROUPFEATURES:  builder.setMultipartReplyBody(setGroupFeatures(rawMessage));
-                 break;
-        case OFPMPMETER:  builder.setMultipartReplyBody(setMeter(rawMessage));
-                 break;
-        case OFPMPMETERCONFIG: builder.setMultipartReplyBody(setMeterConfig(rawMessage));
-                 break;
-        case OFPMPMETERFEATURES: builder.setMultipartReplyBody(setMeterFeatures(rawMessage));
-                 break;
-        case OFPMPTABLEFEATURES: builder.setMultipartReplyBody(setTableFeatures(rawMessage));
-                 break;
-        case OFPMPPORTDESC: builder.setMultipartReplyBody(setPortDesc(rawMessage));
-                 break;
-        case OFPMPEXPERIMENTER: builder.setMultipartReplyBody(setExperimenter(rawMessage));
-                 break;
-        default:
-                 break;
+            case OFPMPDESC:
+                builder.setMultipartReplyBody(setDesc(rawMessage));
+                break;
+            case OFPMPFLOW:
+                builder.setMultipartReplyBody(setFlow(rawMessage));
+                break;
+            case OFPMPAGGREGATE:
+                builder.setMultipartReplyBody(setAggregate(rawMessage));
+                break;
+            case OFPMPTABLE:
+                builder.setMultipartReplyBody(setTable(rawMessage));
+                break;
+            case OFPMPPORTSTATS:
+                builder.setMultipartReplyBody(setPortStats(rawMessage));
+                break;
+            case OFPMPQUEUE:
+                builder.setMultipartReplyBody(setQueue(rawMessage));
+                break;
+            case OFPMPGROUP:
+                builder.setMultipartReplyBody(setGroup(rawMessage));
+                break;
+            case OFPMPGROUPDESC:
+                builder.setMultipartReplyBody(setGroupDesc(rawMessage));
+                break;
+            case OFPMPGROUPFEATURES:
+                builder.setMultipartReplyBody(setGroupFeatures(rawMessage));
+                break;
+            case OFPMPMETER:
+                builder.setMultipartReplyBody(setMeter(rawMessage));
+                break;
+            case OFPMPMETERCONFIG:
+                builder.setMultipartReplyBody(setMeterConfig(rawMessage));
+                break;
+            case OFPMPMETERFEATURES:
+                builder.setMultipartReplyBody(setMeterFeatures(rawMessage));
+                break;
+            case OFPMPTABLEFEATURES:
+                builder.setMultipartReplyBody(setTableFeatures(rawMessage));
+                break;
+            case OFPMPPORTDESC:
+                builder.setMultipartReplyBody(setPortDesc(rawMessage));
+                break;
+            case OFPMPEXPERIMENTER:
+                builder.setMultipartReplyBody(setExperimenter(rawMessage));
+                break;
+            default:
+                break;
         }
 
         return builder.build();
@@ -294,7 +312,7 @@ public class MultipartReplyMessageFactory implements OFDeserializer<MultipartRep
         return caseBuilder.build();
     }
 
-    private static FlowModFlags createFlowModFlagsFromBitmap(int input){
+    private static FlowModFlags createFlowModFlagsFromBitmap(int input) {
         final Boolean fmfSENDFLOWREM = (input & (1 << 0)) != 0;
         final Boolean fmfCHECKOVERLAP = (input & (1 << 1)) != 0;
         final Boolean fmfRESETCOUNTS = (input & (1 << 2)) != 0;
@@ -501,7 +519,7 @@ public class MultipartReplyMessageFactory implements OFDeserializer<MultipartRep
     }
 
     private static MultipartReplyQueueCase setQueue(ByteBuf input) {
-       MultipartReplyQueueCaseBuilder caseBuilder = new MultipartReplyQueueCaseBuilder();
+        MultipartReplyQueueCaseBuilder caseBuilder = new MultipartReplyQueueCaseBuilder();
         MultipartReplyQueueBuilder builder = new MultipartReplyQueueBuilder();
         List<QueueStats> queueStatsList = new ArrayList<>();
         while (input.readableBytes() > 0) {
@@ -579,7 +597,7 @@ public class MultipartReplyMessageFactory implements OFDeserializer<MultipartRep
         return caseBuilder.build();
     }
 
-    private static MeterFlags createMeterFlags(long input){
+    private static MeterFlags createMeterFlags(long input) {
         final Boolean mfKBPS = (input & (1 << 0)) != 0;
         final Boolean mfPKTPS = (input & (1 << 1)) != 0;
         final Boolean mfBURST = (input & (1 << 2)) != 0;
@@ -649,7 +667,7 @@ public class MultipartReplyMessageFactory implements OFDeserializer<MultipartRep
                 int bandType = input.readUnsignedShort();
                 switch (bandType) {
                     case 1:
-                       MeterBandDropCaseBuilder bandDropCaseBuilder = new MeterBandDropCaseBuilder();
+                        MeterBandDropCaseBuilder bandDropCaseBuilder = new MeterBandDropCaseBuilder();
                         MeterBandDropBuilder bandDropBuilder = new MeterBandDropBuilder();
                         bandDropBuilder.setType(MeterBandType.forValue(bandType));
                         actualLength += input.readUnsignedShort();
@@ -660,7 +678,7 @@ public class MultipartReplyMessageFactory implements OFDeserializer<MultipartRep
                         bandsBuilder.setMeterBand(bandDropCaseBuilder.build());
                         break;
                     case 2:
-                       MeterBandDscpRemarkCaseBuilder bandDscpRemarkCaseBuilder = new MeterBandDscpRemarkCaseBuilder();
+                        MeterBandDscpRemarkCaseBuilder bandDscpRemarkCaseBuilder = new MeterBandDscpRemarkCaseBuilder();
                         MeterBandDscpRemarkBuilder bandDscpRemarkBuilder = new MeterBandDscpRemarkBuilder();
                         bandDscpRemarkBuilder.setType(MeterBandType.forValue(bandType));
                         actualLength += input.readUnsignedShort();
@@ -694,8 +712,20 @@ public class MultipartReplyMessageFactory implements OFDeserializer<MultipartRep
     }
 
     private MultipartReplyExperimenterCase setExperimenter(ByteBuf input) {
-        return registry.getDeserializer(ExperimenterDeserializerKeyFactory.createMultipartReplyMessageDeserializerKey(
-                EncodeConstants.OF13_VERSION_ID, input.readUnsignedInt()));
+        final long expId = input.readUnsignedInt();
+        final long expType = input.readUnsignedInt();
+
+        final OFDeserializer<ExperimenterDataOfChoice> deserializer = registry.getDeserializer(
+                ExperimenterDeserializerKeyFactory.createMultipartReplyMessageDeserializerKey(
+                        EncodeConstants.OF13_VERSION_ID, expId, expType));
+
+        final MultipartReplyExperimenterBuilder mpExperimenterBld = new MultipartReplyExperimenterBuilder()
+                .setExperimenter(new ExperimenterId(expId))
+                .setExpType(expType)
+                .setExperimenterDataOfChoice(deserializer.deserialize(input));
+        final MultipartReplyExperimenterCaseBuilder mpReplyExperimenterCaseBld = new MultipartReplyExperimenterCaseBuilder()
+                .setMultipartReplyExperimenter(mpExperimenterBld.build());
+        return mpReplyExperimenterCaseBld.build();
     }
 
     private static MultipartReplyPortDescCase setPortDesc(ByteBuf input) {
@@ -726,38 +756,38 @@ public class MultipartReplyMessageFactory implements OFDeserializer<MultipartRep
         return caseBuilder.build();
     }
 
-    private static PortConfig createPortConfig(long input){
-        final Boolean pcPortDown   = ((input) & (1<<0)) != 0;
-        final Boolean pcNRecv    = ((input) & (1<<2)) != 0;
-        final Boolean pcNFwd       = ((input) & (1<<5)) != 0;
-        final Boolean pcNPacketIn = ((input) & (1<<6)) != 0;
+    private static PortConfig createPortConfig(long input) {
+        final Boolean pcPortDown = ((input) & (1 << 0)) != 0;
+        final Boolean pcNRecv = ((input) & (1 << 2)) != 0;
+        final Boolean pcNFwd = ((input) & (1 << 5)) != 0;
+        final Boolean pcNPacketIn = ((input) & (1 << 6)) != 0;
         return new PortConfig(pcNFwd, pcNPacketIn, pcNRecv, pcPortDown);
     }
 
-    private static PortState createPortState(long input){
-        final Boolean psLinkDown = ((input) & (1<<0)) != 0;
-        final Boolean psBlocked  = ((input) & (1<<1)) != 0;
-        final Boolean psLive     = ((input) & (1<<2)) != 0;
+    private static PortState createPortState(long input) {
+        final Boolean psLinkDown = ((input) & (1 << 0)) != 0;
+        final Boolean psBlocked = ((input) & (1 << 1)) != 0;
+        final Boolean psLive = ((input) & (1 << 2)) != 0;
         return new PortState(psBlocked, psLinkDown, psLive);
     }
 
-    private static PortFeatures createPortFeatures(long input){
-        final Boolean pf10mbHd = ((input) & (1<<0)) != 0;
-        final Boolean pf10mbFd = ((input) & (1<<1)) != 0;
-        final Boolean pf100mbHd = ((input) & (1<<2)) != 0;
-        final Boolean pf100mbFd = ((input) & (1<<3)) != 0;
-        final Boolean pf1gbHd = ((input) & (1<<4)) != 0;
-        final Boolean pf1gbFd = ((input) & (1<<5)) != 0;
-        final Boolean pf10gbFd = ((input) & (1<<6)) != 0;
-        final Boolean pf40gbFd = ((input) & (1<<7)) != 0;
-        final Boolean pf100gbFd = ((input) & (1<<8)) != 0;
-        final Boolean pf1tbFd = ((input) & (1<<9)) != 0;
-        final Boolean pfOther = ((input) & (1<<10)) != 0;
-        final Boolean pfCopper = ((input) & (1<<11)) != 0;
-        final Boolean pfFiber = ((input) & (1<<12)) != 0;
-        final Boolean pfAutoneg = ((input) & (1<<13)) != 0;
-        final Boolean pfPause = ((input) & (1<<14)) != 0;
-        final Boolean pfPauseAsym = ((input) & (1<<15)) != 0;
+    private static PortFeatures createPortFeatures(long input) {
+        final Boolean pf10mbHd = ((input) & (1 << 0)) != 0;
+        final Boolean pf10mbFd = ((input) & (1 << 1)) != 0;
+        final Boolean pf100mbHd = ((input) & (1 << 2)) != 0;
+        final Boolean pf100mbFd = ((input) & (1 << 3)) != 0;
+        final Boolean pf1gbHd = ((input) & (1 << 4)) != 0;
+        final Boolean pf1gbFd = ((input) & (1 << 5)) != 0;
+        final Boolean pf10gbFd = ((input) & (1 << 6)) != 0;
+        final Boolean pf40gbFd = ((input) & (1 << 7)) != 0;
+        final Boolean pf100gbFd = ((input) & (1 << 8)) != 0;
+        final Boolean pf1tbFd = ((input) & (1 << 9)) != 0;
+        final Boolean pfOther = ((input) & (1 << 10)) != 0;
+        final Boolean pfCopper = ((input) & (1 << 11)) != 0;
+        final Boolean pfFiber = ((input) & (1 << 12)) != 0;
+        final Boolean pfAutoneg = ((input) & (1 << 13)) != 0;
+        final Boolean pfPause = ((input) & (1 << 14)) != 0;
+        final Boolean pfPauseAsym = ((input) & (1 << 15)) != 0;
         return new PortFeatures(pf100gbFd, pf100mbFd, pf100mbHd, pf10gbFd, pf10mbFd, pf10mbHd, pf1gbFd,
                 pf1gbHd, pf1tbFd, pf40gbFd, pfAutoneg, pfCopper, pfFiber, pfOther, pfPause, pfPauseAsym);
     }
@@ -768,12 +798,12 @@ public class MultipartReplyMessageFactory implements OFDeserializer<MultipartRep
         featuresBuilder.setTypes(createGroupType(rawMessage.readUnsignedInt()));
         featuresBuilder.setCapabilities(createCapabilities(rawMessage.readUnsignedInt()));
         List<Long> maxGroupsList = new ArrayList<>();
-        for (int i = 0; i < GROUP_TYPES ; i++) {
+        for (int i = 0; i < GROUP_TYPES; i++) {
             maxGroupsList.add(rawMessage.readUnsignedInt());
         }
         featuresBuilder.setMaxGroups(maxGroupsList);
         List<ActionType> actionBitmaps = new ArrayList<>();
-        for (int i = 0; i < GROUP_TYPES ; i++) {
+        for (int i = 0; i < GROUP_TYPES; i++) {
             actionBitmaps.add(createActionBitmap(rawMessage.readUnsignedInt()));
         }
         featuresBuilder.setActionsBitmap(actionBitmaps);
@@ -782,22 +812,22 @@ public class MultipartReplyMessageFactory implements OFDeserializer<MultipartRep
     }
 
     private static ActionType createActionBitmap(long input) {
-        final Boolean atOutput = ((input) & (1<<0)) != 0;
-        final Boolean atCopyTTLout = ((input) & (1<<11)) != 0;
-        final Boolean atCopyTTLin = ((input) & (1<<12)) != 0;
-        final Boolean atSetMplsTTL = ((input) & (1<<15)) != 0;
-        final Boolean atDecMplsTTL = ((input) & (1<<16)) != 0;
-        final Boolean atPushVLAN = ((input) & (1<<17)) != 0;
-        final Boolean atPopVLAN = ((input) & (1<<18)) != 0;
-        final Boolean atPushMPLS = ((input) & (1<<19)) != 0;
-        final Boolean atPopMPLS = ((input) & (1<<20)) != 0;
-        final Boolean atSetQueue = ((input) & (1<<21)) != 0;
-        final Boolean atGroup = ((input) & (1<<22)) != 0;
-        final Boolean atSetNWTTL = ((input) & (1<<23)) != 0;
-        final Boolean atDecNWTTL = ((input) & (1<<24)) != 0;
-        final Boolean atSetField = ((input) & (1<<25)) != 0;
-        final Boolean atPushPBB = ((input) & (1<<26)) != 0;
-        final Boolean atPopPBB = ((input) & (1<<27)) != 0;
+        final Boolean atOutput = ((input) & (1 << 0)) != 0;
+        final Boolean atCopyTTLout = ((input) & (1 << 11)) != 0;
+        final Boolean atCopyTTLin = ((input) & (1 << 12)) != 0;
+        final Boolean atSetMplsTTL = ((input) & (1 << 15)) != 0;
+        final Boolean atDecMplsTTL = ((input) & (1 << 16)) != 0;
+        final Boolean atPushVLAN = ((input) & (1 << 17)) != 0;
+        final Boolean atPopVLAN = ((input) & (1 << 18)) != 0;
+        final Boolean atPushMPLS = ((input) & (1 << 19)) != 0;
+        final Boolean atPopMPLS = ((input) & (1 << 20)) != 0;
+        final Boolean atSetQueue = ((input) & (1 << 21)) != 0;
+        final Boolean atGroup = ((input) & (1 << 22)) != 0;
+        final Boolean atSetNWTTL = ((input) & (1 << 23)) != 0;
+        final Boolean atDecNWTTL = ((input) & (1 << 24)) != 0;
+        final Boolean atSetField = ((input) & (1 << 25)) != 0;
+        final Boolean atPushPBB = ((input) & (1 << 26)) != 0;
+        final Boolean atPopPBB = ((input) & (1 << 27)) != 0;
         final Boolean atExperimenter = false;
         return new ActionType(atCopyTTLin, atCopyTTLout, atDecMplsTTL,
                 atDecNWTTL, atExperimenter, atGroup, atOutput, atPopMPLS,
@@ -806,18 +836,18 @@ public class MultipartReplyMessageFactory implements OFDeserializer<MultipartRep
     }
 
     private static GroupCapabilities createCapabilities(long input) {
-        final Boolean gcSelectWeight = ((input) & (1<<0)) != 0;
-        final Boolean gcSelectLiveness = ((input) & (1<<1)) != 0;
-        final Boolean gcChaining = ((input) & (1<<2)) != 0;
-        final Boolean gcChainingChecks = ((input) & (1<<3)) != 0;
+        final Boolean gcSelectWeight = ((input) & (1 << 0)) != 0;
+        final Boolean gcSelectLiveness = ((input) & (1 << 1)) != 0;
+        final Boolean gcChaining = ((input) & (1 << 2)) != 0;
+        final Boolean gcChainingChecks = ((input) & (1 << 3)) != 0;
         return new GroupCapabilities(gcChaining, gcChainingChecks, gcSelectLiveness, gcSelectWeight);
     }
 
     private static GroupTypes createGroupType(long input) {
-        final Boolean gtAll = ((input) & (1<<0)) != 0;
-        final Boolean gtSelect = ((input) & (1<<1)) != 0;
-        final Boolean gtIndirect = ((input) & (1<<2)) != 0;
-        final Boolean gtFF = ((input) & (1<<3)) != 0;
+        final Boolean gtAll = ((input) & (1 << 0)) != 0;
+        final Boolean gtSelect = ((input) & (1 << 1)) != 0;
+        final Boolean gtIndirect = ((input) & (1 << 2)) != 0;
+        final Boolean gtFF = ((input) & (1 << 3)) != 0;
         return new GroupTypes(gtAll, gtFF, gtIndirect, gtSelect);
     }
 
index 691a270f0905e8a5f00e3438060323734e8d9787..f09992853612145762fbf7f0363855aba544feba 100644 (file)
@@ -9,11 +9,9 @@
 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
 
 import io.netty.buffer.ByteBuf;
-
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.List;
-
 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistryInjector;
 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
@@ -26,16 +24,19 @@ import org.opendaylight.openflowjava.protocol.impl.util.OF10MatchDeserializer;
 import org.opendaylight.openflowjava.util.ByteBufUtils;
 import org.opendaylight.openflowjava.util.ExperimenterDeserializerKeyFactory;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregateCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregateCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyDescCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyDescCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyExperimenterCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyExperimenterCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortStatsCase;
@@ -46,6 +47,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.aggregate._case.MultipartReplyAggregateBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.desc._case.MultipartReplyDescBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.experimenter._case.MultipartReplyExperimenterBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlowBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStats;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStatsBuilder;
@@ -61,6 +63,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 
 /**
  * Translates StatsReply messages (OpenFlow v1.0)
+ *
  * @author michal.polkorab
  */
 public class OF10StatsReplyMessageFactory implements OFDeserializer<MultipartReplyMessage>,
@@ -88,22 +91,29 @@ public class OF10StatsReplyMessageFactory implements OFDeserializer<MultipartRep
         builder.setType(MultipartType.forValue(type));
         builder.setFlags(new MultipartRequestFlags((rawMessage.readUnsignedShort() & 0x01) != 0));
         switch (MultipartType.forValue(type)) {
-        case OFPMPDESC:  builder.setMultipartReplyBody(setDesc(rawMessage));
-            break;
-        case OFPMPFLOW:  builder.setMultipartReplyBody(setFlow(rawMessage));
-            break;
-        case OFPMPAGGREGATE:  builder.setMultipartReplyBody(setAggregate(rawMessage));
-            break;
-        case OFPMPTABLE:  builder.setMultipartReplyBody(setTable(rawMessage));
-            break;
-        case OFPMPPORTSTATS:  builder.setMultipartReplyBody(setPortStats(rawMessage));
-            break;
-        case OFPMPQUEUE:  builder.setMultipartReplyBody(setQueue(rawMessage));
-            break;
-        case OFPMPEXPERIMENTER: builder.setMultipartReplyBody(setExperimenter(rawMessage));
-            break;
-        default:
-            break;
+            case OFPMPDESC:
+                builder.setMultipartReplyBody(setDesc(rawMessage));
+                break;
+            case OFPMPFLOW:
+                builder.setMultipartReplyBody(setFlow(rawMessage));
+                break;
+            case OFPMPAGGREGATE:
+                builder.setMultipartReplyBody(setAggregate(rawMessage));
+                break;
+            case OFPMPTABLE:
+                builder.setMultipartReplyBody(setTable(rawMessage));
+                break;
+            case OFPMPPORTSTATS:
+                builder.setMultipartReplyBody(setPortStats(rawMessage));
+                break;
+            case OFPMPQUEUE:
+                builder.setMultipartReplyBody(setQueue(rawMessage));
+                break;
+            case OFPMPEXPERIMENTER:
+                builder.setMultipartReplyBody(setExperimenter(rawMessage));
+                break;
+            default:
+                break;
         }
         return builder.build();
     }
@@ -295,8 +305,16 @@ public class OF10StatsReplyMessageFactory implements OFDeserializer<MultipartRep
     }
 
     private MultipartReplyExperimenterCase setExperimenter(ByteBuf input) {
-        return registry.getDeserializer(ExperimenterDeserializerKeyFactory.createMultipartReplyMessageDeserializerKey(
-                EncodeConstants.OF10_VERSION_ID, input.readUnsignedInt()));
+        final long expId = input.readUnsignedInt();
+        final OFDeserializer<ExperimenterDataOfChoice> deserializer = registry.getDeserializer(ExperimenterDeserializerKeyFactory.createMultipartReplyVendorMessageDeserializerKey(
+                EncodeConstants.OF10_VERSION_ID, expId));
+
+        final MultipartReplyExperimenterBuilder mpExperimenterBld = new MultipartReplyExperimenterBuilder()
+                .setExperimenter(new ExperimenterId(expId))
+                .setExperimenterDataOfChoice(deserializer.deserialize(input));
+        final MultipartReplyExperimenterCaseBuilder mpReplyExperimenterCaseBld = new MultipartReplyExperimenterCaseBuilder()
+                .setMultipartReplyExperimenter(mpExperimenterBld.build());
+        return mpReplyExperimenterCaseBld.build();
     }
 
     @Override
index be6d0004d52ba064df3fa2c935a65a016213020c..9461da1c9ca6f6738be09dad69e0f3cbccffd13f 100644 (file)
@@ -9,31 +9,39 @@
 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
 
 import io.netty.buffer.ByteBuf;
-
 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistryInjector;
 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.util.ExperimenterDeserializerKeyFactory;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessageBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice;
 
 /**
  * @author michal.polkorab
- *
  */
 public class VendorMessageFactory implements OFDeserializer<ExperimenterMessage>,
         DeserializerRegistryInjector {
 
-    private static final byte VENDOR_ID_INDEX = 8;
     private DeserializerRegistry deserializerRegistry;
 
     @Override
     public ExperimenterMessage deserialize(ByteBuf message) {
-        long expId = message.getUnsignedInt(message.readerIndex() + VENDOR_ID_INDEX);
-        OFDeserializer<ExperimenterMessage> deserializer = deserializerRegistry.getDeserializer(
-                ExperimenterDeserializerKeyFactory.createExperimenterMessageDeserializerKey(
+        final long xid = message.readUnsignedInt();
+        final long expId = message.readUnsignedInt();
+        OFDeserializer<ExperimenterDataOfChoice> deserializer = deserializerRegistry.getDeserializer(
+                ExperimenterDeserializerKeyFactory.createVendorMessageDeserializerKey(
                         EncodeConstants.OF10_VERSION_ID, expId));
-        return deserializer.deserialize(message);
+        final ExperimenterDataOfChoice vendorData = deserializer.deserialize(message);
+
+        final ExperimenterMessageBuilder messageBld = new ExperimenterMessageBuilder()
+                .setVersion((short) EncodeConstants.OF10_VERSION_ID)
+                .setXid(xid)
+                .setExperimenter(new ExperimenterId(expId))
+                .setExperimenterDataOfChoice(vendorData);
+        return messageBld.build();
     }
 
     @Override
index f70962f640f41bd2626c6c09f908a8a84b73fc69..73237c4a4bc34ede7a1c87bede34b62dd5ebed99 100644 (file)
@@ -40,17 +40,13 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.T
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.InPort;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandExperimenterCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestExperimenterCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueueProperty;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeatureProperties;
 
-import com.google.common.util.concurrent.ListenableFuture;
-
 /**
  * @author madamjak
  * @author michal.polkorab
@@ -60,8 +56,8 @@ public class SwitchConnectionProviderImpl02Test {
     @Mock OFGeneralSerializer serializer;
     @Mock OFGeneralDeserializer deserializer;
     @Mock OFDeserializer<ErrorMessage> deserializerError;
-    @Mock OFDeserializer<ExperimenterMessage> deserializerExpMsg;
-    @Mock OFDeserializer<MultipartReplyMessage> deserializerMultipartRplMsg;
+    @Mock OFDeserializer<ExperimenterDataOfChoice> deserializerExpMsg;
+    @Mock OFDeserializer<ExperimenterDataOfChoice> deserializerMultipartRplMsg;
     @Mock OFDeserializer<QueueProperty> deserializerQueueProperty;
     @Mock OFDeserializer<MeterBandExperimenterCase> deserializerMeterBandExpCase;
     @Mock OFSerializer<ExperimenterDataOfChoice> serializerExperimenterInput;
index d25137cac9b00a37c55cb5d080859861bc1aa97c..37dd6ddeb9f4da980b536ded0ae0f5cc43e3c526 100644 (file)
@@ -10,35 +10,39 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
 
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.when;
-import io.netty.buffer.ByteBuf;
 
+import io.netty.buffer.ByteBuf;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.runners.MockitoJUnitRunner;
 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
 import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdDeserializerKey;
 import org.opendaylight.openflowjava.util.ByteBufUtils;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice;
 
 /**
  * @author michal.polkorab
  *
  */
+@RunWith(MockitoJUnitRunner.class)
 public class ExperimenterMessageFactoryTest {
 
     @Mock DeserializerRegistry registry;
-    @Mock OFDeserializer<ExperimenterMessage> deserializer;
-    @Mock ExperimenterMessage message;
+    @Mock OFDeserializer<ExperimenterDataOfChoice> deserializer;
+    @Mock ExperimenterDataOfChoice message;
+    private ExperimenterMessageFactory factory;
 
     /**
      * Initializes mocks
      */
     @Before
     public void startUp() {
-        MockitoAnnotations.initMocks(this);
+        factory = new ExperimenterMessageFactory();
     }
 
     /**
@@ -49,11 +53,10 @@ public class ExperimenterMessageFactoryTest {
         when(registry.getDeserializer(any(ExperimenterIdDeserializerKey.class))).thenReturn(deserializer);
         when(deserializer.deserialize(any(ByteBuf.class))).thenReturn(message);
 
-        ByteBuf buffer = ByteBufUtils.hexStringToByteBuf("00 01 02 03 00 00 00 10");
-        ExperimenterMessageFactory factory = new ExperimenterMessageFactory();
+        ByteBuf buffer = ByteBufUtils.hexStringToByteBuf("00 01 02 03 00 00 00 10 00 00 00 20");
         factory.injectDeserializerRegistry(registry);
         ExperimenterMessage deserializedMessage = factory.deserialize(buffer);
-        Assert.assertEquals("Wrong return value", message, deserializedMessage);
-        Assert.assertEquals("ByteBuf index moved", 0, buffer.readerIndex());
+        Assert.assertEquals("Wrong return value", message, deserializedMessage.getExperimenterDataOfChoice());
+        Assert.assertEquals("ByteBuf index moved", 0, buffer.readableBytes());
     }
 }
\ No newline at end of file
index 050eee0e0d19f2d5daf64c852b2748e860d761a0..aaa94680c756f42b951bdb9a2649610ef6b998b4 100644 (file)
@@ -9,7 +9,6 @@
 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
 
 import io.netty.buffer.ByteBuf;
-
 import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -36,13 +35,13 @@ public class VendorMessageFactoryTest {
      */
     @Test
     public void test() {
-        Mockito.when(registry.getDeserializer(Matchers.any(MessageCodeKey.class))).thenReturn(deserializer);
-        ByteBuf buffer = ByteBufUtils.hexStringToByteBuf("04 04 00 10 01 02 03 04 FF FF FF FF 80 00 00 00");
+        Mockito.when(registry.getDeserializer(Matchers.<MessageCodeKey>any())).thenReturn(deserializer);
+        ByteBuf buffer = ByteBufUtils.hexStringToByteBuf("01 02 03 04 FF FF FF FF 80 00 00 00");
         VendorMessageFactory factory = new VendorMessageFactory();
         factory.injectDeserializerRegistry(registry);
         factory.deserialize(buffer);
 
         Mockito.verify(deserializer, Mockito.times(1)).deserialize(buffer);
-        Assert.assertEquals("Buffer index modified", 16, buffer.readableBytes());
+        Assert.assertEquals("Buffer index modified", 4, buffer.readableBytes());
     }
 }
\ No newline at end of file
index 1e989ed3f25f72db022ba691b8bd11c06b814db0..5acb3f326d7b2916c949de1f12bc28eee8570cfa 100644 (file)
@@ -9,7 +9,6 @@
 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories.multipart;
 
 import io.netty.buffer.ByteBuf;
-
 import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -18,10 +17,12 @@ import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.mockito.runners.MockitoJUnitRunner;
 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
 import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.MultipartReplyMessageFactory;
 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice;
 
 /**
  * @author michal.polkorab
@@ -33,12 +34,15 @@ public class MultipartReplyExperimenterTest {
     @Mock DeserializerRegistry registry;
 
     private MultipartReplyMessageFactory factory = new MultipartReplyMessageFactory();
+    @Mock
+    private OFDeserializer<ExperimenterDataOfChoice> vendorDeserializer;
 
     /**
      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO
      */
     @Test
     public void testMultipartReplyExperimenter() {
+        Mockito.when(registry.getDeserializer(Matchers.<MessageCodeKey>any())).thenReturn(vendorDeserializer);
         factory.injectDeserializerRegistry(registry);
         ByteBuf bb = BufferHelper.buildBuffer("FF FF 00 01 00 00 00 00 "
                                             + "00 00 00 01 00 00 00 02"); // expID, expType
@@ -48,6 +52,6 @@ public class MultipartReplyExperimenterTest {
         Assert.assertEquals("Wrong type", 65535, builtByFactory.getType().getIntValue());
         Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
 
-        Mockito.verify(registry, Mockito.times(1)).getDeserializer(Matchers.any(MessageCodeKey.class));
+        Mockito.verify(vendorDeserializer).deserialize(bb);
     }
 }
\ No newline at end of file
index 8986f5c80f8be976345dd7bd28e81c368423fe76..69d420feb0bdfce3df08a17f7129a7a7a26e3305 100644 (file)
@@ -9,7 +9,6 @@
 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories.multipart;
 
 import io.netty.buffer.ByteBuf;
-
 import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -18,10 +17,12 @@ import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.mockito.runners.MockitoJUnitRunner;
 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
 import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10StatsReplyMessageFactory;
 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice;
 
 /**
  * @author michal.polkorab
@@ -31,12 +32,14 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 public class OF10StatsReplyExperimenterTest {
 
     @Mock DeserializerRegistry registry;
+    @Mock private OFDeserializer<ExperimenterDataOfChoice> vendorDeserializer;
 
     /**
      * Tests {@link OF10StatsReplyMessageFactory} for experimenter body translation
      */
     @Test
     public void test() {
+        Mockito.when(registry.getDeserializer(Matchers.<MessageCodeKey>any())).thenReturn(vendorDeserializer);
         OF10StatsReplyMessageFactory factory = new OF10StatsReplyMessageFactory();
         factory.injectDeserializerRegistry(registry);
 
@@ -47,6 +50,7 @@ public class OF10StatsReplyExperimenterTest {
         BufferHelper.checkHeaderV10(builtByFactory);
         Assert.assertEquals("Wrong type", 65535, builtByFactory.getType().getIntValue());
         Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
-        Mockito.verify(registry, Mockito.times(1)).getDeserializer(Matchers.any(MessageCodeKey.class));
+
+        Mockito.verify(vendorDeserializer).deserialize(bb);
     }
 }
\ No newline at end of file
index 36f44ff2423eda056a20b2605c888ee48b08c630..6c65deedb717f85fc788f4a285173485436b193f 100644 (file)
@@ -9,10 +9,10 @@
 package org.opendaylight.openflowjava.util;
 
 import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdDeserializerKey;
+import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdTypeDeserializerKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandExperimenterCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyExperimenterCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueueProperty;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeatureProperties;
 
@@ -39,21 +39,43 @@ public abstract class ExperimenterDeserializerKeyFactory {
     /**
      * @param version openflow wire version
      * @param experimenterId experimenter / vendor ID
+     * @param type experimenter type according to vendor implementation
      * @return key instance
      */
-    public static ExperimenterIdDeserializerKey createExperimenterMessageDeserializerKey(
-            short version, Long experimenterId) {
-        return new ExperimenterIdDeserializerKey(version, experimenterId, ExperimenterMessage.class);
+    public static ExperimenterIdTypeDeserializerKey createExperimenterMessageDeserializerKey(
+            short version, long experimenterId, long type) {
+        return new ExperimenterIdTypeDeserializerKey(version, experimenterId, type, ExperimenterDataOfChoice.class);
+    }
+
+    /**
+     * @param version        openflow wire version
+     * @param experimenterId experimenter / vendor ID
+     * @return key instance
+     */
+    public static ExperimenterIdDeserializerKey createVendorMessageDeserializerKey(
+            short version, long experimenterId) {
+        return new ExperimenterIdDeserializerKey(version, experimenterId, ExperimenterDataOfChoice.class);
     }
 
     /**
      * @param version openflow wire version
      * @param experimenterId experimenter / vendor ID
+     * @param type
      * @return key instance
      */
-    public static ExperimenterIdDeserializerKey createMultipartReplyMessageDeserializerKey(
-            short version, Long experimenterId) {
-        return new ExperimenterIdDeserializerKey(version, experimenterId, MultipartReplyExperimenterCase.class);
+    public static ExperimenterIdTypeDeserializerKey createMultipartReplyMessageDeserializerKey(
+            short version, long experimenterId, long type) {
+        return new ExperimenterIdTypeDeserializerKey(version, experimenterId, type, ExperimenterDataOfChoice.class);
+    }
+
+    /**
+     * @param version        openflow wire version
+     * @param experimenterId experimenter / vendor ID
+     * @return key instance
+     */
+    public static ExperimenterIdDeserializerKey createMultipartReplyVendorMessageDeserializerKey(
+            short version, long experimenterId) {
+        return new ExperimenterIdDeserializerKey(version, experimenterId, ExperimenterDataOfChoice.class);
     }
 
     /**
index 1b422d313166a51e469c9753a82175ebbebaaf14..a8cc83682a7d32bcc7d9641c917ded62a28e71aa 100644 (file)
@@ -11,84 +11,111 @@ package org.opendaylight.openflowjava.util;
 import org.junit.Assert;
 import org.junit.Test;
 import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdDeserializerKey;
+import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdTypeDeserializerKey;
 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandExperimenterCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyExperimenterCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueueProperty;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeatureProperties;
 
 /**
  * @author michal.polkorab
- *
  */
 public class ExperimenterDeserializerKeyFactoryTest {
 
-    /**
-     * Test ExperimenterDeserializerKeyFactory key creation
-     */
     @Test
-    public void test() {
-        ExperimenterIdDeserializerKey createdKey = ExperimenterDeserializerKeyFactory
+    public void testCreateExperimenterErrorDeserializerKey() throws Exception {
+        ExperimenterIdDeserializerKey createdKey;
+        ExperimenterIdDeserializerKey comparationKey;
+
+        createdKey = ExperimenterDeserializerKeyFactory
                 .createExperimenterErrorDeserializerKey(EncodeConstants.OF10_VERSION_ID, 42L);
-        ExperimenterIdDeserializerKey comparationKey =
-                new ExperimenterIdDeserializerKey(EncodeConstants.OF10_VERSION_ID, 42L, ErrorMessage.class);
-        Assert.assertEquals("Wrong key created", comparationKey, createdKey);
-        createdKey = ExperimenterDeserializerKeyFactory.createExperimenterErrorDeserializerKey(
-                EncodeConstants.OF10_VERSION_ID, null);
-        comparationKey = new ExperimenterIdDeserializerKey(EncodeConstants.OF10_VERSION_ID,
-                null, ErrorMessage.class);
-        Assert.assertEquals("Wrong key created", comparationKey, createdKey);
-        createdKey = ExperimenterDeserializerKeyFactory.createExperimenterMessageDeserializerKey(
-                EncodeConstants.OF10_VERSION_ID, 43L);
-        comparationKey = new ExperimenterIdDeserializerKey(EncodeConstants.OF10_VERSION_ID,
-                43L, ExperimenterMessage.class);
+        comparationKey = new ExperimenterIdDeserializerKey(EncodeConstants.OF10_VERSION_ID, 42L, ErrorMessage.class);
         Assert.assertEquals("Wrong key created", comparationKey, createdKey);
+    }
+
+    @Test
+    public void testCreateExperimenterMessageDeserializerKey() throws Exception {
+        ExperimenterIdDeserializerKey createdKey;
+        ExperimenterIdDeserializerKey comparationKey;
+
         createdKey = ExperimenterDeserializerKeyFactory.createExperimenterMessageDeserializerKey(
-                EncodeConstants.OF10_VERSION_ID, null);
-        comparationKey = new ExperimenterIdDeserializerKey(EncodeConstants.OF10_VERSION_ID,
-                null, ExperimenterMessage.class);
-        Assert.assertEquals("Wrong key created", comparationKey, createdKey);
-        createdKey = ExperimenterDeserializerKeyFactory.createMeterBandDeserializerKey(
-                EncodeConstants.OF10_VERSION_ID, 44L);
-        comparationKey = new ExperimenterIdDeserializerKey(EncodeConstants.OF10_VERSION_ID,
-                44L, MeterBandExperimenterCase.class);
-        Assert.assertEquals("Wrong key created", comparationKey, createdKey);
-        createdKey = ExperimenterDeserializerKeyFactory.createMeterBandDeserializerKey(
-                EncodeConstants.OF10_VERSION_ID, null);
-        comparationKey = new ExperimenterIdDeserializerKey(EncodeConstants.OF10_VERSION_ID,
-                null, MeterBandExperimenterCase.class);
+                EncodeConstants.OF10_VERSION_ID, 43L, 1L);
+        comparationKey = new ExperimenterIdTypeDeserializerKey(EncodeConstants.OF10_VERSION_ID,
+                43L, 1L, ExperimenterDataOfChoice.class);
         Assert.assertEquals("Wrong key created", comparationKey, createdKey);
+    }
+
+    @Test
+    public void testCreateMultipartReplyMessageDeserializerKey() throws Exception {
+        ExperimenterIdDeserializerKey createdKey;
+        ExperimenterIdDeserializerKey comparationKey;
+
         createdKey = ExperimenterDeserializerKeyFactory.createMultipartReplyMessageDeserializerKey(
-                EncodeConstants.OF10_VERSION_ID, 45L);
+                EncodeConstants.OF10_VERSION_ID, 45L, 1L);
         comparationKey = new ExperimenterIdDeserializerKey(EncodeConstants.OF10_VERSION_ID,
-                45L, MultipartReplyExperimenterCase.class);
+                45L, ExperimenterDataOfChoice.class);
         Assert.assertEquals("Wrong key created", comparationKey, createdKey);
-        createdKey = ExperimenterDeserializerKeyFactory.createMultipartReplyMessageDeserializerKey(
-                EncodeConstants.OF10_VERSION_ID, null);
+    }
+
+    @Test
+    public void testCreateMultipartReplyTFDeserializerKey() throws Exception {
+        ExperimenterIdDeserializerKey createdKey;
+        ExperimenterIdDeserializerKey comparationKey;
+
+        createdKey = ExperimenterDeserializerKeyFactory.createMultipartReplyTFDeserializerKey(
+                EncodeConstants.OF10_VERSION_ID, 46L);
         comparationKey = new ExperimenterIdDeserializerKey(EncodeConstants.OF10_VERSION_ID,
-                null, MultipartReplyExperimenterCase.class);
+                46L, TableFeatureProperties.class);
         Assert.assertEquals("Wrong key created", comparationKey, createdKey);
-        createdKey = ExperimenterDeserializerKeyFactory.createMultipartReplyTFDeserializerKey(
-                EncodeConstants.OF10_VERSION_ID, null);
+    }
+
+    @Test
+    public void testCreateQueuePropertyDeserializerKey() throws Exception {
+        ExperimenterIdDeserializerKey createdKey;
+        ExperimenterIdDeserializerKey comparationKey;
+
+        createdKey = ExperimenterDeserializerKeyFactory.createQueuePropertyDeserializerKey(
+                EncodeConstants.OF10_VERSION_ID, 47L);
         comparationKey = new ExperimenterIdDeserializerKey(EncodeConstants.OF10_VERSION_ID,
-                null, TableFeatureProperties.class);
+                47L, QueueProperty.class);
         Assert.assertEquals("Wrong key created", comparationKey, createdKey);
-        createdKey = ExperimenterDeserializerKeyFactory.createMultipartReplyTFDeserializerKey(
-                EncodeConstants.OF10_VERSION_ID, null);
+    }
+
+    @Test
+    public void testCreateMeterBandDeserializerKey() throws Exception {
+        ExperimenterIdDeserializerKey createdKey;
+        ExperimenterIdDeserializerKey comparationKey;
+
+        createdKey = ExperimenterDeserializerKeyFactory.createMeterBandDeserializerKey(
+                EncodeConstants.OF10_VERSION_ID, 44L);
         comparationKey = new ExperimenterIdDeserializerKey(EncodeConstants.OF10_VERSION_ID,
-                null, TableFeatureProperties.class);
+                44L, MeterBandExperimenterCase.class);
         Assert.assertEquals("Wrong key created", comparationKey, createdKey);
-        createdKey = ExperimenterDeserializerKeyFactory.createQueuePropertyDeserializerKey(
-                EncodeConstants.OF10_VERSION_ID, null);
+    }
+
+    @Test
+    public void testCreateVendorMessageDeserializerKey() throws Exception {
+        ExperimenterIdDeserializerKey createdKey;
+        ExperimenterIdDeserializerKey comparationKey;
+
+        createdKey = ExperimenterDeserializerKeyFactory.createVendorMessageDeserializerKey(
+                EncodeConstants.OF10_VERSION_ID, 43L);
         comparationKey = new ExperimenterIdDeserializerKey(EncodeConstants.OF10_VERSION_ID,
-                null, QueueProperty.class);
+                43L, ExperimenterDataOfChoice.class);
         Assert.assertEquals("Wrong key created", comparationKey, createdKey);
-        createdKey = ExperimenterDeserializerKeyFactory.createQueuePropertyDeserializerKey(
-                EncodeConstants.OF10_VERSION_ID, null);
+    }
+
+    @Test
+    public void testCreateMultipartReplyVendorMessageDeserializerKey() throws Exception {
+        ExperimenterIdDeserializerKey createdKey;
+        ExperimenterIdDeserializerKey comparationKey;
+
+        createdKey = ExperimenterDeserializerKeyFactory.createMultipartReplyVendorMessageDeserializerKey(
+                EncodeConstants.OF10_VERSION_ID, 43L);
         comparationKey = new ExperimenterIdDeserializerKey(EncodeConstants.OF10_VERSION_ID,
-                null, QueueProperty.class);
+                43L, ExperimenterDataOfChoice.class);
         Assert.assertEquals("Wrong key created", comparationKey, createdKey);
     }
 }
\ No newline at end of file