Showing
13 changed files
with
170 additions
and
85 deletions
1 | +package org.onlab.onos.cli; | ||
2 | + | ||
3 | +import com.google.common.collect.Lists; | ||
4 | +import org.apache.karaf.shell.commands.Command; | ||
5 | +import org.onlab.onos.cli.net.Comparators; | ||
6 | +import org.onlab.onos.cluster.ClusterService; | ||
7 | +import org.onlab.onos.cluster.ControllerNode; | ||
8 | +import org.onlab.onos.cluster.MastershipService; | ||
9 | +import org.onlab.onos.net.DeviceId; | ||
10 | + | ||
11 | +import java.util.Collections; | ||
12 | +import java.util.List; | ||
13 | + | ||
14 | +import static com.google.common.collect.Lists.newArrayList; | ||
15 | + | ||
16 | +/** | ||
17 | + * Lists device mastership information. | ||
18 | + */ | ||
19 | +@Command(scope = "onos", name = "masters", | ||
20 | + description = "Lists device mastership information") | ||
21 | +public class MastersListCommand extends AbstractShellCommand { | ||
22 | + | ||
23 | + @Override | ||
24 | + protected void execute() { | ||
25 | + ClusterService service = get(ClusterService.class); | ||
26 | + MastershipService mastershipService = get(MastershipService.class); | ||
27 | + List<ControllerNode> nodes = newArrayList(service.getNodes()); | ||
28 | + Collections.sort(nodes, Comparators.NODE_COMPARATOR); | ||
29 | + ControllerNode self = service.getLocalNode(); | ||
30 | + for (ControllerNode node : nodes) { | ||
31 | + List<DeviceId> ids = Lists.newArrayList(mastershipService.getDevicesOf(node.id())); | ||
32 | + Collections.sort(ids, Comparators.ELEMENT_ID_COMPARATOR); | ||
33 | + print("%s: %d devices", node.id(), ids.size()); | ||
34 | + for (DeviceId deviceId : ids) { | ||
35 | + print(" %s", deviceId); | ||
36 | + } | ||
37 | + } | ||
38 | + } | ||
39 | + | ||
40 | +} |
1 | +package org.onlab.onos.cli; | ||
2 | + | ||
3 | +import org.apache.karaf.shell.console.Completer; | ||
4 | +import org.apache.karaf.shell.console.completer.StringsCompleter; | ||
5 | +import org.onlab.onos.cluster.ClusterService; | ||
6 | +import org.onlab.onos.cluster.ControllerNode; | ||
7 | + | ||
8 | +import java.util.Iterator; | ||
9 | +import java.util.List; | ||
10 | +import java.util.SortedSet; | ||
11 | + | ||
12 | +/** | ||
13 | + * Node ID completer. | ||
14 | + */ | ||
15 | +public class NodeIdCompleter implements Completer { | ||
16 | + @Override | ||
17 | + public int complete(String buffer, int cursor, List<String> candidates) { | ||
18 | + // Delegate string completer | ||
19 | + StringsCompleter delegate = new StringsCompleter(); | ||
20 | + | ||
21 | + // Fetch our service and feed it's offerings to the string completer | ||
22 | + ClusterService service = AbstractShellCommand.get(ClusterService.class); | ||
23 | + Iterator<ControllerNode> it = service.getNodes().iterator(); | ||
24 | + SortedSet<String> strings = delegate.getStrings(); | ||
25 | + while (it.hasNext()) { | ||
26 | + strings.add(it.next().id().toString()); | ||
27 | + } | ||
28 | + | ||
29 | + // Now let the completer do the work for figuring out what to offer. | ||
30 | + return delegate.complete(buffer, cursor, candidates); | ||
31 | + } | ||
32 | + | ||
33 | +} |
1 | package org.onlab.onos.cli; | 1 | package org.onlab.onos.cli; |
2 | 2 | ||
3 | import org.apache.karaf.shell.commands.Command; | 3 | import org.apache.karaf.shell.commands.Command; |
4 | +import org.onlab.onos.cli.net.Comparators; | ||
4 | import org.onlab.onos.cluster.ClusterService; | 5 | import org.onlab.onos.cluster.ClusterService; |
5 | import org.onlab.onos.cluster.ControllerNode; | 6 | import org.onlab.onos.cluster.ControllerNode; |
6 | 7 | ||
7 | import java.util.Collections; | 8 | import java.util.Collections; |
8 | -import java.util.Comparator; | ||
9 | import java.util.List; | 9 | import java.util.List; |
10 | 10 | ||
11 | import static com.google.common.collect.Lists.newArrayList; | 11 | import static com.google.common.collect.Lists.newArrayList; |
... | @@ -20,19 +20,11 @@ public class NodesListCommand extends AbstractShellCommand { | ... | @@ -20,19 +20,11 @@ public class NodesListCommand extends AbstractShellCommand { |
20 | private static final String FMT = | 20 | private static final String FMT = |
21 | "id=%s, ip=%s, state=%s %s"; | 21 | "id=%s, ip=%s, state=%s %s"; |
22 | 22 | ||
23 | - protected static final Comparator<ControllerNode> ID_COMPARATOR = | ||
24 | - new Comparator<ControllerNode>() { | ||
25 | - @Override | ||
26 | - public int compare(ControllerNode ci1, ControllerNode ci2) { | ||
27 | - return ci1.id().toString().compareTo(ci2.id().toString()); | ||
28 | - } | ||
29 | - }; | ||
30 | - | ||
31 | @Override | 23 | @Override |
32 | protected void execute() { | 24 | protected void execute() { |
33 | ClusterService service = get(ClusterService.class); | 25 | ClusterService service = get(ClusterService.class); |
34 | List<ControllerNode> nodes = newArrayList(service.getNodes()); | 26 | List<ControllerNode> nodes = newArrayList(service.getNodes()); |
35 | - Collections.sort(nodes, ID_COMPARATOR); | 27 | + Collections.sort(nodes, Comparators.NODE_COMPARATOR); |
36 | ControllerNode self = service.getLocalNode(); | 28 | ControllerNode self = service.getLocalNode(); |
37 | for (ControllerNode node : nodes) { | 29 | for (ControllerNode node : nodes) { |
38 | print(FMT, node.id(), node.ip(), | 30 | print(FMT, node.id(), node.ip(), | ... | ... |
... | @@ -7,7 +7,6 @@ import org.onlab.onos.net.DeviceId; | ... | @@ -7,7 +7,6 @@ import org.onlab.onos.net.DeviceId; |
7 | import org.onlab.onos.net.topology.TopologyCluster; | 7 | import org.onlab.onos.net.topology.TopologyCluster; |
8 | 8 | ||
9 | import java.util.Collections; | 9 | import java.util.Collections; |
10 | -import java.util.Comparator; | ||
11 | import java.util.List; | 10 | import java.util.List; |
12 | 11 | ||
13 | import static org.onlab.onos.net.topology.ClusterId.clusterId; | 12 | import static org.onlab.onos.net.topology.ClusterId.clusterId; |
... | @@ -23,13 +22,6 @@ public class ClusterDevicesCommand extends ClustersListCommand { | ... | @@ -23,13 +22,6 @@ public class ClusterDevicesCommand extends ClustersListCommand { |
23 | required = false, multiValued = false) | 22 | required = false, multiValued = false) |
24 | String id = null; | 23 | String id = null; |
25 | 24 | ||
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 | 25 | @Override |
34 | protected void execute() { | 26 | protected void execute() { |
35 | int cid = Integer.parseInt(id); | 27 | int cid = Integer.parseInt(id); |
... | @@ -39,7 +31,7 @@ public class ClusterDevicesCommand extends ClustersListCommand { | ... | @@ -39,7 +31,7 @@ public class ClusterDevicesCommand extends ClustersListCommand { |
39 | error("No such cluster %s", cid); | 31 | error("No such cluster %s", cid); |
40 | } else { | 32 | } else { |
41 | List<DeviceId> ids = Lists.newArrayList(service.getClusterDevices(topology, cluster)); | 33 | List<DeviceId> ids = Lists.newArrayList(service.getClusterDevices(topology, cluster)); |
42 | - Collections.sort(ids, ID_COMPARATOR); | 34 | + Collections.sort(ids, Comparators.ELEMENT_ID_COMPARATOR); |
43 | for (DeviceId deviceId : ids) { | 35 | for (DeviceId deviceId : ids) { |
44 | print("%s", deviceId); | 36 | print("%s", deviceId); |
45 | } | 37 | } | ... | ... |
... | @@ -5,7 +5,6 @@ import org.apache.karaf.shell.commands.Command; | ... | @@ -5,7 +5,6 @@ import org.apache.karaf.shell.commands.Command; |
5 | import org.onlab.onos.net.topology.TopologyCluster; | 5 | import org.onlab.onos.net.topology.TopologyCluster; |
6 | 6 | ||
7 | import java.util.Collections; | 7 | import java.util.Collections; |
8 | -import java.util.Comparator; | ||
9 | import java.util.List; | 8 | import java.util.List; |
10 | 9 | ||
11 | /** | 10 | /** |
... | @@ -18,19 +17,11 @@ public class ClustersListCommand extends TopologyCommand { | ... | @@ -18,19 +17,11 @@ public class ClustersListCommand extends TopologyCommand { |
18 | private static final String FMT = | 17 | private static final String FMT = |
19 | "id=%d, devices=%d, links=%d"; | 18 | "id=%d, devices=%d, links=%d"; |
20 | 19 | ||
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 | 20 | @Override |
30 | protected void execute() { | 21 | protected void execute() { |
31 | init(); | 22 | init(); |
32 | List<TopologyCluster> clusters = Lists.newArrayList(service.getClusters(topology)); | 23 | List<TopologyCluster> clusters = Lists.newArrayList(service.getClusters(topology)); |
33 | - Collections.sort(clusters, ID_COMPARATOR); | 24 | + Collections.sort(clusters, Comparators.CLUSTER_COMPARATOR); |
34 | 25 | ||
35 | for (TopologyCluster cluster : clusters) { | 26 | for (TopologyCluster cluster : clusters) { |
36 | print(FMT, cluster.id().index(), cluster.deviceCount(), cluster.linkCount()); | 27 | print(FMT, cluster.id().index(), cluster.deviceCount(), cluster.linkCount()); | ... | ... |
1 | +package org.onlab.onos.cli.net; | ||
2 | + | ||
3 | +import org.onlab.onos.cluster.ControllerNode; | ||
4 | +import org.onlab.onos.net.Element; | ||
5 | +import org.onlab.onos.net.ElementId; | ||
6 | +import org.onlab.onos.net.Port; | ||
7 | +import org.onlab.onos.net.flow.FlowRule; | ||
8 | +import org.onlab.onos.net.topology.TopologyCluster; | ||
9 | + | ||
10 | +import java.util.Comparator; | ||
11 | + | ||
12 | +/** | ||
13 | + * Various comparators. | ||
14 | + */ | ||
15 | +public final class Comparators { | ||
16 | + | ||
17 | + // Ban construction | ||
18 | + private Comparators() { | ||
19 | + } | ||
20 | + | ||
21 | + public static final Comparator<ElementId> ELEMENT_ID_COMPARATOR = new Comparator<ElementId>() { | ||
22 | + @Override | ||
23 | + public int compare(ElementId id1, ElementId id2) { | ||
24 | + return id1.uri().toString().compareTo(id2.uri().toString()); | ||
25 | + } | ||
26 | + }; | ||
27 | + | ||
28 | + public static final Comparator<Element> ELEMENT_COMPARATOR = new Comparator<Element>() { | ||
29 | + @Override | ||
30 | + public int compare(Element e1, Element e2) { | ||
31 | + return e1.id().uri().toString().compareTo(e2.id().uri().toString()); | ||
32 | + } | ||
33 | + }; | ||
34 | + | ||
35 | + public static final Comparator<FlowRule> FLOW_RULE_COMPARATOR = new Comparator<FlowRule>() { | ||
36 | + @Override | ||
37 | + public int compare(FlowRule f1, FlowRule f2) { | ||
38 | + return Long.valueOf(f1.id().value()).compareTo(f2.id().value()); | ||
39 | + } | ||
40 | + }; | ||
41 | + | ||
42 | + public static final Comparator<Port> PORT_COMPARATOR = new Comparator<Port>() { | ||
43 | + @Override | ||
44 | + public int compare(Port p1, Port p2) { | ||
45 | + long delta = p1.number().toLong() - p2.number().toLong(); | ||
46 | + return delta == 0 ? 0 : (delta < 0 ? -1 : +1); | ||
47 | + } | ||
48 | + }; | ||
49 | + | ||
50 | + public static final Comparator<TopologyCluster> CLUSTER_COMPARATOR = new Comparator<TopologyCluster>() { | ||
51 | + @Override | ||
52 | + public int compare(TopologyCluster c1, TopologyCluster c2) { | ||
53 | + return c1.id().index() - c2.id().index(); | ||
54 | + } | ||
55 | + }; | ||
56 | + | ||
57 | + public static final Comparator<ControllerNode> NODE_COMPARATOR = new Comparator<ControllerNode>() { | ||
58 | + @Override | ||
59 | + public int compare(ControllerNode ci1, ControllerNode ci2) { | ||
60 | + return ci1.id().toString().compareTo(ci2.id().toString()); | ||
61 | + } | ||
62 | + }; | ||
63 | + | ||
64 | +} |
... | @@ -8,7 +8,6 @@ import org.onlab.onos.net.device.DeviceService; | ... | @@ -8,7 +8,6 @@ import org.onlab.onos.net.device.DeviceService; |
8 | 8 | ||
9 | import java.util.ArrayList; | 9 | import java.util.ArrayList; |
10 | import java.util.Collections; | 10 | import java.util.Collections; |
11 | -import java.util.Comparator; | ||
12 | import java.util.List; | 11 | import java.util.List; |
13 | 12 | ||
14 | import static org.onlab.onos.net.DeviceId.deviceId; | 13 | import static org.onlab.onos.net.DeviceId.deviceId; |
... | @@ -26,14 +25,6 @@ public class DevicePortsListCommand extends DevicesListCommand { | ... | @@ -26,14 +25,6 @@ public class DevicePortsListCommand extends DevicesListCommand { |
26 | required = false, multiValued = false) | 25 | required = false, multiValued = false) |
27 | String uri = null; | 26 | String uri = null; |
28 | 27 | ||
29 | - private static final Comparator<Port> PORT_COMPARATOR = new Comparator<Port>() { | ||
30 | - @Override | ||
31 | - public int compare(Port p1, Port p2) { | ||
32 | - long delta = p1.number().toLong() - p2.number().toLong(); | ||
33 | - return delta == 0 ? 0 : (delta < 0 ? -1 : +1); | ||
34 | - } | ||
35 | - }; | ||
36 | - | ||
37 | @Override | 28 | @Override |
38 | protected void execute() { | 29 | protected void execute() { |
39 | DeviceService service = get(DeviceService.class); | 30 | DeviceService service = get(DeviceService.class); |
... | @@ -55,7 +46,7 @@ public class DevicePortsListCommand extends DevicesListCommand { | ... | @@ -55,7 +46,7 @@ public class DevicePortsListCommand extends DevicesListCommand { |
55 | protected void printDevice(DeviceService service, Device device) { | 46 | protected void printDevice(DeviceService service, Device device) { |
56 | super.printDevice(service, device); | 47 | super.printDevice(service, device); |
57 | List<Port> ports = new ArrayList<>(service.getPorts(device.id())); | 48 | List<Port> ports = new ArrayList<>(service.getPorts(device.id())); |
58 | - Collections.sort(ports, PORT_COMPARATOR); | 49 | + Collections.sort(ports, Comparators.PORT_COMPARATOR); |
59 | for (Port port : ports) { | 50 | for (Port port : ports) { |
60 | print(FMT, port.number(), port.isEnabled() ? "enabled" : "disabled"); | 51 | print(FMT, port.number(), port.isEnabled() ? "enabled" : "disabled"); |
61 | } | 52 | } | ... | ... |
... | @@ -6,7 +6,6 @@ import org.onlab.onos.net.Device; | ... | @@ -6,7 +6,6 @@ import org.onlab.onos.net.Device; |
6 | import org.onlab.onos.net.device.DeviceService; | 6 | import org.onlab.onos.net.device.DeviceService; |
7 | 7 | ||
8 | import java.util.Collections; | 8 | import java.util.Collections; |
9 | -import java.util.Comparator; | ||
10 | import java.util.List; | 9 | import java.util.List; |
11 | 10 | ||
12 | import static com.google.common.collect.Lists.newArrayList; | 11 | import static com.google.common.collect.Lists.newArrayList; |
... | @@ -21,13 +20,6 @@ public class DevicesListCommand extends AbstractShellCommand { | ... | @@ -21,13 +20,6 @@ public class DevicesListCommand extends AbstractShellCommand { |
21 | private static final String FMT = | 20 | private static final String FMT = |
22 | "id=%s, available=%s, role=%s, type=%s, mfr=%s, hw=%s, sw=%s, serial=%s"; | 21 | "id=%s, available=%s, role=%s, type=%s, mfr=%s, hw=%s, sw=%s, serial=%s"; |
23 | 22 | ||
24 | - protected static final Comparator<Device> ID_COMPARATOR = new Comparator<Device>() { | ||
25 | - @Override | ||
26 | - public int compare(Device d1, Device d2) { | ||
27 | - return d1.id().uri().toString().compareTo(d2.id().uri().toString()); | ||
28 | - } | ||
29 | - }; | ||
30 | - | ||
31 | @Override | 23 | @Override |
32 | protected void execute() { | 24 | protected void execute() { |
33 | DeviceService service = get(DeviceService.class); | 25 | DeviceService service = get(DeviceService.class); |
... | @@ -44,7 +36,7 @@ public class DevicesListCommand extends AbstractShellCommand { | ... | @@ -44,7 +36,7 @@ public class DevicesListCommand extends AbstractShellCommand { |
44 | */ | 36 | */ |
45 | protected List<Device> getSortedDevices(DeviceService service) { | 37 | protected List<Device> getSortedDevices(DeviceService service) { |
46 | List<Device> devices = newArrayList(service.getDevices()); | 38 | List<Device> devices = newArrayList(service.getDevices()); |
47 | - Collections.sort(devices, ID_COMPARATOR); | 39 | + Collections.sort(devices, Comparators.ELEMENT_COMPARATOR); |
48 | return devices; | 40 | return devices; |
49 | } | 41 | } |
50 | 42 | ... | ... |
1 | package org.onlab.onos.cli.net; | 1 | package org.onlab.onos.cli.net; |
2 | 2 | ||
3 | -import static com.google.common.collect.Lists.newArrayList; | 3 | +import com.google.common.collect.Maps; |
4 | - | ||
5 | -import java.util.Collections; | ||
6 | -import java.util.Comparator; | ||
7 | -import java.util.List; | ||
8 | -import java.util.Map; | ||
9 | - | ||
10 | import org.apache.karaf.shell.commands.Command; | 4 | import org.apache.karaf.shell.commands.Command; |
11 | import org.onlab.onos.cli.AbstractShellCommand; | 5 | import org.onlab.onos.cli.AbstractShellCommand; |
12 | import org.onlab.onos.net.Device; | 6 | import org.onlab.onos.net.Device; |
... | @@ -14,7 +8,11 @@ import org.onlab.onos.net.device.DeviceService; | ... | @@ -14,7 +8,11 @@ import org.onlab.onos.net.device.DeviceService; |
14 | import org.onlab.onos.net.flow.FlowRule; | 8 | import org.onlab.onos.net.flow.FlowRule; |
15 | import org.onlab.onos.net.flow.FlowRuleService; | 9 | import org.onlab.onos.net.flow.FlowRuleService; |
16 | 10 | ||
17 | -import com.google.common.collect.Maps; | 11 | +import java.util.Collections; |
12 | +import java.util.List; | ||
13 | +import java.util.Map; | ||
14 | + | ||
15 | +import static com.google.common.collect.Lists.newArrayList; | ||
18 | 16 | ||
19 | /** | 17 | /** |
20 | * Lists all currently-known hosts. | 18 | * Lists all currently-known hosts. |
... | @@ -26,13 +24,6 @@ public class FlowsListCommand extends AbstractShellCommand { | ... | @@ -26,13 +24,6 @@ public class FlowsListCommand extends AbstractShellCommand { |
26 | private static final String FMT = | 24 | private static final String FMT = |
27 | " id=%s, selector=%s, treatment=%s, state=%s"; | 25 | " id=%s, selector=%s, treatment=%s, state=%s"; |
28 | 26 | ||
29 | - protected static final Comparator<FlowRule> ID_COMPARATOR = new Comparator<FlowRule>() { | ||
30 | - @Override | ||
31 | - public int compare(FlowRule f1, FlowRule f2) { | ||
32 | - return Long.valueOf(f1.id().value()).compareTo(f2.id().value()); | ||
33 | - } | ||
34 | - }; | ||
35 | - | ||
36 | @Override | 27 | @Override |
37 | protected void execute() { | 28 | protected void execute() { |
38 | DeviceService deviceService = get(DeviceService.class); | 29 | DeviceService deviceService = get(DeviceService.class); |
... | @@ -43,7 +34,6 @@ public class FlowsListCommand extends AbstractShellCommand { | ... | @@ -43,7 +34,6 @@ public class FlowsListCommand extends AbstractShellCommand { |
43 | } | 34 | } |
44 | } | 35 | } |
45 | 36 | ||
46 | - | ||
47 | /** | 37 | /** |
48 | * Returns the list of devices sorted using the device ID URIs. | 38 | * Returns the list of devices sorted using the device ID URIs. |
49 | * | 39 | * |
... | @@ -55,7 +45,7 @@ public class FlowsListCommand extends AbstractShellCommand { | ... | @@ -55,7 +45,7 @@ public class FlowsListCommand extends AbstractShellCommand { |
55 | List<FlowRule> rules; | 45 | List<FlowRule> rules; |
56 | for (Device d : deviceService.getDevices()) { | 46 | for (Device d : deviceService.getDevices()) { |
57 | rules = newArrayList(service.getFlowEntries(d.id())); | 47 | rules = newArrayList(service.getFlowEntries(d.id())); |
58 | - Collections.sort(rules, ID_COMPARATOR); | 48 | + Collections.sort(rules, Comparators.FLOW_RULE_COMPARATOR); |
59 | flows.put(d, rules); | 49 | flows.put(d, rules); |
60 | } | 50 | } |
61 | return flows; | 51 | return flows; | ... | ... |
1 | package org.onlab.onos.cli.net; | 1 | package org.onlab.onos.cli.net; |
2 | 2 | ||
3 | -import java.util.Iterator; | ||
4 | -import java.util.List; | ||
5 | -import java.util.SortedSet; | ||
6 | - | ||
7 | import org.apache.karaf.shell.console.Completer; | 3 | import org.apache.karaf.shell.console.Completer; |
8 | import org.apache.karaf.shell.console.completer.StringsCompleter; | 4 | import org.apache.karaf.shell.console.completer.StringsCompleter; |
9 | import org.onlab.onos.cli.AbstractShellCommand; | 5 | import org.onlab.onos.cli.AbstractShellCommand; |
10 | import org.onlab.onos.net.Host; | 6 | import org.onlab.onos.net.Host; |
11 | import org.onlab.onos.net.host.HostService; | 7 | import org.onlab.onos.net.host.HostService; |
12 | 8 | ||
9 | +import java.util.Iterator; | ||
10 | +import java.util.List; | ||
11 | +import java.util.SortedSet; | ||
12 | + | ||
13 | public class HostIdCompleter implements Completer { | 13 | public class HostIdCompleter implements Completer { |
14 | 14 | ||
15 | @Override | 15 | @Override | ... | ... |
1 | package org.onlab.onos.cli.net; | 1 | package org.onlab.onos.cli.net; |
2 | 2 | ||
3 | -import static com.google.common.collect.Lists.newArrayList; | ||
4 | - | ||
5 | -import java.util.Collections; | ||
6 | -import java.util.Comparator; | ||
7 | -import java.util.List; | ||
8 | - | ||
9 | import org.apache.karaf.shell.commands.Command; | 3 | import org.apache.karaf.shell.commands.Command; |
10 | import org.onlab.onos.cli.AbstractShellCommand; | 4 | import org.onlab.onos.cli.AbstractShellCommand; |
11 | import org.onlab.onos.net.Host; | 5 | import org.onlab.onos.net.Host; |
12 | import org.onlab.onos.net.host.HostService; | 6 | import org.onlab.onos.net.host.HostService; |
13 | 7 | ||
8 | +import java.util.Collections; | ||
9 | +import java.util.List; | ||
10 | + | ||
11 | +import static com.google.common.collect.Lists.newArrayList; | ||
12 | + | ||
14 | /** | 13 | /** |
15 | * Lists all currently-known hosts. | 14 | * Lists all currently-known hosts. |
16 | */ | 15 | */ |
... | @@ -21,13 +20,6 @@ public class HostsListCommand extends AbstractShellCommand { | ... | @@ -21,13 +20,6 @@ public class HostsListCommand extends AbstractShellCommand { |
21 | private static final String FMT = | 20 | private static final String FMT = |
22 | "id=%s, mac=%s, location=%s/%s, vlan=%s, ip(s)=%s"; | 21 | "id=%s, mac=%s, location=%s/%s, vlan=%s, ip(s)=%s"; |
23 | 22 | ||
24 | - protected static final Comparator<Host> ID_COMPARATOR = new Comparator<Host>() { | ||
25 | - @Override | ||
26 | - public int compare(Host h1, Host h2) { | ||
27 | - return h1.id().uri().toString().compareTo(h2.id().uri().toString()); | ||
28 | - } | ||
29 | - }; | ||
30 | - | ||
31 | @Override | 23 | @Override |
32 | protected void execute() { | 24 | protected void execute() { |
33 | HostService service = get(HostService.class); | 25 | HostService service = get(HostService.class); |
... | @@ -44,7 +36,7 @@ public class HostsListCommand extends AbstractShellCommand { | ... | @@ -44,7 +36,7 @@ public class HostsListCommand extends AbstractShellCommand { |
44 | */ | 36 | */ |
45 | protected List<Host> getSortedHosts(HostService service) { | 37 | protected List<Host> getSortedHosts(HostService service) { |
46 | List<Host> hosts = newArrayList(service.getHosts()); | 38 | List<Host> hosts = newArrayList(service.getHosts()); |
47 | - Collections.sort(hosts, ID_COMPARATOR); | 39 | + Collections.sort(hosts, Comparators.ELEMENT_COMPARATOR); |
48 | return hosts; | 40 | return hosts; |
49 | } | 41 | } |
50 | 42 | ... | ... |
... | @@ -41,7 +41,6 @@ public class LinksListCommand extends AbstractShellCommand { | ... | @@ -41,7 +41,6 @@ public class LinksListCommand extends AbstractShellCommand { |
41 | public static String linkString(Link link) { | 41 | public static String linkString(Link link) { |
42 | return String.format(FMT, link.src().deviceId(), link.src().port(), | 42 | return String.format(FMT, link.src().deviceId(), link.src().port(), |
43 | link.dst().deviceId(), link.dst().port(), link.type()); | 43 | link.dst().deviceId(), link.dst().port(), link.type()); |
44 | - | ||
45 | } | 44 | } |
46 | 45 | ||
47 | /** | 46 | /** | ... | ... |
... | @@ -5,8 +5,12 @@ | ... | @@ -5,8 +5,12 @@ |
5 | <action class="org.onlab.onos.cli.NodesListCommand"/> | 5 | <action class="org.onlab.onos.cli.NodesListCommand"/> |
6 | </command> | 6 | </command> |
7 | <command> | 7 | <command> |
8 | - <action class="org.onlab.onos.cli.net.FlowsListCommand"/> | 8 | + <action class="org.onlab.onos.cli.MastersListCommand"/> |
9 | + <completers> | ||
10 | + <ref component-id="clusterIdCompleter"/> | ||
11 | + </completers> | ||
9 | </command> | 12 | </command> |
13 | + | ||
10 | <command> | 14 | <command> |
11 | <action class="org.onlab.onos.cli.net.DevicesListCommand"/> | 15 | <action class="org.onlab.onos.cli.net.DevicesListCommand"/> |
12 | </command> | 16 | </command> |
... | @@ -67,10 +71,15 @@ | ... | @@ -67,10 +71,15 @@ |
67 | </command> | 71 | </command> |
68 | 72 | ||
69 | <command> | 73 | <command> |
74 | + <action class="org.onlab.onos.cli.net.FlowsListCommand"/> | ||
75 | + </command> | ||
76 | + | ||
77 | + <command> | ||
70 | <action class="org.onlab.onos.cli.net.WipeOutCommand"/> | 78 | <action class="org.onlab.onos.cli.net.WipeOutCommand"/> |
71 | </command> | 79 | </command> |
72 | </command-bundle> | 80 | </command-bundle> |
73 | 81 | ||
82 | + <bean id="nodeIdCompleter" class="org.onlab.onos.cli.NodeIdCompleter"/> | ||
74 | <bean id="deviceIdCompleter" class="org.onlab.onos.cli.net.DeviceIdCompleter"/> | 83 | <bean id="deviceIdCompleter" class="org.onlab.onos.cli.net.DeviceIdCompleter"/> |
75 | <bean id="clusterIdCompleter" class="org.onlab.onos.cli.net.ClusterIdCompleter"/> | 84 | <bean id="clusterIdCompleter" class="org.onlab.onos.cli.net.ClusterIdCompleter"/> |
76 | <bean id="roleCompleter" class="org.onlab.onos.cli.net.RoleCompleter"/> | 85 | <bean id="roleCompleter" class="org.onlab.onos.cli.net.RoleCompleter"/> | ... | ... |
-
Please register or login to post a comment