| package org.onlab.onos.cli.net; |
| |
| import com.fasterxml.jackson.databind.ObjectMapper; |
| import org.apache.karaf.shell.commands.Command; |
| import org.onlab.onos.cli.AbstractShellCommand; |
| import org.onlab.onos.net.topology.Topology; |
| import org.onlab.onos.net.topology.TopologyService; |
| |
| /** |
| * Lists summary of the current topology. |
| */ |
| @Command(scope = "onos", name = "topology", |
| description = "Lists summary of the current topology") |
| public class TopologyCommand extends AbstractShellCommand { |
| |
| // TODO: format the time-stamp |
| private static final String FMT = |
| "time=%s, devices=%d, links=%d, clusters=%d, paths=%d"; |
| |
| protected TopologyService service; |
| protected Topology topology; |
| |
| /** |
| * Initializes the context for all cluster commands. |
| */ |
| protected void init() { |
| service = get(TopologyService.class); |
| topology = service.currentTopology(); |
| } |
| |
| @Override |
| protected void execute() { |
| init(); |
| if (outputJson()) { |
| print("%s", new ObjectMapper().createObjectNode() |
| .put("time", topology.time()) |
| .put("deviceCount", topology.deviceCount()) |
| .put("linkCount", topology.linkCount()) |
| .put("clusterCount", topology.clusterCount()) |
| .put("pathCount", topology.pathCount())); |
| } else { |
| print(FMT, topology.time(), topology.deviceCount(), topology.linkCount(), |
| topology.clusterCount(), topology.pathCount()); |
| } |
| } |
| |
| } |