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.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder;
21 * Translates FeaturesReply messages
22 * @author michal.polkorab
23 * @author timotej.kubas
25 public class FeaturesReplyMessageFactory implements OFDeserializer<GetFeaturesOutput>{
27 private static final byte PADDING_IN_FEATURES_REPLY_HEADER = 2;
29 private static FeaturesReplyMessageFactory instance;
31 private FeaturesReplyMessageFactory() {
32 // do nothing, just singleton
36 * @return singleton factory
38 public static synchronized FeaturesReplyMessageFactory getInstance() {
39 if (instance == null) {
40 instance = new FeaturesReplyMessageFactory();
46 public GetFeaturesOutput bufferToMessage(ByteBuf rawMessage, short version) {
47 GetFeaturesOutputBuilder builder = new GetFeaturesOutputBuilder();
48 builder.setVersion(version);
49 builder.setXid(rawMessage.readUnsignedInt());
50 byte[] datapathId = new byte[Long.SIZE/Byte.SIZE];
51 rawMessage.readBytes(datapathId);
52 builder.setDatapathId(new BigInteger(datapathId));
53 builder.setBuffers(rawMessage.readUnsignedInt());
54 builder.setTables(rawMessage.readUnsignedByte());
55 builder.setAuxiliaryId(rawMessage.readUnsignedByte());
56 rawMessage.skipBytes(PADDING_IN_FEATURES_REPLY_HEADER);
57 builder.setCapabilities(createCapabilities(rawMessage.readUnsignedInt()));
58 builder.setReserved(rawMessage.readUnsignedInt());
59 return builder.build();
62 private static Capabilities createCapabilities(long input) {
63 final Boolean FLOW_STATS = (input & (1 << 0)) != 0;
64 final Boolean TABLE_STATS = (input & (1 << 1)) != 0;
65 final Boolean PORT_STATS = (input & (1 << 2)) != 0;
66 final Boolean GROUP_STATS = (input & (1 << 3)) != 0;
67 final Boolean IP_REASM = (input & (1 << 5)) != 0;
68 final Boolean QUEUE_STATS = (input & (1 << 6)) != 0;
69 final Boolean PORT_BLOCKED = (input & (1 << 8)) != 0;
70 return new Capabilities(FLOW_STATS, GROUP_STATS, IP_REASM,
71 PORT_BLOCKED, PORT_STATS, QUEUE_STATS, TABLE_STATS);