Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 2 | * Copyright 2014 Open Networking Laboratory |
Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 4 | * 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 Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 8 | * 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 Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 15 | */ |
tom | 9b4030d | 2014-10-06 10:39:03 -0700 | [diff] [blame] | 16 | package org.onlab.onos.cli; |
| 17 | |
tom | 32085cf | 2014-10-16 00:04:33 -0700 | [diff] [blame] | 18 | import com.fasterxml.jackson.databind.ObjectMapper; |
tom | 9b4030d | 2014-10-06 10:39:03 -0700 | [diff] [blame] | 19 | import org.apache.karaf.shell.commands.Command; |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 20 | import org.onlab.onos.core.CoreService; |
tom | 9b4030d | 2014-10-06 10:39:03 -0700 | [diff] [blame] | 21 | import org.onlab.onos.cluster.ClusterService; |
| 22 | import org.onlab.onos.net.device.DeviceService; |
| 23 | import org.onlab.onos.net.flow.FlowRuleService; |
| 24 | import org.onlab.onos.net.host.HostService; |
| 25 | import org.onlab.onos.net.intent.IntentService; |
| 26 | import org.onlab.onos.net.link.LinkService; |
tom | 800709a | 2014-10-06 20:52:14 -0700 | [diff] [blame] | 27 | import org.onlab.onos.net.topology.Topology; |
tom | 9b4030d | 2014-10-06 10:39:03 -0700 | [diff] [blame] | 28 | import 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") |
| 35 | public class SummaryCommand extends AbstractShellCommand { |
| 36 | |
| 37 | @Override |
| 38 | protected void execute() { |
| 39 | TopologyService topologyService = get(TopologyService.class); |
tom | 800709a | 2014-10-06 20:52:14 -0700 | [diff] [blame] | 40 | Topology topology = topologyService.currentTopology(); |
tom | 32085cf | 2014-10-16 00:04:33 -0700 | [diff] [blame] | 41 | 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()) |
| 46 | .put("devices", get(DeviceService.class).getDeviceCount()) |
| 47 | .put("links", get(LinkService.class).getLinkCount()) |
| 48 | .put("hosts", get(HostService.class).getHostCount()) |
| 49 | .put("clusters", topologyService.getClusters(topology).size()) |
| 50 | .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 | } |
tom | 9b4030d | 2014-10-06 10:39:03 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | } |