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.api.extensibility.OFDeserializer;
16 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder;
22 * Translates FeaturesReply messages
23 * @author michal.polkorab
24 * @author timotej.kubas
26 public class FeaturesReplyMessageFactory implements OFDeserializer<GetFeaturesOutput>{
28 private static final byte PADDING_IN_FEATURES_REPLY_HEADER = 2;
31 public GetFeaturesOutput deserialize(ByteBuf rawMessage) {
32 GetFeaturesOutputBuilder builder = new GetFeaturesOutputBuilder();
33 builder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
34 builder.setXid(rawMessage.readUnsignedInt());
35 byte[] datapathId = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
36 rawMessage.readBytes(datapathId);
37 builder.setDatapathId(new BigInteger(1, datapathId));
38 builder.setBuffers(rawMessage.readUnsignedInt());
39 builder.setTables(rawMessage.readUnsignedByte());
40 builder.setAuxiliaryId(rawMessage.readUnsignedByte());
41 rawMessage.skipBytes(PADDING_IN_FEATURES_REPLY_HEADER);
42 builder.setCapabilities(createCapabilities(rawMessage.readUnsignedInt()));
43 builder.setReserved(rawMessage.readUnsignedInt());
44 return builder.build();
47 private static Capabilities createCapabilities(long input) {
48 final Boolean flowStats = (input & (1 << 0)) != 0;
49 final Boolean tableStats = (input & (1 << 1)) != 0;
50 final Boolean portStats = (input & (1 << 2)) != 0;
51 final Boolean groupStats = (input & (1 << 3)) != 0;
52 final Boolean ipReasm = (input & (1 << 5)) != 0;
53 final Boolean queueStats = (input & (1 << 6)) != 0;
54 final Boolean portBlocked = (input & (1 << 8)) != 0;
55 return new Capabilities(flowStats, groupStats, ipReasm,
56 portBlocked, portStats, queueStats, tableStats);