Copyright update
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / PacketOutInputMessageFactory.java
index dd3f72b22d5703a6cc67f874fa54e2fbe68ecb96..4bdfec95ab682ec059e2658669a174779426e58e 100644 (file)
@@ -1,60 +1,76 @@
-/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
-package org.opendaylight.openflowjava.protocol.impl.serialization.factories;\r
-\r
-import io.netty.buffer.ByteBuf;\r
-\r
-import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;\r
-import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput;\r
-\r
-/**\r
- * @author michal.polkorab\r
- *\r
- */\r
-public class PacketOutInputMessageFactory implements OFSerializer<PacketOutInput>{\r
-\r
-    /** Code type of PacketOut message */\r
-    public static final byte MESSAGE_TYPE = 13;\r
-    private static final int MESSAGE_LENGTH = 30;\r
-    private static final byte PADDING_IN_PACKET_OUT_MESSAGE = 6;\r
-    private static PacketOutInputMessageFactory instance;\r
-    \r
-    private PacketOutInputMessageFactory() {\r
-        // do nothing, just singleton\r
-    }\r
-    \r
-    /**\r
-     * @return singleton factory\r
-     */\r
-    public static synchronized PacketOutInputMessageFactory getInstance() {\r
-        if (instance == null) {\r
-            instance = new PacketOutInputMessageFactory();\r
-        }\r
-        return instance;\r
-    }\r
-    \r
-    @Override\r
-    public void messageToBuffer(short version, ByteBuf out,\r
-            PacketOutInput message) {\r
-        ByteBufUtils.writeOFHeader(instance, message, out);\r
-        out.writeInt(message.getBufferId().intValue());\r
-        out.writeInt(message.getInPort().getValue().intValue());\r
-        ByteBufUtils.padBuffer(PADDING_IN_PACKET_OUT_MESSAGE, out);\r
-        // TODO - finish implementation after Action serialization is done\r
-        //out.writeShort(message.getActions().size());\r
-        // TODO - data field is not clearly defined\r
-        \r
-       \r
-    }\r
-\r
-    @Override\r
-    public int computeLength(PacketOutInput message) {\r
-        return MESSAGE_LENGTH;\r
-    }\r
-\r
-    @Override\r
-    public byte getMessageType() {\r
-        return MESSAGE_TYPE;\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.serialization.factories;
+
+import io.netty.buffer.ByteBuf;
+
+import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;
+import org.opendaylight.openflowjava.protocol.impl.util.ActionsSerializer;
+import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput;
+
+/**
+ * Translates PacketOut messages
+ * @author michal.polkorab
+ * @author timotej.kubas
+ */
+public class PacketOutInputMessageFactory implements OFSerializer<PacketOutInput>{
+
+    /** Code type of PacketOut message */
+    public static final byte MESSAGE_TYPE = 13;
+    private static final int MESSAGE_LENGTH = 24;
+    private static final byte PADDING_IN_PACKET_OUT_MESSAGE = 6;
+    private static PacketOutInputMessageFactory instance;
+    
+    private PacketOutInputMessageFactory() {
+        // do nothing, just singleton
+    }
+    
+    /**
+     * @return singleton factory
+     */
+    public static synchronized PacketOutInputMessageFactory getInstance() {
+        if (instance == null) {
+            instance = new PacketOutInputMessageFactory();
+        }
+        return instance;
+    }
+    
+    @Override
+    public void messageToBuffer(short version, ByteBuf out,
+            PacketOutInput message) {
+        ByteBufUtils.writeOFHeader(instance, message, out);
+        out.writeInt(message.getBufferId().intValue());
+        out.writeInt(message.getInPort().getValue().intValue());
+        out.writeShort(ActionsSerializer.computeLengthOfActions(message.getActionsList()));
+        ByteBufUtils.padBuffer(PADDING_IN_PACKET_OUT_MESSAGE, out);
+        ActionsSerializer.encodeActions(message.getActionsList(), out);
+        byte[] data = message.getData();
+        if (data != null) {
+            out.writeBytes(data);
+        }
+    }
+
+    @Override
+    public int computeLength(PacketOutInput message) {
+        int length = MESSAGE_LENGTH;
+        length += ActionsSerializer.computeLengthOfActions(message.getActionsList());
+        byte[] data = message.getData();
+        if (data != null) {
+            length += data.length;
+        }
+        return length;
+    }
+
+    @Override
+    public byte getMessageType() {
+        return MESSAGE_TYPE;
+    }
+
+}