use of org.openkilda.messaging.info.stats.FlowStatsEntry 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);
}
}
use of org.openkilda.messaging.info.stats.FlowStatsEntry in project open-kilda by telstra.
the class FlowMetricGenBolt 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("Flow stats message: {}={}, component={}, stream={}", CORRELATION_ID, message.getCorrelationId(), componentId, StatsStreamType.valueOf(input.getSourceStreamId()));
FlowStatsData data = (FlowStatsData) message.getData();
long timestamp = message.getTimestamp();
String switchId = data.getSwitchId().replaceAll(":", "");
try {
for (FlowStatsReply reply : data.getStats()) {
for (FlowStatsEntry entry : reply.getEntries()) {
emit(entry, timestamp, switchId);
}
}
collector.ack(input);
} catch (ServiceUnavailableException e) {
LOGGER.error("Error process: {}", input.toString(), e);
// If we can't connect to Neo then don't know if valid input
collector.fail(input);
} catch (Exception e) {
// We tried, no need to try again
collector.ack(input);
}
}
use of org.openkilda.messaging.info.stats.FlowStatsEntry in project open-kilda by telstra.
the class StatsTopologyTest method flowStatsTest.
@Test
public void flowStatsTest() throws Exception {
List<FlowStatsEntry> entries = Collections.singletonList(new FlowStatsEntry((short) 1, cookie, 1500L, 3000L));
final List<FlowStatsReply> stats = Collections.singletonList(new FlowStatsReply(3, entries));
InfoMessage message = new InfoMessage(new FlowStatsData(switchId, stats), 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();
Map result = Testing.completeTopology(cluster, stormTopology, completeTopologyParam);
// verify results which were sent to Kafka bolt
ArrayList<FixedTuple> tuples = (ArrayList<FixedTuple>) result.get(StatsComponentType.FLOW_STATS_METRIC_GEN.name());
assertThat(tuples.size(), is(6));
tuples.stream().map(this::readFromJson).forEach(datapoint -> {
if (datapoint.getMetric().equals("pen.flow.packets")) {
assertThat(datapoint.getTags().get("direction"), is("forward"));
}
assertThat(datapoint.getTags().get("flowid"), is(flowId));
assertThat(datapoint.getTime(), is(timestamp));
});
});
}
Aggregations