Search in sources :

Example 1 with PortStatsData

use of org.openkilda.messaging.info.stats.PortStatsData in project open-kilda by telstra.

the class PortMetricGenBolt method execute.

@Override
public void execute(Tuple input) {
    StatsComponentType componentId = StatsComponentType.valueOf(input.getSourceComponent());
    InfoMessage message = (InfoMessage) input.getValueByField(MESSAGE_FIELD);
    if (!Destination.WFM_STATS.equals(message.getDestination())) {
        collector.ack(input);
        return;
    }
    LOGGER.debug("Port stats message: {}={}, component={}, stream={}", CORRELATION_ID, message.getCorrelationId(), componentId, StatsStreamType.valueOf(input.getSourceStreamId()));
    PortStatsData data = (PortStatsData) message.getData();
    long timestamp = message.getTimestamp();
    try {
        String switchId = switchNameCache.get(data.getSwitchId());
        if (switchId == null) {
            switchId = "SW" + data.getSwitchId().replaceAll(":", "").toUpperCase();
            switchNameCache.put(data.getSwitchId(), switchId);
        }
        for (PortStatsReply reply : data.getStats()) {
            for (PortStatsEntry entry : reply.getEntries()) {
                emit(entry, timestamp, switchId);
            }
        }
    } finally {
        collector.ack(input);
    }
}
Also used : StatsComponentType(org.openkilda.wfm.topology.stats.StatsComponentType) InfoMessage(org.openkilda.messaging.info.InfoMessage) PortStatsData(org.openkilda.messaging.info.stats.PortStatsData) PortStatsEntry(org.openkilda.messaging.info.stats.PortStatsEntry) PortStatsReply(org.openkilda.messaging.info.stats.PortStatsReply)

Example 2 with PortStatsData

use of org.openkilda.messaging.info.stats.PortStatsData 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 3 with PortStatsData

use of org.openkilda.messaging.info.stats.PortStatsData in project open-kilda by telstra.

the class SpeakerBolt method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute(Tuple tuple) {
    logger.debug("Ingoing tuple: {}", tuple);
    String request = tuple.getString(0);
    // String request = tuple.getStringByField("value");
    try {
        Message stats = Utils.MAPPER.readValue(request, Message.class);
        if (!Destination.WFM_STATS.equals(stats.getDestination()) || !(stats instanceof InfoMessage)) {
            return;
        }
        InfoMessage message = (InfoMessage) stats;
        final InfoData data = message.getData();
        if (data instanceof PortStatsData) {
            logger.debug("Port stats message: {}", new Values(request));
            outputCollector.emit(PORT_STATS_STREAM, tuple, new Values(message));
        } else if (data instanceof MeterConfigStatsData) {
            logger.debug("Meter config stats message: {}", new Values(request));
            outputCollector.emit(METER_CFG_STATS_STREAM, tuple, new Values(message));
        } else if (data instanceof FlowStatsData) {
            logger.debug("Flow stats message: {}", new Values(request));
            outputCollector.emit(FLOW_STATS_STREAM, tuple, new Values(message));
        }
    } catch (IOException exception) {
        logger.error("Could not deserialize message={}", request, exception);
    } finally {
        outputCollector.ack(tuple);
        logger.debug("Message ack: {}", request);
    }
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) AbstractTopology.fieldMessage(org.openkilda.wfm.topology.AbstractTopology.fieldMessage) MeterConfigStatsData(org.openkilda.messaging.info.stats.MeterConfigStatsData) FlowStatsData(org.openkilda.messaging.info.stats.FlowStatsData) InfoMessage(org.openkilda.messaging.info.InfoMessage) InfoData(org.openkilda.messaging.info.InfoData) Values(org.apache.storm.tuple.Values) PortStatsData(org.openkilda.messaging.info.stats.PortStatsData) IOException(java.io.IOException)

Example 4 with PortStatsData

use of org.openkilda.messaging.info.stats.PortStatsData in project open-kilda by telstra.

the class StatsTopologyTest method portStatsTest.

