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() { |
tom | caf3bf7 | 2014-09-23 13:20:53 -0700 | [diff] [blame] | 26 | service = get(TopologyService.class); |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 27 | topology = service.currentTopology(); |
| 28 | } |
| 29 | |
| 30 | @Override |
tom | 0872a17 | 2014-09-23 11:24:26 -0700 | [diff] [blame] | 31 | protected void execute() { |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 32 | init(); |
| 33 | print(FMT, topology.time(), topology.deviceCount(), topology.linkCount(), |
| 34 | topology.clusterCount(), topology.pathCount()); |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | } |