tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 1 | package org.onlab.onos.cli.net; |
| 2 | |
tom | 32085cf | 2014-10-16 00:04:33 -0700 | [diff] [blame^] | 3 | import com.fasterxml.jackson.databind.ObjectMapper; |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 4 | import org.apache.karaf.shell.commands.Command; |
| 5 | import org.onlab.onos.cli.AbstractShellCommand; |
| 6 | import org.onlab.onos.net.topology.Topology; |
| 7 | import org.onlab.onos.net.topology.TopologyService; |
| 8 | |
| 9 | /** |
| 10 | * Lists summary of the current topology. |
| 11 | */ |
| 12 | @Command(scope = "onos", name = "topology", |
| 13 | description = "Lists summary of the current topology") |
| 14 | public class TopologyCommand extends AbstractShellCommand { |
| 15 | |
tom | 613d814 | 2014-09-11 15:09:37 -0700 | [diff] [blame] | 16 | // TODO: format the time-stamp |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 17 | private static final String FMT = |
| 18 | "time=%s, devices=%d, links=%d, clusters=%d, paths=%d"; |
| 19 | |
| 20 | protected TopologyService service; |
| 21 | protected Topology topology; |
| 22 | |
| 23 | /** |
| 24 | * Initializes the context for all cluster commands. |
| 25 | */ |
| 26 | protected void init() { |
tom | caf3bf7 | 2014-09-23 13:20:53 -0700 | [diff] [blame] | 27 | service = get(TopologyService.class); |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 28 | topology = service.currentTopology(); |
| 29 | } |
| 30 | |
| 31 | @Override |
tom | 0872a17 | 2014-09-23 11:24:26 -0700 | [diff] [blame] | 32 | protected void execute() { |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 33 | init(); |
tom | 32085cf | 2014-10-16 00:04:33 -0700 | [diff] [blame^] | 34 | if (outputJson()) { |
| 35 | print("%s", new ObjectMapper().createObjectNode() |
| 36 | .put("time", topology.time()) |
| 37 | .put("deviceCount", topology.deviceCount()) |
| 38 | .put("linkCount", topology.linkCount()) |
| 39 | .put("clusterCount", topology.clusterCount()) |
| 40 | .put("pathCount", topology.pathCount())); |
| 41 | } else { |
| 42 | print(FMT, topology.time(), topology.deviceCount(), topology.linkCount(), |
| 43 | topology.clusterCount(), topology.pathCount()); |
| 44 | } |
tom | 13cb485 | 2014-09-11 12:44:17 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | } |