Merge "Bug-835:Reserve ports should be logical ports"
[controller.git] / opendaylight / northbound / statistics / src / main / java / org / opendaylight / controller / statistics / northbound / StatisticsNorthbound.java
index 1c3fd1cf2ea10d32b148aec6d8dbb2fb2fab357a..4175f1e3c49984c7d90ac03b2207df946c9f7e3a 100644 (file)
@@ -15,9 +15,11 @@ 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;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.SecurityContext;
+import javax.ws.rs.ext.ContextResolver;
 
 import org.codehaus.enunciate.jaxrs.ResponseCode;
 import org.codehaus.enunciate.jaxrs.StatusCodes;
@@ -29,6 +31,7 @@ import org.opendaylight.controller.northbound.commons.exception.ResourceConflict
 import org.opendaylight.controller.northbound.commons.exception.ResourceNotFoundException;
 import org.opendaylight.controller.northbound.commons.exception.ServiceUnavailableException;
 import org.opendaylight.controller.northbound.commons.exception.UnauthorizedException;
+import org.opendaylight.controller.northbound.commons.query.QueryContext;
 import org.opendaylight.controller.northbound.commons.utils.NorthboundUtils;
 import org.opendaylight.controller.sal.authorization.Privilege;
 import org.opendaylight.controller.sal.core.Node;
@@ -50,21 +53,24 @@ import org.opendaylight.controller.switchmanager.ISwitchManager;
  * Authentication realm : <b>opendaylight</b><br>
  * Transport : <b>HTTP and HTTPS</b><br>
  * <br>
