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