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 io.netty.buffer.ByteBuf;
12 import java.util.ArrayList;
13 import java.util.List;
14 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
15 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistryInjector;
16 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
17 import org.opendaylight.openflowjava.protocol.impl.util.InstructionConstants;
18 import org.opendaylight.openflowplugin.extension.api.path.ActionPath;
19 import org.opendaylight.openflowplugin.impl.protocol.deserialization.util.ActionUtil;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
23 public abstract class AbstractActionInstructionDeserializer extends AbstractInstructionDeserializer
24 implements DeserializerRegistryInjector {
26 private DeserializerRegistry registry;
27 private final ActionPath actionPath;
30 * Create new instacte of action instruction deserializer.
32 * @param actionPath action extension path
34 public AbstractActionInstructionDeserializer(final ActionPath actionPath) {
35 this.actionPath = actionPath;
39 * Skip first few bytes of instruction message because they are irrelevant and then return length.
41 * @param message Openflow buffered message
42 * @return instruction length
44 protected static int readHeader(ByteBuf message) {
45 message.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
46 return message.readUnsignedShort();
50 * Read list of actions from message.
52 * @param message Openflow buffered message
53 * @param length instruction length
54 * @return list of actions
56 protected List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list
57 .Action> readActions(ByteBuf message, int length) {
59 final int instrLength = length - InstructionConstants.STANDARD_INSTRUCTION_LENGTH;
61 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list
62 .Action> actions = new ArrayList<>();
64 if (message.readableBytes() > 0) {
65 final int startIndex = message.readerIndex();
68 while ((message.readerIndex() - startIndex) < instrLength) {
69 actions.add(new ActionBuilder()
70 .withKey(new ActionKey(offset))
73 .readAction(EncodeConstants.OF13_VERSION_ID, message, registry, actionPath))
84 public void injectDeserializerRegistry(DeserializerRegistry deserializerRegistry) {
85 registry = deserializerRegistry;