Bug 2756 - Action model update
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / deserialization / instruction / AbstractActionInstructionDeserializer.java
1 /*
2  * Copyright (c) 2013 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.openflowjava.protocol.impl.deserialization.instruction;
10
11 import io.netty.buffer.ByteBuf;
12
13 import java.util.List;
14
15 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
16 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistryInjector;
17 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
18 import org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMaker;
19 import org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMakerFactory;
20 import org.opendaylight.openflowjava.protocol.impl.util.InstructionConstants;
21 import org.opendaylight.openflowjava.protocol.impl.util.ListDeserializer;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ActionsInstruction;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ActionsInstructionBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.InstructionBase;
28
29 /**
30  * @author michal.polkorab
31  *
32  */
33 public abstract class AbstractActionInstructionDeserializer extends AbstractInstructionDeserializer
34         implements DeserializerRegistryInjector {
35
36     private DeserializerRegistry registry;
37
38     @Override
39     public Instruction deserialize(ByteBuf input) {
40         InstructionBuilder builder = new InstructionBuilder();
41         input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
42         builder.setType(getType());
43         int instructionLength = input.readUnsignedShort();
44         input.skipBytes(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION);
45         ActionsInstructionBuilder actionsBuilder = new ActionsInstructionBuilder();
46         int length = instructionLength - InstructionConstants.STANDARD_INSTRUCTION_LENGTH;
47         CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF13_VERSION_ID);
48         List<Action> actions = ListDeserializer.deserializeList(
49                 EncodeConstants.OF13_VERSION_ID, length, input, keyMaker, getRegistry());
50         actionsBuilder.setAction(actions);
51         builder.addAugmentation(ActionsInstruction.class, actionsBuilder.build());
52         return builder.build();
53     }
54
55     protected abstract Class<? extends InstructionBase> getType();
56
57     protected DeserializerRegistry getRegistry() {
58         return registry;
59     }
60
61     @Override
62     public void injectDeserializerRegistry(DeserializerRegistry deserializerRegistry) {
63         this.registry = deserializerRegistry;
64     }
65 }