Search in sources :

Example 31 with PortStatistics

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

the class IntentsDiagnosisCommand method perDeviceChecking.

// TODO: It needs to consider FLowObjectiveIntent case
private void perDeviceChecking(DeviceOnIntent devOnIntent, ServiceRefs svcRefs) {
    Collection<PortStatistics> portStats = svcRefs.deviceService().getPortStatistics(devOnIntent.deviceId());
    Collection<PortStatistics> portDeltaStats = svcRefs.deviceService().getPortDeltaStatistics(devOnIntent.deviceId());
    dump("");
    dump(" ------------------------------------------------------------------------------------------");
    Device device = svcRefs.deviceService.getDevice(devOnIntent.deviceId());
    if (device == null) {
        error("INVALID DEVICE for " + devOnIntent.deviceId());
        return;
    }
    dump(" %s", getDeviceString(device));
    dump("  %s", device.annotations());
    devOnIntent.getIngressCps().stream().forEach(cp -> dumpCpStatistics(cp, portStats, portDeltaStats, "INGRESS", svcRefs));
    Stream<FlowEntry> flowEntries = Streams.stream(svcRefs.flowService.getFlowEntries(devOnIntent.deviceId()));
    devOnIntent.getFlowRules().stream().forEach(intentFlowRule -> {
        FlowEntry matchedEntry = flowEntries.filter(entry -> Objects.equals(intentFlowRule.id(), entry.id())).findFirst().orElse(null);
        if (matchedEntry == null) {
            error("FAILED TO FIND FLOW ENTRY: for " + intentFlowRule);
            return;
        }
        if (Objects.equals(intentFlowRule.selector(), matchedEntry.selector()) && Objects.equals(intentFlowRule.treatment(), matchedEntry.treatment())) {
            dumpFlowEntry(matchedEntry, "FLOW ENTRY");
            return;
        }
        error("INSTALLABLE-FLOW ENTRY mismatch");
        dumpFlowRule(intentFlowRule, "INSTALLABLE");
        dumpFlowEntry(matchedEntry, "FLOW ENTRY");
    });
    devOnIntent.getEgressCps().stream().forEach(cp -> dumpCpStatistics(cp, portStats, portDeltaStats, "EGRESS", svcRefs));
}
Also used : DefaultDevice(org.onosproject.net.DefaultDevice) Device(org.onosproject.net.Device) FlowEntry(org.onosproject.net.flow.FlowEntry) PortStatistics(org.onosproject.net.device.PortStatistics)

Example 32 with PortStatistics

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

the class OpenFlowDeviceProvider method pushPortMetrics.

private void pushPortMetrics(Dpid dpid, List<OFPortStatsEntry> portStatsEntries) {
    DeviceId deviceId = DeviceId.deviceId(Dpid.uri(dpid));
    Collection<PortStatistics> stats = buildPortStatistics(deviceId, ImmutableList.copyOf(portStatsEntries));
    providerService.updatePortStatistics(deviceId, stats);
}
Also used : DeviceId(org.onosproject.net.DeviceId) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics) PortStatistics(org.onosproject.net.device.PortStatistics)

Example 33 with PortStatistics

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

the class OpenConfigGnmiPortStatisticsDiscovery method discoverPortStatistics.

