2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.statistics.northbound;
11 import java.util.ArrayList;
12 import java.util.List;
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;
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;
44 * Northbound APIs that returns various Statistics exposed by the Southbound
45 * protocol plugins such as Openflow.
49 * Authentication scheme : <b>HTTP Basic</b><br>
50 * Authentication realm : <b>opendaylight</b><br>
51 * Transport : <b>HTTP and HTTPS</b><br>
53 * HTTPS Authentication is disabled by default.
57 public class StatisticsNorthbound {
59 private String username;
62 public void setSecurityContext(SecurityContext context) {
63 if (context != null && context.getUserPrincipal() != null) username = context.getUserPrincipal().getName();
66 protected String getUserName() {
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());
78 boolean found = false;
79 List<String> containerNames = containerManager.getContainerNames();
80 for (String cName : containerNames) {
81 if (cName.trim().equalsIgnoreCase(containerName.trim())) {
87 throw new ResourceNotFoundException(containerName + " "
88 + RestMessages.NOCONTAINER.toString());
91 IStatisticsManager statsManager = (IStatisticsManager) ServiceHelper
92 .getInstance(IStatisticsManager.class, containerName, this);
94 if (statsManager == null) {
95 throw new ServiceUnavailableException("Statistics "
96 + RestMessages.SERVICEUNAVAILABLE.toString());
103 * Returns a list of all Flow Statistics from all the Nodes.
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
115 * http://localhost:8080/controller/nb/v2/statistics/default/flow
119 * "flowStatistics": [
122 * "id":"00:00:00:00:00:00:00:02",
135 * "mask": "255.255.255.255",
145 * "id":"00:00:00:00:00:00:00:02",
153 * "idleTimeout": "0",
154 * "hardTimeout": "0",
158 * "durationSeconds": "1828",
159 * "durationNanoseconds": "397000000",
160 * "packetCount": "0",
165 * { flow statistics of another node
168 * ......................
175 * <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
177 * <flowStatistics>
179 * <id>00:00:00:00:00:00:00:02</id>
180 * <type>OF</type>
182 * <flowStatistic>
186 * <type>DL_TYPE</type>
187 * <value>2048</value>
188 * </matchField>
190 * <mask>255.255.255.255</mask>
191 * <type>NW_DST</type>
192 * <value>1.1.1.2</value>
193 * </matchField>
196 * xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="output">
199 * <id>00:00:00:00:00:00:00:02</id>
200 * <type>OF</type>
202 * <id>3</id>
203 * <type>OF</type>
206 * <priority>1</priority>
207 * <idleTimeout>0</idleTimeout>
208 * <hardTimeout>0</hardTimeout>
209 * <id>0</id>
211 * <tableId>0</tableId>
212 * <durationSeconds>337</durationSeconds>
213 * <durationNanoseconds>149000000</durationNanoseconds>
214 * <packetCount>0</packetCount>
215 * <byteCount>0</byteCount>
216 * </flowStatistic>
217 * </flowStatistics>
218 * <flowStatistics>
219 * flow statistics for another node
222 * .....................
223 * </flowStatistics>
228 @Path("/{containerName}/flow")
230 @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
231 @TypeHint(AllFlowStatistics.class)
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 "
244 IStatisticsManager statisticsManager = getStatisticsService(containerName);
245 if (statisticsManager == null) {
246 throw new ServiceUnavailableException("Statistics "
247 + RestMessages.SERVICEUNAVAILABLE.toString());
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());
257 List<FlowStatistics> statistics = new ArrayList<FlowStatistics>();
258 for (Node node : switchManager.getNodes()) {
259 List<FlowOnNode> flowStats = new ArrayList<FlowOnNode>();
261 List<FlowOnNode> flows = statisticsManager.getFlows(node);
262 for (FlowOnNode flowOnSwitch : flows) {
263 flowStats.add(flowOnSwitch);
265 FlowStatistics stat = new FlowStatistics(node, flowStats);
266 statistics.add(stat);
268 return new AllFlowStatistics(statistics);
272 * Returns a list of Flow Statistics for a given Node.
274 * @param containerName
275 * Name of the Container. The Container name for the base
276 * controller is "default".
278 * Node Type as specifid in {@link org.opendaylight.controller.sal.core.Node} class
281 * @return List of Flow Statistics for a given Node. *
288 * http://localhost:8080/controller/nb/v2/statistics/default/flow/node/OF/00:00:00:00:00:00:00:01
293 * "id":"00:00:00:00:00:00:00:01",
306 * "mask": "255.255.255.255",
314 * "@type": "setDlDst",
315 * "address": "52d28b0f76ec"
321 * "id":"00:00:00:00:00:00:00:01",
330 * "idleTimeout": "0",
331 * "hardTimeout": "0",
335 * "durationSeconds": "2089",
336 * "durationNanoseconds": "538000000",
337 * "packetCount": "0",
344 * <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
345 * <nodeFlowStatistics>
347 * <id>00:00:00:00:00:00:00:02</id>
348 * <type>OF</type>
350 * <flowStatistic>
354 * <type>DL_TYPE</type>
355 * <value>2048</value>
356 * </matchField>
358 * <mask>255.255.255.255</mask>
359 * <type>NW_DST</type>
360 * <value>1.1.1.2</value>
361 * </matchField>
364 * xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="output">
367 * <id>00:00:00:00:00:00:00:02</id>
368 * <type>OF</type>
370 * <id>3</id>
371 * <type>OF</type>
374 * <priority>1</priority>
375 * <idleTimeout>0</idleTimeout>
376 * <hardTimeout>0</hardTimeout>
377 * <id>0</id>
379 * <tableId>0</tableId>
380 * <durationSeconds>337</durationSeconds>
381 * <durationNanoseconds>149000000</durationNanoseconds>
382 * <packetCount>0</packetCount>
383 * <byteCount>0</byteCount>
384 * </flowStatistic>
385 * <flowStatistic>
389 * <type>DL_TYPE</type>
390 * <value>2048</value>
391 * </matchField>
393 * <mask>255.255.255.255</mask>
394 * <type>NW_DST</type>
395 * <value>1.1.1.1</value>
396 * </matchField>
399 * xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="output">
402 * <id>00:00:00:00:00:00:00:02</id>
403 * <type>OF</type>
405 * <id>3</id>
406 * <type>OF</type>
409 * <priority>1</priority>
410 * <idleTimeout>0</idleTimeout>
411 * <hardTimeout>0</hardTimeout>
412 * <id>0</id>
414 * <tableId>0</tableId>
415 * <durationSeconds>337</durationSeconds>
416 * <durationNanoseconds>208000000</durationNanoseconds>
417 * <packetCount>0</packetCount>
418 * <byteCount>0</byteCount>
419 * </flowStatistic>
420 * </nodeFlowStatistics>
423 @Path("/{containerName}/flow/node/{nodeType}/{nodeId}")
425 @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
426 @TypeHint(FlowStatistics.class)
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 "
441 handleDefaultDisabled(containerName);
443 IStatisticsManager statisticsManager = getStatisticsService(containerName);
444 if (statisticsManager == null) {
445 throw new ServiceUnavailableException("Statistics "
446 + RestMessages.SERVICEUNAVAILABLE.toString());
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());
456 Node node = handleNodeAvailability(containerName, nodeType, nodeId);
457 return new FlowStatistics(node, statisticsManager.getFlows(node));
461 * Returns a list of all the Port Statistics across all the NodeConnectors
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
475 * http://localhost:8080/controller/nb/v2/statistics/default/port
479 * "portStatistics": [
482 * "id":"00:00:00:00:00:00:00:02",
489 * "id":"00:00:00:00:00:00:00:02",
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"
511 * "id":"00:00:00:00:00:00:00:02",
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"
535 * "id":"00:00:00:00:00:00:00:03",
540 * .......................
541 * ..........................
548 * <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
550 * <portStatistics>
552 * <id>00:00:00:00:00:00:00:02</id>
553 * <type>OF</type>
555 * <portStatistic>
556 * <nodeConnector>
558 * <id>00:00:00:00:00:00:00:02</id>
559 * <type>OF</type>
561 * <id>3</id>
562 * <type>OF</type>
563 * </nodeConnector>
564 * <receivePackets>181</receivePackets>
565 * <transmitPackets>172</transmitPackets>
566 * <receiveBytes>12670</receiveBytes>
567 * <transmitBytes>12040</transmitBytes>
568 * <receiveDrops>0</receiveDrops>
569 * <transmitDrops>0</transmitDrops>
570 * <receiveErrors>0</receiveErrors>
571 * <transmitErrors>0</transmitErrors>
572 * <receiveFrameError>0</receiveFrameError>
573 * <receiveOverRunError>0</receiveOverRunError>
574 * <receiveCrcError>0</receiveCrcError>
575 * <collisionCount>0</collisionCount>
576 * </portStatistic>
577 * <portStatistic>
578 * <nodeConnector>
580 * <id>00:00:00:00:00:00:00:02</id>
581 * <type>OF</type>
583 * <id>2</id>
584 * <type>OF</type>
585 * </nodeConnector>
586 * <receivePackets>173</receivePackets>
587 * <transmitPackets>180</transmitPackets>
588 * <receiveBytes>12110</receiveBytes>
589 * <transmitBytes>12600</transmitBytes>
590 * <receiveDrops>0</receiveDrops>
591 * <transmitDrops>0</transmitDrops>
592 * <receiveErrors>0</receiveErrors>
593 * <transmitErrors>0</transmitErrors>
594 * <receiveFrameError>0</receiveFrameError>
595 * <receiveOverRunError>0</receiveOverRunError>
596 * <receiveCrcError>0</receiveCrcError>
597 * <collisionCount>0</collisionCount>
598 * </portStatistic>
599 * </portStatistics>
604 @Path("/{containerName}/port")
606 @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
607 @TypeHint(AllPortStatistics.class)
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) {
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 "
621 IStatisticsManager statisticsManager = getStatisticsService(containerName);
622 if (statisticsManager == null) {
623 throw new ServiceUnavailableException("Statistics "
624 + RestMessages.SERVICEUNAVAILABLE.toString());
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());
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);
641 return new AllPortStatistics(statistics);
645 * Returns a list of all the Port Statistics across all the NodeConnectors
648 * @param containerName
649 * Name of the Container. The Container name for the base
650 * controller is "default".
652 * Node Type as specifid in {@link org.opendaylight.controller.sal.core.Node} class
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.
663 * http://localhost:8080/controller/nb/v2/statistics/default/port/node/OF/00:00:00:00:00:00:00:01
668 * "id":"00:00:00:00:00:00:00:01",
675 * "id":"00:00:00:00:00:00:00:01",
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"
697 * "id":"00:00:00:00:00:00:00:01",
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"
720 * <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
721 * <nodePortStatistics>
723 * <id>00:00:00:00:00:00:00:01</id>
724 * <type>OF</type>
726 * <portStatistic>
727 * <nodeConnector>
729 * <id>00:00:00:00:00:00:00:01</id>
730 * <type>OF</type>
732 * <id>2</id>
733 * <type>OF</type>
734 * </nodeConnector>
735 * <receivePackets>180</receivePackets>
736 * <transmitPackets>2594</transmitPackets>
737 * <receiveBytes>12600</receiveBytes>
738 * <transmitBytes>249396</transmitBytes>
739 * <receiveDrops>0</receiveDrops>
740 * <transmitDrops>0</transmitDrops>
741 * <receiveErrors>0</receiveErrors>
742 * <transmitErrors>0</transmitErrors>
743 * <receiveFrameError>0</receiveFrameError>
744 * <receiveOverRunError>0</receiveOverRunError>
745 * <receiveCrcError>0</receiveCrcError>
746 * <collisionCount>0</collisionCount>
747 * </portStatistic>
748 * <portStatistic>
749 * <nodeConnector>
751 * <id>00:00:00:00:00:00:00:01</id>
752 * <type>OF</type>
754 * <id>5</id>
755 * <type>OF</type>
756 * </nodeConnector>
757 * <receivePackets>2542</receivePackets>
758 * <transmitPackets>2719</transmitPackets>
759 * <receiveBytes>243012</receiveBytes>
760 * <transmitBytes>255374</transmitBytes>
761 * <receiveDrops>0</receiveDrops>
762 * <transmitDrops>0</transmitDrops>
763 * <receiveErrors>0</receiveErrors>
764 * <transmitErrors>0</transmitErrors>
765 * <receiveFrameError>0</receiveFrameError>
766 * <receiveOverRunError>0</receiveOverRunError>
767 * <receiveCrcError>0</receiveCrcError>
768 * <collisionCount>0</collisionCount>
769 * </portStatistic>
770 * </nodePortStatistics>
773 @Path("/{containerName}/port/node/{nodeType}/{nodeId}")
775 @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
776 @TypeHint(PortStatistics.class)
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) {
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 "
792 handleDefaultDisabled(containerName);
794 IStatisticsManager statisticsManager = getStatisticsService(containerName);
795 if (statisticsManager == null) {
796 throw new ServiceUnavailableException("Statistics "
797 + RestMessages.SERVICEUNAVAILABLE.toString());
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());
807 Node node = handleNodeAvailability(containerName, nodeType, nodeId);
808 return new PortStatistics(node,
809 statisticsManager.getNodeConnectorStatistics(node));
813 * Returns a list of all the Table Statistics on all Nodes.
815 * @param containerName
816 * Name of the Container. The Container name for the base
817 * controller is "default".
819 * @return Returns a list of all the Table Statistics in a given Node.
826 * http://localhost:8080/controller/nb/v2/statistics/default/table
830 * "tableStatistics": [
833 * "id":"00:00:00:00:00:00:00:02",
836 * "tableStatistic": [
840 * "id":"00:00:00:00:00:00:00:02",
845 * "activeCount": "11",
846 * "lookupCount": "816",
847 * "matchedCount": "220"
861 * <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
863 * <tableStatistics>
865 * <id>00:00:00:00:00:00:00:01</id>
866 * <type>OF</type>
868 * <tableStatistic>
871 * <id>00:00:00:00:00:00:00:01</id>
872 * <type>OF</type>
874 * <id>0</id>
876 * <activeCount>12</activeCount>
877 * <lookupCount>10935</lookupCount>
878 * <matchedCount>10084</matchedCount>
879 * </tableStatistic>
880 * <tableStatistic>
883 * <id>00:00:00:00:00:00:00:01</id>
884 * <type>OF</type>
886 * <id>1</id>
888 * <activeCount>0</activeCount>
889 * <lookupCount>0</lookupCount>
890 * <matchedCount>0</matchedCount>
891 * </tableStatistic>
892 * <tableStatistic>
895 * <id>00:00:00:00:00:00:00:01</id>
896 * <type>OF</type>
898 * <id>2</id>
900 * <activeCount>0</activeCount>
901 * <lookupCount>0</lookupCount>
902 * <matchedCount>0</matchedCount>
903 * </tableStatistic>
904 * </tableStatistics>
905 * <tableStatistics>
909 * </tableStatistics>
914 @Path("/{containerName}/table")
916 @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
917 @TypeHint(AllTableStatistics.class)
919 @ResponseCode(code = 200, condition = "Operation successful"),
920 @ResponseCode(code = 404, condition = "The containerName is not found"),
921 @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
922 public AllTableStatistics getTableStatistics(
923 @PathParam("containerName") String containerName) {
925 if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.READ, this)) {
926 throw new UnauthorizedException("User is not authorized to perform this operation on container "
929 handleDefaultDisabled(containerName);
931 IStatisticsManager statisticsManager = getStatisticsService(containerName);
932 if (statisticsManager == null) {
933 throw new ServiceUnavailableException("Statistics manager"
934 + RestMessages.SERVICEUNAVAILABLE.toString());
937 ISwitchManager switchManager = (ISwitchManager) ServiceHelper
938 .getInstance(ISwitchManager.class, containerName, this);
939 if (switchManager == null) {
940 throw new ServiceUnavailableException("Switch manager "
941 + RestMessages.SERVICEUNAVAILABLE.toString());
944 List<TableStatistics> statistics = new ArrayList<TableStatistics>();
945 for (Node node : switchManager.getNodes()) {
946 List<NodeTableStatistics> stat = statisticsManager
947 .getNodeTableStatistics(node);
948 TableStatistics tableStat = new TableStatistics(node, stat);
949 statistics.add(tableStat);
951 return new AllTableStatistics(statistics);
955 * Returns a list of all the Table Statistics on a specific node.
957 * @param containerName
958 * Name of the Container. The Container name for the base
959 * controller is "default".
961 * Node Type as specified in {@link org.opendaylight.controller.sal.core.Node} class (e.g. OF for Openflow)
963 * Identifier (e.g. MAC address)
964 * @return Returns a list of all the Table Statistics in a given Node.
971 * http://localhost:8080/controller/nb/v2/statistics/default/table/node/OF/00:00:00:00:00:00:00:01
976 * "id":"00:00:00:00:00:00:00:01",
979 * "tableStatistic": [
983 * "id":"00:00:00:00:00:00:00:01",
988 * "activeCount": "12",
989 * "lookupCount": "11382",
990 * "matchedCount": "10524"
995 * "id":"00:00:00:00:00:00:00:01",
1000 * "activeCount": "0",
1001 * "lookupCount": "0",
1002 * "matchedCount": "0"
1008 * <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
1009 * <nodeTableStatistics>
1011 * <id>00:00:00:00:00:00:00:01</id>
1012 * <type>OF</type>
1014 * <tableStatistic>
1017 * <id>00:00:00:00:00:00:00:01</id>
1018 * <type>OF</type>
1020 * <id>0</id>
1021 * </nodeTable>
1022 * <activeCount>12</activeCount>
1023 * <lookupCount>10935</lookupCount>
1024 * <matchedCount>10084</matchedCount>
1025 * </tableStatistic>
1026 * <tableStatistic>
1029 * <id>00:00:00:00:00:00:00:01</id>
1030 * <type>OF</type>
1032 * <id>1</id>
1033 * </nodeTable>
1034 * <activeCount>0</activeCount>
1035 * <lookupCount>0</lookupCount>
1036 * <matchedCount>0</matchedCount>
1037 * </tableStatistic>
1038 * <tableStatistic>
1041 * <id>00:00:00:00:00:00:00:01</id>
1042 * <type>OF</type>
1044 * <id>2</id>
1045 * </nodeTable>
1046 * <activeCount>0</activeCount>
1047 * <lookupCount>0</lookupCount>
1048 * <matchedCount>0</matchedCount>
1049 * </tableStatistic>
1050 * </nodeTableStatistics>
1054 @Path("/{containerName}/table/node/{nodeType}/{nodeId}")
1056 @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
1057 @TypeHint(TableStatistics.class)
1059 @ResponseCode(code = 200, condition = "Operation successful"),
1060 @ResponseCode(code = 404, condition = "The containerName is not found"),
1061 @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
1062 public TableStatistics getTableStatistics(
1063 @PathParam("containerName") String containerName,
1064 @PathParam("nodeType") String nodeType,
1065 @PathParam("nodeId") String nodeId) {
1067 if (!NorthboundUtils.isAuthorized(
1068 getUserName(), containerName, Privilege.READ, this)) {
1069 throw new UnauthorizedException(
1070 "User is not authorized to perform this operation on container "
1073 handleDefaultDisabled(containerName);
1075 IStatisticsManager statisticsManager = getStatisticsService(containerName);
1076 if (statisticsManager == null) {
1077 throw new ServiceUnavailableException("Statistics "
1078 + RestMessages.SERVICEUNAVAILABLE.toString());
1081 ISwitchManager switchManager = (ISwitchManager) ServiceHelper
1082 .getInstance(ISwitchManager.class, containerName, this);
1083 if (switchManager == null) {
1084 throw new ServiceUnavailableException("Switch manager "
1085 + RestMessages.SERVICEUNAVAILABLE.toString());
1088 Node node = handleNodeAvailability(containerName, nodeType, nodeId);
1089 return new TableStatistics(node,
1090 statisticsManager.getNodeTableStatistics(node));
1093 private void handleDefaultDisabled(String containerName) {
1094 IContainerManager containerManager = (IContainerManager) ServiceHelper
1095 .getGlobalInstance(IContainerManager.class, this);
1096 if (containerManager == null) {
1097 throw new InternalServerErrorException(
1098 RestMessages.INTERNALERROR.toString());
1100 if (containerName.equals(GlobalConstants.DEFAULT.toString())
1101 && containerManager.hasNonDefaultContainer()) {
1102 throw new ResourceConflictException(
1103 RestMessages.DEFAULTDISABLED.toString());
1107 private Node handleNodeAvailability(String containerName, String nodeType,
1110 Node node = Node.fromString(nodeType, nodeId);
1112 throw new ResourceNotFoundException(nodeId + " : "
1113 + RestMessages.NONODE.toString());
1116 ISwitchManager sm = (ISwitchManager) ServiceHelper.getInstance(
1117 ISwitchManager.class, containerName, this);
1120 throw new ServiceUnavailableException("Switch Manager "
1121 + RestMessages.SERVICEUNAVAILABLE.toString());
1124 if (!sm.getNodes().contains(node)) {
1125 throw new ResourceNotFoundException(node.toString() + " : "
1126 + RestMessages.NONODE.toString());