blob: e87989d8b5ae95b52046f1d81a6bbc2a3fde394a [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
Ray Milkey269ffb92014-04-03 14:43:30 -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;
28import org.jboss.netty.util.HashedWheelTimer;
29import org.jboss.netty.util.Timer;
30
31/**
32 * Creates a ChannelPipeline for a server-side openflow channel
Ray Milkey269ffb92014-04-03 14:43:30 -070033 *
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080034 * @author readams
35 */
36public class OpenflowPipelineFactory implements ChannelPipelineFactory {
37
38 protected Controller controller;
39 protected ThreadPoolExecutor pipelineExecutor;
40 protected Timer timer;
41 protected IdleStateHandler idleHandler;
42 protected ReadTimeoutHandler readTimeoutHandler;
Ray Milkey269ffb92014-04-03 14:43:30 -070043
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080044 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 }
Ray Milkey269ffb92014-04-03 14:43:30 -070053
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080054 @Override
55 public ChannelPipeline getPipeline() throws Exception {
56 OFChannelState state = new OFChannelState();
Ray Milkey269ffb92014-04-03 14:43:30 -070057
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080058 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 pipeline.addLast("handshaketimeout",
Ray Milkey269ffb92014-04-03 14:43:30 -070064 new HandshakeTimeoutHandler(state, timer, 60)); // ONOS: was 15 increased it to fix Issue #296
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080065 if (pipelineExecutor != null)
66 pipeline.addLast("pipelineExecutor",
Ray Milkey269ffb92014-04-03 14:43:30 -070067 new ExecutionHandler(pipelineExecutor));
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080068 pipeline.addLast("handler", controller.getChannelHandler(state));
69 return pipeline;
70 }
71
72}