@Override
public Collection<PortStatistics> discoverPortStatistics() {
    if (!setupBehaviour("discoverPortStatistics()")) {
        return Collections.emptyList();
    }
    Map<String, PortNumber> ifacePortNumberMapping = Maps.newHashMap();
    List<Port> ports = deviceService.getPorts(deviceId);
    GetRequest.Builder getRequest = GetRequest.newBuilder();
    getRequest.setEncoding(Gnmi.Encoding.PROTO);
    // Use this path to get all counters from specific interface(port)
    // /interfaces/interface[port-name]/state/counters/[counter name]
    ports.forEach(port -> {
        String portName = port.number().name();
        Path path = interfaceCounterPath(portName);
        getRequest.addPath(path);
        ifacePortNumberMapping.put(portName, port.number());
    });
    GetResponse getResponse = Futures.getUnchecked(client.get(getRequest.build()));
    Map<String, Long> inPkts = Maps.newHashMap();
    Map<String, Long> outPkts = Maps.newHashMap();
    Map<String, Long> inBytes = Maps.newHashMap();
    Map<String, Long> outBytes = Maps.newHashMap();
    Map<String, Long> inDropped = Maps.newHashMap();
    Map<String, Long> outDropped = Maps.newHashMap();
    Map<String, Long> inErrors = Maps.newHashMap();
    Map<String, Long> outErrors = Maps.newHashMap();
    Map<String, Duration> timestamps = Maps.newHashMap();
    // Collect responses and sum {in,out,dropped} packets
    getResponse.getNotificationList().forEach(notification -> {
        notification.getUpdateList().forEach(update -> {
            Path path = update.getPath();
            String ifName = interfaceNameFromPath(path);
            timestamps.putIfAbsent(ifName, Duration.ofNanos(notification.getTimestamp()));
            // Last element is the counter name
            String counterName = path.getElem(path.getElemCount() - 1).getName();
            long counterValue = update.getVal().getUintVal();
            switch(counterName) {
                case "in-octets":
                    inBytes.put(ifName, counterValue);
                    break;
                case "out-octets":
                    outBytes.put(ifName, counterValue);
                    break;
                case "in-discards":
                case "in-fcs-errors":
                    inDropped.compute(ifName, (k, v) -> v == null ? counterValue : v + counterValue);
                    break;
                case "out-discards":
                    outDropped.put(ifName, counterValue);
                    break;
                case "in-errors":
                    inErrors.put(ifName, counterValue);
                    break;
                case "out-errors":
                    outErrors.put(ifName, counterValue);
                    break;
                case "in-unicast-pkts":
                case "in-broadcast-pkts":
                case "in-multicast-pkts":
                case "in-unknown-protos":
                    inPkts.compute(ifName, (k, v) -> v == null ? counterValue : v + counterValue);
                    break;
                case "out-unicast-pkts":
                case "out-broadcast-pkts":
                case "out-multicast-pkts":
                    outPkts.compute(ifName, (k, v) -> v == null ? counterValue : v + counterValue);
                    break;
                default:
                    log.warn("Unsupported counter name {}, ignored", counterName);
                    break;
            }
        });
    });
    // Build ONOS port stats map
    return ifacePortNumberMapping.entrySet().stream().map(e -> {
        String ifName = e.getKey();
        PortNumber portNumber = e.getValue();
        Duration portActive = getDurationActive(portNumber, timestamps.get(ifName));
        return DefaultPortStatistics.builder().setDeviceId(deviceId).setPort(portNumber).setDurationSec(portActive.getSeconds()).setDurationNano(portActive.getNano()).setPacketsSent(outPkts.getOrDefault(ifName, 0L)).setPacketsReceived(inPkts.getOrDefault(ifName, 0L)).setPacketsTxDropped(outDropped.getOrDefault(ifName, 0L)).setPacketsRxDropped(inDropped.getOrDefault(ifName, 0L)).setBytesSent(outBytes.getOrDefault(ifName, 0L)).setBytesReceived(inBytes.getOrDefault(ifName, 0L)).setPacketsTxErrors(outErrors.getOrDefault(ifName, 0L)).setPacketsRxErrors(inErrors.getOrDefault(ifName, 0L)).build();
    }).collect(Collectors.toList());
}
Also used : Path(gnmi.Gnmi.Path) Gnmi(gnmi.Gnmi) PortStatistics(org.onosproject.net.device.PortStatistics) Collection(java.util.Collection) PortNumber(org.onosproject.net.PortNumber) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Path(gnmi.Gnmi.Path) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) Port(org.onosproject.net.Port) Duration(java.time.Duration) Map(java.util.Map) GnmiClient(org.onosproject.gnmi.api.GnmiClient) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics) AbstractGrpcHandlerBehaviour(org.onosproject.grpc.utils.AbstractGrpcHandlerBehaviour) GetResponse(gnmi.Gnmi.GetResponse) GnmiController(org.onosproject.gnmi.api.GnmiController) Collections(java.util.Collections) PortStatisticsDiscovery(org.onosproject.net.device.PortStatisticsDiscovery) GetRequest(gnmi.Gnmi.GetRequest) Port(org.onosproject.net.Port) Duration(java.time.Duration) GetResponse(gnmi.Gnmi.GetResponse) GetRequest(gnmi.Gnmi.GetRequest) PortNumber(org.onosproject.net.PortNumber)

Example 34 with PortStatistics

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

the class SimpleDeviceStore method updatePortStatistics.

@Override
public DeviceEvent updatePortStatistics(ProviderId providerId, DeviceId deviceId, Collection<PortStatistics> newStatsCollection) {
    ConcurrentMap<PortNumber, PortStatistics> prvStatsMap = devicePortStats.get(deviceId);
    ConcurrentMap<PortNumber, PortStatistics> newStatsMap = Maps.newConcurrentMap();
    ConcurrentMap<PortNumber, PortStatistics> deltaStatsMap = Maps.newConcurrentMap();
    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);
    return new DeviceEvent(PORT_STATS_UPDATED, devices.get(deviceId), null);
}
Also used : DeviceEvent(org.onosproject.net.device.DeviceEvent) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics) PortNumber(org.onosproject.net.PortNumber) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics) PortStatistics(org.onosproject.net.device.PortStatistics)

Example 35 with PortStatistics

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

the class SimpleDeviceStore method getStatisticsForPort.

@Override
public PortStatistics getStatisticsForPort(DeviceId deviceId, PortNumber portNumber) {
    Map<PortNumber, PortStatistics> portStatsMap = devicePortStats.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)

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