2 * Copyright 2014 Open Networking Laboratory
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onosproject.openflow.controller.impl;
19 import java.util.concurrent.ThreadPoolExecutor;
21 import org.jboss.netty.channel.ChannelPipeline;
22 import org.jboss.netty.channel.ChannelPipelineFactory;
23 import org.jboss.netty.channel.Channels;
24 import org.jboss.netty.handler.execution.ExecutionHandler;
25 import org.jboss.netty.handler.timeout.IdleStateHandler;
26 import org.jboss.netty.handler.timeout.ReadTimeoutHandler;
27 import org.jboss.netty.util.ExternalResourceReleasable;
28 import org.jboss.netty.util.HashedWheelTimer;
29 import org.jboss.netty.util.Timer;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 import javax.net.ssl.SSLEngine;
36 * Creates a ChannelPipeline for a server-side openflow channel.
38 public class OpenflowPipelineFactory
39 implements ChannelPipelineFactory, ExternalResourceReleasable {
41 private final Logger log = LoggerFactory.getLogger(getClass());
43 private final SSLEngine sslEngine;
44 protected Controller controller;
45 protected ThreadPoolExecutor pipelineExecutor;
46 protected Timer timer;
47 protected IdleStateHandler idleHandler;
48 protected ReadTimeoutHandler readTimeoutHandler;
50 public OpenflowPipelineFactory(Controller controller,
51 ThreadPoolExecutor pipelineExecutor,
52 SSLEngine sslEngine) {
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);
59 this.sslEngine = sslEngine;
63 public ChannelPipeline getPipeline() throws Exception {
64 OFChannelHandler handler = new OFChannelHandler(controller);
66 ChannelPipeline pipeline = Channels.pipeline();
67 if (sslEngine != null) {
68 log.info("OpenFlow SSL enabled.");
69 pipeline.addLast("ssl",
70 new org.jboss.netty.handler.ssl.SslHandler(sslEngine));
72 log.info("OpenFlow SSL disabled");
74 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));
85 pipeline.addLast("handler", handler);
90 public void releaseExternalResources() {