Search in sources :

Example 1 with MessageCodeExperimenterKey

use of org.opendaylight.openflowplugin.api.openflow.protocol.deserialization.MessageCodeExperimenterKey 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 MessageCodeExperimenterKey

use of org.opendaylight.openflowplugin.api.openflow.protocol.deserialization.MessageCodeExperimenterKey in project openflowplugin by opendaylight.

the class FlowMessageDeserializer method deserialize.

@Override
@SuppressWarnings("checkstyle:LineLength")
public FlowMessage deserialize(ByteBuf message) {
    final FlowMessageBuilder builder = new FlowMessageBuilder().setVersion((short) EncodeConstants.OF13_VERSION_ID).setXid(message.readUnsignedInt()).setCookie(new FlowCookie(BigInteger.valueOf(message.readLong()))).setCookieMask(new FlowCookie(BigInteger.valueOf(message.readLong()))).setTableId(message.readUnsignedByte()).setCommand(FlowModCommand.forValue(message.readUnsignedByte())).setIdleTimeout(message.readUnsignedShort()).setHardTimeout(message.readUnsignedShort()).setPriority(message.readUnsignedShort()).setBufferId(message.readUnsignedInt()).setOutPort(BigInteger.valueOf(message.readUnsignedInt())).setOutGroup(message.readUnsignedInt()).setFlags(createFlowModFlagsFromBitmap(message.readUnsignedShort()));
    message.skipBytes(PADDING);
    final OFDeserializer<Match> matchDeserializer = Preconditions.checkNotNull(registry).getDeserializer(MATCH_KEY);
    builder.setMatch(new MatchBuilder(matchDeserializer.deserialize(message)).build());
    final int length = message.readableBytes();
    if (length > 0) {
        final List<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction> instructions = new ArrayList<>();
        final int startIndex = message.readerIndex();
        int offset = 0;
        while (message.readerIndex() - startIndex < length) {
            final int type = message.getUnsignedShort(message.readerIndex());
            OFDeserializer<Instruction> deserializer = null;
            if (InstructionConstants.APPLY_ACTIONS_TYPE == type) {
                deserializer = Preconditions.checkNotNull(registry).getDeserializer(new MessageCodeActionExperimenterKey(EncodeConstants.OF13_VERSION_ID, type, Instruction.class, ActionPath.INVENTORY_FLOWNODE_TABLE_APPLY_ACTIONS, null));
            } else if (InstructionConstants.WRITE_ACTIONS_TYPE == type) {
                deserializer = Preconditions.checkNotNull(registry).getDeserializer(new MessageCodeActionExperimenterKey(EncodeConstants.OF13_VERSION_ID, type, Instruction.class, ActionPath.INVENTORY_FLOWNODE_TABLE_WRITE_ACTIONS, null));
            } else {
                Long expId = null;
                if (EncodeConstants.EXPERIMENTER_VALUE == type) {
                    expId = message.getUnsignedInt(message.readerIndex() + 2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
                }
                deserializer = Preconditions.checkNotNull(registry).getDeserializer(new MessageCodeExperimenterKey(EncodeConstants.OF13_VERSION_ID, type, Instruction.class, expId));
            }
            instructions.add(new InstructionBuilder().setKey(new InstructionKey(offset)).setOrder(offset).setInstruction(deserializer.deserialize(message)).build());
            offset++;
        }
        builder.setInstructions(new InstructionsBuilder().setInstruction(instructions).build());
    }
    return builder.build();
}
Also used : InstructionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder) ArrayList(java.util.ArrayList) FlowMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowMessageBuilder) InstructionKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction) MessageCodeExperimenterKey(org.opendaylight.openflowplugin.api.openflow.protocol.deserialization.MessageCodeExperimenterKey) Match(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match) InstructionsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder) FlowCookie(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder) MessageCodeActionExperimenterKey(org.opendaylight.openflowplugin.impl.protocol.deserialization.key.MessageCodeActionExperimenterKey)

Example 3 with MessageCodeExperimenterKey

use of org.opendaylight.openflowplugin.api.openflow.protocol.deserialization.MessageCodeExperimenterKey in project openflowplugin by opendaylight.

the class InstructionUtil method readInstructionHeader.

/**
 * Deserialize OpenFlow instruction header.
 *
 * @param version  OpenFlow version
 * @param message  OpenFlow buffered message
 * @param registry deserializer registry
 */
