c3e0f386aa19ed2e2ae17181d979af8411b11db7
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / protocol / deserialization / multipart / MultipartReplyMeterStatsDeserializerTest.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 static org.junit.Assert.assertEquals;
12
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;
19
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;
31
32     @Test
33     public void deserialize() throws Exception {
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);
45
46         final MultipartReplyMeterStats reply = (MultipartReplyMeterStats) deserializeMultipart(buffer);
47
48         final MeterStats meterStats = reply.getMeterStats().get(0);
49
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());
61     }
62
63     @Override
64     protected int getType() {
65         return MultipartType.OFPMPMETER.getIntValue();
66     }
67 }