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; ...@@ -17,59 +17,63 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
public class BandwidthResource extends ServerResource { 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") @Get("json")
public Object retrieve() { public Object retrieve() {
IStatisticsService statisticsService = (IStatisticsService) getContext().getAttributes().get(IStatisticsService.class.getCanonicalName()); IStatisticsService statisticsService = (IStatisticsService) getContext().getAttributes().get(IStatisticsService.class.getCanonicalName());
IOFSwitchService switchService = (IOFSwitchService) getContext().getAttributes().get(IOFSwitchService.class.getCanonicalName()); IOFSwitchService switchService = (IOFSwitchService) getContext().getAttributes().get(IOFSwitchService.class.getCanonicalName());
String d = (String) getRequestAttributes().get(SwitchStatisticsWebRoutable.DPID_STR); String d = (String) getRequestAttributes().get(SwitchStatisticsWebRoutable.DPID_STR);
String p = (String) getRequestAttributes().get(SwitchStatisticsWebRoutable.PORT_STR); String p = (String) getRequestAttributes().get(SwitchStatisticsWebRoutable.PORT_STR);
DatapathId dpid = DatapathId.NONE; DatapathId dpid = DatapathId.NONE;
if (!d.trim().equalsIgnoreCase("all")) { if (!d.trim().equalsIgnoreCase("all")) {
try { try {
dpid = DatapathId.of(d); dpid = DatapathId.of(d);
} catch (Exception e) { } catch (Exception e) {
log.error("Could not parse DPID {}", d); log.error("Could not parse DPID {}", d);
return Collections.singletonMap("ERROR", "Could not parse DPID" + d); return Collections.singletonMap("ERROR", "Could not parse DPID " + d);
} }
} /* else assume it's all */ } /* else assume it's all */
OFPort port = OFPort.ALL; OFPort port = OFPort.ALL;
if (!p.trim().equalsIgnoreCase("all")) { if (!p.trim().equalsIgnoreCase("all")) {
try { try {
port = OFPort.of(Integer.parseInt(p)); port = OFPort.of(Integer.parseInt(p));
} catch (Exception e) { } catch (Exception e) {
log.error("Could not parse port {}", p); log.error("Could not parse port {}", p);
return Collections.singletonMap("ERROR", "Could not parse port" + p); return Collections.singletonMap("ERROR", "Could not parse port " + p);
} }
} }
Set<SwitchPortBandwidth> spbs; Set<SwitchPortBandwidth> spbs;
if (dpid.equals(DatapathId.NONE)) { /* do all DPIDs */ if (dpid.equals(DatapathId.NONE)) { /* do all DPIDs */
if (port.equals(OFPort.ALL)) { /* do all ports */ if (port.equals(OFPort.ALL)) { /* do all ports --> do all DPIDs; do all ports */
spbs = new HashSet<SwitchPortBandwidth>(statisticsService.getBandwidthConsumption().values()); spbs = new HashSet<SwitchPortBandwidth>(statisticsService.getBandwidthConsumption().values());
} else { } else {
spbs = new HashSet<SwitchPortBandwidth>(); spbs = new HashSet<SwitchPortBandwidth>();
for (DatapathId id : switchService.getAllSwitchDpids()) { for (DatapathId id : switchService.getAllSwitchDpids()) { /* do all DPIDs; do specific port */
SwitchPortBandwidth spb = statisticsService.getBandwidthConsumption(id, port); SwitchPortBandwidth spb = statisticsService.getBandwidthConsumption(id, port);
if (spb != null) { if (spb != null) {
spbs.add(spb); spbs.add(spb);
} }
} }
} }
} else { } else { /* do specific DPID */
spbs = new HashSet<SwitchPortBandwidth>(); if (!port.equals(OFPort.ALL)) { /* do specific port --> do specific DPID; do specific port */
for (OFPortDesc pd : switchService.getSwitch(dpid).getPorts()) { spbs = new HashSet<SwitchPortBandwidth>(Collections.singleton(statisticsService.getBandwidthConsumption(dpid, port)));
SwitchPortBandwidth spb = statisticsService.getBandwidthConsumption(dpid, pd.getPortNo()); } else {
if (spb != null) { spbs = new HashSet<SwitchPortBandwidth>();
spbs.add(spb); 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; }
} }
}
}
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