Search in sources :

Example 41 with PortStatistics

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));
    }
}
Also used : PortStatistics(org.onosproject.net.device.PortStatistics)

Example 42 with PortStatistics

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("+---------------------------------------------------------------------------------------------------+");
}
Also used : PortStatistics(org.onosproject.net.device.PortStatistics)

Example 43 with PortStatistics

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);
}
Also used : RestSBController(org.onosproject.protocol.rest.RestSBController) DeviceId(org.onosproject.net.DeviceId) Port(org.onosproject.net.Port) DriverHandler(org.onosproject.net.driver.DriverHandler) DeviceService(org.onosproject.net.device.DeviceService) PortStatistics(org.onosproject.net.device.PortStatistics) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics)

Example 44 with 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;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) XPath(javax.xml.xpath.XPath) DeviceId(org.onosproject.net.DeviceId) XPathExpressionException(javax.xml.xpath.XPathExpressionException) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) PortStatistics(org.onosproject.net.device.PortStatistics) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics) NetconfController(org.onosproject.netconf.NetconfController) ConnectPoint(org.onosproject.net.ConnectPoint) NetconfException(org.onosproject.netconf.NetconfException)

Example 45 with PortStatistics

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);
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) XPath(javax.xml.xpath.XPath) DeviceId(org.onosproject.net.DeviceId) XPathExpressionException(javax.xml.xpath.XPathExpressionException) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) PortStatistics(org.onosproject.net.device.PortStatistics) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics) NetconfController(org.onosproject.netconf.NetconfController) NetconfException(org.onosproject.netconf.NetconfException)

Aggregations

PortStatistics (org.onosproject.net.device.PortStatistics)52 DefaultPortStatistics (org.onosproject.net.device.DefaultPortStatistics)26 DeviceId (org.onosproject.net.DeviceId)14 PortNumber (org.onosproject.net.PortNumber)14 DeviceService (org.onosproject.net.device.DeviceService)14 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)11 Device (org.onosproject.net.Device)10 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)8 ArrayList (java.util.ArrayList)8 Map (java.util.Map)8 Port (org.onosproject.net.Port)7 GET (javax.ws.rs.GET)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 PortStatisticsDiscovery (org.onosproject.net.device.PortStatisticsDiscovery)6 ConnectPoint (org.onosproject.net.ConnectPoint)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 Maps (com.google.common.collect.Maps)4 Collection (java.util.Collection)4 Set (java.util.Set)4