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;
12 import static org.junit.Assert.assertTrue;
14 import io.netty.buffer.ByteBuf;
15 import io.netty.buffer.UnpooledByteBufAllocator;
16 import java.util.Arrays;
17 import java.util.List;
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;
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));
38 private static final List<GroupTypes> GROUP_TYPES_SUPPORTED = Arrays.asList(
40 GroupTypes.GroupSelect,
41 GroupTypes.GroupIndirect);
43 private static final List<GroupCapabilities> GROUP_CAPABILITIES_SUPPORTED = Arrays.asList(
44 GroupCapabilities.Chaining,
45 GroupCapabilities.ChainingChecks);
48 public void testDeserialize() {
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));
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));
62 ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer();
64 buffer.writeInt(bitMaskGroups);
65 buffer.writeInt(bitMaskCapabilities);
67 for (Uint32 group : MAX_GROUPS_LIST) {
68 buffer.writeInt(group.intValue());
71 for (Uint32 action: ACTIONS_LIST) {
72 buffer.writeInt(action.intValue());
75 final MultipartReplyGroupFeatures reply = (MultipartReplyGroupFeatures) deserializeMultipart(buffer);
76 assertTrue(reply.getActions().containsAll(ACTIONS_LIST));
77 assertTrue(reply.getMaxGroups().containsAll(MAX_GROUPS_LIST));
79 assertEquals(Set.of(GroupAll.class, GroupSelect.class, GroupIndirect.class), reply.getGroupTypesSupported());
80 assertEquals(Set.of(Chaining.class, ChainingChecks.class), reply.getGroupCapabilitiesSupported());
82 assertEquals(0, buffer.readableBytes());
86 protected int getType() {
87 return MultipartType.OFPMPGROUPFEATURES.getIntValue();