464583f3329ea1851a63b5be639ab2b33309db85
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / protocol / deserialization / multipart / MultipartReplyGroupDescDeserializerTest.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.openflowjava.protocol.impl.util.ActionConstants;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.multipart.reply.multipart.reply.body.MultipartReplyGroupDesc;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupTypes;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
20
21 public class MultipartReplyGroupDescDeserializerTest extends AbstractMultipartDeserializerTest {
22     private static final byte PADDING_IN_GROUP_DESC_HEADER = 1;
23     private static final byte PADDING_IN_BUCKETS_HEADER = 4;
24     private static final short ITEM_LENGTH = 32;
25     private static final int GROUP_TYPE = GroupTypes.GroupSelect.getIntValue();
26     private static final int GROUP_ID = 1;
27     private static final short BUCKET_LENGTH = 24;
28     private static final short WEIGHT = 2;
29     private static final int WATCH_PORT = 3;
30     private static final int WATCH_GROUP = 4;
31
32     @Test
33     public void deserialize() {
34         ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer();
35         buffer.writeShort(ITEM_LENGTH);
36         buffer.writeByte(GROUP_TYPE);
37         buffer.writeZero(PADDING_IN_GROUP_DESC_HEADER);
38         buffer.writeInt(GROUP_ID);
39         buffer.writeShort(BUCKET_LENGTH);
40         buffer.writeShort(WEIGHT);
41         buffer.writeInt(WATCH_PORT);
42         buffer.writeInt(WATCH_GROUP);
43         buffer.writeZero(PADDING_IN_BUCKETS_HEADER);
44
45         // POP PBB action
46         buffer.writeShort(ActionConstants.POP_PBB_CODE);
47         buffer.writeShort(ActionConstants.GENERAL_ACTION_LENGTH);
48         buffer.writeZero(ActionConstants.PADDING_IN_ACTION_HEADER);
49
50         final MultipartReplyGroupDesc reply = (MultipartReplyGroupDesc) deserializeMultipart(buffer);
51
52         assertEquals(GROUP_ID, reply.getGroupDescStats().get(0).getGroupId().getValue().intValue());
53         assertEquals(WEIGHT, reply.getGroupDescStats().get(0).getBuckets().getBucket().get(0).getWeight().intValue());
54         assertEquals(WATCH_PORT, reply.getGroupDescStats().get(0).getBuckets().getBucket().get(0).getWatchPort()
55                 .intValue());
56         assertEquals(WATCH_GROUP, reply.getGroupDescStats().get(0).getBuckets().getBucket().get(0).getWatchGroup()
57                 .intValue());
58         assertEquals(GROUP_TYPE, reply.getGroupDescStats().get(0).getGroupType().getIntValue());
59         assertEquals(0, buffer.readableBytes());
60     }
61
62     @Override
63     protected int getType() {
64         return MultipartType.OFPMPGROUPDESC.getIntValue();
65     }
66 }