1 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */
\r
2 package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
\r
4 import io.netty.buffer.ByteBuf;
\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
12 * Translates PacketOut messages
\r
13 * @author michal.polkorab
\r
14 * @author timotej.kubas
\r
16 public class PacketOutInputMessageFactory implements OFSerializer<PacketOutInput>{
\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
24 private PacketOutInputMessageFactory() {
\r
25 // do nothing, just singleton
\r
29 * @return singleton factory
\r
31 public static synchronized PacketOutInputMessageFactory getInstance() {
\r
32 if (instance == null) {
\r
33 instance = new PacketOutInputMessageFactory();
\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
49 out.writeBytes(data);
\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
59 length += data.length;
\r
65 public byte getMessageType() {
\r
66 return MESSAGE_TYPE;
\r