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 static org.junit.Assert.assertEquals;
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.UnpooledByteBufAllocator;
15 import org.junit.Test;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.multipart.reply.multipart.reply.body.MultipartReplyMeterStats;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStats;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
20 public class MultipartReplyMeterStatsDeserializerTest extends AbstractMultipartDeserializerTest {
21 private static final byte PADDING_IN_METER_STATS_HEADER = 6;
22 private static final int METER_ID = 1;
23 private static final short ITEM_LENGTH = 50;
24 private static final int FLOW_COUNT = 2;
25 private static final long PACKET_IN_COUNT = 3L;
26 private static final long BYTE_IN_COUNT = 4L;
27 private static final int SECOND = 5;
28 private static final int NANOSECOND = 6;
29 private static final long PACKET_BAND_COUNT = 7L;
30 private static final long BYTE_BAND_COUNT = 8L;
33 public void deserialize() {
34 ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer();
35 buffer.writeInt(METER_ID);
36 buffer.writeShort(ITEM_LENGTH);
37 buffer.writeZero(PADDING_IN_METER_STATS_HEADER);
38 buffer.writeInt(FLOW_COUNT);
39 buffer.writeLong(PACKET_IN_COUNT);
40 buffer.writeLong(BYTE_IN_COUNT);
41 buffer.writeInt(SECOND);
42 buffer.writeInt(NANOSECOND);
43 buffer.writeLong(PACKET_BAND_COUNT);
44 buffer.writeLong(BYTE_BAND_COUNT);
46 final MultipartReplyMeterStats reply = (MultipartReplyMeterStats) deserializeMultipart(buffer);
48 final MeterStats meterStats = reply.getMeterStats().get(0);
50 assertEquals(METER_ID, meterStats.getMeterId().getValue().intValue());
51 assertEquals(FLOW_COUNT, meterStats.getFlowCount().getValue().intValue());
52 assertEquals(PACKET_IN_COUNT, meterStats.getPacketInCount().getValue().longValue());
53 assertEquals(BYTE_IN_COUNT, meterStats.getByteInCount().getValue().intValue());
54 assertEquals(SECOND, meterStats.getDuration().getSecond().getValue().intValue());
55 assertEquals(NANOSECOND, meterStats.getDuration().getNanosecond().getValue().intValue());
56 assertEquals(PACKET_BAND_COUNT, meterStats.getMeterBandStats().getBandStat().get(0)
57 .getPacketBandCount().getValue().longValue());
58 assertEquals(BYTE_BAND_COUNT, meterStats.getMeterBandStats().getBandStat().get(0)
59 .getByteBandCount().getValue().longValue());
60 assertEquals(0, buffer.readableBytes());
64 protected int getType() {
65 return MultipartType.OFPMPMETER.getIntValue();