Skip to content
Snippets Groups Projects
Commit 998f57ad authored by Ryan Izard's avatar Ryan Izard
Browse files

Add link speed to statistics REST API, which might be useful to gauge how much...

Add link speed to statistics REST API, which might be useful to gauge how much of the available bandwidth is being used.
parent 644d5da3
No related branches found
No related tags found
No related merge requests found
......@@ -6,7 +6,7 @@ import org.projectfloodlight.openflow.types.DatapathId;
import org.projectfloodlight.openflow.types.OFPort;
import net.floodlightcontroller.core.module.IFloodlightService;
import net.floodlightcontroller.topology.NodePortTuple;
import net.floodlightcontroller.core.types.NodePortTuple;
public interface IStatisticsService extends IFloodlightService {
......
......@@ -36,10 +36,10 @@ import net.floodlightcontroller.core.module.FloodlightModuleContext;
import net.floodlightcontroller.core.module.FloodlightModuleException;
import net.floodlightcontroller.core.module.IFloodlightModule;
import net.floodlightcontroller.core.module.IFloodlightService;
import net.floodlightcontroller.core.types.NodePortTuple;
import net.floodlightcontroller.restserver.IRestApiService;
import net.floodlightcontroller.statistics.web.SwitchStatisticsWebRoutable;
import net.floodlightcontroller.threadpool.IThreadPoolService;
import net.floodlightcontroller.topology.NodePortTuple;
public class StatisticsCollector implements IFloodlightModule, IStatisticsService {
private static final Logger log = LoggerFactory.getLogger(StatisticsCollector.class);
......@@ -120,15 +120,21 @@ public class StatisticsCollector implements IFloodlightModule, IStatisticsServic
} else {
txBytesCounted = pse.getTxBytes().subtract(spb.getPriorByteValueTx());
}
IOFSwitch sw = switchService.getSwitch(npt.getNodeId());
long speed = 0;
if (sw != null) { /* could have disconnected; we'll assume zero-speed then */
speed = sw.getPort(npt.getPortId()).getCurrSpeed();
}
long timeDifSec = (System.currentTimeMillis() - spb.getUpdateTime()) / MILLIS_PER_SEC;
portStats.put(npt, SwitchPortBandwidth.of(npt.getNodeId(), npt.getPortId(),
U64.ofRaw(speed),
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, U64.ZERO, pse.getRxBytes(), pse.getTxBytes()));
tentativePortStats.put(npt, SwitchPortBandwidth.of(npt.getNodeId(), npt.getPortId(), U64.ZERO, U64.ZERO, U64.ZERO, pse.getRxBytes(), pse.getTxBytes()));
}
}
}
......
......@@ -14,6 +14,7 @@ import net.floodlightcontroller.statistics.web.SwitchPortBandwidthSerializer;
public class SwitchPortBandwidth {
private DatapathId id;
private OFPort pt;
private U64 speed;
private U64 rx;
private U64 tx;
private Date time;
......@@ -21,9 +22,10 @@ public class SwitchPortBandwidth {
private U64 txValue;
private SwitchPortBandwidth() {}
private SwitchPortBandwidth(DatapathId d, OFPort p, U64 rx, U64 tx, U64 rxValue, U64 txValue) {
private SwitchPortBandwidth(DatapathId d, OFPort p, U64 s, U64 rx, U64 tx, U64 rxValue, U64 txValue) {
id = d;
pt = p;
speed = s;
this.rx = rx;
this.tx = tx;
time = new Date();
......@@ -31,13 +33,16 @@ public class SwitchPortBandwidth {
this.txValue = txValue;
}
public static SwitchPortBandwidth of(DatapathId d, OFPort p, U64 rx, U64 tx, U64 rxValue, U64 txValue) {
public static SwitchPortBandwidth of(DatapathId d, OFPort p, U64 s, U64 rx, U64 tx, U64 rxValue, U64 txValue) {
if (d == null) {
throw new IllegalArgumentException("Datapath ID cannot be null");
}
if (p == null) {
throw new IllegalArgumentException("Port cannot be null");
}
if (s == null) {
throw new IllegalArgumentException("Link speed cannot be null");
}
if (rx == null) {
throw new IllegalArgumentException("RX bandwidth cannot be null");
}
......@@ -50,7 +55,7 @@ public class SwitchPortBandwidth {
if (txValue == null) {
throw new IllegalArgumentException("TX value cannot be null");
}
return new SwitchPortBandwidth(d, p, rx, tx, rxValue, txValue);
return new SwitchPortBandwidth(d, p, s, rx, tx, rxValue, txValue);
}
public DatapathId getSwitchId() {
......@@ -61,6 +66,10 @@ public class SwitchPortBandwidth {
return pt;
}
public U64 getLinkSpeedBitsPerSec() {
return speed;
}
public U64 getBitsPerSecondRx() {
return rx;
}
......
......@@ -21,6 +21,7 @@ public class SwitchPortBandwidthSerializer extends JsonSerializer<SwitchPortBand
jGen.writeStringField("dpid", spb.getSwitchId().toString());
jGen.writeStringField("port", spb.getSwitchPort().toString());
jGen.writeStringField("updated", new Date(spb.getUpdateTime()).toString());
jGen.writeStringField("link-speed-bits-per-second", spb.getLinkSpeedBitsPerSec().getBigInteger().toString());
jGen.writeStringField("bits-per-second-rx", spb.getBitsPerSecondRx().getBigInteger().toString());
jGen.writeStringField("bits-per-second-tx", spb.getBitsPerSecondTx().getBigInteger().toString());
jGen.writeEndObject();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment