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;
32 * Creates a ChannelPipeline for a server-side openflow channel.
34 public class OpenflowPipelineFactory
35 implements ChannelPipelineFactory, ExternalResourceReleasable {
37 protected Controller controller;
38 protected ThreadPoolExecutor pipelineExecutor;
39 protected Timer timer;
40 protected IdleStateHandler idleHandler;
41 protected ReadTimeoutHandler readTimeoutHandler;
43 public OpenflowPipelineFactory(Controller controller,
44 ThreadPoolExecutor pipelineExecutor) {
46 this.controller = controller;
47 this.pipelineExecutor = pipelineExecutor;
48 this.timer = new HashedWheelTimer();
49 this.idleHandler = new IdleStateHandler(timer, 20, 25, 0);
50 this.readTimeoutHandler = new ReadTimeoutHandler(timer, 30);
54 public ChannelPipeline getPipeline() throws Exception {
55 OFChannelHandler handler = new OFChannelHandler(controller);
57 ChannelPipeline pipeline = Channels.pipeline();
58 pipeline.addLast("ofmessagedecoder", new OFMessageDecoder());
59 pipeline.addLast("ofmessageencoder", new OFMessageEncoder());
60 pipeline.addLast("idle", idleHandler);
61 pipeline.addLast("timeout", readTimeoutHandler);
62 // XXX S ONOS: was 15 increased it to fix Issue #296
63 pipeline.addLast("handshaketimeout",
64 new HandshakeTimeoutHandler(handler, timer, 60));
65 if (pipelineExecutor != null) {
66 pipeline.addLast("pipelineExecutor",
67 new ExecutionHandler(pipelineExecutor));
69 pipeline.addLast("handler", handler);
74 public void releaseExternalResources() {