Javadoc update
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / PacketOutInputMessageFactory.java
1 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
2 package org.opendaylight.openflowjava.protocol.impl.serialization.factories;\r
3 \r
4 import io.netty.buffer.ByteBuf;\r
5 \r
6 import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;\r
7 import org.opendaylight.openflowjava.protocol.impl.util.ActionsSerializer;\r
8 import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
9 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput;\r
10 \r
11 /**\r
12  * Translates PacketOut messages\r
13  * @author michal.polkorab\r
14  * @author timotej.kubas\r
15  */\r
16 public class PacketOutInputMessageFactory implements OFSerializer<PacketOutInput>{\r
17 \r
18     /** Code type of PacketOut message */\r
19     public static final byte MESSAGE_TYPE = 13;\r
20     private static final int MESSAGE_LENGTH = 24;\r
21     private static final byte PADDING_IN_PACKET_OUT_MESSAGE = 6;\r
22     private static PacketOutInputMessageFactory instance;\r
23     \r
24     private PacketOutInputMessageFactory() {\r
25         // do nothing, just singleton\r
26     }\r
27     \r
28     /**\r
29      * @return singleton factory\r
30      */\r
31     public static synchronized PacketOutInputMessageFactory getInstance() {\r
32         if (instance == null) {\r
33             instance = new PacketOutInputMessageFactory();\r
34         }\r
35         return instance;\r
36     }\r
37     \r
38     @Override\r
39     public void messageToBuffer(short version, ByteBuf out,\r
40             PacketOutInput message) {\r
41         ByteBufUtils.writeOFHeader(instance, message, out);\r
42         out.writeInt(message.getBufferId().intValue());\r
43         out.writeInt(message.getInPort().getValue().intValue());\r
44         out.writeShort(ActionsSerializer.computeLengthOfActions(message.getActionsList()));\r
45         ByteBufUtils.padBuffer(PADDING_IN_PACKET_OUT_MESSAGE, out);\r
46         ActionsSerializer.encodeActions(message.getActionsList(), out);\r
47         byte[] data = message.getData();\r
48         if (data != null) {\r
49             out.writeBytes(data);\r
50         }\r
51     }\r
52 \r
53     @Override\r
54     public int computeLength(PacketOutInput message) {\r
55         int length = MESSAGE_LENGTH;\r
56         length += ActionsSerializer.computeLengthOfActions(message.getActionsList());\r
57         byte[] data = message.getData();\r
58         if (data != null) {\r
59             length += data.length;\r
60         }\r
61         return length;\r
62     }\r
63 \r
64     @Override\r
65     public byte getMessageType() {\r
66         return MESSAGE_TYPE;\r
67     }\r
68 \r
69 }\r