X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflow-protocol-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowjava%2Fprotocol%2Fimpl%2Fdeserialization%2Ffactories%2FPacketInMessageFactory.java;h=44679569d44ec2eaef87abfd0626b37feb8901c4;hb=29a2a074c78708f6d18583779ece96bb6573f0c6;hp=ba84fe8667ba7ebf5023ad692b058af27ef6fd34;hpb=41e008a8af2f5ee6134a59391235c145a2b27fc1;p=openflowjava.git diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactory.java index ba84fe86..44679569 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactory.java @@ -1,54 +1,62 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; import io.netty.buffer.ByteBuf; import java.math.BigInteger; -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; -import org.opendaylight.openflowjava.protocol.impl.util.MatchDeserializer; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry; +import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistryInjector; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder; /** + * Translates PacketIn messages * @author michal.polkorab * @author timotej.kubas */ -public class PacketInMessageFactory implements OFDeserializer { +public class PacketInMessageFactory implements OFDeserializer, + DeserializerRegistryInjector { - private static PacketInMessageFactory instance; private static final byte PADDING_IN_PACKET_IN_HEADER = 2; - - private PacketInMessageFactory() { - // Singleton - } - - /** - * @return singleton factory - */ - public static synchronized PacketInMessageFactory getInstance(){ - if(instance == null){ - instance = new PacketInMessageFactory(); - } - return instance; - } + private static final MessageCodeKey MATCH_KEY = new MessageCodeKey( + EncodeConstants.OF13_VERSION_ID, EncodeConstants.EMPTY_VALUE, Match.class); + private DeserializerRegistry registry; @Override - public PacketInMessage bufferToMessage(ByteBuf rawMessage, short version) { + public PacketInMessage deserialize(final ByteBuf rawMessage) { PacketInMessageBuilder builder = new PacketInMessageBuilder(); - builder.setVersion(version); + builder.setVersion((short) EncodeConstants.OF13_VERSION_ID); builder.setXid(rawMessage.readUnsignedInt()); builder.setBufferId(rawMessage.readUnsignedInt()); builder.setTotalLen(rawMessage.readUnsignedShort()); - builder.setReason(rawMessage.readUnsignedByte()); + builder.setReason(PacketInReason.forValue(rawMessage.readUnsignedByte())); builder.setTableId(new TableId((long)rawMessage.readUnsignedByte())); - byte[] cookie = new byte[Long.SIZE/Byte.SIZE]; + byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; rawMessage.readBytes(cookie); - builder.setCookie(new BigInteger(cookie)); - builder.setMatch(MatchDeserializer.createMatch(rawMessage)); + builder.setCookie(new BigInteger(1, cookie)); + OFDeserializer matchDeserializer = registry.getDeserializer(MATCH_KEY); + builder.setMatch(matchDeserializer.deserialize(rawMessage)); rawMessage.skipBytes(PADDING_IN_PACKET_IN_HEADER); builder.setData(rawMessage.readBytes(rawMessage.readableBytes()).array()); return builder.build(); } + + @Override + public void injectDeserializerRegistry(final DeserializerRegistry deserializerRegistry) { + registry = deserializerRegistry; + } }