blob: 4485709851fc08cc051872787999b17c8e5ca242 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
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
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
33 * @author readams
34 */
35public class OpenflowPipelineFactory implements ChannelPipelineFactory {
36
37 protected Controller controller;
38 protected ThreadPoolExecutor pipelineExecutor;
39 protected Timer timer;
40 protected IdleStateHandler idleHandler;
41 protected ReadTimeoutHandler readTimeoutHandler;
42
43 public OpenflowPipelineFactory(Controller controller,
44 ThreadPoolExecutor pipelineExecutor) {
45 super();
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);
51 }
52
53 @Override
54 public ChannelPipeline getPipeline() throws Exception {
55 OFChannelState state = new OFChannelState();
56
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 pipeline.addLast("handshaketimeout",
Umesh Krishnaswamy4572c052013-03-26 13:08:05 -070063 new HandshakeTimeoutHandler(state, timer, 60)); // ONOS: was 15 increased it to fix Issue #296
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080064 if (pipelineExecutor != null)
65 pipeline.addLast("pipelineExecutor",
66 new ExecutionHandler(pipelineExecutor));
67 pipeline.addLast("handler", controller.getChannelHandler(state));
68 return pipeline;
69 }
70
71}