Search in sources :

Example 1 with NewCorrelationContextRequired

use of org.openkilda.floodlight.utils.NewCorrelationContextRequired in project open-kilda by telstra.

the class InputService method receive.

@Override
@NewCorrelationContextRequired
public Command receive(IOFSwitch sw, OFMessage message, FloodlightContext context) {
    // must be constructed as early as possible
    final OfInput input = new OfInput(sw, message, context);
    final String packetIdentity = String.format("(dpId: %s, xId: %s, version: %s, type: %s)", sw.getId(), message.getXid(), message.getVersion(), message.getType());
    log.debug("{} - receive message {}", getClass().getCanonicalName(), packetIdentity);
    try {
        handle(input);
    } catch (Exception e) {
        log.error(String.format("Unhandled exception during processing %s", packetIdentity), e);
    }
    return Command.CONTINUE;
}
Also used : OfInput(org.openkilda.floodlight.model.OfInput) NewCorrelationContextRequired(org.openkilda.floodlight.utils.NewCorrelationContextRequired)

Example 2 with NewCorrelationContextRequired

use of org.openkilda.floodlight.utils.NewCorrelationContextRequired in project open-kilda by telstra.

the class StatisticsService method gatherMeterStats.

@NewCorrelationContextRequired
private void gatherMeterStats(IOFSwitch iofSwitch) {
    OFFactory factory = iofSwitch.getOFFactory();
    SwitchId switchId = new SwitchId(iofSwitch.getId().getLong());
    if (factory.getVersion().compareTo(OFVersion.OF_13) >= 0) {
        OFMeterStatsRequest meterStatsRequest = factory.buildMeterStatsRequest().setMeterId(OFPM_ALL).build();
        logger.info("Getting meter stats for switch={} OF-xid:{}", iofSwitch.getId(), meterStatsRequest.getXid());
        Futures.addCallback(iofSwitch.writeStatsRequest(meterStatsRequest), new RequestCallback<>(data -> OfMeterStatsMapper.INSTANCE.toMeterStatsData(data, switchId), switchId, "meter"), 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) OFMeterStatsRequest(org.projectfloodlight.openflow.protocol.OFMeterStatsRequest) OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) SwitchId(org.openkilda.model.SwitchId) NewCorrelationContextRequired(org.openkilda.floodlight.utils.NewCorrelationContextRequired)

Example 3 with NewCorrelationContextRequired

use of org.openkilda.floodlight.utils.NewCorrelationContextRequired 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 4 with NewCorrelationContextRequired

use of org.openkilda.floodlight.utils.NewCorrelationContextRequired in project open-kilda by telstra.

the class StatisticsService method gatherFlowStats.

@NewCorrelationContextRequired
private void gatherFlowStats(IOFSwitch iofSwitch) {
    OFFactory factory = iofSwitch.getOFFactory();
    final SwitchId switchId = new SwitchId(iofSwitch.getId().getLong());
    OFFlowStatsRequest flowStatsRequest = factory.buildFlowStatsRequest().setOutGroup(OFGroup.ANY).build();
    if (factory.getVersion().compareTo(OFVersion.OF_15) != 0) {
        // skip flow stats for OF 1.5 protocol version
        logger.info("Getting flow stats for switch={} OF-xid:{}", iofSwitch.getId(), flowStatsRequest.getXid());
        Futures.addCallback(iofSwitch.writeStatsRequest(flowStatsRequest), new RequestCallback<>(data -> OfFlowStatsMapper.INSTANCE.toFlowStatsData(data, switchId), switchId, "flow"), 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) OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) SwitchId(org.openkilda.model.SwitchId) OFFlowStatsRequest(org.projectfloodlight.openflow.protocol.OFFlowStatsRequest) NewCorrelationContextRequired(org.openkilda.floodlight.utils.NewCorrelationContextRequired)

Example 5 with NewCorrelationContextRequired

use of org.openkilda.floodlight.utils.NewCorrelationContextRequired in project open-kilda by telstra.

the class StatisticsService method gatherPortStats.

@NewCorrelationContextRequired
private void gatherPortStats(IOFSwitch iofSwitch) {
    OFFactory factory = iofSwitch.getOFFactory();
    SwitchId switchId = new SwitchId(iofSwitch.getId().getLong());
    OFPortStatsRequest portStatsRequest = factory.buildPortStatsRequest().setPortNo(OFPort.ANY).build();
    logger.info("Getting port stats for switch={} OF-xid:{}", iofSwitch.getId(), portStatsRequest.getXid());
    Futures.addCallback(iofSwitch.writeStatsRequest(portStatsRequest), new RequestCallback<>(data -> OfPortStatsMapper.INSTANCE.toPostStatsData(data, switchId), switchId, "port"), 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) OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) OFPortStatsRequest(org.projectfloodlight.openflow.protocol.OFPortStatsRequest) SwitchId(org.openkilda.model.SwitchId) NewCorrelationContextRequired(org.openkilda.floodlight.utils.NewCorrelationContextRequired)

Aggregations

NewCorrelationContextRequired (org.openkilda.floodlight.utils.NewCorrelationContextRequired)6 ImmutableList (com.google.common.collect.ImmutableList)4 FutureCallback (com.google.common.util.concurrent.FutureCallback)4 Futures (com.google.common.util.concurrent.Futures)4 MoreExecutors.directExecutor (com.google.common.util.concurrent.MoreExecutors.directExecutor)4 String.format (java.lang.String.format)4 Collection (java.util.Collection)4 Collections (java.util.Collections)4 List (java.util.List)4 Map (java.util.Map)4 Set (java.util.Set)4 Function (java.util.function.Function)4 Collectors (java.util.stream.Collectors)4 IFloodlightProviderService (net.floodlightcontroller.core.IFloodlightProviderService)4 IOFSwitch (net.floodlightcontroller.core.IOFSwitch)4 IOFSwitchService (net.floodlightcontroller.core.internal.IOFSwitchService)4 FloodlightModuleContext (net.floodlightcontroller.core.module.FloodlightModuleContext)4 IFloodlightModule (net.floodlightcontroller.core.module.IFloodlightModule)4 IFloodlightService (net.floodlightcontroller.core.module.IFloodlightService)4 IThreadPoolService (net.floodlightcontroller.threadpool.IThreadPoolService)4