Yuta HIGUCHI | 6ee6b8c | 2017-05-09 14:44:30 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Yuta HIGUCHI | 6ee6b8c | 2017-05-09 14:44:30 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.openflow.controller.impl; |
| 18 | |
| 19 | import org.slf4j.Logger; |
| 20 | import org.slf4j.LoggerFactory; |
| 21 | |
| 22 | import io.netty.channel.ChannelInitializer; |
| 23 | import io.netty.channel.ChannelPipeline; |
| 24 | import io.netty.channel.socket.SocketChannel; |
| 25 | import io.netty.handler.ssl.SslHandler; |
Anton Chigrin | 4af4f87 | 2019-01-14 17:29:56 +0200 | [diff] [blame^] | 26 | import io.netty.handler.flush.FlushConsolidationHandler; |
Yuta HIGUCHI | 6ee6b8c | 2017-05-09 14:44:30 -0700 | [diff] [blame] | 27 | import io.netty.handler.timeout.IdleStateHandler; |
| 28 | import io.netty.handler.timeout.ReadTimeoutHandler; |
| 29 | import io.netty.util.concurrent.EventExecutorGroup; |
| 30 | |
| 31 | import javax.net.ssl.SSLContext; |
| 32 | import javax.net.ssl.SSLEngine; |
| 33 | |
| 34 | /** |
| 35 | * Creates a ChannelInitializer for a server-side openflow channel. |
| 36 | */ |
| 37 | public class OFChannelInitializer |
| 38 | extends ChannelInitializer<SocketChannel> { |
| 39 | |
| 40 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 41 | |
| 42 | |
| 43 | private final SSLContext sslContext; |
| 44 | protected Controller controller; |
| 45 | protected EventExecutorGroup pipelineExecutor; |
| 46 | |
| 47 | public OFChannelInitializer(Controller controller, |
| 48 | EventExecutorGroup pipelineExecutor, |
| 49 | SSLContext sslContext) { |
| 50 | super(); |
| 51 | this.controller = controller; |
| 52 | this.pipelineExecutor = pipelineExecutor; |
| 53 | this.sslContext = sslContext; |
| 54 | } |
| 55 | |
| 56 | @Override |
| 57 | protected void initChannel(SocketChannel ch) throws Exception { |
| 58 | |
| 59 | OFChannelHandler handler = new OFChannelHandler(controller); |
| 60 | |
| 61 | ChannelPipeline pipeline = ch.pipeline(); |
| 62 | if (sslContext != null) { |
| 63 | log.info("OpenFlow SSL enabled."); |
| 64 | SSLEngine sslEngine = sslContext.createSSLEngine(); |
| 65 | |
| 66 | sslEngine.setNeedClientAuth(true); |
| 67 | sslEngine.setUseClientMode(false); |
| 68 | sslEngine.setEnabledProtocols(sslEngine.getSupportedProtocols()); |
| 69 | sslEngine.setEnabledCipherSuites(sslEngine.getSupportedCipherSuites()); |
| 70 | sslEngine.setEnableSessionCreation(true); |
| 71 | |
| 72 | SslHandler sslHandler = new SslHandler(sslEngine); |
| 73 | pipeline.addLast("ssl", sslHandler); |
| 74 | } else { |
| 75 | log.debug("OpenFlow SSL disabled."); |
| 76 | } |
| 77 | pipeline.addLast("ofmessageencoder", OFMessageEncoder.getInstance()); |
| 78 | pipeline.addLast("ofmessagedecoder", OFMessageDecoder.getInstance()); |
| 79 | |
Anton Chigrin | 4af4f87 | 2019-01-14 17:29:56 +0200 | [diff] [blame^] | 80 | pipeline.addLast("consolidateflush", new FlushConsolidationHandler( |
| 81 | FlushConsolidationHandler.DEFAULT_EXPLICIT_FLUSH_AFTER_FLUSHES, true)); |
Yuta HIGUCHI | 6ee6b8c | 2017-05-09 14:44:30 -0700 | [diff] [blame] | 82 | pipeline.addLast("idle", new IdleStateHandler(20, 25, 0)); |
| 83 | pipeline.addLast("timeout", new ReadTimeoutHandler(30)); |
| 84 | |
| 85 | // XXX S ONOS: was 15 increased it to fix Issue #296 |
| 86 | pipeline.addLast("handshaketimeout", |
| 87 | new HandshakeTimeoutHandler(handler, 60)); |
| 88 | // ExecutionHandler equivalent now part of Netty core |
| 89 | if (pipelineExecutor != null) { |
| 90 | pipeline.addLast(pipelineExecutor, "handler", handler); |
| 91 | } else { |
| 92 | pipeline.addLast("handler", handler); |
| 93 | } |
| 94 | } |
| 95 | } |