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.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;
26 public class MultipartReplyFlowTableStatsDeserializer implements OFDeserializer<MultipartReplyBody> {
28 private static final byte PADDING_IN_TABLE_HEADER = 3;
31 public MultipartReplyBody deserialize(ByteBuf message) {
32 final MultipartReplyFlowTableStatsBuilder builder = new MultipartReplyFlowTableStatsBuilder();
33 final List<FlowTableAndStatisticsMap> items = new ArrayList<>();
35 while (message.readableBytes() > 0) {
36 final FlowTableAndStatisticsMapBuilder itemBuilder = new FlowTableAndStatisticsMapBuilder()
37 .setTableId(new TableId(message.readUnsignedByte()));
39 message.skipBytes(PADDING_IN_TABLE_HEADER);
42 .withKey(new FlowTableAndStatisticsMapKey(itemBuilder.getTableId()))
43 .setActiveFlows(new Counter32(message.readUnsignedInt()));
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);
51 .setPacketsLookedUp(new Counter64(new BigInteger(1, packetsLooked)))
52 .setPacketsMatched(new Counter64(new BigInteger(1, packetsMatched)))
57 .setFlowTableAndStatisticsMap(items)