tom

Merge remote-tracking branch 'origin/master'

...@@ -24,6 +24,11 @@ ...@@ -24,6 +24,11 @@
24 </dependency> 24 </dependency>
25 <dependency> 25 <dependency>
26 <groupId>org.onlab.onos</groupId> 26 <groupId>org.onlab.onos</groupId>
27 + <artifactId>onlab-osgi</artifactId>
28 + <version>${project.version}</version>
29 + </dependency>
30 + <dependency>
31 + <groupId>org.onlab.onos</groupId>
27 <artifactId>onlab-nio</artifactId> 32 <artifactId>onlab-nio</artifactId>
28 <version>${project.version}</version> 33 <version>${project.version}</version>
29 </dependency> 34 </dependency>
......
1 +package org.onlab.onos.foo;
2 +
3 +import java.io.IOException;
4 +
5 +import org.onlab.netty.Message;
6 +import org.onlab.netty.MessageHandler;
7 +import org.slf4j.Logger;
8 +import org.slf4j.LoggerFactory;
9 +
10 +
11 +/**
12 + * Message handler that echos the message back to the sender.
13 + */
14 +public class NettyEchoHandler implements MessageHandler {
15 +
16 + private final Logger log = LoggerFactory.getLogger(getClass());
17 +
18 + @Override
19 + public void handle(Message message) throws IOException {
20 + //log.info("Received message. Echoing it back to the sender.");
21 + message.respond(message.payload());
22 + }
23 +}
1 +package org.onlab.onos.foo;
2 +
3 +import org.onlab.netty.Message;
4 +import org.onlab.netty.MessageHandler;
5 +import org.slf4j.Logger;
6 +import org.slf4j.LoggerFactory;
7 +
8 +/**
9 + * A MessageHandler that simply logs the information.
10 + */
11 +public class NettyLoggingHandler implements MessageHandler {
12 +
13 + private final Logger log = LoggerFactory.getLogger(getClass());
14 +
15 + @Override
16 + public void handle(Message message) {
17 + log.info("Received message. Payload has {} bytes", message.payload().length);
18 + }
19 +}
...@@ -2,7 +2,6 @@ package org.onlab.onos.foo; ...@@ -2,7 +2,6 @@ package org.onlab.onos.foo;
2 2
3 import java.io.IOException; 3 import java.io.IOException;
4 import java.util.concurrent.ExecutionException; 4 import java.util.concurrent.ExecutionException;
5 -import java.util.concurrent.TimeUnit;
6 import java.util.concurrent.TimeoutException; 5 import java.util.concurrent.TimeoutException;
7 6
8 import org.onlab.metrics.MetricsComponent; 7 import org.onlab.metrics.MetricsComponent;
...@@ -35,28 +34,35 @@ public final class SimpleNettyClient { ...@@ -35,28 +34,35 @@ public final class SimpleNettyClient {
35 MetricsManager metrics = new MetricsManager(); 34 MetricsManager metrics = new MetricsManager();
36 messaging.activate(); 35 messaging.activate();
37 metrics.activate(); 36 metrics.activate();
38 - MetricsFeature feature = new MetricsFeature("timers"); 37 + MetricsFeature feature = new MetricsFeature("latency");
39 MetricsComponent component = metrics.registerComponent("NettyMessaging"); 38 MetricsComponent component = metrics.registerComponent("NettyMessaging");
40 - Timer sendAsyncTimer = metrics.createTimer(component, feature, "AsyncSender"); 39 +
41 - final int warmup = 100; 40 + final int warmup = 10000;
42 for (int i = 0; i < warmup; i++) { 41 for (int i = 0; i < warmup; i++) {
42 + messaging.sendAsync(new Endpoint("localhost", 8081), "simple", "Hello World".getBytes());
43 + Response response = messaging
44 + .sendAndReceive(new Endpoint("localhost", 8081), "echo",
45 + "Hello World".getBytes());
46 + }
47 +
48 + Timer sendAsyncTimer = metrics.createTimer(component, feature, "AsyncSender");
49 + Timer sendAndReceiveTimer = metrics.createTimer(component, feature, "SendAndReceive");
50 +
51 + final int iterations = 10000000;
52 + for (int i = 0; i < iterations; i++) {
43 Timer.Context context = sendAsyncTimer.time(); 53 Timer.Context context = sendAsyncTimer.time();
44 - messaging.sendAsync(new Endpoint("localhost", 8080), "simple", "Hello World".getBytes()); 54 + messaging.sendAsync(new Endpoint("localhost", 8081), "simple", "Hello World".getBytes());
45 context.stop(); 55 context.stop();
46 } 56 }
47 - metrics.registerMetric(component, feature, "AsyncTimer", sendAsyncTimer);
48 57
49 - Timer sendAndReceiveTimer = metrics.createTimer(component, feature, "SendAndReceive");
50 - final int iterations = 1000000;
51 for (int i = 0; i < iterations; i++) { 58 for (int i = 0; i < iterations; i++) {
52 Timer.Context context = sendAndReceiveTimer.time(); 59 Timer.Context context = sendAndReceiveTimer.time();
53 Response response = messaging 60 Response response = messaging
54 - .sendAndReceive(new Endpoint("localhost", 8080), "echo", 61 + .sendAndReceive(new Endpoint("localhost", 8081), "echo",
55 "Hello World".getBytes()); 62 "Hello World".getBytes());
56 - System.out.println("Got back:" + new String(response.get(2, TimeUnit.SECONDS))); 63 + // System.out.println("Got back:" + new String(response.get(2, TimeUnit.SECONDS)));
57 context.stop(); 64 context.stop();
58 } 65 }
59 - metrics.registerMetric(component, feature, "AsyncTimer", sendAndReceiveTimer);
60 } 66 }
61 67
62 public static class TestNettyMessagingService extends NettyMessagingService { 68 public static class TestNettyMessagingService extends NettyMessagingService {
......
...@@ -13,6 +13,7 @@ import org.onlab.onos.cli.AbstractShellCommand; ...@@ -13,6 +13,7 @@ import org.onlab.onos.cli.AbstractShellCommand;
13 description = "Starts the simple Netty client") 13 description = "Starts the simple Netty client")
14 public class SimpleNettyClientCommand extends AbstractShellCommand { 14 public class SimpleNettyClientCommand extends AbstractShellCommand {
15 15
16 + //FIXME: replace these arguments with proper ones needed for the test.
16 @Argument(index = 0, name = "serverIp", description = "Server IP address", 17 @Argument(index = 0, name = "serverIp", description = "Server IP address",
17 required = false, multiValued = false) 18 required = false, multiValued = false)
18 String serverIp = "127.0.0.1"; 19 String serverIp = "127.0.0.1";
......
1 package org.onlab.onos.foo; 1 package org.onlab.onos.foo;
2 2
3 -import org.onlab.netty.EchoHandler;
4 import org.onlab.netty.NettyMessagingService; 3 import org.onlab.netty.NettyMessagingService;
5 import org.slf4j.Logger; 4 import org.slf4j.Logger;
6 import org.slf4j.LoggerFactory; 5 import org.slf4j.LoggerFactory;
...@@ -19,10 +18,10 @@ import org.slf4j.LoggerFactory; ...@@ -19,10 +18,10 @@ import org.slf4j.LoggerFactory;
19 } 18 }
20 19
21 public static void startStandalone(String[] args) throws Exception { 20 public static void startStandalone(String[] args) throws Exception {
22 - NettyMessagingService server = new NettyMessagingService(8080); 21 + NettyMessagingService server = new NettyMessagingService(8081);
23 server.activate(); 22 server.activate();
24 - server.registerHandler("simple", new org.onlab.netty.LoggingHandler()); 23 + server.registerHandler("simple", new NettyLoggingHandler());
25 - server.registerHandler("echo", new EchoHandler()); 24 + server.registerHandler("echo", new NettyEchoHandler());
26 } 25 }
27 } 26 }
28 27
......
...@@ -9,10 +9,11 @@ import org.onlab.onos.cli.AbstractShellCommand; ...@@ -9,10 +9,11 @@ import org.onlab.onos.cli.AbstractShellCommand;
9 /** 9 /**
10 * Starts the Simple Netty server. 10 * Starts the Simple Netty server.
11 */ 11 */
12 -@Command(scope = "onos", name = "test-netty-server", 12 +@Command(scope = "onos", name = "simple-netty-server",
13 description = "Starts the simple netty server") 13 description = "Starts the simple netty server")
14 public class SimpleNettyServerCommand extends AbstractShellCommand { 14 public class SimpleNettyServerCommand extends AbstractShellCommand {
15 15
16 + //FIXME: Replace these with parameters for
16 @Argument(index = 0, name = "serverIp", description = "Server IP address", 17 @Argument(index = 0, name = "serverIp", description = "Server IP address",
17 required = false, multiValued = false) 18 required = false, multiValued = false)
18 String serverIp = "127.0.0.1"; 19 String serverIp = "127.0.0.1";
......
...@@ -7,6 +7,12 @@ ...@@ -7,6 +7,12 @@
7 <command> 7 <command>
8 <action class="org.onlab.onos.foo.TestIOServerCommand"/> 8 <action class="org.onlab.onos.foo.TestIOServerCommand"/>
9 </command> 9 </command>
10 + <command>
11 + <action class="org.onlab.onos.foo.SimpleNettyServerCommand"/>
12 + </command>
13 + <command>
14 + <action class="org.onlab.onos.foo.SimpleNettyClientCommand"/>
15 + </command>
10 </command-bundle> 16 </command-bundle>
11 17
12 </blueprint> 18 </blueprint>
......
1 package org.onlab.onos.net.device.impl; 1 package org.onlab.onos.net.device.impl;
2 2
3 import com.google.common.collect.Sets; 3 import com.google.common.collect.Sets;
4 +
4 import org.junit.After; 5 import org.junit.After;
5 import org.junit.Before; 6 import org.junit.Before;
6 import org.junit.Ignore; 7 import org.junit.Ignore;
7 import org.junit.Test; 8 import org.junit.Test;
9 +import org.onlab.onos.cluster.ClusterEventListener;
10 +import org.onlab.onos.cluster.ClusterService;
11 +import org.onlab.onos.cluster.ControllerNode;
12 +import org.onlab.onos.cluster.DefaultControllerNode;
8 import org.onlab.onos.cluster.MastershipServiceAdapter; 13 import org.onlab.onos.cluster.MastershipServiceAdapter;
14 +import org.onlab.onos.cluster.MastershipTerm;
15 +import org.onlab.onos.cluster.MastershipTermService;
9 import org.onlab.onos.cluster.NodeId; 16 import org.onlab.onos.cluster.NodeId;
17 +import org.onlab.onos.cluster.ControllerNode.State;
10 import org.onlab.onos.event.Event; 18 import org.onlab.onos.event.Event;
11 import org.onlab.onos.event.impl.TestEventDispatcher; 19 import org.onlab.onos.event.impl.TestEventDispatcher;
12 import org.onlab.onos.net.Device; 20 import org.onlab.onos.net.Device;
...@@ -27,7 +35,9 @@ import org.onlab.onos.net.device.DeviceService; ...@@ -27,7 +35,9 @@ import org.onlab.onos.net.device.DeviceService;
27 import org.onlab.onos.net.device.PortDescription; 35 import org.onlab.onos.net.device.PortDescription;
28 import org.onlab.onos.net.provider.AbstractProvider; 36 import org.onlab.onos.net.provider.AbstractProvider;
29 import org.onlab.onos.net.provider.ProviderId; 37 import org.onlab.onos.net.provider.ProviderId;
38 +import org.onlab.onos.store.ClockProviderService;
30 import org.onlab.onos.store.trivial.impl.SimpleDeviceStore; 39 import org.onlab.onos.store.trivial.impl.SimpleDeviceStore;
40 +import org.onlab.packet.IpPrefix;
31 41
32 import java.util.ArrayList; 42 import java.util.ArrayList;
33 import java.util.Iterator; 43 import java.util.Iterator;
...@@ -56,6 +66,8 @@ public class DeviceManagerTest { ...@@ -56,6 +66,8 @@ public class DeviceManagerTest {
56 private static final PortNumber P1 = PortNumber.portNumber(1); 66 private static final PortNumber P1 = PortNumber.portNumber(1);
57 private static final PortNumber P2 = PortNumber.portNumber(2); 67 private static final PortNumber P2 = PortNumber.portNumber(2);
58 private static final PortNumber P3 = PortNumber.portNumber(3); 68 private static final PortNumber P3 = PortNumber.portNumber(3);
69 + private static final NodeId NID_LOCAL = new NodeId("local");
70 + private static final IpPrefix LOCALHOST = IpPrefix.valueOf("127.0.0.1");
59 71
60 private DeviceManager mgr; 72 private DeviceManager mgr;
61 73
...@@ -75,6 +87,8 @@ public class DeviceManagerTest { ...@@ -75,6 +87,8 @@ public class DeviceManagerTest {
75 mgr.store = new SimpleDeviceStore(); 87 mgr.store = new SimpleDeviceStore();
76 mgr.eventDispatcher = new TestEventDispatcher(); 88 mgr.eventDispatcher = new TestEventDispatcher();
77 mgr.mastershipService = new TestMastershipService(); 89 mgr.mastershipService = new TestMastershipService();
90 + mgr.clusterService = new TestClusterService();
91 + mgr.clockProviderService = new TestClockProviderService();
78 mgr.activate(); 92 mgr.activate();
79 93
80 service.addListener(listener); 94 service.addListener(listener);
...@@ -273,6 +287,59 @@ public class DeviceManagerTest { ...@@ -273,6 +287,59 @@ public class DeviceManagerTest {
273 public MastershipRole requestRoleFor(DeviceId deviceId) { 287 public MastershipRole requestRoleFor(DeviceId deviceId) {
274 return MastershipRole.MASTER; 288 return MastershipRole.MASTER;
275 } 289 }
290 +
291 + @Override
292 + public MastershipTermService requestTermService() {
293 + return new MastershipTermService() {
294 + @Override
295 + public MastershipTerm getMastershipTerm(DeviceId deviceId) {
296 + // FIXME: just returning something not null
297 + return MastershipTerm.of(NID_LOCAL, 1);
298 + }
299 + };
300 + }
301 + }
302 +
303 + // code clone
304 + private final class TestClusterService implements ClusterService {
305 +
306 + ControllerNode local = new DefaultControllerNode(NID_LOCAL, LOCALHOST);
307 +
308 + @Override
309 + public ControllerNode getLocalNode() {
310 + return local;
311 + }
312 +
313 + @Override
314 + public Set<ControllerNode> getNodes() {
315 + return null;
276 } 316 }
277 317
318 + @Override
319 + public ControllerNode getNode(NodeId nodeId) {
320 + return null;
321 + }
322 +
323 + @Override
324 + public State getState(NodeId nodeId) {
325 + return null;
326 + }
327 +
328 + @Override
329 + public void addListener(ClusterEventListener listener) {
330 + }
331 +
332 + @Override
333 + public void removeListener(ClusterEventListener listener) {
334 + }
335 + }
336 +
337 + private final class TestClockProviderService implements
338 + ClockProviderService {
339 +
340 + @Override
341 + public void setMastershipTerm(DeviceId deviceId, MastershipTerm term) {
342 + // TODO Auto-generated method stub
343 + }
344 + }
278 } 345 }
......
...@@ -29,6 +29,7 @@ import org.onlab.onos.store.cluster.messaging.MessageSubject; ...@@ -29,6 +29,7 @@ import org.onlab.onos.store.cluster.messaging.MessageSubject;
29 import org.onlab.onos.store.serializers.ClusterMessageSerializer; 29 import org.onlab.onos.store.serializers.ClusterMessageSerializer;
30 import org.onlab.onos.store.serializers.KryoPoolUtil; 30 import org.onlab.onos.store.serializers.KryoPoolUtil;
31 import org.onlab.onos.store.serializers.KryoSerializer; 31 import org.onlab.onos.store.serializers.KryoSerializer;
32 +import org.onlab.onos.store.serializers.MessageSubjectSerializer;
32 import org.onlab.util.KryoPool; 33 import org.onlab.util.KryoPool;
33 import org.onlab.netty.Endpoint; 34 import org.onlab.netty.Endpoint;
34 import org.onlab.netty.Message; 35 import org.onlab.netty.Message;
...@@ -66,7 +67,7 @@ public class ClusterCommunicationManager ...@@ -66,7 +67,7 @@ public class ClusterCommunicationManager
66 .register(ClusterMessage.class, new ClusterMessageSerializer()) 67 .register(ClusterMessage.class, new ClusterMessageSerializer())
67 .register(ClusterMembershipEvent.class) 68 .register(ClusterMembershipEvent.class)
68 .register(byte[].class) 69 .register(byte[].class)
69 - .register(MessageSubject.class) 70 + .register(MessageSubject.class, new MessageSubjectSerializer())
70 .build() 71 .build()
71 .populate(1); 72 .populate(1);
72 } 73 }
...@@ -123,7 +124,8 @@ public class ClusterCommunicationManager ...@@ -123,7 +124,8 @@ public class ClusterCommunicationManager
123 Endpoint nodeEp = new Endpoint(node.ip().toString(), node.tcpPort()); 124 Endpoint nodeEp = new Endpoint(node.ip().toString(), node.tcpPort());
124 try { 125 try {
125 log.info("sending..."); 126 log.info("sending...");
126 - Response resp = messagingService.sendAndReceive(nodeEp, message.subject().value(), SERIALIZER.encode(message)); 127 + Response resp = messagingService.sendAndReceive(nodeEp,
128 + message.subject().value(), SERIALIZER.encode(message));
127 resp.get(1, TimeUnit.SECONDS); 129 resp.get(1, TimeUnit.SECONDS);
128 log.info("sent..."); 130 log.info("sent...");
129 return true; 131 return true;
......
...@@ -3,7 +3,6 @@ package org.onlab.onos.store.serializers; ...@@ -3,7 +3,6 @@ package org.onlab.onos.store.serializers;
3 import org.onlab.onos.cluster.NodeId; 3 import org.onlab.onos.cluster.NodeId;
4 import org.onlab.onos.store.cluster.messaging.ClusterMessage; 4 import org.onlab.onos.store.cluster.messaging.ClusterMessage;
5 import org.onlab.onos.store.cluster.messaging.MessageSubject; 5 import org.onlab.onos.store.cluster.messaging.MessageSubject;
6 -
7 import com.esotericsoftware.kryo.Kryo; 6 import com.esotericsoftware.kryo.Kryo;
8 import com.esotericsoftware.kryo.Serializer; 7 import com.esotericsoftware.kryo.Serializer;
9 import com.esotericsoftware.kryo.io.Input; 8 import com.esotericsoftware.kryo.io.Input;
...@@ -11,6 +10,9 @@ import com.esotericsoftware.kryo.io.Output; ...@@ -11,6 +10,9 @@ import com.esotericsoftware.kryo.io.Output;
11 10
12 public final class ClusterMessageSerializer extends Serializer<ClusterMessage> { 11 public final class ClusterMessageSerializer extends Serializer<ClusterMessage> {
13 12
13 + /**
14 + * Creates a serializer for {@link ClusterMessage}.
15 + */
14 public ClusterMessageSerializer() { 16 public ClusterMessageSerializer() {
15 // does not accept null 17 // does not accept null
16 super(false); 18 super(false);
......
...@@ -14,7 +14,7 @@ import com.esotericsoftware.kryo.io.Output; ...@@ -14,7 +14,7 @@ import com.esotericsoftware.kryo.io.Output;
14 public class MastershipBasedTimestampSerializer extends Serializer<MastershipBasedTimestamp> { 14 public class MastershipBasedTimestampSerializer extends Serializer<MastershipBasedTimestamp> {
15 15
16 /** 16 /**
17 - * Default constructor. 17 + * Creates a serializer for {@link MastershipBasedTimestamp}.
18 */ 18 */
19 public MastershipBasedTimestampSerializer() { 19 public MastershipBasedTimestampSerializer() {
20 // non-null, immutable 20 // non-null, immutable
......
1 +package org.onlab.onos.store.serializers;
2 +
3 +import org.onlab.onos.store.cluster.messaging.MessageSubject;
4 +
5 +import com.esotericsoftware.kryo.Kryo;
6 +import com.esotericsoftware.kryo.Serializer;
7 +import com.esotericsoftware.kryo.io.Input;
8 +import com.esotericsoftware.kryo.io.Output;
9 +
10 +public final class MessageSubjectSerializer extends Serializer<MessageSubject> {
11 +
12 + /**
13 + * Creates a serializer for {@link MessageSubject}.
14 + */
15 + public MessageSubjectSerializer() {
16 + // non-null, immutable
17 + super(false, true);
18 + }
19 +
20 +
21 + @Override
22 + public void write(Kryo kryo, Output output, MessageSubject object) {
23 + output.writeString(object.value());
24 + }
25 +
26 + @Override
27 + public MessageSubject read(Kryo kryo, Input input,
28 + Class<MessageSubject> type) {
29 + return new MessageSubject(input.readString());
30 + }
31 +}
...@@ -153,6 +153,7 @@ ...@@ -153,6 +153,7 @@
153 description="ONOS sample playground application"> 153 description="ONOS sample playground application">
154 <feature>onos-api</feature> 154 <feature>onos-api</feature>
155 <bundle>mvn:org.onlab.onos/onos-app-foo/1.0.0-SNAPSHOT</bundle> 155 <bundle>mvn:org.onlab.onos/onos-app-foo/1.0.0-SNAPSHOT</bundle>
156 + <bundle>mvn:org.onlab.onos/onlab-netty/1.0.0-SNAPSHOT</bundle>
156 </feature> 157 </feature>
157 158
158 <feature name="onos-app-config" version="1.0.0" 159 <feature name="onos-app-config" version="1.0.0"
......
1 package org.onlab.metrics; 1 package org.onlab.metrics;
2 2
3 -import java.io.File;
4 -import java.util.Locale;
5 import java.util.Map; 3 import java.util.Map;
6 import java.util.concurrent.ConcurrentHashMap; 4 import java.util.concurrent.ConcurrentHashMap;
7 import java.util.concurrent.ConcurrentMap; 5 import java.util.concurrent.ConcurrentMap;
...@@ -11,8 +9,8 @@ import org.apache.felix.scr.annotations.Activate; ...@@ -11,8 +9,8 @@ import org.apache.felix.scr.annotations.Activate;
11 import org.apache.felix.scr.annotations.Component; 9 import org.apache.felix.scr.annotations.Component;
12 import org.apache.felix.scr.annotations.Deactivate; 10 import org.apache.felix.scr.annotations.Deactivate;
13 11
12 +import com.codahale.metrics.ConsoleReporter;
14 import com.codahale.metrics.Counter; 13 import com.codahale.metrics.Counter;
15 -import com.codahale.metrics.CsvReporter;
16 import com.codahale.metrics.Gauge; 14 import com.codahale.metrics.Gauge;
17 import com.codahale.metrics.Histogram; 15 import com.codahale.metrics.Histogram;
18 import com.codahale.metrics.Meter; 16 import com.codahale.metrics.Meter;
...@@ -69,15 +67,14 @@ public final class MetricsManager implements MetricsService { ...@@ -69,15 +67,14 @@ public final class MetricsManager implements MetricsService {
69 /** 67 /**
70 * Default Reporter for this metrics manager. 68 * Default Reporter for this metrics manager.
71 */ 69 */
72 - private final CsvReporter reporter; 70 + private final ConsoleReporter reporter;
73 71
74 public MetricsManager() { 72 public MetricsManager() {
75 this.metricsRegistry = new MetricRegistry(); 73 this.metricsRegistry = new MetricRegistry();
76 - this.reporter = CsvReporter.forRegistry(metricsRegistry) 74 + this.reporter = ConsoleReporter.forRegistry(metricsRegistry)
77 - .formatFor(Locale.US)
78 .convertRatesTo(TimeUnit.SECONDS) 75 .convertRatesTo(TimeUnit.SECONDS)
79 .convertDurationsTo(TimeUnit.MICROSECONDS) 76 .convertDurationsTo(TimeUnit.MICROSECONDS)
80 - .build(new File("/var/onos/log/metrics/")); 77 + .build();
81 } 78 }
82 79
83 @Activate 80 @Activate
......
...@@ -36,11 +36,6 @@ public class MessageEncoder extends MessageToByteEncoder<InternalMessage> { ...@@ -36,11 +36,6 @@ public class MessageEncoder extends MessageToByteEncoder<InternalMessage> {
36 // write preamble 36 // write preamble
37 out.writeBytes(PREAMBLE); 37 out.writeBytes(PREAMBLE);
38 38
39 - try {
40 - SERIALIZER.encode(message);
41 - } catch (Exception e) {
42 - e.printStackTrace();
43 - }
44 byte[] payload = SERIALIZER.encode(message); 39 byte[] payload = SERIALIZER.encode(message);
45 40
46 // write payload length 41 // write payload length
......