@Override public DeviceEvent updatePortStatistics(ProviderId providerId, DeviceId deviceId, Collection<PortStatistics> portStats) { ConcurrentMap<PortNumber, PortStatistics> statsMap = devicePortStats.get(deviceId); if (statsMap == null) { statsMap = Maps.newConcurrentMap(); devicePortStats.put(deviceId, statsMap); } for (PortStatistics stat: portStats) { PortNumber portNumber = PortNumber.portNumber(stat.port()); statsMap.put(portNumber, stat); } return new DeviceEvent(PORT_STATS_UPDATED, devices.get(deviceId), null); }
private void updatePortData(DeviceId deviceId, PortStatistics stats) { ConnectPoint cp = new ConnectPoint(deviceId, portNumber(stats.port())); DataPoint c = current.get(cp); // Create a new data point and make it the current one current.put(cp, new DataPoint(stats)); // If we have a current data point, demote it to previous if (c != null) { previous.put(cp, c); } }
@Override public ObjectNode encode(PortStatistics entry, CodecContext context) { checkNotNull(entry, "Port Statistics cannot be null"); final ObjectNode result = context.mapper().createObjectNode() .put("port", entry.port()) .put("packetsReceived", entry.packetsReceived()) .put("packetsSent", entry.packetsSent()) .put("bytesReceived", entry.bytesReceived()) .put("bytesSent", entry.bytesSent()) .put("packetsRxDropped", entry.packetsRxDropped()) .put("packetsTxDropped", entry.packetsTxDropped()) .put("packetsRxErrors", entry.packetsRxErrors()) .put("packetsTxErrors", entry.packetsTxErrors()) .put("durationSec", entry.durationSec()); return annotate(result, entry, context); }