Updated extension registration keys
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / PacketOutInputMessageFactory.java
1 /*
2  * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
10
11 import io.netty.buffer.ByteBuf;
12
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.util.ByteBufUtils;
17 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
18 import org.opendaylight.openflowjava.protocol.impl.util.TypeKeyMakerFactory;
19 import org.opendaylight.openflowjava.protocol.impl.util.ListSerializer;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput;
21
22 /**
23  * Translates PacketOut messages
24  * @author michal.polkorab
25  * @author timotej.kubas
26  */
27 public class PacketOutInputMessageFactory implements OFSerializer<PacketOutInput>, SerializerRegistryInjector {
28
29     /** Code type of PacketOut message */
30     private static final byte MESSAGE_TYPE = 13;
31     private static final byte PADDING_IN_PACKET_OUT_MESSAGE = 6;
32     private SerializerRegistry registry;
33
34     @Override
35     public void serialize(PacketOutInput message, ByteBuf outBuffer) {
36         ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
37         outBuffer.writeInt(message.getBufferId().intValue());
38         outBuffer.writeInt(message.getInPort().getValue().intValue());
39         int actionsLengthIndex = outBuffer.writerIndex();
40         outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH);
41         ByteBufUtils.padBuffer(PADDING_IN_PACKET_OUT_MESSAGE, outBuffer);
42         int actionsStartIndex = outBuffer.writerIndex();
43         ListSerializer.serializeList(message.getAction(), TypeKeyMakerFactory
44                 .createActionKeyMaker(EncodeConstants.OF13_VERSION_ID), registry, outBuffer);
45         outBuffer.setShort(actionsLengthIndex, outBuffer.writerIndex() - actionsStartIndex);
46         byte[] data = message.getData();
47         if (data != null) {
48             outBuffer.writeBytes(data);
49         }
50         ByteBufUtils.updateOFHeaderLength(outBuffer);
51     }
52
53     @Override
54     public void injectSerializerRegistry(SerializerRegistry serializerRegistry) {
55         this.registry = serializerRegistry;
56     }
57
58 }