blob: b4b3e98e75d2dd10576e6dfbab63135445fb7a37 [file] [log] [blame]
Thomas Vachuska7d693f52014-10-21 19:17:57 -07001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
tom9b4030d2014-10-06 10:39:03 -070019package org.onlab.onos.cli;
20
tom32085cf2014-10-16 00:04:33 -070021import com.fasterxml.jackson.databind.ObjectMapper;
tom9b4030d2014-10-06 10:39:03 -070022import org.apache.karaf.shell.commands.Command;
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070023import org.onlab.onos.core.CoreService;
tom9b4030d2014-10-06 10:39:03 -070024import org.onlab.onos.cluster.ClusterService;
25import org.onlab.onos.net.device.DeviceService;
26import org.onlab.onos.net.flow.FlowRuleService;
27import org.onlab.onos.net.host.HostService;
28import org.onlab.onos.net.intent.IntentService;
29import org.onlab.onos.net.link.LinkService;
tom800709a2014-10-06 20:52:14 -070030import org.onlab.onos.net.topology.Topology;
tom9b4030d2014-10-06 10:39:03 -070031import org.onlab.onos.net.topology.TopologyService;
32
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
40 @Override
41 protected void execute() {
42 TopologyService topologyService = get(TopologyService.class);
tom800709a2014-10-06 20:52:14 -070043 Topology topology = topologyService.currentTopology();
tom32085cf2014-10-16 00:04:33 -070044 if (outputJson()) {
45 print("%s", new ObjectMapper().createObjectNode()
46 .put("node", get(ClusterService.class).getLocalNode().ip().toString())
47 .put("version", get(CoreService.class).version().toString())
48 .put("nodes", get(ClusterService.class).getNodes().size())
49 .put("devices", get(DeviceService.class).getDeviceCount())
50 .put("links", get(LinkService.class).getLinkCount())
51 .put("hosts", get(HostService.class).getHostCount())
52 .put("clusters", topologyService.getClusters(topology).size())
53 .put("paths", topology.pathCount())
54 .put("flows", get(FlowRuleService.class).getFlowRuleCount())
55 .put("intents", get(IntentService.class).getIntentCount()));
56 } else {
57 print("node=%s, version=%s",
58 get(ClusterService.class).getLocalNode().ip(),
59 get(CoreService.class).version().toString());
60 print("nodes=%d, devices=%d, links=%d, hosts=%d, clusters=%s, paths=%d, flows=%d, intents=%d",
61 get(ClusterService.class).getNodes().size(),
62 get(DeviceService.class).getDeviceCount(),
63 get(LinkService.class).getLinkCount(),
64 get(HostService.class).getHostCount(),
65 topologyService.getClusters(topology).size(),
66 topology.pathCount(),
67 get(FlowRuleService.class).getFlowRuleCount(),
68 get(IntentService.class).getIntentCount());
69 }
tom9b4030d2014-10-06 10:39:03 -070070 }
71
72}