blob: ad6d142149590f74256320967b8a8742123b17ba [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 */
tom9b4030d2014-10-06 10:39:03 -070016package org.onlab.onos.cli;
17
tom32085cf2014-10-16 00:04:33 -070018import com.fasterxml.jackson.databind.ObjectMapper;
tom9b4030d2014-10-06 10:39:03 -070019import org.apache.karaf.shell.commands.Command;
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070020import org.onlab.onos.core.CoreService;
tom9b4030d2014-10-06 10:39:03 -070021import org.onlab.onos.cluster.ClusterService;
22import org.onlab.onos.net.device.DeviceService;
23import org.onlab.onos.net.flow.FlowRuleService;
24import org.onlab.onos.net.host.HostService;
25import org.onlab.onos.net.intent.IntentService;
26import org.onlab.onos.net.link.LinkService;
tom800709a2014-10-06 20:52:14 -070027import org.onlab.onos.net.topology.Topology;
tom9b4030d2014-10-06 10:39:03 -070028import org.onlab.onos.net.topology.TopologyService;
29
30/**
31 * Provides summary of ONOS model.
32 */
33@Command(scope = "onos", name = "summary",
34 description = "Provides summary of ONOS model")
35public class SummaryCommand extends AbstractShellCommand {
36
37 @Override
38 protected void execute() {
39 TopologyService topologyService = get(TopologyService.class);
tom800709a2014-10-06 20:52:14 -070040 Topology topology = topologyService.currentTopology();
tom32085cf2014-10-16 00:04:33 -070041 if (outputJson()) {
42 print("%s", new ObjectMapper().createObjectNode()
43 .put("node", get(ClusterService.class).getLocalNode().ip().toString())
44 .put("version", get(CoreService.class).version().toString())
45 .put("nodes", get(ClusterService.class).getNodes().size())
Thomas Vachuska47635c62014-11-22 01:21:36 -080046 .put("devices", topology.deviceCount())
47 .put("links", topology.linkCount())
tom32085cf2014-10-16 00:04:33 -070048 .put("hosts", get(HostService.class).getHostCount())
Thomas Vachuska47635c62014-11-22 01:21:36 -080049 .put("clusters", topology.clusterCount())
tom32085cf2014-10-16 00:04:33 -070050 .put("paths", topology.pathCount())
51 .put("flows", get(FlowRuleService.class).getFlowRuleCount())
52 .put("intents", get(IntentService.class).getIntentCount()));
53 } else {
54 print("node=%s, version=%s",
55 get(ClusterService.class).getLocalNode().ip(),
56 get(CoreService.class).version().toString());
57 print("nodes=%d, devices=%d, links=%d, hosts=%d, clusters=%s, paths=%d, flows=%d, intents=%d",
58 get(ClusterService.class).getNodes().size(),
59 get(DeviceService.class).getDeviceCount(),
60 get(LinkService.class).getLinkCount(),
61 get(HostService.class).getHostCount(),
62 topologyService.getClusters(topology).size(),
63 topology.pathCount(),
64 get(FlowRuleService.class).getFlowRuleCount(),
65 get(IntentService.class).getIntentCount());
66 }
tom9b4030d2014-10-06 10:39:03 -070067 }
68
69}