Search in sources :

Example 6 with WriteActions

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.actions._case.WriteActions in project openflowplugin by opendaylight.

the class WriteActionsCase method process.

@Override
public Optional<Instruction> process(@Nonnull final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCase source, final ActionConvertorData data, ConvertorExecutor convertorExecutor) {
    WriteActions writeActions = source.getWriteActions();
    WriteActionsCaseBuilder writeActionsCaseBuilder = new WriteActionsCaseBuilder();
    WriteActionsBuilder writeActionsBuilder = new WriteActionsBuilder();
    final Optional<List<Action>> actions = convertorExecutor.convert(writeActions.getAction(), data);
    writeActionsBuilder.setAction(actions.orElse(Collections.emptyList()));
    writeActionsCaseBuilder.setWriteActions(writeActionsBuilder.build());
    InstructionBuilder instructionBuilder = new InstructionBuilder();
    instructionBuilder.setInstructionChoice(writeActionsCaseBuilder.build());
    return Optional.of(instructionBuilder.build());
}
Also used : InstructionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder) WriteActionsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.write.actions._case.WriteActionsBuilder) WriteActionsCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteActionsCaseBuilder) WriteActions(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.actions._case.WriteActions) List(java.util.List)

Example 7 with WriteActions

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.actions._case.WriteActions in project openflowplugin by opendaylight.

the class MultipartReplyFlowStatsDeserializerTest method testDeserialize.

@Test
public void testDeserialize() throws Exception {
    ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    buffer.writeShort(ITEM_LENGTH);
    buffer.writeByte(TABLE_ID);
    buffer.writeZero(PADDING_IN_FLOW_STATS_HEADER_01);
    buffer.writeInt(SECOND);
    buffer.writeInt(NANOSECOND);
    buffer.writeShort(PRIORITY);
    buffer.writeShort(IDLE_TIMEOUT);
    buffer.writeShort(HARD_TIMEOUT);
    buffer.writeShort(ByteBufUtils.fillBitMask(0, FLAGS.isSENDFLOWREM(), FLAGS.isCHECKOVERLAP(), FLAGS.isRESETCOUNTS(), FLAGS.isNOPKTCOUNTS(), FLAGS.isNOBYTCOUNTS()));
    buffer.writeZero(PADDING_IN_FLOW_STATS_HEADER_02);
    buffer.writeLong(COOKIE);
    buffer.writeLong(PACKET_COUNT);
    buffer.writeLong(BYTE_COUNT);
    // 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);
    }
    // Instruction POP PBB 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 instruction
    buffer.setShort(instructionLengthIndex, buffer.writerIndex() - instructionStartIndex);
    // Instruction POP Vlan header
    instructionStartIndex = buffer.writerIndex();
    buffer.writeShort(InstructionConstants.WRITE_ACTIONS_TYPE);
    instructionLengthIndex = buffer.writerIndex();
    buffer.writeShort(EncodeConstants.EMPTY_LENGTH);
    buffer.writeZero(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION);
    // POP Vlan action
    buffer.writeShort(ActionConstants.POP_VLAN_CODE);
    buffer.writeShort(ActionConstants.GENERAL_ACTION_LENGTH);
    buffer.writeZero(ActionConstants.PADDING_IN_ACTION_HEADER);
    // Count total length of instruction
    buffer.setShort(instructionLengthIndex, buffer.writerIndex() - instructionStartIndex);
    final MultipartReplyFlowStats reply = (MultipartReplyFlowStats) deserializeMultipart(buffer);
    final FlowAndStatisticsMapList flowAndStatisticsMapList = reply.getFlowAndStatisticsMapList().get(0);
    assertEquals(TABLE_ID, flowAndStatisticsMapList.getTableId().shortValue());
    assertEquals(SECOND, flowAndStatisticsMapList.getDuration().getSecond().getValue().intValue());
    assertEquals(NANOSECOND, flowAndStatisticsMapList.getDuration().getNanosecond().getValue().intValue());
    assertEquals(PRIORITY, flowAndStatisticsMapList.getPriority().intValue());
    assertEquals(IDLE_TIMEOUT, flowAndStatisticsMapList.getIdleTimeout().intValue());
    assertEquals(HARD_TIMEOUT, flowAndStatisticsMapList.getHardTimeout().intValue());
    assertTrue(flowAndStatisticsMapList.getFlags().equals(FLAGS));
    assertEquals(COOKIE, flowAndStatisticsMapList.getCookie().getValue().longValue());
    assertEquals(BYTE_COUNT, flowAndStatisticsMapList.getByteCount().getValue().longValue());
    assertEquals(PACKET_COUNT, flowAndStatisticsMapList.getPacketCount().getValue().longValue());
    assertEquals(2, flowAndStatisticsMapList.getInstructions().getInstruction().size());
    final Instruction instruction = flowAndStatisticsMapList.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());
    final Instruction instruction1 = flowAndStatisticsMapList.getInstructions().getInstruction().get(1).getInstruction();
    assertEquals(WriteActionsCase.class, instruction1.getImplementedInterface());
    final WriteActionsCase writeActions = WriteActionsCase.class.cast(instruction1);
    assertEquals(1, writeActions.getWriteActions().getAction().size());
    assertEquals(PopVlanActionCase.class, writeActions.getWriteActions().getAction().get(0).getAction().getImplementedInterface());
}
Also used : MultipartReplyFlowStats(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.multipart.reply.multipart.reply.body.MultipartReplyFlowStats) WriteActionsCase(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCase) FlowAndStatisticsMapList(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList) ByteBuf(io.netty.buffer.ByteBuf) 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)

