use of org.onosproject.net.device.PortStatistics in project onos by opennetworkinglab.
the class DefaultOFSwitch method processStatsRequest.
@Override
public void processStatsRequest(Channel channel, OFMessage msg) {
if (msg.getType() != OFType.STATS_REQUEST) {
log.warn("Ignoring message of type {}.", msg.getType());
return;
}
OFStatsRequest ofStatsRequest = (OFStatsRequest) msg;
OFStatsReply ofStatsReply = null;
switch(ofStatsRequest.getStatsType()) {
case PORT_DESC:
List<OFPortDesc> portDescs = new ArrayList<>();
Set<Port> ports = ofSwitchService.ports(networkId, deviceId);
ports.forEach(port -> {
OFPortDesc ofPortDesc = portDesc(port);
portDescs.add(ofPortDesc);
});
ofStatsReply = FACTORY.buildPortDescStatsReply().setXid(msg.getXid()).setEntries(portDescs).build();
break;
case PORT:
OFPortStatsRequest portStatsRequest = (OFPortStatsRequest) msg;
OFPort ofPort = portStatsRequest.getPortNo();
List<OFPortStatsEntry> portStatsEntries = new ArrayList<>();
List<PortStatistics> portStatistics = ofSwitchService.getPortStatistics(networkId, deviceId);
if (ofPort.equals(OFPort.ANY)) {
portStatistics.forEach(portStatistic -> {
OFPortStatsEntry ofPortStatsEntry = portStatsEntry(portStatistic);
portStatsEntries.add(ofPortStatsEntry);
});
}
ofStatsReply = FACTORY.buildPortStatsReply().setEntries(portStatsEntries).setXid(msg.getXid()).build();
break;
case METER_FEATURES:
OFMeterFeatures ofMeterFeatures = FACTORY.buildMeterFeatures().build();
ofStatsReply = FACTORY.buildMeterFeaturesStatsReply().setXid(msg.getXid()).setFeatures(ofMeterFeatures).build();
break;
case FLOW:
List<OFFlowStatsEntry> flowStatsEntries = new ArrayList<>();
List<FlowEntry> flowStats = ofSwitchService.getFlowEntries(networkId, deviceId);
flowStats.forEach(flowEntry -> {
OFFlowStatsEntry ofFlowStatsEntry = ofFlowStatsEntry(flowEntry);
flowStatsEntries.add(ofFlowStatsEntry);
});
ofStatsReply = FACTORY.buildFlowStatsReply().setEntries(flowStatsEntries).setXid(msg.getXid()).build();
break;
case TABLE:
List<OFTableStatsEntry> ofTableStatsEntries = new ArrayList<>();
List<TableStatisticsEntry> tableStats = ofSwitchService.getFlowTableStatistics(networkId, deviceId);
tableStats.forEach(tableStatisticsEntry -> {
OFTableStatsEntry ofFlowStatsEntry = ofFlowTableStatsEntry(tableStatisticsEntry);
ofTableStatsEntries.add(ofFlowStatsEntry);
});
ofStatsReply = FACTORY.buildTableStatsReply().setEntries(ofTableStatsEntries).setXid(msg.getXid()).build();
break;
case GROUP:
List<Group> groupStats = ofSwitchService.getGroups(networkId, deviceId);
List<OFGroupStatsEntry> ofGroupStatsEntries = new ArrayList<>();
groupStats.forEach(group -> {
OFGroupStatsEntry entry = ofGroupStatsEntry(group);
ofGroupStatsEntries.add(entry);
});
ofStatsReply = FACTORY.buildGroupStatsReply().setEntries(ofGroupStatsEntries).setXid(msg.getXid()).build();
break;
case GROUP_DESC:
List<OFGroupDescStatsEntry> ofGroupDescStatsEntries = new ArrayList<>();
List<Group> groupStats2 = ofSwitchService.getGroups(networkId, deviceId);
groupStats2.forEach(group -> {
OFGroupDescStatsEntry entry = ofGroupDescStatsEntry(group);
ofGroupDescStatsEntries.add(entry);
});
ofStatsReply = FACTORY.buildGroupDescStatsReply().setEntries(ofGroupDescStatsEntries).setXid(msg.getXid()).build();
break;
case DESC:
ofStatsReply = FACTORY.buildDescStatsReply().setXid(msg.getXid()).build();
break;
default:
log.debug("Functionality not yet supported for type {} statsType{} msg {}", msg.getType(), ofStatsRequest.getStatsType(), msg);
break;
}
if (ofStatsReply != null) {
log.trace("request {}; reply {}", msg, ofStatsReply);
channel.writeAndFlush(Collections.singletonList(ofStatsReply));
}
}
use of org.onosproject.net.device.PortStatistics in project onos by opennetworkinglab.
the class OpenstackVmStatsCommand method printPortStatsDelta.
private void printPortStatsDelta(String vmDeviceId, Iterable<PortStatistics> portStats, Set<PortNumber> portNumbers) {
final String formatDelta = " port=%s, pktRx=%s, pktTx=%s, bytesRx=%s, bytesTx=%s," + " rateRx=%s, rateTx=%s, pktRxDrp=%s, pktTxDrp=%s, interval=%s";
print("VM Device ID: %s", vmDeviceId);
for (PortStatistics stat : sortByPort(portStats)) {
if (portNumbers.contains(stat.portNumber())) {
float duration = ((float) stat.durationSec()) + (((float) stat.durationNano()) / TimeUnit.SECONDS.toNanos(1));
float rateRx = stat.bytesReceived() * 8 / duration;
float rateTx = stat.bytesSent() * 8 / duration;
print(formatDelta, stat.portNumber(), stat.packetsReceived(), stat.packetsSent(), stat.bytesReceived(), stat.bytesSent(), String.format("%.1f", rateRx), String.format("%.1f", rateTx), stat.packetsRxDropped(), stat.packetsTxDropped(), String.format("%.3f", duration));
}
}
}
use of org.onosproject.net.device.PortStatistics in project onos by opennetworkinglab.
the class StatsFlowRuleManager method getOverlayDstPortBasedFlowInfos.
/**
* Gets a set of flow infos by referring to overlay destination VM port.
*
* @return flow infos
*/
private Set<FlowInfo> getOverlayDstPortBasedFlowInfos() {
Set<FlowInfo> flowInfos = Sets.newConcurrentHashSet();
Set<PortNumber> instPortNums = instPortService.instancePorts().stream().map(InstancePort::portNumber).collect(Collectors.toSet());
Set<DeviceId> deviceIds = osNodeService.completeNodes(COMPUTE).stream().map(OpenstackNode::intgBridge).collect(Collectors.toSet());
deviceIds.forEach(d -> {
List<PortStatistics> stats = deviceService.getPortStatistics(d).stream().filter(s -> instPortNums.contains(s.portNumber())).collect(Collectors.toList());
stats.forEach(s -> {
InstancePort instPort = getInstancePort(d, s.portNumber());
if (instPort != null) {
flowInfos.add(buildTxFlowInfoFromInstancePort(instPort, s));
flowInfos.add(buildRxFlowInfoFromInstancePort(instPort, s));
}
});
});
return flowInfos;
}
use of org.onosproject.net.device.PortStatistics in project onos by opennetworkinglab.
the class DevicePortStatsCommand method jsonPortStats.
/**
* Produces JSON array containing portstats of the specified device.
*
* @param deviceId device id
* @param portStats collection of port statistics
* @return JSON array
*/
private JsonNode jsonPortStats(DeviceId deviceId, ObjectMapper mapper, Iterable<PortStatistics> portStats) {
ObjectNode result = mapper.createObjectNode();
ArrayNode portStatsNode = mapper.createArrayNode();
for (PortStatistics stat : sortByPort(portStats)) {
if (isIrrelevant(stat)) {
continue;
}
if (nonzero && stat.isZero()) {
continue;
}
portStatsNode.add(mapper.createObjectNode().put("port", stat.portNumber().toString()).put("pktRx", stat.packetsReceived()).put("pktTx", stat.packetsSent()).put("bytesRx", stat.bytesReceived()).put("bytesTx", stat.bytesSent()).put("pktRxDrp", stat.packetsRxDropped()).put("pktTxDrp", stat.packetsTxDropped()).put("Dur", stat.durationSec()).set("annotations", annotations(mapper, stat.annotations())));
}
result.put("deviceId", deviceId.toString());
result.set("portStats", portStatsNode);
return result;
}
use of org.onosproject.net.device.PortStatistics in project onos by opennetworkinglab.
the class DevicePortStatsCommand method jsonPortStatsDelta.
/**
* Produces JSON array containing delta portstats of the specified device id.
*
* @param deviceId device id
* @param portStats collection of port statistics
* @return JSON array
*/
private JsonNode jsonPortStatsDelta(DeviceId deviceId, ObjectMapper mapper, Iterable<PortStatistics> portStats) {
ObjectNode result = mapper.createObjectNode();
ArrayNode portStatsNode = mapper.createArrayNode();
for (PortStatistics stat : sortByPort(portStats)) {
if (isIrrelevant(stat)) {
continue;
}
if (nonzero && stat.isZero()) {
continue;
}
float duration = ((float) stat.durationSec()) + (((float) stat.durationNano()) / TimeUnit.SECONDS.toNanos(1));
float rateRx = stat.bytesReceived() * 8 / duration;
float rateTx = stat.bytesSent() * 8 / duration;
portStatsNode.add(mapper.createObjectNode().put("port", stat.portNumber().toString()).put("pktRx", stat.packetsReceived()).put("pktTx", stat.packetsSent()).put("bytesRx", stat.bytesReceived()).put("bytesTx", stat.bytesSent()).put("rateRx", String.format("%.1f", rateRx)).put("rateTx", String.format("%.1f", rateTx)).put("pktRxDrp", stat.packetsRxDropped()).put("pktTxDrp", stat.packetsTxDropped()).put("interval", String.format("%.3f", duration)));
}
result.put("deviceId", deviceId.toString());
result.set("portStats", portStatsNode);
return result;
}
Aggregations