tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 1 | package org.onlab.onos.cli.net; |
| 2 | |
| 3 | import org.apache.karaf.shell.commands.Command; |
| 4 | import org.onlab.onos.cli.AbstractShellCommand; |
| 5 | import org.onlab.onos.net.topology.Topology; |
| 6 | import org.onlab.onos.net.topology.TopologyService; |
| 7 | |
| 8 | /** |
| 9 | * Lists summary of the current topology. |
| 10 | */ |
| 11 | @Command(scope = "onos", name = "topology", |
| 12 | description = "Lists summary of the current topology") |
| 13 | public class TopologyCommand extends AbstractShellCommand { |
| 14 | |
tom | 613d814 | 2014-09-11 15:09:37 -0700 | [diff] [blame] | 15 | // TODO: format the time-stamp |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 16 | private static final String FMT = |
| 17 | "time=%s, devices=%d, links=%d, clusters=%d, paths=%d"; |
| 18 | |
| 19 | protected TopologyService service; |
| 20 | protected Topology topology; |
| 21 | |
| 22 | /** |
| 23 | * Initializes the context for all cluster commands. |
| 24 | */ |
| 25 | protected void init() { |
| 26 | service = getService(TopologyService.class); |
| 27 | topology = service.currentTopology(); |
| 28 | } |
| 29 | |
| 30 | @Override |
| 31 | protected Object doExecute() throws Exception { |
| 32 | init(); |
| 33 | print(FMT, topology.time(), topology.deviceCount(), topology.linkCount(), |
| 34 | topology.clusterCount(), topology.pathCount()); |
| 35 | return null; |
| 36 | } |
| 37 | |
| 38 | } |