Javadoc update
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / OF10PacketOutInputMessageFactory.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.ByteBufUtils;\r
8 import org.opendaylight.openflowjava.protocol.impl.util.OF10ActionsSerializer;\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  */\r
15 public class OF10PacketOutInputMessageFactory implements OFSerializer<PacketOutInput> {\r
16 \r
17     private static final byte MESSAGE_TYPE = 13;\r
18     private static final int MESSAGE_LENGTH = 16;\r
19     \r
20     private static OF10PacketOutInputMessageFactory instance;\r
21     \r
22     private OF10PacketOutInputMessageFactory() {\r
23         // do nothing, just singleton\r
24     }\r
25     \r
26     /**\r
27      * @return singleton factory\r
28      */\r
29     public static synchronized OF10PacketOutInputMessageFactory getInstance() {\r
30         if (instance == null) {\r
31             instance = new OF10PacketOutInputMessageFactory();\r
32         }\r
33         return instance;\r
34     }\r
35     \r
36     @Override\r
37     public void messageToBuffer(short version, ByteBuf out,\r
38             PacketOutInput message) {\r
39         ByteBufUtils.writeOFHeader(instance, message, out);\r
40         out.writeInt(message.getBufferId().intValue());\r
41         out.writeShort(message.getInPort().getValue().intValue());\r
42         out.writeShort(OF10ActionsSerializer.computeActionsLength(message.getActionsList()));\r
43         OF10ActionsSerializer.encodeActionsV10(out, message.getActionsList());\r
44         byte[] data = message.getData();\r
45         if (data != null) {\r
46             out.writeBytes(data);\r
47         }\r
48     }\r
49 \r
50     @Override\r
51     public int computeLength(PacketOutInput message) {\r
52         int length = MESSAGE_LENGTH + OF10ActionsSerializer.computeActionsLength(message.getActionsList());\r
53         byte[] data = message.getData();\r
54         if (data != null) {\r
55             length += data.length;\r
56         }\r
57         return length;\r
58     }\r
59 \r
60     @Override\r
61     public byte getMessageType() {\r
62         return MESSAGE_TYPE;\r
63     }\r
64 \r
65 }\r