Bug 2756 - Match model update
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / OF10FlowRemovedMessageFactory.java
index b25b993a98e475432dbdae30e3268c5ba0ef58d8..b110e2d5a0f1f9229258590bc8c7447c939e29e3 100644 (file)
@@ -1,66 +1,67 @@
-/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
-package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;\r
-\r
-import io.netty.buffer.ByteBuf;\r
-\r
-import java.math.BigInteger;\r
-\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer;\r
-import org.opendaylight.openflowjava.protocol.impl.util.OF10MatchDeserializer;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason;\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.FlowRemovedMessageBuilder;\r
-\r
-/**\r
- * Translates FlowRemoved messages (OpenFlow v1.0)\r
- * @author michal.polkorab\r
- */\r
-public class OF10FlowRemovedMessageFactory implements OFDeserializer<FlowRemovedMessage> {\r
-\r
-    private static final byte PADDING_IN_FLOW_REMOVED_MESSAGE = 1;\r
-    private static final byte PADDING_IN_FLOW_REMOVED_MESSAGE_2 = 2;\r
-    \r
-    \r
-    private static OF10FlowRemovedMessageFactory instance;\r
-    \r
-    private OF10FlowRemovedMessageFactory() {\r
-        // singleton\r
-    }\r
-    \r
-    /**\r
-     * @return singleton factory\r
-     */\r
-    public static synchronized OF10FlowRemovedMessageFactory getInstance(){\r
-        if(instance == null){\r
-            instance = new OF10FlowRemovedMessageFactory();\r
-        }\r
-        return instance;\r
-    }\r
-\r
-    @Override\r
-    public FlowRemovedMessage bufferToMessage(ByteBuf rawMessage, short version) {\r
-        FlowRemovedMessageBuilder builder = new FlowRemovedMessageBuilder();\r
-        builder.setVersion(version);\r
-        builder.setXid(rawMessage.readUnsignedInt());\r
-        builder.setMatchV10(OF10MatchDeserializer.createMatchV10(rawMessage));\r
-        byte[] cookie = new byte[Long.SIZE/Byte.SIZE];\r
-        rawMessage.readBytes(cookie);\r
-        builder.setCookie(new BigInteger(cookie));\r
-        builder.setPriority(rawMessage.readUnsignedShort());\r
-        builder.setReason(FlowRemovedReason.forValue(rawMessage.readUnsignedByte()));\r
-        rawMessage.skipBytes(PADDING_IN_FLOW_REMOVED_MESSAGE);\r
-        builder.setDurationSec(rawMessage.readUnsignedInt());\r
-        builder.setDurationNsec(rawMessage.readUnsignedInt());\r
-        builder.setIdleTimeout(rawMessage.readUnsignedShort());\r
-        rawMessage.skipBytes(PADDING_IN_FLOW_REMOVED_MESSAGE_2);\r
-        byte[] packet_count = new byte[Long.SIZE/Byte.SIZE];\r
-        rawMessage.readBytes(packet_count);\r
-        builder.setPacketCount(new BigInteger(packet_count));\r
-        byte[] byte_count = new byte[Long.SIZE/Byte.SIZE];\r
-        rawMessage.readBytes(byte_count);\r
-        builder.setByteCount(new BigInteger(byte_count));\r
-        return builder.build();\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.deserialization.factories;
+
+import io.netty.buffer.ByteBuf;
+
+import java.math.BigInteger;
+
+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.keys.MessageCodeKey;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowRemovedReason;
+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.FlowRemovedMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessageBuilder;
+
+/**
+ * Translates FlowRemoved messages (OpenFlow v1.0)
+ * @author michal.polkorab
+ */
+public class OF10FlowRemovedMessageFactory implements OFDeserializer<FlowRemovedMessage>,
+        DeserializerRegistryInjector {
+
+    private static final byte PADDING_IN_FLOW_REMOVED_MESSAGE = 1;
+    private static final byte PADDING_IN_FLOW_REMOVED_MESSAGE_2 = 2;
+    private DeserializerRegistry registry;
+
+    @Override
+    public FlowRemovedMessage deserialize(ByteBuf rawMessage) {
+        FlowRemovedMessageBuilder builder = new FlowRemovedMessageBuilder();
+        builder.setVersion((short) EncodeConstants.OF10_VERSION_ID);
+        builder.setXid(rawMessage.readUnsignedInt());
+        OFDeserializer<MatchV10> matchDeserializer = registry.getDeserializer(
+                new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, EncodeConstants.EMPTY_VALUE, MatchV10.class));
+        builder.setMatchV10(matchDeserializer.deserialize(rawMessage));
+        byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
+        rawMessage.readBytes(cookie);
+        builder.setCookie(new BigInteger(1, cookie));
+        builder.setPriority(rawMessage.readUnsignedShort());
+        builder.setReason(FlowRemovedReason.forValue(rawMessage.readUnsignedByte()));
+        rawMessage.skipBytes(PADDING_IN_FLOW_REMOVED_MESSAGE);
+        builder.setDurationSec(rawMessage.readUnsignedInt());
+        builder.setDurationNsec(rawMessage.readUnsignedInt());
+        builder.setIdleTimeout(rawMessage.readUnsignedShort());
+        rawMessage.skipBytes(PADDING_IN_FLOW_REMOVED_MESSAGE_2);
+        byte[] packetCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
+        rawMessage.readBytes(packetCount);
+        builder.setPacketCount(new BigInteger(1, packetCount));
+        byte[] byteCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
+        rawMessage.readBytes(byteCount);
+        builder.setByteCount(new BigInteger(1, byteCount));
+        return builder.build();
+    }
+
+    @Override
+    public void injectDeserializerRegistry(DeserializerRegistry deserializerRegistry) {
+        registry = deserializerRegistry;
+    }
+}