Merge changes from topic 'ofj-models-to-ofp-models'
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / protocol / deserialization / multipart / MultipartReplyFlowAggregateStatsDeserializer.java
1 /*
2  * Copyright (c) 2017 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.openflowplugin.impl.protocol.deserialization.multipart;
10
11 import io.netty.buffer.ByteBuf;
12 import java.math.BigInteger;
13 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
14 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.multipart.reply.multipart.reply.body.MultipartReplyFlowAggregateStatsBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.multipart.reply.MultipartReplyBody;
19
20 public class MultipartReplyFlowAggregateStatsDeserializer implements OFDeserializer<MultipartReplyBody> {
21
22     private static final byte PADDING_IN_AGGREGATE_HEADER = 4;
23
24     @Override
25     public MultipartReplyBody deserialize(ByteBuf message) {
26         final byte[] packetCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
27         message.readBytes(packetCount);
28         final byte[] byteCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
29         message.readBytes(byteCount);
30
31         final MultipartReplyFlowAggregateStatsBuilder builder = new MultipartReplyFlowAggregateStatsBuilder()
32             .setPacketCount(new Counter64(new BigInteger(1, packetCount)))
33             .setByteCount(new Counter64(new BigInteger(1, byteCount)))
34             .setFlowCount(new Counter32(message.readUnsignedInt()));
35
36         message.skipBytes(PADDING_IN_AGGREGATE_HEADER);
37         return builder.build();
38     }
39
40 }