blob: 3d874dffbc72f8763c3df4b4c352b5d1015a8ae1 [file] [log] [blame]
Thomas Vachuska7d693f52014-10-21 19:17:57 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska7d693f52014-10-21 19:17:57 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
Thomas Vachuska7d693f52014-10-21 19:17:57 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
Thomas Vachuska7d693f52014-10-21 19:17:57 -070015 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.cli;
tom9b4030d2014-10-06 10:39:03 -070017
Ray Milkey356f28a2014-12-08 11:59:49 -080018import java.util.Set;
19
tom32085cf2014-10-16 00:04:33 -070020import com.fasterxml.jackson.databind.ObjectMapper;
tom9b4030d2014-10-06 10:39:03 -070021import org.apache.karaf.shell.commands.Command;
Ray Milkey356f28a2014-12-08 11:59:49 -080022import org.onosproject.cluster.ControllerNode;
Brian O'Connorabafb502014-12-02 22:26:20 -080023import org.onosproject.core.CoreService;
24import org.onosproject.cluster.ClusterService;
25import org.onosproject.net.device.DeviceService;
26import org.onosproject.net.flow.FlowRuleService;
27import org.onosproject.net.host.HostService;
28import org.onosproject.net.intent.IntentService;
29import org.onosproject.net.link.LinkService;
30import org.onosproject.net.topology.Topology;
31import org.onosproject.net.topology.TopologyService;
tom9b4030d2014-10-06 10:39:03 -070032
33/**
34 * Provides summary of ONOS model.
35 */
36@Command(scope = "onos", name = "summary",
37 description = "Provides summary of ONOS model")
38public class SummaryCommand extends AbstractShellCommand {
39
Ray Milkey356f28a2014-12-08 11:59:49 -080040 /**
41 * Count the active ONOS controller nodes.
42 *
43 * @param nodes set of all of the controller nodes in the cluster
44 * @return count of active nodes
45 */
46 private int activeNodes(Set<ControllerNode> nodes) {
47 int nodeCount = 0;
48
49 for (final ControllerNode node : nodes) {
50 final ControllerNode.State nodeState =
51 get(ClusterService.class).getState(node.id());
52 if (nodeState == ControllerNode.State.ACTIVE) {
53 nodeCount++;
54 }
55 }
56 return nodeCount;
57 }
58
tom9b4030d2014-10-06 10:39:03 -070059 @Override
60 protected void execute() {
61 TopologyService topologyService = get(TopologyService.class);
tom800709a2014-10-06 20:52:14 -070062 Topology topology = topologyService.currentTopology();
tom32085cf2014-10-16 00:04:33 -070063 if (outputJson()) {
64 print("%s", new ObjectMapper().createObjectNode()
65 .put("node", get(ClusterService.class).getLocalNode().ip().toString())
66 .put("version", get(CoreService.class).version().toString())
67 .put("nodes", get(ClusterService.class).getNodes().size())
Thomas Vachuska47635c62014-11-22 01:21:36 -080068 .put("devices", topology.deviceCount())
69 .put("links", topology.linkCount())
tom32085cf2014-10-16 00:04:33 -070070 .put("hosts", get(HostService.class).getHostCount())
Yuta HIGUCHI39cb61c2014-12-03 01:26:04 -080071 .put("SCC(s)", topology.clusterCount())
tom32085cf2014-10-16 00:04:33 -070072 .put("paths", topology.pathCount())
73 .put("flows", get(FlowRuleService.class).getFlowRuleCount())
74 .put("intents", get(IntentService.class).getIntentCount()));
75 } else {
76 print("node=%s, version=%s",
77 get(ClusterService.class).getLocalNode().ip(),
78 get(CoreService.class).version().toString());
Yuta HIGUCHI39cb61c2014-12-03 01:26:04 -080079 print("nodes=%d, devices=%d, links=%d, hosts=%d, SCC(s)=%s, paths=%d, flows=%d, intents=%d",
Ray Milkey356f28a2014-12-08 11:59:49 -080080 activeNodes(get(ClusterService.class).getNodes()),
tom32085cf2014-10-16 00:04:33 -070081 get(DeviceService.class).getDeviceCount(),
82 get(LinkService.class).getLinkCount(),
83 get(HostService.class).getHostCount(),
84 topologyService.getClusters(topology).size(),
85 topology.pathCount(),
86 get(FlowRuleService.class).getFlowRuleCount(),
87 get(IntentService.class).getIntentCount());
88 }
tom9b4030d2014-10-06 10:39:03 -070089 }
90
91}