2 * Copyright (c) 2013 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.openflowjava.protocol.impl.deserialization.instruction;
11 import io.netty.buffer.ByteBuf;
13 import java.util.List;
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;
30 * @author michal.polkorab
33 public abstract class AbstractActionInstructionDeserializer extends AbstractInstructionDeserializer
34 implements DeserializerRegistryInjector {
36 private DeserializerRegistry registry;
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();
55 protected abstract Class<? extends InstructionBase> getType();
57 protected DeserializerRegistry getRegistry() {
62 public void injectDeserializerRegistry(DeserializerRegistry deserializerRegistry) {
63 this.registry = deserializerRegistry;