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