Search in sources :

Example 1 with OFFlowStatsRequest

use of org.projectfloodlight.openflow.protocol.OFFlowStatsRequest in project open-kilda by telstra.

the class StatisticsService method startUp.

@Override
public void startUp(FloodlightModuleContext context) throws FloodlightModuleException {
    if (interval > 0) {
        threadPoolService.getScheduledExecutor().scheduleAtFixedRate(() -> switchService.getAllSwitchMap().values().forEach(iofSwitch -> {
            OFFactory factory = iofSwitch.getOFFactory();
            final String switchId = iofSwitch.getId().toString();
            OFPortStatsRequest portStatsRequest = factory.buildPortStatsRequest().setPortNo(OFPort.ANY).build();
            OFFlowStatsRequest flowStatsRequest = factory.buildFlowStatsRequest().setOutGroup(OFGroup.ANY).setCookieMask(SYSTEM_MASK).build();
            logger.info("Getting port stats for switch={}", iofSwitch.getId());
            Futures.addCallback(iofSwitch.writeStatsRequest(portStatsRequest), new RequestCallback<>(data -> {
                List<PortStatsReply> replies = data.stream().map(reply -> {
                    List<PortStatsEntry> entries = reply.getEntries().stream().map(entry -> {
                        if (entry.getVersion().compareTo(OFVersion.OF_13) > 0) {
                            long rxFrameErr, rxOverErr, rxCrcErr, collisions;
                            rxFrameErr = rxOverErr = rxCrcErr = collisions = 0;
                            for (OFPortStatsProp property : entry.getProperties()) {
                                if (property.getType() == 0x0) {
                                    OFPortStatsPropEthernet etherProps = (OFPortStatsPropEthernet) property;
                                    rxFrameErr = etherProps.getRxFrameErr().getValue();
                                    rxOverErr = etherProps.getRxOverErr().getValue();
                                    rxCrcErr = etherProps.getRxCrcErr().getValue();
                                    collisions = etherProps.getCollisions().getLength();
                                }
                            }
                            return new PortStatsEntry(entry.getPortNo().getPortNumber(), entry.getRxPackets().getValue(), entry.getTxPackets().getValue(), entry.getRxBytes().getValue(), entry.getTxBytes().getValue(), entry.getRxDropped().getValue(), entry.getTxDropped().getValue(), entry.getRxErrors().getValue(), entry.getTxErrors().getValue(), rxFrameErr, rxOverErr, rxCrcErr, collisions);
                        } else {
                            return new PortStatsEntry(entry.getPortNo().getPortNumber(), entry.getRxPackets().getValue(), entry.getTxPackets().getValue(), entry.getRxBytes().getValue(), entry.getTxBytes().getValue(), entry.getRxDropped().getValue(), entry.getTxDropped().getValue(), entry.getRxErrors().getValue(), entry.getTxErrors().getValue(), entry.getRxFrameErr().getValue(), entry.getRxOverErr().getValue(), entry.getRxCrcErr().getValue(), entry.getCollisions().getValue());
                        }
                    }).collect(toList());
                    return new PortStatsReply(reply.getXid(), entries);
                }).collect(toList());
                return new PortStatsData(switchId, replies);
            }, "port"));
            if (factory.getVersion().compareTo(OFVersion.OF_15) != 0) {
                // skip flow stats for OF 1.5 protocol version
                logger.info("Getting flow stats for switch={}", iofSwitch.getId());
                Futures.addCallback(iofSwitch.writeStatsRequest(flowStatsRequest), new RequestCallback<>(data -> {
                    List<FlowStatsReply> replies = data.stream().map(reply -> {
                        List<FlowStatsEntry> entries = reply.getEntries().stream().map(entry -> new FlowStatsEntry(entry.getTableId().getValue(), entry.getCookie().getValue(), entry.getPacketCount().getValue(), entry.getByteCount().getValue())).collect(toList());
                        return new FlowStatsReply(reply.getXid(), entries);
                    }).collect(toList());
                    return new FlowStatsData(switchId, replies);
                }, "flow"));
            }
        }), interval, interval, TimeUnit.SECONDS);
    }
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) OFVersion(org.projectfloodlight.openflow.protocol.OFVersion) U64(org.projectfloodlight.openflow.types.U64) OFStatsReply(org.projectfloodlight.openflow.protocol.OFStatsReply) OFPortStatsRequest(org.projectfloodlight.openflow.protocol.OFPortStatsRequest) OFFlowStatsRequest(org.projectfloodlight.openflow.protocol.OFFlowStatsRequest) LoggerFactory(org.slf4j.LoggerFactory) IOFSwitchService(net.floodlightcontroller.core.internal.IOFSwitchService) Function(java.util.function.Function) ArrayList(java.util.ArrayList) OFPortStatsProp(org.projectfloodlight.openflow.protocol.OFPortStatsProp) Map(java.util.Map) OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) PortStatsReply(org.openkilda.messaging.info.stats.PortStatsReply) FlowStatsEntry(org.openkilda.messaging.info.stats.FlowStatsEntry) PortStatsData(org.openkilda.messaging.info.stats.PortStatsData) Logger(org.slf4j.Logger) PortStatsEntry(org.openkilda.messaging.info.stats.PortStatsEntry) FlowStatsReply(org.openkilda.messaging.info.stats.FlowStatsReply) Collection(java.util.Collection) InfoData(org.openkilda.messaging.info.InfoData) FloodlightModuleContext(net.floodlightcontroller.core.module.FloodlightModuleContext) FloodlightModuleException(net.floodlightcontroller.core.module.FloodlightModuleException) IFloodlightModule(net.floodlightcontroller.core.module.IFloodlightModule) FutureCallback(com.google.common.util.concurrent.FutureCallback) TimeUnit(java.util.concurrent.TimeUnit) OFPort(org.projectfloodlight.openflow.types.OFPort) Collectors.toList(java.util.stream.Collectors.toList) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) Topic(org.openkilda.messaging.Topic) IFloodlightService(net.floodlightcontroller.core.module.IFloodlightService) KafkaMessageProducer(org.openkilda.floodlight.kafka.KafkaMessageProducer) Destination(org.openkilda.messaging.Destination) IFloodlightProviderService(net.floodlightcontroller.core.IFloodlightProviderService) SYSTEM_CORRELATION_ID(org.openkilda.messaging.Utils.SYSTEM_CORRELATION_ID) Collections(java.util.Collections) FlowStatsData(org.openkilda.messaging.info.stats.FlowStatsData) IThreadPoolService(net.floodlightcontroller.threadpool.IThreadPoolService) OFPortStatsPropEthernet(org.projectfloodlight.openflow.protocol.OFPortStatsPropEthernet) OFGroup(org.projectfloodlight.openflow.types.OFGroup) OFPortStatsPropEthernet(org.projectfloodlight.openflow.protocol.OFPortStatsPropEthernet) OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) OFFlowStatsRequest(org.projectfloodlight.openflow.protocol.OFFlowStatsRequest) PortStatsReply(org.openkilda.messaging.info.stats.PortStatsReply) FlowStatsReply(org.openkilda.messaging.info.stats.FlowStatsReply) FlowStatsEntry(org.openkilda.messaging.info.stats.FlowStatsEntry) FlowStatsData(org.openkilda.messaging.info.stats.FlowStatsData) OFPortStatsRequest(org.projectfloodlight.openflow.protocol.OFPortStatsRequest) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) PortStatsEntry(org.openkilda.messaging.info.stats.PortStatsEntry) PortStatsData(org.openkilda.messaging.info.stats.PortStatsData) OFPortStatsProp(org.projectfloodlight.openflow.protocol.OFPortStatsProp)

