Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
tom | 9b4030d | 2014-10-06 10:39:03 -0700 | [diff] [blame] | 19 | package org.onlab.onos.cli; |
| 20 | |
tom | 32085cf | 2014-10-16 00:04:33 -0700 | [diff] [blame] | 21 | import com.fasterxml.jackson.databind.ObjectMapper; |
tom | 9b4030d | 2014-10-06 10:39:03 -0700 | [diff] [blame] | 22 | import org.apache.karaf.shell.commands.Command; |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 23 | import org.onlab.onos.core.CoreService; |
tom | 9b4030d | 2014-10-06 10:39:03 -0700 | [diff] [blame] | 24 | import org.onlab.onos.cluster.ClusterService; |
| 25 | import org.onlab.onos.net.device.DeviceService; |
| 26 | import org.onlab.onos.net.flow.FlowRuleService; |
| 27 | import org.onlab.onos.net.host.HostService; |
| 28 | import org.onlab.onos.net.intent.IntentService; |
| 29 | import org.onlab.onos.net.link.LinkService; |
tom | 800709a | 2014-10-06 20:52:14 -0700 | [diff] [blame] | 30 | import org.onlab.onos.net.topology.Topology; |
tom | 9b4030d | 2014-10-06 10:39:03 -0700 | [diff] [blame] | 31 | import 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") |
| 38 | public class SummaryCommand extends AbstractShellCommand { |
| 39 | |
| 40 | @Override |
| 41 | protected void execute() { |
| 42 | TopologyService topologyService = get(TopologyService.class); |
tom | 800709a | 2014-10-06 20:52:14 -0700 | [diff] [blame] | 43 | Topology topology = topologyService.currentTopology(); |
tom | 32085cf | 2014-10-16 00:04:33 -0700 | [diff] [blame] | 44 | 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 | } |
tom | 9b4030d | 2014-10-06 10:39:03 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | } |