Search in sources :

Example 1 with ActionDeserializerKey

use of org.opendaylight.openflowjava.protocol.api.keys.ActionDeserializerKey in project openflowplugin by opendaylight.

the class ActionUtil method readAction.

/**
 * Deserialize OpenFlow action, using extension converter if available.
 * TODO: Remove also extension converters
 *
 * @param version  OpenFlow version
 * @param message  OpenFlow buffered message
 * @param registry deserializer registry
 * @param path     Action path
 */
public static Action readAction(short version, ByteBuf message, DeserializerRegistry registry, ActionPath path) {
    int type = message.getUnsignedShort(message.readerIndex());
    Long expId = null;
    if (type == EncodeConstants.EXPERIMENTER_VALUE) {
        expId = message.getUnsignedInt(message.readerIndex() + 2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
    }
    try {
        final MessageCodeExperimenterKey key = new MessageCodeExperimenterKey(version, type, Action.class, expId);
        final OFDeserializer<Action> deserializer = registry.getDeserializer(key);
        return deserializer.deserialize(message);
    } catch (ClassCastException | IllegalStateException e) {
        final MessageCodeKey key = Objects.nonNull(expId) ? new ExperimenterActionDeserializerKey(version, expId) : new ActionDeserializerKey(version, type, expId);
        final OFDeserializer<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action> deserializer = registry.getDeserializer(key);
        return ActionExtensionHelper.processAlienAction(deserializer.deserialize(message), OpenflowVersion.get(version), path);
    }
}
Also used : ExperimenterActionDeserializerKey(org.opendaylight.openflowjava.protocol.api.keys.ExperimenterActionDeserializerKey) OFDeserializer(org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer) Action(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action) MessageCodeExperimenterKey(org.opendaylight.openflowplugin.api.openflow.protocol.deserialization.MessageCodeExperimenterKey) MessageCodeKey(org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey) ExperimenterActionDeserializerKey(org.opendaylight.openflowjava.protocol.api.keys.ExperimenterActionDeserializerKey) ActionDeserializerKey(org.opendaylight.openflowjava.protocol.api.keys.ActionDeserializerKey)

Example 2 with ActionDeserializerKey

use of org.opendaylight.openflowjava.protocol.api.keys.ActionDeserializerKey in project openflowplugin by opendaylight.

the class CodeKeyMakerFactory method createActionsKeyMaker.

public static CodeKeyMaker createActionsKeyMaker(short version) {
    return new AbstractCodeKeyMaker(version) {

        @Override
        public MessageCodeKey make(ByteBuf input) {
            int type = input.getUnsignedShort(input.readerIndex());
            if (type == EncodeConstants.EXPERIMENTER_VALUE) {
                Long expId = input.getUnsignedInt(input.readerIndex() + 2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
                return new ExperimenterActionDeserializerKey(getVersion(), expId);
            }
            ActionDeserializerKey actionDeserializerKey = new ActionDeserializerKey(getVersion(), type, null);
            return actionDeserializerKey;
        }
    };
}
Also used : ExperimenterActionDeserializerKey(org.opendaylight.openflowjava.protocol.api.keys.ExperimenterActionDeserializerKey) ByteBuf(io.netty.buffer.ByteBuf) ExperimenterActionDeserializerKey(org.opendaylight.openflowjava.protocol.api.keys.ExperimenterActionDeserializerKey) ActionDeserializerKey(org.opendaylight.openflowjava.protocol.api.keys.ActionDeserializerKey)

Example 3 with ActionDeserializerKey

use of org.opendaylight.openflowjava.protocol.api.keys.ActionDeserializerKey in project openflowplugin by opendaylight.

the class CodeKeyMakerFactoryTest method testActionKeyMaker.

/**
 * Tests {@link CodeKeyMakerFactory#createActionsKeyMaker(short)}.
 */
@Test
public void testActionKeyMaker() {
    CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF13_VERSION_ID);
    Assert.assertNotNull("Null key maker", keyMaker);
    ByteBuf buffer = BufferHelper.buildBuffer("00 00 00 10 00 00 00 01 00 02 00 00 00 00 00 00");
    // skip XID
    buffer.skipBytes(4);
    MessageCodeKey codeKey = keyMaker.make(buffer);
    Assert.assertNotNull("Null key", codeKey);
    Assert.assertEquals("Wrong key", new ActionDeserializerKey(EncodeConstants.OF13_VERSION_ID, 0, null), codeKey);
    Assert.assertEquals("Buffer index modified", 16, buffer.readableBytes());
}
Also used : MessageCodeKey(org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey) ByteBuf(io.netty.buffer.ByteBuf) ActionDeserializerKey(org.opendaylight.openflowjava.protocol.api.keys.ActionDeserializerKey) Test(org.junit.Test)

Example 4 with ActionDeserializerKey

use of org.opendaylight.openflowjava.protocol.api.keys.ActionDeserializerKey in project openflowplugin by opendaylight.

the class CodeKeyMakerFactoryTest method testExperimenterActionKeyMaker.

/**
 * Tests {@link CodeKeyMakerFactory#createActionsKeyMaker(short)}.
 */
@Test
public void testExperimenterActionKeyMaker() {
    CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF13_VERSION_ID);
    Assert.assertNotNull("Null key maker", keyMaker);
    ByteBuf buffer = BufferHelper.buildBuffer("FF FF 00 08 00 00 00 01");
    // skip XID
    buffer.skipBytes(4);
    MessageCodeKey codeKey = keyMaker.make(buffer);
    Assert.assertNotNull("Null key", codeKey);
    Assert.assertEquals("Wrong key", new ActionDeserializerKey(EncodeConstants.OF13_VERSION_ID, 65535, 1L), codeKey);
    Assert.assertEquals("Buffer index modified", 8, buffer.readableBytes());
}
Also used : MessageCodeKey(org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey) ByteBuf(io.netty.buffer.ByteBuf) ActionDeserializerKey(org.opendaylight.openflowjava.protocol.api.keys.ActionDeserializerKey) Test(org.junit.Test)

Example 5 with ActionDeserializerKey

use of org.opendaylight.openflowjava.protocol.api.keys.ActionDeserializerKey in project openflowplugin by opendaylight.

the class ActionUtil method readActionHeader.

/**
 * Deserialize OpenFlow action header, using extension converter if available.
 * TODO: Remove also extension converters
 *
 * @param version  OpenFlow version
 * @param message  OpenFlow buffered message
 * @param registry deserializer registry
 * @param path     Action path
 */
public static Action readActionHeader(short version, ByteBuf message, DeserializerRegistry registry, ActionPath path) {
    int type = message.getUnsignedShort(message.readerIndex());
    Long expId = null;
    if (type == EncodeConstants.EXPERIMENTER_VALUE) {
        expId = message.getUnsignedInt(message.readerIndex() + 2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
    }
    try {
        final MessageCodeExperimenterKey key = new MessageCodeExperimenterKey(version, type, Action.class, expId);
        final HeaderDeserializer<Action> deserializer = registry.getDeserializer(key);
        return deserializer.deserializeHeader(message);
    } catch (ClassCastException | IllegalStateException e) {
        final MessageCodeKey key = Objects.nonNull(expId) ? new ExperimenterActionDeserializerKey(version, expId) : new ActionDeserializerKey(version, type, expId);
        final HeaderDeserializer<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action> deserializer = registry.getDeserializer(key);
        return ActionExtensionHelper.processAlienAction(deserializer.deserializeHeader(message), OpenflowVersion.get(version), path);
    }
}
Also used : ExperimenterActionDeserializerKey(org.opendaylight.openflowjava.protocol.api.keys.ExperimenterActionDeserializerKey) Action(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action) HeaderDeserializer(org.opendaylight.openflowjava.protocol.api.extensibility.HeaderDeserializer) MessageCodeExperimenterKey(org.opendaylight.openflowplugin.api.openflow.protocol.deserialization.MessageCodeExperimenterKey) MessageCodeKey(org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey) ExperimenterActionDeserializerKey(org.opendaylight.openflowjava.protocol.api.keys.ExperimenterActionDeserializerKey) ActionDeserializerKey(org.opendaylight.openflowjava.protocol.api.keys.ActionDeserializerKey)

Aggregations

ActionDeserializerKey (org.opendaylight.openflowjava.protocol.api.keys.ActionDeserializerKey)5 MessageCodeKey (org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey)4 ByteBuf (io.netty.buffer.ByteBuf)3 ExperimenterActionDeserializerKey (org.opendaylight.openflowjava.protocol.api.keys.ExperimenterActionDeserializerKey)3 Test (org.junit.Test)2 MessageCodeExperimenterKey (org.opendaylight.openflowplugin.api.openflow.protocol.deserialization.MessageCodeExperimenterKey)2 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action)2 HeaderDeserializer (org.opendaylight.openflowjava.protocol.api.extensibility.HeaderDeserializer)1 OFDeserializer (org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer)1