Example 8 with WriteActions

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.actions._case.WriteActions in project genius by opendaylight.

the class FlowBasedServicesUtils method installEgressDispatcherFlow.

private static void installEgressDispatcherFlow(BigInteger dpId, BoundServices boundService, String interfaceName, WriteTransaction writeTransaction, int interfaceTag, short currentServiceIndex, short nextServiceIndex) {
    // Get the metadata and mask from the service's write metadata instruction
    StypeOpenflow stypeOpenflow = boundService.getAugmentation(StypeOpenflow.class);
    if (stypeOpenflow == null) {
        LOG.warn("Could not install egress dispatcher flow, missing service openflow configuration");
        return;
    }
    List<Instruction> serviceInstructions = stypeOpenflow.getInstruction() != null ? stypeOpenflow.getInstruction() : Collections.emptyList();
    // build the final instruction for LPort Dispatcher table flow entry
    List<Action> finalApplyActions = new ArrayList<>();
    List<Instruction> instructions = new ArrayList<>();
    if (boundService.getServicePriority() != ServiceIndex.getIndex(NwConstants.DEFAULT_EGRESS_SERVICE_NAME, NwConstants.DEFAULT_EGRESS_SERVICE_INDEX)) {
        BigInteger[] metadataValues = IfmUtil.mergeOpenflowMetadataWriteInstructions(serviceInstructions);
        BigInteger metadataMask = MetaDataUtil.getWriteMetaDataMaskForEgressDispatcherTable();
        instructions.add(MDSALUtil.buildAndGetWriteMetadaInstruction(metadataValues[0], metadataMask, instructions.size()));
        finalApplyActions.add(MDSALUtil.createSetReg6Action(finalApplyActions.size(), 0, 31, MetaDataUtil.getReg6ValueForLPortDispatcher(interfaceTag, nextServiceIndex)));
    }
    final int applyActionsOffset = finalApplyActions.size();
    for (Instruction info : serviceInstructions) {
        if (info.getInstruction() instanceof WriteActionsCase) {
            List<Action> writeActions = ActionConverterUtil.convertServiceActionToFlowAction(((WriteActionsCase) info.getInstruction()).getWriteActions().getAction());
            instructions.add(MDSALUtil.buildWriteActionsInstruction(writeActions, instructions.size()));
        } else if (info.getInstruction() instanceof ApplyActionsCase) {
            List<Action> applyActions = ActionConverterUtil.convertServiceActionToFlowAction(((ApplyActionsCase) info.getInstruction()).getApplyActions().getAction(), applyActionsOffset);
            finalApplyActions.addAll(applyActions);
        } else if (!(info.getInstruction() instanceof WriteMetadataCase)) {
            // Skip meta data write as that is handled already
            instructions.add(MDSALUtil.buildInstruction(info, instructions.size()));
        }
    }
    if (!finalApplyActions.isEmpty()) {
        instructions.add(MDSALUtil.buildApplyActionsInstruction(finalApplyActions, instructions.size()));
    }
    // build the flow and install it
    String serviceRef = boundService.getServiceName();
    List<? extends MatchInfoBase> matches = FlowBasedServicesUtils.getMatchInfoForEgressDispatcherTable(interfaceTag, currentServiceIndex);
    String flowRef = getFlowRef(dpId, NwConstants.EGRESS_LPORT_DISPATCHER_TABLE, interfaceName, currentServiceIndex);
    Flow egressFlow = MDSALUtil.buildFlowNew(NwConstants.EGRESS_LPORT_DISPATCHER_TABLE, flowRef, boundService.getServicePriority(), serviceRef, 0, 0, stypeOpenflow.getFlowCookie(), matches, instructions);
    LOG.debug("Installing Egress Dispatcher Flow for interface : {}, with flow-ref : {}", interfaceName, flowRef);
    installFlow(dpId, egressFlow, writeTransaction);
}
Also used : Action(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action) WriteMetadataCase(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCase) StypeOpenflow(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.StypeOpenflow) ArrayList(java.util.ArrayList) WriteActionsCase(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCase) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow) BigInteger(java.math.BigInteger) List(java.util.List) BoundServicesStateList(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.BoundServicesStateList) ArrayList(java.util.ArrayList) ApplyActionsCase(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase)

Aggregations

WriteActionsCase (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCase)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Test (org.junit.Test)2 ApplyActionsCase (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase)2 WriteActions (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.actions._case.WriteActions)2 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action)2 WriteActions (org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteActions)2 ByteBuf (io.netty.buffer.ByteBuf)1 BigInteger (java.math.BigInteger)1 SetNwSrcActionCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCaseBuilder)1 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action)1 ActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder)1 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)1 FlowAndStatisticsMapList (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList)1 MultipartReplyFlowStats (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.multipart.reply.multipart.reply.body.MultipartReplyFlowStats)1 Instruction (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction)1 WriteActionsCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCaseBuilder)1 WriteMetadataCase (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCase)1 WriteActionsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.actions._case.WriteActionsBuilder)1