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.api.extensibility.OFSerializer;
14 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
15 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector;
16 import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
17 import org.opendaylight.openflowjava.protocol.impl.util.CodingUtils;
18 import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput;
22 * Translates PacketOut messages
23 * @author michal.polkorab
24 * @author timotej.kubas
26 public class PacketOutInputMessageFactory implements OFSerializer<PacketOutInput>, SerializerRegistryInjector {
28 /** Code type of PacketOut message */
29 private static final byte MESSAGE_TYPE = 13;
30 private static final byte PADDING_IN_PACKET_OUT_MESSAGE = 6;
31 private SerializerRegistry registry;
34 public void serialize(PacketOutInput message, ByteBuf outBuffer) {
35 ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
36 outBuffer.writeInt(message.getBufferId().intValue());
37 outBuffer.writeInt(message.getInPort().getValue().intValue());
38 int actionsLengthIndex = outBuffer.writerIndex();
39 outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH);
40 ByteBufUtils.padBuffer(PADDING_IN_PACKET_OUT_MESSAGE, outBuffer);
41 int actionsStartIndex = outBuffer.writerIndex();
42 CodingUtils.serializeActions(message.getAction(), registry,
43 outBuffer, EncodeConstants.OF13_VERSION_ID);
44 outBuffer.setShort(actionsLengthIndex, outBuffer.writerIndex() - actionsStartIndex);
45 byte[] data = message.getData();
47 outBuffer.writeBytes(data);
49 ByteBufUtils.updateOFHeaderLength(outBuffer);
53 public void injectSerializerRegistry(SerializerRegistry serializerRegistry) {
54 this.registry = serializerRegistry;