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));
}
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);
}
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());
}
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);
}
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;
}
Aggregations