2 * Copyright (c) 2017 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.util;
11 import io.netty.buffer.ByteBuf;
12 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
13 import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderDeserializer;
14 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
15 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
16 import org.opendaylight.openflowjava.protocol.impl.util.InstructionConstants;
17 import org.opendaylight.openflowplugin.api.openflow.protocol.deserialization.MessageCodeExperimenterKey;
18 import org.opendaylight.openflowplugin.extension.api.path.ActionPath;
19 import org.opendaylight.openflowplugin.impl.protocol.deserialization.key.MessageCodeActionExperimenterKey;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction;
21 import org.opendaylight.yangtools.yang.common.Uint8;
24 * Utility class for action deserialization.
26 public final class InstructionUtil {
28 private InstructionUtil() {
32 * Deserialize OpenFlow instruction.
34 * @param version OpenFlow version
35 * @param message OpenFlow buffered message
36 * @param registry deserializer registry
38 public static Instruction readInstruction(final Uint8 version,
39 final ByteBuf message,
40 final DeserializerRegistry registry) {
41 final int type = message.getUnsignedShort(message.readerIndex());
42 final OFDeserializer<Instruction> deserializer;
44 if (InstructionConstants.APPLY_ACTIONS_TYPE == type) {
45 deserializer = registry.getDeserializer(
46 new MessageCodeActionExperimenterKey(
47 version, type, Instruction.class,
48 ActionPath.FLOWS_STATISTICS_UPDATE_APPLY_ACTIONS,
50 } else if (InstructionConstants.WRITE_ACTIONS_TYPE == type) {
51 deserializer = registry.getDeserializer(
52 new MessageCodeActionExperimenterKey(
53 version, type, Instruction.class,
54 ActionPath.FLOWS_STATISTICS_UPDATE_WRITE_ACTIONS,
59 if (EncodeConstants.EXPERIMENTER_VALUE == type) {
60 expId = message.getUnsignedInt(message.readerIndex() + 2 * Short.BYTES);
63 deserializer = registry.getDeserializer(
64 new MessageCodeExperimenterKey(
65 version, type, Instruction.class, expId));
68 return deserializer.deserialize(message);
72 * Deserialize OpenFlow instruction header.
74 * @param version OpenFlow version
75 * @param message OpenFlow buffered message
76 * @param registry deserializer registry
78 public static Instruction readInstructionHeader(final Uint8 version,
79 final ByteBuf message,
80 final DeserializerRegistry registry) {
81 final int type = message.getUnsignedShort(message.readerIndex());
82 final HeaderDeserializer<Instruction> deserializer;
84 if (InstructionConstants.APPLY_ACTIONS_TYPE == type) {
85 deserializer = registry.getDeserializer(
86 new MessageCodeActionExperimenterKey(
87 version, type, Instruction.class,
88 ActionPath.INVENTORY_FLOWNODE_TABLE_APPLY_ACTIONS,
90 } else if (InstructionConstants.WRITE_ACTIONS_TYPE == type) {
91 deserializer = registry.getDeserializer(
92 new MessageCodeActionExperimenterKey(
93 version, type, Instruction.class,
94 ActionPath.INVENTORY_FLOWNODE_TABLE_WRITE_ACTIONS,
99 if (EncodeConstants.EXPERIMENTER_VALUE == type) {
100 expId = message.getUnsignedInt(message.readerIndex() + 2 * Short.BYTES);
103 deserializer = registry.getDeserializer(
104 new MessageCodeExperimenterKey(
105 version, type, Instruction.class, expId));
108 return deserializer.deserializeHeader(message);