Merge "Initial code drop of Netty.io integration"
authorDana Kutenicsova <dkutenic@cisco.com>
Fri, 21 Mar 2014 08:34:57 +0000 (08:34 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 21 Mar 2014 08:34:57 +0000 (08:34 +0000)
tcp-md5/netty/.project [new file with mode: 0644]
tcp-md5/netty/pom.xml [new file with mode: 0644]
tcp-md5/netty/src/main/java/org/opendaylight/bgpcep/tcpmd5/netty/AbstractMD5ChannelConfig.java [new file with mode: 0644]
tcp-md5/netty/src/main/java/org/opendaylight/bgpcep/tcpmd5/netty/MD5ChannelOption.java [new file with mode: 0644]
tcp-md5/netty/src/main/java/org/opendaylight/bgpcep/tcpmd5/netty/MD5NioServerSocketChannel.java [new file with mode: 0644]
tcp-md5/netty/src/main/java/org/opendaylight/bgpcep/tcpmd5/netty/MD5NioSocketChannel.java [new file with mode: 0644]
tcp-md5/netty/src/main/java/org/opendaylight/bgpcep/tcpmd5/netty/MD5ServerSocketChannelConfig.java [new file with mode: 0644]
tcp-md5/netty/src/main/java/org/opendaylight/bgpcep/tcpmd5/netty/MD5SocketChannelConfig.java [new file with mode: 0644]
tcp-md5/netty/src/main/java/org/opendaylight/bgpcep/tcpmd5/netty/ProxyMD5ServerSocketChannelConfig.java [new file with mode: 0644]
tcp-md5/netty/src/main/java/org/opendaylight/bgpcep/tcpmd5/netty/ProxyMD5SocketChannelConfig.java [new file with mode: 0644]
tcp-md5/pom.xml

diff --git a/tcp-md5/netty/.project b/tcp-md5/netty/.project
new file mode 100644 (file)
index 0000000..089a55a
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2013 Robert Varga. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ and is available at http://www.eclipse.org/legal/epl-v10.html
+-->
+<projectDescription>
+       <name>tcpmd5-netty</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>org.eclipse.jdt.core.javabuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.m2e.core.maven2Builder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>org.eclipse.pde.PluginNature</nature>
+               <nature>org.eclipse.jdt.core.javanature</nature>
+               <nature>org.eclipse.m2e.core.maven2Nature</nature>
+       </natures>
+</projectDescription>
diff --git a/tcp-md5/netty/pom.xml b/tcp-md5/netty/pom.xml
new file mode 100644 (file)
index 0000000..5ddbc54
--- /dev/null
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<!--
+ Copyright (c) 2013 Robert Varga. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ and is available at http://www.eclipse.org/legal/epl-v10.html
+-->
+<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/xsd/maven-4.0.0.xsd">
+
+       <parent>
+               <groupId>org.opendaylight.bgpcep</groupId>
+               <artifactId>tcpmd5-parent</artifactId>
+               <version>0.3.1-SNAPSHOT</version>
+       </parent>
+
+       <modelVersion>4.0.0</modelVersion>
+       <artifactId>tcpmd5-netty</artifactId>
+       <description>RFC2385-enable sockets for Netty</description>
+       <packaging>bundle</packaging>
+       <name>${project.artifactId}</name>
+       <prerequisites>
+               <maven>3.0.4</maven>
+       </prerequisites>
+
+       <dependencies>
+               <dependency>
+                       <groupId>${project.groupId}</groupId>
+            <artifactId>tcpmd5-core</artifactId>
+        </dependency>
+        <dependency>
+                       <groupId>io.netty</groupId>
+                       <artifactId>netty-transport</artifactId>
+               </dependency>
+
+               <dependency>
+                       <groupId>com.google.guava</groupId>
+                       <artifactId>guava</artifactId>
+               </dependency>
+               <dependency>
+                       <groupId>org.slf4j</groupId>
+                       <artifactId>slf4j-api</artifactId>
+        </dependency>
+
+        <!-- Testing dependencies -->
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+        </dependency>
+    </dependencies>
+
+       <build>
+               <plugins>
+                       <plugin>
+                               <groupId>org.apache.felix</groupId>
+                               <artifactId>maven-bundle-plugin</artifactId>
+                               <extensions>true</extensions>
+                               <configuration>
+                                       <instructions>
+                                               <Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
+                                       </instructions>
+                               </configuration>
+                       </plugin>
+                       <plugin>
+                               <groupId>org.apache.maven.plugins</groupId>
+                               <artifactId>maven-jar-plugin</artifactId>
+                               <executions>
+                                       <execution>
+                                               <phase>package</phase>
+                                               <goals>
+                                                       <goal>test-jar</goal>
+                                               </goals>
+                                       </execution>
+                               </executions>
+                       </plugin>
+               </plugins>
+       </build>
+
+       <distributionManagement>
+               <site>
+            <id>${project.artifactId}</id>
+                       <name>TCPMD5-NETTY Module site</name>
+                       <url>${basedir}/target/site/${project.artifactId}</url>
+               </site>
+       </distributionManagement>
+</project>
diff --git a/tcp-md5/netty/src/main/java/org/opendaylight/bgpcep/tcpmd5/netty/AbstractMD5ChannelConfig.java b/tcp-md5/netty/src/main/java/org/opendaylight/bgpcep/tcpmd5/netty/AbstractMD5ChannelConfig.java
new file mode 100644 (file)
index 0000000..30a5cc6
--- /dev/null
@@ -0,0 +1,146 @@
+/*
+ * Copyright (c) 2013 Robert Varga. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.bgpcep.tcpmd5.netty;
+
+import io.netty.buffer.ByteBufAllocator;
+import io.netty.channel.ChannelConfig;
+import io.netty.channel.ChannelException;
+import io.netty.channel.ChannelOption;
+import io.netty.channel.MessageSizeEstimator;
+import io.netty.channel.RecvByteBufAllocator;
+
+import java.io.IOException;
+import java.nio.channels.NetworkChannel;
+import java.util.Map;
+
+import org.opendaylight.bgpcep.tcpmd5.MD5SocketOptions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Abstract base class for implementing ChannelConfig classes. This code is abstracted
+ * for reuse between the SocketChannelConfig and ServerSocketChannelConfig.
+ *
+ * @param <C> Base configuration type
+ */
+abstract class AbstractMD5ChannelConfig<C extends ChannelConfig> implements ChannelConfig {
+       private static final Logger LOG = LoggerFactory.getLogger(ProxyMD5ServerSocketChannelConfig.class);
+       private final NetworkChannel channel;
+       protected final C config;
+
+       protected AbstractMD5ChannelConfig(final C config, final NetworkChannel channel) {
+               this.config = Preconditions.checkNotNull(config);
+               this.channel = Preconditions.checkNotNull(channel);
+       }
+
+       protected final byte[] getKey() {
+               try {
+                       return channel.getOption(MD5SocketOptions.TCP_MD5SIG);
+               } catch (IOException e) {
+                       LOG.info("Failed to get channel MD5 signature key", e);
+                       return null;
+               }
+       }
+
+       protected final void setKey(final byte[] key) {
+               try {
+                       channel.setOption(MD5SocketOptions.TCP_MD5SIG, key);
+               } catch (IOException e) {
+                       throw new ChannelException("Failed to set channel MD5 signature key", e);
+               }
+       }
+
+       @Override
+       public Map<ChannelOption<?>, Object> getOptions() {
+               final Map<ChannelOption<?>, Object> opts = config.getOptions();
+               final byte[] key = getKey();
+               if (key != null) {
+                       opts.put(MD5ChannelOption.TCP_MD5SIG, key);
+               }
+
+               return opts;
+       }
+
+       @Override
+       public boolean setOptions(final Map<ChannelOption<?>, ?> options) {
+               boolean setAllOptions = true;
+               if (options.containsKey(MD5ChannelOption.TCP_MD5SIG)) {
+                       setAllOptions = setOption(MD5ChannelOption.TCP_MD5SIG, (byte[]) options.get(MD5ChannelOption.TCP_MD5SIG));
+               }
+
+               return config.setOptions(options) && setAllOptions;
+       }
+
+       @Override
+       public <T> T getOption(final ChannelOption<T> option) {
+               if (option == MD5ChannelOption.TCP_MD5SIG) {
+                       @SuppressWarnings("unchecked")
+                       final T ret = (T) getKey();
+                       return ret;
+               }
+
+               return config.getOption(option);
+       }
+
+       @Override
+       public <T> boolean setOption(final ChannelOption<T> option, final T value) {
+               if (option.equals(MD5ChannelOption.TCP_MD5SIG)) {
+                       setKey((byte[]) value);
+                       return true;
+               }
+
+               return config.setOption(option, value);
+       }
+
+       @Override
+       public final ByteBufAllocator getAllocator() {
+               return config.getAllocator();
+       }
+
+       @Override
+       public final int getConnectTimeoutMillis() {
+               return config.getConnectTimeoutMillis();
+       }
+
+       @Override
+       public final int getMaxMessagesPerRead() {
+               return config.getMaxMessagesPerRead();
+       }
+
+       @Override
+       public final MessageSizeEstimator getMessageSizeEstimator() {
+               return config.getMessageSizeEstimator();
+       }
+
+       @Override
+       public final RecvByteBufAllocator getRecvByteBufAllocator() {
+               return config.getRecvByteBufAllocator();
+       }
+
+       @Override
+       public final int getWriteBufferHighWaterMark() {
+               return config.getWriteBufferHighWaterMark();
+       }
+
+       @Override
+       public final int getWriteBufferLowWaterMark() {
+               return config.getWriteBufferLowWaterMark();
+       }
+
+       @Override
+       public final int getWriteSpinCount() {
+               return config.getWriteSpinCount();
+       }
+
+       @Override
+       public final boolean isAutoRead() {
+               return config.isAutoRead();
+       }
+}
diff --git a/tcp-md5/netty/src/main/java/org/opendaylight/bgpcep/tcpmd5/netty/MD5ChannelOption.java b/tcp-md5/netty/src/main/java/org/opendaylight/bgpcep/tcpmd5/netty/MD5ChannelOption.java
new file mode 100644 (file)
index 0000000..61424ac
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2013 Robert Varga. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.bgpcep.tcpmd5.netty;
+
+import io.netty.channel.ChannelOption;
+
+/**
+ * TCP MD5 Signature {@link ChannelOption}.
+ */
+public final class MD5ChannelOption extends ChannelOption<byte[]> {
+       /**
+        * Singleton instance of TCP MD5 Signature ChannelOption.
+        */
+       public static final MD5ChannelOption TCP_MD5SIG = new MD5ChannelOption("TCP_MD5SIG");
+
+       private MD5ChannelOption(final String name) {
+               super(name);
+       }
+
+       @Override
+       public void validate(final byte[] value) {
+               // null value is allowed
+       }
+}
diff --git a/tcp-md5/netty/src/main/java/org/opendaylight/bgpcep/tcpmd5/netty/MD5NioServerSocketChannel.java b/tcp-md5/netty/src/main/java/org/opendaylight/bgpcep/tcpmd5/netty/MD5NioServerSocketChannel.java
new file mode 100644 (file)
index 0000000..b7a14f2
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2013 Robert Varga. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.bgpcep.tcpmd5.netty;
+
+import io.netty.channel.socket.nio.NioServerSocketChannel;
+
+import org.opendaylight.bgpcep.tcpmd5.MD5ServerSocketChannel;
+
+/**
+ * {@link NioServerSocketChannel} enabled with support for TCP MD5 Signature
+ * option.
+ */
+public class MD5NioServerSocketChannel extends NioServerSocketChannel {
+       private final MD5ServerSocketChannelConfig config;
+       private final MD5ServerSocketChannel channel;
+
+       public MD5NioServerSocketChannel() {
+               super();
+               this.channel = new MD5ServerSocketChannel(javaChannel());
+               this.config = new ProxyMD5ServerSocketChannelConfig(super.config(), channel);
+       }
+
+       @Override
+       public MD5ServerSocketChannelConfig config() {
+               return this.config;
+       }
+
+       @Override
+       protected MD5ServerSocketChannel javaChannel() {
+               return channel;
+       }
+}
diff --git a/tcp-md5/netty/src/main/java/org/opendaylight/bgpcep/tcpmd5/netty/MD5NioSocketChannel.java b/tcp-md5/netty/src/main/java/org/opendaylight/bgpcep/tcpmd5/netty/MD5NioSocketChannel.java
new file mode 100644 (file)
index 0000000..8f2daca
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2013 Robert Varga. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.bgpcep.tcpmd5.netty;
+
+import io.netty.channel.socket.nio.NioSocketChannel;
+
+import org.opendaylight.bgpcep.tcpmd5.MD5SocketChannel;
+
+/**
+ * {@link NioSocketChannel} enabled with support for TCP MD5 Signature
+ * option.
+ */
+public class MD5NioSocketChannel extends NioSocketChannel {
+       private final MD5SocketChannelConfig config;
+       private final MD5SocketChannel channel;
+
+       public MD5NioSocketChannel() {
+               super();
+               this.channel = new MD5SocketChannel(javaChannel());
+               this.config = new ProxyMD5SocketChannelConfig(super.config(), channel);
+       }
+
+       @Override
+       public MD5SocketChannelConfig config() {
+               return this.config;
+       }
+
+       @Override
+       protected MD5SocketChannel javaChannel() {
+               return channel;
+       }
+}
diff --git a/tcp-md5/netty/src/main/java/org/opendaylight/bgpcep/tcpmd5/netty/MD5ServerSocketChannelConfig.java b/tcp-md5/netty/src/main/java/org/opendaylight/bgpcep/tcpmd5/netty/MD5ServerSocketChannelConfig.java
new file mode 100644 (file)
index 0000000..015c683
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2013 Robert Varga. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.bgpcep.tcpmd5.netty;
+
+import io.netty.buffer.ByteBufAllocator;
+import io.netty.channel.MessageSizeEstimator;
+import io.netty.channel.RecvByteBufAllocator;
+import io.netty.channel.socket.ServerSocketChannelConfig;
+
+/**
+ * {@link ServerSocketChannelConfig} augmented with TCP MD5 Signature option support.
+ */
+public interface MD5ServerSocketChannelConfig extends ServerSocketChannelConfig {
+       byte[] getMD5SignatureKey();
+
+       MD5ServerSocketChannelConfig setMD5SignatureKey(byte[] key);
+
+       @Override
+       MD5ServerSocketChannelConfig setBacklog(int backlog);
+
+       @Override
+       MD5ServerSocketChannelConfig setReuseAddress(boolean reuseAddress);
+
+       @Override
+       MD5ServerSocketChannelConfig setReceiveBufferSize(int receiveBufferSize);
+
+       @Override
+       MD5ServerSocketChannelConfig setPerformancePreferences(int connectionTime, int latency, int bandwidth);
+
+       @Override
+       MD5ServerSocketChannelConfig setConnectTimeoutMillis(int connectTimeoutMillis);
+
+       @Override
+       MD5ServerSocketChannelConfig setMaxMessagesPerRead(int maxMessagesPerRead);
+
+       @Override
+       MD5ServerSocketChannelConfig setWriteSpinCount(int writeSpinCount);
+
+       @Override
+       MD5ServerSocketChannelConfig setAllocator(ByteBufAllocator allocator);
+
+       @Override
+       MD5ServerSocketChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator);
+
+       @Override
+       MD5ServerSocketChannelConfig setAutoRead(boolean autoRead);
+
+       @Override
+       MD5ServerSocketChannelConfig setMessageSizeEstimator(MessageSizeEstimator estimator);
+}
diff --git a/tcp-md5/netty/src/main/java/org/opendaylight/bgpcep/tcpmd5/netty/MD5SocketChannelConfig.java b/tcp-md5/netty/src/main/java/org/opendaylight/bgpcep/tcpmd5/netty/MD5SocketChannelConfig.java
new file mode 100644 (file)
index 0000000..c8c3cbb
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2013 Robert Varga. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.bgpcep.tcpmd5.netty;
+
+import io.netty.buffer.ByteBufAllocator;
+import io.netty.channel.MessageSizeEstimator;
+import io.netty.channel.RecvByteBufAllocator;
+import io.netty.channel.socket.SocketChannelConfig;
+
+/**
+ * {@link SocketChannelConfig} augmented with TCP MD5 Signature option support.
+ */
+public interface MD5SocketChannelConfig extends SocketChannelConfig {
+       byte[] getMD5SignatureKey();
+
+       MD5SocketChannelConfig setMD5SignatureKey(byte[] key);
+
+       @Override
+       MD5SocketChannelConfig setTcpNoDelay(boolean tcpNoDelay);
+
+       @Override
+       MD5SocketChannelConfig setSoLinger(int soLinger);
+
+       @Override
+       MD5SocketChannelConfig setSendBufferSize(int sendBufferSize);
+
+       @Override
+       MD5SocketChannelConfig setReceiveBufferSize(int receiveBufferSize);
+
+       @Override
+       MD5SocketChannelConfig setKeepAlive(boolean keepAlive);
+
+       @Override
+       MD5SocketChannelConfig setTrafficClass(int trafficClass);
+
+       @Override
+       MD5SocketChannelConfig setReuseAddress(boolean reuseAddress);
+
+       @Override
+       MD5SocketChannelConfig setPerformancePreferences(int connectionTime, int latency, int bandwidth);
+
+       @Override
+       MD5SocketChannelConfig setAllowHalfClosure(boolean allowHalfClosure);
+
+       @Override
+       MD5SocketChannelConfig setConnectTimeoutMillis(int connectTimeoutMillis);
+
+       @Override
+       MD5SocketChannelConfig setMaxMessagesPerRead(int maxMessagesPerRead);
+
+       @Override
+       MD5SocketChannelConfig setWriteSpinCount(int writeSpinCount);
+
+       @Override
+       MD5SocketChannelConfig setAllocator(ByteBufAllocator allocator);
+
+       @Override
+       MD5SocketChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator);
+
+       @Override
+       MD5SocketChannelConfig setAutoRead(boolean autoRead);
+
+       @Override
+       MD5SocketChannelConfig setMessageSizeEstimator(MessageSizeEstimator estimator);
+}
diff --git a/tcp-md5/netty/src/main/java/org/opendaylight/bgpcep/tcpmd5/netty/ProxyMD5ServerSocketChannelConfig.java b/tcp-md5/netty/src/main/java/org/opendaylight/bgpcep/tcpmd5/netty/ProxyMD5ServerSocketChannelConfig.java
new file mode 100644 (file)
index 0000000..38fdc69
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ * Copyright (c) 2013 Robert Varga. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.bgpcep.tcpmd5.netty;
+
+import io.netty.buffer.ByteBufAllocator;
+import io.netty.channel.ChannelConfig;
+import io.netty.channel.MessageSizeEstimator;
+import io.netty.channel.RecvByteBufAllocator;
+import io.netty.channel.socket.ServerSocketChannelConfig;
+
+import org.opendaylight.bgpcep.tcpmd5.MD5ServerSocketChannel;
+
+/**
+ * Proxy implementation working on top an existing ServerSocketChannelConfig.
+ */
+final class ProxyMD5ServerSocketChannelConfig extends AbstractMD5ChannelConfig<ServerSocketChannelConfig> implements MD5ServerSocketChannelConfig {
+       public ProxyMD5ServerSocketChannelConfig(final ServerSocketChannelConfig config, final MD5ServerSocketChannel channel) {
+               super(config, channel);
+       }
+
+       @Override
+       public int getBacklog() {
+               return config.getBacklog();
+       }
+
+       @Override
+       public boolean isReuseAddress() {
+               return config.isReuseAddress();
+       }
+
+       @Override
+       public int getReceiveBufferSize() {
+               return config.getReceiveBufferSize();
+       }
+
+       @Override
+       public ChannelConfig setWriteBufferHighWaterMark(final int writeBufferHighWaterMark) {
+               config.setWriteBufferHighWaterMark(writeBufferHighWaterMark);
+               return this;
+       }
+
+       @Override
+       public byte[] getMD5SignatureKey() {
+               return getKey();
+       }
+
+       @Override
+       public MD5ServerSocketChannelConfig setMD5SignatureKey(final byte[] key) {
+               setKey(key);
+               return this;
+       }
+
+       @Override
+       public MD5ServerSocketChannelConfig setBacklog(final int backlog) {
+               config.setBacklog(backlog);
+               return this;
+       }
+
+       @Override
+       public MD5ServerSocketChannelConfig setReuseAddress(final boolean reuseAddress) {
+               config.setReuseAddress(reuseAddress);
+               return this;
+       }
+
+       @Override
+       public MD5ServerSocketChannelConfig setReceiveBufferSize(final int receiveBufferSize) {
+               config.setReceiveBufferSize(receiveBufferSize);
+               return this;
+       }
+
+       @Override
+       public MD5ServerSocketChannelConfig setPerformancePreferences(final int connectionTime, final int latency, final int bandwidth) {
+               config.setPerformancePreferences(connectionTime, latency, bandwidth);
+               return this;
+       }
+
+       @Override
+       public MD5ServerSocketChannelConfig setConnectTimeoutMillis(final int connectTimeoutMillis) {
+               config.setConnectTimeoutMillis(connectTimeoutMillis);
+               return this;
+       }
+
+       @Override
+       public MD5ServerSocketChannelConfig setMaxMessagesPerRead(final int maxMessagesPerRead) {
+               config.setMaxMessagesPerRead(maxMessagesPerRead);
+               return this;
+       }
+
+       @Override
+       public MD5ServerSocketChannelConfig setWriteSpinCount(final int writeSpinCount) {
+               config.setWriteSpinCount(writeSpinCount);
+               return this;
+       }
+
+       @Override
+       public MD5ServerSocketChannelConfig setAllocator(final ByteBufAllocator allocator) {
+               config.setAllocator(allocator);
+               return this;
+       }
+
+       @Override
+       public MD5ServerSocketChannelConfig setRecvByteBufAllocator(final RecvByteBufAllocator allocator) {
+               config.setRecvByteBufAllocator(allocator);
+               return this;
+       }
+
+       @Override
+       public MD5ServerSocketChannelConfig setAutoRead(final boolean autoRead) {
+               config.setAutoRead(autoRead);
+               return this;
+       }
+
+       @Override
+       public MD5ServerSocketChannelConfig setMessageSizeEstimator(final MessageSizeEstimator estimator) {
+               config.setMessageSizeEstimator(estimator);
+               return this;
+       }
+
+       @Override
+       public MD5ServerSocketChannelConfig setWriteBufferLowWaterMark(final int writeBufferLowWaterMark) {
+               config.setWriteBufferLowWaterMark(writeBufferLowWaterMark);
+               return this;
+       }
+}
diff --git a/tcp-md5/netty/src/main/java/org/opendaylight/bgpcep/tcpmd5/netty/ProxyMD5SocketChannelConfig.java b/tcp-md5/netty/src/main/java/org/opendaylight/bgpcep/tcpmd5/netty/ProxyMD5SocketChannelConfig.java
new file mode 100644 (file)
index 0000000..33b25b3
--- /dev/null
@@ -0,0 +1,184 @@
+/*
+ * Copyright (c) 2013 Robert Varga. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.bgpcep.tcpmd5.netty;
+
+import io.netty.buffer.ByteBufAllocator;
+import io.netty.channel.ChannelConfig;
+import io.netty.channel.MessageSizeEstimator;
+import io.netty.channel.RecvByteBufAllocator;
+import io.netty.channel.socket.SocketChannelConfig;
+
+import org.opendaylight.bgpcep.tcpmd5.MD5SocketChannel;
+
+/**
+ * Proxy implementation working on top an existing SocketChannelConfig.
+ */
+final class ProxyMD5SocketChannelConfig extends AbstractMD5ChannelConfig<SocketChannelConfig> implements MD5SocketChannelConfig {
+       public ProxyMD5SocketChannelConfig(final SocketChannelConfig config, final MD5SocketChannel channel) {
+               super(config, channel);
+       }
+
+       @Override
+       public boolean isTcpNoDelay() {
+               return config.isTcpNoDelay();
+       }
+
+       @Override
+       public int getSoLinger() {
+               return config.getSoLinger();
+       }
+
+       @Override
+       public int getSendBufferSize() {
+               return config.getSendBufferSize();
+       }
+
+       @Override
+       public int getReceiveBufferSize() {
+               return config.getReceiveBufferSize();
+       }
+
+       @Override
+       public boolean isKeepAlive() {
+               return config.isKeepAlive();
+       }
+
+       @Override
+       public int getTrafficClass() {
+               return config.getTrafficClass();
+       }
+
+       @Override
+       public boolean isReuseAddress() {
+               return config.isReuseAddress();
+       }
+
+       @Override
+       public boolean isAllowHalfClosure() {
+               return config.isAllowHalfClosure();
+       }
+
+       @Override
+       public ChannelConfig setWriteBufferHighWaterMark(final int writeBufferHighWaterMark) {
+               config.setWriteBufferHighWaterMark(writeBufferHighWaterMark);
+               return this;
+       }
+
+       @Override
+       public ChannelConfig setWriteBufferLowWaterMark(final int writeBufferLowWaterMark) {
+               config.setWriteBufferLowWaterMark(writeBufferLowWaterMark);
+               return this;
+       }
+
+       @Override
+       public byte[] getMD5SignatureKey() {
+               return getKey();
+       }
+
+       @Override
+       public MD5SocketChannelConfig setMD5SignatureKey(final byte[] key) {
+               setKey(key);
+               return this;
+       }
+
+       @Override
+       public MD5SocketChannelConfig setTcpNoDelay(final boolean tcpNoDelay) {
+               config.setTcpNoDelay(tcpNoDelay);
+               return this;
+       }
+
+       @Override
+       public MD5SocketChannelConfig setSoLinger(final int soLinger) {
+               config.setSoLinger(soLinger);
+               return this;
+       }
+
+       @Override
+       public MD5SocketChannelConfig setSendBufferSize(final int sendBufferSize) {
+               config.setSendBufferSize(sendBufferSize);
+               return this;
+       }
+
+       @Override
+       public MD5SocketChannelConfig setReceiveBufferSize(final int receiveBufferSize) {
+               config.setReceiveBufferSize(receiveBufferSize);
+               return this;
+       }
+
+       @Override
+       public MD5SocketChannelConfig setKeepAlive(final boolean keepAlive) {
+               config.setKeepAlive(keepAlive);
+               return this;
+       }
+
+       @Override
+       public MD5SocketChannelConfig setTrafficClass(final int trafficClass) {
+               config.setTrafficClass(trafficClass);
+               return this;
+       }
+
+       @Override
+       public MD5SocketChannelConfig setReuseAddress(final boolean reuseAddress) {
+               config.setReuseAddress(reuseAddress);
+               return this;
+       }
+
+       @Override
+       public MD5SocketChannelConfig setPerformancePreferences(final int connectionTime, final int latency, final int bandwidth) {
+               config.setPerformancePreferences(connectionTime, latency, bandwidth);
+               return this;
+       }
+
+       @Override
+       public MD5SocketChannelConfig setAllowHalfClosure(final boolean allowHalfClosure) {
+               config.setAllowHalfClosure(allowHalfClosure);
+               return this;
+       }
+
+       @Override
+       public MD5SocketChannelConfig setConnectTimeoutMillis(final int connectTimeoutMillis) {
+               config.setConnectTimeoutMillis(connectTimeoutMillis);
+               return this;
+       }
+
+       @Override
+       public MD5SocketChannelConfig setMaxMessagesPerRead(final int maxMessagesPerRead) {
+               config.setMaxMessagesPerRead(maxMessagesPerRead);
+               return this;
+       }
+
+       @Override
+       public MD5SocketChannelConfig setWriteSpinCount(final int writeSpinCount) {
+               config.setWriteSpinCount(writeSpinCount);
+               return this;
+       }
+
+       @Override
+       public MD5SocketChannelConfig setAllocator(final ByteBufAllocator allocator) {
+               config.setAllocator(allocator);
+               return this;
+       }
+
+       @Override
+       public MD5SocketChannelConfig setRecvByteBufAllocator(final RecvByteBufAllocator allocator) {
+               config.setRecvByteBufAllocator(allocator);
+               return this;
+       }
+
+       @Override
+       public MD5SocketChannelConfig setAutoRead(final boolean autoRead) {
+               config.setAutoRead(autoRead);
+               return this;
+       }
+
+       @Override
+       public MD5SocketChannelConfig setMessageSizeEstimator(final MessageSizeEstimator estimator) {
+               config.setMessageSizeEstimator(estimator);
+               return this;
+       }
+}
index e04688c42bbf4085b94a072b0ccc09fcbcff8f54..3f93d255670a06c02e0442ce2228336deebd6899 100644 (file)
@@ -35,6 +35,7 @@
        <modules>
         <module>core</module>
         <module>jni</module>
+        <module>netty</module>
     </modules>
 
     <dependencyManagement>
                 <artifactId>tcpmd5-jni</artifactId>
                 <version>${project.version}</version>
             </dependency>
+            <dependency>
+                <groupId>${project.groupId}</groupId>
+                <artifactId>tcpmd5-netty</artifactId>
+                <version>${project.version}</version>
+            </dependency>
             <dependency>
                 <groupId>${project.groupId}</groupId>
                 <artifactId>tcpmd5-jni</artifactId>