Bump MRI upstreams
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / protocol / deserialization / multipart / MultipartReplyGroupFeaturesDeserializerTest.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 import static org.junit.Assert.assertTrue;
13
14 import io.netty.buffer.ByteBuf;
15 import io.netty.buffer.UnpooledByteBufAllocator;
16 import java.util.Arrays;
17 import java.util.List;
18 import java.util.Set;
19 import org.junit.Test;
20 import org.opendaylight.openflowjava.util.ByteBufUtils;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.multipart.reply.multipart.reply.body.MultipartReplyGroupFeatures;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Chaining;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.ChainingChecks;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupAll;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupCapabilities;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupIndirect;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupSelect;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupTypes;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
30 import org.opendaylight.yangtools.yang.common.Uint32;
31
32 public class MultipartReplyGroupFeaturesDeserializerTest extends AbstractMultipartDeserializerTest {
33     private static final List<Uint32> MAX_GROUPS_LIST = Arrays.asList(Uint32.valueOf(1),
34         Uint32.valueOf(2), Uint32.valueOf(3), Uint32.valueOf(4));
35     private static final List<Uint32> ACTIONS_LIST = Arrays.asList(Uint32.valueOf(5), Uint32.valueOf(6),
36         Uint32.valueOf(7), Uint32.valueOf(8));
37
38     private static final List<GroupTypes> GROUP_TYPES_SUPPORTED = Arrays.asList(
39             GroupTypes.GroupAll,
40             GroupTypes.GroupSelect,
41             GroupTypes.GroupIndirect);
42
43     private static final List<GroupCapabilities> GROUP_CAPABILITIES_SUPPORTED = Arrays.asList(
44             GroupCapabilities.Chaining,
45             GroupCapabilities.ChainingChecks);
46
47     @Test
48     public void testDeserialize() {
49
50         int bitMaskGroups = ByteBufUtils.fillBitMask(0,
51                 GROUP_TYPES_SUPPORTED.contains(GroupTypes.GroupAll),
52                 GROUP_TYPES_SUPPORTED.contains(GroupTypes.GroupSelect),
53                 GROUP_TYPES_SUPPORTED.contains(GroupTypes.GroupIndirect),
54                 GROUP_TYPES_SUPPORTED.contains(GroupTypes.GroupFf));
55
56         int bitMaskCapabilities = ByteBufUtils.fillBitMask(0,
57                 GROUP_CAPABILITIES_SUPPORTED.contains(GroupCapabilities.SelectWeight),
58                 GROUP_CAPABILITIES_SUPPORTED.contains(GroupCapabilities.SelectLiveness),
59                 GROUP_CAPABILITIES_SUPPORTED.contains(GroupCapabilities.Chaining),
60                 GROUP_CAPABILITIES_SUPPORTED.contains(GroupCapabilities.ChainingChecks));
61
62         ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer();
63
64         buffer.writeInt(bitMaskGroups);
65         buffer.writeInt(bitMaskCapabilities);
66
67         for (Uint32 group : MAX_GROUPS_LIST) {
68             buffer.writeInt(group.intValue());
69         }
70
71         for (Uint32 action: ACTIONS_LIST) {
72             buffer.writeInt(action.intValue());
73         }
74
75         final MultipartReplyGroupFeatures reply = (MultipartReplyGroupFeatures) deserializeMultipart(buffer);
76         assertTrue(reply.getActions().containsAll(ACTIONS_LIST));
77         assertTrue(reply.getMaxGroups().containsAll(MAX_GROUPS_LIST));
78
79         assertEquals(Set.of(GroupAll.class, GroupSelect.class, GroupIndirect.class), reply.getGroupTypesSupported());
80         assertEquals(Set.of(Chaining.class, ChainingChecks.class), reply.getGroupCapabilitiesSupported());
81
82         assertEquals(0, buffer.readableBytes());
83     }
84
85     @Override
86     protected int getType() {
87         return MultipartType.OFPMPGROUPFEATURES.getIntValue();
88     }
89 }