Adding get flow by table REST api, fixing exceptions in dhcp

Change-Id: Idc07992a91c79f594c998b2d78b980036077c0ad
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/FlowsWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/FlowsWebResource.java
index 89ed072..3de840e 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/FlowsWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/FlowsWebResource.java
@@ -29,6 +29,7 @@
 import org.onosproject.net.flow.FlowEntry;
 import org.onosproject.net.flow.FlowRule;
 import org.onosproject.net.flow.FlowRuleService;
+import org.onosproject.net.flow.IndexTableId;
 import org.onosproject.rest.AbstractWebResource;
 
 import javax.ws.rs.Consumes;
@@ -124,6 +125,31 @@
         return ok(root).build();
     }
 
+     /**
+     * Gets all flow entries for a table. Returns array of all flow rules for a table.
+     * @param tableId table identifier
+     * @return 200 OK with a collection of flows
+     * @onos.rsModel FlowEntries
+     */
+    @GET
+    @Produces(MediaType.APPLICATION_JSON)
+    @Path("table/{tableId}")
+    public Response getTableFlows(@PathParam("tableId") int tableId) {
+        final Iterable<Device> devices = get(DeviceService.class).getDevices();
+        for (final Device device : devices) {
+            final Iterable<FlowEntry> flowEntries = service.getFlowEntries(device.id());
+            if (flowEntries != null) {
+                for (final FlowEntry entry : flowEntries) {
+                    if (((IndexTableId) entry.table()).id() == tableId) {
+                       flowsNode.add(codec(FlowEntry.class).encode(entry, this));
+                    }
+                }
+            }
+        }
+
+        return ok(root).build();
+    }
+
     /**
      * Creates new flow rules. Creates and installs a new flow rules.<br>
      * Flow rule criteria and instruction description: