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.deserialization.factories;
11 import io.netty.buffer.ByteBuf;
13 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
14 import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder;
20 * Translates PacketIn messages (OpenFlow v1.0)
21 * @author michal.polkorab
23 public class OF10PacketInMessageFactory implements OFDeserializer<PacketInMessage> {
25 private static final byte PADDING_IN_PACKET_IN_HEADER = 1;
28 public PacketInMessage deserialize(ByteBuf rawMessage) {
29 PacketInMessageBuilder builder = new PacketInMessageBuilder();
30 builder.setVersion((short) EncodeConstants.OF10_VERSION_ID);
31 builder.setXid(rawMessage.readUnsignedInt());
32 builder.setBufferId(rawMessage.readUnsignedInt());
33 builder.setTotalLen(rawMessage.readUnsignedShort());
34 builder.setInPort(rawMessage.readUnsignedShort());
35 builder.setReason(PacketInReason.forValue(rawMessage.readUnsignedByte()));
36 rawMessage.skipBytes(PADDING_IN_PACKET_IN_HEADER);
37 int remainingBytes = rawMessage.readableBytes();
38 if (remainingBytes > 0) {
39 builder.setData(rawMessage.readBytes(remainingBytes).array());
41 return builder.build();