Search in sources :

Example 1 with MultipartReplyTableCase

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

the class MultipartReplyTranslatorUtil method translateTable.

private static MultipartReplyFlowTableStats translateTable(final MultipartReply msg) {
    MultipartReplyFlowTableStatsBuilder message = new MultipartReplyFlowTableStatsBuilder();
    MultipartReplyTableCase caseBody = (MultipartReplyTableCase) msg.getMultipartReplyBody();
    MultipartReplyTable replyBody = caseBody.getMultipartReplyTable();
    List<TableStats> swTablesStats = replyBody.getTableStats();
    List<FlowTableAndStatisticsMap> salFlowStats = new ArrayList<>();
    // TODO: Duplicate code: look at OpendaylightFlowTableStatisticsServiceImpl method transformToNotification
    for (TableStats swTableStats : swTablesStats) {
        FlowTableAndStatisticsMapBuilder statisticsBuilder = new FlowTableAndStatisticsMapBuilder();
        statisticsBuilder.setActiveFlows(new Counter32(swTableStats.getActiveCount()));
        statisticsBuilder.setPacketsLookedUp(new Counter64(swTableStats.getLookupCount()));
        statisticsBuilder.setPacketsMatched(new Counter64(swTableStats.getMatchedCount()));
        statisticsBuilder.setTableId(new TableId(swTableStats.getTableId()));
        salFlowStats.add(statisticsBuilder.build());
    }
    message.setFlowTableAndStatisticsMap(salFlowStats);
    return message.build();
}
Also used : MultipartReplyFlowTableStatsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.multipart.reply.multipart.reply.body.MultipartReplyFlowTableStatsBuilder) FlowTableAndStatisticsMap(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMap) Counter32(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32) TableId(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId) Counter64(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64) MultipartReplyTableCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableCase) ArrayList(java.util.ArrayList) MultipartReplyTable(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.MultipartReplyTable) FlowTableAndStatisticsMapBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMapBuilder) MultipartReplyFlowTableStats(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.multipart.reply.multipart.reply.body.MultipartReplyFlowTableStats) TableStats(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.multipart.reply.table.TableStats)

Example 2 with MultipartReplyTableCase

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

the class OpendaylightFlowTableStatisticsServiceImpl method transformToNotification.

@Override
public FlowTableStatisticsUpdate transformToNotification(List<MultipartReply> mpReplyList, TransactionId emulatedTxId) {
    FlowTableStatisticsUpdateBuilder notification = new FlowTableStatisticsUpdateBuilder();
    notification.setId(getDeviceInfo().getNodeId());
    notification.setMoreReplies(Boolean.FALSE);
    notification.setTransactionId(emulatedTxId);
    final List<FlowTableAndStatisticsMap> salFlowStats = new ArrayList<>();
    notification.setFlowTableAndStatisticsMap(salFlowStats);
    for (MultipartReply mpReply : mpReplyList) {
        MultipartReplyTableCase caseBody = (MultipartReplyTableCase) mpReply.getMultipartReplyBody();
        MultipartReplyTable replyBody = caseBody.getMultipartReplyTable();
        List<TableStats> swTablesStats = replyBody.getTableStats();
        // TODO: Duplicate code: look at MultiReplyTranslatorUtil method translateTable
        for (TableStats swTableStats : swTablesStats) {
            FlowTableAndStatisticsMapBuilder statisticsBuilder = new FlowTableAndStatisticsMapBuilder();
            statisticsBuilder.setActiveFlows(new Counter32(swTableStats.getActiveCount()));
            statisticsBuilder.setPacketsLookedUp(new Counter64(swTableStats.getLookupCount()));
            statisticsBuilder.setPacketsMatched(new Counter64(swTableStats.getMatchedCount()));
            statisticsBuilder.setTableId(new TableId(swTableStats.getTableId()));
            salFlowStats.add(statisticsBuilder.build());
        }
    }
    return notification.build();
}
Also used : TableId(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId) MultipartReplyTableCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableCase) MultipartReply(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply) FlowTableStatisticsUpdateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdateBuilder) ArrayList(java.util.ArrayList) FlowTableAndStatisticsMapBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMapBuilder) TableStats(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.multipart.reply.table.TableStats) FlowTableAndStatisticsMap(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMap) Counter32(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32) Counter64(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64) MultipartReplyTable(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.MultipartReplyTable)

