blob: b03f00720ee0fb985d2cf78a1bd9afa8b61113cc [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;
26import io.netty.handler.timeout.IdleStateHandler;
27import io.netty.handler.timeout.ReadTimeoutHandler;
28import io.netty.util.concurrent.EventExecutorGroup;
29
30import javax.net.ssl.SSLContext;
31import javax.net.ssl.SSLEngine;
32
33/**
34 * Creates a ChannelInitializer for a server-side openflow channel.
35 */
36public 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
79 pipeline.addLast("idle", new IdleStateHandler(20, 25, 0));
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}