2 * Copyright (c) 2014 Robert Varga. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.bgpcep.tcpmd5.netty;
10 import io.netty.buffer.ByteBufAllocator;
11 import io.netty.channel.ChannelOption;
12 import io.netty.channel.MessageSizeEstimator;
13 import io.netty.channel.RecvByteBufAllocator;
14 import io.netty.channel.socket.DefaultSocketChannelConfig;
18 import org.opendaylight.bgpcep.tcpmd5.KeyAccessFactory;
19 import org.opendaylight.bgpcep.tcpmd5.KeyMapping;
21 public class DefaultMD5SocketChannelConfig extends DefaultSocketChannelConfig implements MD5SocketChannelConfig {
22 private final NettyKeyAccess keyAccess;
24 public DefaultMD5SocketChannelConfig(final MD5NioSocketChannel channel, final KeyAccessFactory keyAccessFactory) {
25 super(channel, channel.javaChannel().socket());
26 this.keyAccess = NettyKeyAccess.create(keyAccessFactory, channel.javaChannel());
30 public KeyMapping getMD5SignatureKeys() {
31 return keyAccess.getKeys();
35 public MD5SocketChannelConfig setMD5SignatureKeys(final KeyMapping keys) {
36 keyAccess.setKeys(keys);
41 public MD5SocketChannelConfig setTcpNoDelay(final boolean tcpNoDelay) {
42 super.setTcpNoDelay(tcpNoDelay);
47 public MD5SocketChannelConfig setSoLinger(final int soLinger) {
48 super.setSoLinger(soLinger);
53 public MD5SocketChannelConfig setSendBufferSize(final int sendBufferSize) {
54 super.setSendBufferSize(sendBufferSize);
59 public MD5SocketChannelConfig setReceiveBufferSize(final int receiveBufferSize) {
60 super.setReceiveBufferSize(receiveBufferSize);
65 public MD5SocketChannelConfig setKeepAlive(final boolean keepAlive) {
66 super.setKeepAlive(keepAlive);
71 public MD5SocketChannelConfig setTrafficClass(final int trafficClass) {
72 super.setTrafficClass(trafficClass);
77 public MD5SocketChannelConfig setReuseAddress(final boolean reuseAddress) {
78 super.setReuseAddress(reuseAddress);
83 public MD5SocketChannelConfig setPerformancePreferences(final int connectionTime, final int latency, final int bandwidth) {
84 super.setPerformancePreferences(connectionTime, latency, bandwidth);
89 public MD5SocketChannelConfig setAllowHalfClosure(final boolean allowHalfClosure) {
90 super.setAllowHalfClosure(allowHalfClosure);
95 public MD5SocketChannelConfig setConnectTimeoutMillis(final int connectTimeoutMillis) {
96 super.setConnectTimeoutMillis(connectTimeoutMillis);
101 public MD5SocketChannelConfig setMaxMessagesPerRead(final int maxMessagesPerRead) {
102 super.setMaxMessagesPerRead(maxMessagesPerRead);
107 public MD5SocketChannelConfig setWriteSpinCount(final int writeSpinCount) {
108 super.setWriteSpinCount(writeSpinCount);
113 public MD5SocketChannelConfig setAllocator(final ByteBufAllocator allocator) {
114 super.setAllocator(allocator);
119 public MD5SocketChannelConfig setRecvByteBufAllocator(final RecvByteBufAllocator allocator) {
120 super.setRecvByteBufAllocator(allocator);
125 public MD5SocketChannelConfig setAutoRead(final boolean autoRead) {
126 super.setAutoRead(autoRead);
131 public MD5SocketChannelConfig setMessageSizeEstimator(final MessageSizeEstimator estimator) {
132 super.setMessageSizeEstimator(estimator);
137 public Map<ChannelOption<?>, Object> getOptions() {
138 final Map<ChannelOption<?>, Object> opts = super.getOptions();
139 final KeyMapping keys = keyAccess.getKeys();
141 opts.put(MD5ChannelOption.TCP_MD5SIG, keys);
148 public boolean setOptions(final Map<ChannelOption<?>, ?> options) {
149 boolean setAllOptions = true;
150 if (options.containsKey(MD5ChannelOption.TCP_MD5SIG)) {
151 setAllOptions = setOption(MD5ChannelOption.TCP_MD5SIG, (KeyMapping) options.get(MD5ChannelOption.TCP_MD5SIG));
154 return super.setOptions(options) && setAllOptions;
158 public <T> T getOption(final ChannelOption<T> option) {
159 if (option == MD5ChannelOption.TCP_MD5SIG) {
160 @SuppressWarnings("unchecked")
161 final T ret = (T) keyAccess.getKeys();
165 return super.getOption(option);
169 public <T> boolean setOption(final ChannelOption<T> option, final T value) {
170 if (option == MD5ChannelOption.TCP_MD5SIG) {
171 keyAccess.setKeys((KeyMapping) value);
175 return super.setOption(option, value);