blob: 1467520dd1f78a86c843a2d6274a661200d74629 [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
19import java.util.concurrent.ThreadPoolExecutor;
20
21import org.jboss.netty.channel.ChannelPipeline;
22import org.jboss.netty.channel.ChannelPipelineFactory;
23import org.jboss.netty.channel.Channels;
24import org.jboss.netty.handler.execution.ExecutionHandler;
25import org.jboss.netty.handler.timeout.IdleStateHandler;
26import org.jboss.netty.handler.timeout.ReadTimeoutHandler;
27import org.jboss.netty.util.ExternalResourceReleasable;
28import org.jboss.netty.util.HashedWheelTimer;
29import org.jboss.netty.util.Timer;
alshabib9b6c19c2015-09-26 12:19:27 -070030import org.slf4j.Logger;
31import org.slf4j.LoggerFactory;
32
33import javax.net.ssl.SSLEngine;
tom7ef8ff92014-09-17 13:08:06 -070034
35/**
36 * Creates a ChannelPipeline for a server-side openflow channel.
37 */
38public class OpenflowPipelineFactory
39 implements ChannelPipelineFactory, ExternalResourceReleasable {
40
alshabib9b6c19c2015-09-26 12:19:27 -070041 private final Logger log = LoggerFactory.getLogger(getClass());
42
43 private final SSLEngine sslEngine;
tom7ef8ff92014-09-17 13:08:06 -070044 protected Controller controller;
45 protected ThreadPoolExecutor pipelineExecutor;
46 protected Timer timer;
47 protected IdleStateHandler idleHandler;
48 protected ReadTimeoutHandler readTimeoutHandler;
49
50 public OpenflowPipelineFactory(Controller controller,
alshabib9b6c19c2015-09-26 12:19:27 -070051 ThreadPoolExecutor pipelineExecutor,
52 SSLEngine sslEngine) {
tom7ef8ff92014-09-17 13:08:06 -070053 super();
54 this.controller = controller;
55 this.pipelineExecutor = pipelineExecutor;
56 this.timer = new HashedWheelTimer();
57 this.idleHandler = new IdleStateHandler(timer, 20, 25, 0);
58 this.readTimeoutHandler = new ReadTimeoutHandler(timer, 30);
alshabib9b6c19c2015-09-26 12:19:27 -070059 this.sslEngine = sslEngine;
tom7ef8ff92014-09-17 13:08:06 -070060 }
61
62 @Override
63 public ChannelPipeline getPipeline() throws Exception {
64 OFChannelHandler handler = new OFChannelHandler(controller);
65
66 ChannelPipeline pipeline = Channels.pipeline();
alshabib9b6c19c2015-09-26 12:19:27 -070067 if (sslEngine != null) {
68 log.info("OpenFlow SSL enabled.");
69 pipeline.addLast("ssl",
70 new org.jboss.netty.handler.ssl.SslHandler(sslEngine));
71 } else {
72 log.info("OpenFlow SSL disabled");
73 }
tom7ef8ff92014-09-17 13:08:06 -070074 pipeline.addLast("ofmessagedecoder", new OFMessageDecoder());
75 pipeline.addLast("ofmessageencoder", new OFMessageEncoder());
76 pipeline.addLast("idle", idleHandler);
77 pipeline.addLast("timeout", readTimeoutHandler);
78 // XXX S ONOS: was 15 increased it to fix Issue #296
79 pipeline.addLast("handshaketimeout",
80 new HandshakeTimeoutHandler(handler, timer, 60));
81 if (pipelineExecutor != null) {
82 pipeline.addLast("pipelineExecutor",
83 new ExecutionHandler(pipelineExecutor));
84 }
85 pipeline.addLast("handler", handler);
86 return pipeline;
87 }
88
89 @Override
90 public void releaseExternalResources() {
91 timer.stop();
92 }
93}