Extensibility support (deserialization part)
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / FeaturesReplyMessageFactory.java
1 /*
2  * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
10
11 import io.netty.buffer.ByteBuf;
12
13 import java.math.BigInteger;
14
15 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
16 import org.opendaylight.openflowjava.protocol.impl.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;
20
21 /**
22  * Translates FeaturesReply messages
23  * @author michal.polkorab
24  * @author timotej.kubas
25  */
26 public class FeaturesReplyMessageFactory implements OFDeserializer<GetFeaturesOutput>{
27
28     private static final byte PADDING_IN_FEATURES_REPLY_HEADER = 2;
29
30     @Override
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();
45     }
46
47     private static Capabilities createCapabilities(long input) {
48         final Boolean FLOW_STATS = (input & (1 << 0)) != 0;
49         final Boolean TABLE_STATS = (input & (1 << 1)) != 0;
50         final Boolean PORT_STATS = (input & (1 << 2)) != 0;
51         final Boolean GROUP_STATS = (input & (1 << 3)) != 0;
52         final Boolean IP_REASM = (input & (1 << 5)) != 0;
53         final Boolean QUEUE_STATS = (input & (1 << 6)) != 0;
54         final Boolean PORT_BLOCKED = (input & (1 << 8)) != 0;
55         return new Capabilities(FLOW_STATS, GROUP_STATS, IP_REASM,
56                 PORT_BLOCKED, PORT_STATS, QUEUE_STATS, TABLE_STATS);
57     }
58
59 }