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;
23 * Utility class for action deserialization.
25 public final class InstructionUtil {
27 private InstructionUtil() {
31 * Deserialize OpenFlow instruction.
33 * @param version OpenFlow version
34 * @param message OpenFlow buffered message
35 * @param registry deserializer registry
37 @SuppressWarnings("checkstyle:LineLength")
38 public static Instruction readInstruction(final short 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 * EncodeConstants.SIZE_OF_SHORT_IN_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 @SuppressWarnings("checkstyle:LineLength")
79 public static Instruction readInstructionHeader(final short version,
80 final ByteBuf message,
81 final DeserializerRegistry registry) {
82 final int type = message.getUnsignedShort(message.readerIndex());
83 final HeaderDeserializer<Instruction> deserializer;
85 if (InstructionConstants.APPLY_ACTIONS_TYPE == type) {
86 deserializer = registry.getDeserializer(
87 new MessageCodeActionExperimenterKey(
88 version, type, Instruction.class,
89 ActionPath.INVENTORY_FLOWNODE_TABLE_APPLY_ACTIONS,
91 } else if (InstructionConstants.WRITE_ACTIONS_TYPE == type) {
92 deserializer = registry.getDeserializer(
93 new MessageCodeActionExperimenterKey(
94 version, type, Instruction.class,
95 ActionPath.INVENTORY_FLOWNODE_TABLE_WRITE_ACTIONS,
100 if (EncodeConstants.EXPERIMENTER_VALUE == type) {
101 expId = message.getUnsignedInt(message.readerIndex() + 2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
104 deserializer = registry.getDeserializer(
105 new MessageCodeExperimenterKey(
106 version, type, Instruction.class, expId));
109 return deserializer.deserializeHeader(message);