aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/StatisticsWebResource.java
diff options
context:
space:
mode:
authorAshlee Young <ashlee@onosfw.com>2015-10-09 18:32:44 -0700
committerAshlee Young <ashlee@onosfw.com>2015-10-09 18:32:44 -0700
commit6a07d2d622eaa06953f3353e39c080984076e8de (patch)
treebfb50a2090fce186c2cc545a400c969bf2ea702b /framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/StatisticsWebResource.java
parente6d71622143ff9b2421a1abbe8434b954b5b1099 (diff)
Updated master to commit id 6ee8aa3e67ce89908a8c93aa9445c6f71a18f986
Change-Id: I94b055ee2f298daf71e2ec794fd0f2495bd8081f
Diffstat (limited to 'framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/StatisticsWebResource.java')
-rw-r--r--framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/StatisticsWebResource.java61
1 files changed, 61 insertions, 0 deletions
diff --git a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/StatisticsWebResource.java b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/StatisticsWebResource.java
index 2ffa2295..c91cb6d0 100644
--- a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/StatisticsWebResource.java
+++ b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/StatisticsWebResource.java
@@ -21,6 +21,7 @@ import java.util.stream.StreamSupport;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
@@ -31,7 +32,12 @@ import javax.ws.rs.core.UriInfo;
import org.onosproject.codec.JsonCodec;
import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.Device;
+import org.onosproject.net.DeviceId;
import org.onosproject.net.Link;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.flow.FlowRuleService;
+import org.onosproject.net.flow.TableStatisticsEntry;
import org.onosproject.net.link.LinkService;
import org.onosproject.net.statistic.Load;
import org.onosproject.net.statistic.StatisticService;
@@ -92,4 +98,59 @@ public class StatisticsWebResource extends AbstractWebResource {
result.set("loads", loads);
return ok(result).build();
}
+
+ /**
+ * Get table statistics for all tables of all devices.
+ *
+ * @return JSON encoded array of table statistics
+ */
+ @GET
+ @Path("flows/tables")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getTableStatistics() {
+ final FlowRuleService service = get(FlowRuleService.class);
+ final Iterable<Device> devices = get(DeviceService.class).getDevices();
+ final ObjectNode root = mapper().createObjectNode();
+ final ArrayNode rootArrayNode = root.putArray("device-table-statistics");
+ for (final Device device : devices) {
+ final ObjectNode deviceStatsNode = mapper().createObjectNode();
+ deviceStatsNode.put("device", device.id().toString());
+ final ArrayNode statisticsNode = deviceStatsNode.putArray("table-statistics");
+ final Iterable<TableStatisticsEntry> tableStatsEntries = service.getFlowTableStatistics(device.id());
+ if (tableStatsEntries != null) {
+ for (final TableStatisticsEntry entry : tableStatsEntries) {
+ statisticsNode.add(codec(TableStatisticsEntry.class).encode(entry, this));
+ }
+ }
+ rootArrayNode.add(deviceStatsNode);
+ }
+
+ return ok(root).build();
+ }
+
+ /**
+ * Get table statistics for all tables of a specified device.
+ *
+ * @param deviceId device ID
+ * @return JSON encoded array of table statistics
+ */
+ @GET
+ @Path("flows/tables/{deviceId}")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getTableStatisticsByDeviceId(@PathParam("deviceId") String deviceId) {
+ final FlowRuleService service = get(FlowRuleService.class);
+ final Iterable<TableStatisticsEntry> tableStatisticsEntries =
+ service.getFlowTableStatistics(DeviceId.deviceId(deviceId));
+ final ObjectNode root = mapper().createObjectNode();
+ final ArrayNode rootArrayNode = root.putArray("table-statistics");
+
+ final ObjectNode deviceStatsNode = mapper().createObjectNode();
+ deviceStatsNode.put("device", deviceId);
+ final ArrayNode statisticsNode = deviceStatsNode.putArray("table-statistics");
+ for (final TableStatisticsEntry entry : tableStatisticsEntries) {
+ statisticsNode.add(codec(TableStatisticsEntry.class).encode(entry, this));
+ }
+ rootArrayNode.add(deviceStatsNode);
+ return ok(root).build();
+ }
}