Search in sources :

Example 1 with MultipartReplyFlowStats

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.multipart.reply.multipart.reply.body.MultipartReplyFlowStats in project openflowplugin by opendaylight.

the class MultipartReplyTranslatorUtil method translateFlow.

private static MultipartReplyFlowStats translateFlow(final MultipartReply msg, final VersionDatapathIdConvertorData data, final ConvertorExecutor convertorExecutor) {
    FlowStatsResponseConvertorData flowData = new FlowStatsResponseConvertorData(data.getVersion());
    flowData.setDatapathId(data.getDatapathId());
    flowData.setMatchPath(MatchPath.FLOWS_STATISTICS_UPDATE_MATCH);
    MultipartReplyFlowStatsBuilder message = new MultipartReplyFlowStatsBuilder();
    MultipartReplyFlowCase caseBody = (MultipartReplyFlowCase) msg.getMultipartReplyBody();
    MultipartReplyFlow replyBody = caseBody.getMultipartReplyFlow();
    final Optional<List<FlowAndStatisticsMapList>> flowAndStatisticsMapLists = convertorExecutor.convert(replyBody.getFlowStats(), flowData);
    message.setFlowAndStatisticsMapList(flowAndStatisticsMapLists.orElse(Collections.emptyList()));
    return message.build();
}
Also used : MultipartReplyFlowStatsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.multipart.reply.multipart.reply.body.MultipartReplyFlowStatsBuilder) FlowStatsResponseConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.FlowStatsResponseConvertorData) MultipartReplyFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlow) ArrayList(java.util.ArrayList) List(java.util.List) FlowAndStatisticsMapList(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList) MultipartReplyFlowCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase)

Example 2 with MultipartReplyFlowStats

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.multipart.reply.multipart.reply.body.MultipartReplyFlowStats in project openflowplugin by opendaylight.

the class MultipartReplyMessageDeserializerTest method deserialize.

@Test
public void deserialize() throws Exception {
    ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    buffer.writeByte(TYPE);
    buffer.writeShort(EncodeConstants.EMPTY_LENGTH);
    buffer.writeInt(XID);
    buffer.writeShort(MULTIPART_TYPE);
    buffer.writeShort(REQ_MORE);
    buffer.writeZero(PADDING_IN_MULTIPART_REPLY_HEADER);
    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);
    // Deserialize and check everything
    final MultipartReply message = (MultipartReply) getFactory().deserialize(buffer, EncodeConstants.OF13_VERSION_ID);
    final MultipartReplyFlowStats reply = (MultipartReplyFlowStats) message.getMultipartReplyBody();
    assertEquals(XID, message.getXid().intValue());
    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(1, 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());
}
Also used : MultipartReplyFlowStats(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.multipart.reply.multipart.reply.body.MultipartReplyFlowStats) MultipartReply(org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartReply) 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) AbstractDeserializerTest(org.opendaylight.openflowplugin.impl.protocol.deserialization.AbstractDeserializerTest)

Example 3 with MultipartReplyFlowStats

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.multipart.reply.multipart.reply.body.MultipartReplyFlowStats 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)

Aggregations

FlowAndStatisticsMapList (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList)3 ByteBuf (io.netty.buffer.ByteBuf)2 Test (org.junit.Test)2 MultipartReplyFlowStats (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.multipart.reply.multipart.reply.body.MultipartReplyFlowStats)2 Instruction (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction)2 ApplyActionsCase (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AbstractDeserializerTest (org.opendaylight.openflowplugin.impl.protocol.deserialization.AbstractDeserializerTest)1 FlowStatsResponseConvertorData (org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.FlowStatsResponseConvertorData)1 MultipartReplyFlowStatsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.multipart.reply.multipart.reply.body.MultipartReplyFlowStatsBuilder)1 WriteActionsCase (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCase)1 MultipartReply (org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartReply)1 MultipartReplyFlowCase (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase)1 MultipartReplyFlow (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlow)1