f6a00986e9424f4101a19b6863f1898f877298db
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / protocol / deserialization / multipart / MultipartReplyGroupStatsDeserializerTest.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.group.statistics.rev131111.multipart.reply.multipart.reply.body.MultipartReplyGroupStats;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
18
19 public class MultipartReplyGroupStatsDeserializerTest extends AbstractMultipartDeserializerTest {
20     private static final byte PADDING_IN_GROUP_HEADER_01 = 2;
21     private static final byte PADDING_IN_GROUP_HEADER_02 = 4;
22
23     private static final short ITEM_LENGTH = 56;
24     private static final int GROUP_ID = 3;
25     private static final int REF_COUNT = 4;
26     private static final int SECOND = 5;
27     private static final int NANOSECOND = 6;
28     private static final long PACKET_COUNT = 1L;
29     private static final long BYTE_COUNT = 2L;
30
31     @Test
32     public void testDeserialize() {
33         ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer();
34         buffer.writeShort(ITEM_LENGTH);
35         buffer.writeZero(PADDING_IN_GROUP_HEADER_01);
36         buffer.writeInt(GROUP_ID);
37         buffer.writeInt(REF_COUNT);
38         buffer.writeZero(PADDING_IN_GROUP_HEADER_02);
39         buffer.writeLong(PACKET_COUNT);
40         buffer.writeLong(BYTE_COUNT);
41         buffer.writeInt(SECOND);
42         buffer.writeInt(NANOSECOND);
43         buffer.writeLong(PACKET_COUNT);
44         buffer.writeLong(BYTE_COUNT);
45
46         final MultipartReplyGroupStats reply = (MultipartReplyGroupStats) deserializeMultipart(buffer);
47         assertEquals(GROUP_ID, reply.getGroupStats().get(0).getGroupId().getValue().intValue());
48         assertEquals(REF_COUNT, reply.getGroupStats().get(0).getRefCount().getValue().intValue());
49         assertEquals(PACKET_COUNT, reply.getGroupStats().get(0).getPacketCount().getValue().longValue());
50         assertEquals(BYTE_COUNT, reply.getGroupStats().get(0).getByteCount().getValue().longValue());
51         assertEquals(SECOND, reply.getGroupStats().get(0).getDuration().getSecond().getValue().intValue());
52         assertEquals(NANOSECOND, reply.getGroupStats().get(0).getDuration().getNanosecond().getValue().intValue());
53         assertEquals(PACKET_COUNT, reply.getGroupStats().get(0).getPacketCount().getValue().longValue());
54         assertEquals(BYTE_COUNT, reply.getGroupStats().get(0).getByteCount().getValue().longValue());
55         assertEquals(0, buffer.readableBytes());
56     }
57
58     @Override
59     protected int getType() {
60         return MultipartType.OFPMPGROUP.getIntValue();
61     }
62 }