Search in sources :

Example 1 with FlowMessage

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowMessage 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 2 with FlowMessage

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowMessage in project openflowplugin by opendaylight.

the class FlowMessageSerializer method writeVlanFlow.

/**
 * Instead of serializing this flow normally, we need to split it to two parts if flow contains
 * #{@link org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCase}.
 *
 * @param message   flow mod message
 * @param outBuffer output buffer
 */
private void writeVlanFlow(final FlowMessage message, final ByteBuf outBuffer) {
    writeFlow(new FlowMessageBuilder(message).setMatch(new MatchBuilder(message.getMatch()).setVlanMatch(VLAN_MATCH_FALSE).build()).setInstructions(new InstructionsBuilder().setInstruction(updateSetVlanIdAction(message)).build()).build(), outBuffer);
    writeFlow(new FlowMessageBuilder(message).setMatch(new MatchBuilder(message.getMatch()).setVlanMatch(VLAN_MATCH_TRUE).build()).build(), outBuffer);
}
Also used : FlowMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowMessageBuilder) VlanMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder) InstructionsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder)

Example 3 with FlowMessage

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowMessage in project openflowplugin by opendaylight.

the class SingleLayerFlowServiceTest method buildRequest.

@Test
public void buildRequest() throws Exception {
    final AddFlowInput input = new AddFlowInputBuilder().setTableId(TABLE_ID).build();
    final OfHeader ofHeader = service.buildRequest(DUMMY_XID, input);
    assertEquals(FlowMessage.class, ofHeader.getImplementedInterface());
    final FlowMessage result = FlowMessage.class.cast(ofHeader);
    assertEquals(FlowModCommand.OFPFCADD, result.getCommand());
    assertEquals(TABLE_ID, result.getTableId().shortValue());
}
Also used : OfHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader) AddFlowInput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput) AddFlowInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder) FlowMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowMessage) Test(org.junit.Test)

Example 4 with FlowMessage

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowMessage in project openflowplugin by opendaylight.

the class FlowMessageDeserializerTest method deserialize.

@Test
public void deserialize() throws Exception {
    // Flow header
    buffer.writeByte(TYPE);
    buffer.writeShort(EncodeConstants.EMPTY_LENGTH);
    buffer.writeInt(XID);
    buffer.writeLong(COOKIE);
    buffer.writeLong(COOKIE_MASK);
    buffer.writeByte(TABLE_ID);
    buffer.writeByte(COMMAND.getIntValue());
    buffer.writeShort(IDLE_TIMEOUT);
    buffer.writeShort(HARD_TIMEOUT);
    buffer.writeShort(PRIORITY);
    buffer.writeInt(BUFFER_ID);
    buffer.writeInt(OUT_PORT);
    buffer.writeInt(OUT_GROUP);
    buffer.writeShort(ByteBufUtils.fillBitMask(0, FLAGS.isSENDFLOWREM(), FLAGS.isCHECKOVERLAP(), FLAGS.isRESETCOUNTS(), FLAGS.isNOPKTCOUNTS(), FLAGS.isNOBYTCOUNTS()));
    buffer.writeZero(PADDING);
    // Match header
    int matchStartIndex = buffer.writerIndex();
    buffer.writeShort(OXM_MATCH_TYPE_CODE);
    int matchLengthIndex = buffer.writerIndex();
    buffer.writeShort(EncodeConstants.EMPTY_LENGTH);
    // MplsLabel match
    buffer.writeShort(OxmMatchConstants.OPENFLOW_BASIC_CLASS);
    buffer.writeByte(OxmMatchConstants.MPLS_LABEL << 1);
    buffer.writeByte(EncodeConstants.SIZE_OF_INT_IN_BYTES);
    buffer.writeInt(MPLS_LABEL);
    // Match footer
    int matchLength = buffer.writerIndex() - matchStartIndex;
    buffer.setShort(matchLengthIndex, matchLength);
    int paddingRemainder = matchLength % EncodeConstants.PADDING;
    if (paddingRemainder != 0) {
        buffer.writeZero(EncodeConstants.PADDING - paddingRemainder);
    }
    // Instructions header
    int instructionStartIndex = buffer.writerIndex();
    buffer.writeShort(InstructionConstants.APPLY_ACTIONS_TYPE);
    int instructionLengthIndex = buffer.writerIndex();
    buffer.writeShort(EncodeConstants.EMPTY_LENGTH);
    buffer.writeZero(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION);
    // POP PBB action
    buffer.writeShort(ActionConstants.POP_PBB_CODE);
    buffer.writeShort(ActionConstants.GENERAL_ACTION_LENGTH);
    buffer.writeZero(ActionConstants.PADDING_IN_ACTION_HEADER);
    // Count total length of instructions
    buffer.setShort(instructionLengthIndex, buffer.writerIndex() - instructionStartIndex);
    // Deserialize and check everything
    final FlowMessage message = (FlowMessage) getFactory().deserialize(buffer, EncodeConstants.OF13_VERSION_ID);
    assertEquals(XID, message.getXid().intValue());
    assertEquals(COMMAND.getIntValue(), message.getCommand().getIntValue());
    assertEquals(MPLS_LABEL, message.getMatch().getProtocolMatchFields().getMplsLabel().intValue());
    assertEquals(1, message.getInstructions().getInstruction().size());
    final Instruction instruction = message.getInstructions().getInstruction().get(0).getInstruction();
    assertEquals(ApplyActionsCase.class, instruction.getImplementedInterface());
    final ApplyActionsCase applyActions = ApplyActionsCase.class.cast(instruction);
    assertEquals(1, applyActions.getApplyActions().getAction().size());
    assertEquals(PopPbbActionCase.class, applyActions.getApplyActions().getAction().get(0).getAction().getImplementedInterface());
}
Also used : FlowMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowMessage) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction) ApplyActionsCase(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase) Test(org.junit.Test) AbstractDeserializerTest(org.opendaylight.openflowplugin.impl.protocol.deserialization.AbstractDeserializerTest)

Aggregations

Test (org.junit.Test)2 FlowMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowMessage)2 FlowMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowMessageBuilder)2 InstructionsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder)2 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)2 Instruction (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction)2 ArrayList (java.util.ArrayList)1 MessageCodeExperimenterKey (org.opendaylight.openflowplugin.api.openflow.protocol.deserialization.MessageCodeExperimenterKey)1 AbstractDeserializerTest (org.opendaylight.openflowplugin.impl.protocol.deserialization.AbstractDeserializerTest)1 MessageCodeActionExperimenterKey (org.opendaylight.openflowplugin.impl.protocol.deserialization.key.MessageCodeActionExperimenterKey)1 AddFlowInput (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput)1 AddFlowInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder)1 FlowCookie (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie)1 ApplyActionsCase (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase)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 VlanMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder)1 OfHeader (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader)1