Added topology command-lines.
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/ClusterDevicesCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/ClusterDevicesCommand.java
new file mode 100644
index 0000000..d4d6d24
--- /dev/null
+++ b/cli/src/main/java/org/onlab/onos/cli/net/ClusterDevicesCommand.java
@@ -0,0 +1,47 @@
+package org.onlab.onos.cli.net;
+
+import com.google.common.collect.Lists;
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.onlab.onos.net.DeviceId;
+import org.onlab.onos.net.topology.TopologyCluster;
+
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import static org.onlab.onos.net.topology.ClusterId.clusterId;
+
+/**
+ * Lists devices of the specified topology cluster in the current topology.
+ */
+@Command(scope = "onos", name = "cluster-devices",
+ description = "Lists devices of the specified topology cluster in the current topology")
+public class ClusterDevicesCommand extends ClustersListCommand {
+
+ @Argument(index = 0, name = "id", description = "Cluster ID",
+ required = false, multiValued = false)
+ String id = null;
+
+ protected static final Comparator<DeviceId> ID_COMPARATOR = new Comparator<DeviceId>() {
+ @Override
+ public int compare(DeviceId id1, DeviceId id2) {
+ return id1.uri().toString().compareTo(id2.uri().toString());
+ }
+ };
+
+ @Override
+ protected Object doExecute() throws Exception {
+ int cid = Integer.parseInt(id);
+ init();
+ TopologyCluster cluster = service.getCluster(topology, clusterId(cid));
+ List<DeviceId> ids = Lists.newArrayList(service.getClusterDevices(topology, cluster));
+ Collections.sort(ids, ID_COMPARATOR);
+ for (DeviceId deviceId : ids) {
+ print("%s", deviceId);
+ }
+ return null;
+ }
+
+
+}
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/ClusterIdCompleter.java b/cli/src/main/java/org/onlab/onos/cli/net/ClusterIdCompleter.java
new file mode 100644
index 0000000..e39e01b
--- /dev/null
+++ b/cli/src/main/java/org/onlab/onos/cli/net/ClusterIdCompleter.java
@@ -0,0 +1,35 @@
+package org.onlab.onos.cli.net;
+
+import org.apache.karaf.shell.console.Completer;
+import org.apache.karaf.shell.console.completer.StringsCompleter;
+import org.onlab.onos.cli.AbstractShellCommand;
+import org.onlab.onos.net.topology.Topology;
+import org.onlab.onos.net.topology.TopologyCluster;
+import org.onlab.onos.net.topology.TopologyService;
+
+import java.util.List;
+import java.util.SortedSet;
+
+/**
+ * Cluster ID completer.
+ */
+public class ClusterIdCompleter implements Completer {
+ @Override
+ public int complete(String buffer, int cursor, List<String> candidates) {
+ // Delegate string completer
+ StringsCompleter delegate = new StringsCompleter();
+
+ // Fetch our service and feed it's offerings to the string completer
+ TopologyService service = AbstractShellCommand.get(TopologyService.class);
+ Topology topology = service.currentTopology();
+
+ SortedSet<String> strings = delegate.getStrings();
+ for (TopologyCluster cluster : service.getClusters(topology)) {
+ strings.add(Integer.toString(cluster.id().index()));
+ }
+
+ // Now let the completer do the work for figuring out what to offer.
+ return delegate.complete(buffer, cursor, candidates);
+ }
+
+}
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/ClusterLinksCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/ClusterLinksCommand.java
new file mode 100644
index 0000000..5285418
--- /dev/null
+++ b/cli/src/main/java/org/onlab/onos/cli/net/ClusterLinksCommand.java
@@ -0,0 +1,34 @@
+package org.onlab.onos.cli.net;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.onlab.onos.net.Link;
+import org.onlab.onos.net.topology.TopologyCluster;
+
+import static org.onlab.onos.cli.net.LinksListCommand.linkString;
+import static org.onlab.onos.net.topology.ClusterId.clusterId;
+
+/**
+ * Lists links of the specified topology cluster in the current topology.
+ */
+@Command(scope = "onos", name = "cluster-links",
+ description = "Lists links of the specified topology cluster in the current topology")
+public class ClusterLinksCommand extends ClustersListCommand {
+
+ @Argument(index = 0, name = "id", description = "Cluster ID",
+ required = false, multiValued = false)
+ String id = null;
+
+ @Override
+ protected Object doExecute() throws Exception {
+ int cid = Integer.parseInt(id);
+ init();
+ TopologyCluster cluster = service.getCluster(topology, clusterId(cid));
+ for (Link link : service.getClusterLinks(topology, cluster)) {
+ print(linkString(link));
+ }
+ return null;
+ }
+
+
+}
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/ClustersListCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/ClustersListCommand.java
new file mode 100644
index 0000000..355825b
--- /dev/null
+++ b/cli/src/main/java/org/onlab/onos/cli/net/ClustersListCommand.java
@@ -0,0 +1,41 @@
+package org.onlab.onos.cli.net;
+
+import com.google.common.collect.Lists;
+import org.apache.karaf.shell.commands.Command;
+import org.onlab.onos.net.topology.TopologyCluster;
+
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+/**
+ * Lists all clusters in the current topology.
+ */
+@Command(scope = "onos", name = "clusters",
+ description = "Lists all clusters in the current topology")
+public class ClustersListCommand extends TopologyCommand {
+
+ private static final String FMT =
+ "id=%s, devices=%d, links=%d";
+
+ protected static final Comparator<TopologyCluster> ID_COMPARATOR =
+ new Comparator<TopologyCluster>() {
+ @Override
+ public int compare(TopologyCluster c1, TopologyCluster c2) {
+ return c1.id().index() - c2.id().index();
+ }
+ };
+
+ @Override
+ protected Object doExecute() throws Exception {
+ init();
+ List<TopologyCluster> clusters = Lists.newArrayList(service.getClusters(topology));
+ Collections.sort(clusters, ID_COMPARATOR);
+
+ for (TopologyCluster cluster : clusters) {
+ print(FMT, cluster.id(), cluster.deviceCount(), cluster.linkCount());
+ }
+ return null;
+ }
+
+}
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/LinksListCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/LinksListCommand.java
index cb6fcb1..6c3952d 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/LinksListCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/LinksListCommand.java
@@ -27,9 +27,20 @@
Iterable<Link> links = uri != null ?
service.getDeviceLinks(deviceId(uri)) : service.getLinks();
for (Link link : links) {
- print(FMT, link.src().deviceId(), link.src().port(),
- link.dst().deviceId(), link.dst().port(), link.type());
+ print(linkString(link));
}
return null;
}
+
+ /**
+ * Returns a formated string representing the gien link.
+ *
+ * @param link infrastructure link
+ * @return formated link string
+ */
+ public static String linkString(Link link) {
+ return String.format(FMT, link.src().deviceId(), link.src().port(),
+ link.dst().deviceId(), link.dst().port(), link.type());
+
+ }
}
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/TopologyCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/TopologyCommand.java
new file mode 100644
index 0000000..a390025
--- /dev/null
+++ b/cli/src/main/java/org/onlab/onos/cli/net/TopologyCommand.java
@@ -0,0 +1,37 @@
+package org.onlab.onos.cli.net;
+
+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 {
+
+ 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 = getService(TopologyService.class);
+ topology = service.currentTopology();
+ }
+
+ @Override
+ protected Object doExecute() throws Exception {
+ init();
+ print(FMT, topology.time(), topology.deviceCount(), topology.linkCount(),
+ topology.clusterCount(), topology.pathCount());
+ return null;
+ }
+
+}