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.serialization.instructions;
11 import io.netty.buffer.ByteBuf;
12 import java.util.Optional;
13 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
14 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector;
15 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
16 import org.opendaylight.openflowjava.protocol.impl.util.InstructionConstants;
17 import org.opendaylight.openflowplugin.impl.protocol.serialization.util.ActionUtil;
18 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.OrderComparator;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.ActionList;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction;
22 public abstract class AbstractActionInstructionSerializer<T extends Instruction>
23 extends AbstractInstructionSerializer<T> implements SerializerRegistryInjector {
25 private SerializerRegistry registry;
28 public void serialize(T input, ByteBuf outBuffer) {
29 outBuffer.writeShort(getType());
33 * Try to write list of OpenFlowPlugin actions to output buffer.
35 * @param actions List of OpenFlowPlugin actions
36 * @param outBuffer output buffer
37 * @param startIndex start index of byte buffer
39 protected void writeActions(ActionList actions, short version, ByteBuf outBuffer, int startIndex) {
40 Optional.ofNullable(actions).flatMap(as -> Optional.ofNullable(as.nonnullAction())).map(as -> {
41 final int lengthIndex = outBuffer.writerIndex();
42 outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH);
43 outBuffer.writeZero(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION);
44 as.values().stream().sorted(OrderComparator.build()).forEach(a -> ActionUtil
45 .writeAction(a.getAction(), version, registry, outBuffer));
46 outBuffer.setShort(lengthIndex, outBuffer.writerIndex() - startIndex);
49 outBuffer.writeShort(getLength());
50 outBuffer.writeZero(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION);
56 public void injectSerializerRegistry(SerializerRegistry serializerRegistry) {
57 registry = serializerRegistry;