Search in sources :

Example 1 with MultipartReplyFlowCase

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase in project openflowplugin by opendaylight.

the class FlowDirectStatisticsServiceTest method testBuildReply.

@Override
public void testBuildReply() throws Exception {
    final MultipartReply reply = mock(MultipartReply.class);
    final MultipartReplyFlowCase flowCase = mock(MultipartReplyFlowCase.class);
    final MultipartReplyFlow flow = mock(MultipartReplyFlow.class);
    final FlowStats flowStat = new FlowStatsBuilder().setDurationSec(1L).setDurationNsec(1L).setTableId(TABLE_NO).setByteCount(BigInteger.ONE).setPacketCount(BigInteger.ONE).setFlags(mock(FlowModFlags.class)).setMatch(new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.MatchBuilder().setMatchEntry(Collections.emptyList()).build()).build();
    final List<FlowStats> flowStats = Collections.singletonList(flowStat);
    final List<MultipartReply> input = Collections.singletonList(reply);
    when(flow.getFlowStats()).thenReturn(flowStats);
    when(flowCase.getMultipartReplyFlow()).thenReturn(flow);
    when(reply.getMultipartReplyBody()).thenReturn(flowCase);
    final GetFlowStatisticsOutput output = service.buildReply(input, true);
    assertTrue(output.getFlowAndStatisticsMapList().size() > 0);
    final FlowAndStatisticsMap stats = output.getFlowAndStatisticsMapList().get(0);
    assertEquals(stats.getTableId(), TABLE_NO);
}
Also used : FlowModFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags) MultipartReply(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply) FlowAndStatisticsMap(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowAndStatisticsMap) MultipartReplyFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlow) MultipartReplyFlowCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase) FlowStats(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStats) FlowStatsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStatsBuilder) GetFlowStatisticsOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutput) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)

Example 2 with MultipartReplyFlowCase

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase 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 3 with MultipartReplyFlowCase

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase in project openflowplugin by opendaylight.

the class MultipartReplyMessageFactory method serializeFlowBody.

private void serializeFlowBody(final MultipartReplyBody body, final ByteBuf outBuffer, final MultipartReplyMessage message) {
    MultipartReplyFlowCase flowCase = (MultipartReplyFlowCase) body;
    MultipartReplyFlow flow = flowCase.getMultipartReplyFlow();
    for (FlowStats flowStats : flow.getFlowStats()) {
        ByteBuf flowStatsBuff = UnpooledByteBufAllocator.DEFAULT.buffer();
        flowStatsBuff.writeShort(EncodeConstants.EMPTY_LENGTH);
        flowStatsBuff.writeByte((byte) flowStats.getTableId().longValue());
        flowStatsBuff.writeZero(FLOW_STATS_PADDING_1);
        flowStatsBuff.writeInt(flowStats.getDurationSec().intValue());
        flowStatsBuff.writeInt(flowStats.getDurationNsec().intValue());
        flowStatsBuff.writeShort(flowStats.getPriority());
        flowStatsBuff.writeShort(flowStats.getIdleTimeout());
        flowStatsBuff.writeShort(flowStats.getHardTimeout());
        flowStatsBuff.writeZero(FLOW_STATS_PADDING_2);
        flowStatsBuff.writeLong(flowStats.getCookie().longValue());
        flowStatsBuff.writeLong(flowStats.getPacketCount().longValue());
        flowStatsBuff.writeLong(flowStats.getByteCount().longValue());
        OFSerializer<Match> matchSerializer = registry.<Match, OFSerializer<Match>>getSerializer(new MessageTypeKey<>(message.getVersion(), Match.class));
        matchSerializer.serialize(flowStats.getMatch(), flowStatsBuff);
        ListSerializer.serializeList(flowStats.getInstruction(), TypeKeyMakerFactory.createInstructionKeyMaker(message.getVersion()), registry, flowStatsBuff);
        flowStatsBuff.setShort(FLOW_STATS_LENGTH_INDEX, flowStatsBuff.readableBytes());
        outBuffer.writeBytes(flowStatsBuff);
    }
}
Also used : FlowStats(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStats) OFSerializer(org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer) MultipartReplyFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlow) MultipartReplyFlowCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase) ByteBuf(io.netty.buffer.ByteBuf) Match(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match)

Example 4 with MultipartReplyFlowCase

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase in project openflowplugin by opendaylight.

the class MultipartReplyMessageFactoryTest method testFlowBody.

