use of org.onosproject.net.device.PortStatistics in project onos by opennetworkinglab.
the class DevicePortStatsCommand method printPortStatsDelta.
/**
* Prints Port delta statistics.
*
* @param deviceId
* @param portStats
*/
private void printPortStatsDelta(DeviceId deviceId, Iterable<PortStatistics> portStats) {
final String formatDelta = " port=%s, pktRx=%s, pktTx=%s, bytesRx=%s, bytesTx=%s," + " rateRx=%s, rateTx=%s, pktRxDrp=%s, pktTxDrp=%s, interval=%s";
print("deviceId=%s", deviceId);
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;
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 DevicePortStatsCommand method printPortStatsDeltaTable.
/**
* Prints human readable table with delta Port Statistics for specific device.
*
* @param deviceId
* @param portStats
*/
private void printPortStatsDeltaTable(DeviceId deviceId, Iterable<PortStatistics> portStats) {
final String formatDeltaTable = "|%5s | %7s | %7s | %7s | %7s | %7s | %7s | %7s | %7s |%9s |";
print("+---------------------------------------------------------------------------------------------------+");
print("| DeviceId = %-86s |", deviceId);
print("|---------------------------------------------------------------------------------------------------|");
print("| | Receive | Transmit | Time [s] |");
print("| Port | Packets | Bytes | Rate bps | Drop | Packets | Bytes | Rate bps | Drop | Interval |");
print("|---------------------------------------------------------------------------------------------------|");
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 = duration > 0 ? stat.bytesReceived() * 8 / duration : 0;
float rateTx = duration > 0 ? stat.bytesSent() * 8 / duration : 0;
print(formatDeltaTable, stat.portNumber(), humanReadable(stat.packetsReceived()), humanReadable(stat.bytesReceived()), humanReadableBps(rateRx), humanReadable(stat.packetsRxDropped()), humanReadable(stat.packetsSent()), humanReadable(stat.bytesSent()), humanReadableBps(rateTx), humanReadable(stat.packetsTxDropped()), String.format("%.3f", duration));
}
print("+---------------------------------------------------------------------------------------------------+");
}
use of org.onosproject.net.device.PortStatistics in project onos by opennetworkinglab.
the class CiscoNxosPortStatistics method discoverPortStatistics.
@Override
public Collection<PortStatistics> discoverPortStatistics() {
DriverHandler handler = handler();
RestSBController controller = checkNotNull(handler.get(RestSBController.class));
DeviceId deviceId = handler.data().deviceId();
DeviceService deviceService = this.handler().get(DeviceService.class);
List<Port> ports = deviceService.getPorts(deviceId);
Collection<PortStatistics> portStatistics = Lists.newArrayList();
ports.stream().filter(Port::isEnabled).forEach(port -> portStatistics.add(discoverSpecifiedPortStatistics(port, controller, deviceId)));
return ImmutableList.copyOf(portStatistics);
}
use of org.onosproject.net.device.PortStatistics in project onos by opennetworkinglab.
the class Ciena5170DeviceDescription method discoverPortStatistics.
@Override
public Collection<PortStatistics> discoverPortStatistics() {
List<PortStatistics> stats = new ArrayList<PortStatistics>();
DeviceId deviceId = handler().data().deviceId();
NetconfController controller = checkNotNull(handler().get(NetconfController.class));
if (controller == null || controller.getDevicesMap() == null || controller.getDevicesMap().get(deviceId) == null) {
log.warn("NETCONF session to device {} not yet established, will be retried", deviceId);
return stats;
}
NetconfSession session = controller.getDevicesMap().get(deviceId).getSession();
try {
Node data = TEMPLATE_MANAGER.doRequest(session, "port-stats");
XPath xp = XPathFactory.newInstance().newXPath();
NodeList interfaces = (NodeList) xp.evaluate("interfaces/interface", data, XPathConstants.NODESET);
int count = interfaces.getLength();
for (int i = 0; i < count; i += 1) {
Node iface = interfaces.item(i);
if (xp.evaluate("config/type/text()", iface).equals("ettp")) {
stats.add(DefaultPortStatistics.builder().setDeviceId(deviceId).setPort(PortNumber.portNumber(xp.evaluate("name/text()", iface))).setBytesReceived(Long.valueOf(xp.evaluate("state/counters/in-octets/text()", iface))).setBytesSent(Long.valueOf(xp.evaluate("state/counters/out-octets/text()", iface))).setPacketsReceived(Long.valueOf(xp.evaluate("state/counters/in-pkts/text()", iface))).setPacketsSent(Long.valueOf(xp.evaluate("state/counters/out-pkts/text()", iface))).setPacketsTxErrors(Long.valueOf(xp.evaluate("state/counters/out-errors/text()", iface))).setPacketsRxErrors(Long.valueOf(xp.evaluate("state/counters/in-errors/text()", iface))).build());
}
}
} catch (NetconfException | XPathExpressionException e) {
log.error("Unable to retrieve port statistics for device {}, {}", deviceId, e);
}
return stats;
}
use of org.onosproject.net.device.PortStatistics in project onos by opennetworkinglab.
the class CienaWaveserverAiPortStatisticsDiscovery method discoverPortStatistics.
@Override
public Collection<PortStatistics> discoverPortStatistics() {
log.debug("Calculating port stats for Waveserver Ai device");
Collection<PortStatistics> portStats = new ArrayList<>();
DeviceId deviceId = handler().data().deviceId();
NetconfController controller = checkNotNull(handler().get(NetconfController.class));
if (controller == null || controller.getDevicesMap() == null || controller.getDevicesMap().get(deviceId) == null) {
log.warn("NETCONF session to device {} not yet established, cannot load links, will be retried", deviceId);
return portStats;
}
NetconfSession session = controller.getDevicesMap().get(deviceId).getSession();
try {
XPath xp = XPathFactory.newInstance().newXPath();
String tx = "current-bin/statistics/interface-counts/tx/";
String rx = "current-bin/statistics/interface-counts/rx/";
Node node = TEMPLATE_MANAGER.doRequest(session, "discoverPortStatistics");
NodeList nodeList = (NodeList) xp.evaluate("waveserver-pm/ethernet-performance-instances", node, XPathConstants.NODESET);
Node nodeListItem;
int count = nodeList.getLength();
for (int i = 0; i < count; ++i) {
nodeListItem = nodeList.item(i);
portStats.add(DefaultPortStatistics.builder().setDeviceId(deviceId).setPort(PortNumber.portNumber(portIdConvert(xp.evaluate("instance-name/text()", nodeListItem)))).setPacketsReceived(Long.parseLong(xp.evaluate(rx + "packets/value/text()", nodeListItem))).setPacketsSent(Long.parseLong(xp.evaluate(tx + "packets/value/text()", nodeListItem))).setBytesReceived(Long.parseLong(xp.evaluate(rx + "bytes/value/text()", nodeListItem))).setBytesSent(Long.parseLong(xp.evaluate(tx + "bytes/value/text()", nodeListItem))).build());
}
} catch (NetconfException | XPathExpressionException e) {
log.error("Unable to retrieve port stats information for device {}, {}", deviceId, e);
}
return ImmutableList.copyOf(portStats);
}
Aggregations