Fixup Augmentable and Identifiable methods changing
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / protocol / deserialization / multipart / MultipartReplyFlowTableStatsDeserializer.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 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.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMap;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMapBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMapKey;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.multipart.reply.multipart.reply.body.MultipartReplyFlowTableStatsBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.multipart.reply.MultipartReplyBody;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId;
25
26 public class MultipartReplyFlowTableStatsDeserializer implements OFDeserializer<MultipartReplyBody> {
27
28     private static final byte PADDING_IN_TABLE_HEADER = 3;
29
30     @Override
31     public MultipartReplyBody deserialize(ByteBuf message) {
32         final MultipartReplyFlowTableStatsBuilder builder = new MultipartReplyFlowTableStatsBuilder();
33         final List<FlowTableAndStatisticsMap> items = new ArrayList<>();
34
35         while (message.readableBytes() > 0) {
36             final FlowTableAndStatisticsMapBuilder itemBuilder = new FlowTableAndStatisticsMapBuilder()
37                 .setTableId(new TableId(message.readUnsignedByte()));
38
39             message.skipBytes(PADDING_IN_TABLE_HEADER);
40
41             itemBuilder
42                 .withKey(new FlowTableAndStatisticsMapKey(itemBuilder.getTableId()))
43                 .setActiveFlows(new Counter32(message.readUnsignedInt()));
44
45             final byte[] packetsLooked = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
46             message.readBytes(packetsLooked);
47             final byte[] packetsMatched = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
48             message.readBytes(packetsMatched);
49
50             items.add(itemBuilder
51                 .setPacketsLookedUp(new Counter64(new BigInteger(1, packetsLooked)))
52                 .setPacketsMatched(new Counter64(new BigInteger(1, packetsMatched)))
53                 .build());
54         }
55
56         return builder
57             .setFlowTableAndStatisticsMap(items)
58             .build();
59     }
60
61 }