- * HTTPS Authentication is disabled by default. Administrator can enable it in
- * tomcat-server.xml after adding a proper keystore / SSL certificate from a
- * trusted authority.<br>
- * More info :
- * http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Configuration
+ * HTTPS Authentication is disabled by default.
  *
  */
 @Path("/")
 public class StatisticsNorthbound {
 
     private String username;
+    private QueryContext queryContext;
 
+    @Context
+    public void setQueryContext(ContextResolver<QueryContext> queryCtxResolver) {
+      if (queryCtxResolver != null) {
+        queryContext = queryCtxResolver.getContext(QueryContext.class);
+      }
+    }
     @Context
     public void setSecurityContext(SecurityContext context) {
-        username = context.getUserPrincipal().getName();
+        if (context != null && context.getUserPrincipal() != null) username = context.getUserPrincipal().getName();
     }
 
     protected String getUserName() {
@@ -111,17 +117,20 @@ public class StatisticsNorthbound {
      *            controller is "default".
      * @return List of FlowStatistics from all the Nodes
      *
-     *         <pre>
+     * <pre>
+     *
      * Example:
-     * Request URL: localhost:8080/controller/nb/v2/statistics/default/flow
      *
-     * Response in JSON:
+     * Request URL:
+     * http://localhost:8080/controller/nb/v2/statistics/default/flow
+     *
+     * Response body in JSON:
      * {
      *     "flowStatistics": [
      *         {
      *             "node": {
-     *                 "@type": "OF",
-     *                 "@id": "00:00:00:00:00:00:00:02"
+     *                 "id":"00:00:00:00:00:00:00:02",
+     *                 "type":"OF"
      *             },
      *             "flowStatistic": [
      *                 {
@@ -142,12 +151,12 @@ public class StatisticsNorthbound {
      *                         "actions": {
      *                             "@type": "output",
      *                             "port": {
-     *                                 "@type": "OF",
-     *                                 "@id": "3",
-     *                                 "node": {
-     *                                     "@type": "OF",
-     *                                     "@id": "00:00:00:00:00:00:00:02"
-     *                                 }
+     *                                 "node":{
+     *                                     "id":"00:00:00:00:00:00:00:02",
+     *                                     "type":"OF"
+     *                                 },
+     *                                 "id":"3",
+     *                                 "type":"OF"
      *                             }
      *                         },
      *                         "priority": "1",
@@ -171,11 +180,15 @@ public class StatisticsNorthbound {
      *
      *     ]
      * }
-     * Response in XML:
+     *
+     * Response body in XML:
      * &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;
      * &lt;list&gt;
      *     &lt;flowStatistics&gt;
-     *         &lt;node type=&quot;OF&quot; id=&quot;00:00:00:00:00:00:00:02&quot;/&gt;
+     *         &lt;node&gt;
+     *             &lt;id&gt;00:00:00:00:00:00:00:02&lt;/id&gt;
+     *             &lt;type&gt;OF&lt;/type&gt;
+     *         &lt;/node&gt;
      *         &lt;flowStatistic&gt;
      *             &lt;flow&gt;
      *                 &lt;match&gt;
@@ -191,8 +204,13 @@ public class StatisticsNorthbound {
      *                 &lt;/match&gt;
      *                 &lt;actions
      *                     xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:type=&quot;output&quot;&gt;
-     *                     &lt;port type=&quot;OF&quot; id=&quot;3&quot;&gt;
-     *                         &lt;node type=&quot;OF&quot; id=&quot;00:00:00:00:00:00:00:02&quot;/&gt;
+     *                     &lt;port&gt;
+     *                         &lt;node&gt;
+     *                             &lt;id&gt;00:00:00:00:00:00:00:02&lt;/id&gt;
+     *                             &lt;type&gt;OF&lt;/type&gt;
+     *                         &lt;/node&gt;
+     *                         &lt;id&gt;3&lt;/id&gt;
+     *                         &lt;type&gt;OF&lt;/type&gt;
      *                     &lt;/port&gt;
      *                 &lt;/actions&gt;
      *                 &lt;priority&gt;1&lt;/priority&gt;
@@ -226,7 +244,8 @@ public class StatisticsNorthbound {
         @ResponseCode(code = 404, condition = "The containerName is not found"),
         @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
     public AllFlowStatistics getFlowStatistics(
-            @PathParam("containerName") String containerName) {
+            @PathParam("containerName") String containerName,
+            @QueryParam("_q") String queryString) {
         if (!NorthboundUtils.isAuthorized(
                 getUserName(), containerName, Privilege.READ, this)) {
             throw new UnauthorizedException(
@@ -257,7 +276,12 @@ public class StatisticsNorthbound {
             FlowStatistics stat = new FlowStatistics(node, flowStats);
             statistics.add(stat);
         }
-        return new AllFlowStatistics(statistics);
+        AllFlowStatistics result = new AllFlowStatistics(statistics);
+        if (queryString != null) {
+            queryContext.createQuery(queryString, AllFlowStatistics.class)
+                .filter(result, FlowStatistics.class);
+        }
+        return result;
     }
 
     /**
@@ -272,16 +296,18 @@ public class StatisticsNorthbound {
      *            Node Identifier
      * @return List of Flow Statistics for a given Node. *
      *
-     *         <pre>
+     * <pre>
+     *
      * Example:
+     *
      * Request URL:
-     * http://host:8080/controller/nb/v2/statistics/default/flow/node/OF/00:00:00:00:00:00:00:01
+     * http://localhost:8080/controller/nb/v2/statistics/default/flow/node/OF/00:00:00:00:00:00:00:01
      *
-     * Response in JSON:
+     * Response body in JSON:
      * {
      *     "node": {
-     *         "@type": "OF",
-     *         "@id": "00:00:00:00:00:00:00:01"
+     *         "id":"00:00:00:00:00:00:00:01",
+     *         "type":"OF"
      *     },
      *     "flowStatistic": [
      *         {
@@ -306,13 +332,13 @@ public class StatisticsNorthbound {
      *                     },
      *                     {
      *                         "@type": "output",
-     *                         "port": {
-     *                             "@type": "OF",
-     *                             "@id": "5",
-     *                             "node": {
-     *                                 "@type": "OF",
-     *                                 "@id": "00:00:00:00:00:00:00:01"
-     *                             }
+     *                         "port":{
+     *                             "node":{
+     *                                 "id":"00:00:00:00:00:00:00:01",
+     *                                 "type":"OF"
+     *                              },
+     *                              "id":"5",
+     *                              "type":"OF"
      *                         }
      *                     }
      *                 ],
@@ -330,11 +356,13 @@ public class StatisticsNorthbound {
      *     ]
      * }
      *
-     *
-     * Response in XML:
+     * Response body in XML:
      * &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;
      *     &lt;nodeFlowStatistics&gt;
-     *         &lt;node type=&quot;OF&quot; id=&quot;00:00:00:00:00:00:00:02&quot;/&gt;
+     *         &lt;node&gt;
+     *             &lt;id&gt;00:00:00:00:00:00:00:02&lt;/id&gt;
+     *             &lt;type&gt;OF&lt;/type&gt;
+     *         &lt;/node&gt;
      *         &lt;flowStatistic&gt;
      *             &lt;flow&gt;
      *                 &lt;match&gt;
@@ -350,8 +378,13 @@ public class StatisticsNorthbound {
      *                 &lt;/match&gt;
      *                 &lt;actions
      *                     xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:type=&quot;output&quot;&gt;
-     *                     &lt;port type=&quot;OF&quot; id=&quot;3&quot;&gt;
-     *                         &lt;node type=&quot;OF&quot; id=&quot;00:00:00:00:00:00:00:02&quot;/&gt;
+     *                     &lt;port&gt;
+     *                         &lt;node&gt;
+     *                             &lt;id&gt;00:00:00:00:00:00:00:02&lt;/id&gt;
+     *                             &lt;type&gt;OF&lt;/type&gt;
+     *                         &lt;/node&gt;
+     *                         &lt;id&gt;3&lt;/id&gt;
+     *                         &lt;type&gt;OF&lt;/type&gt;
      *                     &lt;/port&gt;
      *                 &lt;/actions&gt;
      *                 &lt;priority&gt;1&lt;/priority&gt;
@@ -380,8 +413,13 @@ public class StatisticsNorthbound {
      *                 &lt;/match&gt;
      *                 &lt;actions
      *                     xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:type=&quot;output&quot;&gt;
-     *                     &lt;port type=&quot;OF&quot; id=&quot;3&quot;&gt;
-     *                         &lt;node type=&quot;OF&quot; id=&quot;00:00:00:00:00:00:00:02&quot;/&gt;
+     *                     &lt;port&gt;
+     *                         &lt;node&gt;
+     *                             &lt;id&gt;00:00:00:00:00:00:00:02&lt;/id&gt;
+     *                             &lt;type&gt;OF&lt;/type&gt;
+     *                         &lt;/node&gt;
+     *                         &lt;id&gt;3&lt;/id&gt;
+     *                         &lt;type&gt;OF&lt;/type&gt;
      *                     &lt;/port&gt;
      *                 &lt;/actions&gt;
      *                 &lt;priority&gt;1&lt;/priority&gt;
@@ -445,28 +483,30 @@ public class StatisticsNorthbound {
      * @return List of all the Port Statistics across all the NodeConnectors on
      *         all the Nodes.
      *
-     *         <pre>
+     * <pre>
+     *
      * Example:
      *
-     * Requset URL: http://host:8080/controller/nb/v2/statistics/default/port
+     * Request URL:
+     * http://localhost:8080/controller/nb/v2/statistics/default/port
      *
-     * Response in JSON:
+     * Response body in JSON:
      * {
      *     "portStatistics": [
      *         {
      *             "node": {
-     *                 "@type": "OF",
-     *                 "@id": "00:00:00:00:00:00:00:02"
+     *                  "id":"00:00:00:00:00:00:00:02",
+     *                  "type":"OF"
      *             },
      *             "portStatistic": [
      *                 {
-     *                     "nodeConnector": {
-     *                         "@type": "OF",
-     *                         "@id": "3",
-     *                         "node": {
-     *                             "@type": "OF",
-     *                             "@id": "00:00:00:00:00:00:00:02"
-     *                         }
+     *                     "nodeConnector":{
+     *                          "node":{
+     *                                 "id":"00:00:00:00:00:00:00:02",
+     *                                 "type":"OF"
+     *                           },
+     *                           "id":"3",
+     *                           "type":"OF"
      *                     },
      *                     "receivePackets": "182",
      *                     "transmitPackets": "173",
@@ -483,12 +523,12 @@ public class StatisticsNorthbound {
      *                 },
      *                 {
      *                     "nodeConnector": {
-     *                         "@type": "OF",
-     *                         "@id": "2",
-     *                         "node": {
-     *                             "@type": "OF",
-     *                             "@id": "00:00:00:00:00:00:00:02"
-     *                         }
+     *                          "node":{
+     *                                  "id":"00:00:00:00:00:00:00:02",
+     *                                  "type":"OF"
+     *                           },
+     *                           "id":"2",
+     *                           "type":"OF"
      *                     },
      *                     "receivePackets": "174",
      *                     "transmitPackets": "181",
@@ -508,8 +548,8 @@ public class StatisticsNorthbound {
      *         },
      *         {
      *             "node": {
-     *                 "@type": "OF",
-     *                 "@id": "00:00:00:00:00:00:00:03"
+     *                  "id":"00:00:00:00:00:00:00:03",
+     *                  "type":"OF"
      *             },
      *             "portStatistic": [
      *                  ..................
@@ -520,14 +560,22 @@ public class StatisticsNorthbound {
      *     ]
      * }
      *
-     * Response in XML:
+     * Response body in XML:
      * &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;
      * &lt;list&gt;
      *     &lt;portStatistics&gt;
-     *         &lt;node type=&quot;OF&quot; id=&quot;00:00:00:00:00:00:00:02&quot;/&gt;
-     *         &lt;portStatistic&gt;
-     *             &lt;nodeConnector type=&quot;OF&quot; id=&quot;3&quot;&gt;
-     *                 &lt;node type=&quot;OF&quot; id=&quot;00:00:00:00:00:00:00:02&quot;/&gt;
+     *          &lt;node&gt;
+     *             &lt;id&gt;00:00:00:00:00:00:00:02&lt;/id&gt;
+     *             &lt;type&gt;OF&lt;/type&gt;
+     *          &lt;/node&gt;
+     *          &lt;portStatistic&gt;
+     *             &lt;nodeConnector&gt;
+     *                &lt;node&gt;
+     *                   &lt;id&gt;00:00:00:00:00:00:00:02&lt;/id&gt;
+     *                   &lt;type&gt;OF&lt;/type&gt;
+     *                &lt;/node&gt;
+     *                &lt;id&gt;3&lt;/id&gt;
+     *                &lt;type&gt;OF&lt;/type&gt;
      *             &lt;/nodeConnector&gt;
      *             &lt;receivePackets&gt;181&lt;/receivePackets&gt;
      *             &lt;transmitPackets&gt;172&lt;/transmitPackets&gt;
@@ -543,8 +591,13 @@ public class StatisticsNorthbound {
      *             &lt;collisionCount&gt;0&lt;/collisionCount&gt;
      *         &lt;/portStatistic&gt;
      *         &lt;portStatistic&gt;
-     *             &lt;nodeConnector type=&quot;OF&quot; id=&quot;2&quot;&gt;
-     *                 &lt;node type=&quot;OF&quot; id=&quot;00:00:00:00:00:00:00:02&quot;/&gt;
+     *             &lt;nodeConnector&gt;
+     *                &lt;node&gt;
+     *                   &lt;id&gt;00:00:00:00:00:00:00:02&lt;/id&gt;
+     *                   &lt;type&gt;OF&lt;/type&gt;
+     *                &lt;/node&gt;
+     *                &lt;id&gt;2&lt;/id&gt;
+     *                &lt;type&gt;OF&lt;/type&gt;
      *             &lt;/nodeConnector&gt;
      *             &lt;receivePackets&gt;173&lt;/receivePackets&gt;
      *             &lt;transmitPackets&gt;180&lt;/transmitPackets&gt;
@@ -559,7 +612,6 @@ public class StatisticsNorthbound {
      *             &lt;receiveCrcError&gt;0&lt;/receiveCrcError&gt;
      *             &lt;collisionCount&gt;0&lt;/collisionCount&gt;
      *         &lt;/portStatistic&gt;
-     *
      *     &lt;/portStatistics&gt;
      * &lt;/list&gt;
      * </pre>
@@ -574,7 +626,8 @@ public class StatisticsNorthbound {
         @ResponseCode(code = 404, condition = "The containerName is not found"),
         @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
     public AllPortStatistics getPortStatistics(
-            @PathParam("containerName") String containerName) {
+            @PathParam("containerName") String containerName,
+            @QueryParam("_q") String queryString) {
 
         if (!NorthboundUtils.isAuthorized(
                 getUserName(), containerName, Privilege.READ, this)) {
@@ -602,7 +655,13 @@ public class StatisticsNorthbound {
             PortStatistics portStat = new PortStatistics(node, stat);
             statistics.add(portStat);
         }
-        return new AllPortStatistics(statistics);
+
+        AllPortStatistics result = new AllPortStatistics(statistics);
+        if (queryString != null) {
+            queryContext.createQuery(queryString, AllPortStatistics.class)
+                .filter(result, PortStatistics.class);
+        }
+        return result;
     }
 
     /**
@@ -619,27 +678,28 @@ public class StatisticsNorthbound {
      * @return Returns a list of all the Port Statistics across all the
      *         NodeConnectors in a given Node.
      *
-     *         <pre>
+     * <pre>
+     *
      * Example:
      *
      * Request URL:
-     * http://host:8080/controller/nb/v2/statistics/default/port/node/OF/00:00:00:00:00:00:00:01
+     * http://localhost:8080/controller/nb/v2/statistics/default/port/node/OF/00:00:00:00:00:00:00:01
      *
-     * Response in JSON:
+     * Response body in JSON:
      * {
      *     "node": {
-     *         "@type": "OF",
-     *         "@id": "00:00:00:00:00:00:00:01"
+     *         "id":"00:00:00:00:00:00:00:01",
+     *         "type":"OF"
      *     },
      *     "portStatistic": [
      *         {
      *             "nodeConnector": {
-     *                 "@type": "OF",
-     *                 "@id": "3",
-     *                 "node": {
-     *                     "@type": "OF",
-     *                     "@id": "00:00:00:00:00:00:00:01"
-     *                 }
+     *                 "node":{
+     *                     "id":"00:00:00:00:00:00:00:01",
+     *                     "type":"OF"
+     *                 },
+     *                 "id":"3",
+     *                 "type":"OF"
      *             },
      *             "receivePackets": "171",
      *             "transmitPackets": "2451",
@@ -656,12 +716,12 @@ public class StatisticsNorthbound {
      *         },
      *         {
      *             "nodeConnector": {
-     *                 "@type": "OF",
-     *                 "@id": "2",
-     *                 "node": {
-     *                     "@type": "OF",
-     *                     "@id": "00:00:00:00:00:00:00:01"
-     *                 }
+     *                 "node":{
+     *                     "id":"00:00:00:00:00:00:00:01",
+     *                     "type":"OF"
+     *                 },
+     *                 "id":"2",
+     *                 "type":"OF"
      *             },
      *             "receivePackets": "179",
      *             "transmitPackets": "2443",
@@ -679,13 +739,21 @@ public class StatisticsNorthbound {
      *     ]
      * }
      *
-     * Response in XML:
+     * Response body in XML:
      * &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;
      * &lt;nodePortStatistics&gt;
-     *     &lt;node type=&quot;OF&quot; id=&quot;00:00:00:00:00:00:00:01&quot;/&gt;
+     *     &lt;node&gt;
+     *         &lt;id&gt;00:00:00:00:00:00:00:01&lt;/id&gt;
+     *         &lt;type&gt;OF&lt;/type&gt;
+     *     &lt;/node&gt;
      *     &lt;portStatistic&gt;
-     *         &lt;nodeConnector type=&quot;OF&quot; id=&quot;2&quot;&gt;
-     *             &lt;node type=&quot;OF&quot; id=&quot;00:00:00:00:00:00:00:01&quot;/&gt;
+     *         &lt;nodeConnector&gt;
+     *             &lt;node&gt;
+     *                 &lt;id&gt;00:00:00:00:00:00:00:01&lt;/id&gt;
+     *                 &lt;type&gt;OF&lt;/type&gt;
+     *             &lt;/node&gt;
+     *             &lt;id&gt;2&lt;/id&gt;
+     *             &lt;type&gt;OF&lt;/type&gt;
      *         &lt;/nodeConnector&gt;
      *         &lt;receivePackets&gt;180&lt;/receivePackets&gt;
      *         &lt;transmitPackets&gt;2594&lt;/transmitPackets&gt;
@@ -701,8 +769,13 @@ public class StatisticsNorthbound {
      *         &lt;collisionCount&gt;0&lt;/collisionCount&gt;
      *     &lt;/portStatistic&gt;
      *     &lt;portStatistic&gt;
-     *         &lt;nodeConnector type=&quot;OF&quot; id=&quot;5&quot;&gt;
-     *             &lt;node type=&quot;OF&quot; id=&quot;00:00:00:00:00:00:00:01&quot;/&gt;
+     *         &lt;nodeConnector&gt;
+     *             &lt;node&gt;
+     *                 &lt;id&gt;00:00:00:00:00:00:00:01&lt;/id&gt;
+     *                 &lt;type&gt;OF&lt;/type&gt;
+     *             &lt;/node&gt;
+     *             &lt;id&gt;5&lt;/id&gt;
+     *             &lt;type&gt;OF&lt;/type&gt;
      *         &lt;/nodeConnector&gt;
      *         &lt;receivePackets&gt;2542&lt;/receivePackets&gt;
      *         &lt;transmitPackets&gt;2719&lt;/transmitPackets&gt;
@@ -768,34 +841,34 @@ public class StatisticsNorthbound {
      *
      * @return Returns a list of all the Table Statistics in a given Node.
      *
-     *         <pre>
-     *
-     *  Example:
+     * <pre>
      *
-     *  Request URL:
-     *  http://host:8080/controller/nb/v2/statistics/default/table
+     * Example:
      *
-     *  Response in JSON:
+     * Request URL:
+     * http://localhost:8080/controller/nb/v2/statistics/default/table
      *
+     * Response body in JSON:
      * {
      *     "tableStatistics": [
      *         {
      *             "node": {
-     *                 "@type": "OF",
-     *                 "@id": "00:00:00:00:00:00:00:02"
+     *                 "id":"00:00:00:00:00:00:00:02",
+     *                 "type":"OF"
      *             },
      *             "tableStatistic": [
      *                 {
      *                     "nodeTable": {
-     *                         "@id": "0",
-     *                         "node": {
-     *                             "@type": "OF",
-     *                             "@id": "00:00:00:00:00:00:00:02"
-     *                         }
+     *                        "node":{
+     *                           "id":"00:00:00:00:00:00:00:02",
+     *                           "type":"OF"
+     *                         },
+     *                         "id":"0"
      *                     },
      *                     "activeCount": "11",
      *                     "lookupCount": "816",
-     *                     "matchedCount": "220"
+     *                     "matchedCount": "220",
+     *                     "maximumEntries": "1000"
      *                 },
      *                 {
      *                     ...another table
@@ -808,35 +881,52 @@ public class StatisticsNorthbound {
      *     ]
      * }
      *
-     *
-     *  Response in XML:
+     *  Response body in XML:
      *  &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;
      *  &lt;list&gt;
      *  &lt;tableStatistics&gt;
-     *      &lt;node type=&quot;OF&quot; id=&quot;00:00:00:00:00:00:00:01&quot;/&gt;
+     *      &lt;node&gt;
+     *          &lt;id&gt;00:00:00:00:00:00:00:01&lt;/id&gt;
+     *          &lt;type&gt;OF&lt;/type&gt;
+     *      &lt;/node&gt;
      *      &lt;tableStatistic&gt;
-     *          &lt;nodeTable id=&quot;0&quot;&gt;
-     *              &lt;node type=&quot;OF&quot; id=&quot;00:00:00:00:00:00:00:01&quot;/&gt;
+     *          &lt;nodeTable&gt;
+     *              &lt;node&gt;
+     *                  &lt;id&gt;00:00:00:00:00:00:00:01&lt;/id&gt;
+     *                  &lt;type&gt;OF&lt;/type&gt;
+     *              &lt;/node&gt;
+     *              &lt;id&gt;0&lt;/id&gt;
      *          &lt;/nodeTable&gt;
      *          &lt;activeCount&gt;12&lt;/activeCount&gt;
      *          &lt;lookupCount&gt;10935&lt;/lookupCount&gt;
      *          &lt;matchedCount&gt;10084&lt;/matchedCount&gt;
+     *          &lt;maximumEntries&gt;1000&lt;/maximumEntries&gt;
      *      &lt;/tableStatistic&gt;
      *      &lt;tableStatistic&gt;
-     *          &lt;nodeTable id=&quot;1&quot;&gt;
-     *              &lt;node type=&quot;OF&quot; id=&quot;00:00:00:00:00:00:00:01&quot;/&gt;
+     *          &lt;nodeTable&gt;
+     *              &lt;node&gt;
+     *                  &lt;id&gt;00:00:00:00:00:00:00:01&lt;/id&gt;
+     *                  &lt;type&gt;OF&lt;/type&gt;
+     *              &lt;/node&gt;
+     *              &lt;id&gt;1&lt;/id&gt;
      *          &lt;/nodeTable&gt;
      *          &lt;activeCount&gt;0&lt;/activeCount&gt;
      *          &lt;lookupCount&gt;0&lt;/lookupCount&gt;
      *          &lt;matchedCount&gt;0&lt;/matchedCount&gt;
+     *          &lt;maximumEntries&gt;0&lt;/maximumEntries&gt;
      *      &lt;/tableStatistic&gt;
      *      &lt;tableStatistic&gt;
-     *          &lt;nodeTable id=&quot;2&quot;&gt;
-     *              &lt;node type=&quot;OF&quot; id=&quot;00:00:00:00:00:00:00:01&quot;/&gt;
+     *          &lt;nodeTable&gt;
+     *              &lt;node&gt;
+     *                  &lt;id&gt;00:00:00:00:00:00:00:01&lt;/id&gt;
+     *                  &lt;type&gt;OF&lt;/type&gt;
+     *              &lt;/node&gt;
+     *              &lt;id&gt;2&lt;/id&gt;
      *          &lt;/nodeTable&gt;
      *          &lt;activeCount&gt;0&lt;/activeCount&gt;
      *          &lt;lookupCount&gt;0&lt;/lookupCount&gt;
      *          &lt;matchedCount&gt;0&lt;/matchedCount&gt;
+     *          &lt;maximumEntries&gt;0&lt;/maximumEntries&gt;
      *      &lt;/tableStatistic&gt;
      *  &lt;/tableStatistics&gt;
      *  &lt;tableStatistics&gt;
@@ -857,7 +947,8 @@ public class StatisticsNorthbound {
         @ResponseCode(code = 404, condition = "The containerName is not found"),
         @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
     public AllTableStatistics getTableStatistics(
-            @PathParam("containerName") String containerName) {
+            @PathParam("containerName") String containerName,
+            @QueryParam("_q") String queryString) {
 
         if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.READ, this)) {
             throw new UnauthorizedException("User is not authorized to perform this operation on container "
@@ -885,7 +976,12 @@ public class StatisticsNorthbound {
             TableStatistics tableStat = new TableStatistics(node, stat);
             statistics.add(tableStat);
         }
-        return new AllTableStatistics(statistics);
+        AllTableStatistics allstats = new AllTableStatistics(statistics);
+        if (queryString != null) {
+            queryContext.createQuery(queryString, AllTableStatistics.class)
+                .filter(allstats, TableStatistics.class);
+        }
+        return allstats;
     }
 
     /**
@@ -900,78 +996,97 @@ public class StatisticsNorthbound {
      *            Identifier (e.g. MAC address)
      * @return Returns a list of all the Table Statistics in a given Node.
      *
-     *         <pre>
+     * <pre>
      *
      * Example:
      *
      * Request URL:
-     * http://host:8080/controller/nb/v2/statistics/default/table/node/OF/00:00:00:00:00:00:00:01
+     * http://localhost:8080/controller/nb/v2/statistics/default/table/node/OF/00:00:00:00:00:00:00:01
      *
-     * Response in JSON:
+     * Response body in JSON:
      * {
      *     "node": {
-     *         "@type": "OF",
-     *         "@id": "00:00:00:00:00:00:00:01"
+     *         "id":"00:00:00:00:00:00:00:01",
+     *         "type":"OF"
      *     },
      *     "tableStatistic": [
      *         {
      *             "nodeTable": {
-     *                 "@id": "0",
-     *                 "node": {
-     *                     "@type": "OF",
-     *                     "@id": "00:00:00:00:00:00:00:01"
-     *                 }
+     *                 "node":{
+     *                     "id":"00:00:00:00:00:00:00:01",
+     *                     "type":"OF"
+     *                 },
+     *                 "id":"0"
      *             },
      *             "activeCount": "12",
      *             "lookupCount": "11382",
-     *             "matchedCount": "10524"
+     *             "matchedCount": "10524",
+     *             "maximumEntries": "1000"
      *         },
      *         {
      *             "nodeTable": {
-     *                 "@id": "1",
-     *                 "node": {
-     *                     "@type": "OF",
-     *                     "@id": "00:00:00:00:00:00:00:01"
-     *                 }
+     *                 "node":{
+     *                     "id":"00:00:00:00:00:00:00:01",
+     *                     "type":"OF"
+     *                 },
+     *                 "id":"1"
      *             },
      *             "activeCount": "0",
      *             "lookupCount": "0",
-     *             "matchedCount": "0"
+     *             "matchedCount": "0",
+     *             "maximumEntries": "0"
      *         }
      *    ]
      * }
      *
-     * Response in XML:
+     * Response body in XML:
      * &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;
      * &lt;nodeTableStatistics&gt;
-     *     &lt;node type=&quot;OF&quot; id=&quot;00:00:00:00:00:00:00:01&quot;/&gt;
+     *     &lt;node&gt;
+     *          &lt;id&gt;00:00:00:00:00:00:00:01&lt;/id&gt;
+     *          &lt;type&gt;OF&lt;/type&gt;
+     *     &lt;/node&gt;
      *     &lt;tableStatistic&gt;
-     *         &lt;nodeTable id=&quot;0&quot;&gt;
-     *             &lt;node type=&quot;OF&quot; id=&quot;00:00:00:00:00:00:00:01&quot;/&gt;
+     *         &lt;nodeTable&gt;
+     *             &lt;node&gt;
+     *                 &lt;id&gt;00:00:00:00:00:00:00:01&lt;/id&gt;
+     *                 &lt;type&gt;OF&lt;/type&gt;
+     *             &lt;/node&gt;
+     *             &lt;id&gt;0&lt;/id&gt;
      *         &lt;/nodeTable&gt;
      *         &lt;activeCount&gt;12&lt;/activeCount&gt;
      *         &lt;lookupCount&gt;10935&lt;/lookupCount&gt;
      *         &lt;matchedCount&gt;10084&lt;/matchedCount&gt;
+     *         &lt;maximumEntries&gt;1000&lt;/maximumEntries&gt;
      *     &lt;/tableStatistic&gt;
      *     &lt;tableStatistic&gt;
-     *         &lt;nodeTable id=&quot;1&quot;&gt;
-     *             &lt;node type=&quot;OF&quot; id=&quot;00:00:00:00:00:00:00:01&quot;/&gt;
+     *         &lt;nodeTable&gt;
+     *             &lt;node&gt;
+     *                 &lt;id&gt;00:00:00:00:00:00:00:01&lt;/id&gt;
+     *                 &lt;type&gt;OF&lt;/type&gt;
+     *             &lt;/node&gt;
+     *             &lt;id&gt;1&lt;/id&gt;
      *         &lt;/nodeTable&gt;
      *         &lt;activeCount&gt;0&lt;/activeCount&gt;
      *         &lt;lookupCount&gt;0&lt;/lookupCount&gt;
      *         &lt;matchedCount&gt;0&lt;/matchedCount&gt;
+     *         &lt;maximumEntries&gt;0&lt;/maximumEntries&gt;
      *     &lt;/tableStatistic&gt;
      *     &lt;tableStatistic&gt;
-     *         &lt;nodeTable id=&quot;2&quot;&gt;
-     *             &lt;node type=&quot;OF&quot; id=&quot;00:00:00:00:00:00:00:01&quot;/&gt;
+     *         &lt;nodeTable&gt;
+     *             &lt;node&gt;
+     *                 &lt;id&gt;00:00:00:00:00:00:00:01&lt;/id&gt;
+     *                 &lt;type&gt;OF&lt;/type&gt;
+     *             &lt;/node&gt;
+     *             &lt;id&gt;2&lt;/id&gt;
      *         &lt;/nodeTable&gt;
      *         &lt;activeCount&gt;0&lt;/activeCount&gt;
      *         &lt;lookupCount&gt;0&lt;/lookupCount&gt;
      *         &lt;matchedCount&gt;0&lt;/matchedCount&gt;
+     *         &lt;maximumEntries&gt;0&lt;/maximumEntries&gt;
      *     &lt;/tableStatistic&gt;
      * &lt;/nodeTableStatistics&gt;
      *
-     *
      * </pre>
      */
     @Path("/{containerName}/table/node/{nodeType}/{nodeId}")