Bug 2756 - Action model update
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / OF10PacketInMessageFactory.java
index 5ad3efcb567609e9d0f5033ba6473dacd301843b..3de0288bb7aa924c32649b61c23738f416326f9d 100644 (file)
@@ -1,50 +1,43 @@
-/* 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 org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder;\r
-\r
-/**\r
- * Translates PacketIn messages (OpenFlow v1.0)\r
- * @author michal.polkorab\r
- */\r
-public class OF10PacketInMessageFactory implements OFDeserializer<PacketInMessage> {\r
-\r
-    private static final byte PADDING_IN_PACKET_IN_HEADER = 1;\r
-\r
-    private static OF10PacketInMessageFactory instance;\r
-    \r
-    private OF10PacketInMessageFactory() {\r
-        // Singleton\r
-    }\r
-    \r
-    /**\r
-     * @return singleton factory\r
-     */\r
-    public static synchronized OF10PacketInMessageFactory getInstance(){\r
-        if(instance == null){\r
-            instance = new OF10PacketInMessageFactory();\r
-        }\r
-        return instance;\r
-    }\r
-\r
-    @Override\r
-    public PacketInMessage bufferToMessage(ByteBuf rawMessage, short version) {\r
-        PacketInMessageBuilder builder = new PacketInMessageBuilder();\r
-        builder.setVersion(version);\r
-        builder.setXid(rawMessage.readUnsignedInt());\r
-        builder.setBufferId(rawMessage.readUnsignedInt());\r
-        builder.setTotalLen(rawMessage.readUnsignedShort());\r
-        builder.setInPort(rawMessage.readUnsignedShort());\r
-        builder.setReason(rawMessage.readUnsignedByte());\r
-        rawMessage.skipBytes(PADDING_IN_PACKET_IN_HEADER);\r
-        int remainingBytes = rawMessage.readableBytes();\r
-        if (remainingBytes > 0) {\r
-            builder.setData(rawMessage.readBytes(remainingBytes).array());\r
-        }\r
-        return builder.build();\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 org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder;
+
+/**
+ * Translates PacketIn messages (OpenFlow v1.0)
+ * @author michal.polkorab
+ */
+public class OF10PacketInMessageFactory implements OFDeserializer<PacketInMessage> {
+
+    private static final byte PADDING_IN_PACKET_IN_HEADER = 1;
+
+    @Override
+    public PacketInMessage deserialize(ByteBuf rawMessage) {
+        PacketInMessageBuilder builder = new PacketInMessageBuilder();
+        builder.setVersion((short) EncodeConstants.OF10_VERSION_ID);
+        builder.setXid(rawMessage.readUnsignedInt());
+        builder.setBufferId(rawMessage.readUnsignedInt());
+        builder.setTotalLen(rawMessage.readUnsignedShort());
+        builder.setInPort(rawMessage.readUnsignedShort());
+        builder.setReason(PacketInReason.forValue(rawMessage.readUnsignedByte()));
+        rawMessage.skipBytes(PADDING_IN_PACKET_IN_HEADER);
+        int remainingBytes = rawMessage.readableBytes();
+        if (remainingBytes > 0) {
+            builder.setData(rawMessage.readBytes(remainingBytes).array());
+        }
+        return builder.build();
+    }
+}