Example 3 with MultipartReplyTableCase

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

the class OF10StatsReplyMessageFactoryTest method testTable.

/**
 * Testing OF10StatsReplyMessageFactory (Table) for correct deserialization.
 */
@Test
public void testTable() {
    ByteBuf bb = BufferHelper.buildBuffer("00 03 00 01 " + "08 00 00 00 4A 41 4D 45 53 20 42 4F 4E 44 00 00 00 00 00 00 00 00 00 " + "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 " + "00 00 00 30 00 00 00 10 FF 01 01 01 01 01 01 01 FF 01 01 01 01 01 01 00");
    MultipartReplyMessage builtByFactory = BufferHelper.deserialize(statsFactory, bb);
    BufferHelper.checkHeaderV10(builtByFactory);
    Assert.assertEquals("Wrong type", 0x03, builtByFactory.getType().getIntValue());
    Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
    MultipartReplyTableCase messageCase = (MultipartReplyTableCase) builtByFactory.getMultipartReplyBody();
    MultipartReplyTable message = messageCase.getMultipartReplyTable();
    Assert.assertEquals("Wrong tableId", 8, message.getTableStats().get(0).getTableId().intValue());
    Assert.assertEquals("Wrong name", "JAMES BOND", message.getTableStats().get(0).getName());
    Assert.assertEquals("Wrong wildcards", new FlowWildcardsV10(false, false, false, false, false, false, false, false, false, false), message.getTableStats().get(0).getWildcards());
    Assert.assertEquals("Wrong src-mask", 32, message.getTableStats().get(0).getNwSrcMask().intValue());
    Assert.assertEquals("Wrong dst-mask", 32, message.getTableStats().get(0).getNwDstMask().intValue());
    Assert.assertEquals("Wrong max-entries", 48, message.getTableStats().get(0).getMaxEntries().longValue());
    Assert.assertEquals("Wrong activeCount", 16, message.getTableStats().get(0).getActiveCount().longValue());
    Assert.assertEquals("Wrong lookupCount", new BigInteger(1, new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), message.getTableStats().get(0).getLookupCount());
    Assert.assertEquals("Wrong matchedCount", new BigInteger(1, new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00 }), message.getTableStats().get(0).getMatchedCount());
    Assert.assertTrue("Unread data", bb.readableBytes() == 0);
}
Also used : MultipartReplyMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage) MultipartReplyTableCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableCase) FlowWildcardsV10(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10) MultipartReplyTable(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.MultipartReplyTable) BigInteger(java.math.BigInteger) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 4 with MultipartReplyTableCase

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

the class MultipartReplyMessageFactory method setTable.

private static MultipartReplyTableCase setTable(final ByteBuf input) {
    MultipartReplyTableCaseBuilder caseBuilder = new MultipartReplyTableCaseBuilder();
    MultipartReplyTableBuilder builder = new MultipartReplyTableBuilder();
    List<TableStats> tableStatsList = new ArrayList<>();
    while (input.readableBytes() > 0) {
        TableStatsBuilder tableStatsBuilder = new TableStatsBuilder();
        tableStatsBuilder.setTableId(input.readUnsignedByte());
        input.skipBytes(PADDING_IN_TABLE_HEADER);
        tableStatsBuilder.setActiveCount(input.readUnsignedInt());
        byte[] lookupCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
        input.readBytes(lookupCount);
        tableStatsBuilder.setLookupCount(new BigInteger(1, lookupCount));
        byte[] matchedCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
        input.readBytes(matchedCount);
        tableStatsBuilder.setMatchedCount(new BigInteger(1, matchedCount));
        tableStatsList.add(tableStatsBuilder.build());
    }
    builder.setTableStats(tableStatsList);
    caseBuilder.setMultipartReplyTable(builder.build());
    return caseBuilder.build();
}
Also used : MultipartReplyTableBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.MultipartReplyTableBuilder) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) TableStatsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.multipart.reply.table.TableStatsBuilder) TableStats(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.multipart.reply.table.TableStats) MultipartReplyTableCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableCaseBuilder)

