Aaron Kruglikov
Committed by Gerrit Code Review

Migrating netty messaging into netty messaging manager.

Change-Id: I971db195c9dc155cdf76850f0427ef9b9210113c
/*
* Copyright 2014-2015 Open Networking Laboratory
* Copyright 2016 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.
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onlab.netty;
package org.onosproject.store.cluster.messaging.impl;
/**
* State transitions a decoder goes through as it is decoding an incoming message.
......
/*
* Copyright 2014-2015 Open Networking Laboratory
* Copyright 2016 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.
......@@ -13,13 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onlab.netty;
package org.onosproject.store.cluster.messaging.impl;
import com.google.common.base.MoreObjects;
import org.onlab.util.ByteArraySizeHashPrinter;
import org.onosproject.store.cluster.messaging.Endpoint;
import com.google.common.base.MoreObjects;
/**
* Internal message representation with additional attributes
* for supporting, synchronous request/reply behavior.
......
/*
* Copyright 2014-2015 Open Networking Laboratory
* Copyright 2016 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.
......@@ -13,21 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onlab.netty;
package org.onosproject.store.cluster.messaging.impl;
import com.google.common.base.Charsets;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;
import java.util.List;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpAddress.Version;
import org.onosproject.store.cluster.messaging.Endpoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.Charsets;
import java.util.List;
import static com.google.common.base.Preconditions.checkState;
......@@ -54,7 +52,7 @@ public class MessageDecoder extends ReplayingDecoder<DecoderState> {
}
@Override
@java.lang.SuppressWarnings("squid:S128") // suppress switch fall through warning
@SuppressWarnings("squid:S128") // suppress switch fall through warning
protected void decode(
ChannelHandlerContext context,
ByteBuf buffer,
......
/*
* Copyright 2014-2015 Open Networking Laboratory
* Copyright 2016 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.
......@@ -13,22 +13,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onlab.netty;
package org.onosproject.store.cluster.messaging.impl;
import com.google.common.base.Charsets;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import java.io.IOException;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpAddress.Version;
import org.onosproject.store.cluster.messaging.Endpoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.Charsets;
import java.io.IOException;
/**
* Encode InternalMessage out into a byte buffer.
......
package org.onlab.netty;
package org.onosproject.store.cluster.messaging.impl;
import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
......@@ -9,10 +9,17 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BiFunction;
import com.google.common.collect.Sets;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.IpAddress;
import org.onosproject.cluster.ClusterMetadata;
import org.onosproject.cluster.ClusterMetadataEventListener;
import org.onosproject.cluster.ClusterMetadataService;
import org.onosproject.cluster.ControllerNode;
import org.onosproject.cluster.NodeId;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.store.cluster.messaging.Endpoint;
import com.google.common.util.concurrent.MoreExecutors;
......@@ -24,34 +31,39 @@ import static org.onlab.junit.TestTools.findAvailablePort;
/**
* Unit tests for NettyMessaging.
*/
public class NettyMessagingTest {
public class NettyMessagingManagerTest {
NettyMessaging netty1;
NettyMessaging netty2;
NettyMessagingManager netty1;
NettyMessagingManager netty2;
Endpoint ep1 = new Endpoint(IpAddress.valueOf("127.0.0.1"), 5001);
Endpoint ep2 = new Endpoint(IpAddress.valueOf("127.0.0.1"), 5002);
Endpoint invalidEndPoint = new Endpoint(IpAddress.valueOf("127.0.0.1"), 5003);
private static final String DUMMY_NAME = "node";
private static final String IP_STRING = "127.0.0.1";
Endpoint ep1 = new Endpoint(IpAddress.valueOf(IP_STRING), 5001);
Endpoint ep2 = new Endpoint(IpAddress.valueOf(IP_STRING), 5002);
Endpoint invalidEndPoint = new Endpoint(IpAddress.valueOf(IP_STRING), 5003);
@Before
public void setUp() throws Exception {
ep1 = new Endpoint(IpAddress.valueOf("127.0.0.1"), findAvailablePort(5001));
netty1 = new NettyMessaging();
netty1.start(12, ep1);
netty1 = new NettyMessagingManager();
netty1.clusterMetadataService = dummyMetadataService(DUMMY_NAME, IP_STRING, ep1);
netty1.activate();
ep2 = new Endpoint(IpAddress.valueOf("127.0.0.1"), findAvailablePort(5003));
netty2 = new NettyMessaging();
netty2.start(12, ep2);
netty2 = new NettyMessagingManager();
netty2.clusterMetadataService = dummyMetadataService(DUMMY_NAME, IP_STRING, ep2);
netty2.activate();
}
@After
public void tearDown() throws Exception {
if (netty1 != null) {
netty1.stop();
netty1.deactivate();
}
if (netty2 != null) {
netty2.stop();
netty2.deactivate();
}
}
......@@ -125,4 +137,40 @@ public class NettyMessagingTest {
assertEquals("completion-thread", completionThreadName.get());
assertEquals("handler-thread", handlerThreadName.get());
}
private ClusterMetadataService dummyMetadataService(String name, String ipAddress, Endpoint ep) {
return new ClusterMetadataService() {
@Override
public ClusterMetadata getClusterMetadata() {
return new ClusterMetadata(new ProviderId(DUMMY_NAME, DUMMY_NAME),
name, Sets.newHashSet(), Sets.newHashSet());
}
@Override
public ControllerNode getLocalNode() {
return new ControllerNode() {
@Override
public NodeId id() {
return null;
}
@Override
public IpAddress ip() {
return IpAddress.valueOf(ipAddress);
}
@Override
public int tcpPort() {
return ep.port();
}
};
}
@Override
public void addListener(ClusterMetadataEventListener listener) {}
@Override
public void removeListener(ClusterMetadataEventListener listener) {}
};
}
}
\ No newline at end of file
......
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2014 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onlab-utils</artifactId>
<version>1.5.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>onlab-netty</artifactId>
<packaging>bundle</packaging>
<description>Network I/O using Netty framework</description>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava-testlib</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-api</artifactId>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onlab-misc</artifactId>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onlab-junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-common</artifactId>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-buffer</artifactId>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport</artifactId>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-handler</artifactId>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-codec</artifactId>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-epoll</artifactId>
<version>${netty4.version}</version>
</dependency>
</dependencies>
</project>
/*
* Copyright 2014 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.
*/
/**
* Asynchronous messaging APIs implemented using the Netty framework.
*/
package org.onlab.netty;
......@@ -34,7 +34,6 @@
<modules>
<module>junit</module>
<module>misc</module>
<module>netty</module>
<module>nio</module>
<module>yangutils</module>
<module>osgi</module>
......