Search in sources :

Example 1 with TableStatsEntry

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());
    }
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) OfTableStatsMapper(org.openkilda.floodlight.converter.OfTableStatsMapper) OFStatsReply(org.projectfloodlight.openflow.protocol.OFStatsReply) OFPortStatsRequest(org.projectfloodlight.openflow.protocol.OFPortStatsRequest) OFFlowStatsRequest(org.projectfloodlight.openflow.protocol.OFFlowStatsRequest) LoggerFactory(org.slf4j.LoggerFactory) IOFSwitch(net.floodlightcontroller.core.IOFSwitch) OfFlowStatsMapper(org.openkilda.floodlight.converter.OfFlowStatsMapper) Map(java.util.Map) OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) IKafkaProducerService(org.openkilda.floodlight.service.kafka.IKafkaProducerService) Collection(java.util.Collection) Set(java.util.Set) InfoData(org.openkilda.messaging.info.InfoData) FloodlightModuleContext(net.floodlightcontroller.core.module.FloodlightModuleContext) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) OFTableStatsRequest(org.projectfloodlight.openflow.protocol.OFTableStatsRequest) MoreExecutors.directExecutor(com.google.common.util.concurrent.MoreExecutors.directExecutor) OFPort(org.projectfloodlight.openflow.types.OFPort) CorrelationContext(org.openkilda.floodlight.utils.CorrelationContext) List(java.util.List) IFloodlightProviderService(net.floodlightcontroller.core.IFloodlightProviderService) OfPortStatsMapper(org.openkilda.floodlight.converter.OfPortStatsMapper) OFGroup(org.projectfloodlight.openflow.types.OFGroup) OFVersion(org.projectfloodlight.openflow.protocol.OFVersion) IOFSwitchService(net.floodlightcontroller.core.internal.IOFSwitchService) Function(java.util.function.Function) CollectionUtils(org.apache.commons.collections4.CollectionUtils) SwitchTableStatsData(org.openkilda.messaging.info.stats.SwitchTableStatsData) ImmutableList(com.google.common.collect.ImmutableList) OFTableStatsReply(org.projectfloodlight.openflow.protocol.OFTableStatsReply) TableStatsEntry(org.openkilda.messaging.info.stats.TableStatsEntry) Logger(org.slf4j.Logger) CorrelationContextClosable(org.openkilda.floodlight.utils.CorrelationContext.CorrelationContextClosable) IFloodlightModule(net.floodlightcontroller.core.module.IFloodlightModule) FutureCallback(com.google.common.util.concurrent.FutureCallback) OFMeterStatsRequest(org.projectfloodlight.openflow.protocol.OFMeterStatsRequest) Futures(com.google.common.util.concurrent.Futures) KafkaUtilityService(org.openkilda.floodlight.service.kafka.KafkaUtilityService) NewCorrelationContextRequired(org.openkilda.floodlight.utils.NewCorrelationContextRequired) SwitchId(org.openkilda.model.SwitchId) OfMeterStatsMapper(org.openkilda.floodlight.converter.OfMeterStatsMapper) IFloodlightService(net.floodlightcontroller.core.module.IFloodlightService) Destination(org.openkilda.messaging.Destination) NumberUtils(org.apache.commons.lang3.math.NumberUtils) DatapathId(org.projectfloodlight.openflow.types.DatapathId) Collections(java.util.Collections) IThreadPoolService(net.floodlightcontroller.threadpool.IThreadPoolService) OFTableStatsReply(org.projectfloodlight.openflow.protocol.OFTableStatsReply) InfoData(org.openkilda.messaging.info.InfoData) OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) SwitchId(org.openkilda.model.SwitchId) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) OFTableStatsRequest(org.projectfloodlight.openflow.protocol.OFTableStatsRequest) NewCorrelationContextRequired(org.openkilda.floodlight.utils.NewCorrelationContextRequired)

Example 2 with TableStatsEntry

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());
}
Also used : TableStatsEntry(org.openkilda.messaging.info.stats.TableStatsEntry) OFTableStatsEntry(org.projectfloodlight.openflow.protocol.OFTableStatsEntry) OFFactoryVer13(org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13) OFTableStatsEntry(org.projectfloodlight.openflow.protocol.OFTableStatsEntry) Test(org.junit.Test)

Example 3 with TableStatsEntry

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());
    });
}
Also used : TableStatsEntry(org.openkilda.messaging.info.stats.TableStatsEntry) Datapoint(org.openkilda.messaging.info.Datapoint) SwitchTableStatsData(org.openkilda.messaging.info.stats.SwitchTableStatsData) AbstractStormTest(org.openkilda.wfm.AbstractStormTest) Test(org.junit.Test)

Aggregations

TableStatsEntry (org.openkilda.messaging.info.stats.TableStatsEntry)3 Test (org.junit.Test)2 SwitchTableStatsData (org.openkilda.messaging.info.stats.SwitchTableStatsData)2 ImmutableList (com.google.common.collect.ImmutableList)1 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 Futures (com.google.common.util.concurrent.Futures)1 MoreExecutors.directExecutor (com.google.common.util.concurrent.MoreExecutors.directExecutor)1 String.format (java.lang.String.format)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 IFloodlightProviderService (net.floodlightcontroller.core.IFloodlightProviderService)1 IOFSwitch (net.floodlightcontroller.core.IOFSwitch)1 IOFSwitchService (net.floodlightcontroller.core.internal.IOFSwitchService)1 FloodlightModuleContext (net.floodlightcontroller.core.module.FloodlightModuleContext)1 IFloodlightModule (net.floodlightcontroller.core.module.IFloodlightModule)1