Example 2 with OFFlowStatsRequest

use of org.projectfloodlight.openflow.protocol.OFFlowStatsRequest in project open-kilda by telstra.

the class SwitchManager method dumpFlowTable.

/**
 * {@inheritDoc}
 */
@Override
public List<OFFlowStatsEntry> dumpFlowTable(final DatapathId dpid) throws SwitchNotFoundException {
    List<OFFlowStatsEntry> entries = new ArrayList<>();
    IOFSwitch sw = lookupSwitch(dpid);
    OFFactory ofFactory = sw.getOFFactory();
    OFFlowStatsRequest flowRequest = ofFactory.buildFlowStatsRequest().setOutGroup(OFGroup.ANY).setCookieMask(U64.ZERO).build();
    try {
        Future<List<OFFlowStatsReply>> future = sw.writeStatsRequest(flowRequest);
        List<OFFlowStatsReply> values = future.get(10, TimeUnit.SECONDS);
        if (values != null) {
            entries = values.stream().map(OFFlowStatsReply::getEntries).flatMap(List::stream).collect(toList());
        }
    } catch (ExecutionException | TimeoutException e) {
        logger.error("Could not get flow stats for {}.", dpid, e);
        throw new SwitchNotFoundException(dpid);
    } catch (InterruptedException e) {
        logger.error("Could not get flow stats for {}.", dpid, e);
        Thread.currentThread().interrupt();
        throw new SwitchNotFoundException(dpid);
    }
    return entries;
}
Also used : OFFlowStatsEntry(org.projectfloodlight.openflow.protocol.OFFlowStatsEntry) IOFSwitch(net.floodlightcontroller.core.IOFSwitch) OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) ArrayList(java.util.ArrayList) SwitchNotFoundException(org.openkilda.floodlight.error.SwitchNotFoundException) OFFlowStatsRequest(org.projectfloodlight.openflow.protocol.OFFlowStatsRequest) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) OFFlowStatsReply(org.projectfloodlight.openflow.protocol.OFFlowStatsReply) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 3 with OFFlowStatsRequest

