tom | 9b4030d | 2014-10-06 10:39:03 -0700 | [diff] [blame] | 1 | package org.onlab.onos.cli; |
| 2 | |
tom | 32085cf | 2014-10-16 00:04:33 -0700 | [diff] [blame^] | 3 | import com.fasterxml.jackson.databind.ObjectMapper; |
tom | 9b4030d | 2014-10-06 10:39:03 -0700 | [diff] [blame] | 4 | import org.apache.karaf.shell.commands.Command; |
tom | 53efab5 | 2014-10-07 17:43:48 -0700 | [diff] [blame] | 5 | import org.onlab.onos.CoreService; |
tom | 9b4030d | 2014-10-06 10:39:03 -0700 | [diff] [blame] | 6 | import org.onlab.onos.cluster.ClusterService; |
| 7 | import org.onlab.onos.net.device.DeviceService; |
| 8 | import org.onlab.onos.net.flow.FlowRuleService; |
| 9 | import org.onlab.onos.net.host.HostService; |
| 10 | import org.onlab.onos.net.intent.IntentService; |
| 11 | import org.onlab.onos.net.link.LinkService; |
tom | 800709a | 2014-10-06 20:52:14 -0700 | [diff] [blame] | 12 | import org.onlab.onos.net.topology.Topology; |
tom | 9b4030d | 2014-10-06 10:39:03 -0700 | [diff] [blame] | 13 | import org.onlab.onos.net.topology.TopologyService; |
| 14 | |
| 15 | /** |
| 16 | * Provides summary of ONOS model. |
| 17 | */ |
| 18 | @Command(scope = "onos", name = "summary", |
| 19 | description = "Provides summary of ONOS model") |
| 20 | public class SummaryCommand extends AbstractShellCommand { |
| 21 | |
| 22 | @Override |
| 23 | protected void execute() { |
| 24 | TopologyService topologyService = get(TopologyService.class); |
tom | 800709a | 2014-10-06 20:52:14 -0700 | [diff] [blame] | 25 | Topology topology = topologyService.currentTopology(); |
tom | 32085cf | 2014-10-16 00:04:33 -0700 | [diff] [blame^] | 26 | if (outputJson()) { |
| 27 | print("%s", new ObjectMapper().createObjectNode() |
| 28 | .put("node", get(ClusterService.class).getLocalNode().ip().toString()) |
| 29 | .put("version", get(CoreService.class).version().toString()) |
| 30 | .put("nodes", get(ClusterService.class).getNodes().size()) |
| 31 | .put("devices", get(DeviceService.class).getDeviceCount()) |
| 32 | .put("links", get(LinkService.class).getLinkCount()) |
| 33 | .put("hosts", get(HostService.class).getHostCount()) |
| 34 | .put("clusters", topologyService.getClusters(topology).size()) |
| 35 | .put("paths", topology.pathCount()) |
| 36 | .put("flows", get(FlowRuleService.class).getFlowRuleCount()) |
| 37 | .put("intents", get(IntentService.class).getIntentCount())); |
| 38 | } else { |
| 39 | print("node=%s, version=%s", |
| 40 | get(ClusterService.class).getLocalNode().ip(), |
| 41 | get(CoreService.class).version().toString()); |
| 42 | print("nodes=%d, devices=%d, links=%d, hosts=%d, clusters=%s, paths=%d, flows=%d, intents=%d", |
| 43 | get(ClusterService.class).getNodes().size(), |
| 44 | get(DeviceService.class).getDeviceCount(), |
| 45 | get(LinkService.class).getLinkCount(), |
| 46 | get(HostService.class).getHostCount(), |
| 47 | topologyService.getClusters(topology).size(), |
| 48 | topology.pathCount(), |
| 49 | get(FlowRuleService.class).getFlowRuleCount(), |
| 50 | get(IntentService.class).getIntentCount()); |
| 51 | } |
tom | 9b4030d | 2014-10-06 10:39:03 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | } |