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.serialization.instruction;
11 import io.netty.buffer.ByteBuf;
13 import java.util.List;
15 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
16 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector;
17 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
18 import org.opendaylight.openflowjava.protocol.impl.util.InstructionConstants;
19 import org.opendaylight.openflowjava.protocol.impl.util.ListSerializer;
20 import org.opendaylight.openflowjava.protocol.impl.util.TypeKeyMaker;
21 import org.opendaylight.openflowjava.protocol.impl.util.TypeKeyMakerFactory;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ActionsInstruction;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;
27 * @author michal.polkorab
30 public abstract class AbstractActionInstructionSerializer extends AbstractInstructionSerializer
31 implements SerializerRegistryInjector {
33 private static final TypeKeyMaker<Action> ACTION_KEY_MAKER =
34 TypeKeyMakerFactory.createActionKeyMaker(EncodeConstants.OF13_VERSION_ID);
36 private SerializerRegistry registry;
39 public void serialize(final Instruction instruction, final ByteBuf outBuffer) {
40 int startIndex = outBuffer.writerIndex();
41 outBuffer.writeShort(getType());
42 if (instruction.getAugmentation(ActionsInstruction.class) != null) {
43 List<Action> actions = instruction.getAugmentation(ActionsInstruction.class).getAction();
44 int lengthIndex = outBuffer.writerIndex();
45 outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH);
46 outBuffer.writeZero(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION);
47 ListSerializer.serializeList(actions, ACTION_KEY_MAKER, getRegistry(), outBuffer);
48 int instructionLength = outBuffer.writerIndex() - startIndex;
49 outBuffer.setShort(lengthIndex, instructionLength);
51 outBuffer.writeShort(InstructionConstants.STANDARD_INSTRUCTION_LENGTH);
52 outBuffer.writeZero(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION);
56 protected SerializerRegistry getRegistry() {
61 public void injectSerializerRegistry(final SerializerRegistry serializerRegistry) {
62 registry = serializerRegistry;