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.group.statistics.rev131111.multipart.reply.multipart.reply.body.MultipartReplyGroupStats;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStats;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
20 public class MultipartReplyGroupStatsDeserializerTest extends AbstractMultipartDeserializerTest {
21 private static final byte PADDING_IN_GROUP_HEADER_01 = 2;
22 private static final byte PADDING_IN_GROUP_HEADER_02 = 4;
24 private static final short ITEM_LENGTH = 56;
25 private static final int GROUP_ID = 3;
26 private static final int REF_COUNT = 4;
27 private static final int SECOND = 5;
28 private static final int NANOSECOND = 6;
29 private static final long PACKET_COUNT = 1L;
30 private static final long BYTE_COUNT = 2L;
33 public void testDeserialize() {
34 ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer();
35 buffer.writeShort(ITEM_LENGTH);
36 buffer.writeZero(PADDING_IN_GROUP_HEADER_01);
37 buffer.writeInt(GROUP_ID);
38 buffer.writeInt(REF_COUNT);
39 buffer.writeZero(PADDING_IN_GROUP_HEADER_02);
40 buffer.writeLong(PACKET_COUNT);
41 buffer.writeLong(BYTE_COUNT);
42 buffer.writeInt(SECOND);
43 buffer.writeInt(NANOSECOND);
44 buffer.writeLong(PACKET_COUNT);
45 buffer.writeLong(BYTE_COUNT);
47 final MultipartReplyGroupStats reply = (MultipartReplyGroupStats) deserializeMultipart(buffer);
48 final GroupStats firstGroupStats = reply.nonnullGroupStats().values().iterator().next();
49 assertEquals(GROUP_ID, firstGroupStats.getGroupId().getValue().intValue());
50 assertEquals(REF_COUNT, firstGroupStats.getRefCount().getValue().intValue());
51 assertEquals(PACKET_COUNT, firstGroupStats.getPacketCount().getValue().longValue());
52 assertEquals(BYTE_COUNT, firstGroupStats.getByteCount().getValue().longValue());
53 assertEquals(SECOND, firstGroupStats.getDuration().getSecond().getValue().intValue());
54 assertEquals(NANOSECOND, firstGroupStats.getDuration().getNanosecond().getValue().intValue());
55 assertEquals(PACKET_COUNT, firstGroupStats.getPacketCount().getValue().longValue());
56 assertEquals(BYTE_COUNT, firstGroupStats.getByteCount().getValue().longValue());
57 assertEquals(0, buffer.readableBytes());
61 protected int getType() {
62 return MultipartType.OFPMPGROUP.getIntValue();