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; |
| 26 | import io.netty.handler.timeout.IdleStateHandler; |
| 27 | import io.netty.handler.timeout.ReadTimeoutHandler; |
| 28 | import io.netty.util.concurrent.EventExecutorGroup; |
| 29 | |
| 30 | import javax.net.ssl.SSLContext; |
| 31 | import javax.net.ssl.SSLEngine; |
| 32 | |
| 33 | /** |
| 34 | * Creates a ChannelInitializer for a server-side openflow channel. |
| 35 | */ |
| 36 | public class OFChannelInitializer |
| 37 | extends ChannelInitializer<SocketChannel> { |
| 38 | |
| 39 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 40 | |
| 41 | |
| 42 | private final SSLContext sslContext; |
| 43 | protected Controller controller; |
| 44 | protected EventExecutorGroup pipelineExecutor; |
| 45 | |
| 46 | public OFChannelInitializer(Controller controller, |
| 47 | EventExecutorGroup pipelineExecutor, |
| 48 | SSLContext sslContext) { |
| 49 | super(); |
| 50 | this.controller = controller; |
| 51 | this.pipelineExecutor = pipelineExecutor; |
| 52 | this.sslContext = sslContext; |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | protected void initChannel(SocketChannel ch) throws Exception { |
| 57 | |
| 58 | OFChannelHandler handler = new OFChannelHandler(controller); |
| 59 | |
| 60 | ChannelPipeline pipeline = ch.pipeline(); |
| 61 | if (sslContext != null) { |
| 62 | log.info("OpenFlow SSL enabled."); |
| 63 | SSLEngine sslEngine = sslContext.createSSLEngine(); |
| 64 | |
| 65 | sslEngine.setNeedClientAuth(true); |
| 66 | sslEngine.setUseClientMode(false); |
| 67 | sslEngine.setEnabledProtocols(sslEngine.getSupportedProtocols()); |
| 68 | sslEngine.setEnabledCipherSuites(sslEngine.getSupportedCipherSuites()); |
| 69 | sslEngine.setEnableSessionCreation(true); |
| 70 | |
| 71 | SslHandler sslHandler = new SslHandler(sslEngine); |
| 72 | pipeline.addLast("ssl", sslHandler); |
| 73 | } else { |
| 74 | log.debug("OpenFlow SSL disabled."); |
| 75 | } |
| 76 | pipeline.addLast("ofmessageencoder", OFMessageEncoder.getInstance()); |
| 77 | pipeline.addLast("ofmessagedecoder", OFMessageDecoder.getInstance()); |
| 78 | |
pier | 641f1c0 | 2019-11-22 20:51:26 +0100 | [diff] [blame^] | 79 | pipeline.addLast("idle", new IdleStateHandler(5, 25, 0)); |
Yuta HIGUCHI | 6ee6b8c | 2017-05-09 14:44:30 -0700 | [diff] [blame] | 80 | pipeline.addLast("timeout", new ReadTimeoutHandler(30)); |
| 81 | |
| 82 | // XXX S ONOS: was 15 increased it to fix Issue #296 |
| 83 | pipeline.addLast("handshaketimeout", |
| 84 | new HandshakeTimeoutHandler(handler, 60)); |
| 85 | // ExecutionHandler equivalent now part of Netty core |
| 86 | if (pipelineExecutor != null) { |
| 87 | pipeline.addLast(pipelineExecutor, "handler", handler); |
| 88 | } else { |
| 89 | pipeline.addLast("handler", handler); |
| 90 | } |
| 91 | } |
| 92 | } |