Consolidating null providers and making them fully configurable and integrated with the ConfigProvider to allow arbitrary topologies.
Change-Id: I899e27a9771af4013a3ce6da7f683a4927ffb438
diff --git a/cli/src/main/java/org/onosproject/cli/AbstractChoicesCompleter.java b/cli/src/main/java/org/onosproject/cli/AbstractChoicesCompleter.java
new file mode 100644
index 0000000..b846fde
--- /dev/null
+++ b/cli/src/main/java/org/onosproject/cli/AbstractChoicesCompleter.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.cli;
+
+import org.apache.karaf.shell.console.completer.StringsCompleter;
+
+import java.util.List;
+import java.util.SortedSet;
+
+/**
+ * Abstraction of a completer with preset choices.
+ */
+public abstract class AbstractChoicesCompleter extends AbstractCompleter {
+
+ protected abstract List<String> choices();
+
+ @Override
+ public int complete(String buffer, int cursor, List<String> candidates) {
+ StringsCompleter delegate = new StringsCompleter();
+ SortedSet<String> strings = delegate.getStrings();
+ choices().forEach(strings::add);
+ return delegate.complete(buffer, cursor, candidates);
+ }
+
+}
diff --git a/cli/src/main/java/org/onosproject/cli/net/AbstractCompleter.java b/cli/src/main/java/org/onosproject/cli/AbstractCompleter.java
similarity index 97%
rename from cli/src/main/java/org/onosproject/cli/net/AbstractCompleter.java
rename to cli/src/main/java/org/onosproject/cli/AbstractCompleter.java
index 36c0a04..f232596 100644
--- a/cli/src/main/java/org/onosproject/cli/net/AbstractCompleter.java
+++ b/cli/src/main/java/org/onosproject/cli/AbstractCompleter.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.onosproject.cli.net;
+package org.onosproject.cli;
import org.apache.felix.service.command.CommandSession;
import org.apache.karaf.shell.console.CommandSessionHolder;
diff --git a/cli/src/main/java/org/onosproject/cli/StartStopCompleter.java b/cli/src/main/java/org/onosproject/cli/StartStopCompleter.java
new file mode 100644
index 0000000..b9d9b0f
--- /dev/null
+++ b/cli/src/main/java/org/onosproject/cli/StartStopCompleter.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.cli;
+
+import com.google.common.collect.ImmutableList;
+
+import java.util.List;
+
+/**
+ * Start/stop command completer.
+ */
+public class StartStopCompleter extends AbstractChoicesCompleter {
+
+ public static final String START = "start";
+ public static final String STOP = "stop";
+
+ @Override
+ public List<String> choices() {
+ return ImmutableList.of(START, STOP);
+ }
+}
diff --git a/cli/src/main/java/org/onosproject/cli/UpDownCompleter.java b/cli/src/main/java/org/onosproject/cli/UpDownCompleter.java
new file mode 100644
index 0000000..9d8eda5
--- /dev/null
+++ b/cli/src/main/java/org/onosproject/cli/UpDownCompleter.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.cli;
+
+import com.google.common.collect.ImmutableList;
+
+import java.util.List;
+
+/**
+ * Up/down command completer.
+ */
+public class UpDownCompleter extends AbstractChoicesCompleter {
+
+ public static final String UP = "up";
+ public static final String DOWN = "down";
+
+ @Override
+ public List<String> choices() {
+ return ImmutableList.of(UP, DOWN);
+ }
+}
diff --git a/cli/src/main/java/org/onosproject/cli/app/ApplicationCommandCompleter.java b/cli/src/main/java/org/onosproject/cli/app/ApplicationCommandCompleter.java
index b9ea774..51611ff 100644
--- a/cli/src/main/java/org/onosproject/cli/app/ApplicationCommandCompleter.java
+++ b/cli/src/main/java/org/onosproject/cli/app/ApplicationCommandCompleter.java
@@ -15,30 +15,20 @@
*/
package org.onosproject.cli.app;
-import org.apache.karaf.shell.console.Completer;
-import org.apache.karaf.shell.console.completer.StringsCompleter;
+import com.google.common.collect.ImmutableList;
+import org.onosproject.cli.AbstractChoicesCompleter;
import java.util.List;
-import java.util.SortedSet;
import static org.onosproject.cli.app.ApplicationCommand.*;
/**
- * Application name completer.
+ * Application command completer.
*/
-public class ApplicationCommandCompleter implements Completer {
+public class ApplicationCommandCompleter extends AbstractChoicesCompleter {
@Override
- public int complete(String buffer, int cursor, List<String> candidates) {
- // Delegate string completer
- StringsCompleter delegate = new StringsCompleter();
- SortedSet<String> strings = delegate.getStrings();
- strings.add(INSTALL);
- strings.add(UNINSTALL);
- strings.add(ACTIVATE);
- strings.add(DEACTIVATE);
-
- // Now let the completer do the work for figuring out what to offer.
- return delegate.complete(buffer, cursor, candidates);
+ public List<String> choices() {
+ return ImmutableList.of(INSTALL, UNINSTALL, ACTIVATE, DEACTIVATE);
}
}
diff --git a/cli/src/main/java/org/onosproject/cli/app/ApplicationNameCompleter.java b/cli/src/main/java/org/onosproject/cli/app/ApplicationNameCompleter.java
index e975be0..9342721 100644
--- a/cli/src/main/java/org/onosproject/cli/app/ApplicationNameCompleter.java
+++ b/cli/src/main/java/org/onosproject/cli/app/ApplicationNameCompleter.java
@@ -19,7 +19,7 @@
import org.apache.karaf.shell.console.completer.StringsCompleter;
import org.onosproject.app.ApplicationService;
import org.onosproject.app.ApplicationState;
-import org.onosproject.cli.net.AbstractCompleter;
+import org.onosproject.cli.AbstractCompleter;
import org.onosproject.core.Application;
import java.util.Iterator;
diff --git a/cli/src/main/java/org/onosproject/cli/cfg/ComponentPropertyNameCompleter.java b/cli/src/main/java/org/onosproject/cli/cfg/ComponentPropertyNameCompleter.java
index 4c6e5e9..98e1969 100644
--- a/cli/src/main/java/org/onosproject/cli/cfg/ComponentPropertyNameCompleter.java
+++ b/cli/src/main/java/org/onosproject/cli/cfg/ComponentPropertyNameCompleter.java
@@ -19,7 +19,7 @@
import org.apache.karaf.shell.console.completer.StringsCompleter;
import org.onosproject.cfg.ComponentConfigService;
import org.onosproject.cfg.ConfigProperty;
-import org.onosproject.cli.net.AbstractCompleter;
+import org.onosproject.cli.AbstractCompleter;
import java.util.List;
import java.util.Set;
diff --git a/cli/src/main/java/org/onosproject/cli/net/LinkDstCompleter.java b/cli/src/main/java/org/onosproject/cli/net/LinkDstCompleter.java
new file mode 100644
index 0000000..fbf116f
--- /dev/null
+++ b/cli/src/main/java/org/onosproject/cli/net/LinkDstCompleter.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.cli.net;
+
+import org.apache.karaf.shell.console.completer.ArgumentCompleter;
+import org.apache.karaf.shell.console.completer.StringsCompleter;
+import org.onosproject.cli.AbstractCompleter;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.link.LinkService;
+
+import java.util.List;
+import java.util.SortedSet;
+
+import static org.onosproject.cli.net.AddPointToPointIntentCommand.getDeviceId;
+import static org.onosproject.cli.net.AddPointToPointIntentCommand.getPortNumber;
+import static org.onosproject.net.DeviceId.deviceId;
+import static org.onosproject.net.PortNumber.portNumber;
+
+/**
+ * Link end-point completer.
+ */
+public class LinkDstCompleter extends AbstractCompleter {
+ @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
+ LinkService service = AbstractShellCommand.get(LinkService.class);
+
+ // Link source the previous argument.
+ ArgumentCompleter.ArgumentList list = getArgumentList();
+ String srcArg = list.getArguments()[list.getCursorArgumentIndex() - 1];
+
+ // Generate the device ID/port number identifiers
+ SortedSet<String> strings = delegate.getStrings();
+ try {
+ ConnectPoint src = new ConnectPoint(deviceId(getDeviceId(srcArg)),
+ portNumber(getPortNumber(srcArg)));
+ service.getEgressLinks(src)
+ .forEach(link -> strings.add(link.dst().elementId().toString() +
+ "/" + link.dst().port()));
+ } catch (NumberFormatException e) {
+ System.err.println("Invalid connect-point");
+ }
+
+ // 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/onosproject/cli/net/LinkSrcCompleter.java b/cli/src/main/java/org/onosproject/cli/net/LinkSrcCompleter.java
new file mode 100644
index 0000000..dec8c6b
--- /dev/null
+++ b/cli/src/main/java/org/onosproject/cli/net/LinkSrcCompleter.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.cli.net;
+
+import org.apache.karaf.shell.console.completer.StringsCompleter;
+import org.onosproject.cli.AbstractCompleter;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.net.link.LinkService;
+
+import java.util.List;
+import java.util.SortedSet;
+
+/**
+ * Link end-point completer.
+ */
+public class LinkSrcCompleter extends AbstractCompleter {
+ @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
+ LinkService service = AbstractShellCommand.get(LinkService.class);
+
+ // Generate the device ID/port number identifiers
+ SortedSet<String> strings = delegate.getStrings();
+ service.getLinks()
+ .forEach(link -> strings.add(link.src().elementId().toString() +
+ "/" + link.src().port()));
+
+ // Now let the completer do the work for figuring out what to offer.
+ return delegate.complete(buffer, cursor, candidates);
+ }
+
+}