blob: 56f1d3c06ba4ac99bd9eba2d43b930ceaaeb595f [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 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;
alshabib5162a9d2015-12-07 17:49:37 -080034import java.util.concurrent.ThreadPoolExecutor;
tom7ef8ff92014-09-17 13:08:06 -070035
36/**
37 * Creates a ChannelPipeline for a server-side openflow channel.
38 */
39public class OpenflowPipelineFactory
40 implements ChannelPipelineFactory, ExternalResourceReleasable {
41
alshabib9b6c19c2015-09-26 12:19:27 -070042 private final Logger log = LoggerFactory.getLogger(getClass());
43
alshabib5162a9d2015-12-07 17:49:37 -080044
45 private final SSLContext sslContext;
tom7ef8ff92014-09-17 13:08:06 -070046 protected Controller controller;
47 protected ThreadPoolExecutor pipelineExecutor;
48 protected Timer timer;
49 protected IdleStateHandler idleHandler;
50 protected ReadTimeoutHandler readTimeoutHandler;
51
52 public OpenflowPipelineFactory(Controller controller,
alshabib9b6c19c2015-09-26 12:19:27 -070053 ThreadPoolExecutor pipelineExecutor,
alshabib5162a9d2015-12-07 17:49:37 -080054 SSLContext sslContext) {
tom7ef8ff92014-09-17 13:08:06 -070055 super();
56 this.controller = controller;
57 this.pipelineExecutor = pipelineExecutor;
58 this.timer = new HashedWheelTimer();
59 this.idleHandler = new IdleStateHandler(timer, 20, 25, 0);
60 this.readTimeoutHandler = new ReadTimeoutHandler(timer, 30);
alshabib5162a9d2015-12-07 17:49:37 -080061 this.sslContext = sslContext;
tom7ef8ff92014-09-17 13:08:06 -070062 }
63
64 @Override
65 public ChannelPipeline getPipeline() throws Exception {
66 OFChannelHandler handler = new OFChannelHandler(controller);
67
68 ChannelPipeline pipeline = Channels.pipeline();
alshabib5162a9d2015-12-07 17:49:37 -080069 if (sslContext != null) {
alshabib9b6c19c2015-09-26 12:19:27 -070070 log.info("OpenFlow SSL enabled.");
alshabib5162a9d2015-12-07 17:49:37 -080071 SSLEngine sslEngine = sslContext.createSSLEngine();
72
73 sslEngine.setNeedClientAuth(true);
74 sslEngine.setUseClientMode(false);
75 sslEngine.setEnabledProtocols(sslEngine.getSupportedProtocols());
76 sslEngine.setEnabledCipherSuites(sslEngine.getSupportedCipherSuites());
77 sslEngine.setEnableSessionCreation(true);
78
79 SslHandler sslHandler = new SslHandler(sslEngine);
80 pipeline.addLast("ssl", sslHandler);
alshabib9b6c19c2015-09-26 12:19:27 -070081 } else {
82 log.info("OpenFlow SSL disabled");
83 }
tom7ef8ff92014-09-17 13:08:06 -070084 pipeline.addLast("ofmessagedecoder", new OFMessageDecoder());
85 pipeline.addLast("ofmessageencoder", new OFMessageEncoder());
86 pipeline.addLast("idle", idleHandler);
87 pipeline.addLast("timeout", readTimeoutHandler);
88 // XXX S ONOS: was 15 increased it to fix Issue #296
89 pipeline.addLast("handshaketimeout",
90 new HandshakeTimeoutHandler(handler, timer, 60));
91 if (pipelineExecutor != null) {
92 pipeline.addLast("pipelineExecutor",
93 new ExecutionHandler(pipelineExecutor));
94 }
95 pipeline.addLast("handler", handler);
96 return pipeline;
97 }
98
99 @Override
100 public void releaseExternalResources() {
101 timer.stop();
102 }
103}