private static void testFlowBody(MultipartReplyBody body, ByteBuf output) {
    MultipartReplyFlowCase flowCase = (MultipartReplyFlowCase) body;
    MultipartReplyFlow flow = flowCase.getMultipartReplyFlow();
    FlowStats flowStats = flow.getFlowStats().get(0);
    Assert.assertEquals("Wrong length", 176, output.readShort());
    Assert.assertEquals("Wrong Table ID", flowStats.getTableId().intValue(), output.readUnsignedByte());
    output.skipBytes(1);
    Assert.assertEquals("Wrong duration sec", flowStats.getDurationSec().intValue(), output.readInt());
    Assert.assertEquals("Wrong duration nsec", flowStats.getDurationNsec().intValue(), output.readInt());
    Assert.assertEquals("Wrong priority", flowStats.getPriority().intValue(), output.readShort());
    Assert.assertEquals("Wrong idle timeout", flowStats.getIdleTimeout().intValue(), output.readShort());
    Assert.assertEquals("Wrong hard timeout", flowStats.getHardTimeout().intValue(), output.readShort());
    output.skipBytes(6);
    Assert.assertEquals("Wrong cookie", flowStats.getCookie().longValue(), output.readLong());
    Assert.assertEquals("Wrong Packet count", flowStats.getPacketCount().longValue(), output.readLong());
    Assert.assertEquals("Wrong Byte count", flowStats.getByteCount().longValue(), output.readLong());
    Assert.assertEquals("Wrong match type", 1, output.readUnsignedShort());
    output.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
    Assert.assertEquals("Wrong oxm class", 0x8000, output.readUnsignedShort());
    short fieldAndMask = output.readUnsignedByte();
    Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1);
    Assert.assertEquals("Wrong oxm field", 1, fieldAndMask >> 1);
    output.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
    Assert.assertEquals("Wrong oxm value", 42, output.readUnsignedInt());
    Assert.assertEquals("Wrong oxm class", 0x8000, output.readUnsignedShort());
    fieldAndMask = output.readUnsignedByte();
    Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1);
    Assert.assertEquals("Wrong oxm field", 9, fieldAndMask >> 1);
    output.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
    Assert.assertEquals("Wrong oxm value", 4, output.readUnsignedByte());
    output.skipBytes(7);
    Assert.assertEquals("Wrong instruction type", 1, output.readUnsignedShort());
    Assert.assertEquals("Wrong instruction length", 8, output.readUnsignedShort());
    Assert.assertEquals("Wrong instruction table-id", 5, output.readUnsignedByte());
    output.skipBytes(3);
    Assert.assertEquals("Wrong instruction type", 2, output.readUnsignedShort());
    Assert.assertEquals("Wrong instruction length", 24, output.readUnsignedShort());
    output.skipBytes(4);
    byte[] actual = new byte[8];
    output.readBytes(actual);
    Assert.assertEquals("Wrong instruction metadata", "00 01 02 03 04 05 06 07", ByteBufUtils.bytesToHexString(actual));
    actual = new byte[8];
    output.readBytes(actual);
    Assert.assertEquals("Wrong instruction metadata-mask", "07 06 05 04 03 02 01 00", ByteBufUtils.bytesToHexString(actual));
    Assert.assertEquals("Wrong instruction type", 5, output.readUnsignedShort());
    Assert.assertEquals("Wrong instruction length", 8, output.readUnsignedShort());
    output.skipBytes(4);
    Assert.assertEquals("Wrong instruction type", 6, output.readUnsignedShort());
    Assert.assertEquals("Wrong instruction length", 8, output.readUnsignedShort());
    Assert.assertEquals("Wrong instruction meter-id", 42, output.readUnsignedInt());
    Assert.assertEquals("Wrong instruction type", 3, output.readUnsignedShort());
    Assert.assertEquals("Wrong instruction length", 32, output.readUnsignedShort());
    output.skipBytes(4);
    Assert.assertEquals("Wrong action type", 0, output.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 16, output.readUnsignedShort());
    Assert.assertEquals("Wrong action type", 45, output.readUnsignedInt());
    Assert.assertEquals("Wrong action type", 55, output.readUnsignedShort());
    output.skipBytes(6);
    Assert.assertEquals("Wrong action type", 23, output.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, output.readUnsignedShort());
    Assert.assertEquals("Wrong action type", 64, output.readUnsignedByte());
    output.skipBytes(3);
    Assert.assertEquals("Wrong instruction type", 4, output.readUnsignedShort());
    Assert.assertEquals("Wrong instruction length", 24, output.readUnsignedShort());
    output.skipBytes(4);
    Assert.assertEquals("Wrong action type", 17, output.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, output.readUnsignedShort());
    Assert.assertEquals("Wrong action ethertype", 14, output.readUnsignedShort());
    output.skipBytes(2);
    Assert.assertEquals("Wrong action type", 27, output.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, output.readUnsignedShort());
    output.skipBytes(4);
    Assert.assertTrue("Not all data were read", output.readableBytes() == 0);
}
Also used : FlowStats(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStats) MultipartReplyFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlow) MultipartReplyFlowCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase)

