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);
}
}
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;
}
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());
}
}
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;
}
Aggregations