...
Code Block | ||
---|---|---|
| ||
public void run() { Map<DatapathId, List<OFStatsReply>> replies = getSwitchStatistics(switchService.getAllSwitchDpids(), OFStatsType.PORT); for (Entry<DatapathId, List<OFStatsReply>> e : replies.entrySet()) { for (OFStatsReply r : e.getValue()) { OFPortStatsReply psr = (OFPortStatsReply) r; for (OFPortStatsEntry pse : psr.getEntries()) { NodePortTuple npt = new NodePortTuple(e.getKey(), pse.getPortNo()); SwitchPortBandwidth spb; if (portStats.containsKey(npt) || tentativePortStats.containsKey(npt)) { if (portStats.containsKey(npt)) { /* update */ spb = portStats.get(npt); } else if (tentativePortStats.containsKey(npt)) { /* finish */ spb = tentativePortStats.get(npt); tentativePortStats.remove(npt); } else { log.error("Inconsistent state between tentative and official port stats lists."); return; } /* Get counted bytes over the elapsed period. Check for counter overflow. */ U64 rxBytesCounted; U64 txBytesCounted; if (spb.getPriorByteValueRx().compareTo(pse.getRxBytes()) > 0) { /* overflow */ U64 upper = U64.NO_MASK.subtract(spb.getPriorByteValueRx()); U64 lower = pse.getRxBytes(); rxBytesCounted = upper.add(lower); } else { rxBytesCounted = pse.getRxBytes().subtract(spb.getPriorByteValueRx()); } if (spb.getPriorByteValueTx().compareTo(pse.getTxBytes()) > 0) { /* overflow */ U64 upper = U64.NO_MASK.subtract(spb.getPriorByteValueTx()); U64 lower = pse.getTxBytes(); txBytesCounted = upper.add(lower); } else { txBytesCounted = pse.getTxBytes().subtract(spb.getPriorByteValueTx()); } long timeDifSec = (System.currentTimeMillis() - spb.getUpdateTime()) / MILLIS_PER_SEC; portStats.put(npt, SwitchPortBandwidth.of(npt.getNodeId(), npt.getPortId(), U64.ofRaw((rxBytesCounted.getValue() * BITS_PER_BYTE) / timeDifSec), U64.ofRaw((txBytesCounted.getValue() * BITS_PER_BYTE) / timeDifSec), pse.getRxBytes(), pse.getTxBytes()) ); } else { /* initialize */ tentativePortStats.put( npt, SwitchPortBandwidth.of(npt.getNodeId(), npt.getPortId(), U64.ZERO, npt.getPortId(), U64.ZERO, U64.ZERO, pse.getRxBytes(), U64.ZERO, pse.getRxBytes(), pse.getTxBytes())); } } } } } |
...