Update MRI projects for Aluminium
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / protocol / deserialization / multipart / MultipartReplyFlowTableStatsDeserializerTest.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 package org.opendaylight.openflowplugin.impl.protocol.deserialization.multipart;
9
10 import static org.junit.Assert.assertEquals;
11
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.UnpooledByteBufAllocator;
14 import org.junit.Test;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMap;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.multipart.reply.multipart.reply.body.MultipartReplyFlowTableStats;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
18
19 public class MultipartReplyFlowTableStatsDeserializerTest extends AbstractMultipartDeserializerTest {
20     private static final byte TABLE_ID = 2;
21     private static final long PACKETS_LOOKEDUP = 1L;
22     private static final long PACKETS_MATCHED = 2L;
23     private static final int ACTIVE_FLOWS = 3;
24     private static final byte PADDING_IN_TABLE_HEADER = 3;
25
26     @Test
27     public void testDeserialize() {
28         ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer();
29         buffer.writeByte(TABLE_ID);
30         buffer.writeZero(PADDING_IN_TABLE_HEADER);
31         buffer.writeInt(ACTIVE_FLOWS);
32         buffer.writeLong(PACKETS_LOOKEDUP);
33         buffer.writeLong(PACKETS_MATCHED);
34
35         final MultipartReplyFlowTableStats reply = (MultipartReplyFlowTableStats) deserializeMultipart(buffer);
36         final FlowTableAndStatisticsMap first = reply.nonnullFlowTableAndStatisticsMap().values().iterator().next();
37         assertEquals(TABLE_ID, first.getTableId().getValue().byteValue());
38         assertEquals(ACTIVE_FLOWS, first.getActiveFlows().getValue().intValue());
39         assertEquals(PACKETS_LOOKEDUP, first.getPacketsLookedUp().getValue().longValue());
40         assertEquals(PACKETS_MATCHED, first.getPacketsMatched().getValue().longValue());
41         assertEquals(0, buffer.readableBytes());
42     }
43
44     @Override
45     protected int getType() {
46         return MultipartType.OFPMPTABLE.getIntValue();
47     }
48 }