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