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,
36 .NODES_NODE_TABLE_FLOW_INSTRUCTIONS_INSTRUCTION_WRITEACTIONSCASE_WRITEACTIONS_ACTION_ACTION_EXTENSIONLIST_EXTENSION,
41 public void testDeserialize() throws Exception {
42 final ByteBuf in = UnpooledByteBufAllocator.DEFAULT.buffer();
45 final int startIndex = in.writerIndex();
46 in.writeShort(getType());
47 final int index = in.writerIndex();
48 in.writeShort(getLength());
49 in.writeZero(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION);
52 in.writeShort(ActionConstants.POP_PBB_CODE);
53 in.writeShort(ActionConstants.GENERAL_ACTION_LENGTH);
54 in.writeZero(ActionConstants.PADDING_IN_ACTION_HEADER);
56 in.setShort(index, in.writerIndex() - startIndex);
58 final Instruction instruction = deserializer.deserialize(in);
59 assertEquals(WriteActionsCase.class, instruction.getImplementedInterface());
60 final WriteActionsCase actionCase = WriteActionsCase.class.cast(instruction);
61 assertEquals(1, actionCase.getWriteActions().getAction().size());
62 assertEquals(PopPbbActionCase.class, actionCase.getWriteActions().getAction().get(0)
63 .getAction().getImplementedInterface());
64 assertEquals(0, in.readableBytes());
68 protected short getType() {
69 return InstructionConstants.WRITE_ACTIONS_TYPE;
73 protected short getLength() {
74 return EncodeConstants.EMPTY_LENGTH;