blob: c78e25e6a5381051641eee511fe664725dc0484f [file] [log] [blame]
tom7ef8ff92014-09-17 13:08:06 -07001/**
2* Copyright 2011, Big Switch Networks, Inc.
3* Originally created by David Erickson, Stanford University
4*
5* Licensed under the Apache License, Version 2.0 (the "License"); you may
6* not use this file except in compliance with the License. You may obtain
7* a copy of the License at
8*
9* http://www.apache.org/licenses/LICENSE-2.0
10*
11* Unless required by applicable law or agreed to in writing, software
12* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14* License for the specific language governing permissions and limitations
15* under the License.
16**/
17
tom9c94c5b2014-09-17 13:14:42 -070018package org.onlab.onos.openflow.controller.impl;
tom7ef8ff92014-09-17 13:08:06 -070019
20import java.util.concurrent.ThreadPoolExecutor;
21
22import org.jboss.netty.channel.ChannelPipeline;
23import org.jboss.netty.channel.ChannelPipelineFactory;
24import org.jboss.netty.channel.Channels;
25import org.jboss.netty.handler.execution.ExecutionHandler;
26import org.jboss.netty.handler.timeout.IdleStateHandler;
27import org.jboss.netty.handler.timeout.ReadTimeoutHandler;
28import org.jboss.netty.util.ExternalResourceReleasable;
29import org.jboss.netty.util.HashedWheelTimer;
30import org.jboss.netty.util.Timer;
31
32/**
33 * Creates a ChannelPipeline for a server-side openflow channel.
34 */
35public class OpenflowPipelineFactory
36 implements ChannelPipelineFactory, ExternalResourceReleasable {
37
38 protected Controller controller;
39 protected ThreadPoolExecutor pipelineExecutor;
40 protected Timer timer;
41 protected IdleStateHandler idleHandler;
42 protected ReadTimeoutHandler readTimeoutHandler;
43
44 public OpenflowPipelineFactory(Controller controller,
45 ThreadPoolExecutor pipelineExecutor) {
46 super();
47 this.controller = controller;
48 this.pipelineExecutor = pipelineExecutor;
49 this.timer = new HashedWheelTimer();
50 this.idleHandler = new IdleStateHandler(timer, 20, 25, 0);
51 this.readTimeoutHandler = new ReadTimeoutHandler(timer, 30);
52 }
53
54 @Override
55 public ChannelPipeline getPipeline() throws Exception {
56 OFChannelHandler handler = new OFChannelHandler(controller);
57
58 ChannelPipeline pipeline = Channels.pipeline();
59 pipeline.addLast("ofmessagedecoder", new OFMessageDecoder());
60 pipeline.addLast("ofmessageencoder", new OFMessageEncoder());
61 pipeline.addLast("idle", idleHandler);
62 pipeline.addLast("timeout", readTimeoutHandler);
63 // XXX S ONOS: was 15 increased it to fix Issue #296
64 pipeline.addLast("handshaketimeout",
65 new HandshakeTimeoutHandler(handler, timer, 60));
66 if (pipelineExecutor != null) {
67 pipeline.addLast("pipelineExecutor",
68 new ExecutionHandler(pipelineExecutor));
69 }
70 pipeline.addLast("handler", handler);
71 return pipeline;
72 }
73
74 @Override
75 public void releaseExternalResources() {
76 timer.stop();
77 }
78}