Example 5 with MultipartReplyTableCase

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

the class OF10StatsReplyMessageFactory method setTable.

private static MultipartReplyTableCase setTable(ByteBuf input) {
    final MultipartReplyTableCaseBuilder caseBuilder = new MultipartReplyTableCaseBuilder();
    MultipartReplyTableBuilder builder = new MultipartReplyTableBuilder();
    List<TableStats> tableStatsList = new ArrayList<>();
    // TODO - replace ">= TABLE_STATS_LENGTH" with "> 0" after fix in OVS switch
    while (input.readableBytes() >= TABLE_STATS_LENGTH) {
        TableStatsBuilder tableStatsBuilder = new TableStatsBuilder();
        tableStatsBuilder.setTableId(input.readUnsignedByte());
        input.skipBytes(PADDING_IN_TABLE_HEADER);
        tableStatsBuilder.setName(ByteBufUtils.decodeNullTerminatedString(input, MAX_TABLE_NAME_LENGTH));
        long wildcards = input.readUnsignedInt();
        tableStatsBuilder.setWildcards(OF10MatchDeserializer.createWildcards(wildcards));
        tableStatsBuilder.setNwSrcMask(OF10MatchDeserializer.decodeNwSrcMask(wildcards));
        tableStatsBuilder.setNwDstMask(OF10MatchDeserializer.decodeNwDstMask(wildcards));
        tableStatsBuilder.setMaxEntries(input.readUnsignedInt());
        tableStatsBuilder.setActiveCount(input.readUnsignedInt());
        byte[] lookupCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
        input.readBytes(lookupCount);
        tableStatsBuilder.setLookupCount(new BigInteger(1, lookupCount));
        byte[] matchedCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
        input.readBytes(matchedCount);
        tableStatsBuilder.setMatchedCount(new BigInteger(1, matchedCount));
        tableStatsList.add(tableStatsBuilder.build());
    }
    input.skipBytes(input.readableBytes());
    builder.setTableStats(tableStatsList);
    caseBuilder.setMultipartReplyTable(builder.build());
    return caseBuilder.build();
}
Also used : MultipartReplyTableBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.MultipartReplyTableBuilder) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) TableStatsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.multipart.reply.table.TableStatsBuilder) TableStats(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.multipart.reply.table.TableStats) MultipartReplyTableCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableCaseBuilder)

Aggregations

MultipartReplyTableCase (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableCase)7 MultipartReplyTable (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.MultipartReplyTable)7 TableStats (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.multipart.reply.table.TableStats)7 BigInteger (java.math.BigInteger)4 ArrayList (java.util.ArrayList)4 ByteBuf (io.netty.buffer.ByteBuf)3 Test (org.junit.Test)3 MultipartReplyMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage)3 MultipartReplyTableCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableCaseBuilder)3 MultipartReplyTableBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.MultipartReplyTableBuilder)3 Counter32 (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32)2 Counter64 (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64)2 FlowTableAndStatisticsMap (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMap)2 FlowTableAndStatisticsMapBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMapBuilder)2 TableStatsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.multipart.reply.table.TableStatsBuilder)2 TableId (org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId)2 FlowTableStatisticsUpdateBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdateBuilder)1 MultipartReplyFlowTableStats (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.multipart.reply.multipart.reply.body.MultipartReplyFlowTableStats)1 MultipartReplyFlowTableStatsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.multipart.reply.multipart.reply.body.MultipartReplyFlowTableStatsBuilder)1 FlowWildcardsV10 (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowWildcardsV10)1