2 * Copyright (c) 2017 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.openflowplugin.impl.protocol.deserialization.multipart;
11 import io.netty.buffer.ByteBuf;
12 import java.math.BigInteger;
13 import java.util.ArrayList;
14 import java.util.List;
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.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.multipart.reply.multipart.reply.body.MultipartReplyGroupStatsBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.BucketId;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.BucketsBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.DurationBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.buckets.BucketCounter;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.buckets.BucketCounterBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.buckets.BucketCounterKey;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStats;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStatsBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStatsKey;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.multipart.reply.MultipartReplyBody;
32 public class MultipartReplyGroupStatsDeserializer implements OFDeserializer<MultipartReplyBody> {
34 private static final byte PADDING_IN_GROUP_HEADER_01 = 2;
35 private static final byte PADDING_IN_GROUP_HEADER_02 = 4;
36 private static final byte GROUP_BODY_LENGTH = 40;
37 private static final byte BUCKET_COUNTER_LENGTH = 16;
40 public MultipartReplyBody deserialize(ByteBuf message) {
41 final MultipartReplyGroupStatsBuilder builder = new MultipartReplyGroupStatsBuilder();
42 final List<GroupStats> items = new ArrayList<>();
44 while (message.readableBytes() > 0) {
45 final int itemLength = message.readUnsignedShort();
46 message.skipBytes(PADDING_IN_GROUP_HEADER_01);
48 final GroupStatsBuilder itemBuilder = new GroupStatsBuilder()
49 .setGroupId(new GroupId(message.readUnsignedInt()))
50 .setRefCount(new Counter32(message.readUnsignedInt()));
52 message.skipBytes(PADDING_IN_GROUP_HEADER_02);
54 final byte[] packetCountg = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
55 message.readBytes(packetCountg);
56 final byte[] byteCountg = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
57 message.readBytes(byteCountg);
60 .setKey(new GroupStatsKey(itemBuilder.getGroupId()))
61 .setPacketCount(new Counter64(new BigInteger(1, packetCountg)))
62 .setByteCount(new Counter64(new BigInteger(1, byteCountg)))
63 .setDuration(new DurationBuilder()
64 .setSecond(new Counter32(message.readUnsignedInt()))
65 .setNanosecond(new Counter32(message.readUnsignedInt()))
68 final List<BucketCounter> subItems = new ArrayList<>();
69 int actualLength = GROUP_BODY_LENGTH;
72 while (actualLength < itemLength) {
73 final byte[] packetCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
74 message.readBytes(packetCount);
75 final byte[] byteCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
76 message.readBytes(byteCount);
78 subItems.add(new BucketCounterBuilder()
79 .setBucketId(new BucketId(bucketKey))
80 .setKey(new BucketCounterKey(new BucketId(bucketKey)))
81 .setPacketCount(new Counter64(new BigInteger(1, packetCount)))
82 .setByteCount(new Counter64(new BigInteger(1, byteCount)))
86 actualLength += BUCKET_COUNTER_LENGTH;
90 .setBuckets(new BucketsBuilder()
91 .setBucketCounter(subItems)