use of org.openkilda.messaging.info.stats.TableStatsEntry in project open-kilda by telstra.
the class StatisticsService method gatherTableStats.
@NewCorrelationContextRequired
private void gatherTableStats(IOFSwitch iofSwitch) {
final SwitchId switchId = new SwitchId(iofSwitch.getId().getLong());
OFFactory factory = iofSwitch.getOFFactory();
OFTableStatsRequest flowStatsRequest = factory.buildTableStatsRequest().build();
logger.info("Getting table stats for switch={} OF-xid:{}", iofSwitch.getId(), flowStatsRequest.getXid());
if (factory.getVersion().compareTo(OFVersion.OF_13) >= 0) {
Function<List<OFTableStatsReply>, InfoData> converter = (response) -> {
List<TableStatsEntry> tableEntries = response.stream().filter(reply -> CollectionUtils.isNotEmpty(reply.getEntries())).map(OFTableStatsReply::getEntries).flatMap(List::stream).filter(entry -> entry.getActiveCount() != NumberUtils.LONG_ZERO).map(OfTableStatsMapper.INSTANCE::toTableStatsEntry).collect(Collectors.toList());
return SwitchTableStatsData.builder().switchId(switchId).tableStatsEntries(tableEntries).build();
};
RequestCallback<OFTableStatsReply> callback = new RequestCallback<>(converter, switchId, "table");
Futures.addCallback(iofSwitch.writeStatsRequest(flowStatsRequest), callback, directExecutor());
}
}
use of org.openkilda.messaging.info.stats.TableStatsEntry in project open-kilda by telstra.
the class OfTableStatsMapperTest method shouldConvertSuccessfully.
@Test
public void shouldConvertSuccessfully() {
OFFactoryVer13 ofFactoryVer13 = new OFFactoryVer13();
OFTableStatsEntry entry = ofFactoryVer13.buildTableStatsEntry().setTableId(TableId.of(11)).setActiveCount(10).setMatchedCount(U64.of(100001L)).setLookupCount(U64.of(100002L)).build();
TableStatsEntry result = OfTableStatsMapper.INSTANCE.toTableStatsEntry(entry);
assertEquals(result.getTableId(), entry.getTableId().getValue());
assertEquals(result.getActiveEntries(), entry.getActiveCount());
assertEquals(result.getLookupCount(), entry.getLookupCount().getValue());
assertEquals(result.getMatchedCount(), entry.getMatchedCount().getValue());
}
use of org.openkilda.messaging.info.stats.TableStatsEntry in project open-kilda by telstra.
the class StatsTopologyTest method tableStatsTest.
@Test
public void tableStatsTest() {
TableStatsEntry entry = TableStatsEntry.builder().tableId(1).activeEntries(100).lookupCount(2000).matchedCount(1900).build();
SwitchTableStatsData tableStatsData = SwitchTableStatsData.builder().switchId(SWITCH_ID_1).tableStatsEntries(ImmutableList.of(entry)).build();
sendStatsMessage(tableStatsData);
List<Datapoint> datapoints = pollDatapoints(4);
Map<String, Datapoint> datapointMap = createDatapointMap(datapoints);
assertEquals(entry.getActiveEntries(), datapointMap.get(METRIC_PREFIX + "switch.table.active").getValue().intValue());
assertEquals(entry.getLookupCount(), datapointMap.get(METRIC_PREFIX + "switch.table.lookup").getValue().longValue());
assertEquals(entry.getMatchedCount(), datapointMap.get(METRIC_PREFIX + "switch.table.matched").getValue().longValue());
assertEquals(entry.getLookupCount() - entry.getMatchedCount(), datapointMap.get(METRIC_PREFIX + "switch.table.missed").getValue().longValue());
datapoints.forEach(datapoint -> {
assertEquals(SWITCH_ID_1.toOtsdFormat(), datapoint.getTags().get("switchid"));
assertEquals(entry.getTableId(), Integer.parseInt(datapoint.getTags().get("tableid")));
assertEquals(timestamp, datapoint.getTime().longValue());
});
}
Aggregations