Added onos-test.
Refactored the CLI classes.
diff --git a/cli/src/main/java/org/onlab/onos/cli/AbstractShellCommand.java b/cli/src/main/java/org/onlab/onos/cli/AbstractShellCommand.java
index 8c41b7f..184a7e6 100644
--- a/cli/src/main/java/org/onlab/onos/cli/AbstractShellCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/AbstractShellCommand.java
@@ -15,6 +15,7 @@
* @param serviceClass service class
* @param <T> type of service
* @return service implementation
+ * @throws org.onlab.osgi.ServiceNotFoundException if service is unavailable
*/
public static <T> T get(Class<T> serviceClass) {
return DefaultServiceDirectory.getService(serviceClass);
@@ -26,7 +27,7 @@
* @param format format string; see {@link String#format}
* @param args arguments
*/
- public static void print(String format, Object... args) {
+ public void print(String format, Object... args) {
System.out.println(String.format(format, args));
}
@@ -36,7 +37,7 @@
* @param format format string; see {@link String#format}
* @param args arguments
*/
- public static void error(String format, Object... args) {
+ public void error(String format, Object... args) {
System.err.println(String.format(format, args));
}
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/DevicePortsListCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/DevicePortsListCommand.java
index 9d68fb8..e62fe56 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/DevicePortsListCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/DevicePortsListCommand.java
@@ -36,7 +36,7 @@
@Override
protected void execute() {
- DeviceService service = getService(DeviceService.class);
+ DeviceService service = get(DeviceService.class);
if (uri == null) {
for (Device device : getSortedDevices(service)) {
printDevice(service, device);
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/DeviceRemoveCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/DeviceRemoveCommand.java
index 7cc55e6..564d1ea 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/DeviceRemoveCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/DeviceRemoveCommand.java
@@ -19,7 +19,7 @@
@Override
protected void execute() {
- getService(DeviceAdminService.class).removeDevice(DeviceId.deviceId(uri));
+ get(DeviceAdminService.class).removeDevice(DeviceId.deviceId(uri));
}
}
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/DeviceRoleCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/DeviceRoleCommand.java
index ddccdaf..60a203a 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/DeviceRoleCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/DeviceRoleCommand.java
@@ -25,7 +25,7 @@
@Override
protected void execute() {
MastershipRole mastershipRole = MastershipRole.valueOf(role.toUpperCase());
- getService(DeviceAdminService.class).setRole(DeviceId.deviceId(uri),
+ get(DeviceAdminService.class).setRole(DeviceId.deviceId(uri),
mastershipRole);
}
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/DevicesListCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/DevicesListCommand.java
index 357d005..be102f2 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/DevicesListCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/DevicesListCommand.java
@@ -30,7 +30,7 @@
@Override
protected void execute() {
- DeviceService service = getService(DeviceService.class);
+ DeviceService service = get(DeviceService.class);
for (Device device : getSortedDevices(service)) {
printDevice(service, device);
}
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/FlowsListCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/FlowsListCommand.java
index 9e21642..c2ca416 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/FlowsListCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/FlowsListCommand.java
@@ -35,8 +35,8 @@
@Override
protected void execute() {
- DeviceService deviceService = getService(DeviceService.class);
- FlowRuleService service = getService(FlowRuleService.class);
+ DeviceService deviceService = get(DeviceService.class);
+ FlowRuleService service = get(FlowRuleService.class);
Map<Device, List<FlowRule>> flows = getSortedFlows(deviceService, service);
for (Device d : deviceService.getDevices()) {
printFlows(d, flows.get(d));
diff --git a/cli/src/main/java/org/onlab/onos/cli/net/HostsListCommand.java b/cli/src/main/java/org/onlab/onos/cli/net/HostsListCommand.java
index c45470c..29919a8 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/HostsListCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/HostsListCommand.java
@@ -30,7 +30,7 @@
@Override
protected void execute() {
- HostService service = getService(HostService.class);
+ HostService service = get(HostService.class);
for (Host host : getSortedHosts(service)) {
printHost(host);
}
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 2519bdd..4361bd7 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
@@ -24,7 +24,7 @@
@Override
protected void execute() {
- LinkService service = getService(LinkService.class);
+ LinkService service = get(LinkService.class);
Iterable<Link> links = uri != null ?
service.getDeviceLinks(deviceId(uri)) : service.getLinks();
for (Link link : links) {
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
index a258205..5c8310f 100644
--- a/cli/src/main/java/org/onlab/onos/cli/net/TopologyCommand.java
+++ b/cli/src/main/java/org/onlab/onos/cli/net/TopologyCommand.java
@@ -23,7 +23,7 @@
* Initializes the context for all cluster commands.
*/
protected void init() {
- service = getService(TopologyService.class);
+ service = get(TopologyService.class);
topology = service.currentTopology();
}
diff --git a/tools/dev/bash_profile b/tools/dev/bash_profile
index 94bb578..328f5f4 100644
--- a/tools/dev/bash_profile
+++ b/tools/dev/bash_profile
@@ -30,6 +30,7 @@
# Short-hand for ONOS build from the top of the source tree.
alias ob='o && mvn clean install javadoc:aggregate'
+alias ot='onos-test'
# Short-hand for tailing the ONOS (karaf) log
alias tl='$ONOS_ROOT/tools/dev/watchLog'
diff --git a/tools/test/bin/onos-config b/tools/test/bin/onos-config
index dd03e2d..e9f3f0a 100755
--- a/tools/test/bin/onos-config
+++ b/tools/test/bin/onos-config
@@ -8,25 +8,4 @@
remote=$ONOS_USER@${1:-$OCI}
-LOG=$ONOS_INSTALL_DIR/config.log
-onos=$ONOS_INSTALL_DIR/bin/onos
-
-ssh $remote "
- # Wait until we reach the run-level 100
- echo 'Waiting for cluster bootstrap...'
- running=""
- while [ -z \$running ]; do
- $onos bundle:list 2>>$LOG | grep -q 'START LEVEL 100' && running=1 || sleep 2
- done
-
- echo 'Installing ONOS bundles...'
- $onos cluster:feature-install default onos-api 1>>$LOG 2>&1
- # $onos cluster:feature-install default onos-core 1>>$LOG 2>&1
- $onos cluster:feature-install default onos-core-trivial 1>>$LOG 2>&1
- $onos cluster:feature-install default onos-openflow 1>>$LOG 2>&1
- $onos cluster:feature-install default onos-cli 1>>$LOG 2>&1
- # $onos cluster:feature-install default onos-gui 1>>$LOG 2>&1
- # $onos cluster:feature-install default onos-rest 1>>$LOG 2>&1
- $onos cluster:feature-install default onos-app-tvue 1>>$LOG 2>&1
- $onos cluster:feature-install default onos-app-fwd 1>>$LOG 2>&1
-"
+echo "Deprecated!"
\ No newline at end of file
diff --git a/tools/test/bin/onos-log b/tools/test/bin/onos-log
index 698cc2f..1a205f4 100755
--- a/tools/test/bin/onos-log
+++ b/tools/test/bin/onos-log
@@ -14,6 +14,7 @@
ssh $remote "
while true; do
+ echo ==================================================================
[ ! -f $LOG ] && sleep 2 && continue
tail -n 512 --follow=name $LOG --sleep-interval 2
done
diff --git a/tools/test/bin/onos-test b/tools/test/bin/onos-test
new file mode 100755
index 0000000..d549721
--- /dev/null
+++ b/tools/test/bin/onos-test
@@ -0,0 +1,13 @@
+#!/bin/bash
+#-------------------------------------------------------------------------------
+# Launches the ONOS tests on the current cell environment.
+#-------------------------------------------------------------------------------
+
+[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
+. $ONOS_ROOT/tools/build/envDefaults
+
+nodes=$(env | sort | egrep "OC[0-9]+" | cut -d= -f2)
+
+onos-package
+for node in $nodes; do onos-install -f $node; done
+for node in $nodes; do onos-wait-for-start $node; done
diff --git a/utils/osgi/src/main/java/org/onlab/osgi/DefaultServiceDirectory.java b/utils/osgi/src/main/java/org/onlab/osgi/DefaultServiceDirectory.java
index d483991..bc401fb 100644
--- a/utils/osgi/src/main/java/org/onlab/osgi/DefaultServiceDirectory.java
+++ b/utils/osgi/src/main/java/org/onlab/osgi/DefaultServiceDirectory.java
@@ -2,6 +2,7 @@
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
/**
* Default implementation of the service directory using OSGi framework utilities.
@@ -17,11 +18,16 @@
*/
public static <T> T getService(Class<T> serviceClass) {
BundleContext bc = FrameworkUtil.getBundle(serviceClass).getBundleContext();
- T impl = bc.getService(bc.getServiceReference(serviceClass));
- if (impl == null) {
- throw new ServiceNotFoundException("Service " + serviceClass.getName() + " not found");
+ if (bc != null) {
+ ServiceReference<T> reference = bc.getServiceReference(serviceClass);
+ if (reference != null) {
+ T impl = bc.getService(reference);
+ if (impl != null) {
+ return impl;
+ }
+ }
}
- return impl;
+ throw new ServiceNotFoundException("Service " + serviceClass.getName() + " not found");
}
@Override