@Ignore
@Test
public void portStatsTest() throws Exception {
    final String switchId = "00:00:00:00:00:00:00:01";
    final List<PortStatsEntry> entries = IntStream.range(1, 53).boxed().map(port -> {
        int baseCount = port * 20;
        return new PortStatsEntry(port, baseCount, baseCount + 1, baseCount + 2, baseCount + 3, baseCount + 4, baseCount + 5, baseCount + 6, baseCount + 7, baseCount + 8, baseCount + 9, baseCount + 10, baseCount + 11);
    }).collect(toList());
    final List<PortStatsReply> replies = Collections.singletonList(new PortStatsReply(1, entries));
    InfoMessage message = new InfoMessage(new PortStatsData(switchId, replies), timestamp, CORRELATION_ID, Destination.WFM_STATS);
    // mock kafka spout
    MockedSources sources = new MockedSources();
    sources.addMockData(StatsComponentType.STATS_OFS_KAFKA_SPOUT.toString(), new Values(MAPPER.writeValueAsString(message)));
    completeTopologyParam.setMockedSources(sources);
    // execute topology
    Testing.withTrackedCluster(clusterParam, (cluster) -> {
        StatsTopology topology = new TestingTargetTopology(new TestingKafkaBolt());
        StormTopology stormTopology = topology.createTopology();
        // verify results
        Map result = Testing.completeTopology(cluster, stormTopology, completeTopologyParam);
        ArrayList<FixedTuple> tuples = (ArrayList<FixedTuple>) result.get(StatsComponentType.PORT_STATS_METRIC_GEN.name());
        assertThat(tuples.size(), is(728));
        tuples.stream().map(this::readFromJson).forEach(datapoint -> {
            assertThat(datapoint.getTags().get("switchId"), is(switchId.replaceAll(":", "")));
            assertThat(datapoint.getTime(), is(timestamp));
            assertThat(datapoint.getMetric(), startsWith("pen.switch"));
        });
    });
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) InfoMessage(org.openkilda.messaging.info.InfoMessage) IntStream(java.util.stream.IntStream) StableAbstractStormTest(org.openkilda.wfm.StableAbstractStormTest) java.util(java.util) Testing(org.apache.storm.Testing) CoreMatchers.startsWith(org.hamcrest.CoreMatchers.startsWith) Values(org.apache.storm.tuple.Values) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) StormTopology(org.apache.storm.generated.StormTopology) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) MeterConfigReply(org.openkilda.messaging.info.stats.MeterConfigReply) MAPPER(org.openkilda.messaging.Utils.MAPPER) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Utils(org.openkilda.messaging.Utils) MockedSources(org.apache.storm.testing.MockedSources) PortStatsReply(org.openkilda.messaging.info.stats.PortStatsReply) KafkaBolt(org.apache.storm.kafka.bolt.KafkaBolt) FlowStatsEntry(org.openkilda.messaging.info.stats.FlowStatsEntry) PortStatsData(org.openkilda.messaging.info.stats.PortStatsData) PortStatsEntry(org.openkilda.messaging.info.stats.PortStatsEntry) FlowStatsReply(org.openkilda.messaging.info.stats.FlowStatsReply) TestFlowGenMetricsBolt(org.openkilda.wfm.topology.TestFlowGenMetricsBolt) TestingKafkaBolt(org.openkilda.wfm.topology.TestingKafkaBolt) FixedTuple(org.apache.storm.testing.FixedTuple) Test(org.junit.Test) IOException(java.io.IOException) MeterConfigStatsData(org.openkilda.messaging.info.stats.MeterConfigStatsData) Datapoint(org.openkilda.messaging.info.Datapoint) File(java.io.File) FlowMetricGenBolt(org.openkilda.wfm.topology.stats.metrics.FlowMetricGenBolt) CORRELATION_ID(org.openkilda.messaging.Utils.CORRELATION_ID) Collectors.toList(java.util.stream.Collectors.toList) Ignore(org.junit.Ignore) Destination(org.openkilda.messaging.Destination) FlowStatsData(org.openkilda.messaging.info.stats.FlowStatsData) StormTopology(org.apache.storm.generated.StormTopology) Values(org.apache.storm.tuple.Values) TestingKafkaBolt(org.openkilda.wfm.topology.TestingKafkaBolt) PortStatsReply(org.openkilda.messaging.info.stats.PortStatsReply) FixedTuple(org.apache.storm.testing.FixedTuple) MockedSources(org.apache.storm.testing.MockedSources) InfoMessage(org.openkilda.messaging.info.InfoMessage) PortStatsEntry(org.openkilda.messaging.info.stats.PortStatsEntry) PortStatsData(org.openkilda.messaging.info.stats.PortStatsData) Ignore(org.junit.Ignore) StableAbstractStormTest(org.openkilda.wfm.StableAbstractStormTest) Test(org.junit.Test)

Aggregations

InfoMessage (org.openkilda.messaging.info.InfoMessage)4 PortStatsData (org.openkilda.messaging.info.stats.PortStatsData)4 FlowStatsData (org.openkilda.messaging.info.stats.FlowStatsData)3 PortStatsEntry (org.openkilda.messaging.info.stats.PortStatsEntry)3 PortStatsReply (org.openkilda.messaging.info.stats.PortStatsReply)3 IOException (java.io.IOException)2 Collectors.toList (java.util.stream.Collectors.toList)2 Values (org.apache.storm.tuple.Values)2 Destination (org.openkilda.messaging.Destination)2 InfoData (org.openkilda.messaging.info.InfoData)2 FlowStatsEntry (org.openkilda.messaging.info.stats.FlowStatsEntry)2 FlowStatsReply (org.openkilda.messaging.info.stats.FlowStatsReply)2 MeterConfigStatsData (org.openkilda.messaging.info.stats.MeterConfigStatsData)2 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 Futures (com.google.common.util.concurrent.Futures)1 File (java.io.File)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1