use of org.projectfloodlight.openflow.protocol.OFFlowStatsRequest 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 4 with OFFlowStatsRequest

use of org.projectfloodlight.openflow.protocol.OFFlowStatsRequest in project open-kilda by telstra.

the class SwitchManager method dumpFlowTable.

private List<OFFlowStatsEntry> dumpFlowTable(final DatapathId dpid, final int tableId) throws SwitchNotFoundException {
    List<OFFlowStatsEntry> entries = new ArrayList<>();
    IOFSwitch sw = lookupSwitch(dpid);
    OFFactory ofFactory = sw.getOFFactory();
    OFFlowStatsRequest flowRequest = ofFactory.buildFlowStatsRequest().setOutGroup(OFGroup.ANY).setCookieMask(U64.ZERO).setTableId(TableId.of(tableId)).build();
    try {
        Future<List<OFFlowStatsReply>> future = sw.writeStatsRequest(flowRequest);
        List<OFFlowStatsReply> values = future.get(10, TimeUnit.SECONDS);
        if (values != null) {
            entries = values.stream().map(OFFlowStatsReply::getEntries).flatMap(List::stream).collect(toList());
        }
    } catch (ExecutionException | TimeoutException e) {
        logger.error("Could not get flow stats for {}.", dpid, e);
        throw new SwitchNotFoundException(dpid);
    } catch (InterruptedException e) {
        logger.error("Could not get flow stats for {}.", dpid, e);
        Thread.currentThread().interrupt();
        throw new SwitchNotFoundException(dpid);
    }
    return entries;
}
Also used : OFFlowStatsEntry(org.projectfloodlight.openflow.protocol.OFFlowStatsEntry) IOFSwitch(net.floodlightcontroller.core.IOFSwitch) OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) ArrayList(java.util.ArrayList) SwitchNotFoundException(org.openkilda.floodlight.error.SwitchNotFoundException) OFFlowStatsRequest(org.projectfloodlight.openflow.protocol.OFFlowStatsRequest) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) OFFlowStatsReply(org.projectfloodlight.openflow.protocol.OFFlowStatsReply) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

List (java.util.List)4 OFFactory (org.projectfloodlight.openflow.protocol.OFFactory)4 OFFlowStatsRequest (org.projectfloodlight.openflow.protocol.OFFlowStatsRequest)4 ImmutableList (com.google.common.collect.ImmutableList)3 ArrayList (java.util.ArrayList)3 Collectors.toList (java.util.stream.Collectors.toList)3 IOFSwitch (net.floodlightcontroller.core.IOFSwitch)3 FutureCallback (com.google.common.util.concurrent.FutureCallback)2 Futures (com.google.common.util.concurrent.Futures)2 Arrays.asList (java.util.Arrays.asList)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Collections.emptyList (java.util.Collections.emptyList)2 Collections.singletonList (java.util.Collections.singletonList)2 Map (java.util.Map)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimeoutException (java.util.concurrent.TimeoutException)2 Function (java.util.function.Function)2 IFloodlightProviderService (net.floodlightcontroller.core.IFloodlightProviderService)2 IOFSwitchService (net.floodlightcontroller.core.internal.IOFSwitchService)2