3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 package org.opendaylight.controller.statisticsmanager;
12 import java.util.ArrayList;
13 import java.util.HashMap;
14 import java.util.List;
17 import org.opendaylight.controller.forwardingrulesmanager.FlowEntry;
18 import org.opendaylight.controller.sal.core.Node;
19 import org.opendaylight.controller.sal.core.NodeConnector;
20 import org.opendaylight.controller.sal.flowprogrammer.Flow;
21 import org.opendaylight.controller.sal.reader.FlowOnNode;
22 import org.opendaylight.controller.sal.reader.IReadService;
23 import org.opendaylight.controller.sal.reader.NodeConnectorStatistics;
24 import org.opendaylight.controller.sal.reader.NodeDescription;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
29 * The class which implements the methods for retrieving
30 * the network nodes statistics.
32 public class StatisticsManager implements IStatisticsManager {
33 private static final Logger log = LoggerFactory
34 .getLogger(StatisticsManager.class);
35 private IReadService reader;
37 public StatisticsManager() {
42 * Function called by the dependency manager when all the required
43 * dependencies are satisfied
47 log.debug("INIT called!");
51 * Function called by the dependency manager when at least one
52 * dependency become unsatisfied or when the component is shutting
53 * down because for example bundle is being stopped.
57 log.debug("DESTROY called!");
61 * Function called by dependency manager after "init ()" is called
62 * and after the services provided by the class are registered in
63 * the service registry
67 log.debug("START called!");
71 * Function called by the dependency manager before the services
72 * exported by the component are unregistered, this will be
73 * followed by a "destroy ()" calls
77 log.debug("STOP called!");
80 public void setReaderService(IReadService service) {
81 log.debug("Got inventory service set request {}", service);
82 this.reader = service;
85 public void unsetReaderService(IReadService service) {
86 log.debug("Got a service UNset request");
91 public List<FlowOnNode> getFlows(Node node) {
92 return reader.readAllFlows(node);
96 public Map<Node, List<FlowOnNode>> getFlowStatisticsForFlowList(
97 List<FlowEntry> flowList) {
98 Map<Node, List<FlowOnNode>> map = new HashMap<Node, List<FlowOnNode>>();
99 if (flowList != null) {
100 for (FlowEntry entry : flowList) {
101 Node node = entry.getNode();
102 Flow flow = entry.getFlow();
103 List<FlowOnNode> list = (map.containsKey(node)) ? map.get(node)
104 : new ArrayList<FlowOnNode>();
105 list.add(reader.readFlow(node, flow));
113 public int getFlowsNumber(Node node) {
114 return reader.readAllFlows(node).size();
118 public NodeDescription getNodeDescription(Node node) {
119 return reader.readDescription(node);
123 public NodeConnectorStatistics getNodeConnectorStatistics(
124 NodeConnector nodeConnector) {
125 return reader.readNodeConnector(nodeConnector);
129 public List<NodeConnectorStatistics> getNodeConnectorStatistics(Node node) {
130 return reader.readNodeConnectors(node);