[ONOS-6607] Get active flow entries count in FlowRuleService

Change-Id: I68b4d916f92427c06a82d3622fcc05738f64541c
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/StatisticsWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/StatisticsWebResource.java
index 5dc2d5e..4a64e3b 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/StatisticsWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/StatisticsWebResource.java
@@ -331,4 +331,28 @@
         return ok(root).build();
     }
 
+    /**
+     * Gets sum of active entries in all tables for all devices.
+     *
+     * @onos.rsModel StatisticsFlowsActiveEntries
+     * @return 200 OK with JSON encoded array of active entry count per device
+     */
+    @GET
+    @Path("flows/activeentries")
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response getActiveEntriesCountPerDevice() {
+        final FlowRuleService service = get(FlowRuleService.class);
+        final Iterable<Device> devices = get(DeviceService.class).getDevices();
+        final ObjectNode root = mapper().createObjectNode();
+        final ArrayNode rootArrayNode = root.putArray("statistics");
+        for (final Device device : devices) {
+            long activeEntries = service.getActiveFlowRuleCount(device.id());
+            final ObjectNode entry = mapper().createObjectNode();
+            entry.put("device", device.id().toString());
+            entry.put("activeEntries", activeEntries);
+            rootArrayNode.add(entry);
+        }
+
+        return ok(root).build();
+    }
 }
diff --git a/web/api/src/main/resources/definitions/StatisticsFlowsActiveEntries.json b/web/api/src/main/resources/definitions/StatisticsFlowsActiveEntries.json
new file mode 100644
index 0000000..9a677d7
--- /dev/null
+++ b/web/api/src/main/resources/definitions/StatisticsFlowsActiveEntries.json
@@ -0,0 +1,38 @@
+{
+  "type": "object",
+  "title": "statistics",
+  "required": [
+    "statistics"
+  ],
+  "properties": {
+    "statistics": {
+      "type": "array",
+      "required": [
+        "statistics"
+      ],
+      "xml": {
+        "name": "statistics",
+        "wrapped": true
+      },
+      "items": {
+        "type": "object",
+        "title": "statistics",
+        "required": [
+          "device",
+          "activeEntries"
+        ],
+        "properties": {
+          "device": {
+            "type": "string",
+            "example": "of:0000000000000001"
+          },
+          "activeEntries": {
+            "type": "integer",
+            "format": "int64",
+            "example": 0
+          }
+        }
+      }
+    }
+  }
+}
\ No newline at end of file