Add bundle control and ONF experimenter error deserializers
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / util / CodeKeyMakerFactory.java
index f4002122b667e5dcdfd69fcc978b6cdcb9dfa957..ba692c8f81a629692b08d43e522c686e258a2cf8 100644 (file)
@@ -1,72 +1,93 @@
-/*\r
- * Copyright (c) 2013 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.util;\r
-\r
-import io.netty.buffer.ByteBuf;\r
-\r
-import org.opendaylight.openflowjava.protocol.api.extensibility.EnhancedMessageCodeKey;\r
-import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;\r
-\r
-/**\r
- * @author michal.polkorab\r
- *\r
- */\r
-public abstract class CodeKeyMakerFactory {\r
-\r
-    /**\r
-     * @param version\r
-     * @return\r
-     */\r
-    public static CodeKeyMaker createMatchEntriesKeyMaker(short version) {\r
-        return new AbstractCodeKeyMaker(version) {\r
-            @Override\r
-            public MessageCodeKey make(ByteBuf input) {\r
-                int oxmClass = input.getUnsignedShort(input.readerIndex());\r
-                int oxmField = input.getUnsignedByte(input.readerIndex()\r
-                        + EncodeConstants.SIZE_OF_SHORT_IN_BYTES) >>> 1;\r
-                return new EnhancedMessageCodeKey(getVersion(), oxmClass,\r
-                        oxmField, MatchEntries.class);\r
-            }\r
-        };\r
-    }\r
-\r
-    /**\r
-     * @param version\r
-     * @return\r
-     */\r
-    public static CodeKeyMaker createActionsKeyMaker(short version) {\r
-        return new AbstractCodeKeyMaker(version) {\r
-            @Override\r
-            public MessageCodeKey make(ByteBuf input) {\r
-                // EncodeConstants.EMPTY_VALUE used as temporary value\r
-                // until action deserializers are split\r
-//                int type = input.getUnsignedShort(input.readerIndex());\r
-//                return new MessageCodeKey(getVersion(), type, Action.class);\r
-                return new MessageCodeKey(getVersion(), EncodeConstants.EMPTY_VALUE, Action.class);\r
-            }\r
-        };\r
-    }\r
-\r
-    /**\r
-     * @param version\r
-     * @return\r
-     */\r
-    public static CodeKeyMaker createInstructionsKeyMaker(short version) {\r
-        return new AbstractCodeKeyMaker(version) {\r
-            @Override\r
-            public MessageCodeKey make(ByteBuf input) {\r
-                int type = input.getUnsignedShort(input.readerIndex());\r
-                return new MessageCodeKey(getVersion(), type, Instruction.class);\r
-            }\r
-        };\r
-    }\r
-}\r
+/*
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowjava.protocol.impl.util;
+
+import io.netty.buffer.ByteBuf;
+
+import org.opendaylight.openflowjava.protocol.api.keys.ActionDeserializerKey;
+import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterActionDeserializerKey;
+import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterInstructionDeserializerKey;
+import org.opendaylight.openflowjava.protocol.api.keys.InstructionDeserializerKey;
+import org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey;
+import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+
+/**
+ * @author michal.polkorab
+ *
+ */
+public abstract class CodeKeyMakerFactory {
+
+    private CodeKeyMakerFactory() {
+        //not called
+    }
+    /**
+     * @param version
+     * @return
+     */
+    public static CodeKeyMaker createMatchEntriesKeyMaker(short version) {
+        return new AbstractCodeKeyMaker(version) {
+            @Override
+            public MessageCodeKey make(ByteBuf input) {
+                int oxmClass = input.getUnsignedShort(input.readerIndex());
+                int oxmField = input.getUnsignedByte(input.readerIndex()
+                        + EncodeConstants.SIZE_OF_SHORT_IN_BYTES) >>> 1;
+                MatchEntryDeserializerKey key = new MatchEntryDeserializerKey(getVersion(),
+                        oxmClass, oxmField);
+                if (oxmClass == EncodeConstants.EXPERIMENTER_VALUE) {
+                    long expId = input.getUnsignedInt(input.readerIndex() + EncodeConstants.SIZE_OF_SHORT_IN_BYTES
+                            + 2 * EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
+                    key.setExperimenterId(expId);
+                    return key;
+                }
+                key.setExperimenterId(null);
+                return key;
+            }
+        };
+    }
+
+    /**
+     * @param version
+     * @return
+     */
+    public static CodeKeyMaker createActionsKeyMaker(short version) {
+        return new AbstractCodeKeyMaker(version) {
+            @Override
+            public MessageCodeKey make(ByteBuf input) {
+                int type = input.getUnsignedShort(input.readerIndex());
+                if (type == EncodeConstants.EXPERIMENTER_VALUE) {
+                    Long expId = input.getUnsignedInt(input.readerIndex()
+                            + 2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
+                    return new ExperimenterActionDeserializerKey(getVersion(), expId);
+                }
+                ActionDeserializerKey actionDeserializerKey = new ActionDeserializerKey(getVersion(), type, null);
+                return actionDeserializerKey;
+            }
+        };
+    }
+
+    /**
+     * @param version
+     * @return
+     */
+    public static CodeKeyMaker createInstructionsKeyMaker(short version) {
+        return new AbstractCodeKeyMaker(version) {
+            @Override
+            public MessageCodeKey make(ByteBuf input) {
+                int type = input.getUnsignedShort(input.readerIndex());
+                if (type == EncodeConstants.EXPERIMENTER_VALUE) {
+                    Long expId = input.getUnsignedInt(input.readerIndex()
+                            + 2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
+                    return new ExperimenterInstructionDeserializerKey(getVersion(), expId);
+                }
+                return new InstructionDeserializerKey(getVersion(), type, null);
+            }
+        };
+    }
+}