1 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */
2 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
4 import io.netty.buffer.ByteBuf;
6 import java.math.BigInteger;
8 import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer;
9 import org.opendaylight.openflowjava.protocol.impl.util.MatchDeserializer;
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder;
15 * Translates PacketIn messages
16 * @author michal.polkorab
17 * @author timotej.kubas
19 public class PacketInMessageFactory implements OFDeserializer<PacketInMessage> {
21 private static PacketInMessageFactory instance;
22 private static final byte PADDING_IN_PACKET_IN_HEADER = 2;
24 private PacketInMessageFactory() {
29 * @return singleton factory
31 public static synchronized PacketInMessageFactory getInstance(){
33 instance = new PacketInMessageFactory();
39 public PacketInMessage bufferToMessage(ByteBuf rawMessage, short version) {
40 PacketInMessageBuilder builder = new PacketInMessageBuilder();
41 builder.setVersion(version);
42 builder.setXid(rawMessage.readUnsignedInt());
43 builder.setBufferId(rawMessage.readUnsignedInt());
44 builder.setTotalLen(rawMessage.readUnsignedShort());
45 builder.setReason(rawMessage.readUnsignedByte());
46 builder.setTableId(new TableId((long)rawMessage.readUnsignedByte()));
47 byte[] cookie = new byte[Long.SIZE/Byte.SIZE];
48 rawMessage.readBytes(cookie);
49 builder.setCookie(new BigInteger(cookie));
50 builder.setMatch(MatchDeserializer.createMatch(rawMessage));
51 rawMessage.skipBytes(PADDING_IN_PACKET_IN_HEADER);
52 builder.setData(rawMessage.readBytes(rawMessage.readableBytes()).array());
53 return builder.build();