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.instruction;
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.api.extensibility.OFDeserializer;
17 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
18 import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants;
19 import org.opendaylight.openflowjava.protocol.impl.util.InstructionConstants;
20 import org.opendaylight.openflowplugin.extension.api.path.ActionPath;
21 import org.opendaylight.openflowplugin.impl.protocol.deserialization.key.MessageCodeActionExperimenterKey;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopPbbActionCase;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCase;
26 public class WriteActionsInstructionDeserializerTest extends AbstractInstructionDeserializerTest {
28 private OFDeserializer<Instruction> deserializer;
31 @SuppressWarnings("checkstyle:LineLength")
32 protected void init() {
33 deserializer = getRegistry().getDeserializer(
34 new MessageCodeActionExperimenterKey(EncodeConstants.OF13_VERSION_ID, getType(), Instruction.class,
35 ActionPath.INVENTORY_FLOWNODE_TABLE_WRITE_ACTIONS,
40 public void testDeserialize() {
41 final ByteBuf in = UnpooledByteBufAllocator.DEFAULT.buffer();
44 final int startIndex = in.writerIndex();
45 in.writeShort(getType());
46 final int index = in.writerIndex();
47 in.writeShort(getLength());
48 in.writeZero(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION);
51 in.writeShort(ActionConstants.POP_PBB_CODE);
52 in.writeShort(ActionConstants.GENERAL_ACTION_LENGTH);
53 in.writeZero(ActionConstants.PADDING_IN_ACTION_HEADER);
55 in.setShort(index, in.writerIndex() - startIndex);
57 final Instruction instruction = deserializer.deserialize(in);
58 assertEquals(WriteActionsCase.class, instruction.implementedInterface());
59 final WriteActionsCase actionCase = (WriteActionsCase) instruction;
60 assertEquals(1, actionCase.getWriteActions().getAction().size());
61 assertEquals(PopPbbActionCase.class, actionCase.getWriteActions().getAction().get(0)
62 .getAction().implementedInterface());
63 assertEquals(0, in.readableBytes());
67 protected short getType() {
68 return InstructionConstants.WRITE_ACTIONS_TYPE;
72 protected short getLength() {
73 return EncodeConstants.EMPTY_LENGTH;