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 java.math.BigInteger;
15 import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer;
16 import org.opendaylight.openflowjava.protocol.impl.util.MatchDeserializer;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder;
23 * Translates PacketIn messages
24 * @author michal.polkorab
25 * @author timotej.kubas
27 public class PacketInMessageFactory implements OFDeserializer<PacketInMessage> {
29 private static PacketInMessageFactory instance;
30 private static final byte PADDING_IN_PACKET_IN_HEADER = 2;
32 private PacketInMessageFactory() {
37 * @return singleton factory
39 public static synchronized PacketInMessageFactory getInstance(){
41 instance = new PacketInMessageFactory();
47 public PacketInMessage bufferToMessage(ByteBuf rawMessage, short version) {
48 PacketInMessageBuilder builder = new PacketInMessageBuilder();
49 builder.setVersion(version);
50 builder.setXid(rawMessage.readUnsignedInt());
51 builder.setBufferId(rawMessage.readUnsignedInt());
52 builder.setTotalLen(rawMessage.readUnsignedShort());
53 builder.setReason(PacketInReason.forValue(rawMessage.readUnsignedByte()));
54 builder.setTableId(new TableId((long)rawMessage.readUnsignedByte()));
55 byte[] cookie = new byte[Long.SIZE/Byte.SIZE];
56 rawMessage.readBytes(cookie);
57 builder.setCookie(new BigInteger(cookie));
58 builder.setMatch(MatchDeserializer.createMatch(rawMessage));
59 rawMessage.skipBytes(PADDING_IN_PACKET_IN_HEADER);
60 builder.setData(rawMessage.readBytes(rawMessage.readableBytes()).array());
61 return builder.build();