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.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.group.types.rev131018.group.buckets.Bucket;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.desc.stats.reply.GroupDescStats;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
23 public class MultipartReplyGroupDescDeserializerTest extends AbstractMultipartDeserializerTest {
24 private static final byte PADDING_IN_GROUP_DESC_HEADER = 1;
25 private static final byte PADDING_IN_BUCKETS_HEADER = 4;
26 private static final short ITEM_LENGTH = 32;
27 private static final int GROUP_TYPE = GroupTypes.GroupSelect.getIntValue();
28 private static final int GROUP_ID = 1;
29 private static final short BUCKET_LENGTH = 24;
30 private static final short WEIGHT = 2;
31 private static final int WATCH_PORT = 3;
32 private static final int WATCH_GROUP = 4;
35 public void deserialize() {
36 ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer();
37 buffer.writeShort(ITEM_LENGTH);
38 buffer.writeByte(GROUP_TYPE);
39 buffer.writeZero(PADDING_IN_GROUP_DESC_HEADER);
40 buffer.writeInt(GROUP_ID);
41 buffer.writeShort(BUCKET_LENGTH);
42 buffer.writeShort(WEIGHT);
43 buffer.writeInt(WATCH_PORT);
44 buffer.writeInt(WATCH_GROUP);
45 buffer.writeZero(PADDING_IN_BUCKETS_HEADER);
48 buffer.writeShort(ActionConstants.POP_PBB_CODE);
49 buffer.writeShort(ActionConstants.GENERAL_ACTION_LENGTH);
50 buffer.writeZero(ActionConstants.PADDING_IN_ACTION_HEADER);
52 final MultipartReplyGroupDesc reply = (MultipartReplyGroupDesc) deserializeMultipart(buffer);
53 final GroupDescStats firstGroupDescStats = reply.nonnullGroupDescStats().values().iterator().next();
54 assertEquals(GROUP_ID, firstGroupDescStats.getGroupId().getValue().intValue());
55 assertEquals(GROUP_TYPE, firstGroupDescStats.getGroupType().getIntValue());
57 final Bucket firstBucket = firstGroupDescStats.getBuckets().nonnullBucket().values().iterator().next();
58 assertEquals(WEIGHT, firstBucket.getWeight().intValue());
59 assertEquals(WATCH_PORT, firstBucket.getWatchPort().intValue());
60 assertEquals(WATCH_GROUP, firstBucket.getWatchGroup().intValue());
61 assertEquals(0, buffer.readableBytes());
65 protected int getType() {
66 return MultipartType.OFPMPGROUPDESC.getIntValue();