blob: c94d315b05be75771cf24a7858334fec88f3ff30 [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Thomas Vachuska781d18b2014-10-27 10:31:25 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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
Thomas Vachuska781d18b2014-10-27 10:31:25 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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.
Thomas Vachuska781d18b2014-10-27 10:31:25 -070015 */
tom7ef8ff92014-09-17 13:08:06 -070016
Brian O'Connorabafb502014-12-02 22:26:20 -080017package org.onosproject.openflow.controller.impl;
tom7ef8ff92014-09-17 13:08:06 -070018
tom7ef8ff92014-09-17 13:08:06 -070019import org.jboss.netty.channel.ChannelPipeline;
20import org.jboss.netty.channel.ChannelPipelineFactory;
21import org.jboss.netty.channel.Channels;
22import org.jboss.netty.handler.execution.ExecutionHandler;
alshabib5162a9d2015-12-07 17:49:37 -080023import org.jboss.netty.handler.ssl.SslHandler;
tom7ef8ff92014-09-17 13:08:06 -070024import org.jboss.netty.handler.timeout.IdleStateHandler;
25import org.jboss.netty.handler.timeout.ReadTimeoutHandler;
26import org.jboss.netty.util.ExternalResourceReleasable;
27import org.jboss.netty.util.HashedWheelTimer;
28import org.jboss.netty.util.Timer;
alshabib9b6c19c2015-09-26 12:19:27 -070029import org.slf4j.Logger;
30import org.slf4j.LoggerFactory;
31
alshabib5162a9d2015-12-07 17:49:37 -080032import javax.net.ssl.SSLContext;
alshabib9b6c19c2015-09-26 12:19:27 -070033import javax.net.ssl.SSLEngine;
Yuta HIGUCHIa809a172016-07-21 16:28:38 -070034
35import static org.onlab.util.Tools.groupedThreads;
36
alshabib5162a9d2015-12-07 17:49:37 -080037import java.util.concurrent.ThreadPoolExecutor;
tom7ef8ff92014-09-17 13:08:06 -070038
39/**
40 * Creates a ChannelPipeline for a server-side openflow channel.
41 */
42public class OpenflowPipelineFactory
43 implements ChannelPipelineFactory, ExternalResourceReleasable {
44
alshabib9b6c19c2015-09-26 12:19:27 -070045 private final Logger log = LoggerFactory.getLogger(getClass());
46
alshabib5162a9d2015-12-07 17:49:37 -080047
48 private final SSLContext sslContext;
tom7ef8ff92014-09-17 13:08:06 -070049 protected Controller controller;
50 protected ThreadPoolExecutor pipelineExecutor;
51 protected Timer timer;
52 protected IdleStateHandler idleHandler;
53 protected ReadTimeoutHandler readTimeoutHandler;
54
55 public OpenflowPipelineFactory(Controller controller,
alshabib9b6c19c2015-09-26 12:19:27 -070056 ThreadPoolExecutor pipelineExecutor,
alshabib5162a9d2015-12-07 17:49:37 -080057 SSLContext sslContext) {
tom7ef8ff92014-09-17 13:08:06 -070058 super();
59 this.controller = controller;
60 this.pipelineExecutor = pipelineExecutor;
Yuta HIGUCHIa809a172016-07-21 16:28:38 -070061 this.timer = new HashedWheelTimer(groupedThreads("OpenflowPipelineFactory", "timer-%d", log));
tom7ef8ff92014-09-17 13:08:06 -070062 this.idleHandler = new IdleStateHandler(timer, 20, 25, 0);
63 this.readTimeoutHandler = new ReadTimeoutHandler(timer, 30);
alshabib5162a9d2015-12-07 17:49:37 -080064 this.sslContext = sslContext;
tom7ef8ff92014-09-17 13:08:06 -070065 }
66
67 @Override
68 public ChannelPipeline getPipeline() throws Exception {
69 OFChannelHandler handler = new OFChannelHandler(controller);
70
71 ChannelPipeline pipeline = Channels.pipeline();
alshabib5162a9d2015-12-07 17:49:37 -080072 if (sslContext != null) {
Madan Jampani6bcf5f22016-04-18 13:49:17 -070073 log.debug("OpenFlow SSL enabled.");
alshabib5162a9d2015-12-07 17:49:37 -080074 SSLEngine sslEngine = sslContext.createSSLEngine();
75
76 sslEngine.setNeedClientAuth(true);
77 sslEngine.setUseClientMode(false);
78 sslEngine.setEnabledProtocols(sslEngine.getSupportedProtocols());
79 sslEngine.setEnabledCipherSuites(sslEngine.getSupportedCipherSuites());
80 sslEngine.setEnableSessionCreation(true);
81
82 SslHandler sslHandler = new SslHandler(sslEngine);
83 pipeline.addLast("ssl", sslHandler);
alshabib9b6c19c2015-09-26 12:19:27 -070084 } else {
Madan Jampani6bcf5f22016-04-18 13:49:17 -070085 log.debug("OpenFlow SSL disabled.");
alshabib9b6c19c2015-09-26 12:19:27 -070086 }
tom7ef8ff92014-09-17 13:08:06 -070087 pipeline.addLast("ofmessagedecoder", new OFMessageDecoder());
88 pipeline.addLast("ofmessageencoder", new OFMessageEncoder());
89 pipeline.addLast("idle", idleHandler);
90 pipeline.addLast("timeout", readTimeoutHandler);
91 // XXX S ONOS: was 15 increased it to fix Issue #296
92 pipeline.addLast("handshaketimeout",
93 new HandshakeTimeoutHandler(handler, timer, 60));
94 if (pipelineExecutor != null) {
95 pipeline.addLast("pipelineExecutor",
96 new ExecutionHandler(pipelineExecutor));
97 }
98 pipeline.addLast("handler", handler);
99 return pipeline;
100 }
101
102 @Override
103 public void releaseExternalResources() {
104 timer.stop();
105 }
106}