Merge topic 'checkstyle'
[controller.git] / opendaylight / adsal / northbound / statistics / src / main / java / org / opendaylight / controller / statistics / northbound / StatisticsNorthbound.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.statistics.northbound;
10
11 import java.util.ArrayList;
12 import java.util.List;
13
14 import javax.ws.rs.GET;
15 import javax.ws.rs.Path;
16 import javax.ws.rs.PathParam;
17 import javax.ws.rs.Produces;
18 import javax.ws.rs.QueryParam;
19 import javax.ws.rs.core.Context;
20 import javax.ws.rs.core.MediaType;
21 import javax.ws.rs.core.SecurityContext;
22 import javax.ws.rs.ext.ContextResolver;
23
24 import org.codehaus.enunciate.jaxrs.ResponseCode;
25 import org.codehaus.enunciate.jaxrs.StatusCodes;
26 import org.codehaus.enunciate.jaxrs.TypeHint;
27 import org.opendaylight.controller.containermanager.IContainerManager;
28 import org.opendaylight.controller.northbound.commons.RestMessages;
29 import org.opendaylight.controller.northbound.commons.exception.InternalServerErrorException;
30 import org.opendaylight.controller.northbound.commons.exception.ResourceConflictException;
31 import org.opendaylight.controller.northbound.commons.exception.ResourceNotFoundException;
32 import org.opendaylight.controller.northbound.commons.exception.ServiceUnavailableException;
33 import org.opendaylight.controller.northbound.commons.exception.UnauthorizedException;
34 import org.opendaylight.controller.northbound.commons.query.QueryContext;
35 import org.opendaylight.controller.northbound.commons.utils.NorthboundUtils;
36 import org.opendaylight.controller.sal.authorization.Privilege;
37 import org.opendaylight.controller.sal.core.Node;
38 import org.opendaylight.controller.sal.reader.FlowOnNode;
39 import org.opendaylight.controller.sal.reader.NodeConnectorStatistics;
40 import org.opendaylight.controller.sal.reader.NodeTableStatistics;
41 import org.opendaylight.controller.sal.utils.GlobalConstants;
42 import org.opendaylight.controller.sal.utils.ServiceHelper;
43 import org.opendaylight.controller.statisticsmanager.IStatisticsManager;
44 import org.opendaylight.controller.switchmanager.ISwitchManager;
45
46 /**
47  * Northbound APIs that returns various Statistics exposed by the Southbound
48  * protocol plugins such as Openflow.
49  *
50  * <br>
51  * <br>
52  * Authentication scheme : <b>HTTP Basic</b><br>
53  * Authentication realm : <b>opendaylight</b><br>
54  * Transport : <b>HTTP and HTTPS</b><br>
55  * <br>
56  * HTTPS Authentication is disabled by default.
57  *
58  */
59 @Path("/")
60 public class StatisticsNorthbound {
61
62     private String username;
63     private QueryContext queryContext;
64
65     @Context
66     public void setQueryContext(ContextResolver<QueryContext> queryCtxResolver) {
67       if (queryCtxResolver != null) {
68         queryContext = queryCtxResolver.getContext(QueryContext.class);
69       }
70     }
71     @Context
72     public void setSecurityContext(SecurityContext context) {
73         if (context != null && context.getUserPrincipal() != null) {
74             username = context.getUserPrincipal().getName();
75         }
76     }
77
78     protected String getUserName() {
79         return username;
80     }
81
82     private IStatisticsManager getStatisticsService(String containerName) {
83         IContainerManager containerManager = (IContainerManager) ServiceHelper
84                 .getGlobalInstance(IContainerManager.class, this);
85         if (containerManager == null) {
86             throw new ServiceUnavailableException("Container "
87                     + RestMessages.SERVICEUNAVAILABLE.toString());
88         }
89
90         boolean found = false;
91         List<String> containerNames = containerManager.getContainerNames();
92         for (String cName : containerNames) {
93             if (cName.trim().equalsIgnoreCase(containerName.trim())) {
94                 found = true;
95             }
96         }
97
98         if (found == false) {
99             throw new ResourceNotFoundException(containerName + " "
100                     + RestMessages.NOCONTAINER.toString());
101         }
102
103         IStatisticsManager statsManager = (IStatisticsManager) ServiceHelper
104                 .getInstance(IStatisticsManager.class, containerName, this);
105
106         if (statsManager == null) {
107             throw new ServiceUnavailableException("Statistics "
108                     + RestMessages.SERVICEUNAVAILABLE.toString());
109         }
110
111         return statsManager;
112     }
113
114     /**
115      * Returns a list of all Flow Statistics from all the Nodes.
116      *
117      * @param containerName
118      *            Name of the Container. The Container name for the base
119      *            controller is "default".
120      * @return List of FlowStatistics from all the Nodes
121      *
122      * <pre>
123      *
124      * Example:
125      *
126      * Request URL:
127      * http://localhost:8080/controller/nb/v2/statistics/default/flow
128      *
129      * Response body in JSON:
130      * {
131      *     "flowStatistics": [
132      *         {
133      *             "node": {
134      *                 "id":"00:00:00:00:00:00:00:02",
135      *                 "type":"OF"
136      *             },
137      *             "flowStatistic": [
138      *                 {
139      *                     "flow": {
140      *                         "match": {
141      *                             "matchField": [
142      *                                 {
143      *                                     "type": "DL_TYPE",
144      *                                     "value": "2048"
145      *                                 },
146      *                                 {
147      *                                     "mask": "255.255.255.255",
148      *                                     "type": "NW_DST",
149      *                                     "value": "1.1.1.1"
150      *                                 }
151      *                             ]
152      *                         },
153      *                         "actions": {
154      *                             "@type": "output",
155      *                             "port": {
156      *                                 "node":{
157      *                                     "id":"00:00:00:00:00:00:00:02",
158      *                                     "type":"OF"
159      *                                 },
160      *                                 "id":"3",
161      *                                 "type":"OF"
162      *                             }
163      *                         },
164      *                         "priority": "1",
165      *                         "idleTimeout": "0",
166      *                         "hardTimeout": "0",
167      *                         "id": "0"
168      *                     },
169      *                     "tableId": "0",
170      *                     "durationSeconds": "1828",
171      *                     "durationNanoseconds": "397000000",
172      *                     "packetCount": "0",
173      *                     "byteCount": "0"
174      *                 }
175      *             ]
176      *         },
177      *         {   flow statistics of another node
178      *             ............
179      *             ................
180      *             ......................
181      *         }
182      *
183      *     ]
184      * }
185      *
186      * Response body in XML:
187      * &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;
188      * &lt;list&gt;
189      *     &lt;flowStatistics&gt;
190      *         &lt;node&gt;
191      *             &lt;id&gt;00:00:00:00:00:00:00:02&lt;/id&gt;
192      *             &lt;type&gt;OF&lt;/type&gt;
193      *         &lt;/node&gt;
194      *         &lt;flowStatistic&gt;
195      *             &lt;flow&gt;
196      *                 &lt;match&gt;
197      *                     &lt;matchField&gt;
198      *                         &lt;type&gt;DL_TYPE&lt;/type&gt;
199      *                         &lt;value&gt;2048&lt;/value&gt;
200      *                     &lt;/matchField&gt;
201      *                     &lt;matchField&gt;
202      *                         &lt;mask&gt;255.255.255.255&lt;/mask&gt;
203      *                         &lt;type&gt;NW_DST&lt;/type&gt;
204      *                         &lt;value&gt;1.1.1.2&lt;/value&gt;
205      *                     &lt;/matchField&gt;
206      *                 &lt;/match&gt;
207      *                 &lt;actions
208      *                     xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:type=&quot;output&quot;&gt;
209      *                     &lt;port&gt;
210      *                         &lt;node&gt;
211      *                             &lt;id&gt;00:00:00:00:00:00:00:02&lt;/id&gt;
212      *                             &lt;type&gt;OF&lt;/type&gt;
213      *                         &lt;/node&gt;
214      *                         &lt;id&gt;3&lt;/id&gt;
215      *                         &lt;type&gt;OF&lt;/type&gt;
216      *                     &lt;/port&gt;
217      *                 &lt;/actions&gt;
218      *                 &lt;priority&gt;1&lt;/priority&gt;
219      *                 &lt;idleTimeout&gt;0&lt;/idleTimeout&gt;
220      *                 &lt;hardTimeout&gt;0&lt;/hardTimeout&gt;
221      *                 &lt;id&gt;0&lt;/id&gt;
222      *             &lt;/flow&gt;
223      *             &lt;tableId&gt;0&lt;/tableId&gt;
224      *             &lt;durationSeconds&gt;337&lt;/durationSeconds&gt;
225      *             &lt;durationNanoseconds&gt;149000000&lt;/durationNanoseconds&gt;
226      *             &lt;packetCount&gt;0&lt;/packetCount&gt;
227      *             &lt;byteCount&gt;0&lt;/byteCount&gt;
228      *         &lt;/flowStatistic&gt;
229      *     &lt;/flowStatistics&gt;
230      *     &lt;flowStatistics&gt;
231      *          flow statistics for another node
232      *          ..........
233      *          ................
234      *          .....................
235      *     &lt;/flowStatistics&gt;
236      * &lt;/list&gt;
237      * </pre>
238      */
239
240     @Path("/{containerName}/flow")
241     @GET
242     @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
243     @TypeHint(AllFlowStatistics.class)
244     @StatusCodes({
245         @ResponseCode(code = 200, condition = "Operation successful"),
246         @ResponseCode(code = 404, condition = "The containerName is not found"),
247         @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
248     public AllFlowStatistics getFlowStatistics(
249             @PathParam("containerName") String containerName,
250             @QueryParam("_q") String queryString) {
251         if (!NorthboundUtils.isAuthorized(
252                 getUserName(), containerName, Privilege.READ, this)) {
253             throw new UnauthorizedException(
254                     "User is not authorized to perform this operation on container "
255                             + containerName);
256         }
257         IStatisticsManager statisticsManager = getStatisticsService(containerName);
258         if (statisticsManager == null) {
259             throw new ServiceUnavailableException("Statistics "
260                     + RestMessages.SERVICEUNAVAILABLE.toString());
261         }
262
263         ISwitchManager switchManager = (ISwitchManager) ServiceHelper
264                 .getInstance(ISwitchManager.class, containerName, this);
265         if (switchManager == null) {
266             throw new ServiceUnavailableException("Switch manager "
267                     + RestMessages.SERVICEUNAVAILABLE.toString());
268         }
269
270         List<FlowStatistics> statistics = new ArrayList<FlowStatistics>();
271         for (Node node : switchManager.getNodes()) {
272             List<FlowOnNode> flowStats = new ArrayList<FlowOnNode>();
273
274             List<FlowOnNode> flows = statisticsManager.getFlows(node);
275             for (FlowOnNode flowOnSwitch : flows) {
276                 flowStats.add(flowOnSwitch);
277             }
278             FlowStatistics stat = new FlowStatistics(node, flowStats);
279             statistics.add(stat);
280         }
281         AllFlowStatistics result = new AllFlowStatistics(statistics);
282         if (queryString != null) {
283             queryContext.createQuery(queryString, AllFlowStatistics.class)
284                 .filter(result, FlowStatistics.class);
285         }
286         return result;
287     }
288
289     /**
290      * Returns a list of Flow Statistics for a given Node.
291      *
292      * @param containerName
293      *            Name of the Container. The Container name for the base
294      *            controller is "default".
295      * @param nodeType
296      *            Node Type as specifid in {@link org.opendaylight.controller.sal.core.Node} class
297      * @param nodeId
298      *            Node Identifier
299      * @return List of Flow Statistics for a given Node. *
300      *
301      * <pre>
302      *
303      * Example:
304      *
305      * Request URL:
306      * http://localhost:8080/controller/nb/v2/statistics/default/flow/node/OF/00:00:00:00:00:00:00:01
307      *
308      * Response body in JSON:
309      * {
310      *     "node": {
311      *         "id":"00:00:00:00:00:00:00:01",
312      *         "type":"OF"
313      *     },
314      *     "flowStatistic": [
315      *         {
316      *             "flow": {
317      *                 "match": {
318      *                     "matchField": [
319      *                         {
320      *                             "type": "DL_TYPE",
321      *                             "value": "2048"
322      *                         },
323      *                         {
324      *                             "mask": "255.255.255.255",
325      *                             "type": "NW_DST",
326      *                             "value": "1.1.1.2"
327      *                         }
328      *                     ]
329      *                 },
330      *                 "actions": [
331      *                     {
332      *                         "@type": "setDlDst",
333      *                         "address": "52d28b0f76ec"
334      *                     },
335      *                     {
336      *                         "@type": "output",
337      *                         "port":{
338      *                             "node":{
339      *                                 "id":"00:00:00:00:00:00:00:01",
340      *                                 "type":"OF"
341      *                              },
342      *                              "id":"5",
343      *                              "type":"OF"
344      *                         }
345      *                     }
346      *                 ],
347      *                 "priority": "1",
348      *                 "idleTimeout": "0",
349      *                 "hardTimeout": "0",
350      *                 "id": "0"
351      *             },
352      *             "tableId": "0",
353      *             "durationSeconds": "2089",
354      *             "durationNanoseconds": "538000000",
355      *             "packetCount": "0",
356      *             "byteCount": "0"
357      *         }
358      *     ]
359      * }
360      *
361      * Response body in XML:
362      * &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;
363      *     &lt;nodeFlowStatistics&gt;
364      *         &lt;node&gt;
365      *             &lt;id&gt;00:00:00:00:00:00:00:02&lt;/id&gt;
366      *             &lt;type&gt;OF&lt;/type&gt;
367      *         &lt;/node&gt;
368      *         &lt;flowStatistic&gt;
369      *             &lt;flow&gt;
370      *                 &lt;match&gt;
371      *                     &lt;matchField&gt;
372      *                         &lt;type&gt;DL_TYPE&lt;/type&gt;
373      *                         &lt;value&gt;2048&lt;/value&gt;
374      *                     &lt;/matchField&gt;
375      *                     &lt;matchField&gt;
376      *                         &lt;mask&gt;255.255.255.255&lt;/mask&gt;
377      *                         &lt;type&gt;NW_DST&lt;/type&gt;
378      *                         &lt;value&gt;1.1.1.2&lt;/value&gt;
379      *                     &lt;/matchField&gt;
380      *                 &lt;/match&gt;
381      *                 &lt;actions
382      *                     xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:type=&quot;output&quot;&gt;
383      *                     &lt;port&gt;
384      *                         &lt;node&gt;
385      *                             &lt;id&gt;00:00:00:00:00:00:00:02&lt;/id&gt;
386      *                             &lt;type&gt;OF&lt;/type&gt;
387      *                         &lt;/node&gt;
388      *                         &lt;id&gt;3&lt;/id&gt;
389      *                         &lt;type&gt;OF&lt;/type&gt;
390      *                     &lt;/port&gt;
391      *                 &lt;/actions&gt;
392      *                 &lt;priority&gt;1&lt;/priority&gt;
393      *                 &lt;idleTimeout&gt;0&lt;/idleTimeout&gt;
394      *                 &lt;hardTimeout&gt;0&lt;/hardTimeout&gt;
395      *                 &lt;id&gt;0&lt;/id&gt;
396      *             &lt;/flow&gt;
397      *             &lt;tableId&gt;0&lt;/tableId&gt;
398      *             &lt;durationSeconds&gt;337&lt;/durationSeconds&gt;
399      *             &lt;durationNanoseconds&gt;149000000&lt;/durationNanoseconds&gt;
400      *             &lt;packetCount&gt;0&lt;/packetCount&gt;
401      *             &lt;byteCount&gt;0&lt;/byteCount&gt;
402      *         &lt;/flowStatistic&gt;
403      *         &lt;flowStatistic&gt;
404      *             &lt;flow&gt;
405      *                 &lt;match&gt;
406      *                     &lt;matchField&gt;
407      *                         &lt;type&gt;DL_TYPE&lt;/type&gt;
408      *                         &lt;value&gt;2048&lt;/value&gt;
409      *                     &lt;/matchField&gt;
410      *                     &lt;matchField&gt;
411      *                         &lt;mask&gt;255.255.255.255&lt;/mask&gt;
412      *                         &lt;type&gt;NW_DST&lt;/type&gt;
413      *                         &lt;value&gt;1.1.1.1&lt;/value&gt;
414      *                     &lt;/matchField&gt;
415      *                 &lt;/match&gt;
416      *                 &lt;actions
417      *                     xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:type=&quot;output&quot;&gt;
418      *                     &lt;port&gt;
419      *                         &lt;node&gt;
420      *                             &lt;id&gt;00:00:00:00:00:00:00:02&lt;/id&gt;
421      *                             &lt;type&gt;OF&lt;/type&gt;
422      *                         &lt;/node&gt;
423      *                         &lt;id&gt;3&lt;/id&gt;
424      *                         &lt;type&gt;OF&lt;/type&gt;
425      *                     &lt;/port&gt;
426      *                 &lt;/actions&gt;
427      *                 &lt;priority&gt;1&lt;/priority&gt;
428      *                 &lt;idleTimeout&gt;0&lt;/idleTimeout&gt;
429      *                 &lt;hardTimeout&gt;0&lt;/hardTimeout&gt;
430      *                 &lt;id&gt;0&lt;/id&gt;
431      *             &lt;/flow&gt;
432      *             &lt;tableId&gt;0&lt;/tableId&gt;
433      *             &lt;durationSeconds&gt;337&lt;/durationSeconds&gt;
434      *             &lt;durationNanoseconds&gt;208000000&lt;/durationNanoseconds&gt;
435      *             &lt;packetCount&gt;0&lt;/packetCount&gt;
436      *             &lt;byteCount&gt;0&lt;/byteCount&gt;
437      *         &lt;/flowStatistic&gt;
438      *     &lt;/nodeFlowStatistics&gt;
439      * </pre>
440      */
441     @Path("/{containerName}/flow/node/{nodeType}/{nodeId}")
442     @GET
443     @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
444     @TypeHint(FlowStatistics.class)
445     @StatusCodes({
446         @ResponseCode(code = 200, condition = "Operation successful"),
447         @ResponseCode(code = 404, condition = "The containerName is not found"),
448         @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
449     public FlowStatistics getFlowStatistics(
450             @PathParam("containerName") String containerName,
451             @PathParam("nodeType") String nodeType,
452             @PathParam("nodeId") String nodeId) {
453         if (!NorthboundUtils.isAuthorized(
454                 getUserName(), containerName, Privilege.READ, this)) {
455             throw new UnauthorizedException(
456                     "User is not authorized to perform this operation on container "
457                             + containerName);
458         }
459         handleDefaultDisabled(containerName);
460
461         IStatisticsManager statisticsManager = getStatisticsService(containerName);
462         if (statisticsManager == null) {
463             throw new ServiceUnavailableException("Statistics "
464                     + RestMessages.SERVICEUNAVAILABLE.toString());
465         }
466
467         ISwitchManager switchManager = (ISwitchManager) ServiceHelper
468                 .getInstance(ISwitchManager.class, containerName, this);
469         if (switchManager == null) {
470             throw new ServiceUnavailableException("Switch manager "
471                     + RestMessages.SERVICEUNAVAILABLE.toString());
472         }
473
474         Node node = handleNodeAvailability(containerName, nodeType, nodeId);
475         return new FlowStatistics(node, statisticsManager.getFlows(node));
476     }
477
478     /**
479      * Returns a list of all the Port Statistics across all the NodeConnectors
480      * on all the Nodes.
481      *
482      * @param containerName
483      *            Name of the Container. The Container name for the base
484      *            controller is "default".
485      * @return List of all the Port Statistics across all the NodeConnectors on
486      *         all the Nodes.
487      *
488      * <pre>
489      *
490      * Example:
491      *
492      * Request URL:
493      * http://localhost:8080/controller/nb/v2/statistics/default/port
494      *
495      * Response body in JSON:
496      * {
497      *     "portStatistics": [
498      *         {
499      *             "node": {
500      *                  "id":"00:00:00:00:00:00:00:02",
501      *                  "type":"OF"
502      *             },
503      *             "portStatistic": [
504      *                 {
505      *                     "nodeConnector":{
506      *                          "node":{
507      *                                 "id":"00:00:00:00:00:00:00:02",
508      *                                 "type":"OF"
509      *                           },
510      *                           "id":"3",
511      *                           "type":"OF"
512      *                     },
513      *                     "receivePackets": "182",
514      *                     "transmitPackets": "173",
515      *                     "receiveBytes": "12740",
516      *                     "transmitBytes": "12110",
517      *                     "receiveDrops": "0",
518      *                     "transmitDrops": "0",
519      *                     "receiveErrors": "0",
520      *                     "transmitErrors": "0",
521      *                     "receiveFrameError": "0",
522      *                     "receiveOverRunError": "0",
523      *                     "receiveCrcError": "0",
524      *                     "collisionCount": "0"
525      *                 },
526      *                 {
527      *                     "nodeConnector": {
528      *                          "node":{
529      *                                  "id":"00:00:00:00:00:00:00:02",
530      *                                  "type":"OF"
531      *                           },
532      *                           "id":"2",
533      *                           "type":"OF"
534      *                     },
535      *                     "receivePackets": "174",
536      *                     "transmitPackets": "181",
537      *                     "receiveBytes": "12180",
538      *                     "transmitBytes": "12670",
539      *                     "receiveDrops": "0",
540      *                     "transmitDrops": "0",
541      *                     "receiveErrors": "0",
542      *                     "transmitErrors": "0",
543      *                     "receiveFrameError": "0",
544      *                     "receiveOverRunError": "0",
545      *                     "receiveCrcError": "0",
546      *                     "collisionCount": "0"
547      *                 },
548      *
549      *             ]
550      *         },
551      *         {
552      *             "node": {
553      *                  "id":"00:00:00:00:00:00:00:03",
554      *                  "type":"OF"
555      *             },
556      *             "portStatistic": [
557      *                  ..................
558      *                  .......................
559      *                  ..........................
560      *             ]
561      *         }
562      *     ]
563      * }
564      *
565      * Response body in XML:
566      * &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;
567      * &lt;list&gt;
568      *     &lt;portStatistics&gt;
569      *          &lt;node&gt;
570      *             &lt;id&gt;00:00:00:00:00:00:00:02&lt;/id&gt;
571      *             &lt;type&gt;OF&lt;/type&gt;
572      *          &lt;/node&gt;
573      *          &lt;portStatistic&gt;
574      *             &lt;nodeConnector&gt;
575      *                &lt;node&gt;
576      *                   &lt;id&gt;00:00:00:00:00:00:00:02&lt;/id&gt;
577      *                   &lt;type&gt;OF&lt;/type&gt;
578      *                &lt;/node&gt;
579      *                &lt;id&gt;3&lt;/id&gt;
580      *                &lt;type&gt;OF&lt;/type&gt;
581      *             &lt;/nodeConnector&gt;
582      *             &lt;receivePackets&gt;181&lt;/receivePackets&gt;
583      *             &lt;transmitPackets&gt;172&lt;/transmitPackets&gt;
584      *             &lt;receiveBytes&gt;12670&lt;/receiveBytes&gt;
585      *             &lt;transmitBytes&gt;12040&lt;/transmitBytes&gt;
586      *             &lt;receiveDrops&gt;0&lt;/receiveDrops&gt;
587      *             &lt;transmitDrops&gt;0&lt;/transmitDrops&gt;
588      *             &lt;receiveErrors&gt;0&lt;/receiveErrors&gt;
589      *             &lt;transmitErrors&gt;0&lt;/transmitErrors&gt;
590      *             &lt;receiveFrameError&gt;0&lt;/receiveFrameError&gt;
591      *             &lt;receiveOverRunError&gt;0&lt;/receiveOverRunError&gt;
592      *             &lt;receiveCrcError&gt;0&lt;/receiveCrcError&gt;
593      *             &lt;collisionCount&gt;0&lt;/collisionCount&gt;
594      *         &lt;/portStatistic&gt;
595      *         &lt;portStatistic&gt;
596      *             &lt;nodeConnector&gt;
597      *                &lt;node&gt;
598      *                   &lt;id&gt;00:00:00:00:00:00:00:02&lt;/id&gt;
599      *                   &lt;type&gt;OF&lt;/type&gt;
600      *                &lt;/node&gt;
601      *                &lt;id&gt;2&lt;/id&gt;
602      *                &lt;type&gt;OF&lt;/type&gt;
603      *             &lt;/nodeConnector&gt;
604      *             &lt;receivePackets&gt;173&lt;/receivePackets&gt;
605      *             &lt;transmitPackets&gt;180&lt;/transmitPackets&gt;
606      *             &lt;receiveBytes&gt;12110&lt;/receiveBytes&gt;
607      *             &lt;transmitBytes&gt;12600&lt;/transmitBytes&gt;
608      *             &lt;receiveDrops&gt;0&lt;/receiveDrops&gt;
609      *             &lt;transmitDrops&gt;0&lt;/transmitDrops&gt;
610      *             &lt;receiveErrors&gt;0&lt;/receiveErrors&gt;
611      *             &lt;transmitErrors&gt;0&lt;/transmitErrors&gt;
612      *             &lt;receiveFrameError&gt;0&lt;/receiveFrameError&gt;
613      *             &lt;receiveOverRunError&gt;0&lt;/receiveOverRunError&gt;
614      *             &lt;receiveCrcError&gt;0&lt;/receiveCrcError&gt;
615      *             &lt;collisionCount&gt;0&lt;/collisionCount&gt;
616      *         &lt;/portStatistic&gt;
617      *     &lt;/portStatistics&gt;
618      * &lt;/list&gt;
619      * </pre>
620      */
621
622     @Path("/{containerName}/port")
623     @GET
624     @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
625     @TypeHint(AllPortStatistics.class)
626     @StatusCodes({
627         @ResponseCode(code = 200, condition = "Operation successful"),
628         @ResponseCode(code = 404, condition = "The containerName is not found"),
629         @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
630     public AllPortStatistics getPortStatistics(
631             @PathParam("containerName") String containerName,
632             @QueryParam("_q") String queryString) {
633
634         if (!NorthboundUtils.isAuthorized(
635                 getUserName(), containerName, Privilege.READ, this)) {
636             throw new UnauthorizedException(
637                     "User is not authorized to perform this operation on container "
638                             + containerName);
639         }
640         IStatisticsManager statisticsManager = getStatisticsService(containerName);
641         if (statisticsManager == null) {
642             throw new ServiceUnavailableException("Statistics "
643                     + RestMessages.SERVICEUNAVAILABLE.toString());
644         }
645
646         ISwitchManager switchManager = (ISwitchManager) ServiceHelper
647                 .getInstance(ISwitchManager.class, containerName, this);
648         if (switchManager == null) {
649             throw new ServiceUnavailableException("Switch manager "
650                     + RestMessages.SERVICEUNAVAILABLE.toString());
651         }
652
653         List<PortStatistics> statistics = new ArrayList<PortStatistics>();
654         for (Node node : switchManager.getNodes()) {
655             List<NodeConnectorStatistics> stat = statisticsManager
656                     .getNodeConnectorStatistics(node);
657             PortStatistics portStat = new PortStatistics(node, stat);
658             statistics.add(portStat);
659         }
660
661         AllPortStatistics result = new AllPortStatistics(statistics);
662         if (queryString != null) {
663             queryContext.createQuery(queryString, AllPortStatistics.class)
664                 .filter(result, PortStatistics.class);
665         }
666         return result;
667     }
668
669     /**
670      * Returns a list of all the Port Statistics across all the NodeConnectors
671      * in a given Node.
672      *
673      * @param containerName
674      *            Name of the Container. The Container name for the base
675      *            controller is "default".
676      * @param nodeType
677      *            Node Type as specifid in {@link org.opendaylight.controller.sal.core.Node} class
678      * @param Node
679      *            Identifier (e.g. MAC address)
680      * @return Returns a list of all the Port Statistics across all the
681      *         NodeConnectors in a given Node.
682      *
683      * <pre>
684      *
685      * Example:
686      *
687      * Request URL:
688      * http://localhost:8080/controller/nb/v2/statistics/default/port/node/OF/00:00:00:00:00:00:00:01
689      *
690      * Response body in JSON:
691      * {
692      *     "node": {
693      *         "id":"00:00:00:00:00:00:00:01",
694      *         "type":"OF"
695      *     },
696      *     "portStatistic": [
697      *         {
698      *             "nodeConnector": {
699      *                 "node":{
700      *                     "id":"00:00:00:00:00:00:00:01",
701      *                     "type":"OF"
702      *                 },
703      *                 "id":"3",
704      *                 "type":"OF"
705      *             },
706      *             "receivePackets": "171",
707      *             "transmitPackets": "2451",
708      *             "receiveBytes": "11970",
709      *             "transmitBytes": "235186",
710      *             "receiveDrops": "0",
711      *             "transmitDrops": "0",
712      *             "receiveErrors": "0",
713      *             "transmitErrors": "0",
714      *             "receiveFrameError": "0",
715      *             "receiveOverRunError": "0",
716      *             "receiveCrcError": "0",
717      *             "collisionCount": "0"
718      *         },
719      *         {
720      *             "nodeConnector": {
721      *                 "node":{
722      *                     "id":"00:00:00:00:00:00:00:01",
723      *                     "type":"OF"
724      *                 },
725      *                 "id":"2",
726      *                 "type":"OF"
727      *             },
728      *             "receivePackets": "179",
729      *             "transmitPackets": "2443",
730      *             "receiveBytes": "12530",
731      *             "transmitBytes": "234626",
732      *             "receiveDrops": "0",
733      *             "transmitDrops": "0",
734      *             "receiveErrors": "0",
735      *             "transmitErrors": "0",
736      *             "receiveFrameError": "0",
737      *             "receiveOverRunError": "0",
738      *             "receiveCrcError": "0",
739      *             "collisionCount": "0"
740      *         }
741      *     ]
742      * }
743      *
744      * Response body in XML:
745      * &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;
746      * &lt;nodePortStatistics&gt;
747      *     &lt;node&gt;
748      *         &lt;id&gt;00:00:00:00:00:00:00:01&lt;/id&gt;
749      *         &lt;type&gt;OF&lt;/type&gt;
750      *     &lt;/node&gt;
751      *     &lt;portStatistic&gt;
752      *         &lt;nodeConnector&gt;
753      *             &lt;node&gt;
754      *                 &lt;id&gt;00:00:00:00:00:00:00:01&lt;/id&gt;
755      *                 &lt;type&gt;OF&lt;/type&gt;
756      *             &lt;/node&gt;
757      *             &lt;id&gt;2&lt;/id&gt;
758      *             &lt;type&gt;OF&lt;/type&gt;
759      *         &lt;/nodeConnector&gt;
760      *         &lt;receivePackets&gt;180&lt;/receivePackets&gt;
761      *         &lt;transmitPackets&gt;2594&lt;/transmitPackets&gt;
762      *         &lt;receiveBytes&gt;12600&lt;/receiveBytes&gt;
763      *         &lt;transmitBytes&gt;249396&lt;/transmitBytes&gt;
764      *         &lt;receiveDrops&gt;0&lt;/receiveDrops&gt;
765      *         &lt;transmitDrops&gt;0&lt;/transmitDrops&gt;
766      *         &lt;receiveErrors&gt;0&lt;/receiveErrors&gt;
767      *         &lt;transmitErrors&gt;0&lt;/transmitErrors&gt;
768      *         &lt;receiveFrameError&gt;0&lt;/receiveFrameError&gt;
769      *         &lt;receiveOverRunError&gt;0&lt;/receiveOverRunError&gt;
770      *         &lt;receiveCrcError&gt;0&lt;/receiveCrcError&gt;
771      *         &lt;collisionCount&gt;0&lt;/collisionCount&gt;
772      *     &lt;/portStatistic&gt;
773      *     &lt;portStatistic&gt;
774      *         &lt;nodeConnector&gt;
775      *             &lt;node&gt;
776      *                 &lt;id&gt;00:00:00:00:00:00:00:01&lt;/id&gt;
777      *                 &lt;type&gt;OF&lt;/type&gt;
778      *             &lt;/node&gt;
779      *             &lt;id&gt;5&lt;/id&gt;
780      *             &lt;type&gt;OF&lt;/type&gt;
781      *         &lt;/nodeConnector&gt;
782      *         &lt;receivePackets&gt;2542&lt;/receivePackets&gt;
783      *         &lt;transmitPackets&gt;2719&lt;/transmitPackets&gt;
784      *         &lt;receiveBytes&gt;243012&lt;/receiveBytes&gt;
785      *         &lt;transmitBytes&gt;255374&lt;/transmitBytes&gt;
786      *         &lt;receiveDrops&gt;0&lt;/receiveDrops&gt;
787      *         &lt;transmitDrops&gt;0&lt;/transmitDrops&gt;
788      *         &lt;receiveErrors&gt;0&lt;/receiveErrors&gt;
789      *         &lt;transmitErrors&gt;0&lt;/transmitErrors&gt;
790      *         &lt;receiveFrameError&gt;0&lt;/receiveFrameError&gt;
791      *         &lt;receiveOverRunError&gt;0&lt;/receiveOverRunError&gt;
792      *         &lt;receiveCrcError&gt;0&lt;/receiveCrcError&gt;
793      *         &lt;collisionCount&gt;0&lt;/collisionCount&gt;
794      *     &lt;/portStatistic&gt;
795      * &lt;/nodePortStatistics&gt;
796      * </pre>
797      */
798     @Path("/{containerName}/port/node/{nodeType}/{nodeId}")
799     @GET
800     @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
801     @TypeHint(PortStatistics.class)
802     @StatusCodes({
803         @ResponseCode(code = 200, condition = "Operation successful"),
804         @ResponseCode(code = 404, condition = "The containerName is not found"),
805         @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
806     public PortStatistics getPortStatistics(
807             @PathParam("containerName") String containerName,
808             @PathParam("nodeType") String nodeType,
809             @PathParam("nodeId") String nodeId) {
810
811         if (!NorthboundUtils.isAuthorized(
812                 getUserName(), containerName, Privilege.READ, this)) {
813             throw new UnauthorizedException(
814                     "User is not authorized to perform this operation on container "
815                             + containerName);
816         }
817         handleDefaultDisabled(containerName);
818
819         IStatisticsManager statisticsManager = getStatisticsService(containerName);
820         if (statisticsManager == null) {
821             throw new ServiceUnavailableException("Statistics "
822                     + RestMessages.SERVICEUNAVAILABLE.toString());
823         }
824
825         ISwitchManager switchManager = (ISwitchManager) ServiceHelper
826                 .getInstance(ISwitchManager.class, containerName, this);
827         if (switchManager == null) {
828             throw new ServiceUnavailableException("Switch manager "
829                     + RestMessages.SERVICEUNAVAILABLE.toString());
830         }
831
832         Node node = handleNodeAvailability(containerName, nodeType, nodeId);
833         return new PortStatistics(node,
834                 statisticsManager.getNodeConnectorStatistics(node));
835     }
836
837     /**
838      * Returns a list of all the Table Statistics on all Nodes.
839      *
840      * @param containerName
841      *            Name of the Container. The Container name for the base
842      *            controller is "default".
843      *
844      * @return Returns a list of all the Table Statistics in a given Node.
845      *
846      * <pre>
847      *
848      * Example:
849      *
850      * Request URL:
851      * http://localhost:8080/controller/nb/v2/statistics/default/table
852      *
853      * Response body in JSON:
854      * {
855      *     "tableStatistics": [
856      *         {
857      *             "node": {
858      *                 "id":"00:00:00:00:00:00:00:02",
859      *                 "type":"OF"
860      *             },
861      *             "tableStatistic": [
862      *                 {
863      *                     "nodeTable": {
864      *                        "node":{
865      *                           "id":"00:00:00:00:00:00:00:02",
866      *                           "type":"OF"
867      *                         },
868      *                         "id":"0"
869      *                     },
870      *                     "activeCount": "11",
871      *                     "lookupCount": "816",
872      *                     "matchedCount": "220",
873      *                     "maximumEntries": "1000"
874      *                 },
875      *                 {
876      *                     ...another table
877      *                     .....
878      *                     ........
879      *                 }
880      *
881      *             ]
882      *         }
883      *     ]
884      * }
885      *
886      *  Response body in XML:
887      *  &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;
888      *  &lt;list&gt;
889      *  &lt;tableStatistics&gt;
890      *      &lt;node&gt;
891      *          &lt;id&gt;00:00:00:00:00:00:00:01&lt;/id&gt;
892      *          &lt;type&gt;OF&lt;/type&gt;
893      *      &lt;/node&gt;
894      *      &lt;tableStatistic&gt;
895      *          &lt;nodeTable&gt;
896      *              &lt;node&gt;
897      *                  &lt;id&gt;00:00:00:00:00:00:00:01&lt;/id&gt;
898      *                  &lt;type&gt;OF&lt;/type&gt;
899      *              &lt;/node&gt;
900      *              &lt;id&gt;0&lt;/id&gt;
901      *          &lt;/nodeTable&gt;
902      *          &lt;activeCount&gt;12&lt;/activeCount&gt;
903      *          &lt;lookupCount&gt;10935&lt;/lookupCount&gt;
904      *          &lt;matchedCount&gt;10084&lt;/matchedCount&gt;
905      *          &lt;maximumEntries&gt;1000&lt;/maximumEntries&gt;
906      *      &lt;/tableStatistic&gt;
907      *      &lt;tableStatistic&gt;
908      *          &lt;nodeTable&gt;
909      *              &lt;node&gt;
910      *                  &lt;id&gt;00:00:00:00:00:00:00:01&lt;/id&gt;
911      *                  &lt;type&gt;OF&lt;/type&gt;
912      *              &lt;/node&gt;
913      *              &lt;id&gt;1&lt;/id&gt;
914      *          &lt;/nodeTable&gt;
915      *          &lt;activeCount&gt;0&lt;/activeCount&gt;
916      *          &lt;lookupCount&gt;0&lt;/lookupCount&gt;
917      *          &lt;matchedCount&gt;0&lt;/matchedCount&gt;
918      *          &lt;maximumEntries&gt;0&lt;/maximumEntries&gt;
919      *      &lt;/tableStatistic&gt;
920      *      &lt;tableStatistic&gt;
921      *          &lt;nodeTable&gt;
922      *              &lt;node&gt;
923      *                  &lt;id&gt;00:00:00:00:00:00:00:01&lt;/id&gt;
924      *                  &lt;type&gt;OF&lt;/type&gt;
925      *              &lt;/node&gt;
926      *              &lt;id&gt;2&lt;/id&gt;
927      *          &lt;/nodeTable&gt;
928      *          &lt;activeCount&gt;0&lt;/activeCount&gt;
929      *          &lt;lookupCount&gt;0&lt;/lookupCount&gt;
930      *          &lt;matchedCount&gt;0&lt;/matchedCount&gt;
931      *          &lt;maximumEntries&gt;0&lt;/maximumEntries&gt;
932      *      &lt;/tableStatistic&gt;
933      *  &lt;/tableStatistics&gt;
934      *  &lt;tableStatistics&gt;
935      *  ...
936      *  ......
937      *  ........
938      *  &lt;/tableStatistics&gt;
939      *  &lt;/list&gt;
940      *
941      * </pre>
942      */
943     @Path("/{containerName}/table")
944     @GET
945     @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
946     @TypeHint(AllTableStatistics.class)
947     @StatusCodes({
948         @ResponseCode(code = 200, condition = "Operation successful"),
949         @ResponseCode(code = 404, condition = "The containerName is not found"),
950         @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
951     public AllTableStatistics getTableStatistics(
952             @PathParam("containerName") String containerName,
953             @QueryParam("_q") String queryString) {
954
955         if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.READ, this)) {
956             throw new UnauthorizedException("User is not authorized to perform this operation on container "
957                     + containerName);
958         }
959         handleDefaultDisabled(containerName);
960
961         IStatisticsManager statisticsManager = getStatisticsService(containerName);
962         if (statisticsManager == null) {
963             throw new ServiceUnavailableException("Statistics manager"
964                     + RestMessages.SERVICEUNAVAILABLE.toString());
965         }
966
967         ISwitchManager switchManager = (ISwitchManager) ServiceHelper
968                 .getInstance(ISwitchManager.class, containerName, this);
969         if (switchManager == null) {
970             throw new ServiceUnavailableException("Switch manager "
971                     + RestMessages.SERVICEUNAVAILABLE.toString());
972         }
973
974         List<TableStatistics> statistics = new ArrayList<TableStatistics>();
975         for (Node node : switchManager.getNodes()) {
976             List<NodeTableStatistics> stat = statisticsManager
977                     .getNodeTableStatistics(node);
978             TableStatistics tableStat = new TableStatistics(node, stat);
979             statistics.add(tableStat);
980         }
981         AllTableStatistics allstats = new AllTableStatistics(statistics);
982         if (queryString != null) {
983             queryContext.createQuery(queryString, AllTableStatistics.class)
984                 .filter(allstats, TableStatistics.class);
985         }
986         return allstats;
987     }
988
989     /**
990      * Returns a list of all the Table Statistics on a specific node.
991      *
992      * @param containerName
993      *            Name of the Container. The Container name for the base
994      *            controller is "default".
995      * @param nodeType
996      *            Node Type as specified in {@link org.opendaylight.controller.sal.core.Node} class (e.g. OF for Openflow)
997      * @param Node
998      *            Identifier (e.g. MAC address)
999      * @return Returns a list of all the Table Statistics in a given Node.
1000      *
1001      * <pre>
1002      *
1003      * Example:
1004      *
1005      * Request URL:
1006      * http://localhost:8080/controller/nb/v2/statistics/default/table/node/OF/00:00:00:00:00:00:00:01
1007      *
1008      * Response body in JSON:
1009      * {
1010      *     "node": {
1011      *         "id":"00:00:00:00:00:00:00:01",
1012      *         "type":"OF"
1013      *     },
1014      *     "tableStatistic": [
1015      *         {
1016      *             "nodeTable": {
1017      *                 "node":{
1018      *                     "id":"00:00:00:00:00:00:00:01",
1019      *                     "type":"OF"
1020      *                 },
1021      *                 "id":"0"
1022      *             },
1023      *             "activeCount": "12",
1024      *             "lookupCount": "11382",
1025      *             "matchedCount": "10524",
1026      *             "maximumEntries": "1000"
1027      *         },
1028      *         {
1029      *             "nodeTable": {
1030      *                 "node":{
1031      *                     "id":"00:00:00:00:00:00:00:01",
1032      *                     "type":"OF"
1033      *                 },
1034      *                 "id":"1"
1035      *             },
1036      *             "activeCount": "0",
1037      *             "lookupCount": "0",
1038      *             "matchedCount": "0",
1039      *             "maximumEntries": "0"
1040      *         }
1041      *    ]
1042      * }
1043      *
1044      * Response body in XML:
1045      * &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;
1046      * &lt;nodeTableStatistics&gt;
1047      *     &lt;node&gt;
1048      *          &lt;id&gt;00:00:00:00:00:00:00:01&lt;/id&gt;
1049      *          &lt;type&gt;OF&lt;/type&gt;
1050      *     &lt;/node&gt;
1051      *     &lt;tableStatistic&gt;
1052      *         &lt;nodeTable&gt;
1053      *             &lt;node&gt;
1054      *                 &lt;id&gt;00:00:00:00:00:00:00:01&lt;/id&gt;
1055      *                 &lt;type&gt;OF&lt;/type&gt;
1056      *             &lt;/node&gt;
1057      *             &lt;id&gt;0&lt;/id&gt;
1058      *         &lt;/nodeTable&gt;
1059      *         &lt;activeCount&gt;12&lt;/activeCount&gt;
1060      *         &lt;lookupCount&gt;10935&lt;/lookupCount&gt;
1061      *         &lt;matchedCount&gt;10084&lt;/matchedCount&gt;
1062      *         &lt;maximumEntries&gt;1000&lt;/maximumEntries&gt;
1063      *     &lt;/tableStatistic&gt;
1064      *     &lt;tableStatistic&gt;
1065      *         &lt;nodeTable&gt;
1066      *             &lt;node&gt;
1067      *                 &lt;id&gt;00:00:00:00:00:00:00:01&lt;/id&gt;
1068      *                 &lt;type&gt;OF&lt;/type&gt;
1069      *             &lt;/node&gt;
1070      *             &lt;id&gt;1&lt;/id&gt;
1071      *         &lt;/nodeTable&gt;
1072      *         &lt;activeCount&gt;0&lt;/activeCount&gt;
1073      *         &lt;lookupCount&gt;0&lt;/lookupCount&gt;
1074      *         &lt;matchedCount&gt;0&lt;/matchedCount&gt;
1075      *         &lt;maximumEntries&gt;0&lt;/maximumEntries&gt;
1076      *     &lt;/tableStatistic&gt;
1077      *     &lt;tableStatistic&gt;
1078      *         &lt;nodeTable&gt;
1079      *             &lt;node&gt;
1080      *                 &lt;id&gt;00:00:00:00:00:00:00:01&lt;/id&gt;
1081      *                 &lt;type&gt;OF&lt;/type&gt;
1082      *             &lt;/node&gt;
1083      *             &lt;id&gt;2&lt;/id&gt;
1084      *         &lt;/nodeTable&gt;
1085      *         &lt;activeCount&gt;0&lt;/activeCount&gt;
1086      *         &lt;lookupCount&gt;0&lt;/lookupCount&gt;
1087      *         &lt;matchedCount&gt;0&lt;/matchedCount&gt;
1088      *         &lt;maximumEntries&gt;0&lt;/maximumEntries&gt;
1089      *     &lt;/tableStatistic&gt;
1090      * &lt;/nodeTableStatistics&gt;
1091      *
1092      * </pre>
1093      */
1094     @Path("/{containerName}/table/node/{nodeType}/{nodeId}")
1095     @GET
1096     @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
1097     @TypeHint(TableStatistics.class)
1098     @StatusCodes({
1099         @ResponseCode(code = 200, condition = "Operation successful"),
1100         @ResponseCode(code = 404, condition = "The containerName is not found"),
1101         @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
1102     public TableStatistics getTableStatistics(
1103             @PathParam("containerName") String containerName,
1104             @PathParam("nodeType") String nodeType,
1105             @PathParam("nodeId") String nodeId) {
1106
1107         if (!NorthboundUtils.isAuthorized(
1108                 getUserName(), containerName, Privilege.READ, this)) {
1109             throw new UnauthorizedException(
1110                     "User is not authorized to perform this operation on container "
1111                             + containerName);
1112         }
1113         handleDefaultDisabled(containerName);
1114
1115         IStatisticsManager statisticsManager = getStatisticsService(containerName);
1116         if (statisticsManager == null) {
1117             throw new ServiceUnavailableException("Statistics "
1118                     + RestMessages.SERVICEUNAVAILABLE.toString());
1119         }
1120
1121         ISwitchManager switchManager = (ISwitchManager) ServiceHelper
1122                 .getInstance(ISwitchManager.class, containerName, this);
1123         if (switchManager == null) {
1124             throw new ServiceUnavailableException("Switch manager "
1125                     + RestMessages.SERVICEUNAVAILABLE.toString());
1126         }
1127
1128         Node node = handleNodeAvailability(containerName, nodeType, nodeId);
1129         return new TableStatistics(node,
1130                 statisticsManager.getNodeTableStatistics(node));
1131     }
1132
1133     private void handleDefaultDisabled(String containerName) {
1134         IContainerManager containerManager = (IContainerManager) ServiceHelper
1135                 .getGlobalInstance(IContainerManager.class, this);
1136         if (containerManager == null) {
1137             throw new InternalServerErrorException(
1138                     RestMessages.INTERNALERROR.toString());
1139         }
1140         if (containerName.equals(GlobalConstants.DEFAULT.toString())
1141                 && containerManager.hasNonDefaultContainer()) {
1142             throw new ResourceConflictException(
1143                     RestMessages.DEFAULTDISABLED.toString());
1144         }
1145     }
1146
1147     private Node handleNodeAvailability(String containerName, String nodeType,
1148             String nodeId) {
1149
1150         Node node = Node.fromString(nodeType, nodeId);
1151         if (node == null) {
1152             throw new ResourceNotFoundException(nodeId + " : "
1153                     + RestMessages.NONODE.toString());
1154         }
1155
1156         ISwitchManager sm = (ISwitchManager) ServiceHelper.getInstance(
1157                 ISwitchManager.class, containerName, this);
1158
1159         if (sm == null) {
1160             throw new ServiceUnavailableException("Switch Manager "
1161                     + RestMessages.SERVICEUNAVAILABLE.toString());
1162         }
1163
1164         if (!sm.getNodes().contains(node)) {
1165             throw new ResourceNotFoundException(node.toString() + " : "
1166                     + RestMessages.NONODE.toString());
1167         }
1168         return node;
1169     }
1170
1171 }