Merge branch 'master' of ssh://gerrit.onlab.us:29418/onos-next
diff --git a/apps/foo/pom.xml b/apps/foo/pom.xml
index 868b992..1a62f73 100644
--- a/apps/foo/pom.xml
+++ b/apps/foo/pom.xml
@@ -28,6 +28,11 @@
             <version>${project.version}</version>
         </dependency>
         <dependency>
+            <groupId>org.onlab.onos</groupId>
+            <artifactId>onlab-netty</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
             <groupId>org.apache.karaf.shell</groupId>
             <artifactId>org.apache.karaf.shell.console</artifactId>
         </dependency>
diff --git a/apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyClient.java b/apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyClient.java
new file mode 100644
index 0000000..8f94ec1
--- /dev/null
+++ b/apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyClient.java
@@ -0,0 +1,67 @@
+package org.onlab.onos.foo;
+
+import java.io.IOException;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import org.onlab.metrics.MetricsComponent;
+import org.onlab.metrics.MetricsFeature;
+import org.onlab.metrics.MetricsManager;
+import org.onlab.netty.Endpoint;
+import org.onlab.netty.NettyMessagingService;
+import org.onlab.netty.Response;
+
+import com.codahale.metrics.Timer;
+
+// FIXME: Should be move out to test or app
+public final class SimpleNettyClient {
+    private SimpleNettyClient() {
+    }
+
+    public static void main(String[] args)
+            throws IOException, InterruptedException, ExecutionException,
+            TimeoutException {
+        try {
+            startStandalone(args);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        System.exit(0);
+    }
+    public static void startStandalone(String... args) throws Exception {
+        NettyMessagingService messaging = new TestNettyMessagingService(9081);
+        MetricsManager metrics = new MetricsManager();
+        messaging.activate();
+        metrics.activate();
+        MetricsFeature feature = new MetricsFeature("timers");
+        MetricsComponent component = metrics.registerComponent("NettyMessaging");
+        Timer sendAsyncTimer = metrics.createTimer(component, feature, "AsyncSender");
+        final int warmup = 100;
+        for (int i = 0; i < warmup; i++) {
+            Timer.Context context = sendAsyncTimer.time();
+            messaging.sendAsync(new Endpoint("localhost", 8080), "simple", "Hello World".getBytes());
+            context.stop();
+        }
+        metrics.registerMetric(component, feature, "AsyncTimer", sendAsyncTimer);
+
+        Timer sendAndReceiveTimer = metrics.createTimer(component, feature, "SendAndReceive");
+        final int iterations = 1000000;
+        for (int i = 0; i < iterations; i++) {
+            Timer.Context context = sendAndReceiveTimer.time();
+            Response response = messaging
+                    .sendAndReceive(new Endpoint("localhost", 8080), "echo",
+                                    "Hello World".getBytes());
+            System.out.println("Got back:" + new String(response.get(2, TimeUnit.SECONDS)));
+            context.stop();
+        }
+        metrics.registerMetric(component, feature, "AsyncTimer", sendAndReceiveTimer);
+    }
+
+    public static class TestNettyMessagingService extends NettyMessagingService {
+        public TestNettyMessagingService(int port) throws Exception {
+            super(port);
+        }
+    }
+}
diff --git a/apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyClientCommand.java b/apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyClientCommand.java
new file mode 100644
index 0000000..8a603e9
--- /dev/null
+++ b/apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyClientCommand.java
@@ -0,0 +1,45 @@
+package org.onlab.onos.foo;
+
+import static org.onlab.onos.foo.SimpleNettyClient.startStandalone;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.onlab.onos.cli.AbstractShellCommand;
+
+/**
+ * Test Netty client performance.
+ */
+@Command(scope = "onos", name = "simple-netty-client",
+        description = "Starts the simple Netty client")
+public class SimpleNettyClientCommand extends AbstractShellCommand {
+
+    @Argument(index = 0, name = "serverIp", description = "Server IP address",
+            required = false, multiValued = false)
+    String serverIp = "127.0.0.1";
+
+    @Argument(index = 1, name = "workers", description = "IO workers",
+            required = false, multiValued = false)
+    String workers = "6";
+
+    @Argument(index = 2, name = "messageCount", description = "Message count",
+            required = false, multiValued = false)
+    String messageCount = "1000000";
+
+    @Argument(index = 3, name = "messageLength", description = "Message length (bytes)",
+            required = false, multiValued = false)
+    String messageLength = "128";
+
+    @Argument(index = 4, name = "timeoutSecs", description = "Test timeout (seconds)",
+            required = false, multiValued = false)
+    String timeoutSecs = "60";
+
+    @Override
+    protected void execute() {
+        try {
+            startStandalone(new String[]{serverIp, workers, messageCount, messageLength, timeoutSecs});
+        } catch (Exception e) {
+            error("Unable to start client %s", e);
+        }
+    }
+
+}
diff --git a/apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyServer.java b/apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyServer.java
new file mode 100644
index 0000000..fe8e058
--- /dev/null
+++ b/apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyServer.java
@@ -0,0 +1,28 @@
+package org.onlab.onos.foo;
+
+import org.onlab.netty.EchoHandler;
+import org.onlab.netty.NettyMessagingService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Test to measure Messaging performance.
+ */
+    public class SimpleNettyServer {
+        private static Logger log = LoggerFactory.getLogger(IOLoopTestServer.class);
+
+            private SimpleNettyServer() {}
+
+            public static void main(String... args) throws Exception {
+                startStandalone(args);
+                System.exit(0);
+            }
+
+        public static void startStandalone(String[] args) throws Exception {
+            NettyMessagingService server = new NettyMessagingService(8080);
+            server.activate();
+            server.registerHandler("simple", new org.onlab.netty.LoggingHandler());
+            server.registerHandler("echo", new EchoHandler());
+        }
+    }
+
diff --git a/apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyServerCommand.java b/apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyServerCommand.java
new file mode 100644
index 0000000..2f82da0
--- /dev/null
+++ b/apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyServerCommand.java
@@ -0,0 +1,37 @@
+package org.onlab.onos.foo;
+
+import static org.onlab.onos.foo.SimpleNettyServer.startStandalone;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.onlab.onos.cli.AbstractShellCommand;
+
+/**
+ * Starts the Simple Netty server.
+ */
+@Command(scope = "onos", name = "test-netty-server",
+         description = "Starts the simple netty server")
+public class SimpleNettyServerCommand extends AbstractShellCommand {
+
+    @Argument(index = 0, name = "serverIp", description = "Server IP address",
+              required = false, multiValued = false)
+    String serverIp = "127.0.0.1";
+
+    @Argument(index = 1, name = "workers", description = "IO workers",
+              required = false, multiValued = false)
+    String workers = "6";
+
+    @Argument(index = 2, name = "messageLength", description = "Message length (bytes)",
+              required = false, multiValued = false)
+    String messageLength = "128";
+
+    @Override
+    protected void execute() {
+        try {
+            startStandalone(new String[]{serverIp, workers, messageLength});
+        } catch (Exception e) {
+            error("Unable to start server %s", e);
+        }
+    }
+
+}
diff --git a/pom.xml b/pom.xml
index 9d7edfe..ad4ddcb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -69,6 +69,13 @@
 
             <dependency>
                 <groupId>org.slf4j</groupId>
+                <artifactId>slf4j-core</artifactId>
+                <version>1.7.6</version>
+                <scope>test</scope>
+            </dependency>
+
+            <dependency>
+                <groupId>org.slf4j</groupId>
                 <artifactId>slf4j-jdk14</artifactId>
                 <version>1.7.6</version>
                 <scope>test</scope>