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.util;
11 import java.util.Objects;
13 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
14 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
15 import org.opendaylight.openflowjava.protocol.api.keys.ActionDeserializerKey;
16 import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterActionDeserializerKey;
17 import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
18 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
19 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
20 import org.opendaylight.openflowplugin.api.openflow.protocol.deserialization.MessageCodeExperimenterKey;
21 import org.opendaylight.openflowplugin.extension.api.path.ActionPath;
22 import org.opendaylight.openflowplugin.openflow.md.core.extension.ActionExtensionHelper;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action;
25 import io.netty.buffer.ByteBuf;
28 * Utility class for action deserialization
30 public class ActionUtil {
33 * Deserialize OpenFlow action, using extension converter if available
34 * TODO: Remove also extension converters
36 * @param version OpenFlow version
37 * @param message OpenFlow buffered message
38 * @param registry deserializer registry
39 * @param path Action path
41 public static Action readAction(short version, ByteBuf message, DeserializerRegistry registry,
43 int type = message.getUnsignedShort(message.readerIndex());
46 if (type == EncodeConstants.EXPERIMENTER_VALUE) {
47 expId = message.getUnsignedInt(message.readerIndex()
48 + 2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
52 final MessageCodeExperimenterKey key = new MessageCodeExperimenterKey(
53 version, type, Action.class, expId);
55 final OFDeserializer<Action> deserializer = registry.getDeserializer(key);
57 return deserializer.deserialize(message);
58 } catch (IllegalStateException e) {
59 final MessageCodeKey key = Objects.nonNull(expId)
60 ? new ExperimenterActionDeserializerKey(version, expId)
61 : new ActionDeserializerKey(version, type, expId);
63 final OFDeserializer<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203
64 .actions.grouping.Action> deserializer = registry.getDeserializer(key);
66 return ActionExtensionHelper.processAlienAction(deserializer.deserialize(message),
67 OpenflowVersion.get(version), path);