Example 5 with MultipartReplyFlowCase

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase in project openflowplugin by opendaylight.

the class MultipartReplyMessageFactory method setFlow.

private MultipartReplyFlowCase setFlow(final ByteBuf input) {
    MultipartReplyFlowCaseBuilder caseBuilder = new MultipartReplyFlowCaseBuilder();
    MultipartReplyFlowBuilder flowBuilder = new MultipartReplyFlowBuilder();
    List<FlowStats> flowStatsList = new ArrayList<>();
    while (input.readableBytes() > 0) {
        FlowStatsBuilder flowStatsBuilder = new FlowStatsBuilder();
        int flowRecordLength = input.readUnsignedShort();
        ByteBuf subInput = input.readSlice(flowRecordLength - EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
        flowStatsBuilder.setTableId(subInput.readUnsignedByte());
        subInput.skipBytes(PADDING_IN_FLOW_STATS_HEADER_01);
        flowStatsBuilder.setDurationSec(subInput.readUnsignedInt());
        flowStatsBuilder.setDurationNsec(subInput.readUnsignedInt());
        flowStatsBuilder.setPriority(subInput.readUnsignedShort());
        flowStatsBuilder.setIdleTimeout(subInput.readUnsignedShort());
        flowStatsBuilder.setHardTimeout(subInput.readUnsignedShort());
        flowStatsBuilder.setFlags(createFlowModFlagsFromBitmap(subInput.readUnsignedShort()));
        subInput.skipBytes(PADDING_IN_FLOW_STATS_HEADER_02);
        byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
        subInput.readBytes(cookie);
        flowStatsBuilder.setCookie(new BigInteger(1, cookie));
        byte[] packetCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
        subInput.readBytes(packetCount);
        flowStatsBuilder.setPacketCount(new BigInteger(1, packetCount));
        byte[] byteCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
        subInput.readBytes(byteCount);
        flowStatsBuilder.setByteCount(new BigInteger(1, byteCount));
        OFDeserializer<Match> matchDeserializer = registry.getDeserializer(new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, EncodeConstants.EMPTY_VALUE, Match.class));
        flowStatsBuilder.setMatch(matchDeserializer.deserialize(subInput));
        CodeKeyMaker keyMaker = CodeKeyMakerFactory.createInstructionsKeyMaker(EncodeConstants.OF13_VERSION_ID);
        List<Instruction> instructions = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID, subInput.readableBytes(), subInput, keyMaker, registry);
        flowStatsBuilder.setInstruction(instructions);
        flowStatsList.add(flowStatsBuilder.build());
    }
    flowBuilder.setFlowStats(flowStatsList);
    caseBuilder.setMultipartReplyFlow(flowBuilder.build());
    return caseBuilder.build();
}
Also used : ArrayList(java.util.ArrayList) MultipartReplyFlowCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCaseBuilder) ByteBuf(io.netty.buffer.ByteBuf) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction) Match(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match) FlowStats(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStats) FlowStatsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStatsBuilder) MessageCodeKey(org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey) CodeKeyMaker(org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMaker) BigInteger(java.math.BigInteger) MultipartReplyFlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlowBuilder)

Aggregations

MultipartReplyFlowCase (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase)10 MultipartReplyFlow (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlow)10 FlowStats (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStats)7 ByteBuf (io.netty.buffer.ByteBuf)6 ArrayList (java.util.ArrayList)5 BigInteger (java.math.BigInteger)4 List (java.util.List)3 Test (org.junit.Test)3 FlowAndStatisticsMapList (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList)3 MultipartReply (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply)3 MultipartReplyMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage)3 FlowStatsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStatsBuilder)3 MessageCodeKey (org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey)2 CodeKeyMaker (org.opendaylight.openflowjava.protocol.impl.util.CodeKeyMaker)2 FlowStatsResponseConvertorData (org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.FlowStatsResponseConvertorData)2 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action)2 FlowModFlags (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags)2 Match (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match)2 MatchV10 (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.v10.grouping.MatchV10)2 MultipartReplyFlowCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCaseBuilder)2