c13c4d2ceabd476ffbc1fd71efd60ece34571ddf
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / protocol / deserialization / instruction / ApplyActionsInstructionDeserializerTest.java
1 /*
2  * Copyright (c) 2016 Pantheon Technologies s.r.o. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.openflowplugin.impl.protocol.deserialization.instruction;
10
11 import static org.junit.Assert.assertEquals;
12
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.ApplyActionsCase;
25
26 public class ApplyActionsInstructionDeserializerTest extends AbstractInstructionDeserializerTest {
27
28     private OFDeserializer<Instruction> deserializer;
29
30     @Override
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_APPLY_ACTIONS,
36                         null));
37     }
38
39     @Test
40     public void testDeserialize() {
41         final ByteBuf in = UnpooledByteBufAllocator.DEFAULT.buffer();
42
43         // Header
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);
49
50         // POP PBB action
51         in.writeShort(ActionConstants.POP_PBB_CODE);
52         in.writeShort(ActionConstants.GENERAL_ACTION_LENGTH);
53         in.writeZero(ActionConstants.PADDING_IN_ACTION_HEADER);
54
55         in.setShort(index, in.writerIndex() - startIndex);
56
57         final Instruction instruction = deserializer.deserialize(in);
58         assertEquals(ApplyActionsCase.class, instruction.implementedInterface());
59         final ApplyActionsCase actionCase = (ApplyActionsCase) instruction;
60         assertEquals(1, actionCase.getApplyActions().getAction().size());
61         assertEquals(PopPbbActionCase.class, actionCase.getApplyActions().getAction().get(0)
62                 .getAction().implementedInterface());
63         assertEquals(0, in.readableBytes());
64     }
65
66     @Override
67     protected short getType() {
68         return InstructionConstants.APPLY_ACTIONS_TYPE;
69     }
70
71     @Override
72     protected short getLength() {
73         return EncodeConstants.EMPTY_LENGTH;
74     }
75
76 }