Search in sources :

Example 6 with PortStatistics

use of org.onosproject.net.device.PortStatistics in project onos by opennetworkinglab.

the class GossipDeviceStore method getDeltaStatisticsForPort.

@Override
public PortStatistics getDeltaStatisticsForPort(DeviceId deviceId, PortNumber portNumber) {
    Map<PortNumber, PortStatistics> portStatsMap = devicePortDeltaStats.get(deviceId);
    if (portStatsMap == null) {
        return null;
    }
    PortStatistics portStats = portStatsMap.get(portNumber);
    return portStats;
}
Also used : PortNumber(org.onosproject.net.PortNumber) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics) PortStatistics(org.onosproject.net.device.PortStatistics)

Example 7 with PortStatistics

use of org.onosproject.net.device.PortStatistics in project onos by opennetworkinglab.

the class ECDeviceStore method updatePortStatistics.

@Override
public DeviceEvent updatePortStatistics(ProviderId providerId, DeviceId deviceId, Collection<PortStatistics> newStatsCollection) {
    Map<PortNumber, PortStatistics> prvStatsMap = devicePortStats.get(deviceId);
    Map<PortNumber, PortStatistics> newStatsMap = Maps.newHashMap();
    Map<PortNumber, PortStatistics> deltaStatsMap = Maps.newHashMap();
    if (prvStatsMap != null) {
        for (PortStatistics newStats : newStatsCollection) {
            PortNumber port = newStats.portNumber();
            PortStatistics prvStats = prvStatsMap.get(port);
            DefaultPortStatistics.Builder builder = DefaultPortStatistics.builder();
            PortStatistics deltaStats = builder.build();
            if (prvStats != null) {
                deltaStats = calcDeltaStats(deviceId, prvStats, newStats);
            }
            deltaStatsMap.put(port, deltaStats);
            newStatsMap.put(port, newStats);
        }
    } else {
        for (PortStatistics newStats : newStatsCollection) {
            PortNumber port = newStats.portNumber();
            newStatsMap.put(port, newStats);
        }
    }
    devicePortDeltaStats.put(deviceId, deltaStatsMap);
    devicePortStats.put(deviceId, newStatsMap);
    // DeviceEvent returns null because of InternalPortStatsListener usage
    return null;
}
Also used : DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics) PortNumber(org.onosproject.net.PortNumber) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics) PortStatistics(org.onosproject.net.device.PortStatistics)

Example 8 with PortStatistics

use of org.onosproject.net.device.PortStatistics in project onos by opennetworkinglab.

the class IntentsDiagnosisCommand method dumpCpStatistics.

private void dumpCpStatistics(ConnectPoint cp, Collection<PortStatistics> devPortStats, Collection<PortStatistics> devPortDeltaStats, String direction, ServiceRefs svcs) {
    if (cp == null) {
        return;
    }
    dump("  %s:", direction);
    if (cp.port().isLogical()) {
        dump("   - logical: device: %s, port: %s", cp.deviceId(), cp.port());
        return;
    }
    Port port = svcs.deviceService.getPort(cp.deviceId(), cp.port());
    if (port == null) {
        return;
    }
    try {
        devPortStats.stream().filter(stat -> stat.portNumber().equals(cp.port())).forEach(stat -> dump("   - stat   : %s:", getPortStatStr(stat, port)));
    } catch (IllegalStateException e) {
        error("error: " + e);
        return;
    }
    try {
        devPortDeltaStats.stream().filter(stat -> stat.portNumber().equals(cp.port())).forEach(stat -> dump("   - delta  : %s:", getPortStatStr(stat, port)));
    } catch (IllegalStateException e) {
        error("error: " + e);
    }
}
Also used : PortStatistics(org.onosproject.net.device.PortStatistics) DeviceService(org.onosproject.net.device.DeviceService) FlowEntry(org.onosproject.net.flow.FlowEntry) HashMap(java.util.HashMap) DefaultDevice(org.onosproject.net.DefaultDevice) AnnotationKeys(org.onosproject.net.AnnotationKeys) Link(org.onosproject.net.Link) Command(org.apache.karaf.shell.api.action.Command) ConnectPoint(org.onosproject.net.ConnectPoint) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) FlowRuleService(org.onosproject.net.flow.FlowRuleService) IntentService(org.onosproject.net.intent.IntentService) Port(org.onosproject.net.Port) Map(java.util.Map) Intent(org.onosproject.net.intent.Intent) WorkPartitionService(org.onosproject.net.intent.WorkPartitionService) LinkKey(org.onosproject.net.LinkKey) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) ImmutableSet(com.google.common.collect.ImmutableSet) Device(org.onosproject.net.Device) Collection(java.util.Collection) MoreObjects(com.google.common.base.MoreObjects) Set(java.util.Set) Argument(org.apache.karaf.shell.api.action.Argument) Streams(com.google.common.collect.Streams) Field(java.lang.reflect.Field) SetMultimap(com.google.common.collect.SetMultimap) FlowStatisticService(org.onosproject.net.statistic.FlowStatisticService) ObjectiveTrackerService(org.onosproject.net.intent.ObjectiveTrackerService) Objects(java.util.Objects) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) Key(org.onosproject.net.intent.Key) List(java.util.List) Stream(java.util.stream.Stream) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) FlowRule(org.onosproject.net.flow.FlowRule) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Completion(org.apache.karaf.shell.api.action.Completion) Option(org.apache.karaf.shell.api.action.Option) DeviceId(org.onosproject.net.DeviceId) Port(org.onosproject.net.Port)

Example 9 with PortStatistics

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;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) PortStatistics(org.onosproject.net.device.PortStatistics)

Example 10 with PortStatistics

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;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) PortStatistics(org.onosproject.net.device.PortStatistics)

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