Showing
11 changed files
with
335 additions
and
11 deletions
1 | +package org.onlab.onos.cli.net; | ||
2 | + | ||
3 | +import com.google.common.collect.Lists; | ||
4 | +import org.apache.karaf.shell.commands.Argument; | ||
5 | +import org.apache.karaf.shell.commands.Command; | ||
6 | +import org.onlab.onos.net.DeviceId; | ||
7 | +import org.onlab.onos.net.topology.TopologyCluster; | ||
8 | + | ||
9 | +import java.util.Collections; | ||
10 | +import java.util.Comparator; | ||
11 | +import java.util.List; | ||
12 | + | ||
13 | +import static org.onlab.onos.net.topology.ClusterId.clusterId; | ||
14 | + | ||
15 | +/** | ||
16 | + * Lists devices of the specified topology cluster in the current topology. | ||
17 | + */ | ||
18 | +@Command(scope = "onos", name = "cluster-devices", | ||
19 | + description = "Lists devices of the specified topology cluster in the current topology") | ||
20 | +public class ClusterDevicesCommand extends ClustersListCommand { | ||
21 | + | ||
22 | + @Argument(index = 0, name = "id", description = "Cluster ID", | ||
23 | + required = false, multiValued = false) | ||
24 | + String id = null; | ||
25 | + | ||
26 | + protected static final Comparator<DeviceId> ID_COMPARATOR = new Comparator<DeviceId>() { | ||
27 | + @Override | ||
28 | + public int compare(DeviceId id1, DeviceId id2) { | ||
29 | + return id1.uri().toString().compareTo(id2.uri().toString()); | ||
30 | + } | ||
31 | + }; | ||
32 | + | ||
33 | + @Override | ||
34 | + protected Object doExecute() throws Exception { | ||
35 | + int cid = Integer.parseInt(id); | ||
36 | + init(); | ||
37 | + TopologyCluster cluster = service.getCluster(topology, clusterId(cid)); | ||
38 | + List<DeviceId> ids = Lists.newArrayList(service.getClusterDevices(topology, cluster)); | ||
39 | + Collections.sort(ids, ID_COMPARATOR); | ||
40 | + for (DeviceId deviceId : ids) { | ||
41 | + print("%s", deviceId); | ||
42 | + } | ||
43 | + return null; | ||
44 | + } | ||
45 | + | ||
46 | + | ||
47 | +} |
1 | +package org.onlab.onos.cli.net; | ||
2 | + | ||
3 | +import org.apache.karaf.shell.console.Completer; | ||
4 | +import org.apache.karaf.shell.console.completer.StringsCompleter; | ||
5 | +import org.onlab.onos.cli.AbstractShellCommand; | ||
6 | +import org.onlab.onos.net.topology.Topology; | ||
7 | +import org.onlab.onos.net.topology.TopologyCluster; | ||
8 | +import org.onlab.onos.net.topology.TopologyService; | ||
9 | + | ||
10 | +import java.util.List; | ||
11 | +import java.util.SortedSet; | ||
12 | + | ||
13 | +/** | ||
14 | + * Cluster ID completer. | ||
15 | + */ | ||
16 | +public class ClusterIdCompleter implements Completer { | ||
17 | + @Override | ||
18 | + public int complete(String buffer, int cursor, List<String> candidates) { | ||
19 | + // Delegate string completer | ||
20 | + StringsCompleter delegate = new StringsCompleter(); | ||
21 | + | ||
22 | + // Fetch our service and feed it's offerings to the string completer | ||
23 | + TopologyService service = AbstractShellCommand.get(TopologyService.class); | ||
24 | + Topology topology = service.currentTopology(); | ||
25 | + | ||
26 | + SortedSet<String> strings = delegate.getStrings(); | ||
27 | + for (TopologyCluster cluster : service.getClusters(topology)) { | ||
28 | + strings.add(Integer.toString(cluster.id().index())); | ||
29 | + } | ||
30 | + | ||
31 | + // Now let the completer do the work for figuring out what to offer. | ||
32 | + return delegate.complete(buffer, cursor, candidates); | ||
33 | + } | ||
34 | + | ||
35 | +} |
1 | +package org.onlab.onos.cli.net; | ||
2 | + | ||
3 | +import org.apache.karaf.shell.commands.Argument; | ||
4 | +import org.apache.karaf.shell.commands.Command; | ||
5 | +import org.onlab.onos.net.Link; | ||
6 | +import org.onlab.onos.net.topology.TopologyCluster; | ||
7 | + | ||
8 | +import static org.onlab.onos.cli.net.LinksListCommand.linkString; | ||
9 | +import static org.onlab.onos.net.topology.ClusterId.clusterId; | ||
10 | + | ||
11 | +/** | ||
12 | + * Lists links of the specified topology cluster in the current topology. | ||
13 | + */ | ||
14 | +@Command(scope = "onos", name = "cluster-links", | ||
15 | + description = "Lists links of the specified topology cluster in the current topology") | ||
16 | +public class ClusterLinksCommand extends ClustersListCommand { | ||
17 | + | ||
18 | + @Argument(index = 0, name = "id", description = "Cluster ID", | ||
19 | + required = false, multiValued = false) | ||
20 | + String id = null; | ||
21 | + | ||
22 | + @Override | ||
23 | + protected Object doExecute() throws Exception { | ||
24 | + int cid = Integer.parseInt(id); | ||
25 | + init(); | ||
26 | + TopologyCluster cluster = service.getCluster(topology, clusterId(cid)); | ||
27 | + for (Link link : service.getClusterLinks(topology, cluster)) { | ||
28 | + print(linkString(link)); | ||
29 | + } | ||
30 | + return null; | ||
31 | + } | ||
32 | + | ||
33 | + | ||
34 | +} |
1 | +package org.onlab.onos.cli.net; | ||
2 | + | ||
3 | +import com.google.common.collect.Lists; | ||
4 | +import org.apache.karaf.shell.commands.Command; | ||
5 | +import org.onlab.onos.net.topology.TopologyCluster; | ||
6 | + | ||
7 | +import java.util.Collections; | ||
8 | +import java.util.Comparator; | ||
9 | +import java.util.List; | ||
10 | + | ||
11 | +/** | ||
12 | + * Lists all clusters in the current topology. | ||
13 | + */ | ||
14 | +@Command(scope = "onos", name = "clusters", | ||
15 | + description = "Lists all clusters in the current topology") | ||
16 | +public class ClustersListCommand extends TopologyCommand { | ||
17 | + | ||
18 | + private static final String FMT = | ||
19 | + "id=%s, devices=%d, links=%d"; | ||
20 | + | ||
21 | + protected static final Comparator<TopologyCluster> ID_COMPARATOR = | ||
22 | + new Comparator<TopologyCluster>() { | ||
23 | + @Override | ||
24 | + public int compare(TopologyCluster c1, TopologyCluster c2) { | ||
25 | + return c1.id().index() - c2.id().index(); | ||
26 | + } | ||
27 | + }; | ||
28 | + | ||
29 | + @Override | ||
30 | + protected Object doExecute() throws Exception { | ||
31 | + init(); | ||
32 | + List<TopologyCluster> clusters = Lists.newArrayList(service.getClusters(topology)); | ||
33 | + Collections.sort(clusters, ID_COMPARATOR); | ||
34 | + | ||
35 | + for (TopologyCluster cluster : clusters) { | ||
36 | + print(FMT, cluster.id(), cluster.deviceCount(), cluster.linkCount()); | ||
37 | + } | ||
38 | + return null; | ||
39 | + } | ||
40 | + | ||
41 | +} |
... | @@ -27,9 +27,20 @@ public class LinksListCommand extends AbstractShellCommand { | ... | @@ -27,9 +27,20 @@ public class LinksListCommand extends AbstractShellCommand { |
27 | Iterable<Link> links = uri != null ? | 27 | Iterable<Link> links = uri != null ? |
28 | service.getDeviceLinks(deviceId(uri)) : service.getLinks(); | 28 | service.getDeviceLinks(deviceId(uri)) : service.getLinks(); |
29 | for (Link link : links) { | 29 | for (Link link : links) { |
30 | - print(FMT, link.src().deviceId(), link.src().port(), | 30 | + print(linkString(link)); |
31 | - link.dst().deviceId(), link.dst().port(), link.type()); | ||
32 | } | 31 | } |
33 | return null; | 32 | return null; |
34 | } | 33 | } |
34 | + | ||
35 | + /** | ||
36 | + * Returns a formated string representing the gien link. | ||
37 | + * | ||
38 | + * @param link infrastructure link | ||
39 | + * @return formated link string | ||
40 | + */ | ||
41 | + public static String linkString(Link link) { | ||
42 | + return String.format(FMT, link.src().deviceId(), link.src().port(), | ||
43 | + link.dst().deviceId(), link.dst().port(), link.type()); | ||
44 | + | ||
45 | + } | ||
35 | } | 46 | } | ... | ... |
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 | + | ||
15 | + private static final String FMT = | ||
16 | + "time=%s, devices=%d, links=%d, clusters=%d, paths=%d"; | ||
17 | + | ||
18 | + protected TopologyService service; | ||
19 | + protected Topology topology; | ||
20 | + | ||
21 | + /** | ||
22 | + * Initializes the context for all cluster commands. | ||
23 | + */ | ||
24 | + protected void init() { | ||
25 | + service = getService(TopologyService.class); | ||
26 | + topology = service.currentTopology(); | ||
27 | + } | ||
28 | + | ||
29 | + @Override | ||
30 | + protected Object doExecute() throws Exception { | ||
31 | + init(); | ||
32 | + print(FMT, topology.time(), topology.deviceCount(), topology.linkCount(), | ||
33 | + topology.clusterCount(), topology.pathCount()); | ||
34 | + return null; | ||
35 | + } | ||
36 | + | ||
37 | +} |
... | @@ -30,9 +30,29 @@ | ... | @@ -30,9 +30,29 @@ |
30 | <ref component-id="deviceIdCompleter"/> | 30 | <ref component-id="deviceIdCompleter"/> |
31 | </completers> | 31 | </completers> |
32 | </command> | 32 | </command> |
33 | + | ||
34 | + <command> | ||
35 | + <action class="org.onlab.onos.cli.net.TopologyCommand"/> | ||
36 | + </command> | ||
37 | + <command> | ||
38 | + <action class="org.onlab.onos.cli.net.ClustersListCommand"/> | ||
39 | + </command> | ||
40 | + <command> | ||
41 | + <action class="org.onlab.onos.cli.net.ClusterDevicesCommand"/> | ||
42 | + <completers> | ||
43 | + <ref component-id="clusterIdCompleter"/> | ||
44 | + </completers> | ||
45 | + </command> | ||
46 | + <command> | ||
47 | + <action class="org.onlab.onos.cli.net.ClusterLinksCommand"/> | ||
48 | + <completers> | ||
49 | + <ref component-id="clusterIdCompleter"/> | ||
50 | + </completers> | ||
51 | + </command> | ||
33 | </command-bundle> | 52 | </command-bundle> |
34 | 53 | ||
35 | <bean id="deviceIdCompleter" class="org.onlab.onos.cli.net.DeviceIdCompleter"/> | 54 | <bean id="deviceIdCompleter" class="org.onlab.onos.cli.net.DeviceIdCompleter"/> |
55 | + <bean id="clusterIdCompleter" class="org.onlab.onos.cli.net.ClusterIdCompleter"/> | ||
36 | <bean id="roleCompleter" class="org.onlab.onos.cli.net.RoleCompleter"/> | 56 | <bean id="roleCompleter" class="org.onlab.onos.cli.net.RoleCompleter"/> |
37 | 57 | ||
38 | </blueprint> | 58 | </blueprint> | ... | ... |
... | @@ -2,6 +2,7 @@ package org.onlab.onos.net.topology; | ... | @@ -2,6 +2,7 @@ package org.onlab.onos.net.topology; |
2 | 2 | ||
3 | import org.onlab.onos.net.ConnectPoint; | 3 | import org.onlab.onos.net.ConnectPoint; |
4 | import org.onlab.onos.net.DeviceId; | 4 | import org.onlab.onos.net.DeviceId; |
5 | +import org.onlab.onos.net.Link; | ||
5 | import org.onlab.onos.net.Path; | 6 | import org.onlab.onos.net.Path; |
6 | 7 | ||
7 | import java.util.Set; | 8 | import java.util.Set; |
... | @@ -27,6 +28,14 @@ public interface TopologyService { | ... | @@ -27,6 +28,14 @@ public interface TopologyService { |
27 | boolean isLatest(Topology topology); | 28 | boolean isLatest(Topology topology); |
28 | 29 | ||
29 | /** | 30 | /** |
31 | + * Returns the graph view of the specified topology. | ||
32 | + * | ||
33 | + * @param topology topology descriptor | ||
34 | + * @return topology graph view | ||
35 | + */ | ||
36 | + TopologyGraph getGraph(Topology topology); | ||
37 | + | ||
38 | + /** | ||
30 | * Returns the set of clusters in the specified topology. | 39 | * Returns the set of clusters in the specified topology. |
31 | * | 40 | * |
32 | * @param topology topology descriptor | 41 | * @param topology topology descriptor |
... | @@ -35,12 +44,31 @@ public interface TopologyService { | ... | @@ -35,12 +44,31 @@ public interface TopologyService { |
35 | Set<TopologyCluster> getClusters(Topology topology); | 44 | Set<TopologyCluster> getClusters(Topology topology); |
36 | 45 | ||
37 | /** | 46 | /** |
38 | - * Returns the graph view of the specified topology. | 47 | + * Returns the cluster with the specified ID. |
39 | * | 48 | * |
40 | - * @param topology topology descriptor | 49 | + * @param topology topology descriptor |
41 | - * @return topology graph view | 50 | + * @param clusterId cluster identifier |
51 | + * @return topology cluster | ||
42 | */ | 52 | */ |
43 | - TopologyGraph getGraph(Topology topology); | 53 | + TopologyCluster getCluster(Topology topology, ClusterId clusterId); |
54 | + | ||
55 | + /** | ||
56 | + * Returns the set of devices that belong to the specified cluster. | ||
57 | + * | ||
58 | + * @param topology topology descriptor | ||
59 | + * @param cluster topology cluster | ||
60 | + * @return set of cluster devices | ||
61 | + */ | ||
62 | + Set<DeviceId> getClusterDevices(Topology topology, TopologyCluster cluster); | ||
63 | + | ||
64 | + /** | ||
65 | + * Returns the set of links that form the specified cluster. | ||
66 | + * | ||
67 | + * @param topology topology descriptor | ||
68 | + * @param cluster topology cluster | ||
69 | + * @return set of cluster links | ||
70 | + */ | ||
71 | + Set<Link> getClusterLinks(Topology topology, TopologyCluster cluster); | ||
44 | 72 | ||
45 | /** | 73 | /** |
46 | * Returns the set of all shortest paths, precomputed in terms of hop-count, | 74 | * Returns the set of all shortest paths, precomputed in terms of hop-count, | ... | ... |
... | @@ -133,6 +133,17 @@ public class DefaultTopology extends AbstractModel implements Topology { | ... | @@ -133,6 +133,17 @@ public class DefaultTopology extends AbstractModel implements Topology { |
133 | } | 133 | } |
134 | 134 | ||
135 | /** | 135 | /** |
136 | + * Returns the specified topology cluster. | ||
137 | + * | ||
138 | + * @param clusterId cluster identifier | ||
139 | + * @return topology cluster | ||
140 | + */ | ||
141 | + TopologyCluster getCluster(ClusterId clusterId) { | ||
142 | + return clusters.get(clusterId); | ||
143 | + } | ||
144 | + | ||
145 | + | ||
146 | + /** | ||
136 | * Returns the set of cluster devices. | 147 | * Returns the set of cluster devices. |
137 | * | 148 | * |
138 | * @param cluster topology cluster | 149 | * @param cluster topology cluster | ... | ... |
... | @@ -11,9 +11,11 @@ import org.onlab.onos.event.Event; | ... | @@ -11,9 +11,11 @@ import org.onlab.onos.event.Event; |
11 | import org.onlab.onos.event.EventDeliveryService; | 11 | import org.onlab.onos.event.EventDeliveryService; |
12 | import org.onlab.onos.net.ConnectPoint; | 12 | import org.onlab.onos.net.ConnectPoint; |
13 | import org.onlab.onos.net.DeviceId; | 13 | import org.onlab.onos.net.DeviceId; |
14 | +import org.onlab.onos.net.Link; | ||
14 | import org.onlab.onos.net.Path; | 15 | import org.onlab.onos.net.Path; |
15 | import org.onlab.onos.net.provider.AbstractProviderRegistry; | 16 | import org.onlab.onos.net.provider.AbstractProviderRegistry; |
16 | import org.onlab.onos.net.provider.AbstractProviderService; | 17 | import org.onlab.onos.net.provider.AbstractProviderService; |
18 | +import org.onlab.onos.net.topology.ClusterId; | ||
17 | import org.onlab.onos.net.topology.GraphDescription; | 19 | import org.onlab.onos.net.topology.GraphDescription; |
18 | import org.onlab.onos.net.topology.LinkWeight; | 20 | import org.onlab.onos.net.topology.LinkWeight; |
19 | import org.onlab.onos.net.topology.Topology; | 21 | import org.onlab.onos.net.topology.Topology; |
... | @@ -44,6 +46,8 @@ public class SimpleTopologyManager | ... | @@ -44,6 +46,8 @@ public class SimpleTopologyManager |
44 | 46 | ||
45 | public static final String TOPOLOGY_NULL = "Topology cannot be null"; | 47 | public static final String TOPOLOGY_NULL = "Topology cannot be null"; |
46 | private static final String DEVICE_ID_NULL = "Device ID cannot be null"; | 48 | private static final String DEVICE_ID_NULL = "Device ID cannot be null"; |
49 | + private static final String CLUSTER_ID_NULL = "Cluster ID cannot be null"; | ||
50 | + private static final String CLUSTER_NULL = "Topology cluster cannot be null"; | ||
47 | public static final String CONNECTION_POINT_NULL = "Connection point cannot be null"; | 51 | public static final String CONNECTION_POINT_NULL = "Connection point cannot be null"; |
48 | 52 | ||
49 | private final Logger log = getLogger(getClass()); | 53 | private final Logger log = getLogger(getClass()); |
... | @@ -96,6 +100,27 @@ public class SimpleTopologyManager | ... | @@ -96,6 +100,27 @@ public class SimpleTopologyManager |
96 | } | 100 | } |
97 | 101 | ||
98 | @Override | 102 | @Override |
103 | + public TopologyCluster getCluster(Topology topology, ClusterId clusterId) { | ||
104 | + checkNotNull(topology, TOPOLOGY_NULL); | ||
105 | + checkNotNull(topology, CLUSTER_ID_NULL); | ||
106 | + return store.getCluster(defaultTopology(topology), clusterId); | ||
107 | + } | ||
108 | + | ||
109 | + @Override | ||
110 | + public Set<DeviceId> getClusterDevices(Topology topology, TopologyCluster cluster) { | ||
111 | + checkNotNull(topology, TOPOLOGY_NULL); | ||
112 | + checkNotNull(topology, CLUSTER_NULL); | ||
113 | + return store.getClusterDevices(defaultTopology(topology), cluster); | ||
114 | + } | ||
115 | + | ||
116 | + @Override | ||
117 | + public Set<Link> getClusterLinks(Topology topology, TopologyCluster cluster) { | ||
118 | + checkNotNull(topology, TOPOLOGY_NULL); | ||
119 | + checkNotNull(topology, CLUSTER_NULL); | ||
120 | + return store.getClusterLinks(defaultTopology(topology), cluster); | ||
121 | + } | ||
122 | + | ||
123 | + @Override | ||
99 | public TopologyGraph getGraph(Topology topology) { | 124 | public TopologyGraph getGraph(Topology topology) { |
100 | checkNotNull(topology, TOPOLOGY_NULL); | 125 | checkNotNull(topology, TOPOLOGY_NULL); |
101 | return store.getGraph(defaultTopology(topology)); | 126 | return store.getGraph(defaultTopology(topology)); | ... | ... |
... | @@ -3,8 +3,10 @@ package org.onlab.onos.net.trivial.topology.impl; | ... | @@ -3,8 +3,10 @@ package org.onlab.onos.net.trivial.topology.impl; |
3 | import org.onlab.onos.event.Event; | 3 | import org.onlab.onos.event.Event; |
4 | import org.onlab.onos.net.ConnectPoint; | 4 | import org.onlab.onos.net.ConnectPoint; |
5 | import org.onlab.onos.net.DeviceId; | 5 | import org.onlab.onos.net.DeviceId; |
6 | +import org.onlab.onos.net.Link; | ||
6 | import org.onlab.onos.net.Path; | 7 | import org.onlab.onos.net.Path; |
7 | import org.onlab.onos.net.provider.ProviderId; | 8 | import org.onlab.onos.net.provider.ProviderId; |
9 | +import org.onlab.onos.net.topology.ClusterId; | ||
8 | import org.onlab.onos.net.topology.GraphDescription; | 10 | import org.onlab.onos.net.topology.GraphDescription; |
9 | import org.onlab.onos.net.topology.LinkWeight; | 11 | import org.onlab.onos.net.topology.LinkWeight; |
10 | import org.onlab.onos.net.topology.Topology; | 12 | import org.onlab.onos.net.topology.Topology; |
... | @@ -44,6 +46,16 @@ class SimpleTopologyStore { | ... | @@ -44,6 +46,16 @@ class SimpleTopologyStore { |
44 | } | 46 | } |
45 | 47 | ||
46 | /** | 48 | /** |
49 | + * Returns the immutable graph view of the current topology. | ||
50 | + * | ||
51 | + * @param topology topology descriptor | ||
52 | + * @return graph view | ||
53 | + */ | ||
54 | + TopologyGraph getGraph(DefaultTopology topology) { | ||
55 | + return topology.getGraph(); | ||
56 | + } | ||
57 | + | ||
58 | + /** | ||
47 | * Returns the set of topology SCC clusters. | 59 | * Returns the set of topology SCC clusters. |
48 | * | 60 | * |
49 | * @param topology topology descriptor | 61 | * @param topology topology descriptor |
... | @@ -54,13 +66,36 @@ class SimpleTopologyStore { | ... | @@ -54,13 +66,36 @@ class SimpleTopologyStore { |
54 | } | 66 | } |
55 | 67 | ||
56 | /** | 68 | /** |
57 | - * Returns the immutable graph view of the current topology. | 69 | + * Returns the cluster of the specified topology. |
58 | * | 70 | * |
59 | - * @param topology topology descriptor | 71 | + * @param topology topology descriptor |
60 | - * @return graph view | 72 | + * @param clusterId cluster identity |
73 | + * @return topology cluster | ||
61 | */ | 74 | */ |
62 | - TopologyGraph getGraph(DefaultTopology topology) { | 75 | + TopologyCluster getCluster(DefaultTopology topology, ClusterId clusterId) { |
63 | - return topology.getGraph(); | 76 | + return topology.getCluster(clusterId); |
77 | + } | ||
78 | + | ||
79 | + /** | ||
80 | + * Returns the cluster of the specified topology. | ||
81 | + * | ||
82 | + * @param topology topology descriptor | ||
83 | + * @param cluster topology cluster | ||
84 | + * @return set of cluster links | ||
85 | + */ | ||
86 | + Set<DeviceId> getClusterDevices(DefaultTopology topology, TopologyCluster cluster) { | ||
87 | + return topology.getClusterDevices(cluster); | ||
88 | + } | ||
89 | + | ||
90 | + /** | ||
91 | + * Returns the cluster of the specified topology. | ||
92 | + * | ||
93 | + * @param topology topology descriptor | ||
94 | + * @param cluster topology cluster | ||
95 | + * @return set of cluster links | ||
96 | + */ | ||
97 | + Set<Link> getClusterLinks(DefaultTopology topology, TopologyCluster cluster) { | ||
98 | + return topology.getClusterLinks(cluster); | ||
64 | } | 99 | } |
65 | 100 | ||
66 | /** | 101 | /** | ... | ... |
-
Please register or login to post a comment