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.meter.statistics.rev131111.multipart.reply.multipart.reply.body.MultipartReplyMeterStatsBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.BandId;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.DurationBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.MeterBandStatsBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.meter.band.stats.BandStat;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.meter.band.stats.BandStatBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.meter.band.stats.BandStatKey;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStats;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStatsBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStatsKey;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.multipart.reply.MultipartReplyBody;
32 public class MultipartReplyMeterStatsDeserializer implements OFDeserializer<MultipartReplyBody> {
34 private static final byte PADDING_IN_METER_STATS_HEADER = 6;
35 private static final byte METER_BODY_LENGTH = 40;
36 private static final byte METER_BAND_STATS_LENGTH = 16;
39 public MultipartReplyBody deserialize(ByteBuf message) {
40 final MultipartReplyMeterStatsBuilder builder = new MultipartReplyMeterStatsBuilder();
41 final List<MeterStats> items = new ArrayList<>();
43 while (message.readableBytes() > 0) {
44 final MeterStatsBuilder itemBuilder = new MeterStatsBuilder()
45 .setMeterId(new MeterId(message.readUnsignedInt()));
47 final int itemLength = message.readUnsignedShort();
48 message.skipBytes(PADDING_IN_METER_STATS_HEADER);
51 .setKey(new MeterStatsKey(itemBuilder.getMeterId()))
52 .setFlowCount(new Counter32(message.readUnsignedInt()));
54 final byte[] packetCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
55 message.readBytes(packetCount);
56 final byte[] byteCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
57 message.readBytes(byteCount);
60 .setPacketInCount(new Counter64(new BigInteger(1, packetCount)))
61 .setByteInCount(new Counter64(new BigInteger(1, byteCount)))
62 .setDuration(new DurationBuilder()
63 .setSecond(new Counter32(message.readUnsignedInt()))
64 .setNanosecond(new Counter32(message.readUnsignedInt()))
67 final List<BandStat> subItems = new ArrayList<>();
68 int actualLength = METER_BODY_LENGTH;
71 while (actualLength < itemLength) {
72 final byte[] packetCountB = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
73 message.readBytes(packetCountB);
74 final byte[] byteCountB = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
75 message.readBytes(byteCountB);
77 subItems.add(new BandStatBuilder()
78 .setBandId(new BandId(bandKey))
79 .setKey(new BandStatKey(new BandId(bandKey)))
80 .setPacketBandCount(new Counter64(new BigInteger(1, packetCountB)))
81 .setByteBandCount(new Counter64(new BigInteger(1, byteCountB)))
85 actualLength += METER_BAND_STATS_LENGTH;
89 .setMeterBandStats(new MeterBandStatsBuilder()
90 .setBandStat(subItems)