blob: 62938fe2e670cf33b14503de56d7e8132e1c371a [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
Brian O'Connorc67f9fa2014-08-07 18:17:46 -07002* 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**/
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080017
18package net.floodlightcontroller.core.internal;
19
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;
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070028import org.jboss.netty.util.ExternalResourceReleasable;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080029import org.jboss.netty.util.HashedWheelTimer;
30import org.jboss.netty.util.Timer;
31
32/**
33 * Creates a ChannelPipeline for a server-side openflow channel
34 * @author readams
35 */
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070036public class OpenflowPipelineFactory
37 implements ChannelPipelineFactory, ExternalResourceReleasable {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080038
39 protected Controller controller;
40 protected ThreadPoolExecutor pipelineExecutor;
41 protected Timer timer;
42 protected IdleStateHandler idleHandler;
43 protected ReadTimeoutHandler readTimeoutHandler;
Ray Milkey269ffb92014-04-03 14:43:30 -070044
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080045 public OpenflowPipelineFactory(Controller controller,
46 ThreadPoolExecutor pipelineExecutor) {
47 super();
48 this.controller = controller;
49 this.pipelineExecutor = pipelineExecutor;
50 this.timer = new HashedWheelTimer();
51 this.idleHandler = new IdleStateHandler(timer, 20, 25, 0);
52 this.readTimeoutHandler = new ReadTimeoutHandler(timer, 30);
53 }
Ray Milkey269ffb92014-04-03 14:43:30 -070054
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080055 @Override
56 public ChannelPipeline getPipeline() throws Exception {
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070057 OFChannelHandler handler = new OFChannelHandler(controller);
Ray Milkey269ffb92014-04-03 14:43:30 -070058
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080059 ChannelPipeline pipeline = Channels.pipeline();
60 pipeline.addLast("ofmessagedecoder", new OFMessageDecoder());
61 pipeline.addLast("ofmessageencoder", new OFMessageEncoder());
62 pipeline.addLast("idle", idleHandler);
63 pipeline.addLast("timeout", readTimeoutHandler);
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070064 // XXX S ONOS: was 15 increased it to fix Issue #296
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080065 pipeline.addLast("handshaketimeout",
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070066 new HandshakeTimeoutHandler(handler, timer, 60));
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080067 if (pipelineExecutor != null)
68 pipeline.addLast("pipelineExecutor",
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070069 new ExecutionHandler(pipelineExecutor));
70 pipeline.addLast("handler", handler);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080071 return pipeline;
72 }
73
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070074 @Override
75 public void releaseExternalResources() {
76 timer.stop();
77 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080078}