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

Fix bug in statistics module REST API to correctly retrieve requested...

Fix bug in statistics module REST API to correctly retrieve requested statistics for given DPID and port.
parent 5afa4723
No related branches found
No related tags found
No related merge requests found
......@@ -17,59 +17,63 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class BandwidthResource extends ServerResource {
private static final Logger log = LoggerFactory.getLogger(BandwidthResource.class);
private static final Logger log = LoggerFactory.getLogger(BandwidthResource.class);
@Get("json")
public Object retrieve() {
IStatisticsService statisticsService = (IStatisticsService) getContext().getAttributes().get(IStatisticsService.class.getCanonicalName());
IOFSwitchService switchService = (IOFSwitchService) getContext().getAttributes().get(IOFSwitchService.class.getCanonicalName());
@Get("json")
public Object retrieve() {
IStatisticsService statisticsService = (IStatisticsService) getContext().getAttributes().get(IStatisticsService.class.getCanonicalName());
IOFSwitchService switchService = (IOFSwitchService) getContext().getAttributes().get(IOFSwitchService.class.getCanonicalName());
String d = (String) getRequestAttributes().get(SwitchStatisticsWebRoutable.DPID_STR);
String p = (String) getRequestAttributes().get(SwitchStatisticsWebRoutable.PORT_STR);
String d = (String) getRequestAttributes().get(SwitchStatisticsWebRoutable.DPID_STR);
String p = (String) getRequestAttributes().get(SwitchStatisticsWebRoutable.PORT_STR);
DatapathId dpid = DatapathId.NONE;
DatapathId dpid = DatapathId.NONE;
if (!d.trim().equalsIgnoreCase("all")) {
try {
dpid = DatapathId.of(d);
} catch (Exception e) {
log.error("Could not parse DPID {}", d);
return Collections.singletonMap("ERROR", "Could not parse DPID" + d);
}
} /* else assume it's all */
if (!d.trim().equalsIgnoreCase("all")) {
try {
dpid = DatapathId.of(d);
} catch (Exception e) {
log.error("Could not parse DPID {}", d);
return Collections.singletonMap("ERROR", "Could not parse DPID " + d);
}
} /* else assume it's all */
OFPort port = OFPort.ALL;
if (!p.trim().equalsIgnoreCase("all")) {
try {
port = OFPort.of(Integer.parseInt(p));
} catch (Exception e) {
log.error("Could not parse port {}", p);
return Collections.singletonMap("ERROR", "Could not parse port" + p);
}
}
OFPort port = OFPort.ALL;
if (!p.trim().equalsIgnoreCase("all")) {
try {
port = OFPort.of(Integer.parseInt(p));
} catch (Exception e) {
log.error("Could not parse port {}", p);
return Collections.singletonMap("ERROR", "Could not parse port " + p);
}
}
Set<SwitchPortBandwidth> spbs;
if (dpid.equals(DatapathId.NONE)) { /* do all DPIDs */
if (port.equals(OFPort.ALL)) { /* do all ports */
spbs = new HashSet<SwitchPortBandwidth>(statisticsService.getBandwidthConsumption().values());
} else {
spbs = new HashSet<SwitchPortBandwidth>();
for (DatapathId id : switchService.getAllSwitchDpids()) {
SwitchPortBandwidth spb = statisticsService.getBandwidthConsumption(id, port);
if (spb != null) {
spbs.add(spb);
}
}
}
} else {
spbs = new HashSet<SwitchPortBandwidth>();
for (OFPortDesc pd : switchService.getSwitch(dpid).getPorts()) {
SwitchPortBandwidth spb = statisticsService.getBandwidthConsumption(dpid, pd.getPortNo());
if (spb != null) {
spbs.add(spb);
}
}
}
return spbs;
}
Set<SwitchPortBandwidth> spbs;
if (dpid.equals(DatapathId.NONE)) { /* do all DPIDs */
if (port.equals(OFPort.ALL)) { /* do all ports --> do all DPIDs; do all ports */
spbs = new HashSet<SwitchPortBandwidth>(statisticsService.getBandwidthConsumption().values());
} else {
spbs = new HashSet<SwitchPortBandwidth>();
for (DatapathId id : switchService.getAllSwitchDpids()) { /* do all DPIDs; do specific port */
SwitchPortBandwidth spb = statisticsService.getBandwidthConsumption(id, port);
if (spb != null) {
spbs.add(spb);
}
}
}
} else { /* do specific DPID */
if (!port.equals(OFPort.ALL)) { /* do specific port --> do specific DPID; do specific port */
spbs = new HashSet<SwitchPortBandwidth>(Collections.singleton(statisticsService.getBandwidthConsumption(dpid, port)));
} else {
spbs = new HashSet<SwitchPortBandwidth>();
for (OFPortDesc pd : switchService.getSwitch(dpid).getPorts()) { /* do specific DPID; do all ports */
SwitchPortBandwidth spb = statisticsService.getBandwidthConsumption(dpid, pd.getPortNo());
if (spb != null) {
spbs.add(spb);
}
}
}
}
return spbs;
}
}
\ No newline at end of file
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