blob: a78e6a667bd4d57631e4b97ccffc037b7fec6e32 [file] [log] [blame]
Yuta HIGUCHI6ee6b8c2017-05-09 14:44:30 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Yuta HIGUCHI6ee6b8c2017-05-09 14:44:30 -07003 *
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
17package org.onosproject.openflow.controller.impl;
18
19import org.slf4j.Logger;
20import org.slf4j.LoggerFactory;
21
22import io.netty.channel.ChannelInitializer;
23import io.netty.channel.ChannelPipeline;
24import io.netty.channel.socket.SocketChannel;
25import io.netty.handler.ssl.SslHandler;
Anton Chigrin4af4f872019-01-14 17:29:56 +020026import io.netty.handler.flush.FlushConsolidationHandler;
Yuta HIGUCHI6ee6b8c2017-05-09 14:44:30 -070027import io.netty.handler.timeout.IdleStateHandler;
28import io.netty.handler.timeout.ReadTimeoutHandler;
29import io.netty.util.concurrent.EventExecutorGroup;
30
31import javax.net.ssl.SSLContext;
32import javax.net.ssl.SSLEngine;
33
34/**
35 * Creates a ChannelInitializer for a server-side openflow channel.
36 */
37public 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 Chigrin4af4f872019-01-14 17:29:56 +020080 pipeline.addLast("consolidateflush", new FlushConsolidationHandler(
81 FlushConsolidationHandler.DEFAULT_EXPLICIT_FLUSH_AFTER_FLUSHES, true));
Yuta HIGUCHI6ee6b8c2017-05-09 14:44:30 -070082 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}