2 * Copyright (c) 2016 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.messages;
11 import static org.junit.Assert.assertEquals;
13 import org.junit.Test;
14 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
15 import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants;
16 import org.opendaylight.openflowplugin.impl.protocol.deserialization.AbstractDeserializerTest;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopPbbActionCase;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupMessage;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupTypes;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupModCommand;
23 import io.netty.buffer.ByteBuf;
24 import io.netty.buffer.UnpooledByteBufAllocator;
26 public class GroupMessageDeserializerTest extends AbstractDeserializerTest {
28 private static final byte PADDING = 1;
29 private static final byte PADDING_IN_BUCKETS_HEADER = 4;
31 private static final int TYPE = 15;
32 private static final int XID = 42;
33 private static final GroupModCommand COMMAND = GroupModCommand.OFPGCADD;
34 private static final GroupTypes GROUP_TYPE = GroupTypes.GroupAll;
35 private static final int GROUP_ID = 26;
36 private static final short WEIGHT = 50;
37 private static final int WATCH_PORT = 22;
38 private static final int WATCH_GROUP = 25;
40 private ByteBuf buffer;
43 protected void init() {
44 buffer = UnpooledByteBufAllocator.DEFAULT.buffer();
48 public void deserialize() throws Exception {
50 buffer.writeByte(TYPE);
51 buffer.writeShort(EncodeConstants.EMPTY_LENGTH);
53 buffer.writeShort(COMMAND.getIntValue());
54 buffer.writeByte(GROUP_TYPE.getIntValue());
55 buffer.writeZero(PADDING);
56 buffer.writeInt(GROUP_ID);
59 int index = buffer.writerIndex();
60 buffer.writeShort(EncodeConstants.EMPTY_LENGTH);
61 buffer.writeShort(WEIGHT);
62 buffer.writeInt(WATCH_PORT);
63 buffer.writeInt(WATCH_GROUP);
64 buffer.writeZero(PADDING_IN_BUCKETS_HEADER);
67 buffer.writeShort(ActionConstants.POP_PBB_CODE);
68 buffer.writeShort(ActionConstants.GENERAL_ACTION_LENGTH);
69 buffer.writeZero(ActionConstants.PADDING_IN_ACTION_HEADER);
71 // Count total length of buckets
72 buffer.setShort(index, buffer.writerIndex() - index);
74 // Deserialize and check everything
75 final GroupMessage message = (GroupMessage) getFactory()
76 .deserialize(buffer, EncodeConstants.OF13_VERSION_ID);
78 assertEquals(XID, message.getXid().intValue());
79 assertEquals(COMMAND.getIntValue(), message.getCommand().getIntValue());
80 assertEquals(GROUP_TYPE.getIntValue(), message.getGroupType().getIntValue());
81 assertEquals(1, message.getBuckets().getBucket().size());
83 final Bucket bucket = message.getBuckets().getBucket().get(0);
84 assertEquals(WEIGHT, bucket.getWeight().shortValue());
85 assertEquals(WATCH_PORT, bucket.getWatchPort().intValue());
86 assertEquals(WATCH_GROUP, bucket.getWatchGroup().intValue());
87 assertEquals(1, bucket.getAction().size());
88 assertEquals(PopPbbActionCase.class, bucket.getAction().get(0).getAction().getImplementedInterface());