@SuppressWarnings("checkstyle:LineLength")
public static Instruction readInstructionHeader(final short version, final ByteBuf message, final DeserializerRegistry registry) {
    final int type = message.getUnsignedShort(message.readerIndex());
    final HeaderDeserializer<Instruction> deserializer;
    if (InstructionConstants.APPLY_ACTIONS_TYPE == type) {
        deserializer = registry.getDeserializer(new MessageCodeActionExperimenterKey(version, type, Instruction.class, ActionPath.INVENTORY_FLOWNODE_TABLE_APPLY_ACTIONS, null));
    } else if (InstructionConstants.WRITE_ACTIONS_TYPE == type) {
        deserializer = registry.getDeserializer(new MessageCodeActionExperimenterKey(version, type, Instruction.class, ActionPath.INVENTORY_FLOWNODE_TABLE_WRITE_ACTIONS, null));
    } else {
        Long expId = null;
        if (EncodeConstants.EXPERIMENTER_VALUE == type) {
            expId = message.getUnsignedInt(message.readerIndex() + 2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
        }
        deserializer = registry.getDeserializer(new MessageCodeExperimenterKey(version, type, Instruction.class, expId));
    }
    return deserializer.deserializeHeader(message);
}
Also used : Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction) MessageCodeExperimenterKey(org.opendaylight.openflowplugin.api.openflow.protocol.deserialization.MessageCodeExperimenterKey) MessageCodeActionExperimenterKey(org.opendaylight.openflowplugin.impl.protocol.deserialization.key.MessageCodeActionExperimenterKey)

Example 4 with MessageCodeExperimenterKey

use of org.opendaylight.openflowplugin.api.openflow.protocol.deserialization.MessageCodeExperimenterKey in project openflowplugin by opendaylight.

the class InstructionUtil method readInstruction.

/**
 * Deserialize OpenFlow instruction.
 *
 * @param version  OpenFlow version
 * @param message  OpenFlow buffered message
 * @param registry deserializer registry
 */
@SuppressWarnings("checkstyle:LineLength")
public static Instruction readInstruction(final short version, final ByteBuf message, final DeserializerRegistry registry) {
    final int type = message.getUnsignedShort(message.readerIndex());
    final OFDeserializer<Instruction> deserializer;
    if (InstructionConstants.APPLY_ACTIONS_TYPE == type) {
        deserializer = registry.getDeserializer(new MessageCodeActionExperimenterKey(version, type, Instruction.class, ActionPath.FLOWS_STATISTICS_UPDATE_APPLY_ACTIONS, null));
    } else if (InstructionConstants.WRITE_ACTIONS_TYPE == type) {
        deserializer = registry.getDeserializer(new MessageCodeActionExperimenterKey(version, type, Instruction.class, ActionPath.FLOWS_STATISTICS_UPDATE_WRITE_ACTIONS, null));
    } else {
        Long expId = null;
        if (EncodeConstants.EXPERIMENTER_VALUE == type) {
            expId = message.getUnsignedInt(message.readerIndex() + 2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
        }
        deserializer = registry.getDeserializer(new MessageCodeExperimenterKey(version, type, Instruction.class, expId));
    }
    return deserializer.deserialize(message);
}
Also used : Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction) MessageCodeExperimenterKey(org.opendaylight.openflowplugin.api.openflow.protocol.deserialization.MessageCodeExperimenterKey) MessageCodeActionExperimenterKey(org.opendaylight.openflowplugin.impl.protocol.deserialization.key.MessageCodeActionExperimenterKey)

Example 5 with MessageCodeExperimenterKey

use of org.opendaylight.openflowplugin.api.openflow.protocol.deserialization.MessageCodeExperimenterKey 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

MessageCodeExperimenterKey (org.opendaylight.openflowplugin.api.openflow.protocol.deserialization.MessageCodeExperimenterKey)5 MessageCodeActionExperimenterKey (org.opendaylight.openflowplugin.impl.protocol.deserialization.key.MessageCodeActionExperimenterKey)3 Instruction (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction)3 ActionDeserializerKey (org.opendaylight.openflowjava.protocol.api.keys.ActionDeserializerKey)2 ExperimenterActionDeserializerKey (org.opendaylight.openflowjava.protocol.api.keys.ExperimenterActionDeserializerKey)2 MessageCodeKey (org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey)2 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action)2 ArrayList (java.util.ArrayList)1 HeaderDeserializer (org.opendaylight.openflowjava.protocol.api.extensibility.HeaderDeserializer)1 OFDeserializer (org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer)1 FlowCookie (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie)1 FlowMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowMessageBuilder)1 InstructionsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder)1 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)1 InstructionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder)1 InstructionKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey)1 Match (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match)1