blob: a7e6422684bbab6d165b6864d6d0cb234b93a19d [file] [log] [blame]
tom13cb4852014-09-11 12:44:17 -07001package org.onlab.onos.cli.net;
2
tom32085cf2014-10-16 00:04:33 -07003import com.fasterxml.jackson.databind.ObjectMapper;
tom13cb4852014-09-11 12:44:17 -07004import org.apache.karaf.shell.commands.Command;
5import org.onlab.onos.cli.AbstractShellCommand;
6import org.onlab.onos.net.topology.Topology;
7import 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")
14public class TopologyCommand extends AbstractShellCommand {
15
tom613d8142014-09-11 15:09:37 -070016 // TODO: format the time-stamp
tom13cb4852014-09-11 12:44:17 -070017 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() {
tomcaf3bf72014-09-23 13:20:53 -070027 service = get(TopologyService.class);
tom13cb4852014-09-11 12:44:17 -070028 topology = service.currentTopology();
29 }
30
31 @Override
tom0872a172014-09-23 11:24:26 -070032 protected void execute() {
tom13cb4852014-09-11 12:44:17 -070033 init();
tom32085cf2014-10-16 00:04:33 -070034 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 }
tom13cb4852014-09-11 12:44:17 -070045 }
46
47}