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.impl.deserialization.OFDeserializer;
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;
26 private static OF10PacketInMessageFactory instance;
28 private OF10PacketInMessageFactory() {
33 * @return singleton factory
35 public static synchronized OF10PacketInMessageFactory getInstance(){
37 instance = new OF10PacketInMessageFactory();
43 public PacketInMessage bufferToMessage(ByteBuf rawMessage, short version) {
44 PacketInMessageBuilder builder = new PacketInMessageBuilder();
45 builder.setVersion(version);
46 builder.setXid(rawMessage.readUnsignedInt());
47 builder.setBufferId(rawMessage.readUnsignedInt());
48 builder.setTotalLen(rawMessage.readUnsignedShort());
49 builder.setInPort(rawMessage.readUnsignedShort());
50 builder.setReason(PacketInReason.forValue(rawMessage.readUnsignedByte()));
51 rawMessage.skipBytes(PADDING_IN_PACKET_IN_HEADER);
52 int remainingBytes = rawMessage.readableBytes();
53 if (remainingBytes > 0) {
54 builder.setData(rawMessage.readBytes(remainingBytes).array());
56 return builder.build();