2 * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
11 import io.netty.buffer.ByteBuf;
13 import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;
14 import org.opendaylight.openflowjava.protocol.impl.util.ActionsSerializer;
15 import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput;
19 * Translates PacketOut messages
20 * @author michal.polkorab
21 * @author timotej.kubas
23 public class PacketOutInputMessageFactory implements OFSerializer<PacketOutInput>{
25 /** Code type of PacketOut message */
26 public static final byte MESSAGE_TYPE = 13;
27 private static final int MESSAGE_LENGTH = 24;
28 private static final byte PADDING_IN_PACKET_OUT_MESSAGE = 6;
29 private static PacketOutInputMessageFactory instance;
31 private PacketOutInputMessageFactory() {
32 // do nothing, just singleton
36 * @return singleton factory
38 public static synchronized PacketOutInputMessageFactory getInstance() {
39 if (instance == null) {
40 instance = new PacketOutInputMessageFactory();
46 public void messageToBuffer(short version, ByteBuf out,
47 PacketOutInput message) {
48 ByteBufUtils.writeOFHeader(instance, message, out);
49 out.writeInt(message.getBufferId().intValue());
50 out.writeInt(message.getInPort().getValue().intValue());
51 out.writeShort(ActionsSerializer.computeLengthOfActions(message.getActionsList()));
52 ByteBufUtils.padBuffer(PADDING_IN_PACKET_OUT_MESSAGE, out);
53 ActionsSerializer.encodeActions(message.getActionsList(), out);
54 byte[] data = message.getData();
61 public int computeLength(PacketOutInput message) {
62 int length = MESSAGE_LENGTH;
63 length += ActionsSerializer.computeLengthOfActions(message.getActionsList());
64 byte[] data = message.getData();
66 length += data.length;
72 public byte getMessageType() {