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%2FFeaturesReplyMessageFactory.java;h=b599c208dfb0c21db5d471d059dfd504ebac6abd;hb=5f5622e79402f70a944fa93fd7ee2d84d1776b08;hp=cb111cff0eb919867185d9f041c32804768fe10b;hpb=f7b135c5a0fab2841b445a567b27271081722984;p=openflowjava.git diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FeaturesReplyMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FeaturesReplyMessageFactory.java index cb111cff..b599c208 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FeaturesReplyMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FeaturesReplyMessageFactory.java @@ -1,58 +1,59 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -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.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder; - -/** - * @author michal.polkorab - * - */ -public class FeaturesReplyMessageFactory implements OFDeserializer{ - - private static final byte PADDING_IN_FEATURES_REPLY_HEADER = 2; - - private static FeaturesReplyMessageFactory instance; - - private FeaturesReplyMessageFactory() { - // do nothing, just singleton - } - - /** - * @return singleton factory - */ - public static FeaturesReplyMessageFactory getInstance() { - if (instance == null) { - instance = new FeaturesReplyMessageFactory(); - } - return instance; - } - - /* (non-Javadoc) - * @see org.openflow.core.deserialization.OfDeserializer#createMessage(io.netty.buffer.ByteBuf, short) - */ - @Override - public GetFeaturesOutput bufferToMessage(ByteBuf rawMessage, short version) { - GetFeaturesOutputBuilder gfob = new GetFeaturesOutputBuilder(); - gfob.setVersion(version); - gfob.setXid(rawMessage.readUnsignedInt()); - - // TODO - unsigned long - check for appropriate process - byte[] datapathId = new byte[8]; - rawMessage.readBytes(datapathId); - gfob.setDatapathId(new BigInteger(datapathId)); - gfob.setBuffers(rawMessage.readUnsignedInt()); - gfob.setTables(rawMessage.readUnsignedByte()); - gfob.setAuxiliaryId(rawMessage.readUnsignedByte()); - rawMessage.skipBytes(PADDING_IN_FEATURES_REPLY_HEADER); - gfob.setCapabilities(rawMessage.readUnsignedInt()); - gfob.setReserved(rawMessage.readUnsignedInt()); - return gfob.build(); - } - -} +/* + * 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.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder; + +/** + * Translates FeaturesReply messages + * @author michal.polkorab + * @author timotej.kubas + */ +public class FeaturesReplyMessageFactory implements OFDeserializer{ + + private static final byte PADDING_IN_FEATURES_REPLY_HEADER = 2; + + @Override + public GetFeaturesOutput deserialize(ByteBuf rawMessage) { + GetFeaturesOutputBuilder builder = new GetFeaturesOutputBuilder(); + builder.setVersion((short) EncodeConstants.OF13_VERSION_ID); + builder.setXid(rawMessage.readUnsignedInt()); + byte[] datapathId = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES]; + rawMessage.readBytes(datapathId); + builder.setDatapathId(new BigInteger(1, datapathId)); + builder.setBuffers(rawMessage.readUnsignedInt()); + builder.setTables(rawMessage.readUnsignedByte()); + builder.setAuxiliaryId(rawMessage.readUnsignedByte()); + rawMessage.skipBytes(PADDING_IN_FEATURES_REPLY_HEADER); + builder.setCapabilities(createCapabilities(rawMessage.readUnsignedInt())); + builder.setReserved(rawMessage.readUnsignedInt()); + return builder.build(); + } + + private static Capabilities createCapabilities(long input) { + final Boolean flowStats = (input & (1 << 0)) != 0; + final Boolean tableStats = (input & (1 << 1)) != 0; + final Boolean portStats = (input & (1 << 2)) != 0; + final Boolean groupStats = (input & (1 << 3)) != 0; + final Boolean ipReasm = (input & (1 << 5)) != 0; + final Boolean queueStats = (input & (1 << 6)) != 0; + final Boolean portBlocked = (input & (1 << 8)) != 0; + return new Capabilities(flowStats, groupStats, ipReasm, + portBlocked, portStats, queueStats, tableStats); + } + +}